pub use core::time::Duration;
pub type TimeValue = Duration;
pub const MILLIS_PER_SEC: u64 = 1_000;
pub const MICROS_PER_SEC: u64 = 1_000_000;
pub const NANOS_PER_SEC: u64 = 1_000_000_000;
pub const NANOS_PER_MILLIS: u64 = 1_000_000;
pub const NANOS_PER_MICROS: u64 = 1_000;
#[def_plat_interface]
pub trait TimeIf {
fn current_ticks() -> u64;
fn ticks_to_nanos(ticks: u64) -> u64;
fn nanos_to_ticks(nanos: u64) -> u64;
fn epochoffset_nanos() -> u64;
#[cfg(feature = "irq")]
fn irq_num() -> usize;
#[cfg(feature = "irq")]
fn set_oneshot_timer(deadline_ns: u64);
}
pub fn monotonic_time_nanos() -> u64 {
ticks_to_nanos(current_ticks())
}
pub fn monotonic_time() -> TimeValue {
TimeValue::from_nanos(monotonic_time_nanos())
}
pub fn wall_time_nanos() -> u64 {
monotonic_time_nanos() + epochoffset_nanos()
}
pub fn wall_time() -> TimeValue {
TimeValue::from_nanos(monotonic_time_nanos() + epochoffset_nanos())
}
pub fn busy_wait(dur: Duration) {
busy_wait_until(wall_time() + dur);
}
pub fn busy_wait_until(deadline: TimeValue) {
while wall_time() < deadline {
core::hint::spin_loop();
}
}