57
RSB-4411
User Manual
Chapter 3
S
oftware
Functionality
3.7.2
Watchdog Timer Sample Code
WatchDog Timer (WDT) sample code is as below:
#include
<stdio.h>
#include
<stdlib.h>
#include
<fcntl.h>
#include
<linux/watchdog.h>
#include
<sys/ioctl.h>
#include
<unistd.h>
void
help_info(void);
int
main(int
argc,
const
char
*argv[])
{
int
fd,
timeout,
sleep_sec,
test;
int
count=1;
if
(argc
<
2)
{
help_info();
return
1;
}
t
imeout
=
atoi(argv[1]);
sleep_sec
=
atoi(argv[2]);
if
(sleep_sec
<=
0)
{
sleep_sec
=
1;
printf("correct
0
or
negative
sleep
time
to
%d
seconds\n",
sleep_sec);
}
test
=
atoi(argv[3]);
printf("Starting
wdt_driver
(timeout:
%d,
sleep:
%d,
test:
%s)\n",
timeout,
sleep_sec,
(test
==
0)
?
"ioctl"
:
"write");
fd
=
open("/dev/watchdog",
O_WRONLY);
if
(fd
==
‐
1)
{
perror("watchdog");
exit(1);
}
printf("Trying
to
set
timeout
value=%d
seconds\n",
timeout);
ioctl(fd,
WDIOC_SETTIMEOUT,
&timeout);
printf("The
actual
timeout
was
set
to
%d
seconds\n",
timeout);
ioctl(fd,
WDIOC_GETTIMEOUT,
&timeout);
printf("Now
reading
back
‐‐
The
timeout
is
%d
seconds\n",
timeout);
while
(1)
{
printf("WDT
Time
out
counter:%d\n",count);
if
((test
!=0)
&&
(test
==count))
{
printf("Ping
Watchdog
(reset
wdt)\n");
ioctl(fd,
WDIOC_KEEPALIVE,
0);
test=0;
Summary of Contents for RSB-4411
Page 2: ...User Manual RSB 4411 3 5 SBC with NXP i MX6 Processor ARM Cortex A9 Architecture ...
Page 11: ...RSB 4411 User Manual x ...
Page 12: ...Chapter 1 1 General Introduction ...
Page 15: ...RSB 4411 User Manual 4 ...
Page 16: ...Chapter 2 2 H W Installation ...
Page 33: ...RSB 4411 User Manual 22 Figure 2 25 M 2 Connector ...
Page 37: ...RSB 4411 User Manual 26 ...
Page 82: ...71 RSB 4411 User Manual Chapter 5 Advantech Services ...