oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
timer.h
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,
77 ove_timer_fn callback, void *user_data,
78 uint32_t period_ms, int one_shot);
79
94
95/* _create / _destroy — heap-gated */
96#ifdef OVE_HEAP_TIMER
97
119 void *user_data, uint32_t period_ms, int one_shot);
120
131
132#elif !defined(__ZIG_CIMPORT__) /* !OVE_HEAP_TIMER — zero-heap mode */
133
134#define ove_timer_create(ptimer, callback, user_data, period_ms, one_shot) \
135 ({ static ove_timer_storage_t _ove_stor_; \
136 ove_timer_init((ptimer), &_ove_stor_, (callback), (user_data), \
137 (period_ms), (one_shot)); })
138#define ove_timer_destroy(timer) ove_timer_deinit(timer)
139
140#endif /* OVE_HEAP_TIMER */
141
156
170
186
187#else /* !CONFIG_OVE_TIMER */
188
189static inline int ove_timer_create(ove_timer_t *t, ove_timer_fn cb, void *ud, uint32_t p, int os) { (void)t; (void)cb; (void)ud; (void)p; (void)os; return OVE_ERR_NOT_SUPPORTED; }
190static inline void ove_timer_destroy(ove_timer_t t) { (void)t; }
191static inline int ove_timer_start(ove_timer_t t) { (void)t; return OVE_ERR_NOT_SUPPORTED; }
192static inline int ove_timer_stop(ove_timer_t t) { (void)t; return OVE_ERR_NOT_SUPPORTED; }
193static inline int ove_timer_reset(ove_timer_t t) { (void)t; return OVE_ERR_NOT_SUPPORTED; }
194
195#endif /* CONFIG_OVE_TIMER */
196
197#ifdef __cplusplus
198}
199#endif
200
201#endif /* OVE_TIMER_H */
202
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_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().
#define OVE_ERR_NOT_SUPPORTED
The requested feature is not supported by the active backend.
Definition types.h:38