/************************************************************************** * * 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 ModeFault.c * * @author (last) Vinayakam Mani * @date (last) 05-Aug-2024 * * @author (original) Vinayakam Mani * @date (original) 05-Aug-2024 * ***************************************************************************/ #include "OperationModes.h" #include "ModeFault.h" #include "Messaging.h" #include "Utilities.h" #include "Valves.h" /** * @addtogroup DDFaultMode * @{ */ // ********** private definitions ********** #define DELAY_VALVE_MS ( 1 * MS_PER_SECOND ) ///< Valve state change delay in ms. // ********** private data ********** static DD_FAULT_STATE_T faultState; ///< Currently active fault state. static SELF_TEST_STATUS_T faultPOSTSelfTestResult; ///< Fault POST self test result. // ********** private function prototypes ********** static DD_FAULT_STATE_T handleFaultStartState( void ); static DD_FAULT_STATE_T handleFaultRunNVPOSTsState( void ); /*********************************************************************//** * @brief * The initFaultMode function initializes the Fault Mode unit. * @details \b Inputs : none * @details \b Outputs: Fault mode unit initialized * @return none *************************************************************************/ void initFaultMode( void ) { faultState = DD_FAULT_STATE_START; faultPOSTSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; } /*********************************************************************//** * @brief * The transitionToFaultMode function prepares for transition to fault mode. * @details \b Inputs: none * @details \b Outputs: none * @return initial state *************************************************************************/ U32 transitionToFaultMode( void ) { //deenergizeActuators( PARK_CONC_PUMPS ); initFaultMode(); setCurrentSubState( NO_SUB_STATE ); // Publish POST failure status to UI if fault triggered in Init/POST mode if ( DD_MODE_INIT == getPreviousOperationMode() ) { // Broadcast final POST failed //sendPOSTFinalResult( FALSE ); } return faultState; } /*********************************************************************//** * @brief * The execFaultMode function executes the fault mode state machine. * @details \b Inputs: none * @details \b Outputs: Fault mode state machine executed * @return current state of fault mode *************************************************************************/ U32 execFaultMode( void ) { // deenergizeActuators( NO_PARK_CONC_PUMPS ); // execute current fault state switch ( faultState ) { case DD_FAULT_STATE_START: faultState = handleFaultStartState(); break; case DD_FAULT_STATE_RUN_NV_POSTS: faultState = handleFaultRunNVPOSTsState(); break; case DD_FAULT_STATE_COMPLETE: // Do nothing unless the test configuration to recover treatment is enabled if ( ( TRUE == getTestConfigStatus( TEST_CONFIG_RECOVER_TREATMENT ) ) && ( TRUE == hasRecoverFromFaultModeBeenSet() ) ) { DD_OP_MODE_T prevMode = getPreviousOperationMode(); requestNewOperationMode( prevMode ); } break; default: faultState = DD_FAULT_STATE_COMPLETE; break; } return faultState; } /*********************************************************************//** * @brief * The getCurrentFaultState function returns the current state of the fault mode. * @details \b Inputs: faultState * @details \b Outputs: none * @return current state of fault mode *************************************************************************/ DD_FAULT_STATE_T getCurrentFaultState( void ) { return faultState; } /*********************************************************************//** * @brief * The deenergizeActuators function sets all the actuators to reset and * de-energized state. * @details \b Inputs: none * @details \b Outputs: none * @param parkPumps TRUE if concentrate pumps should be parked, FALSE if not * @return none *************************************************************************/ void deenergizeActuators( BOOL parkPumps ) { U32 i; // De-energize all the hydraulics valves // TODO : valve state name needs to be updated setValveStateDelayed( VDR, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); setValveStateDelayed( VTD, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); setValveStateDelayed( VHB, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); setValveStateDelayed( VRP, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); setValveStateDelayed( VHO, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); setValveStateDelayed( VDB1, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); setValveStateDelayed( VP1, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); setValveStateDelayed( VPT, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); setValveStateDelayed( VDB2, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); setValveStateDelayed( VDI, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); setValveStateDelayed( VDO, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); setValveStateDelayed( VP2, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); setValveStateDelayed( VHI, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); // De-energize Balancing chamber and Ultrafiltration valves for ( i = FIRST_BC_VALVE; i <= LAST_BC_VALVE; i++ ) { setValveStateDelayed( (VALVES_T)i, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); } for ( i = FIRST_UF_VALVE; i <= FIRST_UF_VALVE; i++ ) { setValveStateDelayed( (VALVES_T)i, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); } // requestConcentratePumpOff( CONCENTRATEPUMPS_CP1_ACID, parkPumps ); // requestConcentratePumpOff( CONCENTRATEPUMPS_CP2_BICARB, parkPumps ); // signalROPumpHardStop(); // stopHeater( DD_PRIMARY_HEATER ); // stopHeater( DD_TRIMMER_HEATER ); } /*********************************************************************//** * @brief * The handleFaultStartState function handles the start state of the fault mode. * @details \b Inputs: none * @details \b Outputs: none * @return next state *************************************************************************/ static DD_FAULT_STATE_T handleFaultStartState( void ) { DD_FAULT_STATE_T state = DD_FAULT_STATE_START; //NVDATAMGMT_RECORDS_READ_STATUS_T status = getNVRecordsReadStatus(); // switch ( status ) // { // // If the records are queued or already read, go directly to NV POST to process // // their CRCs. // case NVDATAMGMT_RECORDS_QUEUED: // case NVDATAMGMT_RECORDS_READ: // state = DD_FAULT_STATE_RUN_NV_POSTS; // break; // // // If the NV post was completed prior to transitioning to fault mode, do nothing // case NVDATAMGMT_RECORDS_CRC_CHECKED: // state = DD_FAULT_STATE_COMPLETE; // break; // } return state; } /*********************************************************************//** * @brief * The handleFaultRunNVPOSTsState function handles running non-volatile POSTs. * @details \b Inputs: faultPOSTSelfTestResult * @details \b Outputs: faultPOSTSelfTestResult * @return next state *************************************************************************/ static DD_FAULT_STATE_T handleFaultRunNVPOSTsState( void ) { DD_FAULT_STATE_T state = DD_FAULT_STATE_RUN_NV_POSTS; // faultPOSTSelfTestResult = execNVDataMgmtSelfTest(); // // // Regardless of the status of the NV POST transition to the complete state. // if ( ( SELF_TEST_STATUS_PASSED == faultPOSTSelfTestResult ) || ( SELF_TEST_STATUS_FAILED == faultPOSTSelfTestResult ) ) // { // state = DD_FAULT_STATE_COMPLETE; // } return state; } /**@}*/