refresh_watchdog.cpp 748 Bytes
Newer Older
German Leon's avatar
German Leon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

// iisalive.cpp
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h> // for watchdog timer
#include <unistd.h> // needed only if close() is used to close watchdog timer
#include <sys/ioctl.h> // for watchdog timer
#include <linux/watchdog.h> // for watchdog timer
#include <time.h>

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

/* open WDT0 device (WDT0 enables itself automatically) */
fd = open("/dev/watchdog0", O_RDWR);
if (fd<0) {
fprintf(stderr, "Open watchdog device failed!\r\n");
return -1;
}


ret = ioctl(fd, WDIOC_KEEPALIVE, 0);
if (ret<0) {
fprintf(stderr, "Kick watchdog failed!\r\n");
return -1;
}


close(fd);
if (ret<0) {
fprintf(stderr, "Failed to close watchdog device.");
return -1;
}

return 0;
}