/************************************************************************** * * 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" /** * @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 module. * @details \b Inputs : none * @details \b Outputs: Fault mode module 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 ); } //setCPLDCleanLEDColor( CPLD_CLEAN_LED_OFF ); // Release RTC in case the RTC semaphore was not released prior to transitioning to fault mode. // In fault mode, the non-volatile data mgmt POST might be run again so the RTC has to be available. Also, // the RTC time is read every second which requires the semaphore. releaseSemaphore( SEMAPHORE_RTC ); //#ifndef _RELEASE_ // setHeatNelsonSupportMode( NELSON_NONE ); // setChemNelsonSupportMode( NELSON_NONE ); //#endif 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 ) { // // Turn off the UV reactors // turnOffUVReactor( INLET_UV_REACTOR ); // turnOffUVReactor( OUTLET_UV_REACTOR ); // // // De-energize all the valves // setValveStateDelayed( VPI, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); // setValveStateDelayed( VBF, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); // setValveStateDelayed( VSP, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); // setValveStateDelayed( VPD, VALVE_STATE_DRAIN_C_TO_NO, DELAY_VALVE_MS ); // setValveStateDelayed( VPO, VALVE_STATE_NOFILL_C_TO_NO, DELAY_VALVE_MS ); // setValveStateDelayed( VDR, VALVE_STATE_DRAIN_C_TO_NO, DELAY_VALVE_MS ); // setValveStateDelayed( VRC, VALVE_STATE_DRAIN_C_TO_NO, DELAY_VALVE_MS ); // setValveStateDelayed( VRO, VALVE_STATE_R1_C_TO_NO, DELAY_VALVE_MS ); // setValveStateDelayed( VRD1, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); // setValveStateDelayed( VRD2, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); // setValveStateDelayed( VRI, VALVE_STATE_R1_C_TO_NO, DELAY_VALVE_MS ); // setValveStateDelayed( VRF, VALVE_STATE_R2_C_TO_NO, DELAY_VALVE_MS ); // // requestConcentratePumpOff( CONCENTRATEPUMPS_CP1_ACID, parkPumps ); // requestConcentratePumpOff( CONCENTRATEPUMPS_CP2_BICARB, parkPumps ); // signalROPumpHardStop(); // signalDrainPumpHardStop(); // 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; } /**@}*/