Index: firmware/App/Modes/ModeFault.c =================================================================== diff -u -ra4669c80291e85fa5ce17d77ebcfd0c882831202 -r4b667a7ec18a6196849bbeefdfb23d25d1d58c5a --- firmware/App/Modes/ModeFault.c (.../ModeFault.c) (revision a4669c80291e85fa5ce17d77ebcfd0c882831202) +++ firmware/App/Modes/ModeFault.c (.../ModeFault.c) (revision 4b667a7ec18a6196849bbeefdfb23d25d1d58c5a) @@ -40,12 +40,12 @@ // ********** private data ********** static DG_FAULT_STATE_T faultState; ///< Currently active fault state. -static DG_POST_STATE_T faultPOSTState; ///< Fault POST state. static SELF_TEST_STATUS_T faultPOSTSelfTestResult; ///< Fault POST self test result. // ********** private function prototypes ********** -static DG_FAULT_STATE_T handleRunNVPOSTsState( void ); +static DG_FAULT_STATE_T handleFaultStartState( void ); +static DG_FAULT_STATE_T handleFaultRunNVPOSTsState( void ); /*********************************************************************//** * @brief @@ -57,7 +57,6 @@ void initFaultMode( void ) { faultState = DG_FAULT_STATE_START; - faultPOSTState = DG_POST_STATE_RTC; faultPOSTSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; } @@ -81,11 +80,6 @@ sendPOSTFinalResult( FALSE ); } - // Reset the RTC and NV data management POST states so - // the POSTs can be redone again - resetNVDataMgmtPostState(); - resetRTCPostState(); - setCPLDCleanLEDColor( CPLD_CLEAN_LED_OFF ); return faultState; @@ -106,11 +100,11 @@ switch ( faultState ) { case DG_FAULT_STATE_START: - faultState = DG_FAULT_STATE_RUN_NV_POSTS; + faultState = handleFaultStartState(); break; case DG_FAULT_STATE_RUN_NV_POSTS: - faultState = handleRunNVPOSTsState(); + faultState = handleFaultRunNVPOSTsState(); break; case DG_FAULT_STATE_COMPLETE: @@ -175,44 +169,64 @@ /*********************************************************************//** * @brief - * The handleRunNVPOSTsState function handles running the RTC and non-volatile - * data management POSTs. - * @details Inputs: faultPOSTState, faultPOSTSelfTestResult - * @details Outputs: faultPOSTState, faultPOSTSelfTestResult + * The handleFaultStartState function handles the start state of the fault mode. + * @details Inputs: none + * @details Outputs: none * @return next state *************************************************************************/ -static DG_FAULT_STATE_T handleRunNVPOSTsState( void ) +static DG_FAULT_STATE_T handleFaultStartState( void ) { - DG_FAULT_STATE_T state = DG_FAULT_STATE_RUN_NV_POSTS; + DG_FAULT_STATE_T state = DG_FAULT_STATE_START; + NVDATAMGMT_RECORDS_READ_STATUS status = getNVRecordsReadStatus(); - switch ( faultPOSTState ) + switch ( status ) { - case DG_POST_STATE_RTC: -#ifndef DISABLE_RTC_POST_FAULT - faultPOSTSelfTestResult = execRTCSelfTest(); - if ( SELF_TEST_STATUS_PASSED == faultPOSTSelfTestResult ) + // If the records were not queued make sure there are enough jobs in the queue and + // queue them to be read + case NVDATAMGMT_RECORDS_NOT_STARTED: + // If the NV POST is completed prepare the queues + if ( TRUE == enqueueNVRecordsForRead() ) { - faultPOSTState = DG_POST_STATE_NVDATAMGMT; + state = DG_FAULT_STATE_RUN_NV_POSTS; } - else if ( SELF_TEST_STATUS_FAILED == faultPOSTSelfTestResult ) - { - state = DG_FAULT_STATE_COMPLETE; - } -#else - faultPOSTState = DG_POST_STATE_NVDATAMGMT; -#endif break; - case DG_POST_STATE_NVDATAMGMT: - faultPOSTSelfTestResult = execNVDataMgmtSelfTest(); - if ( ( SELF_TEST_STATUS_PASSED == faultPOSTSelfTestResult ) || ( SELF_TEST_STATUS_FAILED == faultPOSTSelfTestResult ) ) - { - state = DG_FAULT_STATE_COMPLETE; - } + // If the records are queued or already read, go directly to NV POST to process + // their CRCs. + case NVDATAMGMT_RECORDS_QUEUED: + case NVDATAMGMT_RECORDS_READ: + state = DG_FAULT_STATE_RUN_NV_POSTS; break; + + // If the NV post was completed prior to transitioning to fault mode, do nothing + case NVDATAMGMT_RECORDS_CRC_CHECKED: + state = DG_FAULT_STATE_COMPLETE; + break; } return state; } +/*********************************************************************//** + * @brief + * The handleFaultRunNVPOSTsState function handles running non-volatile POSTs. + * @details Inputs: faultPOSTSelfTestResult + * @details Outputs: faultPOSTSelfTestResult + * @return next state + *************************************************************************/ +static DG_FAULT_STATE_T handleFaultRunNVPOSTsState( void ) +{ + DG_FAULT_STATE_T state = DG_FAULT_STATE_RUN_NV_POSTS; + + faultPOSTSelfTestResult = execNVDataMgmtSelfTest(); + + // Regardless of the status of the NV POST transition to the complete state. + if ( ( SELF_TEST_STATUS_PASSED == faultPOSTSelfTestResult ) || ( SELF_TEST_STATUS_FAILED == faultPOSTSelfTestResult ) ) + { + state = DG_FAULT_STATE_COMPLETE; + } + + return state; +} + /**@}*/