Files | |
file | timer.c |
Timer implementation (license: GPLv2). | |
file | timer.h |
Timer header (license: GPLv2). | |
Modules | |
Timer service configuration | |
Typedefs | |
typedef void(* | timer_callback )(int timer) |
The type of callback function executed when a timer expires. | |
Functions | |
void | timer_interval () |
Global timeout handling function. | |
int | timer_alloc (timer_callback callback, uintptr_t user) |
Allocates a timer. | |
void | timer_free (int timer) |
Deallocates a timer. | |
bool | timer_set (int timer, uint32_t millis) |
Starts or restarts a timer. | |
bool | timer_stop (int timer) |
Stops the timer. | |
bool | timer_expired (int timer) |
Checks wether a timer has expired or was stopped manually. | |
uintptr_t | timer_get_user (int timer) |
Retrieves the user-defined data attached to a timer. | |
bool | timer_set_user (int timer, uintptr_t user) |
Assigns user-defined data to a timer. |
void timer_interval | ( | ) |
Global timeout handling function.
This function must be continuously called once for every time slice. This is usually done from the application main loop. However, it should not be done from an interrupt service routine to avoid race conditions.
The accuracy of the timer service is principally dependent on the accuracy of the timer interval between calls of this function. So do your best to guarantee constant intervals.
The length of the time slice is configured with TIMER_MS_PER_TICK.
int timer_alloc | ( | timer_callback | callback, | |
uintptr_t | user | |||
) |
Allocates a timer.
The given callback function is executed whenever the timer expires. The user value is attached to the timer and given as an extra argument to the callback function. It is not used by the timer module in any way.
[in] | callback | The function to execute whenever the timer expires. |
[in] | user | The user-defined value. |
-1
on failure. void timer_free | ( | int | timer | ) |
Deallocates a timer.
The timer being deallocated is stopped and marked as free.
[in] | timer | The identifier of the timer which to deallocate. |
bool timer_set | ( | int | timer, | |
uint32_t | millis | |||
) |
Starts or restarts a timer.
The timer expires after millis milliseconds.
[in] | timer | The identifier of the timer which to start. |
[in] | millis | The number of milliseconds after which the timer will expire. |
true
if the timer has successfully been started, false
on failure. bool timer_stop | ( | int | timer | ) |
Stops the timer.
[in] | timer | The identifier of the timer which to stop. |
true
if the timer has been stopped, false
on failure. bool timer_expired | ( | int | timer | ) |
Checks wether a timer has expired or was stopped manually.
[in] | timer | The identifier of the timer which to check. |
true
if the timer is not running, false
otherwise. uintptr_t timer_get_user | ( | int | timer | ) |
Retrieves the user-defined data attached to a timer.
[in] | timer | The identifier of the timer of which to retrieve the data. |
0
on failure. bool timer_set_user | ( | int | timer, | |
uintptr_t | user | |||
) |
Assigns user-defined data to a timer.
[in] | timer | The identifier of the timer which to assign the data to. |
[in] | user | The data which to assign to the timer. |
true
on success, false
on failure.