diff options
| author | Sebastian Scholz <[email protected]> | 2025-02-12 13:22:43 +0100 |
|---|---|---|
| committer | Sebastian Scholz <[email protected]> | 2025-02-12 13:22:43 +0100 |
| commit | 787606b991e744aa79d6d899dd556a90e4bf9853 (patch) | |
| tree | 1fcf3dc39c9f1531073a51212d7b7c5f7b29f5f1 | |
| parent | 05bbb99603e16dd58604bfd1b59871eb551c74a3 (diff) | |
Expose the watchdog reset reason
| -rw-r--r-- | embassy-rp/src/watchdog.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/embassy-rp/src/watchdog.rs b/embassy-rp/src/watchdog.rs index edd48e0e0..553936602 100644 --- a/embassy-rp/src/watchdog.rs +++ b/embassy-rp/src/watchdog.rs | |||
| @@ -13,6 +13,15 @@ use embassy_time::Duration; | |||
| 13 | use crate::pac; | 13 | use crate::pac; |
| 14 | use crate::peripherals::WATCHDOG; | 14 | use crate::peripherals::WATCHDOG; |
| 15 | 15 | ||
| 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 | |||
| 16 | /// Watchdog peripheral | 25 | /// Watchdog peripheral |
| 17 | pub struct Watchdog { | 26 | pub struct Watchdog { |
| 18 | phantom: PhantomData<WATCHDOG>, | 27 | phantom: PhantomData<WATCHDOG>, |
| @@ -140,4 +149,17 @@ impl Watchdog { | |||
| 140 | _ => panic!("Invalid watchdog scratch index"), | 149 | _ => panic!("Invalid watchdog scratch index"), |
| 141 | } | 150 | } |
| 142 | } | 151 | } |
| 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 | } | ||
| 143 | } | 165 | } |
