Expose the watchdog reset reason

This commit is contained in:
Sebastian Scholz 2025-02-12 13:22:43 +01:00
parent 05bbb99603
commit 787606b991
No known key found for this signature in database
GPG Key ID: E0D5705024FDABF3

View File

@ -13,6 +13,15 @@ use embassy_time::Duration;
use crate::pac;
use crate::peripherals::WATCHDOG;
/// The reason for a system reset from the watchdog.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum ResetReason {
/// The reset was forced.
Forced,
/// The watchdog was not fed in time.
TimedOut,
}
/// Watchdog peripheral
pub struct Watchdog {
phantom: PhantomData<WATCHDOG>,
@ -140,4 +149,17 @@ impl Watchdog {
_ => panic!("Invalid watchdog scratch index"),
}
}
/// Get the reason for the last system reset, if it was caused by the watchdog.
pub fn reset_reason(&self) -> Option<ResetReason> {
let watchdog = pac::WATCHDOG;
let reason = watchdog.reason().read();
if reason.force() {
Some(ResetReason::Forced)
} else if reason.timer() {
Some(ResetReason::TimedOut)
} else {
None
}
}
}