Skip to content

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.

bool syn_timer_expired (
    SYN_Timer * timer
) 

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:

  • timer Timer 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:

  • timer Timer to initialize.
  • period_ms Period in milliseconds.
  • periodic true for repeating timer, false for one-shot.
  • callback Function called on expiry (may be NULL if using polling).
  • user_data User context pointer passed to callback.

function syn_timer_next_expiry

Get the earliest expiry tick among a set of active timers.

uint32_t syn_timer_next_expiry (
    const SYN_Timer * timers,
    size_t count
) 

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:

  • timers Array of timers to scan.
  • count Number 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.

uint32_t syn_timer_remaining (
    const SYN_Timer * timer
) 

Parameters:

  • timer Timer to query.

Returns:

Remaining milliseconds, or 0 if expired/stopped.


function syn_timer_service

Service an array of timers.

void syn_timer_service (
    SYN_Timer * timers,
    size_t count
) 

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:

  • timers Array of timers.
  • count Number of timers in the array.

function syn_timer_set_period

Change the timer's period. Takes effect on next start or next periodic reload.

void syn_timer_set_period (
    SYN_Timer * timer,
    uint32_t period_ms
) 

Parameters:

  • timer Timer.
  • period_ms New period in milliseconds.

function syn_timer_start

Start (or restart) the timer.

void syn_timer_start (
    SYN_Timer * timer
) 

Sets the target tick to now + period_ms and marks the timer active.

Parameters:

  • timer Timer to start.

function syn_timer_stop

Stop the timer. It will not fire until started again.

void syn_timer_stop (
    SYN_Timer * timer
) 

Parameters:

  • timer Timer to stop.


The documentation for this class was generated from the following file src/syntropic/sched/syn_timer.c