/************************************************************************** * * 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) Sean * @date (last) 30-Jul-2024 * * @author (original) Sean * @date (original) 30-Jul-2024 * ***************************************************************************/ #include "Messaging.h" #include "ModeFault.h" #include "OperationModes.h" #include "Utilities.h" /** * @addtogroup TDFaultMode * @{ */ // ********** private data ********** static HD_FAULT_STATE_T faultState; ///< Currently active fault state. static SELF_TEST_STATUS_T faultPOSTSelfTestResult; ///< Fault POST self test result. // ********** private function prototypes ********** static HD_FAULT_STATE_T handleFaultStartState( void ); static HD_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 = HD_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 of the fault mode state machine *************************************************************************/ U32 transitionToFaultMode( void ) { TD_OP_MODE_T previousOpMode = getPreviousOperationMode(); // DD_OP_MODE_T dgOperationMode = getDGOpMode(); initFaultMode(); // requestAlarmLampPattern( LAMP_PATTERN_FAULT ); // in case we get here before LED POST can take alarm lamp out of manual control. // doorClosedRequired( FALSE, FALSE ); // syringeDetectionRequired( FALSE ); // setVenousBubbleDetectionEnabled( FALSE ); setCurrentSubState( NO_SUB_STATE ); // Set user alarm recovery actions allowed in this mode setAlarmUserActionEnabled( ALARM_USER_ACTION_RESUME, FALSE ); setAlarmUserActionEnabled( ALARM_USER_ACTION_RINSEBACK, FALSE ); setAlarmUserActionEnabled( ALARM_USER_ACTION_END_TREATMENT, FALSE ); // // Stop trimmer heater // cmdStopDGTrimmerHeater(); // // Stop syringe pump // stopSyringePump(); // Publish POST failure status to UI if fault triggered in Init/POST mode if ( MODE_INIT == previousOpMode ) { // sendPOSTFinalResult( FALSE ); } if ( ( MODE_PRET == previousOpMode ) || ( MODE_TREA == previousOpMode ) ) { // collectTreatmentLogData(); // sendTreatmentLogDataToUI(); } return faultState; } /*********************************************************************//** * @brief * The execFaultMode function executes the Fault Mode state machine. * @details \b Inputs: none * @details \b Outputs: none * @return current state of the fault mode *************************************************************************/ U32 execFaultMode( void ) { // BOOL stop = isStopButtonPressed(); // DG_OP_MODE_T dgOperationMode = getDGOpMode(); // Ensure all pumps are stopped // signalBloodPumpHardStop(); // setAirPumpState( AIR_PUMP_STATE_OFF ); // Ensure all valves are in safe position // setValveAirTrap( STATE_CLOSED ); // setValvePosition( H1_VALV, VALVE_POSITION_C_CLOSE ); // setValvePosition( H19, VALVE_POSITION_C_CLOSE ); // If DG not stopped, stop it // if ( DG_MODE_GENE == dgOperationMode ) // { // cmdStopDG(); // } switch( faultState ) { case HD_FAULT_STATE_START: faultState = handleFaultStartState(); break; case HD_FAULT_STATE_RUN_NV_POSTS: faultState = handleFaultRunNVPOSTsState(); break; case HD_FAULT_STATE_COMPLETE: // Do nothing unless the test configuration to recover treatment is enabled // if ( ( TRUE == getTestConfigStatus( TEST_CONFIG_RECOVER_TREATMENT ) ) && ( TRUE == hasRecoverFromFaultModeBeenSet() ) ) // { // TD_OP_MODE_T prevMode = getPreviousOperationMode(); // // requestNewOperationMode( prevMode ); // } break; default: faultState = HD_FAULT_STATE_COMPLETE; break; } return faultState; } /*********************************************************************//** * @brief * The signalAlarmActionToFaultMode function executes the given alarm action * as appropriate while in Fault Mode. * @details \b Inputs: none * @details \b Outputs: given alarm action executed * @param action ID of alarm action to execute * @return none *************************************************************************/ void signalAlarmActionToFaultMode( ALARM_ACTION_T action ) { // Fault mode is terminal and already in safe state - no alarm actions handled in this mode. } /*********************************************************************//** * @brief * The handleFaultStartState function handles the start state of the fault mode. * @details \b Inputs: none * @details \b Outputs: none * @return next state *************************************************************************/ static HD_FAULT_STATE_T handleFaultStartState( void ) { HD_FAULT_STATE_T state = HD_FAULT_STATE_COMPLETE; // 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 = HD_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 = HD_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 HD_FAULT_STATE_T handleFaultRunNVPOSTsState( void ) { HD_FAULT_STATE_T state = HD_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 = HD_FAULT_STATE_COMPLETE; // } return state; } /**@}*/