Mistake on this page?
Report an issue in GitHub or email us
Public Types | Public Member Functions
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< SysTimer< Period, IRQ > >

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)
 Get the interrupt number for the tick. 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

using highres_duration = TickerDataClock::duration

duration type used for underlying high-res timer

Definition at line 61 of file SysTimer.h.

using highres_period = TickerDataClock::period

period of underlying high-res timer

Definition at line 65 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.

Constructor & Destructor Documentation

SysTimer ( )

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

Member Function Documentation

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.

void cancel_wake ( )

Cancel any pending wake.

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.
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
highres_duration get_time_since_tick ( ) const

Returns time since last tick.

Returns
Relative time in microseconds
void set_wake_time ( time_point  at)

Get the interrupt number for the tick.

Returns
interrupt number 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!
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!
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 176 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.

Returns
number of unacknowledged ticks

Definition at line 192 of file SysTimer.h.

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.
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 122 of file SysTimer.h.

bool wake_time_set ( ) const

Check whether wake timer is active.

Returns
true if the wake timer is active.

Definition at line 132 of file SysTimer.h.

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.