oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
Typedefs | Functions
Software timer

Periodic and one-shot software timer API backed by the active RTOS. More...

Typedefs

typedef struct ove_timer * ove_timer_t
 Opaque handle for a software timer object.
 
typedef void(* ove_timer_fn) (ove_timer_t timer, void *user_data)
 Timer expiry callback function prototype.
 

Functions

int ove_timer_init (ove_timer_t *timer, ove_timer_storage_t *storage, ove_timer_fn callback, void *user_data, uint32_t period_ms, int one_shot)
 Initialise a software timer using caller-supplied static storage.
 
void ove_timer_deinit (ove_timer_t timer)
 Stop and release resources held by a timer initialised with ove_timer_init().
 
int ove_timer_create (ove_timer_t *timer, ove_timer_fn callback, void *user_data, uint32_t period_ms, int one_shot)
 Allocate and initialise a software timer from the heap.
 
void ove_timer_destroy (ove_timer_t timer)
 Stop and free a timer allocated with ove_timer_create().
 
int ove_timer_start (ove_timer_t timer)
 Start (arm) a timer.
 
int ove_timer_stop (ove_timer_t timer)
 Stop a running timer without invoking its callback.
 
int ove_timer_reset (ove_timer_t timer)
 Restart a timer's countdown from the beginning of its period.
 

Detailed Description

Periodic and one-shot software timer API backed by the active RTOS.

Note
All functions in this group require CONFIG_OVE_TIMER to be defined. When CONFIG_OVE_TIMER is not set, every function is replaced by a static inline stub that returns OVE_ERR_NOT_SUPPORTED.

Two allocation strategies are available:

Typedef Documentation

◆ ove_timer_fn

typedef void(* ove_timer_fn) (ove_timer_t timer, void *user_data)

Timer expiry callback function prototype.

Invoked by the RTOS timer service task (or equivalent) when the timer period elapses. Implementations must be non-blocking and short.

Parameters
[in]timerHandle of the timer that fired.
[in]user_dataOpaque pointer supplied at timer creation time.

Function Documentation

◆ ove_timer_init()

int ove_timer_init ( ove_timer_t timer,
ove_timer_storage_t *  storage,
ove_timer_fn  callback,
void *  user_data,
uint32_t  period_ms,
int  one_shot 
)

Initialise a software timer using caller-supplied static storage.

Creates a timer in the stopped state. Call ove_timer_start() to arm it.

Note
Requires CONFIG_OVE_TIMER.
Parameters
[out]timerReceives the opaque timer handle on success.
[in]storagePointer to statically allocated backend storage. Must remain valid for the lifetime of the timer.
[in]callbackFunction invoked when the timer expires. Must not be NULL.
[in]user_dataOpaque pointer forwarded to callback on each expiry. May be NULL.
[in]period_msTimer period in milliseconds. Must be > 0.
[in]one_shotNon-zero to create a one-shot timer (fires once then stops automatically); zero for a periodic timer that reloads automatically.
Returns
OVE_OK on success, or a negative error code on failure.
See also
ove_timer_deinit, ove_timer_create, ove_timer_start

◆ ove_timer_deinit()

void ove_timer_deinit ( ove_timer_t  timer)

Stop and release resources held by a timer initialised with ove_timer_init().

Stops the timer if it is running. The static storage supplied at init time is not freed.

Note
Requires CONFIG_OVE_TIMER.
Parameters
[in]timerHandle returned by ove_timer_init().
See also
ove_timer_init

◆ ove_timer_create()

int ove_timer_create ( ove_timer_t timer,
ove_timer_fn  callback,
void *  user_data,
uint32_t  period_ms,
int  one_shot 
)

Allocate and initialise a software timer from the heap.

Creates a timer in the stopped state. Call ove_timer_start() to arm it.

Note
Requires CONFIG_OVE_TIMER and OVE_HEAP_TIMER (i.e. CONFIG_OVE_ZERO_HEAP must not be set).
Parameters
[out]timerReceives the opaque timer handle on success.
[in]callbackFunction invoked when the timer expires. Must not be NULL.
[in]user_dataOpaque pointer forwarded to callback on each expiry. May be NULL.
[in]period_msTimer period in milliseconds. Must be > 0.
[in]one_shotNon-zero to create a one-shot timer; zero for a periodic auto-reloading timer.
Returns
OVE_OK on success, or a negative error code on failure.
See also
ove_timer_destroy, ove_timer_init, ove_timer_start

◆ ove_timer_destroy()

void ove_timer_destroy ( ove_timer_t  timer)

Stop and free a timer allocated with ove_timer_create().

Note
Requires CONFIG_OVE_TIMER and OVE_HEAP_TIMER.
Parameters
[in]timerHandle returned by ove_timer_create().
See also
ove_timer_create

◆ ove_timer_start()

int ove_timer_start ( ove_timer_t  timer)

Start (arm) a timer.

If the timer is already running, it is restarted from the beginning of its period. Has no effect if the timer is in a terminated state.

Note
Requires CONFIG_OVE_TIMER.
Parameters
[in]timerTimer handle to start.
Returns
OVE_OK on success, or a negative error code on failure.
See also
ove_timer_stop, ove_timer_reset

◆ ove_timer_stop()

int ove_timer_stop ( ove_timer_t  timer)

Stop a running timer without invoking its callback.

If the timer is already stopped, this function has no effect.

Note
Requires CONFIG_OVE_TIMER.
Parameters
[in]timerTimer handle to stop.
Returns
OVE_OK on success, or a negative error code on failure.
See also
ove_timer_start, ove_timer_reset

◆ ove_timer_reset()

int ove_timer_reset ( ove_timer_t  timer)

Restart a timer's countdown from the beginning of its period.

Equivalent to stopping and then starting the timer, but performed atomically with respect to the RTOS timer service. Useful for implementing watchdog-style "kick" patterns.

Note
Requires CONFIG_OVE_TIMER.
Parameters
[in]timerTimer handle to reset.
Returns
OVE_OK on success, or a negative error code on failure.
See also
ove_timer_start, ove_timer_stop