Appendix a: programming watchdog timer, Appendix a, Programming watchdog timer – Lanner LEC-7100 User Manual
Page 31

28
Programming Watchdog Timer
Embedded and Industrial Computing
Appendix A
Appendix A:
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-7100 Utility on the Driver and Manual CD
Executing through the Command Line:
Execute the WD.EXE file under DOS (WD.EXE and CWSDPMI.
EXE should be placed on same directory), then enter the
values from 0~255. The system will reboot automatically
according to the time-out you set.
Watch Dog sample code:
#include
#include
#include
#include
#include
#define INDEX_PORT 0x2e
#define DATA_PORT 0x2f
void help()
{
printf(“Watchdog timer control for EM-9345\n\n”);
printf(“wd.exe -wr xxx (1-255 sec)(Watchdog Control -
SYSTEM RESET)\n”);
printf(“\n”);
}
int main(int argc, char *argv[])
{
int temp, time;
if( argc < 2 )
{
help();
return -1;
}
if( strcmp(argv[1], “-wr”) == 0 )
{
if( argc != 3 )
{
help();
return -1;
}
write_w83627_reg(0x8, 0xf6, 0); //LDN=8, CRF6, stop
timer first
//clear status bit
write_w83627_reg(0x8, 0xf7, read_w83627_reg(0x8, 0xf7)
& 0xef);
time = atoi(argv[2]);
printf(“Setting Watchdog timer for System Reset...\n”);
set_watchdog(time);
return 0;
}
else
{
help();
return -1;
}
return 0;
}
int set_watchdog(int time)
{
int temp;
outportb(INDEX_PORT, 0x87);
delay(1);
outportb(INDEX_PORT, 0x87); //Entering
W83627HF Configuration
temp = read_w83627_reg(0, 0x2b); //LDN=0, CR2B
temp &= 0xf3;