20
Programming Watchdog Timer
Embedded and Industrial Computing
Appendix F
Appendix F:
Programming Watchdog
Timer
A watchdog timer is a piece of hardware that can be
used to automatically detect system anomalies and reset
the processor in case there are any problems. Generally
speaking, a watchdog timer is based on a counter that
counts down from an initial value to zero. The software
selects the counter’s initial value and periodically restarts
it. Should the counter reach zero before the software
restarts it, the software is presumed to be malfunctioning
and the processor’s reset signal is asserted. Thus, the
processor will be restarted as if a human operator had
cycled the power.
For sample watchdog code, see
watchdog
folder under
LEC-2055 Utility on the
Driver and Manual CD
Executing through the DOS Command Line:
Execute the 83627WD.exe xxx (xxx=1-255 sec) under
DOS (83627WD.exe and CWSDPMI.EXE should be placed
in the same directory), then enter the values from 0~255.
The system will reboot automatically according to the
time-out you set. For sample code, look into the DOS/WD
folder.
Compile and Executing in Linux:
To run the Watchdog sample code, you will need
to compile first by running make with the Makefile
contained in the source code. After compilation, you will
have the following binary files:
1. wdrs_drv.ko (Kernel mode driver module)
2. wdrs_test (the executable Watchdog program)
Note
: You have to run “mknod /dev/wdrs_drv c 244 0” to
create the device file as driver installation. For source code,
look into the linux/watchdog_reset folder. Make sure you
copy all files within the folder to the destination.
The following shows the sample code 83627uhg_wdto
file:
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include <stdlib.h>
#include <inlines/pc.h>
#include <pc.h>
#include <unistd.h>
#define index_port 0x2e
#define data_port 0x2f
void help()
{
printf(“\t\t Lanner Electronics Inc. 2010-01-
06\n”);
printf(“\t\t Watchdog timer reset for VES-403\
n\n”);
printf(“Please input : 83627WD.exe xxx (1-255 sec)
(Watchdog Control - SYSTEM RESET)\n”);
printf(“\n”);
}
int main (int argc, char *argv[])
{
clrscr();
int i, time;
if( argc < 1 || argc != 2 )
{
help();
printf(“\t\t argc = %d\n”, argc);
for (i = 0; i < argc; ++i)
{
printf(“\t\t argv[%d] = %s\n”, i , argv[i]);
}
return -1;