Index: firmware/App/Modes/ModeFault.c =================================================================== diff -u -rbc30c54270ec51f947b129da3c7daad54ec4eb5f -rf6fb03f1e20395a61a5d5996f11f802ab8eacb2f --- firmware/App/Modes/ModeFault.c (.../ModeFault.c) (revision bc30c54270ec51f947b129da3c7daad54ec4eb5f) +++ firmware/App/Modes/ModeFault.c (.../ModeFault.c) (revision f6fb03f1e20395a61a5d5996f11f802ab8eacb2f) @@ -21,6 +21,7 @@ #include "ModeFault.h" #include "Messaging.h" #include "OperationModes.h" +#include "SafetyShutdown.h" #include "Utilities.h" #include "Valves.h" @@ -36,13 +37,17 @@ // ********** private data ********** static DD_FAULT_STATE_T faultState; ///< Currently active fault state. +static DD_FAULT_NVDATA_STATE_T faultNVDataState; ///< Currently active NVdata 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 ); +static DD_FAULT_STATE_T handleFaultDeenergizedState( void ); +static DD_FAULT_STATE_T handleFaultEnergizedState( void ); +static DD_FAULT_NVDATA_STATE_T handleFaultNVDataMgmtStartState( void ); +static DD_FAULT_NVDATA_STATE_T handleFaultRunNVPOSTsState( void ); + /*********************************************************************//** * @brief * The initFaultMode function initializes the Fault Mode unit. @@ -53,6 +58,7 @@ void initFaultMode( void ) { faultState = DD_FAULT_STATE_START; + faultNVDataState = DD_FAULT_NVDATA_STATE_START; faultPOSTSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; } @@ -65,8 +71,6 @@ *************************************************************************/ 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 @@ -82,25 +86,27 @@ /*********************************************************************//** * @brief * The execFaultMode function executes the fault mode state machine. - * @details \b Inputs: none + * @details \b Inputs: faultState * @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(); + case DD_FAULT_DEENERGIZED_STATE: + faultState = handleFaultDeenergizedState(); break; + case DD_FAULT_ENERGIZED_STATE: + faultState = handleFaultEnergizedState(); + 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() ) ) @@ -121,6 +127,39 @@ /*********************************************************************//** * @brief + * The execFaultNVdataMgmt function executes the fault mode NVData + * management state machine. + * @details \b Inputs: faultNVDataState + * @details \b Outputs: Fault mode NVdata state machine executed + * @return current state of fault NVDATA management mode + *************************************************************************/ +U32 execFaultNVdataMgmt( void ) +{ + // execute current fault NVData state manangement state + switch ( faultNVDataState ) + { + case DD_FAULT_NVDATA_STATE_START: + faultNVDataState = handleFaultNVDataMgmtStartState(); + break; + + case DD_FAULT_NVDATA_STATE_RUN_NV_POSTS: + faultNVDataState = handleFaultRunNVPOSTsState(); + break; + + case DD_FAULT_NVDATA_STATE_COMPLETE: + //Do Nothing + break; + + default: + faultNVDataState = DD_FAULT_NVDATA_STATE_COMPLETE; + break; + } + + return faultNVDataState; +} + +/*********************************************************************//** + * @brief * The getCurrentFaultState function returns the current state of the fault mode. * @details \b Inputs: faultState * @details \b Outputs: none @@ -145,7 +184,6 @@ U32 i; // De-energize all the hydraulics valves - // TODO : valve state name needs to be updated setValveStateDelayed( D53_VALV, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); setValveStateDelayed( D52_VALV, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); setValveStateDelayed( D8_VALV, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); @@ -167,13 +205,15 @@ setValveStateDelayed( (VALVES_T)i, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); } + // TODO: To be removed once HDD clean up is done for ( i = FIRST_UF_VALVE; i <= FIRST_UF_VALVE; i++ ) { setValveStateDelayed( (VALVES_T)i, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); } requestConcentratePumpOff( D11_PUMP, parkPumps ); requestConcentratePumpOff( D10_PUMP, parkPumps ); + requestConcentratePumpOff( D76_PUMP, parkPumps ); signalDialysatePumpHardStop( D12_PUMP ); signalDialysatePumpHardStop( D48_PUMP ); stopHeater( D5_HEAT ); @@ -182,14 +222,144 @@ /*********************************************************************//** * @brief - * The handleFaultStartState function handles the start state of the fault mode. + * The deenergizeActuatorsWithDrainEnabled function sets most of the actuators + * to reset and de-energized state, except drain and spent balancing chamber + * valves enabled. * @details \b Inputs: none * @details \b Outputs: none - * @return next state + * @param parkPumps TRUE if concentrate pumps should be parked, FALSE if not + * @return none *************************************************************************/ +void deenergizeActuatorsWithDrainEnabled( BOOL parkPumps ) +{ + U32 i; + + // Energize drain and spent balancing chamber valves to relieve the pressure. + setValveState( D53_VALV, VALVE_STATE_OPEN ); + setValveState( D23_VALV, VALVE_STATE_OPEN ); + setValveState( D24_VALV, VALVE_STATE_OPEN ); + setValveState( D25_VALV, VALVE_STATE_OPEN ); + setValveState( D26_VALV, VALVE_STATE_OPEN ); + + // De-energize hydraulics valves + setValveStateDelayed( D52_VALV, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); + setValveStateDelayed( D8_VALV, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); + setValveStateDelayed( D54_VALV, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); + setValveStateDelayed( D14_VALV, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); + setValveStateDelayed( D65_VALV, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); + setValveStateDelayed( D64_VALV, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); + setValveStateDelayed( D31_VALV, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); + setValveStateDelayed( D34_VALV, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); + setValveStateDelayed( D35_VALV, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); + setValveStateDelayed( D40_VALV, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); + setValveStateDelayed( D47_VALV, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); + setValveStateDelayed( D3_VALV, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); + setValveStateDelayed( M4_VALV, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); + + // De-energize portion of balancing chamber valves. + setValveStateDelayed( D19_VALV, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); + setValveStateDelayed( D20_VALV, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); + setValveStateDelayed( D21_VALV, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); + setValveStateDelayed( D22_VALV, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); + + // TODO: To be removed once HDD clean up is done + // De-energize Ultrafiltration valves + for ( i = FIRST_UF_VALVE; i <= FIRST_UF_VALVE; i++ ) + { + setValveStateDelayed( (VALVES_T)i, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); + } + + requestConcentratePumpOff( D11_PUMP, parkPumps ); + requestConcentratePumpOff( D10_PUMP, parkPumps ); + requestConcentratePumpOff( D76_PUMP, parkPumps ); + signalDialysatePumpHardStop( D12_PUMP ); + signalDialysatePumpHardStop( D48_PUMP ); + stopHeater( D5_HEAT ); + stopHeater( D45_HEAT ); +} + +/*********************************************************************//** + * @brief + * The handleFaultStartState function handles the start state of + * the fault mode. + * @details \b Inputs: safetyShutdownActivated + * @details \b Outputs: none + * @return next fault state + *************************************************************************/ static DD_FAULT_STATE_T handleFaultStartState( void ) { - DD_FAULT_STATE_T state = DD_FAULT_STATE_START; + DD_FAULT_STATE_T state = DD_FAULT_STATE_START; + + // Check saftey shutdown line already pulled + if ( TRUE == isSafetyShutdownActivated() ) + { + state = DD_FAULT_DEENERGIZED_STATE; + } + else + { + state = DD_FAULT_ENERGIZED_STATE; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleFaultDeenergizedState function handles the deenergized + * state of the fault mode. + * @details \b Inputs: faultNVDataState + * @details \b Outputs: none + * @return fault state + *************************************************************************/ +static DD_FAULT_STATE_T handleFaultDeenergizedState( void ) +{ + DD_FAULT_STATE_T state = DD_FAULT_DEENERGIZED_STATE; + + deenergizeActuators( NO_PARK_CONC_PUMPS ); + + //Make sure the stored config datas read completely. + execFaultNVdataMgmt(); + + return state; +} + +/*********************************************************************//** + * @brief + * The handleFaultEnergizedState function handles the energized + * state of the fault mode (by enabling few valves). + * @details \b Inputs: none + * @details \b Outputs: none + * @return fault state + *************************************************************************/ +static DD_FAULT_STATE_T handleFaultEnergizedState( void ) +{ + DD_FAULT_STATE_T state = DD_FAULT_ENERGIZED_STATE; + + deenergizeActuatorsWithDrainEnabled( NO_PARK_CONC_PUMPS ); + + //Make sure the stored config datas read completely. + execFaultNVdataMgmt(); + + //if saftey shutdown line pulled meanwhile, trainsition to deenergized state + if ( TRUE == isSafetyShutdownActivated() ) + { + state = DD_FAULT_DEENERGIZED_STATE; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleFaultNVDataMgmtStartState function handles the start state of + * the fault NVdata management. + * @details \b Inputs: none + * @details \b Outputs: none + * @return next fault NVdata management state + *************************************************************************/ +static DD_FAULT_NVDATA_STATE_T handleFaultNVDataMgmtStartState( void ) +{ + DD_FAULT_NVDATA_STATE_T state = DD_FAULT_NVDATA_STATE_START; //NVDATAMGMT_RECORDS_READ_STATUS_T status = getNVRecordsReadStatus(); // switch ( status ) @@ -198,12 +368,12 @@ // // their CRCs. // case NVDATAMGMT_RECORDS_QUEUED: // case NVDATAMGMT_RECORDS_READ: -// state = DD_FAULT_STATE_RUN_NV_POSTS; +// state = DD_FAULT_NVDATA_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; +// state = DD_FAULT_NVDATA_STATE_COMPLETE; // break; // } @@ -215,18 +385,18 @@ * The handleFaultRunNVPOSTsState function handles running non-volatile POSTs. * @details \b Inputs: faultPOSTSelfTestResult * @details \b Outputs: faultPOSTSelfTestResult - * @return next state + * @return next fault NVdata management state *************************************************************************/ -static DD_FAULT_STATE_T handleFaultRunNVPOSTsState( void ) +static DD_FAULT_NVDATA_STATE_T handleFaultRunNVPOSTsState( void ) { - DD_FAULT_STATE_T state = DD_FAULT_STATE_RUN_NV_POSTS; + DD_FAULT_NVDATA_STATE_T state = DD_FAULT_NVDATA_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; +// state = DD_FAULT_NVDATA_STATE_COMPLETE; // } return state;