Computers running critical applications, often need a way to be reset if an unexpected event causes the system to become unresponsive. Getting a computer back up and running in a remote location can be costly and frustrating. The BeagleBone Black is being used in more applications, and (unattended) situations where an occasional reset may be required from time-to-time. Fortunately, there is an easy way to do this!
A watchdog timer is a circuit that requires a periodic 'wake up' signal or else it generates a reset pulse.
(Feed-me or I will bark!).
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 WatchdogTo 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.
Programming HintThere 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:
#!/usr/bin/env python import time import os os.nice(20) time.sleep(60) # Wait before starting wd = open("/dev/watchdog", "w+") while 1: wd.write("\n") wd.flush() time.sleep(5)Is it time for you to implement your own watchdog timer application?
Additional InformationLinux watchdog and