Index: App/Modes/ModeInitPOST.c =================================================================== diff -u -radd7eb956a7d2c124434541e1f06ca5ae158716f -r614cd0625ac1f98edea2fe3ab2c3d0005f6fc8e0 --- App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision add7eb956a7d2c124434541e1f06ca5ae158716f) +++ App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision 614cd0625ac1f98edea2fe3ab2c3d0005f6fc8e0) @@ -19,12 +19,33 @@ #include "Buttons.h" #include "CPLD.h" #include "OperationModes.h" +#include "WatchdogMgmt.h" #include "ModeInitPOST.h" +// ********** private definitions ********** + +typedef enum POST_States +{ + POST_STATE_START = 0, + POST_STATE_ALARM_LAMP, + POST_STATE_STUCK_BUTTON, + POST_STATE_WATCHDOG, + POST_STATE_COMPLETED, + POST_STATE_FAILED, + NUM_OF_POST_STATES +} POST_STATE_T; + // ********** private data ********** +static POST_STATE_T postState = POST_STATE_START; +static BOOL postCompleted = FALSE; +static BOOL postPassed = FALSE; +static BOOL tempPOSTPassed = TRUE; + // ********** private function prototypes ********** +static POST_STATE_T handlePOSTStatus( SELF_TEST_STATUS_T testStatus ); + /************************************************************************* * @brief initInitAndPOSTMode * The initInitAndPOSTMode function initializes the Initialize & POST Mode module. @@ -36,6 +57,10 @@ *************************************************************************/ void initInitAndPOSTMode( void ) { + postState = POST_STATE_START; + postCompleted = FALSE; + postPassed = FALSE; + tempPOSTPassed = TRUE; } /************************************************************************* @@ -52,7 +77,7 @@ { // temporary test code - solid red alarm lamp requestAlarmLampPattern( LAMP_PATTERN_MANUAL ); - setCPLDLampRed( PIN_SIGNAL_HIGH ); + //setCPLDLampRed( PIN_SIGNAL_HIGH ); } /************************************************************************* @@ -66,11 +91,121 @@ *************************************************************************/ void execInitAndPOSTMode( void ) { - BOOL stop = isStopButtonPressed(); + SELF_TEST_STATUS_T testStatus = SELF_TEST_STATUS_IN_PROGRESS; + // // TODO - temporary test code - remove later + BOOL stop = isStopButtonPressed(); if ( TRUE == stop ) { requestNewOperationMode( MODE_STAN ); } + + // execute current POST state + switch ( postState ) + { + case POST_STATE_START: + postState = POST_STATE_ALARM_LAMP; + break; + + case POST_STATE_ALARM_LAMP: + testStatus = execAlarmLampTest(); + postState = handlePOSTStatus( testStatus ); + break; + + case POST_STATE_STUCK_BUTTON: + testStatus = execStuckButtonTest(); + postState = handlePOSTStatus( testStatus ); + break; + + case POST_STATE_WATCHDOG: + testStatus = execWatchdogTest(); + handlePOSTStatus( testStatus ); // ignoring return value because last test + if ( TRUE == tempPOSTPassed ) + { + postState = POST_STATE_COMPLETED; + } + else + { + postState = POST_STATE_FAILED; + } + break; + + 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 ); + break; + + case POST_STATE_FAILED: + // TODO - send POST status on CAN + // will want POST faults to wait for us to get here before sending us to fault mode + requestNewOperationMode( MODE_FAUL ); + break; + + default: + postState = POST_STATE_FAILED; + // TODO - s/w fault + break; + } } +/************************************************************************* + * @brief isPOSTCompleted + * The isPOSTCompleted function determines whether all HD POST have \n + * been run and completed. If true, call the isPOSTPassed() to see final \n + * result (pass/fail). + * @details + * Inputs : postCompleted + * Outputs : none + * @param none + * @return true if all HD POST tests have completed, false if not + *************************************************************************/ +BOOL isPOSTCompleted( void ) +{ + return postCompleted; +} + +/************************************************************************* + * @brief isPOSTPassed + * The isPOSTPassed function determines whether all HD POST have passed. \n + * Call this function after POST is complete (call isPOSTCompleted function). + * @details + * Inputs : postPassed + * Outputs : none + * @param none + * @return true if all HD POST tests have passed, false if not + *************************************************************************/ +BOOL isPOSTPassed( void ) +{ + return postPassed; +} + +/************************************************************************* + * @brief handlePOSTStatus + * The handlePOSTStatus function handles a status result returned by a + * POST function. + * @details + * Inputs : postPassed + * Outputs : none + * @param testStatus + * @return recommended next POST state + *************************************************************************/ +static POST_STATE_T handlePOSTStatus( SELF_TEST_STATUS_T testStatus ) +{ + POST_STATE_T result = postState; + + if ( ( testStatus == SELF_TEST_STATUS_PASSED ) || ( testStatus == SELF_TEST_STATUS_FAILED ) ) + { + result = (POST_STATE_T)((int)postState + 1); // move on to next POST test + if ( testStatus == SELF_TEST_STATUS_FAILED ) + { + tempPOSTPassed = FALSE; + } + } + + return result; +}