/************************************************************************** * * 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 * * @author (last) Quang Nguyen * @date (last) 29-Jul-2020 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 * ***************************************************************************/ #include "Accel.h" #include "CPLD.h" #include "FPGA.h" #include "OperationModes.h" #include "TemperatureSensors.h" #include "WatchdogMgmt.h" #include "ModeInitPOST.h" #include "Heaters.h" #include "Pressures.h" /** * @addtogroup DGInitAndPOSTMode * @{ */ // ********** private data ********** static DG_POST_STATE_T postState = DG_POST_STATE_START; ///< Currently active initialize & POST state. static BOOL postCompleted = FALSE; ///< Flag indicating POST completed. static BOOL postPassed = FALSE; ///< Flag indicating all POST tests passed. static BOOL tempPOSTPassed = TRUE; ///< Temporary flag indicating all POST tests completed so far have passed. // ********** private function prototypes ********** static DG_POST_STATE_T handlePOSTStatus( SELF_TEST_STATUS_T testStatus ); /*********************************************************************//** * @brief * The initInitAndPOSTMode function initializes the Initialize & POST Mode module. * @details * Inputs : none * Outputs : Initialize & POST Mode module initialized. * @return none *************************************************************************/ void initInitAndPOSTMode( void ) { postState = DG_POST_STATE_START; postCompleted = FALSE; postPassed = FALSE; tempPOSTPassed = TRUE; } /*********************************************************************//** * @brief * The transitionToInitAndPOSTMode function prepares for transition to\n * initialize & POST mode. * @details * Inputs : none * Outputs : * @return none *************************************************************************/ void transitionToInitAndPOSTMode( void ) { // TODO - anything needed here? } /*********************************************************************//** * @brief * The execInitAndPOSTMode function executes the Initialize & POST Mode state machine. * @details * Inputs : postState * Outputs : POST state machine executed * @return current state. *************************************************************************/ U32 execInitAndPOSTMode( void ) { SELF_TEST_STATUS_T testStatus = SELF_TEST_STATUS_IN_PROGRESS; // execute current POST state switch ( postState ) { case DG_POST_STATE_START: postState = DG_POST_STATE_FPGA; #ifdef SKIP_POST postState = DG_POST_STATE_COMPLETED; #endif break; case DG_POST_STATE_FPGA: testStatus = execFPGATest(); postState = handlePOSTStatus( testStatus ); break; case DG_POST_STATE_TEMPERATURE_SENSORS: testStatus = execTemperatureSensorsSelfTest(); postState = handlePOSTStatus( testStatus ); break; case DG_POST_STATE_HEATERS: testStatus = execHeatersSelfTest(); postState = handlePOSTStatus( testStatus ); break; case DG_POST_STATE_ACCELEROMETER: #ifndef DISABLE_ACCELS testStatus = execAccelTest(); #else testStatus = SELF_TEST_STATUS_PASSED; #endif case DG_POST_STATE_PRESSURES: testStatus = execPressureSelfTest(); postState = handlePOSTStatus( testStatus ); break; case DG_POST_STATE_WATCHDOG: testStatus = execWatchdogTest(); handlePOSTStatus( testStatus ); // ignoring return value because last test if ( TRUE == tempPOSTPassed ) { postState = DG_POST_STATE_COMPLETED; } else { postState = DG_POST_STATE_FAILED; } break; case DG_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( DG_MODE_STAN ); break; case DG_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( DG_MODE_FAUL ); break; default: // TODO - s/w fault postState = DG_POST_STATE_FAILED; break; } return postState; } /*********************************************************************//** * @brief * 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 * @return true if all HD POST tests have completed, false if not *************************************************************************/ BOOL isPOSTCompleted( void ) { return postCompleted; } /*********************************************************************//** * @brief * 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 * @return true if all HD POST tests have passed, false if not *************************************************************************/ BOOL isPOSTPassed( void ) { return postPassed; } /*********************************************************************//** * @brief * The handlePOSTStatus function handles a status result returned by a * POST function. * @details * Inputs : postPassed * Outputs : none * @param testStatus status reported by last test * @return recommended next POST state *************************************************************************/ static DG_POST_STATE_T handlePOSTStatus( SELF_TEST_STATUS_T testStatus ) { DG_POST_STATE_T result = postState; if ( ( testStatus == SELF_TEST_STATUS_PASSED ) || ( testStatus == SELF_TEST_STATUS_FAILED ) ) { result = (DG_POST_STATE_T)((int)postState + 1); // move on to next POST test if ( testStatus == SELF_TEST_STATUS_FAILED ) { tempPOSTPassed = FALSE; } } return result; } /*********************************************************************//** * @brief * The getCurrentInitAndPOSTState function returns the current state of the \n * initialize & POST mode. * @details * Inputs : postState * Outputs : none * @return the current state of initialize & POST mode. *************************************************************************/ DG_POST_STATE_T getCurrentInitAndPOSTState( void ) { return postState; } /**@}*/