diff options
| author | huntc <[email protected]> | 2023-01-04 11:07:07 +1100 |
|---|---|---|
| committer | huntc <[email protected]> | 2023-01-04 12:13:44 +1100 |
| commit | 8497f98de244f0f8800df78d6e83a2fb886016bf (patch) | |
| tree | c1d2f5cf95da18d5af76a7a42602ab65fbc15f0a /embassy-nrf/src | |
| parent | 6e6c3cbebcf0cfdb07622df803584f3fbc6a491a (diff) | |
Provides a means of obtaining the current WDT config
Obtaining the current WDT config is important so that we do not have to duplication configuration around the place. A constructor method has been introduced that returns WDT config in accordance with how the register is presently configured. The bootloader example has also been updated to show the watchdog can be obtained and used.
Diffstat (limited to 'embassy-nrf/src')
| -rw-r--r-- | embassy-nrf/src/wdt.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/embassy-nrf/src/wdt.rs b/embassy-nrf/src/wdt.rs index 8760aa301..330ca98bf 100644 --- a/embassy-nrf/src/wdt.rs +++ b/embassy-nrf/src/wdt.rs | |||
| @@ -23,6 +23,30 @@ pub struct Config { | |||
| 23 | pub run_during_debug_halt: bool, | 23 | pub run_during_debug_halt: bool, |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | impl Config { | ||
| 27 | /// Create a config structure from the current configuration of the WDT | ||
| 28 | /// peripheral. | ||
| 29 | pub fn try_new(_wdt: &peripherals::WDT) -> Option<Self> { | ||
| 30 | let r = unsafe { &*WDT::ptr() }; | ||
| 31 | |||
| 32 | #[cfg(not(feature = "_nrf9160"))] | ||
| 33 | let runstatus = r.runstatus.read().runstatus().bit(); | ||
| 34 | #[cfg(feature = "_nrf9160")] | ||
| 35 | let runstatus = r.runstatus.read().runstatuswdt().bit(); | ||
| 36 | |||
| 37 | if runstatus { | ||
| 38 | let config = r.config.read(); | ||
| 39 | Some(Self { | ||
| 40 | timeout_ticks: r.crv.read().bits(), | ||
| 41 | run_during_sleep: config.sleep().bit(), | ||
| 42 | run_during_debug_halt: config.halt().bit(), | ||
| 43 | }) | ||
| 44 | } else { | ||
| 45 | None | ||
| 46 | } | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 26 | impl Default for Config { | 50 | impl Default for Config { |
| 27 | fn default() -> Self { | 51 | fn default() -> Self { |
| 28 | Self { | 52 | Self { |
