These tutorials explains the different possibilities to use native (i.e., non-Java) code in your application. There are at least four methods to do this and we have made separate tutorial for each of the methods.
As an example, we integrate a watchdog in an application that runs on a Raspberry Pi.
The Raspberry Pi comes with a hardware-based watchdog and we will use C or C++ code to access it. We cannot use Java directly because we need the
ioctl() system call to access it.
A watchdog timer is a special kind of timer commonly found on embedded systems that detects when the running software is not operating correctly, i.e hung up on some task. The watchdog timer is basically a countdown timer that counts from some initial value down to zero. When zero is reached, the watchdog timer understands that the system is hung up and resets it. Therefore, the running software must periodically update the watchdog timer with a new value to stop it from reaching zero and causing a reset. When the running software is locked up doing a certain task and cannot update the watchdog timer, the timer will inevitably reach zero and a reset will occur.
It is good practice to have a hardware watchdog on embedded systems.
Although linux does have a watchdog daemon that can send heartbeats to the watchdog to monitor if the OS is hanging, the preferred way of integrating a watchdog is to access it from your main application when it operates correctly. Do not make the mistake of updating the watchdog from a separate timer thread, but make sure updates comes from your “main” loop.
To run these particular demos you will need Raspberry Pi with latest version of Raspbian installed.
Do these preparations
sudo modprobe bcm2708_wdog
sudo nano /etc/modules
Note that adding the kernel module does not enable the watchdog.
These are the tutorials for the different methods: