#include "CommBuffers.h" #include "Download.h" #include "FPGA.h" #include "ModeUpdate.h" #include "NVDataMgmt.h" #include "OperationModes.h" /** * @addtogroup UpdateMode * @{ */ // ********** private definitions ********** // ********** private data ********** static MODE_SW_UPDATE_STATE_T updateCurrentState; // ********** private function prototypes ********** static MODE_SW_UPDATE_STATE_T handleUpdateModeUpdateState( void ); static MODE_SW_UPDATE_STATE_T handleUpdateModeVerifyState( void ); static MODE_SW_UPDATE_STATE_T handleUpdateModeAbortState( void ); /*********************************************************************//** * @brief * The initUpdateMode function initializes the Update Mode Unit. * @details \b Inputs: none * @details \b Outputs: updateCurrentState * @return none *************************************************************************/ void initUpdateMode( void ) { updateCurrentState = SW_UPDATE_UPDATE_STATE; } /*********************************************************************//** * @brief * The transitionToUpdateMode function prepares for transition to Update Mode. * @details \b Inputs: none * @details \b Outputs: Standby Mode unit re-initialized * @return none *************************************************************************/ U32 transitionToUpdateMode( void ) { initUpdateMode(); // Clear the NV status to start from the start address of the firmware clearSWUpdateNVStatus(); // TODO clear FPGA clear stuff here // Got the update command so we are in the update mode. Clear the command clearSWUpdateCommandState(); return 0; } /*********************************************************************//** * @brief * The execUpdateMode function executes the Update Mode state machine. * @details \b Inputs: updateCurrentState * @details \b Outputs: updateCurrentState * @return current state (sub-mode) *************************************************************************/ U32 execUpdateMode( void ) { switch( updateCurrentState ) { case SW_UPDATE_UPDATE_STATE: updateCurrentState = handleUpdateModeUpdateState(); break; case SW_UPDATE_ABORT_STATE: updateCurrentState = handleUpdateModeAbortState(); break; case SW_UPDATE_VERIFY_STATE: updateCurrentState = handleUpdateModeVerifyState(); break; default: // Do nothing break; } return 0; } /*********************************************************************//** * @brief * The handleUpdateModeUpdateState function handles the update mode update state. * This state checks for the SW update command to transition to the proper state. * @details \b Inputs: none * @details \b Outputs: none * @return next state of the update mode state machine *************************************************************************/ static MODE_SW_UPDATE_STATE_T handleUpdateModeUpdateState( void ) { MODE_SW_UPDATE_STATE_T state = SW_UPDATE_UPDATE_STATE; switch( getSWUpdateCommandState() ) { case UPDATE_CMD_VERIFY: state = SW_UPDATE_VERIFY_STATE; break; case UPDATE_CMD_ABORT: state = SW_UPDATE_ABORT_STATE; break; default: // Do nothing, keep updating break; } return state; } /*********************************************************************//** * @brief * The handleUpdateModeVerifyState function handles the update mode verify state. * This state checks for the destination of the current update which can be * either firmware or FPGA. If the update destination was FPGA it makes sure * the FPGA update has been completed and then transitions to standby mode. * If the update destination was firmware, it transitions to standby mode. * @details \b Inputs: none * @details \b Outputs: none * @return next state of the update mode state machine *************************************************************************/ static MODE_SW_UPDATE_STATE_T handleUpdateModeVerifyState( void ) { MODE_SW_UPDATE_STATE_T state = SW_UPDATE_VERIFY_STATE; switch( getSWUpdateDestination() ) { case UPDATE_FPGA: if ( TRUE == isFPGAFlashComplete() ) { requestNewOperationMode( MODE_STAND ); } break; case UPDATE_FIRMWARE: requestNewOperationMode( MODE_STAND ); break; default: // Do nothing break; } return state; } /*********************************************************************//** * @brief * The handleUpdateModeAbortState function handles the update mode abort state. * This state transitions to standby mode upon requesting to abort the update. * @details \b Inputs: none * @details \b Outputs: none * @return next state of the update mode state machine *************************************************************************/ static MODE_SW_UPDATE_STATE_T handleUpdateModeAbortState( void ) { MODE_SW_UPDATE_STATE_T state = SW_UPDATE_ABORT_STATE; requestNewOperationMode( MODE_STAND ); return state; } /**@}*/