-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWTD_dummy_Test.ino
66 lines (53 loc) · 2.67 KB
/
WTD_dummy_Test.ino
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
#define WDT_CONFIG_PER_3 0x3u // 64 clock cycles
#define WDT_CONFIG_PER_4 0x4u // 128 clock cycles
#define WDT_CONFIG_PER_5 0x5u // 256 clock cycles
#define WDT_CONFIG_PER_6 0x6u // 512 clock cycles
#define WDT_CONFIG_PER_7 0x7u // 1024 clock cycles
#define WDT_CONFIG_PER_8 0x8u // 2048 clock cycles
#define WDT_CONFIG_PER_9 0x9u // 4096 clock cycles
#define WDT_CONFIG_PER_10 0xAu // 8192 clock cycles
#define WDT_CONFIG_PER_11 0xBu // 16384 clock cycles
int i=1;
void watchdog_setup(void){
// Set up the generic clock (GCLK2) used to clock the watchdog timer at 1.024kHz
REG_GCLK_GENDIV = GCLK_GENDIV_DIV(4) | // Divide the 32.768kHz clock source by divisor 32, where 2^(4 + 1): 32.768kHz/32=1.024kHz
GCLK_GENDIV_ID(2); // Select Generic Clock (GCLK) 2
while (GCLK->STATUS.bit.SYNCBUSY); // Wait for synchronization
REG_GCLK_GENCTRL = GCLK_GENCTRL_DIVSEL | // Set to divide by 2^(GCLK_GENDIV_DIV(4) + 1)
GCLK_GENCTRL_IDC | // Set the duty cycle to 50/50 HIGH/LOW
GCLK_GENCTRL_GENEN | // Enable GCLK2
GCLK_GENCTRL_SRC_OSCULP32K | // Set the clock source to the ultra low power oscillator (OSCULP32K)
GCLK_GENCTRL_ID(2); // Select GCLK2
while (GCLK->STATUS.bit.SYNCBUSY); // Wait for synchronization
// Feed GCLK2 to WDT (Watchdog Timer)
REG_GCLK_CLKCTRL = GCLK_CLKCTRL_CLKEN | // Enable GCLK2 to the WDT
GCLK_CLKCTRL_GEN_GCLK2 | // Select GCLK2
GCLK_CLKCTRL_ID_WDT; // Feed the GCLK2 to the WDT
while (GCLK->STATUS.bit.SYNCBUSY); // Wait for synchronization
REG_WDT_CONFIG = WDT_CONFIG_PER_10; // Set the WDT reset timeout to 16 seconds
while(WDT->STATUS.bit.SYNCBUSY); // Wait for synchronization
REG_WDT_CTRL = WDT_CTRL_ENABLE; // Enable the WDT in normal mode
while(WDT->STATUS.bit.SYNCBUSY); // Wait for synchronization
}
void watchdog_clear(void){
if (!WDT->STATUS.bit.SYNCBUSY) // Check if the WDT registers are synchronized
{
REG_WDT_CLEAR = WDT_CLEAR_CLEAR_KEY; // Clear the watchdog timer
SerialUSB.println("Clear Key Sent to MCU WathcDog");
}
}
void setup()
{
SerialUSB.begin(9600);
SerialUSB.println("start the i to 1");
i=1;
watchdog_setup();
}
void loop()
{
i=i+1;
delay(i*1000);
SerialUSB.print("Delay Seconds :");
SerialUSB.println(i);
watchdog_clear();
}