aboutsummaryrefslogtreecommitdiff
path: root/drivers/rtwdog/src
diff options
context:
space:
mode:
authorIan McIntyre <me@mciantyre.dev>2025-11-30 18:52:34 -0500
committerIan McIntyre <me@mciantyre.dev>2025-11-30 19:10:51 -0500
commit76199f21616ad86cf68f3b063c1ce23c6fc5a52f (patch)
tree4c076d0afd649803a2bd9a5ed5cbb1f1c74fb459 /drivers/rtwdog/src
First commit
Diffstat (limited to 'drivers/rtwdog/src')
-rw-r--r--drivers/rtwdog/src/lib.rs95
1 files changed, 95 insertions, 0 deletions
diff --git a/drivers/rtwdog/src/lib.rs b/drivers/rtwdog/src/lib.rs
new file mode 100644
index 0000000..9734813
--- /dev/null
+++ b/drivers/rtwdog/src/lib.rs
@@ -0,0 +1,95 @@
+#![no_std]
+
+pub type Instance = ral_registers::Instance<RegisterBlock>;
+
+#[allow(non_snake_case)]
+#[repr(C)]
+pub struct RegisterBlock {
+ pub CS: u32,
+ pub CNT: u32,
+ pub TOVAL: u32,
+ pub WIN: u32,
+}
+
+/// Written to `CNT` during the unlock sequence.
+pub const RTWDOG_MAGIC: u32 = 0xD928_C520;
+
+ral_registers::register! {
+ #[doc = "Watchdog Control and Status Register"]
+ pub CS<u32> RW [
+ #[doc = "Stop Enable"]
+ STOP start(0) width(1) RW {}
+ #[doc = "Wait Enable"]
+ WAIT start(1) width(1) RW {}
+ #[doc = "Debug Enable"]
+ DBG start(2) width(1) RW {}
+ #[doc = "Watchdog Test"]
+ TST start(3) width(2) RW {
+ #[doc = "Watchdog test mode disabled."]
+ DISABLED = 0,
+ #[doc = "Watchdog user mode enabled. (Watchdog test mode disabled.) After testing the watchdog, software should use this setting to indicate that the watchdog is functioning normally in user mode."]
+ USER_MODE = 0x1,
+ #[doc = "Watchdog test mode enabled, only the low byte is used. CNT[CNTLOW] is compared with TOVAL[TOVALLOW]."]
+ TEST_LOW_BYTE_ONLY = 0x2,
+ #[doc = "Watchdog test mode enabled, only the high byte is used. CNT[CNTHIGH] is compared with TOVAL[TOVALHIGH]."]
+ TEST_HIGH_BYTE_ONLY = 0x3,
+ }
+ #[doc = "Allow updates"]
+ UPDATE start(5) width(1) RW {}
+ #[doc = "Watchdog Interrupt"]
+ INT start(6) width(1) RW {}
+ #[doc = "Watchdog Enable"]
+ EN start(7) width(1) RW {}
+ #[doc = "Watchdog Clock"]
+ CLK start(8) width(2) RW {}
+ #[doc = "Reconfiguration Success"]
+ RCS start(10) width(1) RO {}
+ #[doc = "Unlock status"]
+ ULK start(11) width(1) RO {}
+ #[doc = "Watchdog prescaler"]
+ PRES start(12) width(1) RW {}
+ #[doc = "Enables or disables WDOG support for 32-bit (otherwise 16-bit or 8-bit) refresh/unlock command write words"]
+ CMD32EN start(13) width(1) RW {}
+ #[doc = "Watchdog Interrupt Flag"]
+ FLG start(14) width(1) RW {}
+ #[doc = "Watchdog Window"]
+ WIN start(15) width(1) RW {}
+ ]
+}
+
+ral_registers::register! {
+ #[doc = "Watchdog Counter Register"]
+ pub CNT<u32> RW [
+ #[doc = "Low byte of the Watchdog Counter"]
+ CNTLOW start(0) width(8) RW {}
+ #[doc = "High byte of the Watchdog Counter"]
+ CNTHIGH start(8) width(8) RW {}
+ ]
+}
+
+ral_registers::register! {
+ #[doc = "Watchdog Timeout Value Register"]
+ pub TOVAL<u32> RW [
+ #[doc = "Low byte of the timeout value"]
+ TOVALLOW start(0) width(8) RW {}
+ #[doc = "High byte of the timeout value"]
+ TOVALHIGH start(8) width(8) RW {}
+ ]
+}
+
+ral_registers::register! {
+ #[doc = "Watchdog Window Register"]
+ pub WIN<u32> RW [
+ #[doc = "Low byte of Watchdog Window"]
+ WINLOW start(0) width(8) RW {}
+ #[doc = "High byte of Watchdog Window"]
+ WINHIGH start(8) width(8) RW {}
+ ]
+}
+
+/// Unlike and disable the RTWDOG.
+#[inline]
+pub fn disable(rtwdog: Instance) {
+ ral_registers::write_reg!(self, rtwdog, CNT, RTWDOG_MAGIC);
+ ral_registers::modify_reg!(self, rtwdog, CS, EN: 0);
+}