Merge pull request #3877 from Abestanis/feature/watchdog_reason

Expose the watchdog reset reason
This commit is contained in:
Dario Nieuwenhuis 2025-02-12 13:38:07 +01:00 committed by GitHub
commit 712143b81f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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
}
}
}