Add clock::Monotonic trait.

This commit is contained in:
Dario Nieuwenhuis
2020-09-24 23:26:24 +02:00
parent afcf725519
commit 05ca563e7d
6 changed files with 44 additions and 17 deletions

View File

@@ -12,3 +12,4 @@ defmt = "0.1.0"
cortex-m = "0.6.3"
futures = { version = "0.3.5", default-features = false, features = [ "async-await" ] }
pin-project = { version = "0.4.23", default-features = false }
futures-intrusive = { version = "0.3.1", default-features = false }

21
embassy/src/clock.rs Normal file
View File

@@ -0,0 +1,21 @@
/// Monotonic clock with support for setting an alarm.
///
/// The clock uses a "tick" time unit, whose length is an implementation-dependent constant.
pub trait Monotonic {
/// Returns 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.
fn now(&self) -> u64;
/// Sets an alarm at the given timestamp. When the clock reaches that
/// timestamp, the provided callback funcion will be called.
///
/// When callback is called, it is guaranteed that now() will return a value greater or equal than timestamp.
///
/// Only one alarm can be active at a time. This overwrites any previously-set alarm if any.
fn set_alarm(&self, timestamp: u64, callback: fn());
/// Clears the previously-set alarm.
/// If no alarm was set, this is a noop.
fn clear_alarm(&self);
}

View File

@@ -3,6 +3,7 @@
#![feature(generic_associated_types)]
#![feature(const_fn)]
pub mod clock;
pub mod flash;
pub mod util;
pub mod io;
pub mod util;