Expand description
§pw_time
pw_time provides time types and a system clock.
Clock- A monotonically increasing clock with its own scale between internal “ticks” and human time.Instant<Clock>- A sample of a specific instant on a givenClock.Duration<Clock>- A span of time whose internal representation is scaled to the givenClock.SystemClock- The clock used by the core system/RTOS.
§Examples
use pw_time::{SystemClock, Instant, Duration, Clock};
let start = SystemClock::now();
let duration = Duration::from_millis(500);
let end = start + duration;
assert_eq!(end - start, duration);§Design
§Clocks
pw_time is designed to allow type-safe handling of systems with multiple
clock domains. Each clock domain is defined by a Clock. Instant
and Duration are generic of a Clock and can not be mixed.
§Representation
pw_time uses 64 bit internal types to represent Instants (unsigned)
and Durations (signed). The scale of this internal value is defined
by the Clock::TICKS_PER_SEC. Future work may move from this scalar
scale to a ratio based one similar to C++’s std::chrono types.
§Const conversion
Duration’s from_* constructors are const and are designed to be
optimized into single “tick native” values by the compiler.
§Panic behavior
pw_time is designed to never cause a Rust panic because this can lead
to code size bloat on size constrained systems. Instead it relies on
pw_assert to allow system specific panic behavior.
Structs§
- Duration
- A span of time represented by a signed tick count.
- Instant
- A measurement of a monotonically non-decreasing clock.
- System
Clock - The clock used by the core system/RTOS
Traits§
- Clock
- A trait for retrieving the current system or hardware time.