atsamd_hal/peripherals/
reset_cause.rs

1use atsamd_hal_macros::{hal_cfg, hal_macro_helper};
2
3/// ResetCause represents the reason the MCU was reset.
4#[hal_macro_helper]
5#[derive(Debug, Clone, Copy)]
6pub enum ResetCause {
7    Unknown,
8    POR,
9    BOD12,
10    BOD33,
11    #[hal_cfg("rstc-d5x")]
12    NVM,
13    External,
14    Watchdog,
15    System,
16    #[hal_cfg("rstc-d5x")]
17    Backup,
18}
19
20impl From<u8> for ResetCause {
21    #[hal_macro_helper]
22    fn from(rcause_val: u8) -> ResetCause {
23        match rcause_val {
24            1 => Self::POR,
25            2 => Self::BOD12,
26            4 => Self::BOD33,
27            #[hal_cfg("rstc-d5x")]
28            8 => Self::NVM,
29            16 => Self::External,
30            32 => Self::Watchdog,
31            64 => Self::System,
32            #[hal_cfg("rstc-d5x")]
33            128 => Self::Backup,
34            _ => Self::Unknown,
35        }
36    }
37}
38
39/// Returns the cause of the last reset.
40#[hal_cfg(any("pm-d11", "pm-d21"))]
41pub fn reset_cause(pm: &crate::pac::Pm) -> ResetCause {
42    ResetCause::from(pm.rcause().read().bits())
43}
44
45/// Returns the cause of the last reset.
46#[hal_cfg("rstc-d5x")]
47pub fn reset_cause(rstc: &crate::pac::Rstc) -> ResetCause {
48    ResetCause::from(rstc.rcause().read().bits())
49}