Mbed OS Reference
Loading...
Searching...
No Matches
OsClock Struct Reference

A C++11 chrono TrivialClock for os_timer. More...

#include <mbed_os_timer.h>

Detailed Description

A C++11 chrono TrivialClock for os_timer.

Due to the nature of OsTimer/SysTimer, this does not have a single now method, but has multiple ways to report the current state:

 High-res timeline -------------------------------------------------------------
 Ticks               |  a  |  b  |  b  |  b  |  c  |  c  |  c  |  c  |  c  | d ^
                           ^                 ^                             ^   os_timer->get_time()
                    acknowledged_ticks()   reported_ticks()               now()

(a) is time read from hardware by OsTimer, reported to the user of OsTimer, and acknowledged by that user. (b) is time read from hardware by OsTimer, reported to the user of OsTimer, but not yet acknowledged. (c) is time already elapsed in the hardware but yet to be read and processed as ticks by OsTimer. (d) is time already elapsed in the hardware that doesn't yet form a tick.

Time is "reported" either by:

  • calls to the OsTimer's handler following start_tick - these must be acknowledged
  • the result of OsTimer::update_and_get_tick() / OsClock::now() - calling this implies acknowledgment.

As such now() is used when the ticker is not in use - it processes ticks that would have been processed by the tick handler. If the ticker is in uses reported_ticks or acknowleged_ticks must be used.

Note
To fit better into the chrono framework, OsClock uses chrono::milliseconds as its representation, which makes it signed and at least 45 bits, so it will be int64_t or equivalent, unlike OsTimer which uses uint64_t rep.

Definition at line 71 of file mbed_os_timer.h.