oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
timer.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Kamil Lulko <kamil.lulko@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 *
6 * This file is part of oveRTOS.
7 */
8
26#ifndef OVE_TIMER_H
27#define OVE_TIMER_H
28
29#include "ove/types.h"
30#include "ove_config.h"
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
37typedef struct ove_timer *ove_timer_t;
38
48typedef void (*ove_timer_fn)(ove_timer_t timer, void *user_data);
49
50#include "ove/storage.h"
51
52#ifdef CONFIG_OVE_TIMER
53
76int ove_timer_init(ove_timer_t *timer, ove_timer_storage_t *storage, ove_timer_fn callback,
77 void *user_data, uint32_t period_ms, int one_shot);
78
93
124int ove_timer_init_ns(ove_timer_t *timer, ove_timer_storage_t *storage, ove_timer_fn callback,
125 void *user_data, uint64_t period_ns, int one_shot);
126
152int ove_timer_set_period_ns(ove_timer_t timer, uint64_t period_ns);
153
154/* _create / _destroy — heap-gated */
155#ifdef OVE_HEAP_TIMER
156
177int ove_timer_create(ove_timer_t *timer, ove_timer_fn callback, void *user_data, uint32_t period_ms,
178 int one_shot);
179
200int ove_timer_create_ns(ove_timer_t *timer, ove_timer_fn callback, void *user_data,
201 uint64_t period_ns, int one_shot);
202
213
214#endif /* OVE_HEAP_TIMER */
215
230
244
260
261#else /* !CONFIG_OVE_TIMER */
262
263/* P0-3: _init/_deinit stubs so OVE_TIMER_DEFINE_STATIC links cleanly when
264 * CONFIG_OVE_TIMER=n. */
265static inline int ove_timer_init(ove_timer_t *t, ove_timer_storage_t *s, ove_timer_fn cb, void *ud,
266 uint32_t p, int os)
267{
268 (void)t;
269 (void)s;
270 (void)cb;
271 (void)ud;
272 (void)p;
273 (void)os;
275}
276static inline void ove_timer_deinit(ove_timer_t t)
277{
278 (void)t;
279}
280
281static inline int ove_timer_create(ove_timer_t *t, ove_timer_fn cb, void *ud, uint32_t p, int os)
282{
283 (void)t;
284 (void)cb;
285 (void)ud;
286 (void)p;
287 (void)os;
289}
290static inline int ove_timer_init_ns(ove_timer_t *t, ove_timer_storage_t *s, ove_timer_fn cb,
291 void *ud, uint64_t p, int os)
292{
293 (void)t;
294 (void)s;
295 (void)cb;
296 (void)ud;
297 (void)p;
298 (void)os;
300}
301static inline int ove_timer_create_ns(ove_timer_t *t, ove_timer_fn cb, void *ud, uint64_t p, int os)
302{
303 (void)t;
304 (void)cb;
305 (void)ud;
306 (void)p;
307 (void)os;
309}
310static inline int ove_timer_set_period_ns(ove_timer_t t, uint64_t p)
311{
312 (void)t;
313 (void)p;
315}
316static inline void ove_timer_destroy(ove_timer_t t)
317{
318 (void)t;
319}
320static inline int ove_timer_start(ove_timer_t t)
321{
322 (void)t;
324}
325static inline int ove_timer_stop(ove_timer_t t)
326{
327 (void)t;
329}
330static inline int ove_timer_reset(ove_timer_t t)
331{
332 (void)t;
334}
335
336#endif /* CONFIG_OVE_TIMER */
337
338#ifdef __cplusplus
339}
340#endif
341
342#endif /* OVE_TIMER_H */
343
int ove_timer_start(ove_timer_t timer)
Start (arm) a timer.
void ove_timer_deinit(ove_timer_t timer)
Stop and release resources held by a timer initialised with ove_timer_init().
int ove_timer_stop(ove_timer_t timer)
Stop a running timer without invoking its callback.
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.
int ove_timer_create_ns(ove_timer_t *timer, ove_timer_fn callback, void *user_data, uint64_t period_ns, int one_shot)
Allocate and initialise a software timer with a nanosecond period from the heap.
int ove_timer_set_period_ns(ove_timer_t timer, uint64_t period_ns)
Change the period of an existing timer and (re)arm it.
int ove_timer_init_ns(ove_timer_t *timer, ove_timer_storage_t *storage, ove_timer_fn callback, void *user_data, uint64_t period_ns, int one_shot)
Initialise a software timer with a nanosecond period using caller-supplied static storage.
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_fn)(ove_timer_t timer, void *user_data)
Timer expiry callback function prototype.
Definition timer.h:48
int ove_timer_reset(ove_timer_t timer)
Restart a timer's countdown from the beginning of its period.
struct ove_timer * ove_timer_t
Opaque handle for a software timer object.
Definition timer.h:37
void ove_timer_destroy(ove_timer_t timer)
Stop and free a timer allocated with ove_timer_create().
@ OVE_ERR_NOT_SUPPORTED
Definition types.h:98