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; +}