Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions rp235x-hal/src/watchdog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ pub struct Watchdog {
load_value: u32, // decremented by 2 per tick (µs)
}

/// Watchdog reset reason
pub enum ResetReason {
/// A manual watchdog trigger caused the reset.
Force,
/// A watchdog timeout caused the reset.
Timeout,
}

#[derive(Debug)]
#[allow(missing_docs)]
/// Scratch registers of the watchdog peripheral
Expand Down Expand Up @@ -114,6 +122,18 @@ impl Watchdog {
self.watchdog.ctrl().write(|w| w.enable().bit(bit))
}

/// Get the watchdog reset reason.
pub fn reason(&self) -> Option<ResetReason> {
let bits = self.watchdog.reason().read().bits();
if bits & 0b10 != 0 {
Some(ResetReason::Force)
} else if bits & 0b01 != 0 {
Some(ResetReason::Timeout)
} else {
None
}
}

/// Read a scratch register
pub fn read_scratch(&self, reg: ScratchRegister) -> u32 {
match reg {
Expand Down