This chapter introduces the use of the YY3588 watchdog, including driver files, device tree configuration, command line usage, use in programs, and a small demo of actual use
The driver location file is kernel-6.10/drivers/watchdog/dw_wdt.c
watchdog is turned on by default, and the device tree configuration is as follows (you can also refer to it if you need to turn it off)
# View nodes
ls -l /dev/watchdog
# Write any content (except the capital letter 'V'), turn on the watchdog --- The dog needs to be fed once every 44 seconds
echo A > /dev/watchdog
# Turn on the watchdog --- The kernel feeds the dog every 21 seconds echo V > /dev/watchdog ``` ### 2.2 C language small demo ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <sys/ioctl.h> #include <linux/types.h> #include <linux/watchdog.h> int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "Usage: %s <timeout>\n", argv[0]); return 1; } int timeout = atoi(argv[1]); printf("Timeout is set to %d seconds\n", timeout); int current_timeout; int num = 0; int fd = open("/dev/watchdog", O_RDWR); if (fd == -1) { perror("open /dev/watchdog"); exit(EXIT_FAILURE); } if (ioctl(fd, WDIOC_SETTIMEOUT, &timeout) == -1) { perror("ioctl WDIOC_SETTIMEOUT"); close(fd); exit(EXIT_FAILURE); } if (ioctl(fd, WDIOC_GETTIMEOUT, ¤t_timeout) == -1) { perror("ioctl WDIOC_GETTIMEOUT"); close(fd); exit(EXIT_FAILURE); } printf("Current watchdog timeout is %d seconds\n", current_timeout); while (1) { if (ioctl(fd, WDIOC_KEEPALIVE, NULL) == -1) {
perror("ioctl WDIOC_KEEPALIVE");
close(fd);
exit(EXIT_FAILURE);
}
printf("%d : feed the dog, Ctrl+c to exit.\n", ++num);
sleep(10);
}
close(fd);
printf("Watchdog device closed\n");
return 0;
}
Use the cross compiler SDK/prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc
in the SDK to compile and generate an executable file, and push it to the board to run.
The effect is as follows:
$ ./a.out 5
Timeout is set to 5 seconds
Current watchdog timeout is 5 seconds
feed the dog
feed the dog
The WDT accuracy is only 16 levels, and the difference between adjacent levels is relatively large, so it is impossible to count accurately.
For the set duration and actual duration, refer to the following table
Timeout requested by command line | Timeout obtained by program through ioctl | Timeout finally set by watchdog |
---|---|---|
> 89 | timeout_get = timeout_request | 89 |
44 < timeout_request <= 89 | 89 | 89 |
22 < timeout_request <= 44 | 44 | 44 |
11 < timeout_request <= 22 | 22 | 22 |
5 < timeout_request <= 11 | 11 | 11 |
2 < timeout_request <= 5 | 5 | 5 |
timeout_request = 2 | 2 | 2 |
timeout_request = 1 | 1 | 1 |
# Pause count
io -4 0xfd58c000 0x00010001
# Resume count
io -4 0xfd58c000 0x00100000