Safe API Framework 0.1.0 build 384e6ae
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
Timer Module - Architecture

Design Overview

Timer provides one-shot or periodic callbacks with millisecond resolution. Caller provides storage; framework manages state. Callbacks fired by system tick (typically 1ms from monotonic clock).

Core API

rte_timer_create(storage, config, out_handle) // Create timer
rte_timer_start(handle) // Start countdown
rte_timer_stop(handle) // Stop countdown
rte_timer_destroy(handle) // Release
rte_timer_now_ms(out_now_ms) // Get current time
rte_status_t rte_timer_stop(rte_timer_handle_t handle)
Stops a running timer; safe to call on an already-stopped timer.
Definition rte_timer.c:105
rte_status_t rte_timer_start(rte_timer_handle_t handle)
Starts (or restarts) a created timer.
Definition rte_timer.c:79
rte_status_t rte_timer_create(rte_timer_storage_t *storage, const rte_timer_config_t *config, rte_timer_handle_t *out_handle)
Creates a timer bound to caller-owned storage. Does not start it.
Definition rte_timer.c:44
rte_status_t rte_timer_destroy(rte_timer_handle_t handle)
Destroys a timer, releasing any OSAdapter resources bound to it.
Definition rte_timer.c:122

Configuration

typedef struct {
rte_timer_mode_t mode; // ONE_SHOT or PERIODIC
rte_duration_ms_t period_ms; // Period/delay in ms
rte_timer_callback_t callback;// Called on expiry
void *user_ctx; // Passed to callback
rte_timer_mode_t
Whether a timer fires once or repeatedly every period_ms.
Definition rte_timer.h:35
void(*) rte_timer_callback_t(rte_timer_handle_t handle, void *user_ctx)
Signature for a timer expiry callback.
Definition rte_timer.h:49
uint32_t rte_duration_ms_t
Definition rte_types.h:27
Configuration for rte_timer_create().
Definition rte_timer.h:53

Storage Model

Caller provides 64-byte storage via rte_timer_storage_t. Framework uses for internal state. Caller keeps valid for timer lifetime.

Callback Signature

typedef void (*rte_timer_callback_t)(
void *user_ctx
);
struct rte_timer_impl_s * rte_timer_handle_t
Definition rte_timer.h:31

Called when timer expires. Runs in callback context (may be ISR on some OSAdapters). Keep execution time minimal.

Timer Tick System

Framework needs monotonic clock with ~1ms resolution. OSAdapter provides. Every tick, all active timers decrement countdown. On zero, callback fires.

O(1) Per Timer

Operation Time
create() O(1)
start() O(1)
stop() O(1)
destroy() O(1)
tick() O(n) [n = active timers]

Tick is only O(n) operation; typically called once per millisecond.

Constraints

Min period      - 1ms (timer resolution)
Max period      - 2^32 - 1 ms (~49 days)
Storage size    - 64 bytes
Callback time   - Caller's responsibility to bound

See Also