From 39190c357f95e84947597c9f4d47193c941e965c Mon Sep 17 00:00:00 2001 From: Derek Hageman Date: Mon, 10 Oct 2022 05:15:24 -0600 Subject: [PATCH] Fix watchdog counter load (#464) Fix the watchdog load to reflect the 1us tick rate. This was changed in #361, which presumably used the field name (delay_ms) and assumed it was in milliseconds. So this also fixes the name to reflect that it's microseconds. --- rp2040-hal/src/watchdog.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rp2040-hal/src/watchdog.rs b/rp2040-hal/src/watchdog.rs index c9736bd..3c5be87 100644 --- a/rp2040-hal/src/watchdog.rs +++ b/rp2040-hal/src/watchdog.rs @@ -41,7 +41,7 @@ use fugit::MicrosDurationU32; /// Watchdog peripheral pub struct Watchdog { watchdog: WATCHDOG, - delay_ms: u32, + delay_us: u32, } impl Watchdog { @@ -49,7 +49,7 @@ impl Watchdog { pub fn new(watchdog: WATCHDOG) -> Self { Self { watchdog, - delay_ms: 0, + delay_us: 0, } } @@ -110,7 +110,7 @@ impl Watchdog { impl watchdog::Watchdog for Watchdog { fn feed(&mut self) { - self.load_counter(self.delay_ms) + self.load_counter(self.delay_us) } } @@ -122,9 +122,9 @@ impl watchdog::WatchdogEnable for Watchdog { // Due to a logic error, the watchdog decrements by 2 and // the load value must be compensated; see RP2040-E1 - self.delay_ms = period.into().to_millis() * 2; + self.delay_us = period.into().to_micros() * 2; - if self.delay_ms > MAX_PERIOD { + if self.delay_us > MAX_PERIOD { panic!("Period cannot exceed maximum load value of {}", MAX_PERIOD); } @@ -132,7 +132,7 @@ impl watchdog::WatchdogEnable for Watchdog { unsafe { self.configure_wdog_reset_triggers(); } - self.load_counter(self.delay_ms); + self.load_counter(self.delay_us); self.enable(true); } }