Add support for multi alarm to RTC.

This commit is contained in:
Dario Nieuwenhuis
2020-09-25 23:25:49 +02:00
parent a734a9ff46
commit cf1d604749
4 changed files with 75 additions and 30 deletions

View File

@ -27,6 +27,7 @@ pub struct Executor<M, A: Alarm> {
impl<M: Model, A: Alarm> Executor<M, A> {
pub fn new(alarm: A) -> Self {
alarm.set_callback(M::signal);
Self {
inner: se::Executor::new(M::signal),
alarm,
@ -53,7 +54,7 @@ impl<M: Model, A: Alarm> Executor<M, A> {
match self.timer.next_expiration() {
// If this is in the past, set_alarm will immediately trigger the alarm,
// which will make the wfe immediately return so we do another loop iteration.
Some(at) => self.alarm.set(at, M::signal),
Some(at) => self.alarm.set(at),
None => self.alarm.clear(),
}
})

View File

@ -273,13 +273,17 @@ impl Future for Timer {
/// Trait to register a callback at a given timestamp.
pub trait Alarm {
/// Sets the callback function to be called when the alarm triggers.
/// The callback may be called from any context (interrupt or thread mode).
fn set_callback(&self, callback: fn());
/// 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(&self, timestamp: u64, callback: fn());
fn set(&self, timestamp: u64);
/// Clears the previously-set alarm.
/// If no alarm was set, this is a noop.