rtic_monotonic

Trait Monotonic

source
pub trait Monotonic {
    type Instant: Ord + Copy + Add<Self::Duration, Output = Self::Instant> + Sub<Self::Duration, Output = Self::Instant> + Sub<Self::Instant, Output = Self::Duration>;
    type Duration;

    const DISABLE_INTERRUPT_ON_EMPTY_QUEUE: bool = true;

    // Required methods
    fn now(&mut self) -> Self::Instant;
    fn set_compare(&mut self, instant: Self::Instant);
    fn clear_compare_flag(&mut self);
    fn zero() -> Self::Instant;
    unsafe fn reset(&mut self);

    // Provided methods
    fn on_interrupt(&mut self) { ... }
    fn enable_timer(&mut self) { ... }
    fn disable_timer(&mut self) { ... }
}
Expand description

§A monotonic clock / counter definition.

§Correctness

The trait enforces that proper time-math is implemented between Instant and Duration. This is a requirement on the time library that the user chooses to use.

Provided Associated Constants§

source

const DISABLE_INTERRUPT_ON_EMPTY_QUEUE: bool = true

This tells RTIC if it should disable the interrupt bound to the monotonic if there are no scheduled tasks. One may want to set this to false if one is using the on_interrupt method to perform housekeeping and need overflow interrupts to happen, such as when extending a 16 bit timer to 32/64 bits, even if there are no scheduled tasks.

Required Associated Types§

source

type Instant: Ord + Copy + Add<Self::Duration, Output = Self::Instant> + Sub<Self::Duration, Output = Self::Instant> + Sub<Self::Instant, Output = Self::Duration>

The type for instant, defining an instant in time.

Note: In all APIs in RTIC that use instants from this monotonic, this type will be used.

source

type Duration

The type for duration, defining an duration of time.

Note: In all APIs in RTIC that use duration from this monotonic, this type will be used.

Required Methods§

source

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

Get the current time.

source

fn set_compare(&mut self, instant: Self::Instant)

Set the compare value of the timer interrupt.

Note: This method does not need to handle race conditions of the monotonic, the timer queue in RTIC checks this.

source

fn clear_compare_flag(&mut self)

Clear the compare interrupt flag.

source

fn zero() -> Self::Instant

The time at time zero. Used by RTIC before the monotonic has been initialized.

source

unsafe fn reset(&mut self)

Optionally resets the counter to zero for a fixed baseline in a system.

This method will be called exactly once by the RTIC runtime after #[init] returns and before tasks start.

§Safety
§Correctness

The user may not call this method.

Provided Methods§

source

fn on_interrupt(&mut self)

Optional. Commonly used for performing housekeeping of a timer when it has been extended, e.g. a 16 bit timer extended to 32/64 bits. This will be called at the end of the interrupt handler after all other operations have finished.

source

fn enable_timer(&mut self)

Optional. This is used to save power, this is called when the Monotonic interrupt is enabled.

source

fn disable_timer(&mut self)

Optional. This is used to save power, this is called when the Monotonic interrupt is disabled.

Object Safety§

This trait is not object safe.

Implementors§