Index: firmware/App/Services/FPGA.c =================================================================== diff -u -r1f3647830e9de0a1f0a4e445ce8d72d5525f51fb -r90f6438e80dbe0a32472a076a0d1bc54db65d15a --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision 1f3647830e9de0a1f0a4e445ce8d72d5525f51fb) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision 90f6438e80dbe0a32472a076a0d1bc54db65d15a) @@ -80,15 +80,24 @@ typedef struct // TODO - add all sensor readings to this structure per FPGA register map { - U16 bloodLeak; - U32 adc1b; - U32 adc2b; - U32 dialysateTemp1; - U32 venousPressure; - U32 arterialPressure; - U32 adc1a; - U32 adc2a; - U32 dialysateTemp2; + U08 bloodFlowMeterCommStatus; + U08 bloodFlowMeterFrameCount; + U16 bloodFlowMeterDeviceStatus; + F32 bloodFlowLast; + F32 bloodFlowAvg; + F32 bloodFlowMeterSoundSpeed; + F32 bloodFlowMeterAccFlowData; + F32 bloodFlowMeterSignalStrength; + U32 bloodFlowMeterSensorID; + U08 dialysateFlowMeterCommStatus; + U08 dialysateFlowMeterFrameCount; + U16 dialysateFlowMeterDeviceStatus; + F32 dialysateFlowLast; + F32 dialysateFlowAvg; + F32 dialysateFlowMeterSoundSpeed; + F32 dialysateFlowMeterAccFlowData; + F32 dialysateFlowMeterSignalStrength; + U32 dialysateFlowMeterSensorID; } FPGA_SENSORS_T; typedef struct // TODO - add all actuator set points to this structure per FPGA register map @@ -446,8 +455,8 @@ fpgaReadCmdBuffer[2] = 0x00; fpgaReadCmdBuffer[3] = sizeof(FPGA_HEADER_T); crc = crc16( fpgaReadCmdBuffer, FPGA_READ_CMD_HDR_LEN ); - fpgaReadCmdBuffer[4] = GET_LSB_OF_WORD( crc ); - fpgaReadCmdBuffer[5] = GET_MSB_OF_WORD( crc ); + fpgaReadCmdBuffer[4] = GET_MSB_OF_WORD( crc ); + fpgaReadCmdBuffer[5] = GET_LSB_OF_WORD( crc ); // prep DMA for sending the read cmd and receiving the response fpgaReadCommandInProgress = TRUE; setupDMAForReadResp( FPGA_READ_RSP_HDR_LEN + sizeof(FPGA_HEADER_T) + FPGA_CRC_LEN ); @@ -480,11 +489,10 @@ { U32 rspSize = FPGA_READ_RSP_HDR_LEN + sizeof(FPGA_HEADER_T); U32 crcPos = rspSize; - U16 crc = MAKE_WORD_OF_BYTES( fpgaReadResponseBuffer[crcPos+1], fpgaReadResponseBuffer[crcPos] ); + U16 crc = MAKE_WORD_OF_BYTES( fpgaReadResponseBuffer[crcPos], fpgaReadResponseBuffer[crcPos+1] ); // does the FPGA response CRC check out? -// if ( crc == crc16( fpgaReadResponseBuffer, rspSize ) ) - if ( 1 ) // TODO - remove when FPGA CRCs are implemented + if ( crc == crc16( fpgaReadResponseBuffer, rspSize ) ) { fpgaCommRetryCount = 0; // capture the read values @@ -531,22 +539,21 @@ fpgaWriteCmdBuffer[0] = FPGA_WRITE_CMD_CODE; fpgaWriteCmdBuffer[1] = 0x08; // start at FPGA address 8 fpgaWriteCmdBuffer[2] = 0x00; - fpgaWriteCmdBuffer[3] = 1; // TODO - replace 1 with sizeof(FPGA_ACTUATORS_T) -// memcpy( &(fpgaWriteCmdBuffer[FPGA_WRITE_CMD_HDR_LEN]), &fpgaActuatorSetPoints, sizeof(FPGA_ACTUATORS_T) ); - fpgaWriteCmdBuffer[FPGA_WRITE_CMD_HDR_LEN] = 99; // TODO - remove and replace with memcpy above - crc = crc16( fpgaWriteCmdBuffer, FPGA_WRITE_CMD_HDR_LEN+1 ); // TODO - replace +1 with +sizeof(FPGA_ACTUATORS_T) - fpgaWriteCmdBuffer[FPGA_WRITE_CMD_HDR_LEN+1] = GET_LSB_OF_WORD( crc ); // TODO - replace +1 with +sizeof(FPGA_ACTUATORS_T) - fpgaWriteCmdBuffer[FPGA_WRITE_CMD_HDR_LEN+1+1] = GET_MSB_OF_WORD( crc ); // TODO - replace +1 with +sizeof(FPGA_ACTUATORS_T) + fpgaWriteCmdBuffer[3] = sizeof(FPGA_ACTUATORS_T); + memcpy( &(fpgaWriteCmdBuffer[FPGA_WRITE_CMD_HDR_LEN]), &fpgaActuatorSetPoints, sizeof(FPGA_ACTUATORS_T) ); + crc = crc16( fpgaWriteCmdBuffer, FPGA_WRITE_CMD_HDR_LEN+sizeof(FPGA_ACTUATORS_T) ); + fpgaWriteCmdBuffer[FPGA_WRITE_CMD_HDR_LEN+sizeof(FPGA_ACTUATORS_T)] = GET_MSB_OF_WORD( crc ); + fpgaWriteCmdBuffer[FPGA_WRITE_CMD_HDR_LEN+sizeof(FPGA_ACTUATORS_T)+1] = GET_LSB_OF_WORD( crc ); // construct bulk read command to read sensor data registers starting at address 8 fpgaReadCmdBuffer[0] = FPGA_READ_CMD_CODE; - fpgaReadCmdBuffer[1] = 0x08; // start at FPGA address 8 - fpgaReadCmdBuffer[2] = 0x00; + fpgaReadCmdBuffer[1] = 0x08; // start at FPGA address 0x108 (264) + fpgaReadCmdBuffer[2] = 0x01; fpgaReadCmdBuffer[3] = sizeof(FPGA_SENSORS_T); crc = crc16( fpgaReadCmdBuffer, FPGA_READ_CMD_HDR_LEN ); - fpgaReadCmdBuffer[4] = GET_LSB_OF_WORD( crc ); - fpgaReadCmdBuffer[5] = GET_MSB_OF_WORD( crc ); + fpgaReadCmdBuffer[4] = GET_MSB_OF_WORD( crc ); + fpgaReadCmdBuffer[5] = GET_LSB_OF_WORD( crc ); // prep DMA for sending the bulk write cmd and receiving its response - setupDMAForWriteCmd( FPGA_WRITE_CMD_HDR_LEN + 1 + FPGA_CRC_LEN ); // TODO s/b sizeof(FPGA_ACTUATORS_T) instead of 1 + setupDMAForWriteCmd( FPGA_WRITE_CMD_HDR_LEN + sizeof(FPGA_ACTUATORS_T) + FPGA_CRC_LEN ); setupDMAForWriteResp( FPGA_WRITE_RSP_HDR_LEN + FPGA_CRC_LEN ); // prep DMA for sending the bulk read cmd and receiving its response setupDMAForReadCmd( FPGA_READ_CMD_HDR_LEN + FPGA_CRC_LEN ); @@ -589,11 +596,10 @@ { U32 rspSize = FPGA_READ_RSP_HDR_LEN + sizeof(FPGA_SENSORS_T); U32 crcPos = rspSize; - U16 crc = MAKE_WORD_OF_BYTES( fpgaReadResponseBuffer[crcPos+1], fpgaReadResponseBuffer[crcPos] ); + U16 crc = MAKE_WORD_OF_BYTES( fpgaReadResponseBuffer[crcPos], fpgaReadResponseBuffer[crcPos+1] ); // does the FPGA response CRC check out? -// if ( crc == crc16( fpgaReadResponseBuffer, rspSize ) ) - if ( 1 ) // TODO - remove when FPGA CRCs are implemented + if ( crc == crc16( fpgaReadResponseBuffer, rspSize ) ) { fpgaCommRetryCount = 0; // capture the read values @@ -846,7 +852,7 @@ * Inputs : fpgaHeader * Outputs : none * @param none - * @return fpgaDiag + * @return fpgaHeader.fpgaStatus *************************************************************************/ U16 getFPGAStatus( void ) { @@ -855,20 +861,47 @@ /************************************************************************* * @brief getFPGADiag - * The getFPGADiag function gets the version read from the diagnostic register \n - * of the FPGA. + * The getFPGADiag function sets the diagnostic register of the FPGA. * @details * Inputs : fpgaHeader * Outputs : none - * @param none - * @return fpgaDiag + * @param ctrl : value to write to diagnostic register + * @return none *************************************************************************/ void setFPGAControl( U16 ctrl ) { fpgaHeader.fpgaControl = ctrl; } /************************************************************************* + * @brief getFPGABloodFlow + * The getFPGABloodFlow function gets the latest blood flow reading. + * @details + * Inputs : fpgaSensorReadings + * Outputs : none + * @param none + * @return last blood flow reading + *************************************************************************/ +F32 getFPGABloodFlow( void ) +{ + return fpgaSensorReadings.bloodFlowLast; +} + +/************************************************************************* + * @brief getFPGADialysateFlow + * The getFPGADialysateFlow function gets the latest dialysate flow reading. + * @details + * Inputs : fpgaSensorReadings + * Outputs : none + * @param none + * @return last dialysate flow reading + *************************************************************************/ +F32 getFPGADialysateFlow( void ) +{ + return fpgaSensorReadings.dialysateFlowLast; +} + +/************************************************************************* * @brief consumeUnexpectedData * The consumeUnexpectedData function checks to see if a byte is sitting in \n * the SCI2 received data register.