Watchdog
Description
A watchdog is kind of a timer that can reset the chip when it gets stuck. This example show how to use it.
- Pay attention to the following points:
A limit for the timer exists, and depends on the ref clock you are using.
If the watchdog timer is triggered, your chip will reset.
Warning
We don’t have support for watchdog on gvsoc. Therefore, this example can be execute on board only.
Commands
# Create a build repository
cmake -B build
# Manage options
cmake --build build --target menuconfig
# Run the example
cmake --build build --target run
Code
/*
* Copyright (C) 2022 GreenWaves Technologies
* All rights reserved.
*
* This software may be modified and distributed under the terms
* of the BSD license. See the LICENSE file for details.
*/
/* WatchDog example
*
* Set a watchdog timer properly and use it.
*/
/* Note:
* Timer for watchdog is based on RefClk = 24 MHz (Fast) if exist
* or = 32 kHz (Slow) else
* When using the fast clock, it can be divided. For now,
* the clock value is 6 MHz.
*/
#include "pmsis.h"
int main()
{
printf("\n*****\nWhatchDog example\n*****\n");
/* Setting the timer (in us)
* And check if it has been set properly (== 0)
*/
if (pi_watchdog_timer_set(250))
{
printf("Error when setting the watchdog timer.");
/* It can happen if the timer value is to high.
* Remind that regarding the clock the limit will be different.
*/
return -1;
}
/* Starting the countdown
* Executing a task, faster than the timer's limit.
* WatchDog should not be trigger.
*/
printf("Executing first task. No reset should append.\n");
pi_watchdog_start();
pi_time_wait_us(200);
pi_watchdog_stop();
printf("Task faster than the watchdog's timer. Done without reset.\n");
/* In case you try to execute a task that last more than the timer,
* the latter will be trigger and the watchdog will reset the chip.
*/
printf("Executing a second task. No reset should append.\n");
/* To execute a second task that have no attach to the first one (in term of execution time)
* you have to rearm the timer. You can start it again then.
* If you do not rearm it the counter will continue where it stopped.
*/
pi_watchdog_timer_rearm();
pi_watchdog_start();
pi_time_wait_us(300);
pi_watchdog_stop();
printf("Task faster than the watchdog's timer. Done without reset.\n");
return 0;
}