Index: firmware/App/Services/WatchdogMgmt.c =================================================================== diff -u -rf308cc4c35eab630ebbbde405cfe47d049afeafb -r22f1a58ac8e419353ec004b04e7c765c1d59df2b --- firmware/App/Services/WatchdogMgmt.c (.../WatchdogMgmt.c) (revision f308cc4c35eab630ebbbde405cfe47d049afeafb) +++ firmware/App/Services/WatchdogMgmt.c (.../WatchdogMgmt.c) (revision 22f1a58ac8e419353ec004b04e7c765c1d59df2b) @@ -8,7 +8,7 @@ * @file WatchdogMgmt.c * * @author (last) Quang Nguyen -* @date (last) 21-Jul-2020 +* @date (last) 14-Sep-2020 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 @@ -19,45 +19,50 @@ #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 - +#define MIN_WATCHDOG_PET_INTERVAL_MS 45 ///< Minimum watchdog pet interval. +#define WATCHDOG_POST_TIMEOUT_MS 100 ///< Watchdog POST timeout in ms. +#define WATCHDOG_RECOVERY_TIME_MS 250 ///< Watchdog recovery time in ms. + +/// List of watchdog states. typedef enum Button_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 state start + WATCHDOG_SELF_TEST_STATE_IN_PROGRESS, ///< watchdog self-test state in progress + WATCHDOG_SELF_TEST_STATE_RECOVER, ///< Watchdog self-test state recover + WATCHDOG_SELF_TEST_STATE_COMPLETE, ///< Watchdog self-test state complete + 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; ///< Previous watchdog pet timestamp (in ms). -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 U32 watchdogSelfTestTimerCount = 0; - +static WATCHDOG_SELF_TEST_STATE_T watchdogSelfTestState; ///< Watchdog self-test current state. +static SELF_TEST_STATUS_T watchdogSelfTestStatus; ///< Watchdog self-test status. +static U32 watchdogSelfTestTimerCount = 0; ///< Watchdog self-test timer count. + // ********** private function prototypes ********** static void resetWDTaskCheckIns( void ); static BOOL haveAllTasksCheckedIn( void ); static void petWatchdog( void ); -static DATA_ARRAY_GET_PROTOTYPE( BOOL, hasTaskGeneralCheckedIn, task ); - -/************************************************************************* - * @brief initWatchdogMgmt - * The initWatchdogMgmt function initializes the watchdog mgmt. module. - * @details - * Inputs : none - * Outputs : Watchdog mgmt. module initialized. +static BOOL hasTaskGeneralCheckedIn( U32 task ); + +/*********************************************************************//** + * @brief + * The initWatchdogMgmt function initializes the WatchdogMgmt module. + * @details Inputs: none + * @details Outputs: WatchdogMgmt module initialized. * @return none *************************************************************************/ void initWatchdogMgmt( void ) @@ -77,13 +82,12 @@ watchdogTaskCheckedIn[ i ].override = OVERRIDE_RESET; } } - -/************************************************************************* - * @brief execWatchdogMgmt - * The execWatchdogMgmt function executes thewatchdog mgmt. service. - * @details - * Inputs : none - * Outputs : + +/*********************************************************************//** + * @brief + * The execWatchdogMgmt function executes the watchdog management service. + * @details Inputs: watchdogTaskCheckedIn[] + * @details Outputs: Pets watchdog when all tasks checked in * @return none *************************************************************************/ void execWatchdogMgmt( void ) @@ -98,13 +102,13 @@ // if all monitored tasks checked in, pet watchdog and clear the slate if ( ( TRUE == allTasksCheckedIn ) && ( didTimeout( lastWatchdogPetTime, MIN_WATCHDOG_PET_INTERVAL_MS ) ) ) - { - petWatchdog(); + { + petWatchdog(); resetWDTaskCheckIns(); } // check to see if watchdog has expired - if ( getCPLDWatchdogExpired() == PIN_SIGNAL_HIGH ) + if ( PIN_SIGNAL_LOW == getCPLDWatchdogExpired() ) { // ignore expired watchdog until after watchdog POST if ( WATCHDOG_SELF_TEST_STATE_COMPLETE == watchdogSelfTestState ) @@ -115,15 +119,14 @@ } } } - -/************************************************************************* - * @brief checkInWithWatchdogMgmt - * The checkInWithWatchdogMgmt function checks a given task in with the \n - * 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 + +/*********************************************************************//** + * @brief + * The checkInWithWatchdogMgmt function checks a given task in with the + * watchdog management service. + * @details Inputs: none + * @details Outputs: task is checked in with the watchdog management + * @param task the task that is checking in with the watchdog management * @return none *************************************************************************/ void checkInWithWatchdogMgmt( TASK_T task ) @@ -133,15 +136,13 @@ watchdogTaskCheckedIn[ task ].data = TRUE; } } - -/************************************************************************* - * @brief execWatchdogTest - * The execWatchdogTest function executes the watchdog test. \n - * This function should be called periodically until a pass or fail \n - * result is returned. - * @details - * Inputs : - * Outputs : + +/*********************************************************************//** + * @brief + * The execWatchdogTest function executes the watchdog test. This function + * should be called periodically until a pass or fail result is returned. + * @details Inputs: watchdogSelfTestState + * @details Outputs: Executed watchdog self-test * @return in progress, passed, or failed *************************************************************************/ SELF_TEST_STATUS_T execWatchdogTest( void ) @@ -160,13 +161,13 @@ { // waiting here for w.d. test period to prevent this task from checking in - watchdog should expire } - if ( getCPLDWatchdogExpired() == PIN_SIGNAL_HIGH ) + if ( PIN_SIGNAL_LOW == getCPLDWatchdogExpired() ) { watchdogSelfTestStatus = SELF_TEST_STATUS_PASSED; } else { - activateAlarmNoData( ALARM_ID_WATCHDOG_POST_TEST_FAILED ); + activateAlarmNoData( ALARM_ID_DG_WATCHDOG_POST_TEST_FAILED ); watchdogSelfTestStatus = SELF_TEST_STATUS_FAILED; } watchdogSelfTestTimerCount = getMSTimerCount(); @@ -182,7 +183,7 @@ 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; @@ -195,13 +196,12 @@ 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. + * @details Inputs: none + * @details Outputs: watchdogTaskCheckedIn[] array reset to all false. * @return none *************************************************************************/ static void resetWDTaskCheckIns( void ) @@ -214,14 +214,13 @@ watchdogTaskCheckedIn[ i ].data = FALSE; } } - -/************************************************************************* - * @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 + * @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 ) @@ -241,26 +240,43 @@ return result; } - -/************************************************************************* - * @brief hasTaskGeneralCheckedIn - * The hasTaskGeneralCheckedIn function gets the check-in state of a given /n - * task. - * @details - * Inputs : watchdogTaskCheckedIn[] - * Outputs : none + +/*********************************************************************//** + * @brief + * The hasTaskGeneralCheckedIn function gets the check-in state of a given task. + * @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 ) - -/************************************************************************* - * @brief petWatchdog - * The petWatchdog function pets the watchdog by pulsing the CPLD WD pet /n - * signal. - * @details - * Inputs : none - * Outputs : CPLD WD pet signal is pulsed +static 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 + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_TASK, task ); + } + + return result; +} + +/*********************************************************************//** + * @brief + * The petWatchdog function pets the watchdog by pulsing the CPLD WD pet signal. + * @details Inputs: none + * @details Outputs: CPLD WD pet signal is pulsed * @return none *************************************************************************/ static void petWatchdog( void ) @@ -276,19 +292,59 @@ /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ + - -/************************************************************************* - * @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[] +/*********************************************************************//** + * @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; +} + +/**@}*/