Callback timers¶
The ctimer API provides a timer mechanism that calls a specified C function when a ctimer expires.
Structs¶
ctimer¶
Name | Type | Description |
---|---|---|
next |
struct ctimer * |
|
etimer |
struct etimer |
|
p |
struct process * |
|
f |
void(*)(void *) |
|
ptr |
void * |
Functions¶
ctimer_reset¶
Reset a callback timer with the same interval as was previously set.
This function resets the callback timer with the same interval that was given to the callback timer with the ctimer_set() function. The start point of the interval is the exact time that the callback timer last expired. Therefore, this function will cause the timer to be stable over time, unlike the ctimer_restart() function.
Parameters¶
Name | Description |
---|---|
c | A pointer to the callback timer. |
ctimer_restart¶
Restart a callback timer from the current point in time
This function restarts the callback timer with the same interval that was given to the ctimer_set() function. The callback timer will start at the current time.
Note
A periodic timer will drift if this function is used to reset it. For periodic timers, use the ctimer_reset() function instead.
Parameters¶
Name | Description |
---|---|
c | A pointer to the callback timer. |
ctimer_set¶
Set a callback timer.
This function is used to set a callback timer for a time sometime in the future. When the callback timer expires, the callback function f will be called with ptr as argument.
Parameters¶
Name | Description |
---|---|
c | A pointer to the callback timer. |
t | The interval before the timer expires. |
f | A function to be called when the timer expires. |
ptr | An opaque pointer that will be supplied as an argument to the callback function. |
ctimer_stop¶
Stop a pending callback timer.
This function stops a callback timer that has previously been set with ctimer_set(), ctimer_reset(), or ctimer_restart(). After this function has been called, the callback timer will be expired and will not call the callback function.
Parameters¶
Name | Description |
---|---|
c | A pointer to the pending callback timer. |
ctimer_expired¶
Check if a callback timer has expired.
This function tests if a callback timer has expired and returns true or false depending on its status.
Parameters¶
Name | Description |
---|---|
c | A pointer to the callback timer |
Return value¶
Non-zero if the timer has expired, zero otherwise.