Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r17261d704df24e2cbb33f544af053d67262a9e28 -r384157184f801e501c61bdf675d7d8b727b5ab9d --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 17261d704df24e2cbb33f544af053d67262a9e28) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 384157184f801e501c61bdf675d7d8b727b5ab9d) @@ -375,94 +375,94 @@ * @param valve ID of valve for which to handle the Not Homed state * @return next state of the state machine for the given valve *************************************************************************/ -static VALVE_STATE_T handleValvesNotHomedState( VALVE_T valve ) -{ - VALVE_STATE_T nextState = VALVE_STATE_HOMING_NOT_HOMED; - - if ( ( TRUE == currentValveStates[ valve ].hasHomingBeenRequested ) && - ( FALSE == currentValveStates[ valve ].homingOperationActive ) ) - { - if ( TRUE == homePinchValve( valve ) ) - { - currentValveStates[ valve ].hasHomingBeenRequested = FALSE; - currentValveStates[ valve ].hasValveBeenHomed = FALSE; - currentValveStates[ valve ].homingOperationActive = TRUE; - currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; - currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); - } - } - else if ( ( TRUE == currentValveStates[ valve ].homingOperationActive ) && ( TRUE == isPinchValveHomed( valve ) ) ) - { - currentValveStates[ valve ].homingOperationActive = FALSE; - currentValveStates[ valve ].hasValveBeenHomed = TRUE; - currentValveStates[ valve ].commandedPosition = VALVE_POSITION_C_CLOSE; - currentValveStates[ valve ].currentPosition = getCurrentValveABCPosition( valve ); - nextState = VALVE_STATE_IDLE; - } - else if ( ( TRUE == currentValveStates[ valve ].homingOperationActive ) && - ( TRUE == didTimeout( currentValveStates[ valve ].valveOpsStartTime, VALVE_HOMING_TIMEOUT_MS ) ) && - ( TRUE != getCPLDACPowerLossDetected() ) ) - { - currentValveStates[ valve ].homingOperationActive = FALSE; - currentValveStates[ valve ].hasValveBeenHomed = FALSE; - currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; - - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_VALVE_TRANSITION_TIMEOUT, (U32)valve, (U32)getPinchValvePosition( valve ) ) - } - - return nextState; -} - - //static VALVE_STATE_T handleValvesNotHomedState( VALVE_T valve ) //{ // VALVE_STATE_T nextState = VALVE_STATE_HOMING_NOT_HOMED; // -// if ( TRUE == currentValveStates[ valve ].hasHomingBeenRequested ) +// if ( ( TRUE == currentValveStates[ valve ].hasHomingBeenRequested ) && +// ( FALSE == currentValveStates[ valve ].homingOperationActive ) ) // { // if ( TRUE == homePinchValve( valve ) ) // { // currentValveStates[ valve ].hasHomingBeenRequested = FALSE; // currentValveStates[ valve ].hasValveBeenHomed = FALSE; // currentValveStates[ valve ].homingOperationActive = TRUE; // currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; -// currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); +// currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); // } // } -// else if ( ( TRUE == currentValveStates[ valve ].homingOperationActive ) && -// ( TRUE == isPinchValveHomed( valve ) ) && ( FALSE == isPinchValveBusy( valve ) ) ) +// else if ( ( TRUE == currentValveStates[ valve ].homingOperationActive ) && ( TRUE == isPinchValveHomed( valve ) ) ) // { // currentValveStates[ valve ].homingOperationActive = FALSE; // currentValveStates[ valve ].hasValveBeenHomed = TRUE; -// if ( TRUE == movePinchValveToStoredPosition( valve, VALVE_POSITION_C_CLOSE ) ) -// { -// currentValveStates[ valve ].commandedPosition = VALVE_POSITION_C_CLOSE; -// currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; -// currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); -// nextState = VALVE_STATE_IN_TRANSITION; -// } -// else -// { -// currentValveStates[ valve ].hasValveBeenHomed = FALSE; -// currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; -// nextState = VALVE_STATE_HOMING_NOT_HOMED; -// } +// currentValveStates[ valve ].commandedPosition = VALVE_POSITION_C_CLOSE; +// currentValveStates[ valve ].currentPosition = getCurrentValveABCPosition( valve ); +// nextState = VALVE_STATE_IDLE; // } // else if ( ( TRUE == currentValveStates[ valve ].homingOperationActive ) && -// ( TRUE == didTimeout( currentValveStates[ valve ].valveOpsStartTime, VALVE_HOMING_TIMEOUT_MS ) ) && -// ( TRUE != getCPLDACPowerLossDetected() ) ) +// ( TRUE == didTimeout( currentValveStates[ valve ].valveOpsStartTime, VALVE_HOMING_TIMEOUT_MS ) ) && +// ( TRUE != getCPLDACPowerLossDetected() ) ) // { -// // currentValveStates[ valve ].homingOperationActive = FALSE; // currentValveStates[ valve ].hasValveBeenHomed = FALSE; // currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; +// // SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_VALVE_TRANSITION_TIMEOUT, (U32)valve, (U32)getPinchValvePosition( valve ) ) -// nextState = VALVE_STATE_HOMING_NOT_HOMED; // } // // return nextState; //} + +static VALVE_STATE_T handleValvesNotHomedState( VALVE_T valve ) +{ + VALVE_STATE_T nextState = VALVE_STATE_HOMING_NOT_HOMED; + + if ( TRUE == currentValveStates[ valve ].hasHomingBeenRequested ) + { + if ( TRUE == homePinchValve( valve ) ) + { + currentValveStates[ valve ].hasHomingBeenRequested = FALSE; + currentValveStates[ valve ].hasValveBeenHomed = FALSE; + currentValveStates[ valve ].homingOperationActive = TRUE; + currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; + currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); + } + } + else if ( ( TRUE == currentValveStates[ valve ].homingOperationActive ) && + ( TRUE == isPinchValveHomed( valve ) ) && ( FALSE == isPinchValveBusy( valve ) ) ) + { + currentValveStates[ valve ].homingOperationActive = FALSE; + currentValveStates[ valve ].hasValveBeenHomed = TRUE; + if ( TRUE == movePinchValveToStoredPosition( valve, VALVE_POSITION_C_CLOSE ) ) + { + currentValveStates[ valve ].commandedPosition = VALVE_POSITION_C_CLOSE; + currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; + currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); + nextState = VALVE_STATE_IN_TRANSITION; + } + else + { + currentValveStates[ valve ].hasValveBeenHomed = FALSE; + currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; + nextState = VALVE_STATE_HOMING_NOT_HOMED; + } + } + else if ( ( TRUE == currentValveStates[ valve ].homingOperationActive ) && + ( TRUE == didTimeout( currentValveStates[ valve ].valveOpsStartTime, VALVE_HOMING_TIMEOUT_MS ) ) && + ( TRUE != getCPLDACPowerLossDetected() ) ) + { + + currentValveStates[ valve ].homingOperationActive = FALSE; + currentValveStates[ valve ].hasValveBeenHomed = FALSE; + currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_VALVE_TRANSITION_TIMEOUT, (U32)valve, (U32)getPinchValvePosition( valve ) ) + nextState = VALVE_STATE_HOMING_NOT_HOMED; + } + + return nextState; +} + /*********************************************************************//** * @brief * The handleValvesIdleState function handles the Idle state of the state Index: firmware/App/Drivers/PinchValve.c =================================================================== diff -u -rcb993d86277143601d484b8b4d1229605e4b7395 -r384157184f801e501c61bdf675d7d8b727b5ab9d --- firmware/App/Drivers/PinchValve.c (.../PinchValve.c) (revision cb993d86277143601d484b8b4d1229605e4b7395) +++ firmware/App/Drivers/PinchValve.c (.../PinchValve.c) (revision 384157184f801e501c61bdf675d7d8b727b5ab9d) @@ -33,6 +33,11 @@ #define PINCH_VALVE_HOME_OFFSET 20 ///< Offset (in encoder counts) from end of travel edge to set position B and C. +#define H1_VALVE_POSITION_B_OFFSET_COUNTS 600 +#define H1_VALVE_POSITION_C_OFFSET_COUNTS 900 +#define H19_VALVE_POSITION_B_OFFSET_COUNTS 600 +#define H19_VALVE_POSITION_C_OFFSET_COUNTS 800 + #define PINCH_VALVE_FPGA_CMD_START_BIT_MASK 0x01 ///< FPGA command register bit 0 used to start a command transaction #define PINCH_VALVE_FPGA_CMD_WRITE_ONLY_BIT_MASK 0x02 ///< FPGA command register bit 1 indicating a write only command. #define PINCH_VALVE_FPGA_CMD_TX_COUNT_SHIFT 2 ///< Bit shift for the FPGA command transmit word count field @@ -449,7 +454,7 @@ { clearActivePinchValveCommand( valve ); commandFailed[ valve ] = FALSE; - commandState[ valve ] = PINCH_VALVE_CMD_IDLE_STATE; + commandState[ valve ] = PINCH_VALVE_CMD_IDLE_STATE; } else if ( PINCH_VALVE_CMD_SET_CMD_STATE == nextState ) { @@ -584,12 +589,10 @@ { value &= ~PINCH_VALVE_ENABLE_BIT_MASK; } - if ( TRUE == reset ) { value |= PINCH_VALVE_RESET_BIT_MASK; } - setH1EnableReset( value ); } else if ( H19_VALV == valve ) @@ -600,7 +603,6 @@ { value &= ~PINCH_VALVE_ENABLE_BIT_MASK; } - if ( TRUE == reset ) { value |= PINCH_VALVE_RESET_BIT_MASK; @@ -626,7 +628,8 @@ { result = FALSE; - if ( ( PINCH_VALVE_FUNCTION_IDLE_STATE != functionState[ valve ] ) || ( PINCH_VALVE_CMD_IDLE_STATE != commandState[ valve ] ) ) + if ( ( PINCH_VALVE_FUNCTION_IDLE_STATE != functionState[ valve ] ) || + ( PINCH_VALVE_CMD_IDLE_STATE != commandState[ valve ] ) ) { result = TRUE; } @@ -956,7 +959,8 @@ { U08 transmitWordCount = (U08)( command->inputWordCount + 1 ); - if ( ( command->inputWordCount <= PINCH_VALVE_MAX_INPUT_WORDS ) && ( command->outputWordCount <= PINCH_VALVE_MAX_OUTPUT_WORDS ) && + if ( ( command->inputWordCount <= PINCH_VALVE_MAX_INPUT_WORDS ) && + ( command->outputWordCount <= PINCH_VALVE_MAX_OUTPUT_WORDS ) && ( transmitWordCount <= PINCH_VALVE_MAX_TRANSMIT_WORDS ) ) { *fpgaCommand = 0; @@ -986,7 +990,11 @@ *************************************************************************/ static BOOL isPinchValveCommandDone( VALVE_T valve ) { - return ( ( commandSpiStatus[ valve ] & PINCH_VALVE_SPI_DONE_BIT_MASK ) != 0 ); + BOOL result; + + result = ( ( commandSpiStatus[ valve ] & PINCH_VALVE_SPI_DONE_BIT_MASK ) != 0 ); + + return result; } /*********************************************************************//** @@ -999,7 +1007,11 @@ *************************************************************************/ static BOOL isPinchValveControllerFaultActive( VALVE_T valve ) { - return ( ( commandSpiStatus[ valve ] & PINCH_VALVE_SPI_CONTROLLER_FAULT_BIT_MASK ) != 0 ); + BOOL result; + + result = ( ( commandSpiStatus[ valve ] & PINCH_VALVE_SPI_CONTROLLER_FAULT_BIT_MASK ) != 0 ); + + return result; } /*********************************************************************//** @@ -1012,7 +1024,11 @@ *************************************************************************/ static BOOL didPinchValveErrorCountChange( VALVE_T valve ) { - return ( commandErrorCount[ valve ] != errorCountAtCommandStart[ valve ] ); + BOOL result; + + result = ( commandErrorCount[ valve ] != errorCountAtCommandStart[ valve ] ); + + return result; } /*********************************************************************//** @@ -1085,7 +1101,11 @@ *************************************************************************/ static BOOL isValidPinchValve( VALVE_T valve ) { - return ( ( H1_VALV == valve ) || ( H19_VALV == valve ) ); + BOOL result; + + result = ( ( H1_VALV == valve ) || ( H19_VALV == valve ) ); + + return result; } /*********************************************************************//** @@ -1106,7 +1126,8 @@ { U08 transmitWordCount = (U08)( command->inputWordCount + 1 ); - if ( ( command->inputWordCount <= PINCH_VALVE_MAX_INPUT_WORDS ) && ( command->outputWordCount <= PINCH_VALVE_MAX_OUTPUT_WORDS ) && + if ( ( command->inputWordCount <= PINCH_VALVE_MAX_INPUT_WORDS ) && + ( command->outputWordCount <= PINCH_VALVE_MAX_OUTPUT_WORDS ) && ( transmitWordCount <= PINCH_VALVE_MAX_TRANSMIT_WORDS ) ) { result = TRUE; @@ -1137,7 +1158,6 @@ } } - /*********************************************************************//** * @brief * The getSigned32OutputValue function combines two 16 bit command output @@ -1225,23 +1245,23 @@ currentValvePosition[ valve ] = getSigned32OutputValue( valve ); if ( H1_VALV == valve ) { - valvePositions[ valve ][ VALVE_POSITION_B_OPEN ] = currentValvePosition[ valve ] + PINCH_VALVE_HOME_OFFSET; + valvePositions[ valve ][ VALVE_POSITION_B_OPEN ] = currentValvePosition[ valve ] + H1_VALVE_POSITION_B_OFFSET_COUNTS; } else { - valvePositions[ valve ][ VALVE_POSITION_B_OPEN ] = currentValvePosition[ valve ] - PINCH_VALVE_HOME_OFFSET; + valvePositions[ valve ][ VALVE_POSITION_B_OPEN ] = currentValvePosition[ valve ] - H19_VALVE_POSITION_B_OFFSET_COUNTS; } break; case PINCH_VALVE_HOME_CMD_GET_ACTUAL_POSITION_C: currentValvePosition[ valve ] = getSigned32OutputValue( valve ); if ( H1_VALV == valve ) { - valvePositions[ valve ][ VALVE_POSITION_C_CLOSE ] = currentValvePosition[ valve ] - PINCH_VALVE_HOME_OFFSET; + valvePositions[ valve ][ VALVE_POSITION_C_CLOSE ] = currentValvePosition[ valve ] - H1_VALVE_POSITION_C_OFFSET_COUNTS; } else { - valvePositions[ valve ][ VALVE_POSITION_C_CLOSE ] = currentValvePosition[ valve ] + PINCH_VALVE_HOME_OFFSET; + valvePositions[ valve ][ VALVE_POSITION_C_CLOSE ] = currentValvePosition[ valve ] + H19_VALVE_POSITION_C_OFFSET_COUNTS; } positionB = valvePositions[ valve ][ VALVE_POSITION_B_OPEN ]; positionC = valvePositions[ valve ][ VALVE_POSITION_C_CLOSE ]; Index: firmware/App/Monitors/Pressures.c =================================================================== diff -u -r0f2921b5c227ee8fb52d8a9ae8b51e507550ea23 -r384157184f801e501c61bdf675d7d8b727b5ab9d --- firmware/App/Monitors/Pressures.c (.../Pressures.c) (revision 0f2921b5c227ee8fb52d8a9ae8b51e507550ea23) +++ firmware/App/Monitors/Pressures.c (.../Pressures.c) (revision 384157184f801e501c61bdf675d7d8b727b5ab9d) @@ -423,16 +423,15 @@ { filtArt = getFilteredArterialPressure(); filtVen = getFilteredVenousPressure(); + filtTmp = getTMPPressure(); } else { filtArt = getLongFilteredArterialPressure(); filtVen = getLongFilteredVenousPressure(); + filtTmp = getLongFilteredTMPPressure(); } - // Using final TMP value for override. - filtTmp = getLongFilteredTMPPressure(); - curArtPres = FLOAT_TO_INT_WITH_ROUND( filtArt ); curVenPres = FLOAT_TO_INT_WITH_ROUND( filtVen ); curTmpPres = FLOAT_TO_INT_WITH_ROUND( filtTmp ); @@ -497,8 +496,8 @@ { // apply pressure windows when stable S32 artOffset = (S32)getSysConfigTreatmentParameterU32( TREATMENT_PARAM_ART_PRES_LIMIT_WINDOW ); - S32 venMinOffset = (S32)getSysConfigTreatmentParameterU32( TREATMENT_PARAM_VEN_PRES_HIGH_LIMIT_WINDOW ); - S32 venMaxOffset = (S32)getSysConfigTreatmentParameterU32( TREATMENT_PARAM_VEN_PRES_LOW_LIMIT_WINDOW ); + S32 venMinOffset = (S32)getSysConfigTreatmentParameterU32( TREATMENT_PARAM_VEN_PRES_LOW_LIMIT_WINDOW ); + S32 venMaxOffset = (S32)getSysConfigTreatmentParameterU32( TREATMENT_PARAM_VEN_PRES_HIGH_LIMIT_WINDOW ); S32 tmpOffset = (S32)getSysConfigTreatmentParameterU32( TREATMENT_PARAM_TMP_PRES_LIMIT_WINDOW ); currentArterialMinLimit = stableArterialPressure - artOffset;