Ewout van Bekkum | 3c61ae9 | 2020-10-30 15:52:25 -0700 | [diff] [blame] | 1 | .. _module-pw_chrono: |
| 2 | |
| 3 | --------- |
| 4 | pw_chrono |
| 5 | --------- |
| 6 | Pigweed's chrono module provides facilities for applications to deal with time, |
| 7 | leveraging many pieces of STL's the ``std::chrono`` library but with a focus |
| 8 | on portability for constrained embedded devices and maintaining correctness. |
| 9 | |
Ewout van Bekkum | cc756c8 | 2021-05-12 07:57:43 -0700 | [diff] [blame^] | 10 | At a high level Pigweed's time primitives rely on C++'s |
| 11 | `<chrono> <https://en.cppreference.com/w/cpp/header/chrono>`_ library to enable |
| 12 | users to express intents with strongly typed real time units. In addition, it |
| 13 | extends the C++ named |
| 14 | `Clock <https://en.cppreference.com/w/cpp/named_req/Clock>`_ and |
| 15 | `TrivialClock <https://en.cppreference.com/w/cpp/named_req/TrivialClock>`_ |
| 16 | requirements with additional attributes such as whether a clock is monotonic |
| 17 | (not just steady), is always enabled (or requires enabling), is free running |
| 18 | (works even if interrupts are masked), whether it is safe to use in a |
| 19 | Non-Maskable Interrupts (NMI), what the epoch is, and more. |
| 20 | |
Ewout van Bekkum | 3c61ae9 | 2020-10-30 15:52:25 -0700 | [diff] [blame] | 21 | .. warning:: |
Ewout van Bekkum | cc756c8 | 2021-05-12 07:57:43 -0700 | [diff] [blame^] | 22 | This module is still under construction, the API is not yet stable. Also the |
| 23 | documentation is incomplete. |
Ewout van Bekkum | 3c61ae9 | 2020-10-30 15:52:25 -0700 | [diff] [blame] | 24 | |
| 25 | SystemClock facade |
| 26 | ------------------ |
| 27 | The ``pw::chrono::SystemClock`` is meant to serve as the clock used for time |
| 28 | bound operations such as thread sleeping, waiting on mutexes/semaphores, etc. |
| 29 | The ``SystemClock`` always uses a signed 64 bit as the underlying type for time |
| 30 | points and durations. This means users do not have to worry about clock overflow |
| 31 | risk as long as rational durations and time points as used, i.e. within a range |
| 32 | of ±292 years. |