Index: firmware/App/Modes/ModeInitPOST.c =================================================================== diff -u -r30f049651877229042e3f8700c8596e5b9a1e0f4 -r98e24f0db83de34e3d44c4bd72df9f506f8ceddc --- firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision 30f049651877229042e3f8700c8596e5b9a1e0f4) +++ firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision 98e24f0db83de34e3d44c4bd72df9f506f8ceddc) @@ -19,15 +19,20 @@ #include "AlarmLamp.h" #include "BloodFlow.h" #include "Buttons.h" +#include "Compatible.h" #include "CPLD.h" #include "DialInFlow.h" #include "FPGA.h" -#include "OperationModes.h" -#include "RTC.h" -#include "WatchdogMgmt.h" +#include "Integrity.h" #include "ModeInitPOST.h" #include "NVDataMgmt.h" +#include "OperationModes.h" +#include "RTC.h" +#include "SyringePump.h" +#include "SystemCommMessages.h" +#include "TaskGeneral.h" #include "Valves.h" +#include "WatchdogMgmt.h" /** * @addtogroup HDInitAndPOSTMode @@ -36,16 +41,26 @@ // ********** private definitions ********** +/// Delay (in task intervals) after POST completes. +#define POST_COMPLETED_DELAY ( 2 * MS_PER_SECOND / TASK_GENERAL_INTERVAL ) + + // ********** private data ********** -static HD_POST_STATE_T postState = POST_STATE_START; ///< Current state of initialize and POST mode. -static BOOL postCompleted = FALSE; ///< Flag indicates whether POST is completed. -static BOOL postPassed = FALSE; ///< Flag indicates all POST tests passed. -static BOOL tempPOSTPassed = TRUE; ///< Flag indicates all POST tests have passed so far. +static HD_POST_STATE_T postState; ///< Current state of initialize and POST mode. +static BOOL postCompleted; ///< Flag indicates whether POST is completed. +static BOOL postPassed; ///< Flag indicates all POST tests passed. +static BOOL tempPOSTPassed; ///< Flag indicates all POST tests have passed so far. +static BOOL uiPOSTPassed; ///< Final result for UI POST tests (TRUE = passed, FALSE = failed). +static BOOL dgPOSTPassed; ///< Final result for DG POST tests (TRUE = passed, FALSE = failed). + +static U32 postCompleteDelayTimerCtr; ///< Timer counter for 2 second delay after POST completes and before transitioning to Standbymode. + // ********** private function prototypes ********** static HD_POST_STATE_T handlePOSTStatus( SELF_TEST_STATUS_T testStatus ); +static SELF_TEST_STATUS_T execFWCompatibilityTest( void ); /*********************************************************************//** * @brief @@ -60,6 +75,9 @@ postCompleted = FALSE; postPassed = FALSE; tempPOSTPassed = TRUE; + uiPOSTPassed = FALSE; + dgPOSTPassed = FALSE; + postCompleteDelayTimerCtr = 0; } /*********************************************************************//** @@ -80,37 +98,43 @@ /*********************************************************************//** * @brief - * The execInitAndPOSTMode function executes the Initialize & POST Mode state machine. + * The execInitAndPOSTMode function executes the Initialize & POST Mode + * state machine. * @details Inputs: postState * @details Outputs: postState, postPassed, postCompleted * @return current state (sub-mode) *************************************************************************/ U32 execInitAndPOSTMode( void ) { SELF_TEST_STATUS_T testStatus = SELF_TEST_STATUS_IN_PROGRESS; + BOOL stop = isStopButtonPressed(); + if ( TRUE == stop ) + { + // Ignore stop button in this mode. + } + // TODO - send POST status on CAN // Execute current POST state *Note - these switch cases must be in same order as enum HD_POST_States switch ( postState ) { case POST_STATE_START: - postState = POST_STATE_WATCHDOG; -#ifdef SKIP_POST - postState = POST_STATE_VALVES; -#endif + postState = POST_STATE_FW_INTEGRITY; break; - case POST_STATE_WATCHDOG: - testStatus = execWatchdogTest(); + case POST_STATE_FW_INTEGRITY: + testStatus = execIntegrityTest(); + testStatus = SELF_TEST_STATUS_PASSED; postState = handlePOSTStatus( testStatus ); break; - case POST_STATE_FPGA: - testStatus = execFPGATest(); + case POST_STATE_WATCHDOG: + testStatus = execWatchdogTest(); postState = handlePOSTStatus( testStatus ); break; + // NOTE: RTC's POST must go before NVDataMgmt case POST_STATE_RTC: testStatus = execRTCSelfTest(); postState = handlePOSTStatus( testStatus ); @@ -121,6 +145,9 @@ postState = handlePOSTStatus( testStatus ); break; + // NOTE: all the actuators and sensors must execute their POST after NVDataMgmt + // NVDataMgmt must load all the calibration data into RAM so the actuators + // can query their corresponding calibration values successfully case POST_STATE_BLOOD_FLOW: testStatus = execBloodFlowTest(); postState = handlePOSTStatus( testStatus ); @@ -131,6 +158,34 @@ postState = handlePOSTStatus( testStatus ); break; + case POST_STATE_VALVES: + testStatus = execValvesSelfTest(); + postState = handlePOSTStatus( testStatus ); + break; + + case POST_STATE_SYRINGE_PUMP: + testStatus = execSyringePumpSelfTest(); + postState = handlePOSTStatus( testStatus ); + break; + + case POST_STATE_ALARM_AUDIO: +#ifdef SKIP_POST + testStatus = SELF_TEST_STATUS_PASSED; +#else + testStatus = execAlarmAudioSelfTest(); +#endif + postState = handlePOSTStatus( testStatus ); + break; + + case POST_STATE_ALARM_LAMP: +#ifdef SKIP_POST + testStatus = SELF_TEST_STATUS_PASSED; +#else + testStatus = execAlarmLampTest(); +#endif + postState = handlePOSTStatus( testStatus ); + break; + case POST_STATE_ACCELEROMETER: #ifndef DISABLE_ACCELS testStatus = execAccelTest(); @@ -140,19 +195,25 @@ postState = handlePOSTStatus( testStatus ); break; - case POST_STATE_VALVES: - testStatus = execValvesSelfTest(); + case POST_STATE_STUCK_BUTTON: + testStatus = execStuckButtonTest(); postState = handlePOSTStatus( testStatus ); break; - case POST_STATE_ALARM_LAMP: - testStatus = execAlarmLampTest(); + case POST_STATE_UI_POST: + // TODO implement the UI POST self test + testStatus = SELF_TEST_STATUS_PASSED; postState = handlePOSTStatus( testStatus ); break; - // Should be last POST - case POST_STATE_STUCK_BUTTON: - testStatus = execStuckButtonTest(); + case POST_STATE_FW_COMPATIBILITY: + testStatus = execFWCompatibilityTest(); + postState = handlePOSTStatus( testStatus ); + break; + + // Should be last POST (and last POST test must be a test that completes in a single call) + case POST_STATE_FPGA: + testStatus = execFPGATest(); handlePOSTStatus( testStatus ); // Ignoring return value because last test if ( TRUE == tempPOSTPassed ) @@ -165,21 +226,26 @@ } break; + // TODO - add POST test requiring all DG and UI POST tests to pass + case POST_STATE_COMPLETED: // Set overall HD POST status to "passed" postPassed = TRUE; // Set overall HD POST completed status to TRUE postCompleted = TRUE; - // TODO - send POST status on CAN - // Go to standby mode - requestNewOperationMode( MODE_STAN ); + // Broadcast final POST passed + sendPOSTFinalResult( TRUE ); + // Delay before going to standby mode + if ( ++postCompleteDelayTimerCtr > POST_COMPLETED_DELAY ) + { + requestNewOperationMode( MODE_STAN ); + } break; case POST_STATE_FAILED: // Should not get here - any failed post test should have already triggered a fault and taken us to fault mode default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_INIT_POST_INVALID_POST_STATE, postState ) - postState = POST_STATE_FAILED; break; } @@ -197,11 +263,39 @@ *************************************************************************/ void signalAlarmActionToInitAndPOSTMode( ALARM_ACTION_T action ) { + // TODO - anything required here? +} +/*********************************************************************//** + * @brief + * The signalUIPOSTFinalResult function records the final POST result for + * the UI. + * @details Inputs: none + * @details Outputs: uiPOSTPassed + * @param passed TRUE if UI POST tests all passed, FALSE if any UI POST test failed + * @return none + *************************************************************************/ +void signalUIPOSTFinalResult( BOOL passed ) +{ + uiPOSTPassed = passed; } /*********************************************************************//** * @brief + * The signalDGPOSTFinalResult function records the final POST result for + * the DG. + * @details Inputs: none + * @details Outputs: dgPOSTPassed + * @param passed TRUE if DG POST tests all passed, FALSE if any DG POST test failed + * @return none + *************************************************************************/ +void signalDGPOSTFinalResult( BOOL passed ) +{ + dgPOSTPassed = passed; +} + +/*********************************************************************//** + * @brief * The isPOSTCompleted function determines whether all HD POST have * been run and completed. If true, call the isPOSTPassed() to see final * result (pass/fail). @@ -242,12 +336,19 @@ if ( testStatus == SELF_TEST_STATUS_PASSED ) { - result = (HD_POST_STATE_T)((int)postState + 1); // Move on to next POST test + // Broadcast passed POST result + sendPOSTTestResult( (HD_POST_STATE_T)((int)postState), TRUE ); + // Move on to next POST test + result = (HD_POST_STATE_T)((int)postState + 1); } else if ( testStatus == SELF_TEST_STATUS_FAILED ) { - requestAlarmLampPattern( LAMP_PATTERN_FAULT ); + // At least one POST has failed tempPOSTPassed = FALSE; + // Broadcast failed POST results + sendPOSTTestResult( (HD_POST_STATE_T)((int)postState), FALSE ); + sendPOSTFinalResult( FALSE ); + // Test that failed should have triggered a fault which will request fault mode, so should POST state machine should never see FAILED state and will fault if it does result = POST_STATE_FAILED; } else @@ -257,3 +358,21 @@ return result; } + +/*********************************************************************//** + * @brief + * The execFWCompatibilityTest function executes the firmware compatibility test. + * @details Inputs: none + * @details Outputs: none + * @return in progress, passed, or failed + *************************************************************************/ +static SELF_TEST_STATUS_T execFWCompatibilityTest( void ) +{ + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_PASSED; + + // TODO - implement + + return result; +} + +/**@}*/