Revision 257
updated timer rtc_add_function and implemented a rtc_remove_function
time.c | ||
---|---|---|
36 | 36 |
static volatile int _rtc_pulse[MAX_FUNCTIONS]; |
37 | 37 |
static volatile int _rtc_scale[MAX_FUNCTIONS]; |
38 | 38 |
static int function_count = 0; //Number of functions |
39 |
static void (*_rtc_f[MAX_FUNCTIONS])(void); |
|
40 |
|
|
39 |
static void (*_rtc_f[MAX_FUNCTIONS])(void); |
|
41 | 40 |
/** |
42 | 41 |
* @defgroup time Time |
43 | 42 |
* @brief Time functions |
... | ... | |
122 | 121 |
return argc-1; |
123 | 122 |
} |
124 | 123 |
|
125 |
int add_function(int prescale_opt, void *rtc_func (void))
|
|
124 |
int rtc_add_function(void (*rtc_func) (void), int prescale_opt)
|
|
126 | 125 |
{ |
127 |
if(function_count+1>=MAX_FUNCTIONS)
|
|
126 |
if(function_count>=MAX_FUNCTIONS) |
|
128 | 127 |
return -1; |
129 |
function_count++; |
|
130 | 128 |
_rtc_f[function_count] = rtc_func; |
131 | 129 |
_rtc_pulse[function_count] = 0; |
132 | 130 |
_rtc_scale[function_count] = prescale_opt; |
133 |
return 1; |
|
131 |
//return position in array that function was added to, increment count |
|
132 |
//this position may change if functions are removed |
|
133 |
return function_count++; |
|
134 | 134 |
} |
135 | 135 |
|
136 |
int rtc_init(int prescale_opt, void *rtc_func(void)){ |
|
136 |
//remove function pointer |
|
137 |
int rtc_remove_function(void (*rtc_func)(void)) |
|
138 |
{ |
|
139 |
for(int i = 0; i < function_count; i++) |
|
140 |
if(_rtc_f[i] == rtc_func) { |
|
141 |
//If not last function replace with last and reduce number of functions |
|
142 |
if(i < function_count-1) { |
|
143 |
_rtc_f[i] = _rtc_f[function_count-1]; |
|
144 |
_rtc_pulse[i] = _rtc_pulse[function_count-1]; |
|
145 |
_rtc_scale[i] = _rtc_scale[function_count-1]; |
|
146 |
} |
|
147 |
return --function_count; |
|
148 |
} |
|
149 |
|
|
150 |
return -1; |
|
151 |
} |
|
152 |
|
|
153 |
int rtc_get_function_count() |
|
154 |
{ |
|
155 |
return function_count; |
|
156 |
} |
|
157 |
|
|
158 |
int rtc_init(int prescale_opt, void (*rtc_func)(void)){ |
|
137 | 159 |
int temp[] = {prescale_opt}; |
138 | 160 |
void (*temp2[MAX_FUNCTIONS])(void) = {rtc_func}; |
139 | 161 |
return rtc_multi_init(temp, temp2, 1); |
... | ... | |
168 | 190 |
|
169 | 191 |
void rtc_reset_all(void) |
170 | 192 |
{ |
171 |
for(int i =0; i <MAX_FUNCTIONS; i++)
|
|
193 |
for(int i =0; i < function_count; i++)
|
|
172 | 194 |
_rtc_val[i] = 0; |
173 | 195 |
} |
174 | 196 |
|
Also available in: Unified diff