Elektra CPU User Manual V1.00
Page 77
19.3 Example : Watchdog Timer With Software Trigger
Software trigger relies on a thread of execution to constantly trigger WDT. If the thread is ever
halted, WDT will reach zero and initiate the reset sequence.
In this example we will set the watchdog timer to a countdown period of 2.175 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(0x25D, 0xF0);
//set WDT to 15 (2.175 sec)
outp(0x25F, inp(0x25F) | 0x10);
//set WDEN chip select high to enable WDT.
The timer is now setup and active. A separate thread should be constantly running this code:
while (1)
{
outp(0x25C, 0x10);
//reset WDT
sleep(1000);
//sleep one second
}
If this thread is interrupted or if the parent process crashes, then the board will reset 2 seconds
after the last trigger is received.
19.4 Example : Watchdog Timer With Hardware Trigger
Hardware trigger relies on an external pulse to constantly retrigger WDT. If the external stream of
pulses is ever halted, WDT will reach zero and initiate the reset sequence.
In this example, we will make use of the “WDOEN” feature to automatically reset WDT unless a
physical connection is broken. The physical connection must be made between WDO and WDI
on the watchdog header J6.
Since software is not involved in maintaining the timer, we can set the reset period to a much
smaller value. In this example, the reset pulse will travel across the physical connection every 435
milliseconds.
outp(0x25D, 0x30);
//set WDT to 3 (435 ms)
outp(0x25E, 0xD0);
//set WDIEN=1, WDOEN=1, WDEDGE=1
outp(0x25F, inp(0x25F) | 0x10);
//set WDEN chip select
Now when WDT reaches 1, a rising edge will flow from WDO to WDI, resetting the timer back to 3
and lowering the signal on WDO. When the connection from WDO to WDI is severed, the rising
edge will never reach WDI and the system will reset.