Mbed OS Reference
|
The SysTimer class is used to provide timing for system suspension, and the idle loop in TICKLESS mode. More...
#include <SysTimer.h>
Public Types | |
using | highres_duration = TickerDataClock::duration |
duration type used for underlying high-res timer More... | |
using | highres_time_point = TickerDataClock::time_point |
time_point type used for underlying high-res timer More... | |
using | highres_period = TickerDataClock::period |
period of underlying high-res timer More... | |
Public Member Functions | |
SysTimer () | |
Default constructor uses LPTICKER if available (so the timer will continue to run in deep sleep), else USTICKER. More... | |
void | set_wake_time (time_point at) |
Set the wake time. More... | |
bool | wake_time_passed () const |
Check whether the wake time has passed. More... | |
bool | wake_time_set () const |
Check whether wake timer is active. More... | |
void | cancel_wake () |
Cancel any pending wake. More... | |
void | start_tick () |
Schedule an os tick to fire. More... | |
void | acknowledge_tick () |
Acknowledge an os tick. More... | |
void | cancel_tick () |
Prevent any more scheduled ticks from triggering. More... | |
bool | ticking () const |
Check whether ticker is active. More... | |
std::chrono::duration< int, period > | unacknowledged_ticks () const |
Check unacknowledged ticks. More... | |
time_point | get_tick () const |
Get the current tick count. More... | |
time_point | update_and_get_tick () |
Update and get the current tick count. More... | |
highres_duration | get_time_since_tick () const |
Returns time since last tick. More... | |
highres_time_point | get_time () const |
Get the time. More... | |
The SysTimer class is used to provide timing for system suspension, and the idle loop in TICKLESS mode.
Template for speed for testing - only one instance will be used normally.
Definition at line 50 of file SysTimer.h.
using highres_duration = TickerDataClock::duration |
duration type used for underlying high-res timer
Definition at line 61 of file SysTimer.h.
using highres_time_point = TickerDataClock::time_point |
time_point type used for underlying high-res timer
Definition at line 63 of file SysTimer.h.
using highres_period = TickerDataClock::period |
period of underlying high-res timer
Definition at line 65 of file SysTimer.h.
SysTimer | ( | ) |
Default constructor uses LPTICKER if available (so the timer will continue to run in deep sleep), else USTICKER.
void set_wake_time | ( | time_point | at | ) |
Set the wake time.
Schedules an interrupt to cause wake-up in time for the event. Interrupt may be arranged early to account for latency. If the time has already passed, no interrupt will be scheduled.
This is called from outside a critical section, as it is known to be a slow operation.
If the wake time is already set, this is a no-op. But that check is racy, which means wake_time_set() should be rechecked after taking a critical section.
As a side-effect, this clears the unacknowledged tick count - the caller is expected to use update_and_get_tick() after the suspend operation.
at | Wake up tick |
bool wake_time_passed | ( | ) | const |
Check whether the wake time has passed.
This is a fast operation, based on checking whether the wake interrupt has run.
Definition at line 128 of file SysTimer.h.
bool wake_time_set | ( | ) | const |
Check whether wake timer is active.
Definition at line 138 of file SysTimer.h.
void cancel_wake | ( | ) |
Cancel any pending wake.
void start_tick | ( | ) |
Schedule an os tick to fire.
Ticks will be rescheduled automatically every tick until cancel_tick is called.
A tick will be fired immediately if there are any unacknowledged ticks.
void acknowledge_tick | ( | ) |
Acknowledge an os tick.
This will queue another os tick immediately if the os is running slow
void cancel_tick | ( | ) |
Prevent any more scheduled ticks from triggering.
If called from OS tick context, there may be remaining unacknowledged ticks.
bool ticking | ( | ) | const |
Check whether ticker is active.
Each time the tick interrupt fires, it is automatically rescheduled, so this will remain true once the tick is started, except during processing.
Definition at line 182 of file SysTimer.h.
std::chrono::duration< int, period > unacknowledged_ticks | ( | ) | const |
Check unacknowledged ticks.
Returns the count of how many times the OS timer has been queued minus the number of times is has been acknowledged.
get_tick() - unacknowledged_ticks() should equal the OS's tick count, although such a calculation is not atomic if the ticker is currently running.
Definition at line 198 of file SysTimer.h.
time_point get_tick | ( | ) | const |
Get the current tick count.
This count is updated by the ticker interrupt, if the ticker interrupt is running. It the ticker interrupt is not running, update_and_get_tick() should be used instead.
This indicates how many ticks have been generated by the tick interrupt. The os_timer should equal this number minus the number of unacknowledged ticks.
time_point update_and_get_tick | ( | ) |
Update and get the current tick count.
This is a slow operation that reads the timer and adjusts for elapsed time. Can only be used when the ticker is not running, as there is no IRQ synchronization.
This clears the unacknowledged tick counter - the caller is assumed to update their timer based on this return.
highres_duration get_time_since_tick | ( | ) | const |
Returns time since last tick.
highres_time_point get_time | ( | ) | const |
Get the time.
Returns the instantaneous precision time from underlying timer. This is a slow operation so should not be called from critical sections.