12#include <stk_config.h>
17#define STK_C_TIMERS_TOTAL (STK_C_TIMER_MAX * STK_C_CPU_COUNT)
20#undef STK_TIMER_COUNT_MAX
21#define STK_TIMER_COUNT_MAX (STK_C_TIMER_MAX)
23#undef STK_TIMER_HANDLER_STACK_SIZE
24#define STK_TIMER_HANDLER_STACK_SIZE (STK_C_TIMER_HANDLER_STACK_SIZE)
27inline void *
operator new(std::size_t,
void *ptr)
noexcept {
return ptr; }
28inline void operator delete(
void *,
void *)
noexcept { }
189 s_Timers[i].timer.handle.Initialize(callback, user_data);
341 uint32_t memory_size,
356 trig->~stk_periodic_trigger_t();
Top-level STK include. Provides the Kernel class template and all built-in task-switching strategies.
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Implementation of stk::time::TimerHost, a software timer multiplexer that manages multiple stk::time:...
Time-related utilities: stk::time::PeriodicTrigger.
C language binding/interface for SuperTinyKernel (STK).
C language binding for stk::time::TimerHost and stk::time::TimerHost::Timer.
static stk_timerhost_t s_TimerHosts[(1)]
#define STK_C_TIMERS_TOTAL
static struct TimerSlot s_Timers[(32 *(1))]
struct stk_kernel_t stk_kernel_t
Opaque handle to a kernel instance.
#define STK_C_CPU_COUNT
Number of kernel instances / CPU cores supported (default: 1).
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.
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.
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.
Namespace of STK package.
int64_t Ticks
Ticks value.
@ ACCESS_USER
Unprivileged access mode (access to some hardware is restricted, see CPU manual for details).
@ ACCESS_PRIVILEGED
Privileged access mode (access to hardware is fully unrestricted).
Interface for the implementation of the kernel of the scheduler. It supports Soft and Hard Real-Time ...
RAII-style low-level synchronization primitive for atomic code execution. Used as building brick for ...
Software timer multiplexer that manages multiple Timer instances on top of a small fixed set of kerne...
bool Reset(Timer &timer)
Reset periodic timer's deadline.
bool SetPeriod(Timer &timer, uint32_t period)
Change the period of a running periodic timer without affecting its current deadline.
void Initialize(IKernel *kernel, EAccessMode mode)
Initialize timer host instance.
bool IsEmpty() const
Return true if no timers are currently active.
Ticks GetTimeNow() const
Get current time.
size_t GetSize() const
Return number of currently active timers.
bool Shutdown()
Shutdown host instance. All timers are stopped and removed from the host.
bool Restart(Timer &timer, uint32_t delay, uint32_t period=0)
Atomically stop and re-start timer.
bool StartOrReset(Timer &timer, uint32_t delay, uint32_t period=0)
Start timer if inactive, or reset its deadline if already active and periodic.
bool Stop(Timer &timer)
Stop running timer.
bool Start(Timer &timer, uint32_t delay, uint32_t period=0)
Start timer.
Abstract base class for a timer managed by TimerHost.
Ticks GetDeadline() const
uint32_t GetRemainingTime() const
Get remaining ticks until the timer next expires.
uint32_t GetPeriod() const
Ticks GetTimestamp() const
Lightweight periodic trigger: returns true once per configured period when polled.
uint32_t GetPeriod() const
Get currently configured trigger period.
void Restart()
Reset the trigger and start.
void SetPeriod(uint32_t period)
Change the trigger period while preserving phase.
bool Poll()
Check whether the scheduled trigger time has been reached.
Opaque memory container for a stk_periodic_trigger_t instance.
void Initialize(stk_timer_callback_t callback, void *user_data)
stk_timerhost_t * m_host_handle
C-level host, forwarded to the callback.
stk_timer_callback_t GetCallback() const
stk_timer_callback_t m_callback
stk_timerhost_t * GetHostHandle() const
void * GetUserData() const
void SetHostHandle(stk_timerhost_t *host_handle)
void OnExpired(TimerHost *)
time::PeriodicTrigger handle