EVE 1.0
watchdog.c
1 #include <dev/watchdog.h>
2 #include <em_wdog.h>
3 
4 void watchdog_init(void)
5 {
6  static const WDOG_Init_TypeDef init =
7  {
8  .enable = false,
9  .debugRun = false,
10  .em2Run = false,
11  .em3Run = false,
12  .em4Block = false,
13  .swoscBlock = false,
14  .lock = false,
15  .clkSel = wdogClkSelULFRCO,
16  .perSel = wdogPeriod_4k, /* 4 sec. */
17  };
18  WDOG_Init(&init);
19 }
20 
21 void watchdog_start(void)
22 {
23  /* XXX!!! Does not work when system is locked in EM1, but no event is expected (f.e. usb-powered device) */
24 #if 0
25  WDOG_Enable(true);
26 #endif
27 }
28 
29 void watchdog_periodic(void)
30 {
31  WDOG_Feed();
32 }
33 
34 void watchdog_stop(void)
35 {
36  WDOG_Enable(false);
37 }
38 
39 void watchdog_reboot(void)
40 {
41  static const WDOG_Init_TypeDef init =
42  {
43  .enable = true,
44  .debugRun = true,
45  .em2Run = true,
46  .em3Run = true,
47  .em4Block = true,
48  .swoscBlock = true,
49  .lock = true,
50  .clkSel = wdogClkSelLFRCO,
51  .perSel = wdogPeriod_9,
52  };
53  WDOG_Init(&init);
54  /* Loop until reboot by wdog */
55  __disable_irq();
56  while(1);
57 }