pub struct CYCCNTClock<const SYSCLK_HZ: u32> {}
Expand description
Clock based on the Cortex-M CYCCNT counter allowing to measure time durations and produce
delays.
Precise at a microsecond scale if your SYSCLK clock is greater than 1MHz
Implementations§
Source§impl<const SYSCLK_HZ: u32> CYCCNTClock<SYSCLK_HZ>
impl<const SYSCLK_HZ: u32> CYCCNTClock<SYSCLK_HZ>
Sourcepub fn now() -> Instant<SYSCLK_HZ>
pub fn now() -> Instant<SYSCLK_HZ>
Return an Instant
object corresponding to a snapshot created at the time this method was called.
Panic if the counter has not been initialized with CYCCNTClock::init()
before.
const SYSCLK_FREQ_HZ : u32 = 8_000_000;
let t1 = CYCCNTClock<SYSCLK_FREQ_HZ>::now();
// Wait 100 us
let duration = Duration::micros(100);
CYCCNTClock<SYSCLK_FREQ_HZ>::delay(duration)
let t2 = CYCCNTClock<SYSCLK_FREQ_HZ>::now();
let elpased_time = t2 - t1; // Very small elapsed time
println!("time_us {}", elapsed_time.to_micros());
Sourcepub fn delay(duration: Duration<SYSCLK_HZ>)
pub fn delay(duration: Duration<SYSCLK_HZ>)
Blocking wait for the duration specified as argument
Interrupts can still trigger during this call.
Panic if the counter has not been initialized with CYCCNTClock::init()
before.
const SYSCLK_FREQ_HZ : u32 = 8_000_000;
let t1 = CYCCNTClock<SYSCLK_FREQ_HZ>::now();
// Wait 100 us
let duration = Duration::micros(100);
CYCCNTClock<SYSCLK_FREQ_HZ>::delay(duration)
let t2 = CYCCNTClock<SYSCLK_FREQ_HZ>::now();
let elpased_time = t2 - t1; // Very small elapsed time
println!("time_us {}", elapsed_time.to_micros());
Sourcepub fn update()
pub fn update()
Synchronize the hardware counter with this clock.
Must be called at least one time for every CYCCNT counter cycle after init. Otherwise
time counting will be corrupted.
In general, calling this method in every SysTick IRQ call is the simpler option
This method will NOT panic if the CYCCNTClock::init()
method has not be called first.