Pigweed
|
#include <system_clock.h>
Public Types | |
using | rep = int64_t |
using | period = std::ratio< PW_CHRONO_SYSTEM_CLOCK_PERIOD_SECONDS_NUMERATOR, PW_CHRONO_SYSTEM_CLOCK_PERIOD_SECONDS_DENOMINATOR > |
The period must be provided by the backend. | |
using | duration = std::chrono::duration< rep, period > |
Alias for durations representable with this clock. | |
using | time_point = std::chrono::time_point< SystemClock > |
Static Public Member Functions | |
static time_point | now () noexcept |
This is thread and IRQ safe. This must be provided by the backend. | |
template<class Rep , class Period > | |
static constexpr duration | for_at_least (std::chrono::duration< Rep, Period > d) |
static time_point | TimePointAfterAtLeast (duration after_at_least) |
Static Public Attributes | |
static constexpr Epoch | epoch = backend::kSystemClockEpoch |
The epoch must be provided by the backend. | |
static constexpr bool | is_monotonic = true |
static constexpr bool | is_steady = false |
static constexpr bool | is_free_running = backend::kSystemClockFreeRunning |
static constexpr bool | is_stopped_in_halting_debug_mode = true |
The clock must stop while in halting debug mode. | |
static constexpr bool | is_always_enabled = true |
The now() function can be invoked at any time. | |
static constexpr bool | is_nmi_safe = backend::kSystemClockNmiSafe |
The SystemClock
represents an unsteady, monotonic clock.
The epoch of this clock is unspecified and may not be related to wall time (for example, it can be time since boot). The time between ticks of this clock may vary due to sleep modes and potential interrupt handling. SystemClock
meets the requirements of C++'s TrivialClock
and Pigweed's PigweedClock.
SystemClock
is compatible with C++'s Clock
& TrivialClock
including:
SystemClock::rep
SystemClock::period
SystemClock::duration
SystemClock::time_point
SystemClock::is_steady
SystemClock::now()
Example:
This code is thread & IRQ safe, it may be NMI safe depending on is_nmi_safe.
|
inlinestaticconstexpr |
This is purely a helper, identical to directly using std::chrono::ceil, to convert a duration type which cannot be implicitly converted where the result is rounded up.
|
inlinestatic |
Computes the nearest time_point after the specified duration has elapsed.
This is useful for translating delay or timeout durations into deadlines.
The time_point is computed based on now() plus the specified duration where a singular clock tick is added to handle partial ticks. This ensures that a duration of at least 1 tick does not result in [0,1] ticks and instead in [1,2] ticks.
|
staticconstexpr |
The now() function may not move forward while in a critical section or interrupt. This must be provided by the backend.
|
staticconstexpr |
The time points of this clock cannot decrease, however the time between ticks of this clock may slightly vary due to sleep modes. The duration during sleep may be ignored or backfilled with another clock.
|
staticconstexpr |
The now() function may work in non-maskable interrupt contexts (e.g. exception/fault handlers), depending on the backend. This must be provided by the backend.