Initial Release
This commit is contained in:
11
watchdog/hello_watchdog/CMakeLists.txt
Normal file
11
watchdog/hello_watchdog/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
add_executable(hello_watchdog
|
||||
hello_watchdog.c
|
||||
)
|
||||
|
||||
target_link_libraries(hello_watchdog pico_stdlib)
|
||||
|
||||
# create map/bin/hex file etc.
|
||||
pico_add_extra_outputs(hello_watchdog)
|
||||
|
||||
# add url via pico_set_program_url
|
||||
example_auto_set_url(hello_watchdog)
|
||||
33
watchdog/hello_watchdog/hello_watchdog.c
Normal file
33
watchdog/hello_watchdog/hello_watchdog.c
Normal file
@@ -0,0 +1,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);
|
||||
}
|
||||
Reference in New Issue
Block a user