SuperTinyKernel™ RTOS 1.06.x
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
47#ifndef STK_C_TIMER_MAX
48 #define STK_C_TIMER_MAX (32U)
49#endif
50
54#ifndef STK_C_TIMER_HANDLER_STACK_SIZE
55 #define STK_C_TIMER_HANDLER_STACK_SIZE (256U)
56#endif
57
58// =============================================================================
59// Types
60// =============================================================================
61
65
68typedef struct stk_timer_t stk_timer_t;
69
78 stk_timer_t *timer,
79 void *user_data);
80
81// =============================================================================
82// TimerHost - per-core host management
83// =============================================================================
84
90stk_timerhost_t *stk_timerhost_get(uint8_t core_nr);
91
101 stk_kernel_t *kernel,
102 bool privileged);
103
110
116
121size_t stk_timerhost_get_size(const stk_timerhost_t *host);
122
128
129// =============================================================================
130// Timer lifecycle
131// =============================================================================
132
143stk_timer_t *stk_timer_create(stk_timer_callback_t callback, void *user_data);
144
151
152// =============================================================================
153// Timer control
154// =============================================================================
155
165 stk_timer_t *tmr,
166 uint32_t delay,
167 uint32_t period);
168
176
184
197 stk_timer_t *tmr,
198 uint32_t delay,
199 uint32_t period);
200
216 stk_timer_t *tmr,
217 uint32_t delay,
218 uint32_t period_ticks);
219
230 stk_timer_t *tmr,
231 uint32_t period_ticks);
232
233// =============================================================================
234// Timer query
235// =============================================================================
236
242bool stk_timer_is_active(const stk_timer_t *tmr);
243
248uint32_t stk_timer_get_period(const stk_timer_t *tmr);
249
254int64_t stk_timer_get_deadline(const stk_timer_t *tmr);
255
260int64_t stk_timer_get_timestamp(const stk_timer_t *tmr);
261
268uint32_t stk_timer_get_remaining_ticks(const stk_timer_t *tmr);
269
270// =============================================================================
271// PeriodicTrigger - lightweight in-place periodic polling helper
272// =============================================================================
273
290
293#define STK_PERIODIC_TRIGGER_IMPL_SIZE (16U)
294
301
305
317 uint32_t membuf_size,
318 uint32_t period_ticks,
319 bool started);
320
325
340
348void stk_periodic_trigger_set_period(stk_periodic_trigger_t *trig, uint32_t period_ticks);
349
357
363
365
366#ifdef __cplusplus
367}
368#endif
369
371
372#endif /* STK_C_TIME_H_ */
C language binding/interface for SuperTinyKernel RTOS.
struct stk_kernel_t stk_kernel_t
Opaque handle to a kernel instance.
Definition stk_c.h:126
uintptr_t stk_word_t
CPU register type.
Definition stk_c.h:94
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:77
bool stk_timerhost_is_empty(const stk_timerhost_t *host)
Return true when no timers are currently active on this host.
bool stk_timer_restart(stk_timerhost_t *host, stk_timer_t *tmr, uint32_t delay, uint32_t period)
Atomically stop and re-start a timer.
bool stk_timer_start(stk_timerhost_t *host, stk_timer_t *tmr, uint32_t delay, uint32_t period)
Start a timer.
bool stk_timer_set_period(stk_timerhost_t *host, stk_timer_t *tmr, uint32_t period_ticks)
Change the period of a running periodic timer without affecting the current deadline.
bool stk_timer_is_active(const stk_timer_t *tmr)
Check whether a timer is currently active (started and not yet expired/stopped).
bool stk_timer_stop(stk_timerhost_t *host, stk_timer_t *tmr)
Stop a running timer.
bool stk_timer_start_or_reset(stk_timerhost_t *host, stk_timer_t *tmr, uint32_t delay, uint32_t period_ticks)
Start the timer if inactive, or reset its deadline if already active and periodic.
stk_timer_t * stk_timer_create(stk_timer_callback_t callback, void *user_data)
Allocate a timer from the static pool.
uint32_t stk_timer_get_remaining_ticks(const stk_timer_t *tmr)
Get remaining ticks until next expiration.
int64_t stk_timer_get_timestamp(const stk_timer_t *tmr)
Get the tick count at which the timer last expired.
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.
int64_t stk_timer_get_deadline(const stk_timer_t *tmr)
Get the absolute expiration tick count of the timer's next deadline.
void stk_timer_destroy(stk_timer_t *tmr)
Return a timer handle back to the static pool.
bool stk_timerhost_shutdown(stk_timerhost_t *host)
Gracefully shut down the TimerHost.
bool stk_timer_reset(stk_timerhost_t *host, stk_timer_t *tmr)
Reset a periodic timer's deadline (re-arm from now).
uint32_t stk_timer_get_period(const stk_timer_t *tmr)
Get the timer's reload period.
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_destroy(stk_periodic_trigger_t *const trig)
Destroy instance (calls the C++ destructor in-place).
stk_periodic_trigger_t * stk_periodic_trigger_create(stk_periodic_trigger_mem_t *const membuf, uint32_t membuf_size, uint32_t period_ticks, bool started)
Construct PeriodicTrigger instance in the supplied memory buffer.
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 stk_word_t) required for PeriodicTrigger instance.
Definition stk_c_time.h:293
void stk_periodic_trigger_restart(stk_periodic_trigger_t *trig)
Reset and start the trigger from the current tick count.
bool stk_periodic_trigger_poll(stk_periodic_trigger_t *trig)
Check whether the scheduled trigger time has been reached.
void stk_periodic_trigger_set_period(stk_periodic_trigger_t *trig, uint32_t period_ticks)
Change the trigger period while preserving phase.
Opaque memory container for a stk_periodic_trigger_t instance.
Definition stk_c_time.h:298
stk_word_t data[(16U)]
Definition stk_c_time.h:299