NVIDIA Tegra
NVIDIA Tegra Linux Driver Package

Development Guide
28.1 Release


 
Watchdog Timer
If an application terminates or hangs, a Watchdog timer eventually expires, triggering a CPU reset, and enabling the system to recover without user intervention.
Note: For information about the available Tegra Watchdog Timers and configurations, see the “Watchdog Timers (WDTs)” section of the Tegra Technical Reference Manual (TRM) for your chip.
WDT0 is not enabled in the Linux kernel by default; to enable, see To enable WDT0 from the Linux kernel or To enable WDT0 from user space. This hardware, when turned on, has a timer that starts decrementing. The default timeout value is 120 seconds. For Linux for Tegra (L4T), WDT0 is configured to use TIMER7; therefore, TIMER7 must not be used for any other purpose. When the timeout condition occurs, the WDT0 hardware sends a reset signal to the CPU that causes it to reset.
You can enable WDT0 from the kernel or from user space. If WDT0 is enabled in the kernel, during kernel boot, the kernel loads the WDT0 driver and then starts resetting, or “kicking” WDT0. This prevents the device restarting under normal operation.
If you already enabled the default WDT0 driver from the Linux kernel, your applications in the user space do not need to kick WDT0.
Alternatively, applications can manually enable WDT0 from user space using standard Linux system calls and then by kicking the watchdog periodically. For more information, see the sample code in To enable WDT0 from user space.
Normally, enabling WDT0 enablement is sufficient for system monitoring. If you need to enable Watchdog on other CPUs or AVP, you must modify the WDT driver.
To enable WDT0 from the Linux kernel
1. Go to the kernel configuration file:
arch/arm/configs/tegra21/18_defconfig
2. Add the following 2 lines under CONFIG_WATCHDOG_NOWAYOUT=y:
CONFIG_TEGRA_WATCHDOG=y
CONFIG_TEGRA_WATCHDOG_ENABLE_ON_PROBE=y
To modify the WDT0 timeout value
1. Go to the WDT kernel driver:
drivers/watchdog/tegra_wdt.c
2. Modify the heartbeat value. The default value is 120 seconds. The example below changes the timeout value to 60 seconds:
-static int heartbeat = 120;
+static int heartbeat = 60;
To enable WDT0 from user space
1. Go to the kernel configuration file:
arch/arm/configs/tegra12_defconfig
2. Add the following line under CONFIG_WATCHDOG_NOWAYOUT=y:
CONFIG_TEGRA_WATCHDOG=y
The WDT0 device node is /dev/watchdog0. The following user-space sample code shows opening, enabling, obtaining and specifiying the timeout value, and kicking the watchdog timer.
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;
}