aboutsummaryrefslogtreecommitdiff
path: root/drivers/rtwdog/src/lib.rs
blob: 9734813d1068b9743f6607c9fb1228405e663e98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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);
}