objc

examples/runtime/watchdog/main.c
#include <runtime-hw/hw.h>
// CORE 0 TASKS
bool core0_task() {
// Create the watchdog
if (!hw_watchdog_valid(watchdog)) {
sys_printf("core 0: Failed to initialize watchdog\n");
return false;
}
// Explain that the last boot was caused by the watchdog resetting
if (hw_watchdog_did_reset(watchdog)) {
sys_printf("Watchdog triggered a reset\n");
}
// Run the event processing loop - which is just sleeping for 1s
int count = 0;
do {
sys_printf("Ping the watchdog (%d)\n", count++);
sys_sleep(100);
if (count == 50) {
sys_printf("Resetting the watchdog in 5s\n");
hw_watchdog_reset(watchdog, 5000);
}
} while (true);
// If we were to reach here, finalize the watchdog
return true;
}
// MAIN
int main() {
// Initialize
// Check that watchdog is supported
if (hw_watchdog_maxtimeout() == 0) {
sys_printf("Watchdog not supported on this hardware\n");
return -1;
}
// Run the task
sys_printf("Running %s on %s\n", sys_env_name(), sys_env_serial());
if (core0_task() == false) {
sys_printf("Main: core 0 task failed\n");
}
// Cleanup and exit
return 0;
}