Hi,
I want to use the hardware watchdog but can’t find a good guide on how to use it. All information available also seem to mix the hardware watchdog with the linux kernel watchdog timer(softdog). I can confirm the driver is installed with dmesg:
dmesg | grep wdt
[ 1.056557] tegra_wdt_t18x 30c0000.watchdog: Expiry count is deprecated
[ 1.056814] tegra_wdt_t18x 30c0000.watchdog: Tegra WDT init timeout = 120 sec
[ 1.056888] tegra_wdt_t18x 30c0000.watchdog: Registered successfully
-
What do I need to call in my software to kick the timer? I see this example using ioctl on TX1 will it also work on Xavier and is this for the HW watchdog or kernel soft dog?
-
How can I set the timeout value to 1 sec? The below code notes value should be 5 sec or more - why is there a limit?
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/watchdog.h>
int main (void) {
int fd, ret;
int timeout = 0;
/* open WDT0 device (WDT0 enables itself automatically) */
fd = open("/dev/watchdog0", O_RDWR);
if(fd < 0) {
fprintf(stderr, "Open watchdog device failed!\n");
return -1;
}
/* WDT0 is counting now,check the default timeout value */
ret = ioctl(fd, WDIOC_GETTIMEOUT, &timeout);
if(ret) {
fprintf(stderr, "Get watchdog timeout value failed!\n");
return -1;
}
fprintf(stdout, "Watchdog timeout value: %d\n", timeout);
/* set new timeout value 60s */
/* Note the value should be within [5, 1000] */
timeout = 60;
ret = ioctl(fd, WDIOC_SETTIMEOUT, &timeout);
if(ret) {
fprintf(stderr, "Set watchdog timeout value failed!\n");
return -1;
}
fprintf(stdout, "New watchdog timeout value: %d\n", timeout);
/*Kick WDT0, this should be running periodically */
ret = ioctl(fd, WDIOC_KEEPALIVE, NULL);
if(ret) {
fprintf(stderr, "Kick watchdog failed!\n");
return -1;
}
}