Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -ra6fec5578295ef0bb7223376facb7d0cbd2c1209 -r9d40104500ae1c144a19b36b83a0515d32fb7fc9 --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision a6fec5578295ef0bb7223376facb7d0cbd2c1209) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 9d40104500ae1c144a19b36b83a0515d32fb7fc9) @@ -45,25 +45,31 @@ #define VBV_ENABLE_PID_STATUS_BIT_MASK 0x0010 #define VBV_ENABLE_BYPASS_STATUS_BIT_MASK 0x0020 -#define ADC_TO_VOLTAGE_CONVERSION(adc) ( (F32)( adc / 2048 ) -1 ) -#define VOLTAGE_TO_AMPS_CONVERSION(vol) ( ( 2 * vol) - 1 ) +#define ALL_VALVES_ENABLE_PID_INTERFACE 0x0055 +#define ADC_TO_CURRENT_CONVERSION_CONSTANT 2048.0 + #define INITIAL_EDGE_OFFSET_READ_COUNT 100 -#define INITIAL_DEENERGIZED_POSITION ( 0 - INITIAL_EDGE_OFFSET_READ_COUNT ) -#define INITIAL_ENERGIZED_POSITION ( 12000 + INITIAL_EDGE_OFFSET_READ_COUNT ) +#define INITIAL_DEENERGIZED_POSITION ( 0 - INITIAL_EDGE_OFFSET_READ_COUNT ) //TODO remove +#define INITIAL_ENERGIZED_POSITION ( 12000 + INITIAL_EDGE_OFFSET_READ_COUNT ) //TODO Remove -#define STEP_CHANGE_IN_COUNTS 100 +#define STEP_CHANGE_IN_COUNTS 1000 #define MAX_POS_DEVIATION_FROM_TARGET_COUNTS 1000 //TODO test this tolerance -#define VALVE_TRANSITION_TIMEOUT_MS 50 //TODO test the timeout -#define MAX_POSITION_DEVIATION_FROM_EDGES_COUNTS 50U +#define VALVE_TRANSITION_TIMEOUT_MS 5000 //TODO test the timeout +#define MAX_POSITION_DEVIATION_FROM_EDGES_IN_COUNTS 150U #define MAX_ALLOWED_FAILED_HOMINGS 3U #define HOMING_EDGE_DETECTION_TARGET_COUNTER 5U #define VALVES_CURRENT_THRESHOLD_AMPS 1U #define OVER_CURRENT_COUNTER 100U #define OUT_OF_RANGE_COUNTER 100U -#define VALVES_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) +#define NEXT_STEP_COMD_TIME_INTERVAL_COUNTER 10U +#define DEENERGIZED_EDGE_CHECK_COUNTER 250U + +// 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 ) ) + // ********** private data ********** /// Exec valve self test states @@ -88,26 +94,29 @@ } VALVE_STATE_T; #pragma pack(push, 1) -/// Valve status struct +/// Valve status structure typedef struct { VALVE_POSITION_T commandedPosition; VALVE_POSITION_T currentPosition; S16 currentPositionInCounts; + S16 nextPositionInCounts; BOOL hasTransitionBeenRequested; VALVE_STATE_T execState; U32 transitionStartTime; S16 positions[ NUM_OF_VALVE_POSITIONS ]; F32 valveCurrent; U32 valveOverCurrentCounter; U32 valvePositionOutOfRangeCounter; - U32 valvesDataPublishCounter; + U32 valveDataPublishCounter; + U32 valveNextStepCmdCounter; // Homing variables S16 previousPositionInCounts; U32 numberOfFailedHomings; U32 homingEdgeDetectionCounter; BOOL hasHomingBeenRequested; BOOL hasValveBeenHomed; + U32 deenergizedEdgeCheckKickoffCounter; } VALVE_STATUS_T; #pragma pack(pop) @@ -118,6 +127,8 @@ static OVERRIDE_U32_T valvesDataPublishInterval = { VALVES_DATA_PUB_INTERVAL, VALVES_DATA_PUB_INTERVAL, 0, 0 }; +static OVERRIDE_U32_T valvesPositionOverride[ NUM_OF_VALVES ] = { VALVE_POSITION_C_CLOSE, VALVE_POSITION_C_CLOSE, 0, 0 }; + // Self test function prototypes static VALVE_SELF_TEST_STATE_T handleValveSelfTestEnableValves( void ); static VALVE_SELF_TEST_STATE_T handleValveSelfTestConfirmEnable( void ); @@ -197,6 +208,7 @@ if ( position != VALVE_POSITION_NOT_IN_POSITION ) { valvesStatus[ valve ].commandedPosition = position; + valvesStatus[ valve ].hasTransitionBeenRequested = TRUE; result = TRUE; } @@ -349,10 +361,11 @@ valvesSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; // Enable the PID controller of all of the valves - enableFPGAValvesPIDControl( VDI_ENABLE_PID_INTERFACE ); + enableFPGAValvesPIDControl( ALL_VALVES_ENABLE_PID_INTERFACE ); + /*(enableFPGAValvesPIDControl( VDI_ENABLE_PID_INTERFACE ); enableFPGAValvesPIDControl( VDO_ENABLE_PID_INTERFACE ); enableFPGAValvesPIDControl( VBA_ENABLE_PID_INTERFACE ); - enableFPGAValvesPIDControl( VBV_ENABLE_PID_INTERFACE ); + enableFPGAValvesPIDControl( VBV_ENABLE_PID_INTERFACE );*/ return state; } @@ -426,7 +439,8 @@ VALVE_POSITION_T commandedPositionEnum = valvesStatus[ valve ].commandedPosition; S16 nextStep = valvesStatus[ valve ].positions[commandedPositionEnum ]; // Just set the valves to transition so it will not be in a known position for a while - valvesStatus[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; + valvesStatus[ valve ].transitionStartTime = getMSTimerCount(); + //valvesStatus[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; setFPGAValue( valve, nextStep ); state = VALVE_STATE_IN_TRANSITION; @@ -469,13 +483,13 @@ 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 ( didTimeout( valvesStatus[ valve ].transitionStartTime, VALVE_TRANSITION_TIMEOUT_MS ) ) { // TODO raise an alarm valvesStatus[ valve ].hasTransitionBeenRequested = FALSE; // Go back to Idle state state = VALVE_STATE_IDLE; - } + }*/ // If everything is good, decide what is the next step else { @@ -502,7 +516,7 @@ // If the valve is currently in position C, subtract the defined number of steps for the next transition else if ( currentPositionEnum == VALVE_POSITION_C_CLOSE ) { - nextStep = valvesStatus[ valve ].currentPositionInCounts - STEP_CHANGE_IN_COUNTS; + nextStep = valvesStatus[ valve ].currentPositionInCounts + STEP_CHANGE_IN_COUNTS; } setFPGAValue( valve, nextStep ); @@ -532,11 +546,16 @@ && isDoorClosed ) { // Get ready for the energized state - setFPGAValue( valve, STEP_CHANGE_IN_COUNTS ); valvesStatus[ valve ].transitionStartTime = getMSTimerCount(); valvesStatus[ valve ].homingEdgeDetectionCounter = 0; valvesStatus[ valve ].numberOfFailedHomings = 0; + valvesStatus[ valve ].valveNextStepCmdCounter = 0; + valvesStatus[ valve ].nextPositionInCounts = STEP_CHANGE_IN_COUNTS; + valvesStatus[ valve ].previousPositionInCounts = 0; valvesStatus[ valve ].hasValveBeenHomed = FALSE; + valvesStatus[ valve ].deenergizedEdgeCheckKickoffCounter = 0; + valvesStatus[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; + setFPGAValue( valve, valvesStatus[ valve ].nextPositionInCounts ); state = VALVE_STATE_HOMING_FIND_ENERGIZED_EDGE; } @@ -556,31 +575,42 @@ { VALVE_STATE_T state = VALVE_STATE_HOMING_FIND_ENERGIZED_EDGE; - S16 currentPosition = 0; - S16 previousPosition = 0; - - // Read the energized position back - currentPosition = fabs( valvesStatus[ valve ].currentPositionInCounts ); - previousPosition = fabs( valvesStatus[ valve ].previousPositionInCounts ); - // Check if the valve is within accepted range of the target - if ( fabs( currentPosition - INITIAL_ENERGIZED_POSITION ) <= MAX_POS_DEVIATION_FROM_TARGET_COUNTS ) + if ( ++valvesStatus[ valve ].valveNextStepCmdCounter >= NEXT_STEP_COMD_TIME_INTERVAL_COUNTER ) { + // Read the energized position back + S16 currentPosition = valvesStatus[ valve ].currentPositionInCounts; + S16 previousPosition = valvesStatus[ valve ].previousPositionInCounts; + // Check if the valve is within the range from the energized edge and it has been there for the defined time - if( fabs( currentPosition - previousPosition ) <= MAX_POSITION_DEVIATION_FROM_EDGES_COUNTS && - ++valvesStatus[ valve ].homingEdgeDetectionCounter > HOMING_EDGE_DETECTION_TARGET_COUNTER ) + if( fabs( fabs( currentPosition ) - fabs( previousPosition ) ) <= MAX_POSITION_DEVIATION_FROM_EDGES_IN_COUNTS && + ++valvesStatus[ valve ].homingEdgeDetectionCounter >= HOMING_EDGE_DETECTION_TARGET_COUNTER ) { // Current position (positive or negative) will be stored in the Position B of the current valve // Do not use the above variables because they absolute valves using fabs - valvesStatus[ valve ].positions[ VALVE_POSITION_B_OPEN ] = valvesStatus[ valve ].currentPositionInCounts; + valvesStatus[ valve ].positions[ VALVE_POSITION_B_OPEN ] = currentPosition; // Reset the current time and transition to the next state valvesStatus[ valve ].transitionStartTime = getMSTimerCount(); valvesStatus[ valve ].homingEdgeDetectionCounter = 0; + valvesStatus[ valve ].valveNextStepCmdCounter = 0; state = VALVE_STATE_HOMING_FIND_DEENERGIZED_EDGE; } + else + { + // Everything is normal and the valve is in transition + // Reset the number of failed homing attempts in case there was lingering failures from before + //valvesStatus[ valve ].homingEdgeDetectionCounter = 0; //TODO we should not do this + + valvesStatus[ valve ].nextPositionInCounts = valvesStatus[ valve ].nextPositionInCounts + STEP_CHANGE_IN_COUNTS; + + setFPGAValue( valve, valvesStatus[ valve ].nextPositionInCounts ); + } + + valvesStatus[ valve ].valveNextStepCmdCounter = 0; + valvesStatus[ valve ].previousPositionInCounts = currentPosition; } // Check if the transition has timed out - else if ( didTimeout( valvesStatus[ valve ].transitionStartTime, VALVE_TRANSITION_TIMEOUT_MS ) ) + /*else if ( didTimeout( valvesStatus[ valve ].transitionStartTime, VALVE_TRANSITION_TIMEOUT_MS ) ) { // If the valve has exceeded the max number of failed homings, raise an alarm if ( ++valvesStatus[ valve ].numberOfFailedHomings >= MAX_ALLOWED_FAILED_HOMINGS ) @@ -589,15 +619,7 @@ } state = VALVE_STATE_HOMING_NOT_STARTED; - } - else - { - // Everything is normal and the valve is in transition - // Reset the number of failed homing attempts in case there was lingering failures from before - //valvesStatus[ valve ].homingEdgeDetectionCounter = 0; //TODO we should not do this - S16 nextStep = valvesStatus[ valve ].currentPositionInCounts + STEP_CHANGE_IN_COUNTS; - setFPGAValue( valve, nextStep ); - } + }*/ valvesStatus[ valve ].execState = state; } @@ -615,35 +637,29 @@ { VALVE_STATE_T state = VALVE_STATE_HOMING_FIND_DEENERGIZED_EDGE; - S16 currentPosition = 0; - S16 previousPosition = 0; - // Read the energized position back - currentPosition = fabs( valvesStatus[ valve ].currentPositionInCounts ); - previousPosition = fabs( valvesStatus[ valve ].previousPositionInCounts ); + S16 currentPosition = valvesStatus[ valve ].currentPositionInCounts; + S16 previousPosition = valvesStatus[ valve ].previousPositionInCounts; - // TODO test this statement - if ( fabs( currentPosition - previousPosition ) <= MAX_POSITION_DEVIATION_FROM_EDGES_COUNTS ) + // Check if the valve is within accepted range of the target + if ( ++valvesStatus[ valve ].deenergizedEdgeCheckKickoffCounter >= DEENERGIZED_EDGE_CHECK_COUNTER ) { - if( fabs( currentPosition - INITIAL_DEENERGIZED_POSITION ) <= MAX_POS_DEVIATION_FROM_TARGET_COUNTS && - ++valvesStatus[ valve ].homingEdgeDetectionCounter > HOMING_EDGE_DETECTION_TARGET_COUNTER ) + // Check if the valve is within the range from the energized edge and it has been there for the defined time + if( fabs( fabs( currentPosition ) - fabs( previousPosition ) ) <= MAX_POSITION_DEVIATION_FROM_EDGES_IN_COUNTS && + ++valvesStatus[ valve ].homingEdgeDetectionCounter >= HOMING_EDGE_DETECTION_TARGET_COUNTER ) { S16 positionB = valvesStatus[ valve ].positions[ VALVE_POSITION_B_OPEN ]; // Position A is the average of the Position B that was read last time and position C that was // the target of this state - S16 positionA = ( valvesStatus[ valve ].currentPositionInCounts + positionB ) / 2; + S16 positionA = ( currentPosition + positionB ) / 2; valvesStatus[ valve ].positions[ VALVE_POSITION_A_INSERT_EJECT ] = positionA; // 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 ] = valvesStatus[ valve ].currentPositionInCounts - - INITIAL_EDGE_OFFSET_READ_COUNT; + valvesStatus[ valve ].positions[ VALVE_POSITION_C_CLOSE ] = currentPosition - INITIAL_EDGE_OFFSET_READ_COUNT; - // Reset the current time and transition to the next state - valvesStatus[ valve ].transitionStartTime = getMSTimerCount(); - // Homing successfully finished valvesStatus[ valve ].hasValveBeenHomed = TRUE; @@ -652,26 +668,36 @@ valvesStatus[ valve ].currentPosition = VALVE_POSITION_C_CLOSE; valvesStatus[ valve ].commandedPosition = VALVE_POSITION_A_INSERT_EJECT; valvesStatus[ valve ].hasTransitionBeenRequested = TRUE; + valvesStatus[ valve ].hasHomingBeenRequested = FALSE; // Idle will initiate a transition state = VALVE_STATE_IDLE; } + + valvesStatus[ valve ].previousPositionInCounts = currentPosition; } - else if ( didTimeout( valvesStatus[ valve ].transitionStartTime, VALVE_TRANSITION_TIMEOUT_MS ) ) + + if ( ++valvesStatus[ valve ].valveNextStepCmdCounter >= NEXT_STEP_COMD_TIME_INTERVAL_COUNTER ) { + valvesStatus[ valve ].nextPositionInCounts = valvesStatus[ valve ].nextPositionInCounts - STEP_CHANGE_IN_COUNTS; + + setFPGAValue( valve, valvesStatus[ valve ].nextPositionInCounts ); + + valvesStatus[ valve ].valveNextStepCmdCounter = 0; + valvesStatus[ valve ].previousPositionInCounts = currentPosition; + } + + // Check if the transition has timed out + /*else if ( didTimeout( valvesStatus[ valve ].transitionStartTime, VALVE_TRANSITION_TIMEOUT_MS ) ) + { + // If the valve has exceeded the max number of failed homings, raise an alarm if ( ++valvesStatus[ valve ].numberOfFailedHomings >= MAX_ALLOWED_FAILED_HOMINGS ) { //TODO fault alarm } state = VALVE_STATE_HOMING_NOT_STARTED; - } - else - { - //valvesStatus[ valve ].homingEdgeDetectionCounter = 0; //TODO do we need this? - S16 nextStep = valvesStatus[ valve ].currentPositionInCounts - STEP_CHANGE_IN_COUNTS; - setFPGAValue( valve, nextStep ); - } + }*/ valvesStatus[ valve ].execState = state; } @@ -826,30 +852,18 @@ { U08 i; U16 currentInADC = 0; - F32 ADC2Voltage = 0; - F32 voltage2Current = 0; - // Get the current from FPGA in ADC and use the macros to convert - // the ADC count into voltage, and convert voltage to current currentInADC = getFPGAValveDialyzerInletCurrentCounts(); - ADC2Voltage = ADC_TO_VOLTAGE_CONVERSION( currentInADC ); - voltage2Current = ADC_TO_VOLTAGE_CONVERSION( ADC2Voltage ); - valvesStatus[ VDI ].valveCurrent = voltage2Current; + valvesStatus[ VDI ].valveCurrent = ( (F32)currentInADC / ADC_TO_CURRENT_CONVERSION_CONSTANT ) - 1; currentInADC = getFPGAValveDialyzerOutletCurrentCounts(); - ADC2Voltage = ADC_TO_VOLTAGE_CONVERSION( currentInADC ); - voltage2Current = ADC_TO_VOLTAGE_CONVERSION( ADC2Voltage ); - valvesStatus[ VDO ].valveCurrent = voltage2Current; + valvesStatus[ VDO ].valveCurrent = ( (F32)currentInADC / ADC_TO_CURRENT_CONVERSION_CONSTANT ) - 1; currentInADC = getFPGAValveBloodVenousCurrentCounts(); - ADC2Voltage = ADC_TO_VOLTAGE_CONVERSION( currentInADC ); - voltage2Current = ADC_TO_VOLTAGE_CONVERSION( ADC2Voltage ); - valvesStatus[ VBA ].valveCurrent = voltage2Current; + valvesStatus[ VBA ].valveCurrent = ( (F32)currentInADC / ADC_TO_CURRENT_CONVERSION_CONSTANT ) - 1; currentInADC = getFPGAValveBloodArterialCurrentCounts(); - ADC2Voltage = ADC_TO_VOLTAGE_CONVERSION( currentInADC ); - voltage2Current = ADC_TO_VOLTAGE_CONVERSION( ADC2Voltage ); - valvesStatus[ VBV ].valveCurrent = voltage2Current; + valvesStatus[ VBV ].valveCurrent = ( (F32)currentInADC / ADC_TO_CURRENT_CONVERSION_CONSTANT ) - 1; // The current of all the valves for ( i = 0; i < NUM_OF_VALVES; i++) @@ -956,15 +970,19 @@ static void publishValvesData( VALVE_T valve ) { // Check the counter - if ( ++valvesStatus[ valve ].valvesDataPublishCounter > getPublishValvesDataInterval() ) + if ( ++valvesStatus[ valve ].valveDataPublishCounter > getPublishValvesDataInterval() ) { - U32 currentPos = (U32)valvesStatus[ valve ].currentPosition; - S16 currentPosCount = valvesStatus[ valve ].currentPositionInCounts; - F32 current = valvesStatus[ valve ].valveCurrent; + valveData.valveID = (U32)valve; + valveData.state = (U32)valvesStatus[ valve ].execState; + valveData.currentPosID = (U32)valvesStatus[ valve ].currentPosition; + valveData.currentPos = valvesStatus[ valve ].currentPositionInCounts; + valveData.prevPos = valvesStatus[ valve ].previousPositionInCounts; + valveData.nextPos = valvesStatus[ valve ].nextPositionInCounts; + valveData.current = valvesStatus[ valve ].valveCurrent; - broadcastHDValves( (U32)valve, currentPos, currentPosCount, current ); + broadcastHDValves(); - valvesStatus[ valve ].valvesDataPublishCounter = 0; + valvesStatus[ valve ].valveDataPublishCounter = 0; } } @@ -1023,6 +1041,62 @@ return result; } +/*********************************************************************//** + * @brief + * The testSetValvesPositionOverride function overrides the valves \n + * position. + * @details + * Inputs: valvesPositionOverride, valvesStatus + * Outputs: valvesPositionOverride, valvesStatus + * @param valve The valve ID + * @param position The position the valve has to transition to + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetValvesPositionOverride( U32 valve, U32 position ) +{ + BOOL result = FALSE; + if ( 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; + result = setValvePosition( (VALVE_T)valve, (VALVE_POSITION_T)position ); + } + } + return result; +} + +/*********************************************************************//** + * @brief + * The testResetValvesDataPublishInterval function resets the override \n + * of the valves publish interval. + * @details + * Inputs: valvesDataPublishInterval + * Outputs: valvesDataPublishInterval + * @param valve The valve ID + * @return TRUE if override reset successful, FALSE if not + *************************************************************************/ +BOOL testResetValvesPositionOverride( U32 valve ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + valvesPositionOverride[ valve ].override = OVERRIDE_RESET; + valvesPositionOverride[ valve ].ovData = valvesPositionOverride[ valve ].ovInitData; + + result = setValvePosition( (VALVE_T)valve, (VALVE_POSITION_T)valvesPositionOverride[ valve ].ovInitData ); + } + + return result; +} + + + + Index: firmware/App/Controllers/Valves.h =================================================================== diff -u -ra6fec5578295ef0bb7223376facb7d0cbd2c1209 -r9d40104500ae1c144a19b36b83a0515d32fb7fc9 --- firmware/App/Controllers/Valves.h (.../Valves.h) (revision a6fec5578295ef0bb7223376facb7d0cbd2c1209) +++ firmware/App/Controllers/Valves.h (.../Valves.h) (revision 9d40104500ae1c144a19b36b83a0515d32fb7fc9) @@ -36,6 +36,23 @@ NUM_OF_VALVES ///< Number of valves } VALVE_T; +#pragma pack(push, 1) +/// HD valves broadcast data +typedef struct +{ + U32 valveID; ///< Valve ID + U32 state; ///< Current state of the state machine + U32 currentPosID; ///< Current position in enum + S16 currentPos; ///< Current position in counts + S16 nextPos; ///< Next position in counts + F32 current; ///< Current of the valves + S16 prevPos; ///< Previous position in counts + +} HD_VALVE_DATA_T; +#pragma pack(pop) + +HD_VALVE_DATA_T valveData; ///< Valves data struct + // ********** public function prototypes ********* void initValves( void ); @@ -56,6 +73,10 @@ BOOL testResetValvesDataPublishInterval( void ); +BOOL testSetValvesPositionOverride( U32 valve, U32 position ); + +BOOL testResetValvesPositionOverride( U32 valve ); + /**@}*/ #endif Index: firmware/App/Services/FPGA.c =================================================================== diff -u -r28dd261825b2c742df73042ac2902db0c8f6f2b7 -r9d40104500ae1c144a19b36b83a0515d32fb7fc9 --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision 28dd261825b2c742df73042ac2902db0c8f6f2b7) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision 9d40104500ae1c144a19b36b83a0515d32fb7fc9) @@ -163,7 +163,24 @@ U16 VBVPWMTarget; ///< Reg 372. PWM target duty cycle for VBV pinch valve. U16 VDiPWMTarget; ///< Reg 374. PWM target duty cycle for VDi pinch valve. U16 VDoPWMTarget; ///< Reg 376. PWM target duty cycle for VDo pinch valve. - U16 VSparePWMTarget; ///< Reg 378. PWM target duty cycle for Vspare pinch valve. + U16 VSparePWMTarget; ///< Reg 378. PWM target duty cycle for Vspare pinch valve. + U16 SyringePumpStatus; ///< Reg 380. Syringe pump status register + U16 SyringePumpEncStatus; ///< Reg 382. Syringe pump encoder status + U32 SyringePumpEncPosition; ///< Reg 384. Syringe pump encoder position + U16 sPumpAdcDataReadChannel0; ///< Reg 388. + U16 sPumpAdcDataReadCh1; ///< Reg 390. + U16 sPumpAdcDataReadCh2; ///< Reg 392. + U16 sPumpAdcDataReadCh3; ///< Reg 394. + U16 VBASpeed; ///< Reg 396. VBA pinch valve speed (Register VAUX0) + U16 VBVSpeed; ///< Reg 398. VBV pinch valve speed (Register VAUX1) + U16 VBVCurrent; ///< Reg 400. VBV pinch valve current (Register VAUX2) + U16 VDoCurrent; ///< Reg 402. VDo pinch valve current (Register VAUX3) + U16 VBACurrent; ///< Reg 404. VBA pinch valve current (Register VAUX8) + U16 VDiSpeed; ///< Reg 406. VDi pinch valve current (Register VAUX9) + U16 VDoSpeed; ///< Reg 408. VDo pinch valve speed (Register VAUX10) + U16 VDiCurrent; ///< Reg 410. VDi pinch valve current (Register VAUX11) + U16 VSpareSpeed; ///< Reg 412. VSpare speed (Register VAUX5) + U16 VSpareCurrent; ///< Reg 414. VSpare current (Register VAUX13) } FPGA_SENSORS_T; /// Record structure for FPGA continuous priority writes. @@ -182,7 +199,8 @@ U16 VSparePWMFixed; ///< Reg 32. Vspare PWM set to fixed current by setting fixed PWM duty cycle. Range 750 to 4250. < 2500 is reverse direction. U08 AlarmControl; ///< Reg 34. Alarm (audio) control register. } FPGA_ACTUATORS_T; - + +// TODO clean up the struct /// Record structure for FPGA async (as needed) reads. typedef struct // TODO - add all sensor readings to this structure per FPGA register map { @@ -1324,8 +1342,8 @@ *************************************************************************/ void enableFPGAValvesPIDControl( U16 bits ) { - fpgaActuatorSetPoints.fpgaPIDControl = - fpgaActuatorSetPoints.fpgaPIDControl | bits; + fpgaActuatorSetPoints.fpgaPIDControl = bits; + //fpgaActuatorSetPoints.fpgaPIDControl | bits; } /*********************************************************************//** @@ -1392,12 +1410,12 @@ * of VDi in counts * @details * Inputs : none - * Outputs : FILL UP + * Outputs : fpgaSensorReadings * @return The current of VDi *************************************************************************/ U16 getFPGAValveDialyzerInletCurrentCounts( void ) { - return 0; + return fpgaSensorReadings.VDiCurrent; } /*********************************************************************//** @@ -1435,12 +1453,12 @@ * of VDo in counts * @details * Inputs : none - * Outputs : FILL UP + * Outputs : fpgaSensorReadings * @return The current of VDo *************************************************************************/ U16 getFPGAValveDialyzerOutletCurrentCounts( void ) { - return 0; + return fpgaSensorReadings.VDoCurrent; } /*********************************************************************//** @@ -1478,12 +1496,12 @@ * of VBV in counts * @details * Inputs : none - * Outputs : FILL UP + * Outputs : fpgaSensorReadings * @return The current of VBV *************************************************************************/ U16 getFPGAValveBloodVenousCurrentCounts( void ) { - return 0; + return fpgaSensorReadings.VBVCurrent; } /*********************************************************************//** @@ -1521,12 +1539,12 @@ * of VBA in counts * @details * Inputs : none - * Outputs : FILL UP + * Outputs : fpgaSensorReadings * @return The current of VBA *************************************************************************/ U16 getFPGAValveBloodArterialCurrentCounts( void ) { - return 0; + return fpgaSensorReadings.VBACurrent; } /*********************************************************************//** Index: firmware/App/Services/FPGA.h =================================================================== diff -u -r28dd261825b2c742df73042ac2902db0c8f6f2b7 -r9d40104500ae1c144a19b36b83a0515d32fb7fc9 --- firmware/App/Services/FPGA.h (.../FPGA.h) (revision 28dd261825b2c742df73042ac2902db0c8f6f2b7) +++ firmware/App/Services/FPGA.h (.../FPGA.h) (revision 9d40104500ae1c144a19b36b83a0515d32fb7fc9) @@ -68,7 +68,7 @@ void getFPGAAccelMaxes( S16 *xm, S16*ym, S16*zm ); void getFPGAAccelStatus( U16 *cnt, U16 *accelFPGAFaultReg ); -void enableValvesPIDControl( U16 bits ); +void enableFPGAValvesPIDControl( U16 bits ); void enableFPGAValvesBypassControl( U16 bits ); U16 getFPGAValvesStatus( void ); Index: firmware/App/Services/MessagePayloads.h =================================================================== diff -u -ra6fec5578295ef0bb7223376facb7d0cbd2c1209 -r9d40104500ae1c144a19b36b83a0515d32fb7fc9 --- firmware/App/Services/MessagePayloads.h (.../MessagePayloads.h) (revision a6fec5578295ef0bb7223376facb7d0cbd2c1209) +++ firmware/App/Services/MessagePayloads.h (.../MessagePayloads.h) (revision 9d40104500ae1c144a19b36b83a0515d32fb7fc9) @@ -173,14 +173,6 @@ U32 ctrlMode; } OVERRIDE_PUMP_SET_PT_PAYLOAD_T; -typedef struct -{ - U32 valveID; - U32 currentPosID; - S16 currentPos; - F32 current; -} HD_VALVES_T; - #pragma pack(pop) #endif Index: firmware/App/Services/SystemComm.c =================================================================== diff -u -rc84daa1f07003427fc5cdde8f5651434478f7313 -r9d40104500ae1c144a19b36b83a0515d32fb7fc9 --- firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision c84daa1f07003427fc5cdde8f5651434478f7313) +++ firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 9d40104500ae1c144a19b36b83a0515d32fb7fc9) @@ -1390,6 +1390,10 @@ handleTestDialOutFlowSetPointOverrideRequest( message ); break; + case MSG_ID_HD_VALVES_HOME: + handleHomeHDValve( message ); + break; + default: // TODO - unrecognized message ID received - ignore break; Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -ra6fec5578295ef0bb7223376facb7d0cbd2c1209 -r9d40104500ae1c144a19b36b83a0515d32fb7fc9 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision a6fec5578295ef0bb7223376facb7d0cbd2c1209) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 9d40104500ae1c144a19b36b83a0515d32fb7fc9) @@ -1133,24 +1133,26 @@ * @param current : Current of the valve * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ -BOOL broadcastHDValves( U32 valve, U32 currentPosEnum, S16 currentPosCount, F32 current ) +BOOL broadcastHDValves() { BOOL result; MESSAGE_T msg; U08 *payloadPtr = msg.payload; - HD_VALVES_T payload; + //HD_VALVE_DATA_T payload; // create a message record blankMessage( &msg ); msg.hdr.msgID = MSG_ID_HD_VALVES_DATA; - msg.hdr.payloadLen = sizeof( HD_VALVES_T ); + msg.hdr.payloadLen = sizeof( HD_VALVE_DATA_T ); - payload.valveID = valve; + /*payload.valveID = valve; + payload.state = state; payload.currentPosID = currentPosEnum; payload.currentPos = currentPosCount; - payload.current = current; + payload.nextPos = nextPosCount; + payload.current = current;*/ - memcpy( payloadPtr, &payload, sizeof( HD_VALVES_T ) ); + memcpy( payloadPtr, &valveData, sizeof( HD_VALVE_DATA_T ) ); // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_BROADCAST, ACK_NOT_REQUIRED ); @@ -2400,6 +2402,31 @@ sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); } +/************************************************************************* + * @brief + * The handleHomeHDValve function handles a request to home an HD valve + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleHomeHDValve( MESSAGE_T *message ) +{ + BOOL result; + + if ( message->hdr.payloadLen == sizeof(U32) ) + { + VALVE_T payload; + + memcpy( &payload, message->payload, sizeof(U32) ); + result = homeValve( payload ); + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + /*********************************************************************//** * @brief * The handleTestHDValvesBroadcastIntervalOverrideRequest function handles \n @@ -2411,3 +2438,21 @@ * @return none *************************************************************************/ DATA_OVERRIDE_HANDLER_FUNC_U32( U32, handleTestHDValvesBroadcastIntervalOverrideRequest, testSetValvesDataPublishInterval, testResetValvesDataPublishInterval ) + + +void handleSetHDValvesPosition( MESSAGE_T *message ) +{ + BOOL result; + + if ( message->hdr.payloadLen == sizeof(LINEAR_F32_CAL_PAYLOAD_T) ) + { + LINEAR_F32_CAL_PAYLOAD_T payload; + + memcpy( &payload, message->payload, sizeof(LINEAR_F32_CAL_PAYLOAD_T) ); + result = setDialInFlowCalibration( payload.gain, payload.offset ); + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); + +} Index: firmware/App/Services/SystemCommMessages.h =================================================================== diff -u -ra6fec5578295ef0bb7223376facb7d0cbd2c1209 -r9d40104500ae1c144a19b36b83a0515d32fb7fc9 --- firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision a6fec5578295ef0bb7223376facb7d0cbd2c1209) +++ firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 9d40104500ae1c144a19b36b83a0515d32fb7fc9) @@ -161,7 +161,7 @@ BOOL broadcastHDOperationMode( U32 mode, U32 subMode ); //MSG_ID_HD_VALVES_DATA -BOOL broadcastHDValves( U32 valve, U32 currentPosEnum, S16 currentPosCount, F32 current ); +BOOL broadcastHDValves(); #ifdef EMC_TEST_BUILD // MSG_ID_CAN_ERROR_COUNT @@ -314,8 +314,14 @@ // MSG_ID_HD_DIALYSATE_FLOW_SET_CALIBRATION: void handleSetDialysateFlowCalibration( MESSAGE_T *message ); -//MSG_ID_HD_VALVES_SEND_INTERVAL_OVERRIDE +// MSG_ID_HD_VALVES_SEND_INTERVAL_OVERRIDE void handleTestHDValvesBroadcastIntervalOverrideRequest( MESSAGE_T *message ); + +// MSG_ID_HD_HOME_VALVE +void handleHomeHDValve( MESSAGE_T *message ); + +// MSG_ID_HD_VALVES_POSITION_OVERRIDE +void handleSetHDValvesPosition( MESSAGE_T *message ); #endif