Merge #1447
1447: rp/watchdog: fix overflow if period is longer than 4294 seconds. r=Dirbaio a=Dirbaio bors r+ Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
This commit is contained in:
commit
dec75474d5
1 changed files with 5 additions and 7 deletions
|
@ -89,14 +89,12 @@ impl Watchdog {
|
|||
pub fn start(&mut self, period: Duration) {
|
||||
const MAX_PERIOD: u32 = 0xFFFFFF;
|
||||
|
||||
let delay_us = period.as_micros() as u32;
|
||||
if delay_us > MAX_PERIOD / 2 {
|
||||
panic!(
|
||||
"Period cannot exceed maximum load value of {} ({} microseconds))",
|
||||
MAX_PERIOD,
|
||||
MAX_PERIOD / 2
|
||||
);
|
||||
let delay_us = period.as_micros();
|
||||
if delay_us > (MAX_PERIOD / 2) as u64 {
|
||||
panic!("Period cannot exceed {} microseconds", MAX_PERIOD / 2);
|
||||
}
|
||||
let delay_us = delay_us as u32;
|
||||
|
||||
// Due to a logic error, the watchdog decrements by 2 and
|
||||
// the load value must be compensated; see RP2040-E1
|
||||
self.load_value = delay_us * 2;
|
||||
|
|
Loading…
Reference in a new issue