embassy-time-driver

Crates

git

Versions

default

Flavors

Driver

Trait Driver 

Source
pub trait Driver:
    Send
    + Sync
    + 'static {
    // Required methods
    fn now(&self) -> u64;
    fn schedule_wake(&self, at: u64, waker: &Waker);
}
Expand description

Time driver

Required Methods§

Source

fn now(&self) -> u64

Return the current timestamp in ticks.

Implementations MUST ensure that:

  • This is guaranteed to be monotonic, i.e. a call to now() will always return a greater or equal value than earlier calls. Time can’t “roll backwards”.
  • It “never” overflows. It must not overflow in a sufficiently long time frame, say in 10_000 years (Human civilization is likely to already have self-destructed 10_000 years from now.). This means if your hardware only has 16bit/32bit timers you MUST extend them to 64-bit, for example by counting overflows in software, or chaining multiple timers together.
  • It never fails, including any kind of access fault, even if the underlying hardware has not yet been initialized. In these cases, it may be necessary to check if the hardware is initialized (using an atomic boolean, or similar), and if not, return a default value, such as zero (while still respecting the other requirements above).
Source

fn schedule_wake(&self, at: u64, waker: &Waker)

Schedules a waker to be awoken at moment at. If this moment is in the past, the waker might be awoken immediately.

Implementors§