Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r9725baecc8bf9720e4c27a4564b8aee3d62813e5 -r4f4050a451d88043f170814d9929ff497dc43030 --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 9725baecc8bf9720e4c27a4564b8aee3d62813e5) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 4f4050a451d88043f170814d9929ff497dc43030) @@ -78,10 +78,9 @@ #define MAX_POS_DEVIATION_TIME_INTERVAL_COUNTER ( MS_PER_SECOND / ( TASK_PRIORITY_INTERVAL ) ) ///< Valves out of range time interval counter #define VALVE_TRANSITION_TIMEOUT_MS 3000U ///< Valves transition time out in ms -// TODO changed the interval count to every 10 calls in priority task which is 100 ms -#define VALVES_DATA_PUB_INTERVAL ( MS_PER_SECOND / ( 10 * TASK_PRIORITY_INTERVAL ) ) ///< Valve data publication time interval +#define VALVES_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Valve data publication time interval -#define VALVE_MAX_ALLOWED_PWM_PERCENT 100U ///< Valve maximum allowed PWM in percent +#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_CCW_PWM_TO_CNT_CONVERSION( pwm ) ( ( -20 * pwm ) + 2500 ) ///< Valve counter clockwise PWM to count conversion @@ -130,6 +129,7 @@ NUM_OF_VALVE_CONTROL_STATUS ///< Number of valve control status }; +/// Valves bypass mode direction typedef enum valve_bypass_mode_direction { VAVLE_DIR_CLOCKWISE = 0, ///< Clockwise direction in bypass mode @@ -267,9 +267,17 @@ * @param valve that is set to be homed * @return none *************************************************************************/ -void homeValve( VALVE_T valve ) +BOOL homeValve( VALVE_T valve ) { - valvesStatus[ valve ].hasHomingBeenRequested = TRUE; + BOOL result = FALSE; + + if ( valve < NUM_OF_VALVES ) + { + valvesStatus[ valve ].hasHomingBeenRequested = TRUE; + result = TRUE; + } + + return result; } /*********************************************************************//** @@ -288,7 +296,7 @@ // Valve not in position cannot be requested // All the other positions are valid - if ( position != VALVE_POSITION_NOT_IN_POSITION ) + if ( position != VALVE_POSITION_NOT_IN_POSITION && valve < NUM_OF_VALVES ) { valvesStatus[ valve ].commandedPosition = position; valvesStatus[ valve ].hasTransitionBeenRequested = TRUE; @@ -327,7 +335,7 @@ { BOOL energized = FALSE; - if ( state == STATE_OPEN ) + if ( STATE_OPEN == state ) { energized = TRUE; } @@ -383,11 +391,10 @@ execMonitorValves(); - // TODO un-comment the for loop - //for ( valve = VDI; valve < NUM_OF_VALVES; valve++ ) + for ( valve = VDI; valve < NUM_OF_VALVES; valve++ ) { //TODO FOR TESTING ONLY REMOVE - valve = VBA; + //valve = VBA; //TODO FOR TESTING ONLY REMOVE switch ( valvesStatus[ valve ].execState ) @@ -473,18 +480,16 @@ *************************************************************************/ static VALVE_SELF_TEST_STATE_T handleValveSelfTestConfirmEnable( void ) { - VALVE_SELF_TEST_STATE_T state = VALVE_SELF_TEST_CONFIRM_ENABLE; + VALVE_SELF_TEST_STATE_T state = VALVE_SELF_TEST_COMPLETE; // TODO do we need to wait for 50ms? if ( areValvesFunctional() ) { valvesSelfTestResult = SELF_TEST_STATUS_PASSED; - state = VALVE_SELF_TEST_COMPLETE; } else { valvesSelfTestResult = SELF_TEST_STATUS_FAILED; - state = VALVE_SELF_TEST_COMPLETE; } return state; @@ -585,7 +590,9 @@ } else if ( deltaPosition < MAX_DEVIATION_FROM_TARGET_IN_COUNTS ) { +#ifdef DEBUG_ENABLED // To remove this if statement from VectorCAST if ( valvesStatus[ valve ].restCounter >= 0 )//TODO add a #define for the rest time. Do we need the rest? +#endif { valvesStatus[ valve ].homingEdgeDetectionCounter = 0; valvesStatus[ valve ].targetPositionInCounts = currentPosition + HOMING_STEP_CHANGE_IN_COUNTS; @@ -660,7 +667,9 @@ } else if ( abs(deltaPosition) < MAX_DEVIATION_FROM_TARGET_IN_COUNTS ) { +#ifdef DEBUG_ENABLED //To remove this if statement from VecotrCAST if ( valvesStatus[ valve ].restCounter >= 0 ) //TODO add a #define for the rest time. Do we need the rest? +#endif { valvesStatus[ valve ].homingEdgeDetectionCounter = 0; valvesStatus[ valve ].targetPositionInCounts = currentPosition - HOMING_STEP_CHANGE_IN_COUNTS; @@ -969,7 +978,7 @@ break; default: - // TODO alarm or ignore it? + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_HD_VALVES_INVALID_VALVE_SELECTED, (U32)valve ); break; } } @@ -1070,7 +1079,7 @@ if ( valvesStatus[ valve ].positionOutOfRangeCounter > MAX_POS_DEVIATION_TIME_INTERVAL_COUNTER ) { - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_VALVE_CURRENT_OUT_OF_RANGE, (F32)valve, currentPostion ); //TODO is S16 ok with F32? + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_VALVE_POSITION_OUT_OF_RANGE, (F32)valve, currentPostion ); //TODO is S16 ok with F32? } else if ( abs( currentPostion - commandedPoistion ) < MAX_DEVIATION_FROM_TARGET_IN_COUNTS && valvesStatus[ valve ].positionOutOfRangeCounter > 0 ) @@ -1135,10 +1144,11 @@ } // TODO REMOVE Fast 10ms publish + HD_VALVE_FAST_DATA_T fastDataRemoveLater; fastDataRemoveLater.currentPos = valvesStatus[ valve ].currentPositionInCounts; fastDataRemoveLater.current = valvesStatus[ valve ].current; fastDataRemoveLater.cmdPosition = valvesStatus[ valve ].targetPositionInCounts; - broadcastFastTempHDValves(); + broadcastFastTempHDValves( &fastDataRemoveLater ); // TODO REMOVE } @@ -1288,6 +1298,8 @@ } } #endif + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ @@ -1355,17 +1367,14 @@ { BOOL result = FALSE; - if ( valve < NUM_OF_VALVES ) + if ( TRUE == isTestingActivated() && valve < NUM_OF_VALVES ) { - if ( TRUE == isTestingActivated() ) - { - // Get the current position of the valve as the initial position - valvesPositionOverride[ valve ].ovInitData = (U32)valvesStatus[ valve ].currentPosition; - valvesPositionOverride[ valve ].ovData = position; - valvesPositionOverride[ valve ].override = OVERRIDE_KEY; + // Get the current position of the valve as the initial position + valvesPositionOverride[ valve ].ovInitData = (U32)valvesStatus[ valve ].currentPosition; + valvesPositionOverride[ valve ].ovData = position; + valvesPositionOverride[ valve ].override = OVERRIDE_KEY; - result = setValvePosition( (VALVE_T)valve, (VALVE_POSITION_T)position ); - } + result = setValvePosition( (VALVE_T)valve, (VALVE_POSITION_T)position ); } return result; @@ -1385,7 +1394,7 @@ { BOOL result = FALSE; - if ( TRUE == isTestingActivated() ) + if ( TRUE == isTestingActivated() && valve < NUM_OF_VALVES ) { valvesPositionOverride[ valve ].override = OVERRIDE_RESET; valvesPositionOverride[ valve ].ovData = valvesPositionOverride[ valve ].ovInitData; @@ -1414,27 +1423,23 @@ { BOOL result = FALSE; - if ( TRUE == isTestingActivated() ) + if ( TRUE == isTestingActivated() && valve < NUM_OF_VALVES ) { - // Check if the valve is in the range of the valves available - if ( valve < NUM_OF_VALVES ) + BOOL homingStatus = valvesStatus[ valve ].hasValveBeenHomed; + + // The PWM should be in range and also the valve direction should be legal and the valve must have been homed + // prior to running this command + if ( pwm <= VALVE_MAX_ALLOWED_PWM_PERCENT && direction < NUM_OF_VALVE_DIRECTION && homingStatus ) { - BOOL homingStatus = valvesStatus[ valve ].hasValveBeenHomed; + valvesStatus[ (VALVE_T)valve ].bypassModeStatus.commandedPWMInPercent = (U16)pwm; + valvesStatus[ (VALVE_T)valve ].bypassModeStatus.direction = (VALVE_DIRECTION_T)direction; + // This flag sets the valves to bypass mode in the idle state. After that the valve will be sitting in the + // bypass mode until this flag is set to FALSE in the reset function. + valvesStatus[ (VALVE_T)valve ].bypassModeStatus.hasBypassModeBeenRequeseted = TRUE; + // This flag is used to check if a change in PWM has been requested so the new PWM is processed and set + valvesStatus[ (VALVE_T)valve ].bypassModeStatus.hasChangeBeenRequested = TRUE; - // The PWM should be in range and also the valve direction should be legal and the valve must have been homed - // prior to running this command - if ( pwm <= VALVE_MAX_ALLOWED_PWM_PERCENT && direction < NUM_OF_VALVE_DIRECTION && homingStatus ) - { - valvesStatus[ (VALVE_T)valve ].bypassModeStatus.commandedPWMInPercent = (U16)pwm; - valvesStatus[ (VALVE_T)valve ].bypassModeStatus.direction = (VALVE_DIRECTION_T)direction; - // This flag sets the valves to bypass mode in the idle state. After that the valve will be sitting in the - // bypass mode until this flag is set to FALSE in the reset function. - valvesStatus[ (VALVE_T)valve ].bypassModeStatus.hasBypassModeBeenRequeseted = TRUE; - // This flag is used to check if a change in PWM has been requested so the new PWM is processed and set - valvesStatus[ (VALVE_T)valve ].bypassModeStatus.hasChangeBeenRequested = TRUE; - - result = TRUE; - } + result = TRUE; } } @@ -1456,7 +1461,7 @@ BOOL result = FALSE; // Check if the valve is in the range of the valves available - if ( valve < NUM_OF_VALVES ) + if ( TRUE == isTestingActivated() && valve < NUM_OF_VALVES ) { // Turn off the bypass mode request and the change request valvesStatus[ (VALVE_T)valve ].bypassModeStatus.hasBypassModeBeenRequeseted = FALSE;