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