Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -rccfd15568f1e3d304320c2babb2fd4bcf0413304 -r372c5a6b51002cdf79aa3c7c9036cced7d5b00a6 --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision ccfd15568f1e3d304320c2babb2fd4bcf0413304) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 372c5a6b51002cdf79aa3c7c9036cced7d5b00a6) @@ -20,6 +20,7 @@ #include "gio.h" #include "FPGA.h" +#include "MessageSupport.h" #include "SafetyShutdown.h" #include "SystemCommMessages.h" #include "TaskPriority.h" @@ -131,7 +132,7 @@ typedef enum valve_modes { VALVE_CONTROL_MODE_ENABLE_PID = 0, ///< Valve control mode enable PID - VALVE_CONTORL_MODE_ENABLE_BYPASS, ///< Valve control mode enable bypass + VALVE_CONTROL_MODE_ENABLE_BYPASS, ///< Valve control mode enable bypass VALVE_CONTROL_MODE_DISABLE_ALL, ///< Valve control mode disable all modes NUM_OF_VALVE_CONTROL_MODES, ///< Number of valve control modes } VALVE_MODE_T; @@ -169,7 +170,8 @@ { VALVE_POSITION_T commandedPosition; ///< Valve commanded position enum VALVE_POSITION_T currentPosition; ///< Valve current position enum - OVERRIDE_S32_T currentPositionInCounts; ///< Valve current position in counts + VALVE_POSITION_T pendingCommandedPosition; ///< Valve pending position enum + OVERRIDE_S32_T currentPositionInCounts; ///< Valve current position in counts S16 targetPositionInCounts; ///< Valve target position in counts BOOL hasTransitionBeenRequested; ///< Valve transition request flag VALVE_STATE_T execState; ///< Valve execution state @@ -257,8 +259,7 @@ /*********************************************************************//** * @brief * The initValves function initializes the valves driver. - * @details Inputs: valveSelfTestState, valvesSelfTestResult, valvesStatus, - * valvesControlSetBits + * @details Inputs: none * @details Outputs: valveSelfTestState, valvesSelfTestResult, valvesStatus * @return none *************************************************************************/ @@ -293,7 +294,7 @@ /*********************************************************************//** * @brief * The homeValve function sets the homing request flag of a valve to TRUE. - * @details Inputs: valvesStatus + * @details Inputs: none * @details Outputs: valvesStatus (The flag that sets the homing request) * @param valve that is set to be homed * @return none @@ -318,7 +319,7 @@ /*********************************************************************//** * @brief * The setValvePosition function sets the requested position of a valve. - * @details Inputs: valvesStatus + * @details Inputs: none * @details Outputs: valvesStatus * @param valve that its position is set * @param position that the valve is set @@ -330,11 +331,10 @@ // Valve not in position cannot be requested // All the other positions are valid - if ( position != VALVE_POSITION_NOT_IN_POSITION && valve < NUM_OF_VALVES ) + if ( ( position != VALVE_POSITION_NOT_IN_POSITION ) && ( valve < NUM_OF_VALVES ) ) { - valvesStatus[ valve ].commandedPosition = position; + valvesStatus[ valve ].pendingCommandedPosition = position; valvesStatus[ valve ].hasTransitionBeenRequested = TRUE; - result = TRUE; } else @@ -372,7 +372,7 @@ /*********************************************************************//** * @brief * The getValveCurrent function returns the current of a valve. - * @details Inputs: none + * @details Inputs: valvesStatus * @details Outputs: valvesStatus * @param valve that the current is requested * @return returns the current of the valve in float @@ -393,7 +393,7 @@ * @brief * The setValveBloodTrap function set the blood trap valve to open or close * position. - * @details Inputs: valveAirTrapStatus + * @details Inputs: none * @details Outputs: valveAirTrapStatus * @param state enumeration of open or close for valve * @return: none @@ -532,8 +532,8 @@ /*********************************************************************//** * @brief * The handleValveSelfTestEnableValves function starts the valves self test. - * @details Inputs: valvesSelfTestResult, valvesSelfTestResult - * @details Outputs: valvesSelfTestResult, valvesSelfTestResult + * @details Inputs: none + * @details Outputs: valvesStatus, valvesSelfTestResult * @return next state of the self test state machine *************************************************************************/ static VALVE_SELF_TEST_STATE_T handleValveSelfTestEnableValves( void ) @@ -559,7 +559,7 @@ * @brief * The handleValveSelfTestConfirmEnable function checks to make sure the * valves are enabled properly. - * @details Inputs: valvesSelfTestResult + * @details Inputs: none * @details Outputs: valvesSelfTestResult * @return next state of the self test state machine *************************************************************************/ @@ -720,7 +720,7 @@ // Set the current position to Position C and the commanded position to Position A valvesStatus[ valve ].hasValveBeenHomed = TRUE; valvesStatus[ valve ].currentPosition = VALVE_POSITION_C_CLOSE; - valvesStatus[ valve ].commandedPosition = VALVE_POSITION_A_INSERT_EJECT; + valvesStatus[ valve ].pendingCommandedPosition = VALVE_POSITION_A_INSERT_EJECT; valvesStatus[ valve ].hasTransitionBeenRequested = TRUE; valvesStatus[ valve ].hasHomingBeenRequested = FALSE; valvesStatus[ valve ].numberOfFailedHomings = 0; @@ -783,34 +783,31 @@ } #endif - if ( valvesStatus[ valve ].hasHomingBeenRequested ) + if ( TRUE == valvesStatus[ valve ].hasHomingBeenRequested ) { state = VALVE_STATE_HOMING_NOT_STARTED; } - else if ( valvesStatus[ valve ].hasValveBeenHomed && valvesStatus[ valve ].hasTransitionBeenRequested ) + else if ( ( TRUE == valvesStatus[ valve ].hasValveBeenHomed ) && ( TRUE == valvesStatus[ valve ].hasTransitionBeenRequested ) ) { - if ( valvesStatus[ valve ].currentPosition != valvesStatus[ valve ].commandedPosition ) + if ( valvesStatus[ valve ].currentPosition != valvesStatus[ valve ].pendingCommandedPosition ) { // Just set the valves to transition so it will not be in a known position for a while - valvesStatus[ valve ].transitionStartTime = getMSTimerCount(); + valvesStatus[ valve ].commandedPosition = valvesStatus[ valve ].pendingCommandedPosition; + valvesStatus[ valve ].transitionStartTime = getMSTimerCount(); + valvesStatus[ valve ].hasTransitionBeenRequested = FALSE; setValveNextStep( valve, TRANSITION_STEP_CHANGE_IN_COUNTS ); state = VALVE_STATE_IN_TRANSITION; } - else - { - valvesStatus[ valve ].hasTransitionBeenRequested = FALSE; - } } // This option is only available in a debug build #ifdef DEBUG_ENABLED // Check if the valves have been homed and a bypass mode has been requested - else if ( valvesStatus[ valve ].hasValveBeenHomed && - valvesStatus[ valve ].bypassModeStatus.hasBypassModeBeenRequeseted ) + else if ( ( TRUE == valvesStatus[ valve ].hasValveBeenHomed ) && ( TRUE == valvesStatus[ valve ].bypassModeStatus.hasBypassModeBeenRequeseted ) ) { // Set the valve control mode to bypass and set the PWM - setValveControlMode( valve, VALVE_CONTORL_MODE_ENABLE_BYPASS ); - valvesStatus[ valve ].controlMode = VALVE_CONTORL_MODE_ENABLE_BYPASS; + setValveControlMode( valve, VALVE_CONTROL_MODE_ENABLE_BYPASS ); + valvesStatus[ valve ].controlMode = VALVE_CONTROL_MODE_ENABLE_BYPASS; valvesStatus[ valve ].bypassModeStatus.hasChangeBeenRequested = FALSE; setFPGAValvePWM( valve ); @@ -847,15 +844,12 @@ { // The valve is in range. Set the current position to the commanded position valvesStatus[ valve ].currentPosition = commandedPositionEnum; - // Set the transition request to false as it has been serviced - valvesStatus[ valve ].hasTransitionBeenRequested = FALSE; // If we are in Pos B, enable current relaxation if ( commandedPositionEnum == VALVE_POSITION_B_OPEN ) { // Enable current relaxation setFPGAValveSetPoint( valve, currentPosition, TRUE ); - valvesStatus[ valve ].hasTransitionBeenRequested = TRUE; } // Go back to Idle state @@ -864,14 +858,14 @@ // Check if the valve's transition time has timed out else if ( didTimeout( valvesStatus[ valve ].transitionStartTime, VALVE_TRANSITION_TIMEOUT_MS ) ) { - valvesStatus[ valve ].hasTransitionBeenRequested = FALSE; + //valvesStatus[ valve ].hasTransitionBeenRequested = FALSE; TODO remove // Go back to Idle state state = VALVE_STATE_IDLE; #ifndef DISABLE_VALVE_ALARMS SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_VALVE_TRANSITION_TIMEOUT, (U32)valve ); #endif // If the valve transition timeout is active and the valve's commanded positions is position C, activate safety shutdown - if ( isAlarmActive( ALARM_ID_HD_VALVE_TRANSITION_TIMEOUT ) && valvesStatus[ valve ].commandedPosition == VALVE_POSITION_C_CLOSE ) + if ( ( TRUE == isAlarmActive( ALARM_ID_HD_VALVE_TRANSITION_TIMEOUT ) ) && ( VALVE_POSITION_C_CLOSE == valvesStatus[ valve ].commandedPosition ) ) { activateSafetyShutdown(); // Set the alarm @@ -926,8 +920,7 @@ /*********************************************************************//** * @brief * The setValveControlMode function sets the valves control mode. - * @details Inputs: valvesControlSetBits, valvesControlModesSetBits, - * valvesControlModesResetBits + * @details Inputs: none * @details Outputs: valvesControlSetBits * @param valve that its control mode is set * @param mode the control mode that the valve will be set to @@ -984,7 +977,7 @@ * The areValvesEnabled function checks the current valves status from FPGA * to the enable bit mask of each valve. If any of the valves is not enabled * the function raises an alarm. - * @details Inputs: valvesStatus, valvesControlStatusBits + * @details Inputs: valvesStatus * @details Outputs: none * @return Returns TRUE if all the valves are enabled properly *************************************************************************/ @@ -1017,7 +1010,7 @@ result = FALSE; } } - else if ( mode == VALVE_CONTORL_MODE_ENABLE_BYPASS ) + else if ( mode == VALVE_CONTROL_MODE_ENABLE_BYPASS ) { if ( ! ( status & VALVE_CONTROL_STATUS_BITS[ valve ][ VALVE_CONTROL_STATUS_BYPASS_ENABLED ] ) ) { @@ -1048,7 +1041,7 @@ /*********************************************************************//** * @brief - * The setFPGAValue function sets the position of a valve to FPGA. + * The setFPGAValveSetPoint function sets the position of a valve to FPGA. * @details Inputs: none * @details Outputs: none * @param valve that its FPGA set point is updated @@ -1237,7 +1230,7 @@ valveData.pwm = valvesStatus[ valve ].bypassModeStatus.currentPWMInPercent; valveData.airTrapValve = (U32)getValveAirTrapStatus(); - broadcastHDValves( &valveData ); + broadcastData( MSG_ID_HD_VALVES_DATA, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&valveData, sizeof( HD_VALVE_DATA_T ) ); valvesStatus[ valve ].dataPublishCounter = 0; } @@ -1386,7 +1379,7 @@ * @brief * The getValvesCurrentPWM function gets the PWM counts from the FPGA module * and converts them in to duty cycle in percent. - * @details Inputs: valvesStatus + * @details Inputs: none * @details Outputs: valvesStatus * @return none *************************************************************************/ @@ -1456,7 +1449,7 @@ * @brief * The testResetValvesDataPublishInterval function resets the override * of the valves publish interval. - * @details Inputs: valvesDataPublishInterval + * @details Inputs: none * @details Outputs: valvesDataPublishInterval * @return TRUE if override reset successful, FALSE if not *************************************************************************/ @@ -1477,7 +1470,7 @@ /*********************************************************************//** * @brief * The testSetValvesPositionOverride function overrides the valves position. - * @details Inputs: valvesPositionOverride, valvesStatus + * @details Inputs: none * @details Outputs: valvesPositionOverride * @param valve to override its position * @param position of the valve that will be overridden @@ -1567,7 +1560,7 @@ * @brief * The testResetValvePWMOverride function resets the override PWM in bypass * control mode. - * @details Inputs: valvesStatus + * @details Inputs: none * @details Outputs: valvesStatus * @param valve that its PWM override will be reset * @return TRUE if override reset successful, FALSE if not @@ -1640,8 +1633,8 @@ * @brief * The testSetValvesPositionCountOverride function overrides the valves * position in counts. - * @details Inputs: valvesPositionOverride, valvesStatus - * @details Outputs: valvesPositionOverride + * @details Inputs: valvesStatus + * @details Outputs: none * @param valve to override its position * @param position of the valve that will be overridden * @return TRUE if override successful, FALSE if not @@ -1666,7 +1659,7 @@ * @brief * The testResetValvesPositionCountOverride function resets the override * of the valves' position in counts. - * @details Inputs: valvesStatus + * @details Inputs: none * @details Outputs: valvesStatus * @param valve that its position count override will be reset * @return TRUE if override reset successful, FALSE if not