Mbed OS Reference
Loading...
Searching...
No Matches
LowPowerTimer Class Reference

Timer implementation using the LP ticker. More...

#include <LowPowerTimer.h>

Inheritance diagram for LowPowerTimer:
TimerBase

Public Member Functions

void start ()
 Start the timer.
 
void stop ()
 Stop the timer.
 
void reset ()
 Reset the timer to 0.
 
float read () const
 Get the time passed in seconds.
 
int read_ms () const
 Get the time passed in milliseconds.
 
int read_us () const
 Get the time passed in microseconds.
 
 operator float () const
 An operator shorthand for read()
 
us_timestamp_t read_high_resolution_us () const
 Get (in a high resolution type) the time passed in microseconds.
 
std::chrono::microseconds elapsed_time () const
 Get the time passed as chrono microseconds.
 

Detailed Description

Timer implementation using the LP ticker.

Does not lock the deep sleep, and counts time correctly even while deep sleeping. However, provides less precision than Timer. The exact precision varies by target but will be between 250us and 15us.

Note
When constructed, a LowPowerTimer is stopped and reset to zero time.
Synchronization level: Interrupt safe

Definition at line 40 of file LowPowerTimer.h.

Member Function Documentation

◆ start()

void start ( )
inherited

Start the timer.

Will lock deep sleep if this is a Timer instance

◆ stop()

void stop ( )
inherited

Stop the timer.

Will release the deep sleep lock if this is a Timer instance

◆ reset()

void reset ( )
inherited

Reset the timer to 0.

If it was already running, it will continue

◆ read()

float read ( ) const
inherited

Get the time passed in seconds.

Returns
Time passed in floating-point seconds
Deprecated:
"Floating point operators should normally be avoided for code size. If really needed, you can use `duration<float>{elapsed_time()}.count()`" [since "mbed-os-6.0.0" ]

◆ read_ms()

int read_ms ( ) const
inherited

Get the time passed in milliseconds.

Returns
Time passed in integer milliseconds
Deprecated:
"Use the Chrono-based elapsed_time method. If integer milliseconds are needed, you can use `duration_cast<milliseconds>(elapsed_time()).count()`" [since "mbed-os-6.0.0" ]

◆ read_us()

int read_us ( ) const
inherited

Get the time passed in microseconds.

Returns
Time passed in integer microseconds
Warning
Limited to 31 bits – will not return correct values for times larger than about 35 minutes. Use read_high_resolution_us or elapsed_time instead as they are not vulnerable to this problem.
Deprecated:
"Use the Chrono-based elapsed_time method. If integer microseconds are needed, you can use `elapsed_time().count()`" [since "mbed-os-6.0.0" ]

◆ operator float()

operator float ( ) const
inherited

An operator shorthand for read()

Returns
Time passed in floating-point seconds
Deprecated:
"Floating point operators should normally be avoided for code size. If really needed, you can use `duration<float>{elapsed_time()}.count()`" [since "mbed-os-6.0.0" ]

◆ read_high_resolution_us()

us_timestamp_t read_high_resolution_us ( ) const
inherited

Get (in a high resolution type) the time passed in microseconds.

Returns
Time passed as 64-bit microseconds.
Deprecated:
"Use the Chrono-based elapsed_time method. If integer microseconds are needed, you can use `elapsed_time().count()`" [since "mbed-os-6.0.0" ]

◆ elapsed_time()

std::chrono::microseconds elapsed_time ( ) const
inherited

Get the time passed as chrono microseconds.

Returns
Time passed as std::chrono::microseconds