Hercules-EBX CPU User Manual V1.02
Page 105
16. WATCHDOG TIMER PROGRAMMING
16.1 Example : Watchdog Timer With Software Trigger
Software trigger relies on a thread of execution to constantly trigger watchdog timer A. If the
thread is ever halted, timer A will reach zero and start timer B. Once timer B reaches 0, the board
will reset.
In this example we will set the watchdog timer to a countdown period of 4 seconds. Note that
longer timeout periods should typically be used when relying on software-based triggers for the
Watchdog Timer in order to accommodate varying software latencies (Interrupt latencies, other
tasks with priority at certain times, etc)
Setting up the watchdog timer:
outp(base + 0, 0x00);
//set page 0
outp(base + 28, 40000 & 0xFF);
//set LSB of WD timer A (4 seconds)
outp(base + 29, (40000 >> 8) & 0xFF);
//set MSB of WD timer A
outp(base + 30, 0xFF);
//set WD timer B to 0.0255 seconds
outp(base + 31, 0x28);
//set WDEN=1, WDRST=1 (enable WD timer, reset)
The timer is now setup and active. A separate thread should now be constantly running this
code:
while (1)
{
outp(base + 31, 0x80);
//trigger watchdog timer
sleep(1000);
//sleep one second
}
If this thread is interrupted or if the parent process crashes, then the board will reset 4 seconds
after the last trigger is received.