Index: firmware/App/Services/WatchdogMgmt.c =================================================================== diff -u -r5bec978fa9cce89bbf8c559f0844b7528a10c0d1 -r8e7158d8231435496fcf1d5649e51babf859ccc7 --- firmware/App/Services/WatchdogMgmt.c (.../WatchdogMgmt.c) (revision 5bec978fa9cce89bbf8c559f0844b7528a10c0d1) +++ firmware/App/Services/WatchdogMgmt.c (.../WatchdogMgmt.c) (revision 8e7158d8231435496fcf1d5649e51babf859ccc7) @@ -1,48 +1,55 @@ -/************************************************************************** - * - * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. - * - * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN - * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. - * - * @file WatchdogMgmt.c - * - * @date 20-Sep-2019 - * @author S. Nash - * - * @brief Monitor for the off and stop buttons. - * - **************************************************************************/ +/************************************************************************** +* +* Copyright (c) 2019-2021 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file WatchdogMgmt.c +* +* @author (last) Sean Nash +* @date (last) 24-Sep-2020 +* +* @author (original) Dara Navaei +* @date (original) 05-Nov-2019 +* +***************************************************************************/ #include "CPLD.h" #include "SafetyShutdown.h" #include "SystemCommMessages.h" #include "Timers.h" #include "WatchdogMgmt.h" +/** + * @addtogroup WatchdogMgmt + * @{ + */ + // ********** private definitions ********** -#define MIN_WATCHDOG_PET_INTERVAL_MS 45 -#define WATCHDOG_POST_TIMEOUT_MS 100 -#define WATCHDOG_RECOVERY_TIME_MS 250 - -typedef enum Button_Self_Test_States +#define MIN_WATCHDOG_PET_INTERVAL_MS 45 ///< Minimum watchdog pet interval (in ms). +#define WATCHDOG_POST_TIMEOUT_MS 100 ///< Watchdog POST test timeout (in ms). +#define WATCHDOG_RECOVERY_TIME_MS 250 ///< After watchdog POST test, wait this long (in ms) before moving on. + +/// Enumeration of watchdog self-test states. +typedef enum Watchdog_Self_Test_States { - WATCHDOG_SELF_TEST_STATE_START = 0, - WATCHDOG_SELF_TEST_STATE_IN_PROGRESS, - WATCHDOG_SELF_TEST_STATE_RECOVER, - WATCHDOG_SELF_TEST_STATE_COMPLETE, - NUM_OF_WATCHDOG_SELF_TEST_STATES + WATCHDOG_SELF_TEST_STATE_START = 0, ///< Watchdog self-test start state + WATCHDOG_SELF_TEST_STATE_IN_PROGRESS, ///< Watchdog self-test in progress state + WATCHDOG_SELF_TEST_STATE_RECOVER, ///< Watchdog self-test recovery state + WATCHDOG_SELF_TEST_STATE_COMPLETE, ///< Watchdog self-test completed state + NUM_OF_WATCHDOG_SELF_TEST_STATES ///< Number of watchdog self-test states } WATCHDOG_SELF_TEST_STATE_T; // ********** private data ********** -static U32 lastWatchdogPetTime = 0; +static U32 lastWatchdogPetTime = 0; ///< Timestamp (ms counter) since last watchdog pet. -DATA_ARRAY_DECL( BOOL, TaskCheckIns, NUM_OF_TASKS, watchdogTaskCheckedIn ); +static OVERRIDE_U32_T watchdogTaskCheckedIn[ NUM_OF_TASKS ]; ///< Array of flags indicating whether individual tasks have checked in with watchdog manager. -static WATCHDOG_SELF_TEST_STATE_T watchdogSelfTestState = WATCHDOG_SELF_TEST_STATE_START; -static SELF_TEST_STATUS_T watchdogSelfTestStatus; +static WATCHDOG_SELF_TEST_STATE_T watchdogSelfTestState = WATCHDOG_SELF_TEST_STATE_START; ///< Current watchdog self-test state. +static SELF_TEST_STATUS_T watchdogSelfTestStatus; ///< Watchdog self-test state timer counter. static U32 watchdogSelfTestTimerCount = 0; // ********** private function prototypes ********** @@ -52,13 +59,11 @@ static void petWatchdog( void ); static DATA_ARRAY_GET_PROTOTYPE( BOOL, hasTaskGeneralCheckedIn, task ); -/************************************************************************* - * @brief initWatchdogMgmt +/*********************************************************************//** + * @brief * The initWatchdogMgmt function initializes the watchdog mgmt. module. - * @details - * Inputs : none - * Outputs : Watchdog mgmt. module initialized. - * @param none + * @details Inputs: none + * @details Outputs: Watchdog mgmt. module initialized. * @return none *************************************************************************/ void initWatchdogMgmt( void ) @@ -79,13 +84,11 @@ } } -/************************************************************************* - * @brief execWatchdogMgmt +/*********************************************************************//** + * @brief * The execWatchdogMgmt function executes thewatchdog mgmt. service. - * @details - * Inputs : none - * Outputs : - * @param none + * @details Inputs: watchdogTaskCheckedIn[] + * @details Outputs: watchdogTaskCheckedIn[] * @return none *************************************************************************/ void execWatchdogMgmt( void ) @@ -124,14 +127,13 @@ } -/************************************************************************* - * @brief checkInWithWatchdogMgmt - * The checkInWithWatchdogMgmt function checks a given task in with the \n +/*********************************************************************//** + * @brief + * The checkInWithWatchdogMgmt function checks a given task in with the * watchdog mgmt. service. - * @details - * Inputs : none - * Outputs : task is checked in with the watchdog mgmt.. - * @param task : the task that is checking in with the watchdog mgmt. + * @details Inputs: none + * @details Outputs: task is checked in with the watchdog mgmt.. + * @param task the task that is checking in with the watchdog mgmt * @return none *************************************************************************/ void checkInWithWatchdogMgmt( TASK_T task ) @@ -142,15 +144,13 @@ } } -/************************************************************************* - * @brief execWatchdogTest - * The execWatchdogTest function executes the watchdog test. \n - * This function should be called periodically until a pass or fail \n +/*********************************************************************//** + * @brief + * The execWatchdogTest function executes the watchdog test. + * This function should be called periodically until a pass or fail * result is returned. - * @details - * Inputs : - * Outputs : - * @param none + * @details Inputs: watchdogSelfTestState + * @details Outputs: watchdogSelfTestState * @return in progress, passed, or failed *************************************************************************/ SELF_TEST_STATUS_T execWatchdogTest( void ) @@ -191,27 +191,25 @@ break; case WATCHDOG_SELF_TEST_STATE_COMPLETE: - // if we get called in this state, assume we're doing self test again + // if we get called in this state, assume we're doing self-test again watchdogSelfTestStatus = SELF_TEST_STATUS_IN_PROGRESS; watchdogSelfTestState = WATCHDOG_SELF_TEST_STATE_START; break; default: result = SELF_TEST_STATUS_FAILED; - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_WATCHDOG_INVALID_SELF_TEST_STATE, watchdogSelfTestState ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_WATCHDOG_INVALID_SELF_TEST_STATE, watchdogSelfTestState ) break; } return result; } -/************************************************************************* - * @brief resetWDTaskCheckIns +/*********************************************************************//** + * @brief * The resetWDTaskCheckIns function resets the task check-ins with the watchdog. - * @details - * Inputs : none - * Outputs : watchdogTaskCheckedIn[] array reset to all false. - * @param none + * @details Inputs: none + * @details Outputs: watchdogTaskCheckedIn[] array reset to all false. * @return none *************************************************************************/ static void resetWDTaskCheckIns( void ) @@ -225,14 +223,12 @@ } } -/************************************************************************* - * @brief haveAllTasksCheckedIn - * The haveAllTasksCheckedIn function determines whether all tasks have /n +/*********************************************************************//** + * @brief + * The haveAllTasksCheckedIn function determines whether all tasks have * checked in with watchdog mgmt. - * @details - * Inputs : watchdogTaskCheckedIn[] - * Outputs : none - * @param none + * @details Inputs: watchdogTaskCheckedIn[] + * @details Outputs: none * @return TRUE if all tasks have checked in since last watchdog pet, FALSE if not. *************************************************************************/ static BOOL haveAllTasksCheckedIn( void ) @@ -253,26 +249,44 @@ return result; } -/************************************************************************* - * @brief hasTaskGeneralCheckedIn - * The hasTaskGeneralCheckedIn function gets the check-in state of a given /n +/*********************************************************************//** + * @brief + * The hasTaskGeneralCheckedIn function gets the check-in state of a given * task. - * @details - * Inputs : watchdogTaskCheckedIn[] - * Outputs : none - * @param task : ID of task to check + * @details Inputs: watchdogTaskCheckedIn[] + * @details Outputs: none + * @param task ID of task to check * @return TRUE if given task has checked in, FALSE if not *************************************************************************/ -static DATA_ARRAY_GET( BOOL, hasTaskGeneralCheckedIn, task, NUM_OF_TASKS-1, watchdogTaskCheckedIn, FALSE ) +BOOL hasTaskGeneralCheckedIn( U32 task ) +{ + BOOL result = FALSE; + + if ( task < NUM_OF_TASKS ) + { + if ( OVERRIDE_KEY == watchdogTaskCheckedIn[ task ].override ) + { + result = (BOOL)watchdogTaskCheckedIn[ task ].ovData; + } + else + { + result = (BOOL)watchdogTaskCheckedIn[ task ].data; + } + } + else + { + activateAlarmNoData( ALARM_ID_HD_SOFTWARE_FAULT ); + } + + return result; +} -/************************************************************************* - * @brief petWatchdog - * The petWatchdog function pets the watchdog by pulsing the CPLD WD pet /n +/*********************************************************************//** + * @brief + * The petWatchdog function pets the watchdog by pulsing the CPLD WD pet * signal. - * @details - * Inputs : none - * Outputs : CPLD WD pet signal is pulsed - * @param none + * @details Inputs: none + * @details Outputs: CPLD WD pet signal is pulsed * @return none *************************************************************************/ static void petWatchdog( void ) @@ -292,17 +306,57 @@ *************************************************************************/ -/************************************************************************* - * @brief testSetWatchdogTaskCheckInOverride and testResetWatchdogTaskCheckInOverride - * The testSetWatchdogTaskCheckInOverride function overrides the state of the \n - * task check-in with the watchdog management with a given check-in state. \n - * The testResetWatchdogTaskCheckInOverride function resets the override of the \n - * state of the check-in with the watchdog management. - * @details - * Inputs : none - * Outputs : watchdogTaskCheckedIn[] - * @param task : ID of task to override check-in state for - * @param value : override state for the given task ID +/*********************************************************************//** + * @brief + * The testSetWatchdogTaskCheckInOverride function overrides the state of the + * task check-in with the watchdog management with a given check-in state. + * @details Inputs: none + * @details Outputs: watchdogTaskCheckedIn[] + * @param task ID of task to override check-in state for + * @param value override state for the given task ID * @return TRUE if override successful, FALSE if not *************************************************************************/ -DATA_ARRAY_OVERRIDE_FUNC( BOOL, testSetWatchdogTaskCheckInOverride, testResetWatchdogTaskCheckInOverride, watchdogTaskCheckedIn, task, NUM_OF_TASKS-1 ) +BOOL testSetWatchdogTaskCheckInOverride( U32 task, BOOL value ) +{ + BOOL result = FALSE; + + if ( task < NUM_OF_TASKS ) + { + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + watchdogTaskCheckedIn[ task ].ovData = value; + watchdogTaskCheckedIn[ task ].override = OVERRIDE_KEY; + } + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetWatchdogTaskCheckInOverride function resets the override of the + * state of the check-in with the watchdog management. + * @details Inputs: none + * @details Outputs: watchdogTaskCheckedIn[] + * @param task ID of task to override check-in state for + * @return TRUE if override reset successful, FALSE if not + *************************************************************************/ +BOOL testResetWatchdogTaskCheckInOverride( U32 task ) +{ + BOOL result = FALSE; + + if ( task < NUM_OF_TASKS ) + { + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + watchdogTaskCheckedIn[ task ].override = OVERRIDE_RESET; + watchdogTaskCheckedIn[ task ].ovData = watchdogTaskCheckedIn[ task ].ovInitData; + } + } + + return result; +} + +/**@}*/