Timer library¶
The timer library provides functions for setting, resetting and restarting timers, and for checking if a timer has expired. An application must "manually" check if its timers have expired; this is not done automatically.
A timer is declared as a struct
timer
and all access to the timer is made by a pointer to the declared timer.
Note
The timer library is not able to post events when a timer expires. The Event timers should be used for this purpose.
Note
The timer library uses the Clock library to measure time. Intervals should be specified in the format used by the clock library.
Structs¶
timer¶
A timer.
This structure is used for declaring a timer. The timer must be set with timer_set() before it can be used.
Name | Type | Description |
---|---|---|
start |
clock_time_t |
|
interval |
clock_interval_t |
Functions¶
timer_set¶
Set a timer.
This function is used to set a timer for a time sometime in the future. The function timer_expired() will evaluate to true after the timer has expired.
Parameters¶
Name | Description |
---|---|
t | A pointer to the timer. |
interval | The interval before the timer expires. |
timer_reset¶
Reset the timer with the same interval.
This function resets the timer with the same interval that was given to the timer_set() function. The start point of the interval is the exact time that the timer last expired. Therefore, this function will cause the timer to be stable over time, unlike the timer_restart() function.
Note
Must not be executed before timer expired.
Parameters¶
Name | Description |
---|---|
t | A pointer to the timer. |
timer_restart¶
Restart the timer from the current point in time
This function restarts a timer with the same interval that was given to the timer_set() function. The timer will start at the current time.
Note
A periodic timer will drift if this function is used to reset it. For preioric timers, use the timer_reset() function instead.
Parameters¶
Name | Description |
---|---|
t | A pointer to the timer. |
timer_get_expire_time¶
Get the time for when the timer expires
Parameters¶
Name | Description |
---|---|
t | A pointer to the timer. |
Return value¶
Expiration time
timer_expired¶
Check if a timer has expired.
This function tests if a timer has expired and returns true or false depending on its status.
Parameters¶
Name | Description |
---|---|
t | A pointer to the timer. |
Return value¶
Non-zero if the timer has expired, zero otherwise.