Expand description
typus_fugit provides a comprehensive library of Duration and Instant for the handling of
time in embedded systems. The library is specifically designed to maximize type-system use
which allows for most comparisons and changes of time-base to be made at compile time, rather
than run time, as well as restricting use to legal values only.
The library is aimed at performance and correctness first, with minimal friction to follow.
We lift the concept of “values” into types using typenum. This allows for:
- Specifying illigal values within the type-system, such as zero-val denominators
- not needing to specify machine-representation of values that are only used at compile-time
- compile-time arithmetic of values
use typus_fugit::{Duration, ExtU32};
// Efficient short-hands (`.millis()`, ...)
let d = Duration::<u32, typenum::U1, typenum::U1000>::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, typenum::U1, typenum::U1000>, d2: Duration<u32, typenum::U1, typenum::U1000000>) {
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, typenum::U1, typenum::U1000>, d2: Duration<u64, typenum::U1, typenum::U1000000>) {
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.
}Re-exports§
pub use typenum;
Structs§
- Represents a duration of time.
- Represents an instant in time.
- Represents a frequency.
Traits§
- Extension trait for simple short-hands for u32 Durations
- Extension trait for simple short-hands for u64 Durations
- Extension trait for simple short-hands for u32 Durations (ceil rounded)
- Extension trait for simple short-hands for u64 Durations (ceil rounded)
- Extension trait for simple short-hands for u32 Rate
- Extension trait for simple short-hands for u64 Rate
Type Aliases§
- Alias for hertz rate
- Alias for hertz rate (
u32backing storage) - Alias for hertz rate (
u64backing storage) - Alias for hours duration
- Alias for hours duration (
u32backing storage) - Alias for hours duration (
u64backing storage) - Alias for kilohertz rate
- Alias for kilohertz rate (
u32backing storage) - Alias for kilohertz rate (
u64backing storage) - Alias for megahertz rate
- Alias for megahertz rate (
u32backing storage) - Alias for megahertz rate (
u64backing storage) - Alias for microsecond duration
- Alias for microsecond duration (
u32backing storage) - Alias for microsecond duration (
u64backing storage) - Alias for millisecond duration
- Alias for millisecond duration (
u32backing storage) - Alias for millisecond duration (
u64backing storage) - Alias for minutes duration
- Alias for minutes duration (
u32backing storage) - Alias for minutes duration (
u64backing storage) - Alias for nanosecond duration
- Alias for nanosecond duration (
u32backing storage) - Alias for nanosecond duration (
u64backing storage) - Alias for second duration
- Alias for second duration (
u32backing storage) - Alias for second duration (
u64backing storage) - Alias for durations that come from timers with a specific frequency
- Alias for durations that come from timers with a specific frequency (
u32backing storage) - Alias for durations that come from timers with a specific frequency (
u64backing storage) - Alias for instants that come from timers with a specific frequency
- Alias for instants that come from timers with a specific frequency (
u32backing storage) - Alias for instants that come from timers with a specific frequency (
u64backing storage) - Alias for rate that come from timers with a specific frequency
- Alias for rate that come from timers with a specific frequency (
u32backing storage) - Alias for rate that come from timers with a specific frequency (
u64backing storage) - There are 3600 seconds in an hour