Skip to main content

Timer

Struct Timer 

Source
pub struct Timer<R: Rate>(/* private fields */);
Expand description

A running timer, and the scope its timestamps belong to.

stop takes it by value, so a timestamp taken from it keeps the count running for as long as it is held.

Implementations§

Source§

impl<R: Rate> Timer<R>

Source

pub unsafe fn start(_rate: R) -> Option<Self>

Start counting at R, or None if the timer is already running.

Writing the control register can advance the timer once, so the first interrupt may come early.

§Safety

Lets the timer interrupt through and turns interrupts on. That is preemption, which the surrounding code may have been written to rule out, and it happens whether or not a timer is handed back.

Source

pub fn now(&self) -> Instant<'_, R>

The tick count now.

Source

pub fn wait(&self, span: Duration<R>)

Sleep until span has passed.

The CPU sleeps while waiting, so this does not return if IE lacks TIMER or interrupts are off: the count only moves when the handler runs.

Source

pub fn count(&self) -> u8

How far the timer has counted towards its next overflow.

This is the hardware register, so it moves at the input clock rather than the overflow rate and costs no interrupt at all.

Source

pub fn stop(self)

Stop counting.

Trait Implementations§

Source§

impl<R: Rate> !Send for Timer<R>

Source§

impl<R: Rate> !Sync for Timer<R>

Auto Trait Implementations§

§

impl<R> BankSafe for Timer<R>
where R: BankSafe,

§

impl<R> Freeze for Timer<R>

§

impl<R> RefUnwindSafe for Timer<R>
where R: RefUnwindSafe,

§

impl<R> Unpin for Timer<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for Timer<R>

§

impl<R> UnwindSafe for Timer<R>
where R: 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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.