Skip to content

Commit 712143b

Browse files
authored
Merge pull request embassy-rs#3877 from Abestanis/feature/watchdog_reason
Expose the watchdog reset reason
2 parents 05bbb99 + 787606b commit 712143b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

embassy-rp/src/watchdog.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ use embassy_time::Duration;
1313
use crate::pac;
1414
use crate::peripherals::WATCHDOG;
1515

16+
/// The reason for a system reset from the watchdog.
17+
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
18+
pub enum ResetReason {
19+
/// The reset was forced.
20+
Forced,
21+
/// The watchdog was not fed in time.
22+
TimedOut,
23+
}
24+
1625
/// Watchdog peripheral
1726
pub struct Watchdog {
1827
phantom: PhantomData<WATCHDOG>,
@@ -140,4 +149,17 @@ impl Watchdog {
140149
_ => panic!("Invalid watchdog scratch index"),
141150
}
142151
}
152+
153+
/// Get the reason for the last system reset, if it was caused by the watchdog.
154+
pub fn reset_reason(&self) -> Option<ResetReason> {
155+
let watchdog = pac::WATCHDOG;
156+
let reason = watchdog.reason().read();
157+
if reason.force() {
158+
Some(ResetReason::Forced)
159+
} else if reason.timer() {
160+
Some(ResetReason::TimedOut)
161+
} else {
162+
None
163+
}
164+
}
143165
}

0 commit comments

Comments
 (0)