atsamd_hal/peripherals/
watchdog.rs
1use crate::ehal_02::watchdog;
2use crate::pac::Wdt;
3use atsamd_hal_macros::hal_macro_helper;
4
5#[repr(u8)]
8#[derive(Copy, Clone, Eq, PartialEq, Debug)]
9pub enum WatchdogTimeout {
10 Cycles8 = 0,
11 Cycles16,
12 Cycles32,
13 Cycles64,
14 Cycles128,
15 Cycles256,
16 Cycles512,
17 Cycles1K,
18 Cycles2K,
19 Cycles4K,
20 Cycles8K,
21 Cycles16K,
22}
23
24pub struct Watchdog {
25 wdt: Wdt,
26}
27
28impl Watchdog {
29 pub fn new(wdt: Wdt) -> Self {
30 Self { wdt }
31 }
32}
33
34impl watchdog::Watchdog for Watchdog {
35 fn feed(&mut self) {
38 self.wdt.clear().write(|w| unsafe { w.clear().bits(0xA5) });
39 }
40}
41
42impl watchdog::WatchdogDisable for Watchdog {
44 #[hal_macro_helper]
45 fn disable(&mut self) {
46 #[hal_cfg(any("wdt-d11", "wdt-d21"))]
47 {
48 self.wdt.ctrl().write(|w| w.enable().clear_bit());
50 while self.wdt.status().read().syncbusy().bit_is_set() {}
52 }
53 #[hal_cfg("wdt-d5x")]
54 {
55 self.wdt.ctrla().write(|w| w.enable().clear_bit());
57 while self.wdt.syncbusy().read().enable().bit_is_set() {}
59 }
60 }
61}
62
63impl watchdog::WatchdogEnable for Watchdog {
64 type Time = u8;
65
66 #[hal_macro_helper]
69 fn start<T>(&mut self, period: T)
70 where
71 T: Into<Self::Time>,
72 {
73 self.wdt
75 .config()
76 .write(|w| unsafe { w.per().bits(period.into()) });
77 #[hal_cfg(any("wdt-d11", "wdt-d21"))]
78 {
79 self.wdt.ctrl().write(|w| w.enable().set_bit());
81 while self.wdt.status().read().syncbusy().bit_is_set() {}
83 }
84
85 #[hal_cfg("wdt-d5x")]
86 {
87 self.wdt.ctrla().write(|w| w.enable().set_bit());
89 while self.wdt.syncbusy().read().enable().bit_is_set() {}
91 }
92 }
93}