Fix logic issue with delay_ms

This commit is contained in:
jspaulsen 2021-05-16 14:41:38 -07:00 committed by 9names
parent 596bea309b
commit fe72637972

View file

@ -8,15 +8,14 @@ use embedded_time::{
use crate::pac::WATCHDOG; use crate::pac::WATCHDOG;
//const MAX_LOAD: u32 = 0x7FFFFF; ///
pub struct Watchdog { pub struct Watchdog {
watchdog: WATCHDOG, watchdog: WATCHDOG,
delay_ms: u32, delay_ms: u32,
} }
impl Watchdog { impl Watchdog {
///
pub fn new(watchdog: WATCHDOG) -> Self { pub fn new(watchdog: WATCHDOG) -> Self {
Self { Self {
watchdog, watchdog,
@ -24,6 +23,7 @@ impl Watchdog {
} }
} }
///
pub fn enable_tick_generation(&mut self, cycles: u8) { pub fn enable_tick_generation(&mut self, cycles: u8) {
const WATCHDOG_TICK_ENABLE_BITS: u32 = 0x200; const WATCHDOG_TICK_ENABLE_BITS: u32 = 0x200;
@ -57,11 +57,11 @@ impl watchdog::WatchdogEnable for Watchdog {
/// Due to a logic error, the watchdog decrements by 2 and /// Due to a logic error, the watchdog decrements by 2 and
/// value must be compensated; see RP2040-E1 /// value must be compensated; see RP2040-E1
fn start<T: Into<Self::Time>>(&mut self, period: T) { fn start<T: Into<Self::Time>>(&mut self, period: T) {
let delay_ms = period self.delay_ms = period
.into() .into()
.integer() * 2; .integer() * 2;
self.load_counter(delay_ms); self.load_counter(self.delay_ms);
self.enable(); self.enable();
} }
} }