Index: firmware/App/Controllers/LoadCell.c =================================================================== diff -u -rdd3356035996866e5db7678d352f933fc22ad789 -r16dfbeeca1bcf1d2115c2f7549999fdaae0700e9 --- firmware/App/Controllers/LoadCell.c (.../LoadCell.c) (revision dd3356035996866e5db7678d352f933fc22ad789) +++ firmware/App/Controllers/LoadCell.c (.../LoadCell.c) (revision 16dfbeeca1bcf1d2115c2f7549999fdaae0700e9) @@ -76,10 +76,10 @@ void execLoadCell(void) { // get latest raw load cell readings - measuredLoadCellReadingsRaw[ LOAD_CELL_A1 ].data = getFPGALoadCellA1() & 0x7FFFFFFF; // Temporary neg sign removal fix while FPGA code is being fixed - measuredLoadCellReadingsRaw[ LOAD_CELL_A2 ].data = getFPGALoadCellA2() & 0x7FFFFFFF; - measuredLoadCellReadingsRaw[ LOAD_CELL_B1 ].data = getFPGALoadCellB1() & 0x7FFFFFFF; - measuredLoadCellReadingsRaw[ LOAD_CELL_B2 ].data = getFPGALoadCellB2() & 0x7FFFFFFF; + measuredLoadCellReadingsRaw[ LOAD_CELL_A1 ].data = getFPGALoadCellA1(); + measuredLoadCellReadingsRaw[ LOAD_CELL_A2 ].data = getFPGALoadCellA2(); + measuredLoadCellReadingsRaw[ LOAD_CELL_B1 ].data = getFPGALoadCellB1(); + measuredLoadCellReadingsRaw[ LOAD_CELL_B2 ].data = getFPGALoadCellB2(); // update sums for load cell average calculations measuredLoadCellReadingsSum[ LOAD_CELL_A1 ] += getMeasuredRawLoadCellReading( LOAD_CELL_A1 ); measuredLoadCellReadingsSum[ LOAD_CELL_A2 ] += getMeasuredRawLoadCellReading( LOAD_CELL_A2 ); Index: firmware/App/Controllers/Pressures.c =================================================================== diff -u -r68fc03b5a22f14190146fc9069f022c109682b63 -r16dfbeeca1bcf1d2115c2f7549999fdaae0700e9 --- firmware/App/Controllers/Pressures.c (.../Pressures.c) (revision 68fc03b5a22f14190146fc9069f022c109682b63) +++ firmware/App/Controllers/Pressures.c (.../Pressures.c) (revision 16dfbeeca1bcf1d2115c2f7549999fdaae0700e9) @@ -17,6 +17,7 @@ #include "Pressures.h" #include "AlarmMgmt.h" #include "FPGA.h" +#include "InternalADC.h" #include "OperationModes.h" #include "SystemCommMessages.h" #include "TaskPriority.h" @@ -30,8 +31,11 @@ // ********** private definitions ********** /// Default publication interval for pressure and occlusion data. -#define PRESSURES_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< interval (ms/task time) at which the pressures data is published on the CAN bus. +#define PRESSURES_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< interval (ms/task time) at which the pressures data is published on the CAN bus. +#define PUMP_PRESSURE_ZERO 0x309 ///< ADC counts equivalent to 0 PSI for pump in/out pressure sensors. +#define PUMP_PRESSURE_PSI_PER_COUNT 0.06343 ///< PSI per ADC count conversion factor for pump in/out pressure sensors. + /// Defined states for the pressures monitor state machine. typedef enum PresOccl_States { @@ -60,6 +64,7 @@ static PRESSURE_SELF_TEST_STATE_T pressuresSelfTestState = PRESSURE_SELF_TEST_STATE_START; ///< current pressure self test state. static U32 pressuresSelfTestTimerCount = 0; ///< timer counter for pressure self test. + // ********** private function prototypes ********** static PRESSURE_STATE_T handlePressuresInitState( void ); @@ -143,16 +148,16 @@ { PRESSURE_STATE_T result = PRESSURE_CONTINUOUS_READ_STATE; - U16 roIn = getFPGAROPumpInletPressure(); - U16 roOut = getFPGAROPumpOutletPressure(); - U16 drainIn = getFPGADrainPumpInletPressure(); - U16 drainOut = getFPGADrainPumpOutletPressure(); + S32 roIn = (S32)getIntADCReading( INT_ADC_RO_PUMP_INLET_PRESSURE ); + S32 roOut = (S32)getIntADCReading( INT_ADC_RO_PUMP_OUTLET_PRESSURE ); + S32 drainIn = (S32)getIntADCReading( INT_ADC_DRAIN_PUMP_OUTLET_PRESSURE ); + S32 drainOut = (S32)getIntADCReading( INT_ADC_DRAIN_PUMP_INLET_PRESSURE ); - // TODO - convert ADC counts to mmHg for each sensor - pressures[ PRESSURE_SENSOR_RO_PUMP_INLET ].data = (F32)roIn; - pressures[ PRESSURE_SENSOR_RO_PUMP_OUTLET ].data = (F32)roOut; - pressures[ PRESSURE_SENSOR_DRAIN_PUMP_INLET ].data = (F32)drainIn; - pressures[ PRESSURE_SENSOR_DRAIN_PUMP_OUTLET ].data = (F32)drainOut; + // convert ADC counts to PSI for each sensor + pressures[ PRESSURE_SENSOR_RO_PUMP_INLET ].data = (F32)( roIn - PUMP_PRESSURE_ZERO ) * PUMP_PRESSURE_PSI_PER_COUNT; + pressures[ PRESSURE_SENSOR_RO_PUMP_OUTLET ].data = (F32)( roOut - PUMP_PRESSURE_ZERO ) * PUMP_PRESSURE_PSI_PER_COUNT; + pressures[ PRESSURE_SENSOR_DRAIN_PUMP_INLET ].data = (F32)( drainIn - PUMP_PRESSURE_ZERO ) * PUMP_PRESSURE_PSI_PER_COUNT; + pressures[ PRESSURE_SENSOR_DRAIN_PUMP_OUTLET ].data = (F32)( drainOut - PUMP_PRESSURE_ZERO ) * PUMP_PRESSURE_PSI_PER_COUNT; // TODO - any filtering required??? @@ -246,7 +251,7 @@ F32 drainIn = getMeasuredDGPressure( PRESSURE_SENSOR_DRAIN_PUMP_INLET ); F32 drainOut = getMeasuredDGPressure( PRESSURE_SENSOR_DRAIN_PUMP_OUTLET ); - broadcastPressuresData( roIn, roOut, drainIn, drainOut ); + broadcastPressureSensorsData( roIn, roOut, drainIn, drainOut ); pressuresDataPublicationTimerCounter = 0; } } Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -r68fc03b5a22f14190146fc9069f022c109682b63 -r16dfbeeca1bcf1d2115c2f7549999fdaae0700e9 --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 68fc03b5a22f14190146fc9069f022c109682b63) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 16dfbeeca1bcf1d2115c2f7549999fdaae0700e9) @@ -21,9 +21,10 @@ #include "etpwm.h" #include "FPGA.h" -#include "InternalADC.h" +//#include "InternalADC.h" #include "OperationModes.h" #include "PIControllers.h" +#include "Pressures.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" #include "TaskPriority.h" @@ -45,6 +46,8 @@ #define ROP_SPEED_ADC_TO_RPM_FACTOR 1.0 ///< conversion factor from ADC counts to RPM for RO pump #define ROP_PSI_TO_PWM_DC(p) ( 0.2 + ( (F32)((p) - 100) * 0.01 ) ) ///< conversion factor from target PSI to PWM duty cycle estimate TODO - this is a place holder for real conversion +#define RO_FLOW_ADC_TO_LPM_FACTOR 0.00018 ///< conversion factor from ADC counts to LPM (liters/min) for RO flow rate. + typedef enum ROPump_States { RO_PUMP_OFF_STATE = 0, @@ -72,8 +75,8 @@ static OVERRIDE_U32_T roPumpDataPublishInterval = { 0, 0, 0, 0 }; ///< interval (in ms) at which to publish RO flow data to CAN bus. static OVERRIDE_U32_T targetROPumpPressure = { 0, 0, 0, 0 }; ///< Target RO pressure (in PSI). -static OVERRIDE_F32_T measuredROPumpPressure = { 0.0, 0.0, 0.0, 0 }; ///< Tmeasured RO pressure (in PSI). -static OVERRIDE_F32_T roPumpSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< measured RO pump motor speed (in RPM). +static OVERRIDE_F32_T measuredROPumpPressure = { 0.0, 0.0, 0.0, 0 }; ///< measured RO pressure (in PSI). +static OVERRIDE_F32_T measuredROFlowRateLPM = { 0.0, 0.0, 0.0, 0 }; ///< measured RO flow rate (in LPM). static U32 roControlTimerCounter = 0; ///< determines when to perform control on ro flow @@ -165,25 +168,31 @@ * The execROPumpMonitor function executes the RO Pump monitor. * @details * Inputs : none - * Outputs : measuredROPumpPressure + * Outputs : measuredROPumpPressure, measuredROFlowRateLPM * @param none * @return none *************************************************************************/ void execROPumpMonitor( void ) { - U16 roRPM = getFPGAROPumpSpeed(); - F32 roPressure = getFPGAROOutPressure(); + S32 roFlow = (S32)getFPGAROPumpFlowRate(); + F32 roPressure = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_OUTLET ); - roPumpSpeedRPM.data = (F32)((S16)roRPM); + measuredROFlowRateLPM.data = (F32)(roFlow) * RO_FLOW_ADC_TO_LPM_FACTOR; measuredROPumpPressure.data = (F32)((S16)roPressure); - // check pressure -// if ( roPressure < MIN_RO_PRESSURE || roPressure > MAX_RO_PRESSURE ) -// { -// SET_ALARM_WITH_1_F32_DATA( ALARM_ID_RO_PUMP_OUT_PRESSURE_OUR_OF_RANGE, roPressure ) -// } + // check RO flow + // TODO - check flow - // publish RO flow data on interval + // check pressure while RO pump is on + if ( TRUE == isROPumpOn ) + { + if ( roPressure < MIN_RO_PRESSURE || roPressure > MAX_RO_PRESSURE ) + { + SET_ALARM_WITH_1_F32_DATA( ALARM_ID_RO_PUMP_OUT_PRESSURE_OUR_OF_RANGE, roPressure ) // TODO - add persistence + } + } + + // publish RO pump data on interval publishROPumpData(); } @@ -229,7 +238,7 @@ RO_PUMP_STATE_T result = RO_PUMP_OFF_STATE; // if we've been given a pressure, transition to control to target state - if ( getTargetROPressure() > 0 ) + if ( getTargetROPumpPressure() > 0 ) { // set initial PWM duty cycle roPumpPWMDutyCyclePctSet = roPumpPWMDutyCyclePct; @@ -263,11 +272,11 @@ { if ( roPumpControlModeSet == PUMP_CONTROL_MODE_CLOSED_LOOP ) { - F32 tgtFlow = (F32)getTargetROPressure(); - F32 actFlow = getMeasuredROPressure(); + F32 tgtPres = (F32)getTargetROPumpPressure(); + F32 actPres = getMeasuredROPumpPressure(); F32 newPWM; - newPWM = runPIController( PI_CONTROLLER_ID_RO_PUMP, tgtFlow, actFlow ); + newPWM = runPIController( PI_CONTROLLER_ID_RO_PUMP, tgtPres, actPres ); roPumpPWMDutyCyclePctSet = newPWM; setROPumpControlSignalPWM( newPWM ); } @@ -318,8 +327,18 @@ * @param none * @return the current RO pump data publication interval (in ms). *************************************************************************/ -DATA_GET( U32, getPublishROPumpDataInterval, roPumpDataPublishInterval ) +U32 getPublishROPumpDataInterval( void ) +{ + U32 result = roPumpDataPublishInterval.data; + if ( OVERRIDE_KEY == roPumpDataPublishInterval.override ) + { + result = roPumpDataPublishInterval.ovData; + } + + return result; +} + /************************************************************************* * @brief * The getTargetROPumpPressure function gets the current target RO pump \n @@ -330,8 +349,18 @@ * @param none * @return the current target RO pressure (in PSI). *************************************************************************/ -DATA_GET( S32, getTargetROPumpPressure, targetROPumpPressure ) +U32 getTargetROPumpPressure( void ) +{ + U32 result = targetROPumpPressure.data; + if ( OVERRIDE_KEY == targetROPumpPressure.override ) + { + result = targetROPumpPressure.ovData; + } + + return result; +} + /************************************************************************* * @brief * The getMeasuredROPumpPressure function gets the measured RO pump \n @@ -342,20 +371,40 @@ * @param none * @return the current RO pressure (in PSI). *************************************************************************/ -DATA_GET( F32, getMeasuredROPumpPressure, measuredROPumpPressure ) +F32 getMeasuredROPumpPressure( void ) +{ + F32 result = measuredROPumpPressure.data; + if ( OVERRIDE_KEY == measuredROPumpPressure.override ) + { + result = measuredROPumpPressure.ovData; + } + + return result; +} + /************************************************************************* * @brief - * The getMeasuredROPumpSpeed function gets the measured RO pump \n - * speed. + * The getMeasuredROFlowRate function gets the measured RO pump \n + * flow rate. * @details * Inputs : roPumpSpeedRPM * Outputs : none * @param none * @return the current RO pump speed (in RPM). *************************************************************************/ -DATA_GET( F32, getMeasuredROPumpSpeed, roPumpSpeedRPM ) +F32 getMeasuredROFlowRate( void ) +{ + F32 result = measuredROFlowRateLPM.data; + if ( OVERRIDE_KEY == measuredROFlowRateLPM.override ) + { + result = measuredROFlowRateLPM.ovData; + } + + return result; +} + /************************************************************************* * @brief * The publishROPumpData function publishes RO pump data at the set \n @@ -370,11 +419,10 @@ // publish RO pump data on interval if ( ++roPumpDataPublicationTimerCounter >= getPublishROPumpDataInterval() ) { - S32 presStPt = (S32)getTargetROPumpPressure(); - F32 measPres = getMeasuredROPumpPressure(); - F32 measSpd = getMeasuredROPumpSpeed(); + U32 presStPt = getTargetROPumpPressure(); + F32 measFlow = getMeasuredROFlowRate(); F32 pumpPWMPctDutyCycle = roPumpPWMDutyCyclePctSet * FRACTION_TO_PERCENT_FACTOR; - broadcastROPumpData( presStPt, measPres, measSpd, pumpPWMPctDutyCycle ); + broadcastROPumpData( presStPt, measFlow, pumpPWMPctDutyCycle ); roPumpDataPublicationTimerCounter = 0; } } @@ -504,95 +552,47 @@ /************************************************************************* * @brief - * The testResetMeasuredROPumpPressureOverride function overrides the measured \n - * ro pressure. + * The testSetMeasuredROFlowRateOverride function overrides the measured \n + * RO flow rate. * @details * Inputs : none - * Outputs : measuredROPumpPressure - * @param value : override measured RO pressure (in PSI) - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testSetMeasuredROPumpPressureOverride( F32 value ) -{ - BOOL result = FALSE; - - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - measuredROPumpPressure.ovData = value; - measuredROPumpPressure.override = OVERRIDE_KEY; - } - - return result; -} - -/************************************************************************* - * @brief - * The testResetOffButtonStateOverride function resets the override of the \n - * measured RO pressure. - * @details - * Inputs : none - * Outputs : measuredROPumpPressure - * @param none - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testResetMeasuredROPumpPressureOverride( void ) -{ - BOOL result = FALSE; - - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - measuredROPumpPressure.override = OVERRIDE_RESET; - measuredROPumpPressure.ovData = measuredROPumpPressure.ovInitData; - } - - return result; -} - -/************************************************************************* - * @brief - * The testSetMeasuredROPumpSpeedOverride function overrides the measured \n - * RO pump motor speed. - * @details - * Inputs : none - * Outputs : roPumpSpeedRPM + * Outputs : measuredROFlowRateLPM * @param value : override measured RO pump motor speed (in RPM) * @return TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testSetMeasuredROPumpSpeedOverride( F32 value ) +BOOL testSetMeasuredROFlowRateOverride( F32 value ) { BOOL result = FALSE; if ( TRUE == isTestingActivated() ) { result = TRUE; - roPumpSpeedRPM.ovData = value; - roPumpSpeedRPM.override = OVERRIDE_KEY; + measuredROFlowRateLPM.ovData = value; + measuredROFlowRateLPM.override = OVERRIDE_KEY; } return result; } /************************************************************************* * @brief - * The testResetMeasuredROPumpSpeedOverride function resets the override of the \n - * measured RO pump motor speed. + * The testResetMeasuredROFlowRateOverride function resets the override of the \n + * measured RO flow rate. * @details * Inputs : none - * Outputs : roPumpSpeedRPM + * Outputs : measuredROFlowRateLPM * @param none * @return TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testResetMeasuredROPumpSpeedOverride( void ) +BOOL testResetMeasuredROFlowRateOverride( void ) { BOOL result = FALSE; if ( TRUE == isTestingActivated() ) { result = TRUE; - roPumpSpeedRPM.override = OVERRIDE_RESET; - roPumpSpeedRPM.ovData = roPumpSpeedRPM.ovInitData; + measuredROFlowRateLPM.override = OVERRIDE_RESET; + measuredROFlowRateLPM.ovData = measuredROFlowRateLPM.ovInitData; } return result; Index: firmware/App/Controllers/ROPump.h =================================================================== diff -u -r138efd92a8645e0d2fe422409ef5a33dd2929a25 -r16dfbeeca1bcf1d2115c2f7549999fdaae0700e9 --- firmware/App/Controllers/ROPump.h (.../ROPump.h) (revision 138efd92a8645e0d2fe422409ef5a33dd2929a25) +++ firmware/App/Controllers/ROPump.h (.../ROPump.h) (revision 16dfbeeca1bcf1d2115c2f7549999fdaae0700e9) @@ -35,17 +35,15 @@ SELF_TEST_STATUS_T execROPumpTest( void ); -DATA_GET_PROTOTYPE( S32, getTargetROPressure ); -DATA_GET_PROTOTYPE( F32, getMeasuredROPressure); -DATA_GET_PROTOTYPE( F32, getMeasuredROPumpSpeed ); +DATA_GET_PROTOTYPE( U32, getTargetROPumpPressure ); +DATA_GET_PROTOTYPE( F32, getMeasuredROPumpPressure); +DATA_GET_PROTOTYPE( F32, getMeasuredROFlowRate ); BOOL testSetROPumpDataPublishIntervalOverride( U32 value ); BOOL testResetROPumpDataPublishIntervalOverride( void ); BOOL testSetTargetROPressureOverride( S32 value ); BOOL testResetTargetROPressureOverride( void ); -BOOL testSetMeasuredROPressureOverride( F32 value ); -BOOL testResetMeasuredROPressureOverride( void ); -BOOL testSetMeasuredROPumpSpeedOverride( F32 value ); -BOOL testResetMeasuredROPumpSpeedOverride( void ); +BOOL testSetMeasuredROFlowRateOverride( F32 value ); +BOOL testResetMeasuredROFlowRateOverride( void ); #endif Index: firmware/App/Services/FPGA.c =================================================================== diff -u -r4fa5628781e2b420cad6afc42a4b754dd484b997 -r16dfbeeca1bcf1d2115c2f7549999fdaae0700e9 --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision 4fa5628781e2b420cad6afc42a4b754dd484b997) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision 16dfbeeca1bcf1d2115c2f7549999fdaae0700e9) @@ -1,4 +1,4 @@ -/************************************************************************** +/**********************************************************************//** * * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. * @@ -68,45 +68,88 @@ #define MAX_COMM_ERROR_RETRIES 5 +#define MASK_OFF_U32_MSB 0x00FFFFFF +#define DRAIN_PUMP_DAC_SHIFT_BITS 4 + // FPGA Sensors Record #pragma pack(push,1) typedef struct { U08 fpgaId; U08 fpgaRev; - U16 fpgaADC1Control; - U08 fpagDiag; - U08 reserved1; - U16 fpagADC2Control; - U16 fpagRTDControl; } FPGA_HEADER_T; // read only on FPGA typedef struct // TODO - add all sensor readings to this structure per FPGA register map { - U08 fpgaId; - U08 fpgaRev; - U16 fpgaADC1Control; + U32 fpgaLCA1; + U32 fpgaLCA2; + U32 fpgaADC1Temp; + + U32 fpgaLCB1; + U32 fpgaLCB2; + U32 fpgaADC2Temp; + + U32 fpgaCD1; + U32 fpgaCD2; + U32 fpgaTPiTemp; + U32 fpgaTPoTemp; + U32 fpgaRTDTemp; + + U32 fpgaTHDo; + U32 fpgaTHDoTemp; + + U32 fpgaTDi; + U32 fpgaTDiTemp; + + U32 fpgaCPoEc; + U32 fpgaCPoTds; + U16 fpgaStatus; + + U16 fpgaPrimaryHeaterIntTemp; + U16 fpgaPrimaryHeaterIntJunctionTemp; + U16 fpgaTrimmerHeaterIntTemp; + U16 fpgaTrimmerHeaterIntJunctionTemp; + + U16 fpgaDrainPumpSpeed; + U16 fpgaROFlowRate; + U16 fpgaValveStates; + U08 fpgaIOErrorCntProcessor; U08 fpgaIOErrorCntPC; - U32 reserved1; - U32 reserved2; - U32 reserved3; - U32 reserved4; - U32 reserved5; - U32 reserved6; - U32 reserved7; - U32 reserved8; - U32 reserved9; - U32 LCA1; - U32 LCA2; - U32 LCB1; - U32 LCB2; + U08 fpgaADC1ReadCnt; + U08 fpgaADC1ErrorCnt; + U08 fpgaADC2ReadCnt; + U08 fpgaADC2ErrorCnt; + U08 fpgaRTDReadCnt; + U08 fpgaRTDErrorCnt; + U08 fpgaTHDoReadCnt; + U08 fpgaTHDoErrorCnt; + U08 fpgaTDiReadCnt; + U08 fpgaTDiErrorCnt; + U08 fpgaPrimaryHeaterFlags; + U08 fpgaPrimaryHeaterReadCnt; + U08 fpgaTrimmerHeaterFlags; + U08 fpgaTrimmerHeaterReadCnt; + U08 fpgaCPoTempConf; + U08 fpgaCPoSanityData; + U08 fpgaCPoReadCnt; + U08 fpgaCPoErrorCnt; } DG_FPGA_SENSORS_T; -typedef struct // TODO - add all actuator set points to this structure per FPGA register map +typedef struct { - U08 bloodValveSetState; + U16 fpgaCPoProbeType; + U16 fpgaDrainPumpSetSpeed; + U16 fpgaValveStates; + U08 fpgaID; + U08 fpgaRev; + U08 fpgaADC1Control; + U08 fpgaDiag; + U08 fpgaADC2Control; + U08 fpgaRTDControl; + U08 fpgaTHDoControl; + U08 fpgaTDiControl; } FPGA_ACTUATORS_T; #pragma pack(pop) @@ -138,7 +181,7 @@ // FPGA data static FPGA_HEADER_T fpgaHeader; -static DG_FPGA_SENSORS_T fpgaSensorReadings; +static DG_FPGA_SENSORS_T fpgaSensorReadings; static FPGA_ACTUATORS_T fpgaActuatorSetPoints; // ********** private function prototypes ********** @@ -160,8 +203,8 @@ static void consumeUnexpectedData( void ); -/************************************************************************* - * @brief initFPGA +/*********************************************************************//** + * @brief * The initFPGA function initializes the FPGA module. * @details * Inputs : none @@ -271,8 +314,8 @@ consumeUnexpectedData(); } -/************************************************************************* - * @brief resetFPGACommFlags +/*********************************************************************//** + * @brief * The resetFPGACommFlags function resets the various fpga comm flags and \n * counters. * @details @@ -292,8 +335,8 @@ fpgaReceiptCounter = 0; } -/************************************************************************* - * @brief signalFPGAReceiptCompleted +/*********************************************************************//** + * @brief * The signalFPGAReceiptCompleted function increments a counter to indicate \n * that another DMA receipt from the FPGA has completed. * @details @@ -328,8 +371,8 @@ } } -/************************************************************************* - * @brief signalFPGATransmitCompleted +/*********************************************************************//** + * @brief * The signalFPGATransmitCompleted function increments a counter to indicate \n * that another DMA transmit to the FPGA has completed. * @details @@ -343,8 +386,8 @@ fpgaTransmitCounter++; } -/************************************************************************* - * @brief execFPGAIn +/*********************************************************************//** + * @brief * The execFPGA function manages incoming data exchanges with the FPGA. * @details * Inputs : fpgaState @@ -397,8 +440,8 @@ resetFPGACommFlags(); } -/************************************************************************* - * @brief execFPGAOut +/*********************************************************************//** + * @brief * The execFPGAOut function manages outgoing data exchanges with the FPGA. * @details * Inputs : fpgaState @@ -438,8 +481,8 @@ } } -/************************************************************************* - * @brief handleFPGAReadHeaderState +/*********************************************************************//** + * @brief * The handleFPGAReadHeaderState function handles the FPGA state where \n * the read header registers command is sent to the FPGA. * @details @@ -455,7 +498,7 @@ // construct read command to read 3 registers starting at address 0 fpgaReadCmdBuffer[ 0 ] = FPGA_READ_CMD_CODE; - fpgaReadCmdBuffer[ 1 ] = 0x00; // start at FPGA address 0 + fpgaReadCmdBuffer[ 1 ] = 0x06; // start at FPGA address 6 fpgaReadCmdBuffer[ 2 ] = 0x00; fpgaReadCmdBuffer[ 3 ] = sizeof(FPGA_HEADER_T); crc = crc16( fpgaReadCmdBuffer, FPGA_READ_CMD_HDR_LEN ); @@ -471,8 +514,8 @@ return result; } -/************************************************************************* - * @brief handleFPGAReceiveHeaderState +/*********************************************************************//** + * @brief * The handleFPGAReceiveHeaderState function handles the FPGA state \n * where the header registers read response should be ready to take in. * @details @@ -524,8 +567,8 @@ return result; } -/************************************************************************* - * @brief handleFPGAWriteAllActuatorsState +/*********************************************************************//** + * @brief * The handleFPGAWriteAllActuatorsState function handles the FPGA state \n * where the bulk write command is sent to the FPGA. * @details @@ -541,7 +584,7 @@ // construct bulk write command to write actuator data registers starting at address 3 (TODO - change address later) fpgaWriteCmdBuffer[ 0 ] = FPGA_WRITE_CMD_CODE; - fpgaWriteCmdBuffer[ 1 ] = 0x08; // start at FPGA address 8 + fpgaWriteCmdBuffer[ 1 ] = 0x00; // start at FPGA address 0 fpgaWriteCmdBuffer[ 2 ] = 0x00; fpgaWriteCmdBuffer[ 3 ] = sizeof(FPGA_ACTUATORS_T); memcpy( &( fpgaWriteCmdBuffer[ FPGA_WRITE_CMD_HDR_LEN ] ), &fpgaActuatorSetPoints, sizeof( FPGA_ACTUATORS_T ) ); @@ -572,8 +615,8 @@ return result; } -/************************************************************************* - * @brief handleFPGAReceiveAllSensorsState +/*********************************************************************//** + * @brief * The handleFPGAReceiveAllSensorsState function handles the FPGA state \n * where the bulk read response should be ready to parse. * @details @@ -631,8 +674,8 @@ return result; } -/************************************************************************* - * @brief execFPGATest +/*********************************************************************//** + * @brief * The execFPGATest function executes the FPGA self-test. \n * @details * Inputs : fpgaHeader @@ -662,8 +705,8 @@ return result; } -/************************************************************************* - * @brief setupDMAForWriteCmd +/*********************************************************************//** + * @brief * The setupDMAForWriteCmd function sets the byte count for the next DMA \n * write command to the FPGA. * @details @@ -685,8 +728,8 @@ } } -/************************************************************************* - * @brief startDMAWriteCmd +/*********************************************************************//** + * @brief * The startDMAWriteCmd function initiates the DMA transmit for the next \n * DMA write command to the FPGA. * @details @@ -702,8 +745,8 @@ setSCI2DMATransmitInterrupt(); } -/************************************************************************* - * @brief setupDMAForWriteResp +/*********************************************************************//** + * @brief * The setupDMAForWriteResp function sets the expected byte count for the \n * next DMA write command response from the FPGA. * @details @@ -725,8 +768,8 @@ } } -/************************************************************************* - * @brief startDMAReceiptOfWriteResp +/*********************************************************************//** + * @brief * The startDMAReceiptOfWriteResp function initiates readiness of the DMA \n * receiver for the next DMA write command response from the FPGA. * @details @@ -742,8 +785,8 @@ setSCI2DMAReceiveInterrupt(); } -/************************************************************************* - * @brief setupDMAForReadCmd +/*********************************************************************//** + * @brief * The setupDMAForReadCmd function sets the byte count for the next DMA \n * read command to the FPGA. * @details @@ -765,8 +808,8 @@ } } -/************************************************************************* - * @brief startDMAReadCmd +/*********************************************************************//** + * @brief * The startDMAReadCmd function initiates the DMA transmit for the next \n * DMA read command to the FPGA. * @details @@ -782,8 +825,8 @@ setSCI2DMATransmitInterrupt(); } -/************************************************************************* - * @brief setupDMAForReadResp +/*********************************************************************//** + * @brief * The setupDMAForReadResp function sets the expected byte count for the \n * next DMA read command response from the FPGA. * @details @@ -805,8 +848,8 @@ } } -/************************************************************************* - * @brief startDMAReceiptOfReadResp +/*********************************************************************//** + * @brief * The startDMAReceiptOfReadResp function initiates readiness of the DMA \n * receiver for the next DMA read command response from the FPGA. * @details @@ -822,8 +865,76 @@ setSCI2DMAReceiveInterrupt(); } -/************************************************************************* - * @brief getFPGAId +/*********************************************************************//** + * @brief + * The consumeUnexpectedData function checks to see if a byte is sitting in \n + * the SCI2 received data register. + * @details + * Inputs : fpgaHeader + * Outputs : none + * @param none + * @return fpgaDiag + *************************************************************************/ +static void consumeUnexpectedData( void ) +{ + // clear any errors + sciRxError( scilinREG ); + // if a byte is pending read, read it + if ( sciIsRxReady( scilinREG ) != 0 ) + { + sciReceiveByte( scilinREG ); + } +} + +/*********************************************************************//** + * @brief + * The setFPGAValveStates function sets the DG valve states with a 16-bit \n + * set of states - one bit per valve, with a 1 meaning "energized" and a 0 \n + * meaning "de-energized". The bit positions for these bit states are as follows: \n + * 0 - VRf.\n + * 1 - VRi.\n + * 2 - VRd.\n + * 3 - VRo.\n + * 4 - VPo.\n + * 5 - VBf.\n + * 6 - VRc.\n + * 7 - VDr.\n + * 8 - VPi.\n + * 9 - VSP.\n + * 10- VR1.\n + * 11- VR2.\n + * 12..15 - reserved or unused. + * @details + * Inputs : none + * Outputs : fpgaActuatorSetPoints.fpgaValveStates + * @param valveStates + * @return none + *************************************************************************/ +void setFPGAValveStates( U16 valveStates ) +{ + fpgaActuatorSetPoints.fpgaValveStates = valveStates; +} + +/*********************************************************************//** + * @brief + * The setFPGADrainPumpSpeed function sets the drain pump target speed. \n + * The drain pump DAC value should be set to 1 count for each 12.94 RPM desired. + * @details + * Inputs : none + * Outputs : fpgaActuatorSetPoints.fpgaDrainPumpSetSpeed + * @param drainPumpDAC + * @return none + *************************************************************************/ +void setFPGADrainPumpSpeed( U08 drainPumpDAC ) +{ + U16 dac = (U16)drainPumpDAC & MASK_OFF_MSB; + + dac = dac << DRAIN_PUMP_DAC_SHIFT_BITS; + fpgaActuatorSetPoints.fpgaDrainPumpSetSpeed = dac; +} + +/*********************************************************************//** + * @brief * The getFPGAId function gets the version read from the Id register \n * of the FPGA. * @details @@ -837,8 +948,8 @@ return fpgaHeader.fpgaId; } -/************************************************************************* - * @brief getFPGARev +/*********************************************************************//** + * @brief * The getFPGARev function gets the revision read from the Rev register \n * of the FPGA. * @details @@ -852,8 +963,8 @@ return fpgaHeader.fpgaRev; } -/************************************************************************* - * @brief getFPGAStatus +/*********************************************************************//** + * @brief * The getFPGAStatus function gets the version read from the diagnostic register \n * of the FPGA. * @details @@ -867,8 +978,8 @@ return fpgaSensorReadings.fpgaStatus; } -/************************************************************************* - * @brief getFPGALoadCellA1 +/*********************************************************************//** + * @brief * The getFPGALoadCellA1 function gets the latest load cell A 1 reading. * @details * Inputs : fpgaSensorReadings @@ -878,11 +989,11 @@ *************************************************************************/ U32 getFPGALoadCellA1( void ) { - return fpgaSensorReadings.LCA1; + return ( fpgaSensorReadings.fpgaLCA1 & MASK_OFF_U32_MSB ); } -/************************************************************************* - * @brief getFPGALoadCellA2 +/*********************************************************************//** + * @brief * The getFPGALoadCellA2 function gets the latest load cell A 2 reading. * @details * Inputs : fpgaSensorReadings @@ -892,11 +1003,11 @@ *************************************************************************/ U32 getFPGALoadCellA2( void ) { - return fpgaSensorReadings.LCA2; + return ( fpgaSensorReadings.fpgaLCA2 & MASK_OFF_U32_MSB ); } -/************************************************************************* - * @brief getFPGALoadCellB1 +/*********************************************************************//** + * @brief * The getFPGALoadCellB1 function gets the latest load cell B 1 reading. * @details * Inputs : fpgaSensorReadings @@ -906,11 +1017,11 @@ *************************************************************************/ U32 getFPGALoadCellB1( void ) { - return fpgaSensorReadings.LCB1; + return ( fpgaSensorReadings.fpgaLCB1 & MASK_OFF_U32_MSB ); } -/************************************************************************* - * @brief getFPGALoadCellB2 +/*********************************************************************//** + * @brief * The getFPGALoadCellB2 function gets the latest load cell B 2 reading. * @details * Inputs : fpgaSensorReadings @@ -920,27 +1031,108 @@ *************************************************************************/ U32 getFPGALoadCellB2( void ) { - return fpgaSensorReadings.LCB2; + return ( fpgaSensorReadings.fpgaLCB2 & MASK_OFF_U32_MSB ); } -/************************************************************************* - * @brief consumeUnexpectedData - * The consumeUnexpectedData function checks to see if a byte is sitting in \n - * the SCI2 received data register. +/*********************************************************************//** + * @brief + * The getFPGAValveStates function gets the latest sensed valve states. \n + * See setFPGAValveStates for valve state bit positions. * @details - * Inputs : fpgaHeader + * Inputs : fpgaSensorReadings.fpgaValveStates * Outputs : none * @param none - * @return fpgaDiag + * @return last valve states reading *************************************************************************/ -static void consumeUnexpectedData( void ) +U16 getFPGAValveStates( void ) { - // clear any errors - sciRxError( scilinREG ); - // if a byte is pending read, read it - if ( sciIsRxReady( scilinREG ) != 0 ) - { - sciReceiveByte( scilinREG ); - } + return fpgaSensorReadings.fpgaValveStates; } +/*********************************************************************//** + * @brief + * The getFPGAROPumpFlowRate function gets the latest RO flow rate. + * @details + * Inputs : fpgaSensorReadings.fpgaROFlowRate + * Outputs : none + * @param none + * @return last RO flow rate reading + *************************************************************************/ +U16 getFPGAROPumpFlowRate( void ) +{ + return fpgaSensorReadings.fpgaROFlowRate; +} + +/*********************************************************************//** + * @brief + * The getFPGADrainPumpSpeed function gets the latest sensed drain pump speed. + * @details + * Inputs : fpgaSensorReadings.fpgaDrainPumpSpeed + * Outputs : none + * @param none + * @return last drain pump speed reading + *************************************************************************/ +U16 getFPGADrainPumpSpeed( void ) +{ + return fpgaSensorReadings.fpgaDrainPumpSpeed; +} + +/*********************************************************************//** + * @brief + * The getFPGATPiTemp function gets the latest primary heater inlet \n + * temperature reading. + * @details + * Inputs : fpgaSensorReadings.fpgaTPiTemp + * Outputs : none + * @param none + * @return last primary heater inlet temperature reading + *************************************************************************/ +U32 getFPGATPiTemp( void ) +{ + return ( fpgaSensorReadings.fpgaTPiTemp & MASK_OFF_U32_MSB ); +} + +/*********************************************************************//** + * @brief + * The getFPGATPoTemp function gets the latest primary heater outlet \n + * temperature reading. + * @details + * Inputs : fpgaSensorReadings.fpgaTPoTemp + * Outputs : none + * @param none + * @return last primary heater outlet temperature reading + *************************************************************************/ +U32 getFPGATPoTemp( void ) +{ + return ( fpgaSensorReadings.fpgaTPoTemp & MASK_OFF_U32_MSB ); +} + +/*********************************************************************//** + * @brief + * The getFPGAPrimaryHeaterTemp function gets the latest primary heater \n + * internal temperature reading. + * @details + * Inputs : fpgaSensorReadings.fpgaPrimaryHeaterIntTemp + * Outputs : none + * @param none + * @return last primary heater temperature reading + *************************************************************************/ +U16 getFPGAPrimaryHeaterTemp( void ) +{ + return fpgaSensorReadings.fpgaPrimaryHeaterIntTemp; +} + +/*********************************************************************//** + * @brief + * The getFPGATrimmerHeaterTemp function gets the latest trimmer heater \n + * internal temperature reading. + * @details + * Inputs : fpgaSensorReadings.fpgaTrimmerHeaterIntTemp + * Outputs : none + * @param none + * @return last trimmer heater temperature reading + *************************************************************************/ +U16 getFPGATrimmerHeaterTemp( void ) +{ + return fpgaSensorReadings.fpgaTrimmerHeaterIntTemp; +} Index: firmware/App/Services/FPGA.h =================================================================== diff -u -r4fa5628781e2b420cad6afc42a4b754dd484b997 -r16dfbeeca1bcf1d2115c2f7549999fdaae0700e9 --- firmware/App/Services/FPGA.h (.../FPGA.h) (revision 4fa5628781e2b420cad6afc42a4b754dd484b997) +++ firmware/App/Services/FPGA.h (.../FPGA.h) (revision 16dfbeeca1bcf1d2115c2f7549999fdaae0700e9) @@ -1,4 +1,4 @@ -/************************************************************************** +/**********************************************************************//** * * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. * @@ -32,10 +32,20 @@ void signalFPGAReceiptCompleted( void ); void signalFPGATransmitCompleted( void ); +void setFPGAValveStates( U16 valveStates ); +void setFPGADrainPumpSpeed( U08 drainPumpDAC ); + U16 getFPGAStatus( void ); +U16 getFPGAValveStates( void ); +U16 getFPGAROPumpFlowRate( void ); +U16 getFPGADrainPumpSpeed( void ); U32 getFPGALoadCellA1( void ); U32 getFPGALoadCellA2( void ); U32 getFPGALoadCellB1( void ); U32 getFPGALoadCellB2( void ); +U32 getFPGATPiTemp( void ); +U32 getFPGATPoTemp( void ); +U16 getFPGAPrimaryHeaterTemp( void ); +U16 getFPGATrimmerHeaterTemp( void ); #endif Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r138efd92a8645e0d2fe422409ef5a33dd2929a25 -r16dfbeeca1bcf1d2115c2f7549999fdaae0700e9 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 138efd92a8645e0d2fe422409ef5a33dd2929a25) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 16dfbeeca1bcf1d2115c2f7549999fdaae0700e9) @@ -60,8 +60,7 @@ typedef struct { U32 setROPumpPressure; - F32 measROPumpPressure; - F32 measROPumpSpeed; + F32 measROFlowRate; F32 roPumpPWM; } RO_PUMP_DATA_T; @@ -339,12 +338,11 @@ * Inputs : none * Outputs : RO pump data msg constructed and queued * @param tgtPressure : target pressure for RO pump in PSI. - * @param measPressure : measured pressure for RO pump in PSI. - * @param measSpeed : measure RO pump speed in RPM. + * @param measFlow : measure RO flow rate in LPM. * @param setPWM : set PWM duty cycle in %. * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ -BOOL broadcastROPumpData( U32 tgtPressure, F32 measPressure, F32 measSpeed, F32 setPWM ) +BOOL broadcastROPumpData( U32 tgtPressure, F32 measFlow, F32 setPWM ) { BOOL result; MESSAGE_T msg; @@ -357,8 +355,7 @@ msg.hdr.payloadLen = sizeof( RO_PUMP_DATA_T ); payload.setROPumpPressure = tgtPressure; - payload.measROPumpPressure = measPressure; - payload.measROPumpSpeed = measSpeed; + payload.measROFlowRate = measFlow; payload.roPumpPWM = setPWM; memcpy( payloadPtr, &payload, sizeof( RO_PUMP_DATA_T ) ); Index: firmware/App/Services/SystemCommMessages.h =================================================================== diff -u -r138efd92a8645e0d2fe422409ef5a33dd2929a25 -r16dfbeeca1bcf1d2115c2f7549999fdaae0700e9 --- firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 138efd92a8645e0d2fe422409ef5a33dd2929a25) +++ firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 16dfbeeca1bcf1d2115c2f7549999fdaae0700e9) @@ -39,7 +39,7 @@ BOOL broadcastLoadCellData( F32 loadCellA1, F32 loadCellA2, F32 loadCellB1, F32 loadCellB2 ); // MSG_ID_RO_PUMP_DATA -BOOL broadcastROPumpData( U32 tgtPressure, F32 measPressure, F32 measSpeed, F32 setPWM ); +BOOL broadcastROPumpData( U32 tgtPressure, F32 measFlow, F32 setPWM ); // MSG_ID_DG_PRESSURES_DATA BOOL broadcastPressureSensorsData( F32 measROIn, F32 measROOut, F32 measDrainIn, F32 measDrainOut );