Contiki 3.x
watchdog.c
1 #include "dev/watchdog.h"
2 #include "derivative.h"
3 #include "contiki-conf.h"
4 #include "cpu.h"
5 #include <stdio.h>
6 
7 static volatile uint8_t watchdog_status;
8 
9 void watchdog_init(void) {
10  /* Once configured, it cannot be reconfigured or stopped. */
11 
12 #if (DISABLE_WDOG == 0)
13  /* Lock in Watchdog settings. */
14  /* Configure Watchdog to timout after 1.024s. */
15  SIM_COPC = SIM_COPC_COPT(0x03);
16 #endif
17 
18 }
19 
20 void watchdog_start(void) {
21  /* The watchdog starts with the core. */
22 #if (DISABLE_WDOG == 0)
23  CPU_Watchdog_Enable();
24 #endif
25 }
26 
27 void watchdog_periodic(void) {
28  /* This function is called periodically to restart the watchdog
29  timer. */
30 #if (DISABLE_WDOG == 0)
31  SIM_SRVCOP = 0x55;
32  SIM_SRVCOP = 0xAA;
33 #endif
34 }
35 
36 void watchdog_stop(void) {
37  /* We cannot actually stop the watchdog once running. */
38 #if (DISABLE_WDOG == 0)
39  CPU_Watchdog_Disable();
40 #endif
41 }
42 
43 void watchdog_reboot(void) {
44  /* Trigger a reboot by writing junk to the COP register. */
45  //printf("\n\rCode-Induced Watchdog.\n\r");
46  //SIM_SRVCOP = 0xFF;
47  uint16_t endian = SCB->AIRCR & 0x8000;
48 
49  SCB->AIRCR = 0x05FA0004 | endian;
50 }
51 
52 
53 #if (DISABLE_WDOG == 0)
54 uint8_t CPU_Watchdog_Disabled(void) {
55  return watchdog_status;
56 }
57 
58 void CPU_Watchdog_Disable(void) {
59  watchdog_status = 1;
60 }
61 void CPU_Watchdog_Enable(void) {
62  watchdog_status = 0;
63 }
64 #endif
void watchdog_stop(void)
Stops the WDT such that it won't timeout and cause MCU reset.
Definition: watchdog.c:60
#define SCB
Definition: core_cm0.h:494
void watchdog_reboot(void)
Keeps control until the WDT throws a reset signal.
Definition: watchdog.c:94
void watchdog_periodic(void)
Writes the WDT clear sequence.
Definition: watchdog.c:85
void watchdog_init(void)
Initialisation function for the WDT.
Definition: watchdog.c:63
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
Definition: watchdog.c:72