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

A partial implementation of a C++11 Clock representing a HAL ticker. More...

#include <TickerDataClock.h>

Public Member Functions

constexpr TickerDataClock (const ticker_data_t *ticker)
 Construct a TickerDataClock referring to a ticker_data_t. More...
 
void set_handler (ticker_event_handler handler)
 Initialize a ticker and set the event handler. More...
 
void remove_event (ticker_event_t *obj)
 Remove an event from the queue. More...
 
void insert_event (ticker_event_t *obj, time_point timestamp, uint32_t id)
 Insert an event to the queue. More...
 
time_point now () const
 Read the current (absolute) ticker's timestamp. More...
 
int get_next_timestamp (time_point *timestamp) const
 Read the next event's timestamp. More...
 
void suspend ()
 Suspend this ticker. More...
 
void resume ()
 Resume this ticker. More...
 

Detailed Description

A partial implementation of a C++11 Clock representing a HAL ticker.

This class allows us to create chrono time_points for objects like Timer, with the limitation that the tickers are not singletons. This means:

  • the now() function is not static - this will limit use with some algorithms,
  • there is no distinction between time_points for different tickers

This "pseudo-Clock" approach has been endorsed by Howard Hinnant (designer of Chrono) here: https://stackoverflow.com/questions/56400313/why-does-the-c-standard-require-the-clocknow-function-to-be-static

TickerDataClock::time_point values should only be used with mbed APIs specifically taking them, not passed to generic templated chrono algorithms, and it is up to the user to use them in conjunction with the correct TickerDataClock.

operators for -> and conversion to ticker_data_t * are provided allowing TickerDataClock to be easily substituted in place of a ticker_data_t *.

Definition at line 52 of file TickerDataClock.h.

Constructor & Destructor Documentation

◆ TickerDataClock()

constexpr TickerDataClock ( const ticker_data_t ticker)
constexpr

Construct a TickerDataClock referring to a ticker_data_t.

Definition at line 55 of file TickerDataClock.h.

Member Function Documentation

◆ set_handler()

void set_handler ( ticker_event_handler  handler)

Initialize a ticker and set the event handler.

Parameters
handlerA handler to be set

Definition at line 70 of file TickerDataClock.h.

◆ remove_event()

void remove_event ( ticker_event_t obj)

Remove an event from the queue.

Parameters
objThe event object to be removed from the queue

Definition at line 79 of file TickerDataClock.h.

◆ insert_event()

void insert_event ( ticker_event_t obj,
time_point  timestamp,
uint32_t  id 
)

Insert an event to the queue.

The event will be executed in timestamp - ticker_read_us() us.

Note
If an event is inserted with a timestamp less than the current timestamp then the event will be scheduled immediately resulting in an instant call to event handler.
Parameters
objThe event object to be inserted to the queue
timestampThe event's timestamp
idThe event object

Definition at line 96 of file TickerDataClock.h.

◆ now()

time_point now ( ) const

Read the current (absolute) ticker's timestamp.

Warning
Return an absolute timestamp counting from the initialization of the ticker.
Returns
The current timestamp

Definition at line 108 of file TickerDataClock.h.

◆ get_next_timestamp()

int get_next_timestamp ( time_point *  timestamp) const

Read the next event's timestamp.

Parameters
timestampThe timestamp object.
Returns
1 if timestamp is pending event, 0 if there's no event pending

Definition at line 118 of file TickerDataClock.h.

◆ suspend()

void suspend ( )

Suspend this ticker.

When suspended reads will always return the same time and no events will be dispatched. When suspended the common layer will only ever call the interface function clear_interrupt() and that is only if ticker_irq_handler is called.

Definition at line 134 of file TickerDataClock.h.

◆ resume()

void resume ( )

Resume this ticker.

When resumed the ticker will ignore any time that has passed and continue counting up where it left off.

Definition at line 144 of file TickerDataClock.h.