![]() |
SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
|
Lightweight periodic trigger: returns true once per configured period when polled.
More...
#include <stk_time_util.h>
Public Member Functions | |
| PeriodicTrigger (uint32_t period, bool start=false) | |
| Construct a PeriodicTrigger. | |
| uint32_t | GetPeriod () const |
| Get currently configured trigger period. | |
| void | SetPeriod (uint32_t period) |
| Change the trigger period while preserving phase. | |
| void | Restart () |
| Reset the trigger and start. | |
| bool | Poll () |
| Check whether the scheduled trigger time has been reached. | |
Protected Attributes | |
| Ticks | m_next |
| Next trigger time in ticks. | |
| uint32_t | m_period |
| Trigger period in ticks. Modified only by SetPeriod(). Must be > 0. | |
Lightweight periodic trigger: returns true once per configured period when polled.
Implements an absolute-time based periodic trigger. Internally stores the tick value of the next scheduled firing (m_next). Each call to Poll() compares the current tick count against m_next. When the current time reaches or exceeds m_next, Poll() returns true and advances m_next by exactly one period.
Because the next trigger time is incremented by m_period rather than reset to the current time, the long-term firing rate remains stable even if individual Poll() calls are delayed.
Usage example:
m_period ticks after the start moment. Definition at line 50 of file stk_time_util.h.
|
inline |
Construct a PeriodicTrigger.
| [in] | period | Trigger period in ticks. Must be > 0. The wall-clock duration of one tick is determined by the resolution passed to IKernel::Initialize() (see IKernel::GetTickResolution()). |
| [in] | start | true to start immediately, false otherwise (default). |
Definition at line 62 of file stk_time_util.h.
References m_next, m_period, and Restart().
|
inline |
Get currently configured trigger period.
Definition at line 73 of file stk_time_util.h.
References m_period.
Referenced by stk_periodic_trigger_get_period().
|
inline |
Check whether the scheduled trigger time has been reached.
true once when the current tick count reaches or exceeds the scheduled trigger time, false otherwise. true is returned and m_next is advanced by exactly one period. Subsequent calls will continue to catch up one period at a time until the schedule is realigned. Definition at line 108 of file stk_time_util.h.
References stk::GetTicks(), m_next, m_period, and STK_ASSERT.
Referenced by stk_periodic_trigger_poll().
|
inline |
Reset the trigger and start.
m_next to (current ticks + m_period). The next Poll() firing will occur no earlier than m_period ticks after this call. Definition at line 93 of file stk_time_util.h.
References stk::GetTicks(), m_next, and m_period.
Referenced by PeriodicTrigger(), and stk_periodic_trigger_restart().
|
inline |
Change the trigger period while preserving phase.
| [in] | period | New trigger period in ticks. Must be > 0. |
m_next so that the relative progress toward the next firing is preserved. Takes effect immediately. Definition at line 83 of file stk_time_util.h.
References m_next, and m_period.
Referenced by stk_periodic_trigger_set_period().
|
protected |
Next trigger time in ticks.
Definition at line 125 of file stk_time_util.h.
Referenced by PeriodicTrigger(), Poll(), Restart(), and SetPeriod().
|
protected |
Trigger period in ticks. Modified only by SetPeriod(). Must be > 0.
Definition at line 126 of file stk_time_util.h.
Referenced by GetPeriod(), PeriodicTrigger(), Poll(), Restart(), and SetPeriod().