aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2023-05-12 22:33:59 +0000
committerGitHub <[email protected]>2023-05-12 22:33:59 +0000
commitdec75474d5fd82dd6abe25647f0e221c2266dda2 (patch)
treece8ae94669c4fddcf9fc7f16f630b2a2b2a0a925
parent7f96359804b5f2bb3248cb7c0e1bab30e9135a41 (diff)
parent3edd81a94e7f3b45798e4b4a34c242ebb3eb76f5 (diff)
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 <[email protected]>
-rw-r--r--embassy-rp/src/watchdog.rs12
1 files changed, 5 insertions, 7 deletions
diff --git a/embassy-rp/src/watchdog.rs b/embassy-rp/src/watchdog.rs
index f4f165b29..3631b2a9d 100644
--- a/embassy-rp/src/watchdog.rs
+++ b/embassy-rp/src/watchdog.rs
@@ -89,14 +89,12 @@ impl Watchdog {
89 pub fn start(&mut self, period: Duration) { 89 pub fn start(&mut self, period: Duration) {
90 const MAX_PERIOD: u32 = 0xFFFFFF; 90 const MAX_PERIOD: u32 = 0xFFFFFF;
91 91
92 let delay_us = period.as_micros() as u32; 92 let delay_us = period.as_micros();
93 if delay_us > MAX_PERIOD / 2 { 93 if delay_us > (MAX_PERIOD / 2) as u64 {
94 panic!( 94 panic!("Period cannot exceed {} microseconds", MAX_PERIOD / 2);
95 "Period cannot exceed maximum load value of {} ({} microseconds))",
96 MAX_PERIOD,
97 MAX_PERIOD / 2
98 );
99 } 95 }
96 let delay_us = delay_us as u32;
97
100 // Due to a logic error, the watchdog decrements by 2 and 98 // Due to a logic error, the watchdog decrements by 2 and
101 // the load value must be compensated; see RP2040-E1 99 // the load value must be compensated; see RP2040-E1
102 self.load_value = delay_us * 2; 100 self.load_value = delay_us * 2;