How can I use the hardware watchdog and can the timeout be set below 5 sec e.g. 1sec?

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
  1. 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?

  2. 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;
	}
}

https://forums.developer.nvidia.com/t/how-can-i-change-the-timeout-value-and-kick-watchdog-on-jetson-tx1/46069?u=lars2

Yes, it’s the same with TX1.
Did you confirm unable set 1s?

Hi @ShaneCCC,

I tried to compile the above example and can confirm I’m able to set the watchdog time to 1sec even though the value is outside the 5 - 1000 range. Thanks!

Can you confirm that /dev/watchdog0 is in fact the SoC hardware watchdog timer on Xavier?

tegra wdt hardware and kernel driver does not apply any such restriction, you can reduce the timeout to as low as 1 sec