forked from raspberrypi/pico-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello_watchdog.c
33 lines (27 loc) · 854 Bytes
/
hello_watchdog.c
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
/**
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/watchdog.h"
int main() {
stdio_init_all();
if (watchdog_caused_reboot()) {
printf("Rebooted by Watchdog!\n");
return 0;
} else {
printf("Clean boot\n");
}
// Enable the watchdog, requiring the watchdog to be updated every 100ms or the chip will reboot
// second arg is pause on debug which means the watchdog will pause when stepping through code
watchdog_enable(100, 1);
for (uint i = 0; i < 5; i++) {
printf("Updating watchdog %d\n", i);
watchdog_update();
}
// Wait in an infinite loop and don't update the watchdog so it reboots us
printf("Waiting to be rebooted by watchdog\n");
while(1);
}