Index: App/Modes/ModeInitPOST.c =================================================================== diff -u -r765d2c35118e202444e737c66c77faf9678cc87e -r40a959e1341c8964f872df462ac3a2d874e3b0b3 --- App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision 765d2c35118e202444e737c66c77faf9678cc87e) +++ App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision 40a959e1341c8964f872df462ac3a2d874e3b0b3) @@ -1,30 +1,51 @@ -/************************************************************************* -* -* Copyright Diality, Inc. 2019-2020. All Rights Reserved. -* 181 Technology, Ste. 150 -* Irvine, CA 92618 -* -* Project Denali -* -* @file ModeInitPOST.c -* -* @brief Top-level state machine for the initialize & POST mode. -* -* @date 19-Sep-2019 -* -*************************************************************************/ +/************************************************************************** + * + * Copyright (c) 2019-2019 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 ModeInitPOST.c + * + * @date 19-Sep-2019 + * @author S. Nash + * + * @brief Top-level state machine for the initialize & POST mode. + * + **************************************************************************/ +#include +#include #include "Common.h" -#include "AlarmLamp.h" -#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. @@ -33,9 +54,13 @@ * Outputs : Initialize & POST Mode module initialized. * @param none * @return none -*************************************************************************/ + *************************************************************************/ void initInitAndPOSTMode( void ) { + postState = POST_STATE_START; + postCompleted = FALSE; + postPassed = FALSE; + tempPOSTPassed = TRUE; } /************************************************************************* @@ -47,12 +72,10 @@ * Outputs : * @param none * @return none -*************************************************************************/ + *************************************************************************/ void transitionToInitAndPOSTMode( void ) { - // temporary test code - solid red alarm lamp - RequestLampPattern( LAMP_PATTERN_MANUAL ); - setCPLDLampRed( PIN_SIGNAL_HIGH ); + requestAlarmLampPattern( LAMP_PATTERN_MANUAL ); } /************************************************************************* @@ -63,14 +86,117 @@ * Outputs : * @param none * @return none -*************************************************************************/ + *************************************************************************/ void execInitAndPOSTMode( void ) { - BOOL stop = isStopButtonPressed(); + SELF_TEST_STATUS_T testStatus = SELF_TEST_STATUS_IN_PROGRESS; - 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; +}