diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-05-13 00:33:00 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-05-13 00:33:00 +0200 |
| commit | 3edd81a94e7f3b45798e4b4a34c242ebb3eb76f5 (patch) | |
| tree | 882ac908f025ffc6718d5550888782927d7dbff7 /embassy-rp | |
| parent | e179e7cf85810f0aa7ef8027d8d48f6d21f64dac (diff) | |
rp/watchdog: fix overflow if period is longer than 4294 seconds.
Diffstat (limited to 'embassy-rp')
| -rw-r--r-- | embassy-rp/src/watchdog.rs | 12 |
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; |
