Trait Timer

Source
pub trait Timer {
    type Duration: Clone;
    type Instant: Clone + Ord + AddAssign<Self::Duration>;

    const DELTA: Self::Duration;

    // Required methods
    fn reset(&mut self);
    fn interrupt_free<F: FnOnce(&CriticalSection) -> R, R>(f: F) -> R;
    fn now(&self) -> Self::Instant;
    fn disarm(&mut self);
    fn arm(&mut self, deadline: &Self::Instant);
}
Expand description

A clock device that supports throwing alarm interrupts at given instant.

This trait assumes that the clock is not (re)set after initial configuration.

Required Associated Constants§

Source

const DELTA: Self::Duration

A minimal time increment, i.e. the time it takes to execute a handful of instructions.

Used when scheduling the next deadline, but in the meantime the deadline has passed.

Required Associated Types§

Source

type Duration: Clone

A length of time.

You will probably want to make this type as close to your Instant type as possible, with a focus on making addition and storage efficient.

Source

type Instant: Clone + Ord + AddAssign<Self::Duration>

A moment in time.

You will probably make this type as close to the internal representation of an instant as used by your RTC peripheral.

Required Methods§

Source

fn reset(&mut self)

Initialize the clock and start counting.

You will need to run this sometime after initializing the static memory in which the timer lives, such that the interrupt handler can access the timer.

Source

fn interrupt_free<F: FnOnce(&CriticalSection) -> R, R>(f: F) -> R

Execute the function in an interrupt free critical section.

Probably you want to directly feed through cortex_m::interrupt::free or similar.

Source

fn now(&self) -> Self::Instant

Yield the current time.

Source

fn disarm(&mut self)

Disarm the set alarm.

Source

fn arm(&mut self, deadline: &Self::Instant)

Set the alarm for a given time.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Timer for Rtc

Source§

const DELTA: DurationU32

Source§

type Instant = InstantU32

Source§

type Duration = DurationU32

Source§

fn reset(&mut self)

Source§

fn interrupt_free<F: FnOnce(&CriticalSection) -> R, R>(f: F) -> R

Source§

fn now(&self) -> Self::Instant

Source§

fn disarm(&mut self)

Source§

fn arm(&mut self, deadline: &Self::Instant)

Implementors§

Source§

impl Timer for Lptim1Rtc

Source§

const DELTA: Self::Duration = {transmute(0x00000002): <impls::stm32l4x6_lptim1::Lptim1Rtc as Timer>::Duration}

Source§

type Instant = InstantU32

Source§

type Duration = DurationU32