Mbed OS Reference
Loading...
Searching...
No Matches
SysTimer< Period, IRQ > Class Template Reference

The SysTimer class is used to provide timing for system suspension, and the idle loop in TICKLESS mode. More...

#include <SysTimer.h>

Inheritance diagram for SysTimer< Period, IRQ >:
TimerEvent NonCopyable< T >

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...
 

Detailed Description

template<class Period, bool IRQ = true>
class mbed::internal::SysTimer< Period, IRQ >

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.

Note
SysTimer is not the part of Mbed API.

Definition at line 50 of file SysTimer.h.

Member Typedef Documentation

◆ highres_duration

using highres_duration = TickerDataClock::duration

duration type used for underlying high-res timer

Definition at line 61 of file SysTimer.h.

◆ highres_time_point

using highres_time_point = TickerDataClock::time_point

time_point type used for underlying high-res timer

Definition at line 63 of file SysTimer.h.

◆ highres_period

using highres_period = TickerDataClock::period

period of underlying high-res timer

Definition at line 65 of file SysTimer.h.

Constructor & Destructor Documentation

◆ SysTimer()

SysTimer ( )

Default constructor uses LPTICKER if available (so the timer will continue to run in deep sleep), else USTICKER.

Member Function Documentation

◆ set_wake_time()

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.

Parameters
atWake up tick
Warning
If the ticker tick is already scheduled it needs to be cancelled first!

◆ wake_time_passed()

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.

Returns
true if the specified wake tick has passed

Definition at line 128 of file SysTimer.h.

◆ wake_time_set()

bool wake_time_set ( ) const

Check whether wake timer is active.

Returns
true if the wake timer is active.

Definition at line 138 of file SysTimer.h.

◆ cancel_wake()

void cancel_wake ( )

Cancel any pending wake.

◆ start_tick()

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.

Warning
If a tick is already scheduled it needs to be cancelled first!

◆ acknowledge_tick()

void acknowledge_tick ( )

Acknowledge an os tick.

This will queue another os tick immediately if the os is running slow

◆ cancel_tick()

void cancel_tick ( )

Prevent any more scheduled ticks from triggering.

If called from OS tick context, there may be remaining unacknowledged ticks.

◆ ticking()

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.

Returns
true if the ticker is active.

Definition at line 182 of file SysTimer.h.

◆ unacknowledged_ticks()

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.

Returns
number of unacknowledged ticks

Definition at line 198 of file SysTimer.h.

◆ get_tick()

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.

Returns
The number of ticks since timer creation.

◆ update_and_get_tick()

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.

Returns
The number of ticks since timer creation.

◆ get_time_since_tick()

highres_duration get_time_since_tick ( ) const

Returns time since last tick.

Returns
Relative time in microseconds

◆ get_time()

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.

Returns
Current time in microseconds