Periodic ztimer API. More...
Periodic ztimer API.
Once started, the periodic timer will call the configured callback function once each interval until the timer is either stopped using ztimer_periodic_stop or the callback function returns a non-zero value.
Should the timer underflow ((time_at_interrupt + interval) % 2**32 > interval), the next timer will be scheduled with an offset of zero, thus fire right away. This leads to a callback for each missed tick, until the original period can be honoured again.
Example:
ztimer periodic API
Definition in file periodic.h.
Go to the source code of this file.
Data Structures | |
struct | ztimer_periodic_t |
ztimer periodic structure More... | |
#define | ZTIMER_PERIODIC_KEEP_GOING 0 |
Periodic timer stop unless it returns this value. | |
void | ztimer_periodic_init (ztimer_clock_t *clock, ztimer_periodic_t *timer, int(*callback)(void *), void *arg, uint32_t interval) |
Initialize a periodic timer structure. More... | |
void | ztimer_periodic_start (ztimer_periodic_t *timer) |
Start or restart a periodic timer. More... | |
void | ztimer_periodic_stop (ztimer_periodic_t *timer) |
Stop a periodic timer. More... | |
void ztimer_periodic_init | ( | ztimer_clock_t * | clock, |
ztimer_periodic_t * | timer, | ||
int(*)(void *) | callback, | ||
void * | arg, | ||
uint32_t | interval | ||
) |
Initialize a periodic timer structure.
This sets up the underlying structure of a periodic timer. After initializing, use ztimer_periodic_start() to start the timer.
[in] | clock | the clock to configure this timer on |
[in,out] | timer | periodic timer object to initialize |
[in] | callback | function to call on each trigger |
[in] | arg | argument to pass to callback function |
[in] | interval | period length of this timer instance |
void ztimer_periodic_start | ( | ztimer_periodic_t * | timer | ) |
Start or restart a periodic timer.
When called on a newly initialized timer, the timer will start.
When called on an already running timer, the current interval is reset to its start (thus the next callback will be called after the configured interval has passed).
[in] | timer | periodic timer object to work on |
void ztimer_periodic_stop | ( | ztimer_periodic_t * | timer | ) |
Stop a periodic timer.
The periodic timer will not trigger anymore.
[in] | timer | periodic timer object to stop |