Package ej.hal

Class 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 void checkpoint​(int checkpointId)
      Validates the checkpoint identified by the given checkpointId and refreshes the watchdog if all checkpoints are passed.
      static int getWatchdogTimeoutMs()
      Gets the configured watchdog timeout period (in milliseconds).
      static void init()
      Initializes the watchdog timer and the checkpoints registration system.
      static boolean isResetCause()
      Checks whether the last reset was caused by the watchdog or not.
      static int registerCheckpoint()
      Registers a watchdog checkpoint and returns its corresponding Id.
      static void start()
      Starts the watchdog timer.
      static void stop()
      Stops the watchdog timer and unregisters all existing checkpoints.
      static void unregisterCheckpoint​(int checkpointId)
      Unregisters the checkpoint with the given checkpointId.
    • Method Detail

      • init

        public static void init()
                         throws WatchdogTimerException
        Initializes 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 WatchdogTimerException
        Starts 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 WatchdogTimerException
        Stops 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 WatchdogTimerException
        Registers 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.
      • checkpoint

        public static void checkpoint​(int checkpointId)
                               throws WatchdogTimerException,
                                      IllegalArgumentException
        Validates the checkpoint identified by the given checkpointId and 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 WatchdogTimerException
        Checks 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 WatchdogTimerException
        Gets the configured watchdog timeout period (in milliseconds).
        Returns:
        the watchdog timeout period.
        Throws:
        WatchdogTimerException - if an error occurs.