Index: firmware/App/Services/FPGA.c =================================================================== diff -u -r05f42ecd223cf512e9e8f3434dd01bdac3aca86d -r26c64288f4baab3707eb9555636b61c0e747f965 --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision 05f42ecd223cf512e9e8f3434dd01bdac3aca86d) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision 26c64288f4baab3707eb9555636b61c0e747f965) @@ -1,4 +1,4 @@ -/************************************************************************** +/**********************************************************************//** * * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. * @@ -40,11 +40,11 @@ } FPGA_STATE_T; #define FPGA_PAGE_SIZE 256 -#define FPGA_EXPECTED_ID 0x59 +#define FPGA_EXPECTED_ID 0x60 -#define FPGA_HEADER_START_ADDR 256 // update these after re-arranging w/ Randy -#define FPGA_BULK_READ_START_ADDR 262 -#define FPGA_BULK_WRITE_START_ADDR 2 +#define FPGA_HEADER_START_ADDR 0x0000 +#define FPGA_BULK_READ_START_ADDR 0x0100 +#define FPGA_BULK_WRITE_START_ADDR 0x0010 #define FPGA_WRITE_CMD_BUFFER_LEN (FPGA_PAGE_SIZE+8) #define FPGA_READ_CMD_BUFFER_LEN 8 @@ -68,55 +68,93 @@ #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 fpgaControl; - U16 fpgaStatus; + U08 fpgaId; ///< Reg 0. FPGA ID code. Checked against expected value at power up to verify basic FPGA communication and operation. + U08 fpgaRev; ///< Reg 1. FPGA revision being reported. } FPGA_HEADER_T; // read only on FPGA typedef struct // TODO - add all sensor readings to this structure per FPGA register map { - U32 LCA1; - U32 LCA2; - U32 LCB1; - U32 LCB2; + U32 fpgaLCA1; ///< Reg 256. ADC1 channel 0 - load cell A1. + U32 fpgaLCB1; ///< Reg 260. ADC1 channel 1 - load cell B1. + U32 fpgaADC1Temp; ///< Reg 264. ADC1 channel 2 - internal temperature. - //U08 bloodFlowMeterDataPktCount; - //U08 bloodFlowMeterSlowPktCounts; - //U08 bloodFlowMeterDeviceStatus; - //U08 bloodFlowMeterResponse; - //F32 bloodFlowLast; - //U08 dialysateFlowMeterDataPktCount; - //U08 dialysateFlowMeterSlowPckCounts; - //U08 dialysateFlowMeterDeviceStatus; - //U08 dialysateFlowMeterResponse; - //F32 dialysateFlowLast; + U32 fpgaLCA2; ///< Reg 268. ADC2 channel 0 - load cell A2. + U32 fpgaLCB2; ///< Reg 272. ADC2 channel 1 - load cell B2. + U32 fpgaADC2Temp; ///< Reg 276. ADC2 channel 2 - internal temperature. - U08 bloodFlowMeterErrorCount; - U08 dialysateFlowMeterErrorCount; - U16 bloodOcclusionData; - U08 bloodOcclusionReadCount; - U08 bloodOcclusionErrorCount; - U16 dialysateInOcclusionData; - U08 dialysateInOcclusionReadCount; - U08 dialysateInOcclusionErrorCount; - U16 dialysateOutOcclusionData; - U08 dialysateOutOcclusionReadCount; - U08 dialysateOutOcclusionErrorCount; - U16 arterialPressureData; - U08 arterialPressureReadCount; - U08 arterialPressureErrorCount; - U16 dialysateTempPrimaryData; - U16 dialysateTempBackupData; + U32 fpgaCD1; ///< Reg 280. ADC RTD channel 0 - conductivity sensor 1. + U32 fpgaCD2; ///< Reg 284. ADC RTD channel 1 - conductivity sensor 2. + U32 fpgaTPoTemp; ///< Reg 288. ADC RTD channel 2 - conductivity sensor CPi temperature. + U32 fpgaTPiTemp; ///< Reg 292. ADC RTD channel 3 - conductivity sensor CPo temperature. + U32 fpgaRTDTemp; ///< Reg 296. ADC RTD channel 4 - internal temperature. + + U32 fpgaTHDo; ///< Reg 300. ADC THDo channel 0 - temperature. + U32 fpgaTHDoTemp; ///< Reg 304. ADC THDo channel 1 - internal temperature. + + U32 fpgaTDi; ///< Reg 308. ADC TDi channel 0 - temperature. + U32 fpgaTDiTemp; ///< Reg 312. ADC TDi channel 1 - internal temperature. + + U32 fpgaCPo; ///< Reg 316. Conductivity CPo. + U32 fpgaCPi; ///< Reg 320. Conductivity CPi. + + U16 fpgaPrimaryHeaterIntTemp; ///< Reg 324. Primary heater temperature. + U16 fpgaPrimaryHeaterIntJunctionTemp; ///< Reg 326. Primary heater internal temperature. + U16 fpgaTrimmerHeaterIntTemp; ///< Reg 328. Trimmer heater temperature. + U16 fpgaTrimmerHeaterIntJunctionTemp; ///< Reg 330. Trimmer heater internal temperature. + + U16 fpgaDrainPumpSpeed; ///< Reg 332. Drain pump speed feedback. + U16 fpgaROFlowRate; ///< Reg 334. RO flow. + + U16 accelX; ///< Reg 336. Accelerometer X axis data. + U16 accelY; ///< Reg 338. Accelerometer Y axis data. + U16 accelZ; ///< Reg 340. Accelerometer Z axis data. + U16 accelXMax; ///< Reg 342. Accelerometer X axis max data (since last read). + U16 accelYMax; ///< Reg 344. Accelerometer Y axis max data (since last read). + U16 accelZMax; ///< Reg 346. Accelerometer Z axis max data (since last read). + U16 accelFaultRegister; ///< Reg 348. Accelerometer fault register. + U16 accelSampleCounter; ///< Reg 350. Accelerometer sample count. + + U08 fpgaIOErrorCntProcessor; ///< Reg 352. + U08 fpgaIOErrorCntPC; ///< Reg 353. + U08 fpgaADC1ReadCnt; ///< Reg 354. + U08 fpgaADC1ErrorCnt; ///< Reg 355. + U08 fpgaADC2ReadCnt; ///< Reg 356. + U08 fpgaADC2ErrorCnt; ///< Reg 357. + U08 fpgaRTDReadCnt; ///< Reg 358. + U08 fpgaRTDErrorCnt; ///< Reg 359. + U08 fpgaTHDoReadCnt; ///< Reg 360. + U08 fpgaTHDoErrorCnt; ///< Reg 361. + U08 fpgaTDiReadCnt; ///< Reg 362. + U08 fpgaTDiErrorCnt; ///< Reg 363. + U08 fpgaPrimaryHeaterFlags; ///< Reg 364. + U08 fpgaPrimaryHeaterReadCnt; ///< Reg 365. + U08 fpgaTrimmerHeaterFlags; ///< Reg 366. + U08 fpgaTrimmerHeaterReadCnt; ///< Reg 367. + U08 fpgaCPoFault; ///< Reg 368. + U08 fpgaCPoReadCnt; ///< Reg 369. + U08 fpgaCPoErrorCnt; ///< Reg 370. + U08 fpgaCPiFault; ///< Reg 371. + U08 fpgaCPiReadCnt; ///< Reg 372. + U08 fpgaCPiErrorCnt; ///< Reg 373. + U08 fpgaCP1CP2Fault; ///< Reg 374. + U08 fpgaReserved1; ///< Reg 375. + + U16 fpgaValveStates; ///< Reg 376. } 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 fpgaCPiProbeType; + U16 fpgaDrainPumpSetSpeed; + U16 fpgaValveStates; } FPGA_ACTUATORS_T; #pragma pack(pop) @@ -148,7 +186,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 ********** @@ -170,8 +208,8 @@ static void consumeUnexpectedData( void ); -/************************************************************************* - * @brief initFPGA +/*********************************************************************//** + * @brief * The initFPGA function initializes the FPGA module. * @details * Inputs : none @@ -186,6 +224,11 @@ memset( &fpgaSensorReadings, 0, sizeof(DG_FPGA_SENSORS_T) ); memset( &fpgaActuatorSetPoints, 0, sizeof(FPGA_ACTUATORS_T) ); + // TODO Remove the below line + // Initialize the valves + fpgaActuatorSetPoints.fpgaValveStates = 0x015F; + // TODO Remove the above line + // initialize fpga comm buffers memset( &fpgaWriteCmdBuffer, 0, FPGA_WRITE_CMD_BUFFER_LEN ); memset( &fpgaReadCmdBuffer, 0, FPGA_READ_CMD_BUFFER_LEN ); @@ -281,8 +324,8 @@ consumeUnexpectedData(); } -/************************************************************************* - * @brief resetFPGACommFlags +/*********************************************************************//** + * @brief * The resetFPGACommFlags function resets the various fpga comm flags and \n * counters. * @details @@ -302,8 +345,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 @@ -338,8 +381,8 @@ } } -/************************************************************************* - * @brief signalFPGATransmitCompleted +/*********************************************************************//** + * @brief * The signalFPGATransmitCompleted function increments a counter to indicate \n * that another DMA transmit to the FPGA has completed. * @details @@ -353,8 +396,8 @@ fpgaTransmitCounter++; } -/************************************************************************* - * @brief execFPGAIn +/*********************************************************************//** + * @brief * The execFPGA function manages incoming data exchanges with the FPGA. * @details * Inputs : fpgaState @@ -407,8 +450,8 @@ resetFPGACommFlags(); } -/************************************************************************* - * @brief execFPGAOut +/*********************************************************************//** + * @brief * The execFPGAOut function manages outgoing data exchanges with the FPGA. * @details * Inputs : fpgaState @@ -448,8 +491,8 @@ } } -/************************************************************************* - * @brief handleFPGAReadHeaderState +/*********************************************************************//** + * @brief * The handleFPGAReadHeaderState function handles the FPGA state where \n * the read header registers command is sent to the FPGA. * @details @@ -465,8 +508,8 @@ // 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[ 2 ] = 0x00; + fpgaReadCmdBuffer[ 1 ] = GET_LSB_OF_WORD( FPGA_HEADER_START_ADDR ); + fpgaReadCmdBuffer[ 2 ] = GET_MSB_OF_WORD( FPGA_HEADER_START_ADDR ); fpgaReadCmdBuffer[ 3 ] = sizeof(FPGA_HEADER_T); crc = crc16( fpgaReadCmdBuffer, FPGA_READ_CMD_HDR_LEN ); fpgaReadCmdBuffer[ 4 ] = GET_MSB_OF_WORD( crc ); @@ -481,8 +524,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 @@ -534,8 +577,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 @@ -551,17 +594,17 @@ // 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[ 2 ] = 0x00; + fpgaWriteCmdBuffer[ 1 ] = GET_LSB_OF_WORD( FPGA_BULK_WRITE_START_ADDR ); + fpgaWriteCmdBuffer[ 2 ] = GET_MSB_OF_WORD( FPGA_BULK_WRITE_START_ADDR ); 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 0x108 (264) - fpgaReadCmdBuffer[ 2 ] = 0x01; + fpgaReadCmdBuffer[ 1 ] = GET_LSB_OF_WORD( FPGA_BULK_READ_START_ADDR ); + fpgaReadCmdBuffer[ 2 ] = GET_MSB_OF_WORD( FPGA_BULK_READ_START_ADDR ); fpgaReadCmdBuffer[ 3 ] = sizeof(DG_FPGA_SENSORS_T); crc = crc16( fpgaReadCmdBuffer, FPGA_READ_CMD_HDR_LEN ); fpgaReadCmdBuffer[ 4 ] = GET_MSB_OF_WORD( crc ); @@ -582,8 +625,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 @@ -641,8 +684,8 @@ return result; } -/************************************************************************* - * @brief execFPGATest +/*********************************************************************//** + * @brief * The execFPGATest function executes the FPGA self-test. \n * @details * Inputs : fpgaHeader @@ -672,8 +715,8 @@ return result; } -/************************************************************************* - * @brief setupDMAForWriteCmd +/*********************************************************************//** + * @brief * The setupDMAForWriteCmd function sets the byte count for the next DMA \n * write command to the FPGA. * @details @@ -695,8 +738,8 @@ } } -/************************************************************************* - * @brief startDMAWriteCmd +/*********************************************************************//** + * @brief * The startDMAWriteCmd function initiates the DMA transmit for the next \n * DMA write command to the FPGA. * @details @@ -712,8 +755,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 @@ -735,8 +778,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 @@ -752,8 +795,8 @@ setSCI2DMAReceiveInterrupt(); } -/************************************************************************* - * @brief setupDMAForReadCmd +/*********************************************************************//** + * @brief * The setupDMAForReadCmd function sets the byte count for the next DMA \n * read command to the FPGA. * @details @@ -775,8 +818,8 @@ } } -/************************************************************************* - * @brief startDMAReadCmd +/*********************************************************************//** + * @brief * The startDMAReadCmd function initiates the DMA transmit for the next \n * DMA read command to the FPGA. * @details @@ -792,8 +835,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 @@ -815,8 +858,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 @@ -832,8 +875,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..11 - reserved (spare).\n + * 12- VPd.\n + * 13..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 @@ -847,8 +958,8 @@ return fpgaHeader.fpgaId; } -/************************************************************************* - * @brief getFPGARev +/*********************************************************************//** + * @brief * The getFPGARev function gets the revision read from the Rev register \n * of the FPGA. * @details @@ -862,8 +973,8 @@ return fpgaHeader.fpgaRev; } -/************************************************************************* - * @brief getFPGAStatus +/*********************************************************************//** + * @brief * The getFPGAStatus function gets the version read from the diagnostic register \n * of the FPGA. * @details @@ -874,25 +985,11 @@ *************************************************************************/ U16 getFPGAStatus( void ) { - return fpgaHeader.fpgaStatus; + return 0;//fpgaSensorReadings.fpgaStatus; } -/************************************************************************* - * @brief getFPGADiag - * The getFPGADiag function sets the diagnostic register of the FPGA. - * @details - * Inputs : fpgaHeader - * Outputs : none - * @param ctrl : value to write to diagnostic register - * @return none - *************************************************************************/ -void setFPGAControl( U16 ctrl ) -{ - fpgaHeader.fpgaControl = ctrl; -} - -/************************************************************************* - * @brief getFPGALoadCellA1 +/*********************************************************************//** + * @brief * The getFPGALoadCellA1 function gets the latest load cell A 1 reading. * @details * Inputs : fpgaSensorReadings @@ -902,11 +999,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 @@ -916,11 +1013,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 @@ -930,11 +1027,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 @@ -944,112 +1041,347 @@ *************************************************************************/ U32 getFPGALoadCellB2( void ) { - return fpgaSensorReadings.LCB2; + return ( fpgaSensorReadings.fpgaLCB2 & MASK_OFF_U32_MSB ); } +/*********************************************************************//** + * @brief + * The getFPGAValveStates function gets the latest sensed valve states. \n + * See setFPGAValveStates for valve state bit positions. + * @details + * Inputs : fpgaSensorReadings.fpgaValveStates + * Outputs : none + * @param none + * @return last valve states reading + *************************************************************************/ +U16 getFPGAValveStates( void ) +{ + return fpgaSensorReadings.fpgaValveStates; +} -/************************************************************************* - * @brief getFPGABloodPumpOcclusion - * The getFPGABloodPumpOcclusion function gets the latest blood occlusion reading. +/*********************************************************************//** + * @brief + * The getFPGAROPumpFlowRate function gets the latest RO flow rate. * @details - * Inputs : fpgaSensorReadings + * Inputs : fpgaSensorReadings.fpgaROFlowRate * Outputs : none * @param none - * @return last blood occlusion reading + * @return last RO flow rate reading *************************************************************************/ -U16 getFPGABloodPumpOcclusion( void ) +U16 getFPGAROPumpFlowRate( void ) { - return fpgaSensorReadings.bloodOcclusionData; + return fpgaSensorReadings.fpgaROFlowRate; } -/************************************************************************* - * @brief getFPGADialInPumpOcclusion - * The getFPGADialInPumpOcclusion function gets the latest dialysate \n - * inlet occlusion reading. +/*********************************************************************//** + * @brief + * The getFPGADrainPumpSpeed function gets the latest sensed drain pump speed. * @details - * Inputs : fpgaSensorReadings + * Inputs : fpgaSensorReadings.fpgaDrainPumpSpeed * Outputs : none * @param none - * @return last dialysate inlet occlusion reading + * @return last drain pump speed reading *************************************************************************/ -U16 getFPGADialInPumpOcclusion( void ) +U16 getFPGADrainPumpSpeed( void ) { -#ifdef DEBUG_ENABLED -// { -// // TODO - temporary debug code - remove later -// char debugOccStr[ 60 ]; -// S32 dat = fpgaSensorReadings.dialysateInOcclusionData; -// S32 rct = fpgaSensorReadings.dialysateInOcclusionReadCount; -// S32 ect = fpgaSensorReadings.dialysateInOcclusionErrorCount; -// -// sprintf( debugOccStr, "Data %5d Reads %5d Errors %5d\n", dat, rct, ect ); -// sendDebugData( (U08*)debugOccStr, strlen(debugOccStr) ); -// } -#endif - return fpgaSensorReadings.dialysateInOcclusionData; + return fpgaSensorReadings.fpgaDrainPumpSpeed; } -/************************************************************************* - * @brief getFPGADialOutPumpOcclusion - * The getFPGADialOutPumpOcclusion function gets the latest dialysate \n - * outlet occlusion reading. +/*********************************************************************//** + * @brief + * The getFPGATPiTemp function gets the latest primary heater inlet \n + * temperature reading. * @details - * Inputs : fpgaSensorReadings + * Inputs : fpgaSensorReadings.fpgaTPiTemp * Outputs : none * @param none - * @return last dialysate outlet occlusion reading + * @return last primary heater inlet temperature reading *************************************************************************/ -U16 getFPGADialOutPumpOcclusion( void ) +U32 getFPGATPiTemp( void ) { - return fpgaSensorReadings.dialysateOutOcclusionData; + return fpgaSensorReadings.fpgaTPiTemp; } -/************************************************************************* - * @brief getFPGAArterialPressure - * The getFPGAArterialPressure function gets the latest arterial pressure reading. +/*********************************************************************//** + * @brief + * The getFPGATPoTemp function gets the latest primary heater outlet \n + * temperature reading. * @details - * Inputs : fpgaSensorReadings + * Inputs : fpgaSensorReadings.fpgaTPoTemp * Outputs : none * @param none - * @return last arterial pressure reading + * @return last primary heater outlet temperature reading *************************************************************************/ -U16 getFPGAArterialPressure( void ) +U32 getFPGATPoTemp( void ) { - return fpgaSensorReadings.arterialPressureData; + return fpgaSensorReadings.fpgaTPoTemp; } -/************************************************************************* - * @brief getFPGAVenousPressure - * The getFPGAVenousPressure function gets the venous arterial pressure reading. +/*********************************************************************//** + * @brief + * The getFPGATD1Temp function gets the latest conductivity sensor 1 \n + * temperature reading in ADC. * @details - * Inputs : fpgaSensorReadings + * Inputs : fpgaSensorReadings.fpgaCD1Temp * Outputs : none * @param none - * @return last venous pressure reading + * @return last conductivity sensor 1 outlet temperature reading *************************************************************************/ -U16 getFPGAVenousPressure( void ) +U32 getFPGACD1Temp( void ) { - return 0; // TODO - return reading when available + return fpgaSensorReadings.fpgaCD1; } -/************************************************************************* - * @brief consumeUnexpectedData - * The consumeUnexpectedData function checks to see if a byte is sitting in \n - * the SCI2 received data register. +/*********************************************************************//** + * @brief + * The getFPGATD2Temp function gets the latest conductivity sensor 2 \n + * temperature reading in ADC. * @details - * Inputs : fpgaHeader + * Inputs : fpgaSensorReadings.fpgaCD2Temp * Outputs : none * @param none - * @return fpgaDiag + * @return last conductivity sensor 2 outlet temperature reading *************************************************************************/ -static void consumeUnexpectedData( void ) +U32 getFPGACD2Temp( void ) { - // clear any errors - sciRxError( scilinREG ); - // if a byte is pending read, read it - if ( sciIsRxReady( scilinREG ) != 0 ) - { - sciReceiveByte( scilinREG ); - } + return fpgaSensorReadings.fpgaCD2; } +/*********************************************************************//** + * @brief + * The getFPGARTDErrorCount function gets error count of the RTD. It covers \n + * all the four conductivity sensors which include temperature sensors + * @details + * Inputs : fpgaSensorReadings.fpgaRTDErrorCnt + * Outputs : none + * @param none + * @return Last error count of the RTD conductivity sensors + *************************************************************************/ +U08 getFPGARTDErrorCount( void ) +{ + return fpgaSensorReadings.fpgaRTDErrorCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGARTDReadCount function gets the read count of the RTD \n + * conductivity sensors. It covers all the 4 conductivity sensors + * @details + * Inputs : fpgaSensorReadings.fpgaRTDReadCnt + * Outputs : none + * @param none + * @return Last read count of the RTC conductivity sensors + *************************************************************************/ +U08 getFPGARTDReadCount( void ) +{ + return fpgaSensorReadings.fpgaRTDReadCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGATRoTemp function gets the latest redundant sensor outlet \n + * temperature reading in ADC. + * @details + * Inputs : fpgaSensorReadings.fpgaTHDoTemp + * Outputs : none + * @param none + * @return Last redundant sensor outlet temperature reading + *************************************************************************/ +U32 getFPGATHDoTemp( void ) +{ + return fpgaSensorReadings.fpgaTHDo; +} + +/*********************************************************************//** + * @brief + * The getFPGATHDoErrorCount gets the error count of the THDo (redundant) \n + * temperature sensor + * @details + * Inputs : fpgaSensorReadings.fpgaTHDoErrorCnt + * Outputs : none + * @param none + * @return Last redundant sensor outlet temperature error count + *************************************************************************/ +U08 getFPGATHDoErrorCount( void ) +{ + return fpgaSensorReadings.fpgaTHDoErrorCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGATHDoReadCount gets the read count of the THDo (redundant) \n + * @details + * Inputs : fpgaSensorReadings.fpgaTHDoReadCnt + * Outputs : none + * @param none + * @return Last redundant sensor outlet temperature error count reading + *************************************************************************/ +U08 getFPGATHDoReadCount( void ) +{ + return fpgaSensorReadings.fpgaTHDoReadCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGATDiTemp function gets the latest dialysate inlet \n + * temperature reading in ADC. + * @details + * Inputs : fpgaSensorReadings.fpgaTDiTemp + * Outputs : none + * @param none + * @return last primary heater outlet temperature reading + *************************************************************************/ +U32 getFPGATDiTemp( void ) +{ + return fpgaSensorReadings.fpgaTDi; +} + +/*********************************************************************//** + * @brief + * The getFPGATDiErrorCount function gets the latest dialysate inlet \n + * temperature error count. + * @details + * Inputs : fpgaSensorReadings.fpgaTDiErrorCnt + * Outputs : none + * @param none + * @return Last dialysate inlet error count + *************************************************************************/ +U08 getFPGATDiErrorCount( void ) +{ + return fpgaSensorReadings.fpgaTDiErrorCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGATDiReadCount function gets the latest dialysate inlet \n + * temperature read count. + * @details + * Inputs : fpgaSensorReadings.fpgaTDiReadCnt + * Outputs : none + * @param none + * @return Last dialysate inlet read count + *************************************************************************/ +U08 getFPGATDiReadCount( void ) +{ + return fpgaSensorReadings.fpgaTDiReadCnt; +} + +/*********************************************************************//** + * @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 getFPGAPrimaryHeaterFlags function gets the latest primary heater \n + * internal temperature sensor flags read + * @details + * Inputs : fpgaSensorReadings.fpgaPrimaryHeaterFlags + * Outputs : none + * @param none + * @return Last primary heater internal temperature sensor flag read + *************************************************************************/ +U08 getFPGAPrimaryHeaterFlags( void ) +{ + return fpgaSensorReadings.fpgaPrimaryHeaterFlags; +} + +/*********************************************************************//** + * @brief + * The geetFPGAPrimaryHeaterReadCount function gets the latest primary heater \n + * internal temperature sensor read count + * @details + * Inputs : fpgaSensorReadings.fpgaPrimaryHeaterReadCnt + * Outputs : none + * @param none + * @return Last primary heater internal temperature sensor read count + *************************************************************************/ +U08 getFPGAPrimaryHeaterReadCount( void ) +{ + return fpgaSensorReadings.fpgaPrimaryHeaterReadCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGATrimmerHeaterTemp function gets the latest trimmer heater \n + * internal temperature sensor reading. + * @details + * Inputs : fpgaSensorReadings.fpgaTrimmerHeaterIntTemp + * Outputs : none + * @param none + * @return last trimmer heater temperature reading + *************************************************************************/ +U16 getFPGATrimmerHeaterTemp( void ) +{ + return fpgaSensorReadings.fpgaTrimmerHeaterIntTemp; +} + +/*********************************************************************//** + * @brief + * The getFPGATrimmerHeaterFlags function gets the latest trimmer heater \n + * internal temperature flags read. + * @details + * Inputs : fpgaSensorReadings.fpgaTrimmerHeaterFlags + * Outputs : none + * @param none + * @return Last trimmer heater internal temperature flags read + *************************************************************************/ +U08 getFPGATrimmerHeaterFlags( void ) +{ + return fpgaSensorReadings.fpgaTrimmerHeaterFlags; +} + +/*********************************************************************//** + * @brief + * The getFPGATrimmerHeaterReadCount function gets the latest trimmer heater \n + * internal temperature read count. + * @details + * Inputs : fpgaSensorReadings.fpgaTrimmerHeaterReadCnt + * Outputs : none + * @param none + * @return Last trimmer heater internal temperature read count + *************************************************************************/ +U08 getFPGATrimmerHeaterReadCount( void ) +{ + return fpgaSensorReadings.fpgaTrimmerHeaterReadCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGAPRimaryColdJunctionTemp function gets primary cold junction + * temperature + * @details + * Inputs : fpgaSensorReadings.fpgaPrimaryHeaterIntJunctionTemp + * Outputs : none + * @param none + * @return Last primary cold junction temperature + *************************************************************************/ +U16 getFPGAPRimaryColdJunctionTemp ( void ) +{ + return fpgaSensorReadings.fpgaPrimaryHeaterIntJunctionTemp; +} + +/*********************************************************************//** + * @brief + * The getFPGATrimmerColdJunctionTemp function gets trimmer cold junction + * temperature + * @details + * Inputs : fpgaSensorReadings.fpgaTrimmerHeaterIntJunctionTemp + * Outputs : none + * @param none + * @return Last trimmer cold junction temperature + *************************************************************************/ +U16 getFPGATrimmerColdJunctionTemp ( void ) +{ + return fpgaSensorReadings.fpgaTrimmerHeaterIntJunctionTemp; +}