![]() |
SuperTinyKernel™ RTOS 1.05.3
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
|
Software timer multiplexer that manages multiple Timer instances on top of a small fixed set of kernel tasks. More...
#include <stk_time_timer.h>
Classes | |
| class | Timer |
| Abstract base class for a timer managed by TimerHost. More... | |
| class | TimerWorkerTask |
| The actual task that executes timer callback. More... | |
| struct | TimerCommand |
Public Types | |
| enum | EConsts { TASK_COUNT = (1 + 1 ) , TASK_TICK_MEMORY_SIZE = stk::Max<size_t>(256U, STK_STACK_SIZE_MIN) , TASK_HANDLER_STACK_SIZE = stk::Max<size_t>( 256 , STK_STACK_SIZE_MIN) } |
Public Member Functions | |
| TimerHost () | |
| ~TimerHost () | |
| Destructor. | |
| void | Initialize (IKernel *kernel, EAccessMode mode) |
| Initialize timer host instance. | |
| bool | Start (Timer &timer, uint32_t delay, uint32_t period=0) |
| Start timer. | |
| bool | Stop (Timer &timer) |
| Stop running timer. | |
| bool | Reset (Timer &timer) |
| Reset periodic timer's deadline. | |
| 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 | SetPeriod (Timer &timer, 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. | |
| size_t | GetSize () const |
| Return number of currently active timers. | |
| bool | Shutdown () |
| Shutdown host instance. All timers are stopped and removed from the host. | |
| Ticks | GetTimeNow () const |
| Get current time. | |
Private Types | |
| typedef void(* | TimerFuncType) (TimerHost *host) |
| Timer task function prototype. | |
| typedef StackMemoryDef< TASK_TICK_MEMORY_SIZE >::Type | TaskTickMemory |
| typedef StackMemoryDef< TASK_HANDLER_STACK_SIZE >::Type | TimerHostMemory |
| typedef sync::Pipe< Timer *, 32 > | ReadyQueue |
| typedef sync::Pipe< TimerCommand, 32 > | CommandQueue |
Private Member Functions | |
| STK_NONCOPYABLE_CLASS (TimerHost) | |
| void | UpdateTime () |
| void | ProcessTimers () |
| bool | ProcessCommands (Timeout next_sleep) |
| bool | PushCommand (TimerCommand cmd) |
Private Attributes | |
| TaskTickMemory | m_task_tick_memory |
| tick task memory | |
| TimerHostMemory | m_task_handler_memory [1] |
| handler task memory | |
| TimerWorkerTask | m_task_tick |
| timer task | |
| TimerWorkerTask | m_task_process [1] |
| handler tasks | |
| util::DListHead< Timer, false > | m_active |
| active timers (tick task only) | |
| ReadyQueue | m_queue |
| queue of timers ready for handling | |
| CommandQueue | m_commands |
| command queue | |
| Ticks | m_now |
| last known current time (ticks) | |
Software timer multiplexer that manages multiple Timer instances on top of a small fixed set of kernel tasks.
TimerHost internally runs two categories of tasks:
All timers share the same tick and handler tasks, so the total kernel task overhead is constant regardless of how many timers are active.
Two timer modes are supported:
uint32_t (~49 days at 1 ms resolution).Definition at line 111 of file stk_time_timer.h.
|
private |
Definition at line 354 of file stk_time_timer.h.
|
private |
Definition at line 353 of file stk_time_timer.h.
Definition at line 351 of file stk_time_timer.h.
|
private |
Timer task function prototype.
Definition at line 279 of file stk_time_timer.h.
Definition at line 352 of file stk_time_timer.h.
| Enumerator | |
|---|---|
| TASK_COUNT | total number of tasks serving this instance stack memory size of the tick task |
| TASK_TICK_MEMORY_SIZE | stack memory size of the timer handler task |
| TASK_HANDLER_STACK_SIZE | |
Definition at line 114 of file stk_time_timer.h.
|
inlineexplicit |
Definition at line 176 of file stk_time_timer.h.
References m_active, m_now, m_task_handler_memory, m_task_process, m_task_tick, and m_task_tick_memory.
Referenced by Initialize(), stk::time::TimerHost::TimerWorkerTask::Initialize(), and STK_NONCOPYABLE_CLASS().
|
inline |
Destructor.
Definition at line 183 of file stk_time_timer.h.
|
inline |
Return number of currently active timers.
Definition at line 261 of file stk_time_timer.h.
References m_active.
Referenced by stk_timerhost_get_size().
|
inline |
Get current time.
Definition at line 271 of file stk_time_timer.h.
References m_now, and stk::hw::ReadVolatile64().
Referenced by stk_timerhost_get_time_now().
|
inline |
Initialize timer host instance.
| [in] | kernel | Kernel to which instance will be bound. |
| [in] | mode | Access mode for the timer handling tasks which call expired timers. |
Definition at line 386 of file stk_time_timer.h.
References stk::ACCESS_USER, stk::IKernel::AddTask(), m_task_handler_memory, m_task_process, m_task_tick, m_task_tick_memory, ProcessTimers(), STK_TIMER_THREADS_COUNT, TASK_HANDLER_STACK_SIZE, TASK_TICK_MEMORY_SIZE, TimerHost(), and UpdateTime().
Referenced by stk_timerhost_init().
|
inline |
Return true if no timers are currently active.
Definition at line 255 of file stk_time_timer.h.
References m_active.
Referenced by stk_timerhost_is_empty().
|
inlineprivate |
Definition at line 652 of file stk_time_timer.h.
References stk::time::TimerHost::TimerCommand::cmd, stk::time::TimerHost::TimerCommand::CMD_RESET, stk::time::TimerHost::TimerCommand::CMD_RESTART, stk::time::TimerHost::TimerCommand::CMD_SET_PERIOD, stk::time::TimerHost::TimerCommand::CMD_SHUTDOWN, stk::time::TimerHost::TimerCommand::CMD_START, stk::time::TimerHost::TimerCommand::CMD_START_OR_RESET, stk::time::TimerHost::TimerCommand::CMD_STOP, stk::time::TimerHost::TimerCommand::delay, stk::util::DListEntry< T, _ClosedLoop >::GetHead(), stk::util::DListEntry< T, _ClosedLoop >::IsLinked(), m_active, stk::time::TimerHost::Timer::m_active, m_commands, stk::time::TimerHost::Timer::m_deadline, stk::time::TimerHost::Timer::m_pending, stk::time::TimerHost::Timer::m_period, m_queue, stk::NO_WAIT, stk::time::TimerHost::TimerCommand::period, STK_ASSERT, STK_TIMER_THREADS_COUNT, stk::time::TimerHost::TimerCommand::timer, stk::time::TimerHost::TimerCommand::timestamp, and stk::WAIT_INFINITE.
Referenced by UpdateTime().
|
inlineprivate |
Definition at line 631 of file stk_time_timer.h.
References stk::time::TimerHost::Timer::m_pending, m_queue, and stk::time::TimerHost::Timer::OnExpired().
Referenced by Initialize().
|
inlineprivate |
Definition at line 800 of file stk_time_timer.h.
References m_commands, stk::NO_WAIT, and STK_ASSERT.
Referenced by Reset(), Restart(), SetPeriod(), Shutdown(), Start(), StartOrReset(), and Stop().
|
inline |
Reset periodic timer's deadline.
| [in] | timer | Timer instance. Must be active and periodic. |
Definition at line 447 of file stk_time_timer.h.
References stk::time::TimerHost::TimerCommand::CMD_RESET, stk::GetTicks(), stk::time::TimerHost::Timer::m_active, stk::time::TimerHost::Timer::m_period, and PushCommand().
Referenced by stk_timer_reset().
|
inline |
Atomically stop and re-start timer.
| [in] | timer | Timer instance (active or inactive). |
| [in] | delay | Initial delay in ticks before first expiration. |
| [in] | period | Reload period in ticks (0 is one-shot timer). |
Definition at line 466 of file stk_time_timer.h.
References stk::time::TimerHost::TimerCommand::CMD_RESTART, stk::GetTicks(), PushCommand(), STK_ASSERT, and stk::WAIT_INFINITE.
Referenced by stk_timer_restart().
|
inline |
Change the period of a running periodic timer without affecting its current deadline.
| [in] | timer | Timer instance. Must be active and periodic. |
| [in] | period | New reload period in ticks. Must be non-zero. |
Definition at line 502 of file stk_time_timer.h.
References stk::time::TimerHost::TimerCommand::CMD_SET_PERIOD, stk::time::TimerHost::Timer::m_active, stk::time::TimerHost::Timer::m_period, PushCommand(), and stk::WAIT_INFINITE.
Referenced by stk_timer_set_period().
|
inline |
Shutdown host instance. All timers are stopped and removed from the host.
Definition at line 525 of file stk_time_timer.h.
References stk::time::TimerHost::TimerCommand::CMD_SHUTDOWN, and PushCommand().
Referenced by stk_timerhost_shutdown().
|
inline |
Start timer.
| [in] | timer | Timer instance. Must not already be active. |
| [in] | delay | Initial delay in ticks before first expiration. |
| [in] | period | Reload period in ticks (0 is one-shot timer). |
Definition at line 406 of file stk_time_timer.h.
References stk::time::TimerHost::TimerCommand::CMD_START, stk::GetTicks(), stk::time::TimerHost::Timer::m_active, PushCommand(), STK_ASSERT, and stk::WAIT_INFINITE.
Referenced by stk_timer_start().
|
inline |
Start timer if inactive, or reset its deadline if already active and periodic.
| [in] | timer | Timer instance (active or inactive). |
| [in] | delay | Initial delay in ticks (used only when starting). |
| [in] | period | Reload period in ticks (used only when starting, 0 is one-shot). |
Definition at line 484 of file stk_time_timer.h.
References stk::time::TimerHost::TimerCommand::CMD_START_OR_RESET, stk::GetTicks(), PushCommand(), STK_ASSERT, and stk::WAIT_INFINITE.
Referenced by stk_timer_start_or_reset().
|
private |
|
inline |
Stop running timer.
| [in] | timer | Timer instance. Must be active. |
Definition at line 428 of file stk_time_timer.h.
References stk::time::TimerHost::TimerCommand::CMD_STOP, stk::time::TimerHost::Timer::m_active, and PushCommand().
Referenced by stk_timer_stop().
|
inlineprivate |
Definition at line 540 of file stk_time_timer.h.
References stk::util::DListEntry< T, _ClosedLoop >::GetNext(), stk::GetTicks(), m_active, stk::time::TimerHost::Timer::m_active, stk::time::TimerHost::Timer::m_deadline, m_now, stk::time::TimerHost::Timer::m_pending, stk::time::TimerHost::Timer::m_period, m_queue, stk::time::TimerHost::Timer::m_timestamp, stk::NO_WAIT, ProcessCommands(), STK_ASSERT, stk::WAIT_INFINITE, and stk::hw::WriteVolatile64().
Referenced by Initialize().
|
private |
active timers (tick task only)
Definition at line 360 of file stk_time_timer.h.
Referenced by GetSize(), IsEmpty(), ProcessCommands(), TimerHost(), and UpdateTime().
|
private |
command queue
Definition at line 362 of file stk_time_timer.h.
Referenced by ProcessCommands(), and PushCommand().
|
private |
last known current time (ticks)
Definition at line 363 of file stk_time_timer.h.
Referenced by GetTimeNow(), TimerHost(), and UpdateTime().
|
private |
queue of timers ready for handling
Definition at line 361 of file stk_time_timer.h.
Referenced by ProcessCommands(), ProcessTimers(), and UpdateTime().
|
private |
handler task memory
Definition at line 357 of file stk_time_timer.h.
Referenced by Initialize(), and TimerHost().
|
private |
handler tasks
Definition at line 359 of file stk_time_timer.h.
Referenced by Initialize(), and TimerHost().
|
private |
timer task
Definition at line 358 of file stk_time_timer.h.
Referenced by Initialize(), and TimerHost().
|
private |
tick task memory
Definition at line 356 of file stk_time_timer.h.
Referenced by Initialize(), and TimerHost().