Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
sapi_timer.c
Go to the documentation of this file.
1
10
12
14
17static const sapi_timer_backend_t *s_backend = NULL;
18
20
22
23
26{
27 sapi_status_t lifecycle_status;
28
29 if (backend == NULL)
30 {
32 }
33 /* REQ-LIFECYCLE-001 (ADR-026): registering a backend is a setup-only
34 * action - refuse once the application's setup phase has been locked. */
35 lifecycle_status = sapi_lifecycle_check_setup_allowed();
36 if (lifecycle_status != SAPI_STATUS_OK)
37 {
38 return lifecycle_status;
39 }
40 s_backend = backend;
41 return SAPI_STATUS_OK;
42}
43
44sapi_status_t sapi_timer_create(sapi_timer_storage_t *storage,
45 const sapi_timer_config_t *config,
46 sapi_timer_handle_t *out_handle)
47{
48 if ((storage == NULL) || (config == NULL) || (out_handle == NULL))
49 {
51 }
52 if ((config->callback == NULL) || (config->period_ms == 0U))
53 {
55 }
56 *out_handle = NULL;
57 /* REQ-LIFECYCLE-001 (ADR-026): a timer is a setup-only resource - refuse once the
58 * application's setup phase has been locked (sapi_appmanager_run(),
59 * after ops->init() succeeds). */
60 {
62
63 if (lifecycle_status != SAPI_STATUS_OK)
64 {
65 return lifecycle_status;
66 }
67 }
68 if (s_backend == NULL)
69 {
71 }
72 if (s_backend->create == NULL)
73 {
75 }
76 return s_backend->create(storage, config, out_handle);
77}
78
80{
81 if (handle == NULL)
82 {
84 }
85 if (s_backend == NULL)
86 {
88 }
89 if (s_backend->start == NULL)
90 {
92 }
93 return s_backend->start(handle);
94}
95
97{
98 if (handle == NULL)
99 {
101 }
102 if (s_backend == NULL)
103 {
105 }
106 if (s_backend->stop == NULL)
107 {
109 }
110 return s_backend->stop(handle);
111}
112
114{
115 if (handle == NULL)
116 {
118 }
119 if (s_backend == NULL)
120 {
122 }
123 if (s_backend->destroy == NULL)
124 {
126 }
127 return s_backend->destroy(handle);
128}
129
131{
132 if (out_now_ms == NULL)
133 {
135 }
136 *out_now_ms = 0U;
137 if (s_backend == NULL)
138 {
140 }
141 if (s_backend->now == NULL)
142 {
144 }
145 return s_backend->now(out_now_ms);
146}
sapi_status_t sapi_lifecycle_check_setup_allowed(void)
Convenience check for a setup-only constructor: call this as one of the first checks in any function ...
sapi_status_t
Common result/status codes.
Definition sapi_status.h:27
@ SAPI_STATUS_NOT_SUPPORTED
Definition sapi_status.h:34
@ SAPI_STATUS_INVALID_PARAM
Definition sapi_status.h:29
@ SAPI_STATUS_NOT_INITIALIZED
Definition sapi_status.h:30
@ SAPI_STATUS_OK
Definition sapi_status.h:28
sapi_status_t sapi_timer_register_backend(const sapi_timer_backend_t *backend)
Registers the backend implementation used by every sapi_timer_* call. This is how an integrator suppl...
Definition sapi_timer.c:25
sapi_status_t sapi_timer_start(sapi_timer_handle_t handle)
Starts (or restarts) a created timer.
Definition sapi_timer.c:79
sapi_status_t sapi_timer_stop(sapi_timer_handle_t handle)
Stops a running timer; safe to call on an already-stopped timer.
Definition sapi_timer.c:96
sapi_status_t sapi_timer_destroy(sapi_timer_handle_t handle)
Destroys a timer, releasing any backend resources bound to it.
Definition sapi_timer.c:113
struct sapi_timer_impl_s * sapi_timer_handle_t
Definition sapi_timer.h:31
sapi_status_t sapi_timer_now(sapi_timestamp_ms_t *out_now_ms)
Returns the current monotonic time base used by all timers.
Definition sapi_timer.c:130
sapi_status_t sapi_timer_create(sapi_timer_storage_t *storage, const sapi_timer_config_t *config, sapi_timer_handle_t *out_handle)
Creates a timer bound to caller-owned storage. Does not start it.
Definition sapi_timer.c:44
uint64_t sapi_timestamp_ms_t
Definition sapi_types.h:30
static const sapi_clocksync_backend_t * s_backend
Process-wide application setup-phase lock (ADR-026).
OS Abstraction Layer - Timer service.
OS-backend adaptation surface for the Timer service (ADR-005, ADR-021).
Backend vtable: an integrator's implementation of the timer service for a specific OS/RTOS/BSP target...
sapi_status_t(*) destroy(sapi_timer_handle_t handle)
Backend implementation of sapi_timer_destroy(). May be NULL.
sapi_status_t(*) stop(sapi_timer_handle_t handle)
Backend implementation of sapi_timer_stop(). May be NULL.
sapi_status_t(*) now(sapi_timestamp_ms_t *out_now_ms)
Backend implementation of sapi_timer_now(). May be NULL.
sapi_status_t(*) start(sapi_timer_handle_t handle)
Backend implementation of sapi_timer_start(). May be NULL.
sapi_status_t(*) create(sapi_timer_storage_t *storage, const sapi_timer_config_t *config, sapi_timer_handle_t *out_handle)
Backend implementation of sapi_timer_create(). May be NULL.
Configuration for sapi_timer_create().
Definition sapi_timer.h:53
sapi_timer_callback_t callback
Definition sapi_timer.h:56
sapi_duration_ms_t period_ms
Definition sapi_timer.h:55