I am working with watchdog now
I wrote a small piece of code to understand the working of software watchdog
#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>
void Keep_Alive(int fd)
{
// int options = 0;
int pretimeout = 10;
int options = 0;
ioctl(fd, WDIOS_ENABLECARD, &options);
ioctl(fd, WDIOC_SETPRETIMEOUT, &pretimeout);
// ioctl(fd, WDIOC_SETOPTIONS, &options);
printf("Watchdog Alive \n");
}
void Kill(int fd)
{
write(fd, "V", 1);
printf("Watchdog killed\n");
}
int main()
{
int fd;
int timeout = 15;
fd = open("/dev/watchdog", O_WRONLY);
if(fd == -1)
{
fprintf(stderr, "Watchdog faild to open");
return ;
}
else
{
ioctl(fd, WDIOC_SETTIMEOUT, &timeout);
printf("The timeout was set to %d seconds\n", timeout);
}
while(1)
{
Keep_Alive(fd);
sleep(10);
}
// Kill(fd);
}
Output :
root@imx6ulevk:/media# ./WatchDog
The timeout was set to 15 seconds
Watchdog Alive
watchdog pre-timeout:10, 5 Seconds remained
Watchdog Alive
U-Boot 2015.04-imx_v2015.04_3.14.38_6ul_ga+g5d63276 (May 16 2016 - 14:32:19)
I am kicking the watchdog for every 10 seconds still the board is rebooting after 15 secs.
What is the wrong i am doing.
i am using imx6ulevk board and 3.14.38 kernel.
Solved! Go to Solution.
my bad i overlooked the options of watchdog.
I changed ioctl(fd, WDIOC_SETPRETIMEOUT, &pretimeout); this line to ioctl(fd, WDIOC_KEEPALIVE, &options);
Hi chandra
one can check if serviced correctly WDOGx_WSR register :
0x5555 Write to the Watchdog Service Register (WDOG_WSR).
0xAAAA Write to the Watchdog Service Register (WDOG_WSR).
use, for example memtool and try to reset wdog.
Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi igorpadykov
How can I write values directly to resgisters in linux?? How can I check the register values?
my bad i overlooked the options of watchdog.
I changed ioctl(fd, WDIOC_SETPRETIMEOUT, &pretimeout); this line to ioctl(fd, WDIOC_KEEPALIVE, &options);