Files
kaptan/libs/kaptan-time/src/lib.rs
T

33 lines
1.1 KiB
Rust

//! Monotonic flight-controller time values and clock contract.
#![no_std]
/// Monotonic microsecond instant since boot.
///
/// Platform clocks must extend narrower counters before constructing this type.
/// A value never wraps during one power cycle.
#[derive(Clone, Copy, Debug, Default, Eq, Ord, PartialEq, PartialOrd)]
pub struct Timestamp(u64);
impl Timestamp {
/// Creates an instant from monotonic microseconds since boot.
pub const fn from_microseconds(microseconds: u64) -> Self {
Self(microseconds)
}
/// Returns the instant in monotonic microseconds since boot.
pub const fn as_microseconds(self) -> u64 {
self.0
}
}
/// Supplies monotonically increasing instants to reusable runtime services.
///
/// Implementations may extend a hardware counter internally. `now` takes a
/// mutable receiver so an implementation can record wrap state without hidden
/// interior mutability or synchronization.
pub trait MonotonicClock {
/// Captures the current monotonic instant since boot.
fn now(&mut self) -> Timestamp;
}