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... | |
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:
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.
constexpr TickerDataClock | ( | const ticker_data_t * | ticker | ) |
Construct a TickerDataClock referring to a ticker_data_t.
Definition at line 55 of file TickerDataClock.h.
int get_next_timestamp | ( | time_point * | timestamp | ) | const |
Read the next event's timestamp.
timestamp | The timestamp object. |
Definition at line 118 of file TickerDataClock.h.
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.
obj | The event object to be inserted to the queue |
timestamp | The event's timestamp |
id | The event object |
Definition at line 96 of file TickerDataClock.h.
time_point now | ( | ) | const |
Read the current (absolute) ticker's timestamp.
Definition at line 108 of file TickerDataClock.h.
void remove_event | ( | ticker_event_t * | obj | ) |
Remove an event from the queue.
obj | The event object to be removed from the queue |
Definition at line 79 of file TickerDataClock.h.
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.
void set_handler | ( | ticker_event_handler | handler | ) |
Initialize a ticker and set the event handler.
handler | A handler to be set |
Definition at line 70 of file TickerDataClock.h.
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.