Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r8466e63f95f65a3ffb18c3af85ac99328e41167b -rcb832b3a86cc2a3147e8447f33fc99f34a2b0011 --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 8466e63f95f65a3ffb18c3af85ac99328e41167b) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision cb832b3a86cc2a3147e8447f33fc99f34a2b0011) @@ -1,17 +1,17 @@ /************************************************************************** * -* Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. +* Copyright (c) 2020-2022 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 Valves.c +* @file Valves.c * -* @author (last) Sean Nash -* @date (last) 14-Oct-2020 +* @author (last) Dara Navaei +* @date (last) 26-May-2022 * -* @author (original) Dara Navaei -* @date (original) 07-Aug-2020 +* @author (original) Dara Navaei +* @date (original) 07-Aug-2020 * ***************************************************************************/ @@ -20,8 +20,11 @@ #include "gio.h" #include "FPGA.h" +#include "MessageSupport.h" +#include "NVDataMgmt.h" #include "SafetyShutdown.h" #include "SystemCommMessages.h" +#include "Switches.h" #include "TaskPriority.h" #include "Timers.h" #include "Valves.h" @@ -72,7 +75,7 @@ #define ENABLE_VALVE_CURRENT_RELAXATION 0x8000 ///< Enable valves current relaxation #define DISABLE_VALVE_CURRENT_RELAXATION 0x7FFF ///< Disable valves current relaxation -#define ADC_TO_CURRENT_CONVERSION_CONSTANT 2048.0 ///< Valves ADC count to current conversion +#define ADC_TO_CURRENT_CONVERSION_CONSTANT 2048.0F ///< Valves ADC count to current conversion #define INITIAL_EDGE_OFFSET_READ_COUNT 100U ///< Offset in counts from energized and de-energized edges @@ -89,7 +92,7 @@ #define MAX_ALLOWED_FAILED_HOMINGS 3U ///< Maximum allowed failed homings /// The time that the valve must be at the edge to be considered for edge detection static const U32 HOMING_EDGE_DETECTION_TIME_INTERVAL = ( MS_PER_SECOND / ( 2 * TASK_PRIORITY_INTERVAL ) ); -#define VALVES_CURRENT_THRESHOLD_AMPS 1.0 ///< Valves current threshold +#define VALVES_CURRENT_THRESHOLD_AMPS 1.0F ///< Valves current threshold /// Valves over current time interval counter static const U32 MAX_OVER_CURRENT_TIME_INTERVAL_COUNTER = ( MS_PER_SECOND / ( TASK_PRIORITY_INTERVAL ) ); /// Valves out of range time interval counter @@ -101,10 +104,12 @@ #define VALVE_MAX_ALLOWED_PWM_PERCENT 100U ///< Valve maximum allowed PWM in percent #define VALVE_CW_PWM_TO_CNT_CONVERSION( pwm ) ( ( 20 * pwm ) + 2500 ) ///< Valve clockwise PWM to count conversion -#define VALVE_CW_CNT_TO_PWM_CONVERSION( cnt ) ( ( 0.05 * cnt ) - 125 ) ///< Valve clockwise count to PWM conversion +#define VALVE_CW_CNT_TO_PWM_CONVERSION( cnt ) ( ( 0.05F * cnt ) - 125 ) ///< Valve clockwise count to PWM conversion #define VALVE_CCW_PWM_TO_CNT_CONVERSION( pwm ) ( ( -20 * pwm ) + 2500 ) ///< Valve counter clockwise PWM to count conversion -#define VALVE_CCW_CNT_TO_PWM_CONVERSION( cnt ) ( ( -0.05 * cnt ) + 125 ) ///< Valve counter clockwise count to PWM conversion +#define VALVE_CCW_CNT_TO_PWM_CONVERSION( cnt ) ( ( -0.05F * cnt ) + 125 ) ///< Valve counter clockwise count to PWM conversion +#define DATA_PUBLISH_COUNTER_START_COUNT 80 ///< Data publish counter start count. + /// Exec valve self test states typedef enum valves_Self_Test_States { @@ -131,7 +136,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 +174,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 @@ -211,18 +217,15 @@ static const U16 VALVE_CONTROL_MODES_RESET_BITS[ NUM_OF_VALVES ] = { VDI_RESET_CONTROL_BIT_MASK, VDO_RESET_CONTROL_BIT_MASK, VBA_RESET_CONTROL_BIT_MASK, VBV_RESET_CONTROL_BIT_MASK }; ///< Valves control modes rest bits -#ifndef DISABLE_3WAY_VALVES -#ifndef DISABLE_VALVE_ALARMS static const U16 VALVE_CONTROL_STATUS_BITS[ NUM_OF_VALVES ][ NUM_OF_VALVE_CONTROL_STATUS ] = { { VDI_INIT_STATUS_BIT_MASK, VDI_ENABLE_PID_STATUS_BIT_MASK, VDI_ENABLE_BYPASS_STATUS_BIT_MASK, VDI_RESET_CONTROL_BIT_MASK }, { VDO_INIT_STATUS_BIT_MASK, VDO_ENABLE_PID_STATUS_BIT_MASK, VDO_ENABLE_BYPASS_STATUS_BIT_MASK, VDO_RESET_CONTROL_BIT_MASK }, { VBA_INIT_STATUS_BIT_MASK, VBA_ENABLE_PID_STATUS_BIT_MASK, VBA_ENABLE_BYPASS_STATUS_BIT_MASK, VBA_RESET_CONTROL_BIT_MASK }, { VBV_INIT_STATUS_BIT_MASK, VBV_ENABLE_PID_STATUS_BIT_MASK, VBV_ENABLE_BYPASS_STATUS_BIT_MASK, VBV_RESET_CONTROL_BIT_MASK } }; ///< Valves control status bits -#endif -#endif static U16 valvesControlSetBits = 0x0000; ///< Valves control set bit static OPN_CLS_STATE_T valveAirTrapStatus; ///< Air trap valve status (open/close) +static HD_VALVES_CAL_RECORD_T valvesCalibrationRecord; ///< Valves calibration record. // Self test function prototypes static VALVE_SELF_TEST_STATE_T handleValveSelfTestEnableValves( void ); @@ -257,8 +260,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 *************************************************************************/ @@ -279,11 +281,12 @@ // Initialize some of the variables for ( valve = VDI; valve < NUM_OF_VALVES; valve++ ) { - valvesStatus[ valve ].execState = VALVE_STATE_WAIT_FOR_POST; - valvesStatus[ valve ].current.data = 0.0; - valvesStatus[ valve ].current.ovData = 0.0; + valvesStatus[ valve ].execState = VALVE_STATE_WAIT_FOR_POST; + valvesStatus[ valve ].current.data = 0.0; + valvesStatus[ valve ].current.ovData = 0.0; valvesStatus[ valve ].current.ovInitData = 0.0; - valvesStatus[ valve ].current.override = 0; + valvesStatus[ valve ].current.override = 0; + valvesStatus[ valve ].dataPublishCounter = DATA_PUBLISH_COUNTER_START_COUNT; } // Close air trap valve @@ -293,7 +296,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 @@ -303,9 +306,12 @@ BOOL result = FALSE; if ( valve < NUM_OF_VALVES ) - { - valvesStatus[ valve ].hasHomingBeenRequested = TRUE; - result = TRUE; + { // If haven't already homed the valves, home the valves + if ( valvesStatus[ valve ].hasValveBeenHomed != TRUE ) + { + valvesStatus[ valve ].hasHomingBeenRequested = TRUE; + result = TRUE; + } } else { @@ -318,7 +324,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 +336,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 +377,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 +398,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 @@ -518,11 +523,14 @@ break; #endif +#ifndef _VECTORCAST_ + // The default cannot be reached in VectorCAST since the cases are run in a for loop default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_HD_VALVES_INVALID_EXEC_STATE, valvesStatus[ valve ].execState ); valvesStatus[ valve ].execState = VALVE_STATE_IDLE; break; +#endif } publishValvesData( valve ); @@ -532,8 +540,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,15 +567,18 @@ * @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 *************************************************************************/ static VALVE_SELF_TEST_STATE_T handleValveSelfTestConfirmEnable( void ) { VALVE_SELF_TEST_STATE_T state = VALVE_SELF_TEST_COMPLETE; - if ( TRUE == areValvesFunctional() ) + BOOL calStatus = getNVRecord2Driver( GET_CAL_VALVES, (U08*)&valvesCalibrationRecord, sizeof( HD_VALVES_CAL_RECORD_T ), + NUM_OF_CAL_DATA_HD_VALVES, ALARM_ID_NO_ALARM ); + + if ( ( TRUE == areValvesFunctional() ) && ( TRUE == calStatus ) ) { valvesSelfTestResult = SELF_TEST_STATUS_PASSED; } @@ -610,16 +621,13 @@ *************************************************************************/ static VALVE_STATE_T handleValveStateHomingNotStarted( VALVE_T valve ) { - VALVE_STATE_T state = VALVE_STATE_HOMING_NOT_STARTED; + VALVE_STATE_T state = VALVE_STATE_HOMING_NOT_STARTED; + OPN_CLS_STATE_T frontDoor = getSwitchStatus( FRONT_DOOR ); - // TODO connect this flag to the doors driver later - // For now it is assumed the door is closed - BOOL isDoorClosed = TRUE; - // If homing has been requested or POST is completed and the door has been close for the specified - // Period of time, start the homing - if ( valveSelfTestState == VALVE_SELF_TEST_COMPLETE && ( valvesStatus[ valve ].hasHomingBeenRequested || isDoorClosed ) - && ( ! valvesStatus[ valve ].hasHomingFailed ) ) + // Period of time, start the homing process + if ( ( VALVE_SELF_TEST_COMPLETE == valveSelfTestState ) && ( ( TRUE == valvesStatus[ valve ].hasHomingBeenRequested ) || ( STATE_CLOSED == frontDoor ) ) + && ( FALSE == valvesStatus[ valve ].hasHomingFailed ) ) { // Get ready for the energized state valvesStatus[ valve ].homingEdgeDetectionCounter = 0; @@ -712,15 +720,23 @@ // Positions B and C will have an offset from the edge to make sure each time the valve will not hit the edge valvesStatus[ valve ].positions[ VALVE_POSITION_B_OPEN ] = positionB - INITIAL_EDGE_OFFSET_READ_COUNT; + valvesStatus[ valve ].positions[ VALVE_POSITION_C_CLOSE ] = currentPosition + INITIAL_EDGE_OFFSET_READ_COUNT; // Position A is the average of the Position B that was read last time and position C that was the target of this state valvesStatus[ valve ].positions[ VALVE_POSITION_A_INSERT_EJECT ] = ( valvesStatus[ valve ].positions[ VALVE_POSITION_B_OPEN ] - valvesStatus[ valve ].positions[ VALVE_POSITION_C_CLOSE ] ) / 2; +#ifndef _RELEASE_ + if ( ( getSoftwareConfigStatus( SW_CONFIG_ENABLE_VBA_SPECIAL_POSITION_C ) == SW_CONFIG_ENABLE_VALUE ) && ( VBA == valve ) ) + { + valvesStatus[ valve ].positions[ VALVE_POSITION_C_CLOSE ] = currentPosition + 3000; + } +#endif + // 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; @@ -734,9 +750,7 @@ valvesStatus[ valve ].hasValveBeenHomed = FALSE; valvesStatus[ valve ].hasHomingFailed = TRUE; state = VALVE_STATE_HOMING_NOT_STARTED; -#ifndef DISABLE_VALVE_ALARMS SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_VALVE_HOMING_FAILED, (U32)valve ); -#endif } else { @@ -773,44 +787,31 @@ { VALVE_STATE_T state = VALVE_STATE_IDLE; -#ifdef TST_3WAY_VALVES_ALWAYS_OPEN - static BOOL valvesOpenedForSarina[NUM_OF_VALVES] = { FALSE, FALSE, FALSE, FALSE }; - - if ( FALSE == valvesOpenedForSarina[ valve ] ) + if ( TRUE == valvesStatus[ valve ].hasHomingBeenRequested ) { - valvesOpenedForSarina[ valve ] = TRUE; - setValvePosition( valve, VALVE_POSITION_B_OPEN ); - } -#endif - - if ( 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,35 +848,28 @@ { // 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 state = VALVE_STATE_IDLE; } // Check if the valve's transition time has timed out - else if ( didTimeout( valvesStatus[ valve ].transitionStartTime, VALVE_TRANSITION_TIMEOUT_MS ) ) + else if ( TRUE == didTimeout( valvesStatus[ valve ].transitionStartTime, VALVE_TRANSITION_TIMEOUT_MS ) ) { - valvesStatus[ valve ].hasTransitionBeenRequested = FALSE; // 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 - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_VALVE_TRANSITION_TIMEOUT, (U32)valve ); } } // Check if the valve is close to the temporary target position and if it is, assign the next target position @@ -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 @@ -958,15 +951,12 @@ *************************************************************************/ static void execMonitorValves( void ) { -#ifndef DISABLE_3WAY_VALVES // Check if the valves are still enabled areValvesFunctional(); -#endif // Get the current position of the valves in counts and store them getAndMonitorValvesCurrentFPGAPosition(); -#ifndef DISABLE_3WAY_VALVES // Get the current in ADC and convert them to amps // Check whether any of the valves are over current convertAndMonitorValvesCurrent(); @@ -976,23 +966,20 @@ #ifdef DEBUG_ENABLED getValvesCurrentPWM(); #endif -#endif } /*********************************************************************//** * @brief * 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 *************************************************************************/ static BOOL areValvesFunctional( void ) { BOOL result = TRUE; -#ifndef DISABLE_3WAY_VALVES -#ifndef DISABLE_VALVE_ALARMS VALVE_T valve; VALVE_MODE_T mode; @@ -1006,49 +993,50 @@ // Depending on the control mode of the valve, different bit masks will be checked if ( mode == VALVE_CONTROL_MODE_ENABLE_PID ) { - if ( ! ( status & VALVE_CONTROL_STATUS_BITS[ valve ][ VALVE_CONTROL_STATUS_INITIALIZED ] ) ) + if ( FALSE == ( status & VALVE_CONTROL_STATUS_BITS[ valve ][ VALVE_CONTROL_STATUS_INITIALIZED ] ) ) { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_VALVE_NOT_FUNCTIONAL, (U32)valve, (U32)mode ); result = FALSE; } - if ( ! ( status & VALVE_CONTROL_STATUS_BITS[ valve ][ VALVE_CONTROL_STATUS_PID_ENABLED ] ) ) + if ( FALSE == ( status & VALVE_CONTROL_STATUS_BITS[ valve ][ VALVE_CONTROL_STATUS_PID_ENABLED ] ) ) { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_VALVE_NOT_FUNCTIONAL, (U32)valve, (U32)mode ); 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 ] ) ) + if ( FALSE == ( status & VALVE_CONTROL_STATUS_BITS[ valve ][ VALVE_CONTROL_STATUS_BYPASS_ENABLED ] ) ) { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_VALVE_NOT_FUNCTIONAL, (U32)valve, (U32)mode ); result = FALSE; } } else if ( mode == VALVE_CONTROL_MODE_DISABLE_ALL ) { - if ( ! ( status & ( ~VALVE_CONTROL_STATUS_BITS[ valve ][ VALVE_CONTROL_STATUS_DISABLED ] ) ) ) + if ( FALSE == ( status & ( ~VALVE_CONTROL_STATUS_BITS[ valve ][ VALVE_CONTROL_STATUS_DISABLED ] ) ) ) { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_VALVE_NOT_FUNCTIONAL, (U32)valve, (U32)mode ); result = FALSE; } } +#ifndef _VECTORCAST_ + // The default cannot be reached in VectorCAST since the cases are run in a for loop // Invalid mode was selected else { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_HD_VALVES_INVALID_CONTROL_MODE_SELECTED, (U32)valve ); result = FALSE; } - } #endif -#endif + } return result; } /*********************************************************************//** * @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 @@ -1131,9 +1119,7 @@ // Check if the current is over the threshold for the defined amount of time if ( valvesStatus[ valve ].overCurrentCounter > MAX_OVER_CURRENT_TIME_INTERVAL_COUNTER ) { -#ifndef DISABLE_VALVE_ALARMS SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_VALVE_CURRENT_OUT_OF_RANGE, (F32)valve, current ); -#endif } // If the current is below the threshold again and the counter for the time is greater than else if ( ( current < VALVES_CURRENT_THRESHOLD_AMPS ) && ( valvesStatus[ valve ].overCurrentCounter > 0 ) ) @@ -1157,8 +1143,8 @@ static void getAndMonitorValvesCurrentFPGAPosition( void ) { VALVE_T valve; - S16 currentPostion = 0; - S16 commandedPoistion = 0; + S16 currentPosition = 0; + S16 commandedPosition = 0; VALVE_POSITION_T commandedPositionEnum; // Get the position of the valves and update the structure of each valve @@ -1167,7 +1153,6 @@ valvesStatus[ VBA ].currentPositionInCounts.data = (S32)getFPGAValveBloodArterialPosition(); valvesStatus[ VBV ].currentPositionInCounts.data = (S32)getFPGAValveBloodVenousPosition(); -#ifndef DISABLE_3WAY_VALVES // Check the position of each valve for ( valve = VDI; valve < NUM_OF_VALVES; valve++ ) { @@ -1176,9 +1161,9 @@ { U32 maxDeviation = MAX_DEVIATION_FROM_TARGET_IN_COUNTS; - currentPostion = getValvePositionCounts( valve ); + currentPosition = getValvePositionCounts( valve ); commandedPositionEnum = valvesStatus[ valve ].commandedPosition; - commandedPoistion = valvesStatus[ valve ].positions[ commandedPositionEnum ]; + commandedPosition = valvesStatus[ valve ].positions[ commandedPositionEnum ]; // If the current position is B, current relaxation requires looser range check if ( VALVE_POSITION_B_OPEN == commandedPositionEnum ) @@ -1189,25 +1174,22 @@ // Check if the current position has deviated from the position it is supposed to be in // For more than a certain amount of time. If it has, raise an alarm // Absolute value is used for comparison to cover +/- from the commanded position - if ( abs( currentPostion - commandedPoistion ) > maxDeviation ) + if ( abs( currentPosition - commandedPosition ) > maxDeviation ) { valvesStatus[ valve ].positionOutOfRangeCounter++; } - if ( valvesStatus[ valve ].positionOutOfRangeCounter > MAX_POS_DEVIATION_TIME_INTERVAL_COUNTER ) + if ( valvesStatus[ valve ].positionOutOfRangeCounter > MAX_POS_DEVIATION_TIME_INTERVAL_COUNTER ) { -#ifndef DISABLE_VALVE_ALARMS - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_VALVE_POSITION_OUT_OF_RANGE, (U32)valve, currentPostion ); -#endif + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_VALVE_POSITION_OUT_OF_RANGE, (U32)valve, currentPosition ); } - else if ( abs( currentPostion - commandedPoistion ) < MAX_DEVIATION_FROM_TARGET_IN_COUNTS && + else if ( abs( currentPosition - commandedPosition ) < MAX_DEVIATION_FROM_TARGET_IN_COUNTS && valvesStatus[ valve ].positionOutOfRangeCounter > 0 ) { valvesStatus[ valve ].positionOutOfRangeCounter = 0; } } } -#endif } /*********************************************************************//** @@ -1225,6 +1207,7 @@ if ( ++valvesStatus[ valve ].dataPublishCounter >= getU32OverrideValue( &valvesDataPublishInterval ) ) { HD_VALVE_DATA_T valveData; + valveData.valveID = (U32)valve; valveData.state = (U32)valvesStatus[ valve ].execState; valveData.currentPosID = (U32)getValvePosition( valve ); @@ -1237,7 +1220,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 +1369,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 +1439,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 +1460,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 @@ -1524,7 +1507,6 @@ return result; } -#ifdef DEBUG_ENABLED /*********************************************************************//** * @brief * The testSetValvePWMOverride function overrides the valves PWM in bypass @@ -1567,7 +1549,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 +1622,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 +1648,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 @@ -1685,6 +1667,4 @@ return result; } -#endif - /**@}*/