WATCHDOG REFERENCE

version 1.0


1. OVERVIEW

Watchdog adopts the standard linux framework and provides hardware watchdog. The upper application can set the time out time and keep alive by itself.

Watchdog is disabled by default. It is recommended to enable it in the main thread. If operating in other threads, the watchdog will be disabled as the thread is closed.


2. WATCHDOG SETTING

2.1. Enable Watchdog

Turn on /dev/watchdog to start watchdog.

The reference code is as follows:

int wdt_fd = -1;  
wdt_fd = open("/dev/watchdog", O_WRONLY); 
if (wdt_fd == -1)  
{  
    // fail to open watchdog device  
}

2.2. Disable Watchdog

The reference code is as follows:

int option = WDIOS_DISABLECARD;

ioctl(wdt_fd, WDIOC_SETOPTIONS, &option);

if (wdt_fd != -1)  
    {  
        close(wdt_fd);  
        wdt_fd = -1;  
    }

2.3. Set Timeout

Use the standard IOCTL command WDIOC_SETTIMEOUT to set the timeout, the unit is second, it is recommended that timeout > 5s.

The reference code is as follows:

#define WATCHDOG_IOCTL_BASE 'W'

#define WDIOC_SETTIMEOUT _IOWR(WATCHDOG_IOCTL_BASE, 6, int)

int timeout = 20;

ioctl(wdt_fd, WDIOC_SETTIMEOUT, &timeout);

2.4. Keep Alive

Command WDIOC_KEEPALIVE input through standard IOCTL. The time is determined according to the set timeout. The input time should be smaller than timeout. The reference code is as follows:

#define WATCHDOG_IOCTL_BASE 'W'

#define WDIOC_KEEPALIVE _IOR(WATCHDOG_IOCTL_BASE, 5, int)

ioctl(wdt_fd, WDIOC_KEEPALIVE, 0);