This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMDS64GPEVM: Watchdog - cannot simulate timeout

Part Number: TMDS64GPEVM

Hello

I'm trying to simulate watchdog timeout to better understand how things works. I enabled watchdog driver rti_wdt and wrote some example application:

#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/watchdog.h>

int main(int argc, char * argv[]) {

        printf("Watchdog test app\n");

        if(argc < 4) {
                printf("Not all arguments provided!\n");
                exit(EXIT_FAILURE);
        }
        const char * watchdog_dev = argv[1];
        int timeout = atoi(argv[2]);
        int keepalive = atoi(argv[3]);
        printf("timeout: %d | ping time: %d\n",timeout,keepalive);

        struct watchdog_info cap;
        int fd = open(watchdog_dev, O_WRONLY);
        int ret = 0;
        if (fd == -1) {
                perror("watchdog");
                exit(EXIT_FAILURE);
        }
        ret = ioctl(fd,WDIOC_GETSUPPORT,&cap);
        if(ret) {
                printf("failed to get watchdog capabilities! error: %d\n",ret);
        }
        else {
                printf("Watchdog identity: %s\n",cap.identity);
                int current_timeout = 0;
                if(ioctl(fd,WDIOC_GETTIMEOUT,&current_timeout) == 0) {
                        printf("Current timeout: %d\n",current_timeout);
                }
                if(cap.options & WDIOF_MAGICCLOSE) {
                        printf("Magic close feature supported!\n");
                        //setup magic close
                        const char v = 'V';
                        ret = write(fd,&v,1);
                        if(ret) {
                                printf("Failed to set magic close option!\n");
                        }
                }
                if(cap.options & WDIOF_KEEPALIVEPING) {
                        printf("ioctl keepalive ping feature supported!\n");
                }
                if(cap.options & WDIOF_SETTIMEOUT) {
                        printf("settimeout feature supported!\n");
                        if(ioctl(fd,WDIOC_SETTIMEOUT,&timeout) == 0) {
                                printf("watchdog timeout sucessfully set to: %d\n",timeout);
                        }
                }
                if(cap.options & WDIOF_PRETIMEOUT) {
                        printf("pretimeout feature supported!\n");
                }
        }

        while (1) {
                ret = write(fd, "a", 1);
                if (ret != 1) {
                        printf("Failed to kick watchdog! error: %d\n",ret);
                        ret = -1;
                        break;
                }
                int timeleft = 0;
                ret = ioctl(fd, WDIOC_GETTIMELEFT,&timeleft);
                if(ret) {
                        printf("getting time left feature not supported! error: %d\n",ret);
                }
                else {
                        printf("time left: %d s\n",timeleft);
                }
                while(1);
                sleep(keepalive);



        }
        close(fd);
        return ret;
}

For some reason even if timeout is shorter than keepalive intervals between which watchdog is kicked, system reboot does not appear (even when sysfs attribute /sys/class/watchdog/watchdog0/timeleft shows 0). Why?

Below are logs from calling this test app: