SuperTinyKernel™ RTOS 1.05.3
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
stk_c_time.h
Go to the documentation of this file.
1/*
2 * SuperTinyKernel(TM) RTOS: Lightweight High-Performance Deterministic C++ RTOS for Embedded Systems.
3 *
4 * Source: https://github.com/SuperTinyKernel-RTOS
5 *
6 * Copyright (c) 2022-2026 Neutron Code Limited <stk@neutroncode.com>. All Rights Reserved.
7 * License: MIT License, see LICENSE for a full text.
8 */
9
10#ifndef STK_C_TIME_H_
11#define STK_C_TIME_H_
12
13#include "stk_c.h"
14
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36// ─────────────────────────────────────────────────────────────────────────────
37// Configuration macros
38// ─────────────────────────────────────────────────────────────────────────────
39
44#ifndef STK_C_TIMER_MAX
45 #define STK_C_TIMER_MAX 32
46#endif
47
51#ifndef STK_C_TIMER_HANDLER_STACK_SIZE
52 #define STK_C_TIMER_HANDLER_STACK_SIZE 256
53#endif
54
55// ─────────────────────────────────────────────────────────────────────────────
56// Types
57// ─────────────────────────────────────────────────────────────────────────────
58
62
65typedef struct stk_timer_t stk_timer_t;
66
75 stk_timer_t *timer,
76 void *user_data);
77
78// ─────────────────────────────────────────────────────────────────────────────
79// TimerHost — per-core host management
80// ─────────────────────────────────────────────────────────────────────────────
81
87stk_timerhost_t *stk_timerhost_get(uint8_t core_nr);
88
98 stk_kernel_t *kernel,
99 bool privileged);
100
107
113
118size_t stk_timerhost_get_size(const stk_timerhost_t *host);
119
125
126// ─────────────────────────────────────────────────────────────────────────────
127// Timer lifecycle
128// ─────────────────────────────────────────────────────────────────────────────
129
137stk_timer_t *stk_timer_create(stk_timer_callback_t callback, void *user_data);
138
144void stk_timer_destroy(stk_timer_t *timer);
145
146// ─────────────────────────────────────────────────────────────────────────────
147// Timer control
148// ─────────────────────────────────────────────────────────────────────────────
149
159 stk_timer_t *timer,
160 uint32_t delay,
161 uint32_t period);
162
169bool stk_timer_stop(stk_timerhost_t *host, stk_timer_t *timer);
170
178
191 stk_timer_t *timer,
192 uint32_t delay,
193 uint32_t period);
194
210 stk_timer_t *timer,
211 uint32_t delay,
212 uint32_t period);
213
224 stk_timer_t *timer,
225 uint32_t period);
226
227// ─────────────────────────────────────────────────────────────────────────────
228// Timer query
229// ─────────────────────────────────────────────────────────────────────────────
230
236bool stk_timer_is_active(const stk_timer_t *timer);
237
242uint32_t stk_timer_get_period(const stk_timer_t *timer);
243
248int64_t stk_timer_get_deadline(const stk_timer_t *timer);
249
254int64_t stk_timer_get_timestamp(const stk_timer_t *timer);
255
262uint32_t stk_timer_get_remaining_time(const stk_timer_t *timer);
263
264// ─────────────────────────────────────────────────────────────────────────────
265// PeriodicTrigger — lightweight in-place periodic polling helper
266// ─────────────────────────────────────────────────────────────────────────────
267
284
287#define STK_PERIODIC_TRIGGER_IMPL_SIZE 16
288
295
299
311 uint32_t memory_size,
312 uint32_t period,
313 bool started);
314
319
334
343
351
357
359
360#ifdef __cplusplus
361}
362#endif
363
365
366#endif /* STK_C_TIME_H_ */
C language binding/interface for SuperTinyKernel (STK).
struct stk_kernel_t stk_kernel_t
Opaque handle to a kernel instance.
Definition stk_c.h:91
void(* stk_timer_callback_t)(stk_timerhost_t *host, stk_timer_t *timer, void *user_data)
Timer expiration callback invoked from within the TimerHost handler task.
Definition stk_c_time.h:74
bool stk_timer_stop(stk_timerhost_t *host, stk_timer_t *timer)
Stop a running timer.
uint32_t stk_timer_get_period(const stk_timer_t *timer)
Get the timer's reload period.
bool stk_timer_start_or_reset(stk_timerhost_t *host, stk_timer_t *timer, uint32_t delay, uint32_t period)
Start the timer if inactive, or reset its deadline if already active and periodic.
bool stk_timerhost_is_empty(const stk_timerhost_t *host)
Return true when no timers are currently active on this host.
bool stk_timer_reset(stk_timerhost_t *host, stk_timer_t *timer)
Reset a periodic timer's deadline (re-arm from now).
bool stk_timer_set_period(stk_timerhost_t *host, stk_timer_t *timer, uint32_t period)
Change the period of a running periodic timer without affecting the current deadline.
stk_timer_t * stk_timer_create(stk_timer_callback_t callback, void *user_data)
Allocate a timer from the static pool.
int64_t stk_timer_get_timestamp(const stk_timer_t *timer)
Get the tick count at which the timer last expired.
bool stk_timer_restart(stk_timerhost_t *host, stk_timer_t *timer, uint32_t delay, uint32_t period)
Atomically stop and re-start a timer.
bool stk_timer_start(stk_timerhost_t *host, stk_timer_t *timer, uint32_t delay, uint32_t period)
Start a timer.
void stk_timerhost_init(stk_timerhost_t *host, stk_kernel_t *kernel, bool privileged)
Initialize the TimerHost and register its internal tasks with the kernel.
size_t stk_timerhost_get_size(const stk_timerhost_t *host)
Return the number of currently active timers on this host.
bool stk_timer_is_active(const stk_timer_t *timer)
Check whether a timer is currently active (started and not yet expired/stopped).
bool stk_timerhost_shutdown(stk_timerhost_t *host)
Gracefully shut down the TimerHost.
int64_t stk_timer_get_deadline(const stk_timer_t *timer)
Get the absolute expiration tick count of the timer's next deadline.
uint32_t stk_timer_get_remaining_time(const stk_timer_t *timer)
Get remaining ticks until next expiration.
void stk_timer_destroy(stk_timer_t *timer)
Return a timer handle back to the static pool.
stk_timerhost_t * stk_timerhost_get(uint8_t core_nr)
Obtain the pre-allocated TimerHost for the given CPU core.
int64_t stk_timerhost_get_time_now(const stk_timerhost_t *host)
Return the last tick count snapshot maintained by the host's tick task.
void stk_periodic_trigger_set_period(stk_periodic_trigger_t *trig, uint32_t period)
Change the trigger period while preserving phase.
uint32_t stk_periodic_trigger_get_period(const stk_periodic_trigger_t *trig)
Get currently configured trigger period.
#define STK_PERIODIC_TRIGGER_IMPL_SIZE
A memory size (multiples of size_t) required for PeriodicTrigger instance.
Definition stk_c_time.h:287
void stk_periodic_trigger_restart(stk_periodic_trigger_t *trig)
Reset and start the trigger from the current tick count.
stk_periodic_trigger_t * stk_periodic_trigger_create(stk_periodic_trigger_mem_t *memory, uint32_t memory_size, uint32_t period, bool started)
Construct PeriodicTrigger instance in the supplied memory buffer.
void stk_periodic_trigger_destroy(stk_periodic_trigger_t *trig)
Destroy instance (calls the C++ destructor in-place).
bool stk_periodic_trigger_poll(stk_periodic_trigger_t *trig)
Check whether the scheduled trigger time has been reached.
Opaque memory container for a stk_periodic_trigger_t instance.
Definition stk_c_time.h:292