mirror of
https://github.com/embassy-rs/embassy.git
synced 2025-02-23 04:13:45 +00:00
Merge pull request #3877 from Abestanis/feature/watchdog_reason
Expose the watchdog reset reason
This commit is contained in:
commit
712143b81f
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user