pub struct PollingSysTick { /* private fields */ }Expand description
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.