Skip to main content

CountDownTimer

Struct CountDownTimer 

Source
pub struct CountDownTimer<TIMERX> { /* private fields */ }
Expand description

A running timer, counting down the interval Timer::start was given.

Free-running: the counter reloads and starts over on every rollover, so the interval repeats until the timer is stopped.

Implementations§

Source§

impl<TIMERX: Instance> CountDownTimer<TIMERX>

Source

pub fn cnt(&self) -> u16

Returns the current counter value, in timer ticks.

Says where inside the current interval the timer is, not how many intervals passed. One tick is psc() + 1 cycles of the timer clock.

Source

pub fn car(&self) -> u16

Returns the value the counter rolls over at, in timer ticks.

Read back from the hardware, so it holds for a raw start too. One interval is car() + 1 ticks: cnt() reaching this value is the last tick before a rollover, not the rollover.

Source

pub fn psc(&self) -> u16

Returns the prescaler the counter is running on.

One tick is psc() + 1 cycles of the timer clock — what turns a cnt reading into time. Read back from the hardware.

Source

pub fn elapsed<const NOM: u64, const DENOM: u64>( &self, ) -> Duration<u32, NOM, DENOM>

Returns how far into the current interval the counter is, as a duration.

Restarts from zero at every rollover and never exceeds one interval; counting intervals is the caller’s business. The scale comes from the binding (let t: MillisDuration = timer.elapsed();) — coarser than one tick floors to zero, finer than u32 spans saturates. Resolution is one tick.

Source

pub fn listen(&mut self, event: Event)

Lets event raise an interrupt. Unmasking the line in the NVIC is the caller’s.

Source

pub fn unlisten(&mut self, event: Event)

Stops event from raising an interrupt. Leaves the NVIC alone.

Source

pub fn is_listening(&self, event: Event) -> bool

Whether event reaches the NVIC.

Source

pub fn is_pending(&self, event: Event) -> bool

Whether the flag event raises is standing.

The enable and the flag are independent: this reports rollovers whether or not anything is listening for them.

Source

pub fn clear_interrupt(&mut self, event: Event)

Clears the flag event raised.

A handler must call this, first thing: the request is the flag being set, and hardware never clears it, so returning with it still set re-enters the handler at once and starves everything else.

Source

pub fn wait(&mut self)

Blocks until the counter rolls over, then clears the update flag.

Leaves the timer running, so calling this in a loop yields one full interval per call.

Source

pub fn stop(self) -> Timer<TIMERX>

Halts the counter, stops listening and hands the timer back in its stopped form.

The counter keeps its current value; a later start reloads the dividers and restarts from zero.

Source

pub fn release(self, rcu: &mut Rcu) -> TIMERX

Halts the counter and returns the peripheral with its clock stopped, skipping the stopped form.

Auto Trait Implementations§

§

impl<TIMERX> Freeze for CountDownTimer<TIMERX>
where TIMERX: Freeze,

§

impl<TIMERX> RefUnwindSafe for CountDownTimer<TIMERX>
where TIMERX: RefUnwindSafe,

§

impl<TIMERX> Send for CountDownTimer<TIMERX>
where TIMERX: Send,

§

impl<TIMERX> Sync for CountDownTimer<TIMERX>
where TIMERX: Sync,

§

impl<TIMERX> Unpin for CountDownTimer<TIMERX>
where TIMERX: Unpin,

§

impl<TIMERX> UnsafeUnpin for CountDownTimer<TIMERX>
where TIMERX: UnsafeUnpin,

§

impl<TIMERX> UnwindSafe for CountDownTimer<TIMERX>
where TIMERX: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.