Package ej.hal
Class WatchdogTimer
- java.lang.Object
-
- ej.hal.WatchdogTimer
-
public class WatchdogTimer extends Object
This class provides a way to handle watchdog timers. It is implemented over a low level watchdog timer and provides a checkpoint registration system. The registration system allows to add checkpoints monitored by the watchdog.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheckpoint(int checkpointId)Validates the checkpoint identified by the givencheckpointIdand refreshes the watchdog if all checkpoints are passed.static intgetWatchdogTimeoutMs()Gets the configured watchdog timeout period (in milliseconds).static voidinit()Initializes the watchdog timer and the checkpoints registration system.static booleanisResetCause()Checks whether the last reset was caused by the watchdog or not.static intregisterCheckpoint()Registers a watchdog checkpoint and returns its corresponding Id.static voidstart()Starts the watchdog timer.static voidstop()Stops the watchdog timer and unregisters all existing checkpoints.static voidunregisterCheckpoint(int checkpointId)Unregisters the checkpoint with the givencheckpointId.
-
-
-
Method Detail
-
init
public static void init() throws WatchdogTimerExceptionInitializes the watchdog timer and the checkpoints registration system. This method does nothing if the watchdog is already initialized.- Throws:
WatchdogTimerException- if an error occurs.
-
start
public static void start() throws WatchdogTimerExceptionStarts the watchdog timer. This method does nothing if the watchdog is already started.- Throws:
WatchdogTimerException- if the watchdog is not initialized or an error occurs.
-
stop
public static void stop() throws WatchdogTimerExceptionStops the watchdog timer and unregisters all existing checkpoints. This method does nothing if the watchdog is not started.- Throws:
WatchdogTimerException- if an error occurs.
-
registerCheckpoint
public static int registerCheckpoint() throws WatchdogTimerExceptionRegisters a watchdog checkpoint and returns its corresponding Id. The maximum number of checkpoints that can be registered is 32 and the checkpoint Id values are comprise between 0 and 31.- Returns:
- the registered checkpoint Id.
- Throws:
WatchdogTimerException- if we exceed the maximum number of registrations or if watchdog was not initialized.
-
unregisterCheckpoint
public static void unregisterCheckpoint(int checkpointId) throws WatchdogTimerException, IllegalArgumentExceptionUnregisters the checkpoint with the givencheckpointId.- Parameters:
checkpointId- the checkpoint Id to unregister.- Throws:
WatchdogTimerException- if watchdog is not initialized or the checkpointId is not registered.IllegalArgumentException- if checkpointId is out of the range.
-
checkpoint
public static void checkpoint(int checkpointId) throws WatchdogTimerException, IllegalArgumentExceptionValidates the checkpoint identified by the givencheckpointIdand refreshes the watchdog if all checkpoints are passed. Be sure that all the checkpoints are validated before the watchdog timeout expires otherwise a hardware reset will be performed.- Parameters:
checkpointId- the Id of the checkpoint to validate.- Throws:
WatchdogTimerException- if the watchdog is not initialized
if the checkpointId is not registered or an error occurs.IllegalArgumentException- if checkpointId is out of the range.
-
isResetCause
public static boolean isResetCause() throws WatchdogTimerExceptionChecks whether the last reset was caused by the watchdog or not.- Returns:
- true if the last reset was caused by the watchdog; false otherwise.
- Throws:
WatchdogTimerException- if an error occurs.
-
getWatchdogTimeoutMs
public static int getWatchdogTimeoutMs() throws WatchdogTimerExceptionGets the configured watchdog timeout period (in milliseconds).- Returns:
- the watchdog timeout period.
- Throws:
WatchdogTimerException- if an error occurs.
-
-