A watchdog timer (WDT) is used by a computer system to identify and recover from unexpected interruptions. Watchdog timers are especially important in remote and embedded applications. If the computer “hangs” or needs to be reset, a watchdog timer can be used to automate the recovery process, saving downtime and eliminating the need for the system to be constantly monitored by an operator.
As the BeagleBone Black begins to be more frequently deployed in commercial settings, ensuring reliable operation is paramount. Fortunately, the BeagleBone Black comes equipped with built-in watchdog timer functionality. Our new Inspire tutorial provides step by step instructions for accessing and activating the BeagleBone Black watchdog timer.
The BeagleBone Black has an embedded watchdog timer that can be very useful in providing a reset function.
A watchdog timer will:
- Allow enough time for the system to boot before triggering a reset.
- Needs to receive periodic signals from the critical program (I’m alive and well).
- Reset the system, if the program becomes unresponsive (fails to report on time).
On the BeagleBone Black, the watchdog timer is activated by accessing the system device /dev/watchdog.
cat > /dev/watchdog
The watchdog function is initially activated by writing to /dev/watchdog.
This enables the watchdog, and it must now be periodically accessed. The initial period is about 60 seconds.
Your application program, should then access the watchdog timer to ensure that under normal operation the time interval is satisfied. Failing to write to the watchdog will cause a forced system reset. This is what we would like to happen if our program has become unresponsive.
Testing The Watchdog
To test the watchdog, simply write to the watchdog.
cat > /dev/watchdog
Wait about 60 seconds and your BeagleBone will reset and reboot.
On the other hand, if you issue the command again, before the timer has elapsed, the reset will be delayed further. These simple steps will help you test the watchdog timer.
NOTE: The watchdog is enabled once you FIRST write to /dev/watchdog, otherwise it is in-active.
There are many approaches to implementing the watchdog ‘keep alive’ function. A simple method is to regularly issue a system command from the programming language chosen. Another method is to simply open the file ‘/dev/watchdog’ for writing.
This tutorial shows an example of issuing a system command using bonescript (exec child process).
BoneScript also has a simple method to automatically run a program. In Bonescript, simply drop the program into the AUTORUN folder.
Similar execution of system functions exist for Python and C/C++. The implementation will vary based on the application needs.
A simple python example:
time.sleep(60) # Wait before starting
wd = open("/dev/watchdog", "w+")
Is it time for you to implement your own watchdog timer application?