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 Service

One-shot and periodic timers with millisecond resolution (ADR-001). More...

Files

file  src/oal/timer/rte_timer.c
 Timer service: validates parameters, then dispatches to the OSAdapter registered via rte_osadapter_timer_register() (ADR-005).

Data Structures

struct  rte_timer_config_t
 Configuration for rte_timer_create(). More...

Typedefs

typedef struct rte_timer_impl_s * rte_timer_handle_t
typedef void(*) rte_timer_callback_t(rte_timer_handle_t handle, void *user_ctx)
 Signature for a timer expiry callback.

Enumerations

enum  rte_timer_mode_t { RTE_TIMER_MODE_ONE_SHOT = 0 , RTE_TIMER_MODE_PERIODIC = 1 }
 Whether a timer fires once or repeatedly every period_ms. More...

Functions

 RTE_DECLARE_STORAGE (rte_timer_storage_t, 64U)
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.
rte_status_t rte_timer_start (rte_timer_handle_t handle)
 Starts (or restarts) a created timer.
rte_status_t rte_timer_stop (rte_timer_handle_t handle)
 Stops a running timer; safe to call on an already-stopped timer.
rte_status_t rte_timer_destroy (rte_timer_handle_t handle)
 Destroys a timer, releasing any OSAdapter resources bound to it.
rte_status_t rte_timer_now (rte_timestamp_ms_t *out_now_ms)
 Returns the current monotonic time base used by all timers.

Detailed Description

One-shot and periodic timers with millisecond resolution (ADR-001).

Typedef Documentation

◆ rte_timer_handle_t

typedef struct rte_timer_impl_s* rte_timer_handle_t

Opaque handle bound to a rte_timer_storage_t after rte_timer_create().

Definition at line 31 of file rte_timer.h.

◆ rte_timer_callback_t

typedef void(*) rte_timer_callback_t(rte_timer_handle_t handle, void *user_ctx)

Signature for a timer expiry callback.

Parameters
handleThe timer that expired.
user_ctxOpaque context pointer supplied at creation time.

REQ-OAL-TIMER-003: the callback executes in a bounded-time, non-blocking context (exact context - task/ISR - is osadapter-defined and documented by the OSAdapter implementation).

Definition at line 49 of file rte_timer.h.

Enumeration Type Documentation

◆ rte_timer_mode_t

Whether a timer fires once or repeatedly every period_ms.

Enumerator
RTE_TIMER_MODE_ONE_SHOT 

Fires once after period_ms, then stops.

RTE_TIMER_MODE_PERIODIC 

Fires every period_ms until stopped.

Definition at line 34 of file rte_timer.h.

Function Documentation

◆ RTE_DECLARE_STORAGE()

RTE_DECLARE_STORAGE ( rte_timer_storage_t ,
64U  )

Opaque caller-owned storage for one timer instance. Size is part of the ABI.

◆ rte_timer_create()

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.

Parameters
storageCaller-owned storage the timer's state is placed into. Must not be NULL and must outlive the timer.
configTimer configuration. Must not be NULL; config->callback must not be NULL and config->period_ms must be > 0.
out_handleReceives the created timer's handle. Must not be NULL.
Returns
RTE_STATUS_OK; RTE_STATUS_INVALID_PARAM for a bad argument; RTE_STATUS_NOT_INITIALIZED if no OSAdapter is registered (rte_osadapter_timer_register()); RTE_STATUS_NOT_SUPPORTED if the registered OSAdapter does not implement create. REQ-OAL-TIMER-010

Definition at line 44 of file rte_timer.c.

◆ rte_timer_start()

rte_status_t rte_timer_start ( rte_timer_handle_t handle)

Starts (or restarts) a created timer.

Parameters
handleTimer to start. Must not be NULL.
Returns
RTE_STATUS_OK, RTE_STATUS_INVALID_PARAM, RTE_STATUS_NOT_INITIALIZED, or RTE_STATUS_NOT_SUPPORTED (see rte_timer_create()). REQ-OAL-TIMER-011

Definition at line 79 of file rte_timer.c.

◆ rte_timer_stop()

rte_status_t rte_timer_stop ( rte_timer_handle_t handle)

Stops a running timer; safe to call on an already-stopped timer.

Parameters
handleTimer to stop. Must not be NULL.
Returns
See rte_timer_start(). REQ-OAL-TIMER-012

Definition at line 105 of file rte_timer.c.

◆ rte_timer_destroy()

rte_status_t rte_timer_destroy ( rte_timer_handle_t handle)

Destroys a timer, releasing any OSAdapter resources bound to it.

Parameters
handleTimer to destroy. Must not be NULL. Invalid to use after this call.
Returns
See rte_timer_start(). REQ-OAL-TIMER-013

Definition at line 122 of file rte_timer.c.

◆ rte_timer_now()

rte_status_t rte_timer_now ( rte_timestamp_ms_t * out_now_ms)

Returns the current monotonic time base used by all timers.

Parameters
out_now_msReceives the current time in milliseconds. Must not be NULL; set to 0 if this call fails.
Returns
RTE_STATUS_OK, RTE_STATUS_INVALID_PARAM, RTE_STATUS_NOT_INITIALIZED, or RTE_STATUS_NOT_SUPPORTED (see rte_timer_create()). REQ-OAL-TIMER-014

Definition at line 139 of file rte_timer.c.