[−][src]Struct cortex_m_systick_countdown::PollingSysTick
Millisecond counter based on SysTick
Effectively a singleton because this struct will consume the only SYST value
in the program. (Use free
if you need to get it back.)
Usage
For simple blocking delays, use the
embedded_hal::blocking::delay::DelayMs
trait
to pause the program for a certain amount of time.
For timeouts or other non-blocking operations, create a
MillisCountDown
instance and use its
start
and wait
methods. You can have multiple MillisCountDown
instances active at the same time.
Because this uses polling for measuring SysTick, it will work even during periods where interrupts are disabled.
Implementation
We configure SysTick’s reload value to a count that will take 1ms to decrement to. When we detect that this count has wrapped over we increment our internal count of the milliseconds that have ellapsed.
We use the polling pattern for querying the time, rather than relying on
interrupts, which means that our count is only guaranteed to be no faster
than SysTick. We only keep accurate count while the count
method is being actively called, and may experience some jitter depending on
where SysTick is in its count when you start a timer.
This also means we need to use internal mutability so that we can access the SYST.has_wrapped() method (which mutates on read) and update our counter.
Methods
impl PollingSysTick
[src]
pub fn new(syst: SYST, calibration: &SysTickCalibration) -> Self
[src]
Configures SysTick based on the values provided in the calibration.
pub fn free(self) -> SYST
[src]
Turns this value back into the underlying SysTick.
Trait Implementations
impl CountsMillis for PollingSysTick
[src]
fn count(&self) -> Wrapping<u32>
[src]
Returns a number that goes up no faster than once per millisecond. This value will not increment unless polled (this is so it can operate during critical sections when interrupts are disabled).
impl DelayMs<u32> for PollingSysTick
[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Same<T> for T
type Output = T
Should always be Self