Add module-level documentation for embassy::time
This commit is contained in:
parent
3e4e292cb7
commit
cf1323fb67
@ -1,3 +1,6 @@
|
|||||||
|
/// Time abstractions
|
||||||
|
/// To use these abstractions, first call `set_clock` with an instance of an monotonic `Clock`.
|
||||||
|
///
|
||||||
mod duration;
|
mod duration;
|
||||||
mod instant;
|
mod instant;
|
||||||
mod traits;
|
mod traits;
|
||||||
@ -14,10 +17,16 @@ pub const TICKS_PER_SECOND: u64 = 32768;
|
|||||||
|
|
||||||
static mut CLOCK: Option<&'static dyn Clock> = None;
|
static mut CLOCK: Option<&'static dyn Clock> = None;
|
||||||
|
|
||||||
|
/// Sets the clock used for the timing abstractions
|
||||||
|
///
|
||||||
|
/// Safety: Sets a mutable global.
|
||||||
pub unsafe fn set_clock(clock: &'static dyn Clock) {
|
pub unsafe fn set_clock(clock: &'static dyn Clock) {
|
||||||
CLOCK = Some(clock);
|
CLOCK = Some(clock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the current timestamp in ticks.
|
||||||
|
/// This is guaranteed to be monotonic, i.e. a call to now() will always return
|
||||||
|
/// a greater or equal value than earler calls.
|
||||||
pub(crate) fn now() -> u64 {
|
pub(crate) fn now() -> u64 {
|
||||||
unsafe { unwrap!(CLOCK, "No clock set").now() }
|
unsafe { unwrap!(CLOCK, "No clock set").now() }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user