![]() |
SuperTinyKernel™ RTOS 1.06.0
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
|
Pure C interface for stk::time::TimerHost and stk::time::TimerHost::Timer. More...
Topics | |
| STK C PeriodicTrigger API | |
| Pure C interface for stk::time::PeriodicTrigger. | |
Macros | |
| #define | STK_C_TIMER_MAX 32 |
| Maximum number of concurrent stk_timer_t instances per core (default: 32). | |
| #define | STK_C_TIMER_HANDLER_STACK_SIZE 256 |
| Stack size of the timer handler, increase if your timers consume more (default: 256). | |
Typedefs | |
| typedef struct stk_timerhost_t | stk_timerhost_t |
Opaque handle to a TimerHost instance (one per CPU core). | |
| typedef struct stk_timer_t | stk_timer_t |
| Opaque handle to a concrete timer managed by stk_timerhost_t. | |
| typedef 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. | |
Functions | |
| stk_timerhost_t * | stk_timerhost_get (uint8_t core_nr) |
| Obtain the pre-allocated TimerHost for the given CPU core. | |
| 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. | |
| bool | stk_timerhost_shutdown (stk_timerhost_t *host) |
| Gracefully shut down the TimerHost. | |
| bool | stk_timerhost_is_empty (const stk_timerhost_t *host) |
Return true when no timers are currently active on this host. | |
| size_t | stk_timerhost_get_size (const stk_timerhost_t *host) |
| Return the number of currently active timers on this host. | |
| 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. | |
| stk_timer_t * | stk_timer_create (stk_timer_callback_t callback, void *user_data) |
| Allocate a timer from the static pool. | |
| void | stk_timer_destroy (stk_timer_t *timer) |
| Return a timer handle back to the static pool. | |
| bool | stk_timer_start (stk_timerhost_t *host, stk_timer_t *timer, uint32_t delay, uint32_t period) |
| Start a timer. | |
| bool | stk_timer_stop (stk_timerhost_t *host, stk_timer_t *timer) |
| Stop a running timer. | |
| 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_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_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_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. | |
| bool | stk_timer_is_active (const stk_timer_t *timer) |
| Check whether a timer is currently active (started and not yet expired/stopped). | |
| uint32_t | stk_timer_get_period (const stk_timer_t *timer) |
| Get the timer's reload period. | |
| int64_t | stk_timer_get_deadline (const stk_timer_t *timer) |
| Get the absolute expiration tick count of the timer's next deadline. | |
| int64_t | stk_timer_get_timestamp (const stk_timer_t *timer) |
| Get the tick count at which the timer last expired. | |
| uint32_t | stk_timer_get_remaining_time (const stk_timer_t *timer) |
| Get remaining ticks until next expiration. | |
Pure C interface for stk::time::TimerHost and stk::time::TimerHost::Timer.
| #define STK_C_TIMER_HANDLER_STACK_SIZE 256 |
Stack size of the timer handler, increase if your timers consume more (default: 256).
Definition at line 52 of file stk_c_time.h.
| #define STK_C_TIMER_MAX 32 |
Maximum number of concurrent stk_timer_t instances per core (default: 32).
Definition at line 45 of file stk_c_time.h.
| typedef 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.
| [in] | host | TimerHost that fired the timer. |
| [in] | timer | The timer that expired. |
| [in] | user_data | Opaque pointer supplied at timer creation time. |
Definition at line 74 of file stk_c_time.h.
| typedef struct stk_timer_t stk_timer_t |
Opaque handle to a concrete timer managed by stk_timerhost_t.
Definition at line 65 of file stk_c_time.h.
| typedef struct stk_timerhost_t stk_timerhost_t |
Opaque handle to a TimerHost instance (one per CPU core).
Definition at line 61 of file stk_c_time.h.
| stk_timer_t * stk_timer_create | ( | stk_timer_callback_t | callback, |
| void * | user_data ) |
Allocate a timer from the static pool.
| [in] | callback | Function to call when the timer expires (must not be NULL). |
| [in] | user_data | Opaque pointer forwarded to callback on expiration. |
Definition at line 181 of file stk_c_time.cpp.
References s_Timers, STK_ASSERT, and STK_C_TIMERS_TOTAL.
| void stk_timer_destroy | ( | stk_timer_t * | timer | ) |
Return a timer handle back to the static pool.
| [in] | timer | Timer handle. |
Definition at line 203 of file stk_c_time.cpp.
References stk_timer_t::handle, stk::time::TimerHost::Timer::IsActive(), CTimerWrapper::Reset(), s_Timers, STK_ASSERT, and STK_C_TIMERS_TOTAL.
| int64_t stk_timer_get_deadline | ( | const stk_timer_t * | timer | ) |
Get the absolute expiration tick count of the timer's next deadline.
| [in] | timer | Timer handle. |
Definition at line 311 of file stk_c_time.cpp.
References stk::time::TimerHost::Timer::GetDeadline(), stk_timer_t::handle, and STK_ASSERT.
| uint32_t stk_timer_get_period | ( | const stk_timer_t * | timer | ) |
Get the timer's reload period.
| [in] | timer | Timer handle. |
Definition at line 304 of file stk_c_time.cpp.
References stk::time::TimerHost::Timer::GetPeriod(), stk_timer_t::handle, and STK_ASSERT.
| uint32_t stk_timer_get_remaining_time | ( | const stk_timer_t * | timer | ) |
Get remaining ticks until next expiration.
| [in] | timer | Timer handle. |
Definition at line 325 of file stk_c_time.cpp.
References stk::time::TimerHost::Timer::GetRemainingTime(), stk_timer_t::handle, and STK_ASSERT.
| int64_t stk_timer_get_timestamp | ( | const stk_timer_t * | timer | ) |
Get the tick count at which the timer last expired.
| [in] | timer | Timer handle. |
Definition at line 318 of file stk_c_time.cpp.
References stk::time::TimerHost::Timer::GetTimestamp(), stk_timer_t::handle, and STK_ASSERT.
| bool stk_timer_is_active | ( | const stk_timer_t * | timer | ) |
Check whether a timer is currently active (started and not yet expired/stopped).
| [in] | timer | Timer handle. |
true if the timer is active. Definition at line 297 of file stk_c_time.cpp.
References stk_timer_t::handle, stk::time::TimerHost::Timer::IsActive(), and STK_ASSERT.
| bool stk_timer_reset | ( | stk_timerhost_t * | host, |
| stk_timer_t * | timer ) |
Reset a periodic timer's deadline (re-arm from now).
| [in] | host | TimerHost managing the timer. |
| [in] | timer | Timer handle. Must be active and periodic (period != 0). |
true on success, false if preconditions are not met or the command queue is full. Definition at line 255 of file stk_c_time.cpp.
References stk_timer_t::handle, stk_timerhost_t::handle, stk::time::TimerHost::Reset(), and STK_ASSERT.
| 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.
Unlike calling stk_timer_stop() + stk_timer_start(), this operation is atomic with respect to the tick task: the timer cannot fire between the implicit stop and re-start. Consumes only one command queue slot.
| [in] | host | TimerHost managing the timer. |
| [in] | timer | Timer handle (active or inactive). |
| [in] | delay | Initial delay in ticks before the first expiration. |
| [in] | period | Reload period in ticks (0 = one-shot). |
true on success, false if the command queue is full. Definition at line 263 of file stk_c_time.cpp.
References stk_timer_t::handle, stk_timerhost_t::handle, stk::time::TimerHost::Restart(), CTimerWrapper::SetHostHandle(), and STK_ASSERT.
| 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.
The new period takes effect on the next reload after the current deadline fires. To apply immediately, follow with stk_timer_reset().
| [in] | host | TimerHost managing the timer. |
| [in] | timer | Timer handle. Must be active and periodic. |
| [in] | period | New reload period in ticks. Must be non-zero. |
true on success, false if preconditions are not met or the command queue is full. Definition at line 285 of file stk_c_time.cpp.
References stk_timer_t::handle, stk_timerhost_t::handle, stk::time::TimerHost::SetPeriod(), and STK_ASSERT.
| bool stk_timer_start | ( | stk_timerhost_t * | host, |
| stk_timer_t * | timer, | ||
| uint32_t | delay, | ||
| uint32_t | period ) |
Start a timer.
| [in] | host | TimerHost that will manage this timer. |
| [in] | timer | Timer handle. Must not already be active. |
| [in] | delay | Initial delay in ticks before the first expiration. |
| [in] | period | Reload period in ticks. Pass 0 for a one-shot timer. |
true on success, false if the timer is already active or the command queue is full. Definition at line 233 of file stk_c_time.cpp.
References stk_timer_t::handle, stk_timerhost_t::handle, CTimerWrapper::SetHostHandle(), stk::time::TimerHost::Start(), and STK_ASSERT.
| 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.
Collapses the common pattern:
into a single atomic operation, eliminating the TOCTOU race. If the timer is active but one-shot, no action is taken.
| [in] | host | TimerHost managing the timer. |
| [in] | timer | Timer handle (active or inactive). |
| [in] | delay | Initial delay in ticks (used only when starting). |
| [in] | period | Reload period in ticks (used only when starting, 0 = one-shot). |
true on success, false if the command queue is full. Definition at line 274 of file stk_c_time.cpp.
References stk_timer_t::handle, stk_timerhost_t::handle, CTimerWrapper::SetHostHandle(), stk::time::TimerHost::StartOrReset(), and STK_ASSERT.
| bool stk_timer_stop | ( | stk_timerhost_t * | host, |
| stk_timer_t * | timer ) |
Stop a running timer.
| [in] | host | TimerHost managing the timer. |
| [in] | timer | Timer handle. Must be currently active. |
true on success, false if the timer is not active or the command queue is full. Definition at line 247 of file stk_c_time.cpp.
References stk_timer_t::handle, stk_timerhost_t::handle, STK_ASSERT, and stk::time::TimerHost::Stop().
| stk_timerhost_t * stk_timerhost_get | ( | uint8_t | core_nr | ) |
Obtain the pre-allocated TimerHost for the given CPU core.
| [in] | core_nr | CPU core index (0 … STK_C_CPU_COUNT-1). |
Definition at line 130 of file stk_c_time.cpp.
References s_TimerHosts, and STK_C_CPU_COUNT.
| size_t stk_timerhost_get_size | ( | const stk_timerhost_t * | host | ) |
Return the number of currently active timers on this host.
| [in] | host | TimerHost handle. |
Definition at line 163 of file stk_c_time.cpp.
References stk::time::TimerHost::GetSize(), stk_timerhost_t::handle, and STK_ASSERT.
| 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.
| [in] | host | TimerHost handle. |
Definition at line 170 of file stk_c_time.cpp.
References stk::time::TimerHost::GetTimeNow(), stk_timerhost_t::handle, and STK_ASSERT.
| 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.
| [in] | host | TimerHost handle obtained via stk_timerhost_get(). |
| [in] | kernel | Kernel instance the timer tasks will be added to. |
| [in] | privileged | If true the internal handler tasks run in privileged mode, otherwise they run in user mode. |
Definition at line 138 of file stk_c_time.cpp.
References stk::ACCESS_PRIVILEGED, stk::ACCESS_USER, stk_timerhost_t::handle, stk::time::TimerHost::Initialize(), and STK_ASSERT.
| bool stk_timerhost_is_empty | ( | const stk_timerhost_t * | host | ) |
Return true when no timers are currently active on this host.
| [in] | host | TimerHost handle. |
Definition at line 156 of file stk_c_time.cpp.
References stk_timerhost_t::handle, stk::time::TimerHost::IsEmpty(), and STK_ASSERT.
| bool stk_timerhost_shutdown | ( | stk_timerhost_t * | host | ) |
Gracefully shut down the TimerHost.
| [in] | host | TimerHost handle. |
true on success, false if the internal command queue is full. Definition at line 149 of file stk_c_time.cpp.
References stk_timerhost_t::handle, stk::time::TimerHost::Shutdown(), and STK_ASSERT.