/************************************************************************** * * Copyright (c) 2019-2020 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 "AlarmLamp.h" #include "Buttons.h" #include "CPLD.h" #include "FPGA.h" #include "OperationModes.h" #include "RTC.h" #include "WatchdogMgmt.h" #include "ModeInitPOST.h" #include "NVDataMgmt.h" // ********** private definitions ********** typedef enum POST_States { POST_STATE_START = 0, POST_STATE_WATCHDOG, POST_STATE_ALARM_LAMP, POST_STATE_FPGA, POST_STATE_RTC, POST_STATE_NVDATAMGMT, POST_STATE_STUCK_BUTTON, 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. * @details * Inputs : none * Outputs : Initialize & POST Mode module initialized. * @param none * @return none *************************************************************************/ void initInitAndPOSTMode( void ) { postState = POST_STATE_START; postCompleted = FALSE; postPassed = FALSE; tempPOSTPassed = TRUE; } /************************************************************************* * @brief transitionToInitAndPOSTMode * The transitionToInitAndPOSTMode function prepares for transition to\n * initialize & POST mode. * @details * Inputs : none * Outputs : * @param none * @return none *************************************************************************/ void transitionToInitAndPOSTMode( void ) { } /************************************************************************* * @brief execInitAndPOSTMode * The execInitAndPOSTMode function executes the Initialize & POST Mode state machine. * @details * Inputs : none * Outputs : * @param none * @return none *************************************************************************/ void execInitAndPOSTMode( void ) { SELF_TEST_STATUS_T testStatus = SELF_TEST_STATUS_IN_PROGRESS; // TODO - send POST status on CAN // execute current POST state switch ( postState ) { case POST_STATE_START: postState = POST_STATE_WATCHDOG; break; case POST_STATE_WATCHDOG: #ifndef RM46_EVAL_BOARD_TARGET testStatus = execWatchdogTest(); postState = handlePOSTStatus( testStatus ); // ignoring return value because last test #else postState = POST_STATE_RTC; #endif break; case POST_STATE_ALARM_LAMP: testStatus = execAlarmLampTest(); postState = handlePOSTStatus( testStatus ); break; case POST_STATE_FPGA: testStatus = execFPGATest(); postState = handlePOSTStatus( testStatus ); break; case POST_STATE_RTC: testStatus = execRTCSelfTest(); postState = handlePOSTStatus( testStatus ); break; // NVDataMgmt is dependent on RTC POST // so RTC POST has to go first case POST_STATE_NVDATAMGMT: testStatus = execNVDataMgmtSelfTest(); postState = handlePOSTStatus( testStatus ); break; case POST_STATE_STUCK_BUTTON: testStatus = execStuckButtonTest(); handlePOSTStatus( testStatus ); 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: // 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_SOFTWARE_FAULT, SW_FAULT_ID_MODE_INIT_POST_INVALID_POST_STATE, postState ) postState = POST_STATE_FAILED; 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 ) { result = (POST_STATE_T)((int)postState + 1); // move on to next POST test } else if ( testStatus == SELF_TEST_STATUS_FAILED ) { requestAlarmLampPattern( LAMP_PATTERN_FAULT ); tempPOSTPassed = FALSE; result = POST_STATE_FAILED; } else { // test still in progress - do nothing } return result; }