Watchdog Driver
The hardware watchdog timer is a specialized timer with its timing output connected to the circuit's reset terminal. In a productized embedded system, a watchdog is typically required to enable automatic system reset under abnormal conditions.
When the watchdog is started, its counter starts counting automatically. If the counter value is not reset before it overflows, the counter overflow will trigger a reset signal to the CPU, causing the system to restart. When the system is running, the watchdog counter must be cleared within the allowed time interval (a process commonly known as "feeding the dog"), which prevents the generation of a reset signal. Timely dog feeding ensures proper system functioning; failure to do so will result in automatic system reset.
In general, users can feed the dog in RT-Thread's idle hook function or key function.
The application accesses the watchdog hardware through the I/O device management interface provided by RT-Thread. The related interfaces are listed as follows:
| Function | Description |
|---|---|
| rt_device_find() | Finds the device handle based on the watchdog device name. |
| rt_device_init() | Initializes the watchdog device. |
| rt_device_control() | Controls the watchdog device. |
| rt_device_close() | Closes the watchdog device. |
The RTOS contains a watchdog driver and a test program that is located at rtthread/bsp/starfive/libraries/driver/drv_wdt.c.
Run the test program as follows:
Test description: Start the watchdog device and set the timeout value to 1 second. The dog must be fed within 1 second. Otherwise, the board will restart.
