libs/kaptan-time: add monotonic timestamp contract
This commit is contained in:
1 parent
a6edeec330
commit
66c4e73ae1
2 files changed
+42
No files matched your search
@@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "kaptan-time"
|
||||||
|
edition.workspace = true
|
||||||
|
license.workspace = true
|
||||||
|
repository.workspace = true
|
||||||
|
rust-version.workspace = true
|
||||||
|
version.workspace = true
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
//! 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;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user