File syn_timer.c¶
FileList > sched > syn_timer.c
Go to the source code of this file
Software timer implementation.
#include "../port/syn_port_system.h"#include "../util/syn_assert.h"#include "syn_timer.h"
Public Functions¶
| Type | Name |
|---|---|
| bool | syn_timer_expired (SYN_Timer * timer) Poll whether the timer has expired. |
| void | syn_timer_init (SYN_Timer * timer, uint32_t period_ms, bool periodic, SYN_TimerCallback callback, void * user_data) Initialize a software timer. |
| uint32_t | syn_timer_next_expiry (const SYN_Timer * timers, size_t count) Get the earliest expiry tick among a set of active timers. |
| uint32_t | syn_timer_remaining (const SYN_Timer * timer) Get the remaining time until the next expiry. |
| void | syn_timer_service (SYN_Timer * timers, size_t count) Service an array of timers. |
| void | syn_timer_set_period (SYN_Timer * timer, uint32_t period_ms) Change the timer's period. Takes effect on next start or next periodic reload. |
| void | syn_timer_start (SYN_Timer * timer) Start (or restart) the timer. |
| void | syn_timer_stop (SYN_Timer * timer) Stop the timer. It will not fire until started again. |
Public Functions Documentation¶
function syn_timer_expired¶
Poll whether the timer has expired.
If expired and periodic, the timer is automatically re-armed. If expired and one-shot, the timer is stopped.
This can be used instead of (or in addition to) the callback.
Parameters:
timerTimer to check.
Returns:
true if the timer has expired since the last check.
function syn_timer_init¶
Initialize a software timer.
void syn_timer_init (
SYN_Timer * timer,
uint32_t period_ms,
bool periodic,
SYN_TimerCallback callback,
void * user_data
)
The timer is created in the stopped state. Call syn_timer_start() to begin counting.
Parameters:
timerTimer to initialize.period_msPeriod in milliseconds.periodictrue for repeating timer, false for one-shot.callbackFunction called on expiry (may be NULL if using polling).user_dataUser context pointer passed to callback.
function syn_timer_next_expiry¶
Get the earliest expiry tick among a set of active timers.
Scans the timer array and returns the minimum target_tick of any active timer whose deadline is in the future. Used by the tickless scheduler to account for software timer wakeups.
Parameters:
timersArray of timers to scan.countNumber of timers in the array.
Returns:
Earliest expiry tick, or UINT32_MAX if no timers are active or all have already expired.
function syn_timer_remaining¶
Get the remaining time until the next expiry.
Parameters:
timerTimer to query.
Returns:
Remaining milliseconds, or 0 if expired/stopped.
function syn_timer_service¶
Service an array of timers.
Checks each timer for expiry and calls its callback if set. Call this from your main loop, a scheduler task, or a periodic ISR.
Parameters:
timersArray of timers.countNumber of timers in the array.
function syn_timer_set_period¶
Change the timer's period. Takes effect on next start or next periodic reload.
Parameters:
timerTimer.period_msNew period in milliseconds.
function syn_timer_start¶
Start (or restart) the timer.
Sets the target tick to now + period_ms and marks the timer active.
Parameters:
timerTimer to start.
function syn_timer_stop¶
Stop the timer. It will not fire until started again.
Parameters:
timerTimer to stop.
The documentation for this class was generated from the following file src/syntropic/sched/syn_timer.c