18#define STK_C_TIMERS_TOTAL (STK_C_TIMER_MAX * STK_C_CPU_COUNT)
21#undef STK_TIMER_COUNT_MAX
22#define STK_TIMER_COUNT_MAX (STK_C_TIMER_MAX)
24#undef STK_TIMER_HANDLER_STACK_SIZE
25#define STK_TIMER_HANDLER_STACK_SIZE (STK_C_TIMER_HANDLER_STACK_SIZE)
82 return reinterpret_cast<stk_timer_t *
>(
reinterpret_cast<void *
>(t));
209 s_Timers[i].timer.handle.Initialize(callback, user_data);
365 uint32_t membuf_size,
366 uint32_t period_ticks,
385 trig->~stk_periodic_trigger_t();
Collection of memory-related primitives (stk::memory namespace).
Top-level STK include. Provides the Kernel class template and all built-in task-switching strategies.
#define STK_UNUSED(X)
Explicitly marks a variable as unused to suppress compiler warnings.
#define __stk_forceinline
Forces compiler to always inline the decorated function, regardless of optimisation level.
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Collection of time-related primitives (stk::time namespace).
C language binding/interface for SuperTinyKernel RTOS.
C language binding for stk::time::TimerHost and stk::time::TimerHost::Timer.
static stk_timerhost_t s_TimerHosts[STK_C_CPU_COUNT]
#define STK_C_TIMERS_TOTAL
static __stk_forceinline stk_timer_t * CastCppTimerWrapperToC(CTimerWrapper *const t)
static struct TimerSlot s_Timers[(STK_C_TIMER_MAX *STK_C_CPU_COUNT)]
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_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.
void stk_periodic_trigger_restart(stk_periodic_trigger_t *trig)
Reset and start the trigger from the current tick count.
struct stk_periodic_trigger_t stk_periodic_trigger_t
Opaque handle to a stk::time::PeriodicTrigger instance.
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.
Namespace of STK package.
EAccessMode
Hardware access mode by the user task.
@ 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).
void InitializeTimerHost(stk_kernel_t *kernel, stk::time::TimerHost *th, EAccessMode amode)
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 SetPeriod(Timer &tmr, uint32_t period)
Change the period of a running periodic timer without affecting its current deadline.
bool IsEmpty() const
Return true if no timers are currently active.
bool Stop(Timer &tmr)
Stop running timer.
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 &tmr, uint32_t delay, uint32_t period=0)
Atomically stop and re-start timer.
bool StartOrReset(Timer &tmr, uint32_t delay, uint32_t period=0)
Start timer if inactive, or reset its deadline if already active and periodic.
bool Reset(Timer &tmr)
Reset periodic timer's deadline.
bool Start(Timer &tmr, uint32_t delay, uint32_t period=0)
Start timer.
Abstract base class for a timer managed by TimerHost.
Ticks GetDeadline() const
Get the absolute time in ticks at which the timer will expire.
uint32_t GetRemainingTicks() const
Get remaining ticks until the timer next expires.
bool IsActive() const
Check whether the timer is currently active.
uint32_t GetPeriod() const
Get the reload period of the timer.
Ticks GetTimestamp() const
Get the tick count at which the timer last expired.
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 const callback, void *user_data)
stk_timerhost_t * m_host_handle
C-level host, forwarded to the callback.
stk_timer_callback_t m_callback
void OnExpired(TimerHost *host) override
Callback invoked by the handler task when this timer expires.
stk_timerhost_t * GetHostHandle()
void SetHostHandle(stk_timerhost_t *host_handle)
stk_timer_callback_t GetCallback()
stk_periodic_trigger_t(uint32_t period, bool start)
time::PeriodicTrigger handle