diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-12-13 11:21:00 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-12-13 11:21:00 +0000 |
| commit | bfec5c1486951147479c259c0fa5786fc63f1262 (patch) | |
| tree | ea59d44a3d7cb315ecaaa0d5c3002b6cd6c1f9a1 | |
| parent | e44ee26cd5bfdc0265097dec1f001257d3119028 (diff) | |
| parent | df5a399125aea0014a1629d01ef1559b5ae04af9 (diff) | |
Merge pull request #3631 from Lakier15/feature/nrf5340-reset
nrf: Add RESET operations helpers for the nrf5340
| -rw-r--r-- | embassy-nrf/src/lib.rs | 3 | ||||
| -rw-r--r-- | embassy-nrf/src/reset.rs | 82 |
2 files changed, 85 insertions, 0 deletions
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index 7c5dd7c83..e7ec4eb9d 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs | |||
| @@ -126,6 +126,9 @@ pub mod qspi; | |||
| 126 | #[cfg(not(any(feature = "_nrf91", feature = "_nrf5340-app")))] | 126 | #[cfg(not(any(feature = "_nrf91", feature = "_nrf5340-app")))] |
| 127 | pub mod radio; | 127 | pub mod radio; |
| 128 | #[cfg(not(feature = "_nrf54l"))] // TODO | 128 | #[cfg(not(feature = "_nrf54l"))] // TODO |
| 129 | #[cfg(feature = "_nrf5340")] | ||
| 130 | pub mod reset; | ||
| 131 | #[cfg(not(feature = "_nrf54l"))] // TODO | ||
| 129 | #[cfg(not(any(feature = "_nrf5340-app", feature = "_nrf91")))] | 132 | #[cfg(not(any(feature = "_nrf5340-app", feature = "_nrf91")))] |
| 130 | pub mod rng; | 133 | pub mod rng; |
| 131 | #[cfg(not(feature = "_nrf54l"))] // TODO | 134 | #[cfg(not(feature = "_nrf54l"))] // TODO |
diff --git a/embassy-nrf/src/reset.rs b/embassy-nrf/src/reset.rs new file mode 100644 index 000000000..a33d8f31f --- /dev/null +++ b/embassy-nrf/src/reset.rs | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | //! Reset | ||
| 2 | |||
| 3 | #![macro_use] | ||
| 4 | |||
| 5 | use bitflags::bitflags; | ||
| 6 | use nrf_pac::reset::regs::Resetreas; | ||
| 7 | #[cfg(not(feature = "_nrf5340-net"))] | ||
| 8 | use nrf_pac::reset::vals::Forceoff; | ||
| 9 | |||
| 10 | use crate::chip::pac::RESET; | ||
| 11 | |||
| 12 | bitflags! { | ||
| 13 | #[derive(Debug, Copy, Clone, PartialEq)] | ||
| 14 | /// Bitflag representation of the `RESETREAS` register | ||
| 15 | pub struct ResetReason: u32 { | ||
| 16 | /// Reset Pin | ||
| 17 | const RESETPIN = 1; | ||
| 18 | /// Application watchdog timer 0 | ||
| 19 | const DOG0 = 1 << 1; | ||
| 20 | /// Application CTRL-AP | ||
| 21 | const CTRLAP = 1 << 2; | ||
| 22 | /// Application soft reset | ||
| 23 | const SREQ = 1 << 3; | ||
| 24 | /// Application CPU lockup | ||
| 25 | const LOCKUP = 1 << 4; | ||
| 26 | /// Wakeup from System OFF when wakeup is triggered by DETECT signal from GPIO | ||
| 27 | const OFF = 1 << 5; | ||
| 28 | /// Wakeup from System OFF when wakeup is triggered by ANADETECT signal from LPCOMP | ||
| 29 | const LPCOMP = 1 << 6; | ||
| 30 | /// Wakeup from System OFF when wakeup is triggered by entering the Debug Interface mode | ||
| 31 | const DIF = 1 << 7; | ||
| 32 | /// Network soft reset | ||
| 33 | #[cfg(feature = "_nrf5340-net")] | ||
| 34 | const LSREQ = 1 << 16; | ||
| 35 | /// Network CPU lockup | ||
| 36 | #[cfg(feature = "_nrf5340-net")] | ||
| 37 | const LLOCKUP = 1 << 17; | ||
| 38 | /// Network watchdog timer | ||
| 39 | #[cfg(feature = "_nrf5340-net")] | ||
| 40 | const LDOG = 1 << 18; | ||
| 41 | /// Force-OFF reset from application core | ||
| 42 | #[cfg(feature = "_nrf5340-net")] | ||
| 43 | const MFORCEOFF = 1 << 23; | ||
| 44 | /// Wakeup from System OFF mode due to NFC field being detected | ||
| 45 | const NFC = 1 << 24; | ||
| 46 | /// Application watchdog timer 1 | ||
| 47 | const DOG1 = 1 << 25; | ||
| 48 | /// Wakeup from System OFF mode due to VBUS rising into valid range | ||
| 49 | const VBUS = 1 << 26; | ||
| 50 | /// Network CTRL-AP | ||
| 51 | #[cfg(feature = "_nrf5340-net")] | ||
| 52 | const LCTRLAP = 1 << 27; | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | /// Reads the bitflag of the reset reasons | ||
| 57 | pub fn read_reasons() -> ResetReason { | ||
| 58 | ResetReason::from_bits_retain(RESET.resetreas().read().0) | ||
| 59 | } | ||
| 60 | |||
| 61 | /// Resets the reset reasons | ||
| 62 | pub fn clear_reasons() { | ||
| 63 | RESET.resetreas().write(|w| *w = Resetreas(ResetReason::all().bits())); | ||
| 64 | } | ||
| 65 | |||
| 66 | /// Returns if the network core is held in reset | ||
| 67 | #[cfg(not(feature = "_nrf5340-net"))] | ||
| 68 | pub fn network_core_held() -> bool { | ||
| 69 | RESET.network().forceoff().read().forceoff() == Forceoff::HOLD | ||
| 70 | } | ||
| 71 | |||
| 72 | /// Releases the network core from the FORCEOFF state | ||
| 73 | #[cfg(not(feature = "_nrf5340-net"))] | ||
| 74 | pub fn release_network_core() { | ||
| 75 | RESET.network().forceoff().write(|w| w.set_forceoff(Forceoff::RELEASE)); | ||
| 76 | } | ||
| 77 | |||
| 78 | /// Holds the network core in the FORCEOFF state | ||
| 79 | #[cfg(not(feature = "_nrf5340-net"))] | ||
| 80 | pub fn hold_network_core() { | ||
| 81 | RESET.network().forceoff().write(|w| w.set_forceoff(Forceoff::HOLD)); | ||
| 82 | } | ||
