/**********************************************************************//** * * 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 11-Dec-2019 * @author L. Baloa * * @brief Top-level state machine for the initialize & POST mode. * **************************************************************************/ #include "CPLD.h" #include "FPGA.h" #include "OperationModes.h" #include "WatchdogMgmt.h" #include "ModeInitPOST.h" /** * @addtogroup InitAndPOSTMode * @{ */ // ********** private definitions ********** /// Enumeration of init & POST mode states. typedef enum POST_States { POST_STATE_START = 0, ///< Start initialize & POST mode state. POST_STATE_FPGA, ///< FPGA POST test state. POST_STATE_WATCHDOG, ///< Watchdog POST test state. POST_STATE_COMPLETED, ///< POST completed successfully state. POST_STATE_FAILED, ///< POST failed state. NUM_OF_POST_STATES ///< Number of initialize & POST mode states. } POST_STATE_T; // ********** private data ********** static POST_STATE_T postState = 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 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 = 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 ) { } /*********************************************************************//** * @brief * The execInitAndPOSTMode function executes the Initialize & POST Mode state machine. * @details * Inputs : none * Outputs : * @return none *************************************************************************/ void execInitAndPOSTMode( void ) { SELF_TEST_STATUS_T testStatus = SELF_TEST_STATUS_IN_PROGRESS; // execute current POST state switch ( postState ) { case POST_STATE_START: postState = POST_STATE_FPGA; break; case POST_STATE_FPGA: testStatus = execFPGATest(); 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 * 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 * @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; } /**@}*/