#include "Messaging.h" #include "ModeUpdate.h" #include "OperationModes.h" #include "Timers.h" /** * @addtogroup TDStandbyMode * @{ */ // ********** private definitions ********** #define BEFORE_MCU_RESET_TIMEOUT_MS 100 ///< Before micro-controller unit reset timeout in milliseconds. // ********** private data ********** static U32 modeUpdateStartTimeMS; ///< Mode update start time in milliseconds. static TD_UPDATE_STATE_T currentUpdateState; ///< Current state (sub-mode) of update mode. // ********** private function prototypes ********** static TD_UPDATE_STATE_T handleUpdateModeStartState( void ); static TD_UPDATE_STATE_T handleUpdateModeResetMCUState( void ); /*********************************************************************//** * @brief * The initUpdateMode function initializes the Update Mode Unit. * @details \b Inputs: none * @details \b Outputs: currentUpdateState, modeUpdateStartTimeMS * @return none *************************************************************************/ void initUpdateMode( void ) { currentUpdateState = UPDATE_INIT_STATE; modeUpdateStartTimeMS = 0; } /*********************************************************************//** * @brief * The transitionToUpdateMode function prepares for transition to update mode. * @details \b Inputs: none * @details \b Outputs: Update Mode unit re-initialized. * @return initial state *************************************************************************/ U32 transitionToUpdateMode( void ) { initUpdateMode(); // Set the timer when the transition to update mode has been called upon requesting to transition to mode update modeUpdateStartTimeMS = getMSTimerCount(); return currentUpdateState; } /*********************************************************************//** * @brief * The execUpdateMode function executes the update Mode state machine. * @details \b Inputs: currentUpdateState * @details \b Outputs: currentUpdateState * @return current state (sub-mode) *************************************************************************/ U32 execUpdateMode( void ) { switch ( currentUpdateState ) { case UPDATE_INIT_STATE: currentUpdateState = handleUpdateModeStartState(); break; case UPDATE_RESET_MCU_STATE: currentUpdateState = handleUpdateModeResetMCUState(); break; default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_UPDATE_INVALID_STATE, currentUpdateState ); currentUpdateState = UPDATE_INIT_STATE; break; } return currentUpdateState; } /*********************************************************************//** * @brief * The handleUpdateModeStartState function executes the update mode start * state. The start state transitions to the next state after the specified * timeout. * @details \b Inputs: modeUpdateStartTimeMS * @details \b Outputs: none * @return next state of the update mode state machine *************************************************************************/ static TD_UPDATE_STATE_T handleUpdateModeStartState( void ) { TD_UPDATE_STATE_T state = UPDATE_INIT_STATE; if ( TRUE == didTimeout( modeUpdateStartTimeMS, BEFORE_MCU_RESET_TIMEOUT_MS ) ) { state = UPDATE_RESET_MCU_STATE; } return state; } /*********************************************************************//** * @brief * The handleUpdateModeResetMCUState function executes the update mode reset * micro-controller unit state. The state resets the MCU. * @details \b Inputs: none * @details \b Outputs: none * @return next state of the update mode state machine *************************************************************************/ static TD_UPDATE_STATE_T handleUpdateModeResetMCUState( void ) { TD_UPDATE_STATE_T state = UPDATE_RESET_MCU_STATE; resetMicroControllerUnit(); return state; } /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ /**@}*/