Trait Alarm

Source
pub trait Alarm<'a>: Time {
    // Required methods
    fn set_alarm_client(&self, client: &'a dyn AlarmClient);
    fn set_alarm(&self, reference: Self::Ticks, dt: Self::Ticks);
    fn get_alarm(&self) -> Self::Ticks;
    fn disarm(&self) -> Result<(), ErrorCode>;
    fn is_armed(&self) -> bool;
    fn minimum_dt(&self) -> Self::Ticks;
}
Expand description

Interface for receiving notification when a particular time (Counter value) is reached.

Clients use the AlarmClient trait to signal when the counter has reached a pre-specified value set in set_alarm. Alarms are intended for low-level time needs that require precision (i.e., firing on a precise clock tick). Software that needs more functionality but can tolerate some jitter should use the Timer trait instead.

Required Methods§

Source

fn set_alarm_client(&self, client: &'a dyn AlarmClient)

Specify the callback for when the counter reaches the alarm value. If there was a previously installed callback this call replaces it.

Source

fn set_alarm(&self, reference: Self::Ticks, dt: Self::Ticks)

Specify when the callback should be called and enable it. The callback will be enqueued when Time::now() == reference + dt. The callback itself may not run exactly at this time, due to delays. However, it it assured to execute after reference + dt: it can be delayed but will never fire early. The method takes reference and dt rather than a single value denoting the counter value so it can distinguish between alarms which have very recently already passed and those in the far far future (see #1651).

Source

fn get_alarm(&self) -> Self::Ticks

Return the current alarm value. This is undefined at boot and otherwise returns now + dt from the last call to set_alarm.

Source

fn disarm(&self) -> Result<(), ErrorCode>

Disable the alarm and stop it from firing in the future. Valid Result<(), ErrorCode> codes are:

  • Ok(()) the alarm has been disarmed and will not invoke the callback in the future
  • Err(ErrorCode::FAIL) the alarm could not be disarmed and will invoke the callback in the future
Source

fn is_armed(&self) -> bool

Returns whether the alarm is currently armed. Note that this does not reliably indicate whether there will be a future callback: it is possible that the alarm has triggered (and disarmed) and a callback is pending and has not been called yet. In this case it possible for is_armed to return false yet to receive a callback.

Source

fn minimum_dt(&self) -> Self::Ticks

Return the minimum dt value that is supported. Any dt smaller than this will automatically be increased to this minimum value.

Implementors§

impl<'a> Alarm<'a> for STimer<'a>

impl<'a, A: Alarm<'a>> Alarm<'a> for VirtualMuxAlarm<'a, A>

impl<'a, CFG: EarlGreyConfig> Alarm<'a> for RvTimer<'a, CFG>

impl<'a, F: Frequency, const C3: bool> Alarm<'a> for TimG<'a, F, C3>

impl<'a, F: Frequency> Alarm<'a> for Gpt<'a, F>

impl<'c, R: LiteXSoCRegisterConfiguration, F: Frequency> Alarm<'c> for LiteXAlarm<'_, 'c, R, F>

impl<'a> Alarm<'a> for TimerA<'a>

impl<'a> Alarm<'a> for Rtc<'a>

impl<'a> Alarm<'a> for TimerAlarm<'a>

impl<'a> Alarm<'a> for Tcpwm0<'a>

impl<'a> Alarm<'a> for RPTimer<'a>

impl<'a> Alarm<'a> for Ast<'a>

impl<'a, F: Frequency> Alarm<'a> for Clint<'a, F>

impl<'a> Alarm<'a> for Tim2<'a>

impl<'a> Alarm<'a> for Tim2<'a>