Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r1c43de0034f7347a38ca8d91acb5753a344a7133 -ra97fcffbe7b7b2d9543358ac06868829d41cf173 --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 1c43de0034f7347a38ca8d91acb5753a344a7133) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision a97fcffbe7b7b2d9543358ac06868829d41cf173) @@ -169,8 +169,7 @@ { 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 - S16 currentPositionInCounts; ///< Valve current position in counts + 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 @@ -240,10 +239,11 @@ static BOOL areValvesFunctional( void ); static void setFPGAValveSetPoint( VALVE_T valve, S16 position, BOOL enableCurrentRelaxation ); static void convertAndMonitorValvesCurrent( void ); -static void getAndMonitorValvesCurrentPosition( void ); +static void getAndMonitorValvesCurrentFPGAPosition( void ); static U32 getPublishValvesDataInterval( void ); static void publishValvesData( VALVE_T valve ); static void setValveNextStep( VALVE_T valve, U32 stepChange ); +static S16 getValvePositionCounts( VALVE_T valve ); // These functions will be used in debug only mode #ifdef DEBUG_ENABLED @@ -620,7 +620,7 @@ { // Get ready for the energized state valvesStatus[ valve ].homingEdgeDetectionCounter = 0; - valvesStatus[ valve ].targetPositionInCounts = valvesStatus[ valve ].currentPositionInCounts + HOMING_STEP_CHANGE_IN_COUNTS; + valvesStatus[ valve ].targetPositionInCounts = getValvePositionCounts( valve ) + HOMING_STEP_CHANGE_IN_COUNTS; valvesStatus[ valve ].hasValveBeenHomed = FALSE; valvesStatus[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; setFPGAValveSetPoint( valve, valvesStatus[ valve ].targetPositionInCounts, FALSE ); @@ -643,7 +643,7 @@ { VALVE_STATE_T state = VALVE_STATE_HOMING_FIND_ENERGIZED_EDGE; - S16 currentPosition = valvesStatus[ valve ].currentPositionInCounts; + S16 currentPosition = getValvePositionCounts( valve ); S16 targetPosition = valvesStatus[ valve ].targetPositionInCounts; S16 deltaPosition = targetPosition - currentPosition; @@ -664,7 +664,6 @@ { valvesStatus[ valve ].homingEdgeDetectionCounter++; } - } // Reached to target, go for the next target else @@ -690,7 +689,7 @@ { VALVE_STATE_T state = VALVE_STATE_HOMING_FIND_DEENERGIZED_EDGE; - S16 currentPosition = valvesStatus[ valve ].currentPositionInCounts; + S16 currentPosition = getValvePositionCounts( valve ); S16 targetPosition = valvesStatus[ valve ].targetPositionInCounts; S16 deltaPosition = currentPosition - targetPosition; @@ -836,7 +835,7 @@ // Get the corresponding counts of the positions S16 commandedPosition = valvesStatus[ valve ].positions[ commandedPositionEnum ]; - S16 currentPosition = valvesStatus[ valve ].currentPositionInCounts; + S16 currentPosition = getValvePositionCounts( valve ); S16 targetPosition = valvesStatus[ valve ].targetPositionInCounts; // Check if the valve is within range of the final commanded position. @@ -962,7 +961,7 @@ #endif // Get the current position of the valves in counts and store them - getAndMonitorValvesCurrentPosition(); + getAndMonitorValvesCurrentFPGAPosition(); #ifndef DISABLE_3WAY_VALVES // Get the current in ADC and convert them to amps @@ -1143,27 +1142,27 @@ /*********************************************************************//** * @brief - * The getAndMonitorValvesCurrentPosition function gets the current position \n - * of the valves and stores them into the structure of each valve. The function \n - * checks whether any of the valves have deviated from their current position \n - * if they are in idle state. If any of the valves have deviated, the function \n - * raises an alarm. + * The getAndMonitorValvesCurrentFPGAPosition function gets the current + * position of the valves from FPGA and stores them into the structure of + * each valve.The function checks whether any of the valves have deviated + * from their current position if they are in idle state. If any of the + * valves have deviated, the function raises an alarm. * @details Inputs: valvesStatus * @details Outputs: valvesStatus * @return none *************************************************************************/ -static void getAndMonitorValvesCurrentPosition( void ) +static void getAndMonitorValvesCurrentFPGAPosition( void ) { VALVE_T valve; S16 currentPostion = 0; S16 commandedPoistion = 0; VALVE_POSITION_T commandedPositionEnum; // Get the position of the valves and update the structure of each valve - valvesStatus[ VDI ].currentPositionInCounts = getFPGAValveDialyzerInletPosition(); - valvesStatus[ VDO ].currentPositionInCounts = getFPGAValveDialyzerOutletPosition(); - valvesStatus[ VBA ].currentPositionInCounts = getFPGAValveBloodArterialPosition(); - valvesStatus[ VBV ].currentPositionInCounts = getFPGAValveBloodVenousPosition(); + valvesStatus[ VDI ].currentPositionInCounts.data = (S32)getFPGAValveDialyzerInletPosition(); + valvesStatus[ VDO ].currentPositionInCounts.data = (S32)getFPGAValveDialyzerOutletPosition(); + valvesStatus[ VBA ].currentPositionInCounts.data = (S32)getFPGAValveBloodArterialPosition(); + valvesStatus[ VBV ].currentPositionInCounts.data = (S32)getFPGAValveBloodVenousPosition(); #ifndef DISABLE_3WAY_VALVES // Check the position of each valve @@ -1174,7 +1173,7 @@ { U32 maxDeviation = MAX_DEVIATION_FROM_TARGET_IN_COUNTS; - currentPostion = valvesStatus[ valve ].currentPositionInCounts; + currentPostion = getValvePositionCounts( valve ); commandedPositionEnum = valvesStatus[ valve ].commandedPosition; commandedPoistion = valvesStatus[ valve ].positions[ commandedPositionEnum ]; @@ -1246,7 +1245,7 @@ valveData.valveID = (U32)valve; valveData.state = (U32)valvesStatus[ valve ].execState; valveData.currentPosID = (U32)valvesStatus[ valve ].currentPosition; - valveData.currentPos = valvesStatus[ valve ].currentPositionInCounts; + valveData.currentPos = getValvePositionCounts( valve ); valveData.nextPos = valvesStatus[ valve ].targetPositionInCounts; valveData.current = getValveCurrent( valve ); valveData.posC = valvesStatus[ valve ].positions[ VALVE_POSITION_C_CLOSE ]; @@ -1275,7 +1274,7 @@ S16 nextStep = 0; VALVE_POSITION_T currentPositionEnum = valvesStatus[ valve ].currentPosition; VALVE_POSITION_T commandedPositionEnum = valvesStatus[ valve ].commandedPosition; - S16 currentPosition = valvesStatus[ valve ].currentPositionInCounts; + S16 currentPosition = getValvePositionCounts( valve ); S16 commandedPosition = valvesStatus[ valve ].positions[ commandedPositionEnum ]; // If the next step is less than the specified step change, set that @@ -1301,22 +1300,22 @@ // Subtract the defined number of steps for the next transition if ( commandedPositionEnum == VALVE_POSITION_B_OPEN ) { - valvesStatus[ valve ].targetPositionInCounts = valvesStatus[ valve ].currentPositionInCounts + nextStep; + valvesStatus[ valve ].targetPositionInCounts = getValvePositionCounts( valve ) + nextStep; } if ( commandedPositionEnum == VALVE_POSITION_C_CLOSE ) { - valvesStatus[ valve ].targetPositionInCounts = valvesStatus[ valve ].currentPositionInCounts - nextStep; + valvesStatus[ valve ].targetPositionInCounts = getValvePositionCounts( valve ) - nextStep; } break; case VALVE_POSITION_B_OPEN: // If the valve is currently in position B, subtract the defined number of steps for the next transition - valvesStatus[ valve ].targetPositionInCounts = valvesStatus[ valve ].currentPositionInCounts - nextStep; + valvesStatus[ valve ].targetPositionInCounts = getValvePositionCounts( valve ) - nextStep; break; case VALVE_POSITION_C_CLOSE: // If the valve is currently in position C, add the defined number of steps for the next transition - valvesStatus[ valve ].targetPositionInCounts = valvesStatus[ valve ].currentPositionInCounts + nextStep; + valvesStatus[ valve ].targetPositionInCounts = getValvePositionCounts( valve ) + nextStep; break; default: @@ -1329,6 +1328,27 @@ setFPGAValveSetPoint( valve, valvesStatus[ valve ].targetPositionInCounts, FALSE ); } +/*********************************************************************//** + * @brief + * The getValvePositionCounts function returns a valve's position in + * counts. + * @details Inputs: valvesStatus + * @details Outputs: none + * @param valve that its position in counts is requested + * @return current position of the valve in counts (S16) + *************************************************************************/ +static S16 getValvePositionCounts( VALVE_T valve ) +{ + S16 position = (S16)valvesStatus[ valve ].currentPositionInCounts.data; + + if ( OVERRIDE_KEY == valvesStatus[ valve ].currentPositionInCounts.override ) + { + position = (S16)valvesStatus[ valve ].currentPositionInCounts.ovData; + } + + return position; +} + #ifdef DEBUG_ENABLED /*********************************************************************//** * @brief @@ -1553,7 +1573,6 @@ 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; } } @@ -1580,7 +1599,6 @@ // Turn off the bypass mode request and the change request valvesStatus[ (VALVE_T)valve ].bypassModeStatus.hasBypassModeBeenRequeseted = FALSE; valvesStatus[ (VALVE_T)valve ].bypassModeStatus.hasChangeBeenRequested = FALSE; - result = TRUE; } @@ -1589,73 +1607,72 @@ /*********************************************************************//** * @brief - * The testSetValvesPositionCountOverride function overrides the valves - * position in counts. - * @details Inputs: valvesPositionOverride, valvesStatus - * @details Outputs: valvesPositionOverride - * @param valve to override its position - * @param position of the valve that will be overridden + * The testSetValvesCurrentOverride function overrides the valves' current. + * @details Inputs: valvesStatus + * @details Outputs: valvesStatus + * @param valve to override its current + * @param current of the valve that will be overridden * @return TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testSetValvesPositionCountOverride( U32 valve, U32 count ) +BOOL testSetValvesCurrentOverride( U32 valve, F32 current ) { BOOL result = FALSE; // Check if the valve is in the range of the valves available if ( ( TRUE == isTestingActivated() ) && ( valve < NUM_OF_VALVES ) ) { - /*S32 convert = (S32)count; - valvesStatus[ (VALVE_T)valve ].currentPositionInCounts.override = OVERRIDE_KEY; - valvesStatus[ (VALVE_T)valve ].currentPositionInCounts.ovData = (S16)convert; - valvesStatus[ (VALVE_T)valve ].currentPositionInCounts.ovInitData = valvesStatus[ (VALVE_T)valve ].currentPositionInCounts.data; - result = TRUE;*/ + valvesStatus[ (VALVE_T)valve ].current.override = OVERRIDE_KEY; + valvesStatus[ (VALVE_T)valve ].current.ovData = current; + valvesStatus[ (VALVE_T)valve ].current.ovInitData = valvesStatus[ (VALVE_T)valve ].current.data; + result = TRUE; } return result; } /*********************************************************************//** * @brief - * The testResetValvesPositionCountOverride function resets the override - * of the valves' position in counts. + * The testResetValvesCurrentOverride function resets the override + * of the valves' current. * @details Inputs: valvesStatus * @details Outputs: valvesStatus - * @param valve that its position count override will be reset + * @param valve that its current override will be reset * @return TRUE if override reset successful, FALSE if not *************************************************************************/ -BOOL testResetValvesPositionCountOverride( U32 valve ) +BOOL testResetValvesCurrentOverride( U32 valve ) { BOOL result = FALSE; if ( ( TRUE == isTestingActivated() ) && ( valve < NUM_OF_VALVES ) ) { - /*valvesStatus[ (VALVE_T)valve ].currentPositionInCounts.override = OVERRIDE_RESET; - valvesStatus[ (VALVE_T)valve ].currentPositionInCounts.ovData = valvesStatus[ (VALVE_T)valve ].currentPositionInCounts.ovInitData; - result = TRUE;*/ + valvesStatus[ (VALVE_T)valve ].current.override = OVERRIDE_RESET; + valvesStatus[ (VALVE_T)valve ].current.ovData = valvesStatus[ (VALVE_T)valve ].current.ovInitData; + result = TRUE; } return result; } /*********************************************************************//** * @brief - * The testSetValvesPositionOverride function overrides the valves position. - * @details Inputs: valvesStatus - * @details Outputs: valvesStatus + * The testSetValvesPositionCountOverride function overrides the valves + * position in counts. + * @details Inputs: valvesPositionOverride, valvesStatus + * @details Outputs: valvesPositionOverride * @param valve to override its position - * @param current of the valve that will be overridden + * @param position of the valve that will be overridden * @return TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testSetValvesCurrentOverride( U32 valve, F32 current ) +BOOL testSetValvesPositionCountOverride( U32 valve, U32 count ) { BOOL result = FALSE; // Check if the valve is in the range of the valves available if ( ( TRUE == isTestingActivated() ) && ( valve < NUM_OF_VALVES ) ) { - valvesStatus[ (VALVE_T)valve ].current.override = OVERRIDE_KEY; - valvesStatus[ (VALVE_T)valve ].current.ovData = current; - valvesStatus[ (VALVE_T)valve ].current.ovInitData = valvesStatus[ (VALVE_T)valve ].current.data; + valvesStatus[ (VALVE_T)valve ].currentPositionInCounts.override = OVERRIDE_KEY; + valvesStatus[ (VALVE_T)valve ].currentPositionInCounts.ovData = (S32)count; + valvesStatus[ (VALVE_T)valve ].currentPositionInCounts.ovInitData = valvesStatus[ (VALVE_T)valve ].currentPositionInCounts.data; result = TRUE; } @@ -1664,21 +1681,21 @@ /*********************************************************************//** * @brief - * The testResetValvesCurrentOverride function resets the override - * of the valves' current. + * The testResetValvesPositionCountOverride function resets the override + * of the valves' position in counts. * @details Inputs: valvesStatus * @details Outputs: valvesStatus - * @param valve that its current override will be reset + * @param valve that its position count override will be reset * @return TRUE if override reset successful, FALSE if not *************************************************************************/ -BOOL testResetValvesCurrentOverride( U32 valve ) +BOOL testResetValvesPositionCountOverride( U32 valve ) { BOOL result = FALSE; if ( ( TRUE == isTestingActivated() ) && ( valve < NUM_OF_VALVES ) ) { - valvesStatus[ (VALVE_T)valve ].current.override = OVERRIDE_RESET; - valvesStatus[ (VALVE_T)valve ].current.ovData = valvesStatus[ (VALVE_T)valve ].current.ovInitData; + valvesStatus[ (VALVE_T)valve ].currentPositionInCounts.override = OVERRIDE_RESET; + valvesStatus[ (VALVE_T)valve ].currentPositionInCounts.ovData = valvesStatus[ (VALVE_T)valve ].currentPositionInCounts.ovInitData; result = TRUE; }