Index: firmware/App/Modes/ModeStandby.c =================================================================== diff -u -r533272e6ef2873fcfe7a41338a6c88c7a601605d -r9ad496e4c3a54e96402afd66955be575bdaa3f57 --- firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 533272e6ef2873fcfe7a41338a6c88c7a601605d) +++ firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 9ad496e4c3a54e96402afd66955be575bdaa3f57) @@ -1,25 +1,173 @@ +/************************************************************************** +* +* 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 OVERRIDE_U32_T 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.data = FALSE; + pendingStartRORequest.ovData = FALSE; + pendingStartRORequest.ovInitData = FALSE; + pendingStartRORequest.override = OVERRIDE_RESET; } +/*********************************************************************//** + * @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 == getU32OverrideValue( &pendingStartRORequest ) ) + { + pendingStartRORequest.data = FALSE; + requestNewOperationMode( RO_MODE_GEN_PERM ); + } + + 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_STANDBY_MODE_STATE_IDLE == standbyState ) + { + result = TRUE; + pendingStartRORequest.data = TRUE; + } + + return result; +} + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testROstartGenPermeateOverride function sets the override value + * to start the generate permeate operation mode. + * @details Inputs: pendingStartRORequest + * @details Outputs: pendingStartRORequest + * @param message Override message from Dialin which includes the flag + * to override the operation mode. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testROstartGenPermeateOverride( MESSAGE_T *message ) +{ + BOOL result = u32Override( message, &pendingStartRORequest, FALSE, TRUE ); + + return result; +} + /**@}*/