Mistake on this page?
Report an issue in GitHub or email us
Public Member Functions | Static Private Member Functions
SysTimer< US_IN_TICK, 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< US_IN_TICK, IRQ >:
TimerEvent NonCopyable< SysTimer< US_IN_TICK, IRQ > >

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 (uint64_t 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...
 
int unacknowledged_ticks () const
 Check unacknowledged ticks. More...
 
uint64_t get_tick () const
 Get the current tick count. More...
 
uint64_t update_and_get_tick ()
 Update and get the current tick count. More...
 
us_timestamp_t get_time_since_tick () const
 Returns time since last tick. More...
 
us_timestamp_t get_time () const
 Get the time. More...
 

Static Private Member Functions

static void irq (uint32_t id)
 The handler registered with the underlying timer interrupt. More...
 

Detailed Description

template<uint32_t US_IN_TICK, bool IRQ = true>
class mbed::internal::SysTimer< US_IN_TICK, 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 49 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.

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

Returns time since last tick.

Returns
Relative time in microseconds
void set_wake_time ( uint64_t  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 157 of file SysTimer.h.

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

uint64_t 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 103 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 113 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.