Index: firmware/App/Modes/ModeStandby.c =================================================================== diff -u -r533272e6ef2873fcfe7a41338a6c88c7a601605d -r07f2ffedebb65a5a2b76ed9833c654c24221ec37 --- firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 533272e6ef2873fcfe7a41338a6c88c7a601605d) +++ firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 07f2ffedebb65a5a2b76ed9833c654c24221ec37) @@ -1,25 +1,153 @@ +/************************************************************************** +* +* Copyright (c) 2024-2024 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 ModeStandby.c +* +* @author (last) Michael Garthwaite +* @date (last) 28-Feb-2025 +* +* @author (original) Michael Garthwaite +* @date (original) 28-Feb-2025 +* +***************************************************************************/ - #include "ModeStandby.h" - +#include "OperationModes.h" +#include "PersistentAlarm.h" +#include "SystemCommRO.h" +#include "TaskGeneral.h" /** * @addtogroup ROStandbyMode * @{ */ +// ********** private definitions ********** + +// ********** private data ********** + +static RO_STANDBY_MODE_STATE_T standbyState; ///< Currently active standby state. +static U32 pendingStartRORequest; ///< Flag indicating DD has requested RO start the generate permeate (Overridable). + +// ********** private function prototypes ********** + +static RO_STANDBY_MODE_STATE_T handleStandbyIdleState( void ); + +/*********************************************************************//** + * @brief + * The initStandbyMode function initializes the standby mode unit. + * @details \b Inputs: none + * @details \b Outputs:unit variables initialized. + * @return none + *************************************************************************/ void initStandbyMode( void ) { - + standbyState = RO_STANDBY_MODE_STATE_IDLE; + pendingStartRORequest = FALSE; } +/*********************************************************************//** + * @brief + * The transitionToStandbyMode function prepares for transition to standby mode. + * while transition, deenergize all actuators. + * @details \b Inputs: none + * @details \b Outputs: Re-initialized standby mode + * @return initial state + *************************************************************************/ U32 transitionToStandbyMode( void ) { - return 0; + initStandbyMode(); + + return standbyState; } +/*********************************************************************//** + * @brief + * The execStandbyMode function executes the standby mode state machine. + * @details \b Inputs: none + * @details \b Outputs: Standby mode state machine executed + * @details \b Alarm: ALARM_ID_RO_SOFTWARE_FAULT if standbyState is invalid. + * @return current state + *************************************************************************/ U32 execStandbyMode( void ) { - return 0; + // execute current Standby state + switch ( standbyState ) + { + case RO_STANDBY_MODE_STATE_IDLE: + standbyState = handleStandbyIdleState(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_RO_SOFTWARE_FAULT, SW_FAULT_ID_MODE_STANDBY_INVALID_STATE, standbyState ) + standbyState = RO_STANDBY_MODE_STATE_IDLE; + break; + } + + return standbyState; } +/*********************************************************************//** + * @brief + * The handleStandbyIdleState function executes the idle state of the + * standby mode state machine. + * @details \b Inputs: + * @details \b Outputs: + * @details \b Message \Sent: + * @return the next state + *************************************************************************/ +static RO_STANDBY_MODE_STATE_T handleStandbyIdleState( void ) +{ + RO_STANDBY_MODE_STATE_T state = RO_STANDBY_MODE_STATE_IDLE; + + if ( TRUE == pendingStartRORequest ) + { + pendingStartRORequest = FALSE; + requestNewOperationMode( RO_MODE_GENP ); + } + + return state; +} + +/*********************************************************************//** + * @brief + * The getCurrentStandbyState function returns the current state of standby mode. + * @details \b Inputs: standbyState + * @details \b Outputs: none + * @return the current state of standby mode. + *************************************************************************/ +RO_STANDBY_MODE_STATE_T getCurrentStandbyState( void ) +{ + return standbyState; +} + +/*********************************************************************//** + * @brief + * The requestROStart function handles an DD request to start (go to gen permeate mode). + * @details \b Inputs: standbyState + * @details \b Outputs: pendingStartRORequest + * @return TRUE if request accepted, FALSE if not. + *************************************************************************/ +BOOL requestROStart( void ) +{ + BOOL result = FALSE; + + if ( ( RO_MODE_STAN == getCurrentOperationMode() ) && ( RO_STANDBY_MODE_STATE_IDLE == standbyState ) ) + { + result = TRUE; + pendingStartRORequest = TRUE; + } + + return result; +} + + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + /**@}*/