Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions examples/rt685s-evk/src/bin/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,12 @@ async fn main(spawner: Spawner) {
spawner.spawn(monitor_task()).unwrap();

let sfro = ClockConfig::crystal().sfro;
let mut tmr1 = CountingTimer::new_blocking(p.CTIMER0_COUNT_CHANNEL0, sfro).expect("Invalid clock config");
let mut countdown_timer =
CountingTimer::new_async(p.CTIMER1_COUNT_CHANNEL0, sfro, Irqs).expect("Invalid clock config");

let sfro = ClockConfig::crystal().sfro;
let mut tmr2 = CountingTimer::new_async(p.CTIMER1_COUNT_CHANNEL0, sfro, Irqs).expect("Invalid clock config");

tmr1.wait_us(3000000); // 3 seoconds wait
info!("First Counting timer expired");

tmr2.wait_us(5000000).await; // 5 seconds wait
info!("Second Counting timer expired");
info!("Counting timer started");
countdown_timer.wait_us(5000000).await; // 5 seconds wait
info!("Counting timer expired");

{
let sfro = ClockConfig::crystal().sfro;
Expand All @@ -62,7 +58,7 @@ async fn main(spawner: Spawner) {

loop {
// This code is showing how to use the timer in a periodic fashion
tmr2.wait_us(5000000).await;
countdown_timer.wait_us(5000000).await;
info!("Primary task running");
}
}
27 changes: 0 additions & 27 deletions src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,33 +796,6 @@ impl<'p> CountingTimer<'p, Async> {
}
}

impl<'p> CountingTimer<'p, Blocking> {
/// Creates a new `CountingTimer` in blocking mode.
///
/// Returns [`Error::Clock`] if an invalid clock configuration is used.
pub fn new_blocking<T: Instance>(_inst: Peri<'p, T>, clk: impl ConfigurableClock) -> Result<Self> {
let info = T::info();

Ok(Self {
clk_freq: clk.get_clock_rate().map_err(Error::Clock)?,
timeout: 0,
_phantom: core::marker::PhantomData,
info,
})
}

/// Waits synchronously for the countdown timer to complete.
pub fn wait_us(&mut self, count_us: u32) {
self.start(count_us);

loop {
if self.info.has_count_timer_expired() {
break;
}
}
}
}

impl<'p, M: Mode> Drop for CountingTimer<'p, M> {
fn drop(&mut self) {
self.info.count_timer_disable_interrupt();
Expand Down