Expand description
fugit provides a comprehensive library of Duration and Instant for the handling of
time in embedded systems. The library is specifically designed to maximize const-ification
which allows for most comparisons and changes of time-base to be made at compile time, rather
than run time.
The library is aimed at ease-of-use and performance first.
use fugit::{Duration, ExtU32};
// Efficient short-hands (`.millis()`, ...)
let d = Duration::<u32, 1, 1_000>::from_ticks(111);
let sum1 = d + 300.millis();
// ^^^ Compile time move of base, only a sum is needed and no change of base
// -----------------------
// Best effort for fixed types
fn bar(d1: Duration<u32, 1, 1_000>, d2: Duration<u32, 1, 1_000_000>) {
let sum = d1 + d2.convert();
// ^^^^^^^ Run time move of base, will use a `mul` and `div` instruction (Cortex-M3+) to
// perform the move of base.
// The `.convert()` explicitly signals the move of base.
let ops = d1 > d2;
// ^^^^^^^ Run time comparison of different base, will use 2 `mul` instructions
// (Cortex-M3+) to perform the comparison.
}
fn baz(d1: Duration<u64, 1, 1_000>, d2: Duration<u64, 1, 1_000_000>) {
let sum = d1 + d2.convert();
// ^^^^^^^ Run time move of base, will use a `mul` insruction and `div`
// soft-impl (Cortex-M3+) to perform the move of base.
// The `.convert()` explicitly signals the move of base.
let ops = d1 > d2;
// ^^^^^^^ Run time comparison of different base, will use 4 `mul` instructions
// (Cortex-M3+) to perform the comparison.
}§Two kinds of instant
Instant takes a kind as its last type parameter, because the two
readings of a timestamp need different operations to be correct.
Pick Wrapping for a raw hardware counter. Ticks wrap, and comparison is
wrap-aware, which is only meaningful within half the tick range and is not transitive, so
there is no Ord.
Pick Monotonic for a timeline that does not wrap, such as a counter
extended to 64 bits in software. Comparison is a plain integer compare, so it is Ord.
Nothing checks the claim that a monotonic timeline does not wrap: Instant::from_ticks
takes any value, so a counter that wrapped before the value arrived is invisible here and
Ord will simply place the instant in the past. The producer owns that guarantee.
Use the aliases rather than naming a marker: WrappingTimerInstantU32,
MonotonicTimerInstantU64 and friends.
Modules§
Structs§
- Duration
- Represents a duration of time.
- Instant
- Represents an instant in time.
- Rate
- Represents a frequency.
Traits§
- ExtU32
- Extension trait for simple short-hands for u32 Durations
- ExtU64
- Extension trait for simple short-hands for u64 Durations
- ExtU32
Ceil - Extension trait for simple short-hands for u32 Durations (ceil rounded)
- ExtU64
Ceil - Extension trait for simple short-hands for u64 Durations (ceil rounded)
- Rate
ExtU32 - Extension trait for simple short-hands for u32 Rate
- Rate
ExtU64 - Extension trait for simple short-hands for u64 Rate
Type Aliases§
- Gigahertz
- Alias for gigahertz rate
- Gigahertz
U32 - Alias for gigahertz rate (
u32backing storage) - Gigahertz
U64 - Alias for gigahertz rate (
u64backing storage) - Hertz
- Alias for hertz rate
- Hertz
U32 - Alias for hertz rate (
u32backing storage) - Hertz
U64 - Alias for hertz rate (
u64backing storage) - Hours
Duration - Alias for hours duration
- Hours
Duration U32 - Alias for hours duration (
u32backing storage) - Hours
Duration U64 - Alias for hours duration (
u64backing storage) - Kilohertz
- Alias for kilohertz rate
- Kilohertz
U32 - Alias for kilohertz rate (
u32backing storage) - Kilohertz
U64 - Alias for kilohertz rate (
u64backing storage) - Megahertz
- Alias for megahertz rate
- Megahertz
U32 - Alias for megahertz rate (
u32backing storage) - Megahertz
U64 - Alias for megahertz rate (
u64backing storage) - Micros
Duration - Alias for microsecond duration
- Micros
Duration U32 - Alias for microsecond duration (
u32backing storage) - Micros
Duration U64 - Alias for microsecond duration (
u64backing storage) - Millis
Duration - Alias for millisecond duration
- Millis
Duration U32 - Alias for millisecond duration (
u32backing storage) - Millis
Duration U64 - Alias for millisecond duration (
u64backing storage) - Minutes
Duration - Alias for minutes duration
- Minutes
Duration U32 - Alias for minutes duration (
u32backing storage) - Minutes
Duration U64 - Alias for minutes duration (
u64backing storage) - Monotonic
Instant - Alias for instants on a monotonic timeline
- Monotonic
Timer Instant - Alias for monotonic instants that come from timers with a specific frequency
- Monotonic
Timer Instant U32 - Alias for monotonic instants that come from timers with a specific frequency (
u32backing storage) - Monotonic
Timer Instant U64 - Alias for monotonic instants that come from timers with a specific frequency (
u64backing storage) - Nanos
Duration - Alias for nanosecond duration
- Nanos
Duration U32 - Alias for nanosecond duration (
u32backing storage) - Nanos
Duration U64 - Alias for nanosecond duration (
u64backing storage) - Picos
Duration - Alias for picosecond duration
- Picos
Duration U32 - Alias for picosecond duration (
u32backing storage) - Picos
Duration U64 - Alias for picosecond duration (
u64backing storage) - Secs
Duration - Alias for second duration
- Secs
Duration U32 - Alias for second duration (
u32backing storage) - Secs
Duration U64 - Alias for second duration (
u64backing storage) - Timer
Duration - Alias for durations that come from timers with a specific frequency
- Timer
Duration U32 - Alias for durations that come from timers with a specific frequency (
u32backing storage) - Timer
Duration U64 - Alias for durations that come from timers with a specific frequency (
u64backing storage) - Timer
Rate - Alias for rate that come from timers with a specific frequency
- Timer
Rate U32 - Alias for rate that come from timers with a specific frequency (
u32backing storage) - Timer
Rate U64 - Alias for rate that come from timers with a specific frequency (
u64backing storage) - Wrapping
Instant - Alias for instants on a wrapping counter
- Wrapping
Timer Instant - Alias for wrapping instants that come from timers with a specific frequency
- Wrapping
Timer Instant U32 - Alias for wrapping instants that come from timers with a specific frequency (
u32backing storage) - Wrapping
Timer Instant U64 - Alias for wrapping instants that come from timers with a specific frequency (
u64backing storage)