Index: firmware/App/Services/FPGA.c =================================================================== diff -u -reb877ae36c28eb83553ee11ccccf42e2c4a5b4d2 -r8f57bb251f1cfa320b2186273a1f09e0023793b7 --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision eb877ae36c28eb83553ee11ccccf42e2c4a5b4d2) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision 8f57bb251f1cfa320b2186273a1f09e0023793b7) @@ -1,824 +1,2318 @@ -/************************************************************************** - * - * Copyright (c) 2019-2019 Diality Inc. - All Rights Reserved. - * - * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN - * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. - * - * @file FPGA.c - * - * @date 21-Oct-2019 - * @author S. Nash - * - * @brief FPGA interface service module. Provides an interface to the FPGA. \n - * Various sensor readings are gathered and get functions provided for them. \n - * Various actuator settings are sent and set functions provided for them. - * - **************************************************************************/ - -#include // for memset(), memcpy() - -#include "sci.h" -#include "sys_dma.h" - -#include "FPGA.h" -#include "Comm.h" -#include "SystemCommMessages.h" -#include "Utilities.h" - -// ********** private definitions ********** - -typedef enum FPGA_States -{ - FPGA_STATE_START = 0, - FPGA_STATE_READ_HEADER, - FPGA_STATE_RCV_HEADER, - FPGA_STATE_WRITE_ALL_ACTUATORS, - FPGA_STATE_RCV_ALL_SENSORS, - FPGA_STATE_FAILED, - NUM_OF_FPGA_STATES -} FPGA_STATE_T; - -#define FPGA_PAGE_SIZE 256 -#define FPGA_EXPECTED_ID 0x59 - -#define FPGA_WRITE_CMD_BUFFER_LEN (FPGA_PAGE_SIZE+8) -#define FPGA_READ_CMD_BUFFER_LEN 8 -#define FPGA_WRITE_RSP_BUFFER_LEN 8 -#define FPGA_READ_RSP_BUFFER_LEN (FPGA_PAGE_SIZE+8) - -#define FPGA_WRITE_CMD_CODE 0x55 -#define FPGA_READ_CMD_CODE 0x5A -#define FPGA_WRITE_CMD_ACK 0xA5 -#define FPGA_WRITE_CMD_NAK 0xAE -#define FPGA_READ_CMD_ACK 0xAA -#define FPGA_READ_CMD_NAK 0xAF - -#define FPGA_CRC_LEN 2 -#define FPGA_WRITE_CMD_HDR_LEN 4 -#define FPGA_READ_CMD_HDR_LEN 4 -#define FPGA_WRITE_RSP_HDR_LEN 1 -#define FPGA_READ_RSP_HDR_LEN 1 - -#define SCI2_RECEIVE_DMA_REQUEST 28 -#define SCI2_TRANSMIT_DMA_REQUEST 29 - -// FPGA Sensors Record -#pragma pack(push,1) -typedef struct -{ - U08 fpgaId; - U08 fpgaRev; - U08 fpgaDiag; - U08 gap1; - U16 fpgaStatus; - U16 fpgaControl; -} FPGA_HEADER_T; - -typedef struct -{ - U16 bloodLeak; - U32 adc1b; - U32 adc2b; - U32 dialysateTemp1; - U32 venousPressure; - U32 arterialPressure; - U32 adc1a; - U32 adc2a; - U32 dialysateTemp2; -} FPGA_SENSORS_T; - -typedef struct -{ -} FPGA_ACTUATORS_T; -#pragma pack(pop) - -// ********** private data ********** - -// FPGA state -static FPGA_STATE_T fpgaState = FPGA_STATE_START; - -static U32 fpgaReceiptCounter = 0; -static U32 fpgaTransmitCounter = 0; -static BOOL fpgaWriteCommandInProgress = FALSE; -static BOOL fpgaReadCommandInProgress = FALSE; -static BOOL fpgaBulkWriteAndReadInProgress = FALSE; -static BOOL fpgaWriteCommandResponseReceived = FALSE; -static BOOL fpgaReadCommandResponseReceived = FALSE; - -// FPGA comm buffers -static U08 fpgaWriteCmdBuffer[FPGA_WRITE_CMD_BUFFER_LEN]; -static U08 fpgaReadCmdBuffer[FPGA_READ_CMD_BUFFER_LEN]; -static U08 fpgaWriteResponseBuffer[FPGA_WRITE_RSP_BUFFER_LEN]; -static U08 fpgaReadResponseBuffer[FPGA_READ_RSP_BUFFER_LEN]; - -// DMA control records -static g_dmaCTRL fpgaDMAWriteControlRecord; -static g_dmaCTRL fpgaDMAWriteRespControlRecord; -static g_dmaCTRL fpgaDMAReadControlRecord; -static g_dmaCTRL fpgaDMAReadRespControlRecord; - -// FPGA data -static FPGA_HEADER_T fpgaHeader; -static FPGA_SENSORS_T fpgaSensorReadings; -static FPGA_ACTUATORS_T fpgaActuatorSetPoints; - -// ********** private function prototypes ********** - -static FPGA_STATE_T handleFPGAReadHeaderState( void ); -static FPGA_STATE_T handleFPGAReceiveHeaderState( void ); -static FPGA_STATE_T handleFPGAWriteAllActuatorsState( void ); -static FPGA_STATE_T handleFPGAReceiveAllSensorsState( void ); - -static void resetFPGACommFlags( void ); -static void setupDMAForWriteCmd( U32 bytes2Transmit ); -static void startDMAWriteCmd( void ); -static void setupDMAForWriteResp( U32 bytes2Receive ); -static void startDMAReceiptOfWriteResp( void ); -static void setupDMAForReadCmd( U32 bytes2Transmit ); -static void startDMAReadCmd( void ); -static void setupDMAForReadResp( U32 bytes2Receive ); -static void startDMAReceiptOfReadResp( void ); - -static void consumeUnexpectedData( void ); - -/************************************************************************* - * @brief initFPGA - * The initFPGA function initializes the FPGA module. - * @details - * Inputs : none - * Outputs : FPGA module initialized. - * @param none - * @return none - *************************************************************************/ -void initFPGA( void ) -{ - // initialize fpga data structures - memset( &fpgaHeader, 0, sizeof(FPGA_HEADER_T) ); - memset( &fpgaSensorReadings, 0, sizeof(FPGA_SENSORS_T) ); - memset( &fpgaActuatorSetPoints, 0, sizeof(FPGA_ACTUATORS_T) ); - - // enable interrupt notifications for FPGA serial port - sciEnableNotification( scilinREG, SCI_OE_INT | SCI_FE_INT ); - - // assign DMA channels to h/w DMA requests - dmaReqAssign( DMA_CH0, SCI2_RECEIVE_DMA_REQUEST ); - dmaReqAssign( DMA_CH2, SCI2_TRANSMIT_DMA_REQUEST ); - // set DMA channel priorities - dmaSetPriority( DMA_CH0, HIGHPRIORITY ); - dmaSetPriority( DMA_CH2, LOWPRIORITY ); - // Enable DMA block transfer complete interrupts - dmaEnableInterrupt( DMA_CH0, BTC ); - dmaEnableInterrupt( DMA_CH2, BTC ); - - // initialize FPGA DMA Write Control Record - fpgaDMAWriteControlRecord.PORTASGN = 4; // port B (only choice per datasheet) - fpgaDMAWriteControlRecord.SADD = (U32)fpgaWriteCmdBuffer; // transfer source address - fpgaDMAWriteControlRecord.DADD = (U32)(&(scilinREG->TD)); // dest. is SCI2 xmit register - fpgaDMAWriteControlRecord.CHCTRL = 0; // no chaining - fpgaDMAWriteControlRecord.ELCNT = 1; // frame is 1 element - fpgaDMAWriteControlRecord.FRCNT = 0; // block is TBD frames - will be populated later when known - fpgaDMAWriteControlRecord.RDSIZE = ACCESS_8_BIT; // element size is 1 byte - fpgaDMAWriteControlRecord.WRSIZE = ACCESS_8_BIT; // - fpgaDMAWriteControlRecord.TTYPE = FRAME_TRANSFER; // transfer type is block transfer - fpgaDMAWriteControlRecord.ADDMODERD = ADDR_INC1; // source addressing mode is post-increment - fpgaDMAWriteControlRecord.ADDMODEWR = ADDR_FIXED; // dest. addressing mode is fixed - fpgaDMAWriteControlRecord.AUTOINIT = AUTOINIT_OFF; // auto-init off - fpgaDMAWriteControlRecord.ELSOFFSET = 0; // not used - fpgaDMAWriteControlRecord.ELDOFFSET = 0; // not used - fpgaDMAWriteControlRecord.FRSOFFSET = 0; // not used - fpgaDMAWriteControlRecord.FRDOFFSET = 0; // not used - - // initialize FPGA DMA Write Response Control Record - fpgaDMAWriteRespControlRecord.PORTASGN = 4; // port B (only choice per datasheet) - fpgaDMAWriteRespControlRecord.SADD = (U32)(&(scilinREG->RD));// source is SCI2 recv register - fpgaDMAWriteRespControlRecord.DADD = (U32)fpgaWriteResponseBuffer; // transfer destination address - fpgaDMAWriteRespControlRecord.CHCTRL = 0; // no chaining - fpgaDMAWriteRespControlRecord.ELCNT = 1; // frame is 1 element - fpgaDMAWriteRespControlRecord.FRCNT = 0; // block is TBD frames - will be populated later when known - fpgaDMAWriteRespControlRecord.RDSIZE = ACCESS_8_BIT; // element size is 1 byte - fpgaDMAWriteRespControlRecord.WRSIZE = ACCESS_8_BIT; // - fpgaDMAWriteRespControlRecord.TTYPE = FRAME_TRANSFER; // transfer type is block transfer - fpgaDMAWriteRespControlRecord.ADDMODERD = ADDR_FIXED; // source addressing mode is fixed - fpgaDMAWriteRespControlRecord.ADDMODEWR = ADDR_INC1; // dest. addressing mode is post-increment - fpgaDMAWriteRespControlRecord.AUTOINIT = AUTOINIT_OFF; // auto-init off - fpgaDMAWriteRespControlRecord.ELDOFFSET = 0; // not used - fpgaDMAWriteRespControlRecord.ELSOFFSET = 0; // not used - fpgaDMAWriteRespControlRecord.FRDOFFSET = 0; // not used - fpgaDMAWriteRespControlRecord.FRSOFFSET = 0; // not used - - // initialize FPGA DMA Read Control Record - fpgaDMAReadControlRecord.PORTASGN = 4; // port B (only choice per datasheet) - fpgaDMAReadControlRecord.SADD = (U32)fpgaReadCmdBuffer; // transfer source address - fpgaDMAReadControlRecord.DADD = (U32)(&(scilinREG->TD)); // dest. is SCI2 xmit register - fpgaDMAReadControlRecord.CHCTRL = 0; // no chaining - fpgaDMAReadControlRecord.ELCNT = 1; // frame is 1 element - fpgaDMAReadControlRecord.FRCNT = 0; // block is TBD frames - will be populated later when known - fpgaDMAReadControlRecord.RDSIZE = ACCESS_8_BIT; // element size is 1 byte - fpgaDMAReadControlRecord.WRSIZE = ACCESS_8_BIT; // - fpgaDMAReadControlRecord.TTYPE = FRAME_TRANSFER; // transfer type is block transfer - fpgaDMAReadControlRecord.ADDMODERD = ADDR_INC1; // source addressing mode is post-increment - fpgaDMAReadControlRecord.ADDMODEWR = ADDR_FIXED; // dest. addressing mode is fixed - fpgaDMAReadControlRecord.AUTOINIT = AUTOINIT_OFF; // auto-init off - fpgaDMAReadControlRecord.ELSOFFSET = 0; // not used - fpgaDMAReadControlRecord.ELDOFFSET = 0; // not used - fpgaDMAReadControlRecord.FRSOFFSET = 0; // not used - fpgaDMAReadControlRecord.FRDOFFSET = 0; // not used - - // initialize FPGA DMA Read Response Control Record - fpgaDMAReadRespControlRecord.PORTASGN = 4; // port B (only choice per datasheet) - fpgaDMAReadRespControlRecord.SADD = (U32)(&(scilinREG->RD)); // source is SCI2 recv register - fpgaDMAReadRespControlRecord.DADD = (U32)fpgaReadResponseBuffer; // transfer destination address - fpgaDMAReadRespControlRecord.CHCTRL = 0; // no chaining - fpgaDMAReadRespControlRecord.ELCNT = 1; // frame is 1 element - fpgaDMAReadRespControlRecord.FRCNT = 0; // block is TBD frames - will be populated later when known - fpgaDMAReadRespControlRecord.RDSIZE = ACCESS_8_BIT; // element size is 1 byte - fpgaDMAReadRespControlRecord.WRSIZE = ACCESS_8_BIT; // - fpgaDMAReadRespControlRecord.TTYPE = FRAME_TRANSFER; // transfer type is block transfer - fpgaDMAReadRespControlRecord.ADDMODERD = ADDR_FIXED; // source addressing mode is fixed - fpgaDMAReadRespControlRecord.ADDMODEWR = ADDR_INC1; // dest. addressing mode is post-increment - fpgaDMAReadRespControlRecord.AUTOINIT = AUTOINIT_OFF; // auto-init off - fpgaDMAReadRespControlRecord.ELDOFFSET = 0; // not used - fpgaDMAReadRespControlRecord.ELSOFFSET = 0; // not used - fpgaDMAReadRespControlRecord.FRDOFFSET = 0; // not used - fpgaDMAReadRespControlRecord.FRSOFFSET = 0; // not used - - // there shouldn't be any data pending yet - consumeUnexpectedData(); -} - -/************************************************************************* - * @brief resetFPGACommFlags - * The resetFPGACommFlags function resets the various fpga comm flags and \n - * counters. - * @details - * Inputs : none - * Outputs : fpga comm flags & counters reset - * @param none - * @return none - *************************************************************************/ -static void resetFPGACommFlags( void ) -{ - fpgaWriteCommandResponseReceived = FALSE; - fpgaReadCommandResponseReceived = FALSE; - fpgaWriteCommandInProgress = FALSE; - fpgaReadCommandInProgress = FALSE; - fpgaBulkWriteAndReadInProgress = FALSE; - fpgaTransmitCounter = 0; - fpgaReceiptCounter = 0; -} - -/************************************************************************* - * @brief signalFPGAReceiptCompleted - * The signalFPGAReceiptCompleted function increments a counter to indicate \n - * that another DMA receipt from the FPGA has completed. - * @details - * Inputs : none - * Outputs : fpgaReceiptCounter - * @param none - * @return none - *************************************************************************/ -void signalFPGAReceiptCompleted( void ) -{ - fpgaReceiptCounter++; - // did FPGA Ack last command? - if ( TRUE == fpgaWriteCommandInProgress ) - { - fpgaWriteCommandInProgress = FALSE; - fpgaWriteCommandResponseReceived = TRUE; - } - else if ( TRUE == fpgaReadCommandInProgress ) - { - fpgaReadCommandInProgress = FALSE; - fpgaReadCommandResponseReceived = TRUE; - } - - // see if we want to follow up with a bulk read command - if ( TRUE == fpgaBulkWriteAndReadInProgress ) - { - // first receipt? - if ( 1 == fpgaReceiptCounter ) - { - fpgaBulkWriteAndReadInProgress = FALSE; - fpgaReadCommandInProgress = TRUE; - // TODO - initiate bulk read command - } - } -} - -/************************************************************************* - * @brief signalFPGATransmitCompleted - * The signalFPGATransmitCompleted function increments a counter to indicate \n - * that another DMA transmit to the FPGA has completed. - * @details - * Inputs : none - * Outputs : fpgaReceiptCounter - * @param none - * @return none - *************************************************************************/ -void signalFPGATransmitCompleted( void ) -{ - fpgaTransmitCounter++; -} - -/************************************************************************* - * @brief execFPGAIn - * The execFPGA function manages incoming data exchanges with the FPGA. - * @details - * Inputs : fpgaState - * Outputs : fpgaState - * @param none - * @return none - *************************************************************************/ -void execFPGAIn( void ) -{ - // FPGA incoming state machine - switch ( fpgaState ) - { - case FPGA_STATE_START: - fpgaState = FPGA_STATE_READ_HEADER; - break; - - case FPGA_STATE_RCV_HEADER: - fpgaState = handleFPGAReceiveHeaderState(); - break; - - - - case FPGA_STATE_RCV_ALL_SENSORS: - fpgaState = handleFPGAReceiveAllSensorsState(); - break; - - case FPGA_STATE_FAILED: - // do nothing - we'll be stuck here - break; - - default: - if ( fpgaState >= NUM_OF_FPGA_STATES ) - { - // TODO - s/w fault - } - else - { - // ok, some states handled in the outgoing state machine - } - break; - } - - // reset comm flags after processing incoming responses - resetFPGACommFlags(); -} - -/************************************************************************* - * @brief execFPGAOut - * The execFPGAOut function manages outgoing data exchanges with the FPGA. - * @details - * Inputs : fpgaState - * Outputs : fpgaState - * @param none - * @return none - *************************************************************************/ -void execFPGAOut( void ) -{ - // FPGA outgoing state machine - switch ( fpgaState ) - { - case FPGA_STATE_READ_HEADER: - fpgaState = handleFPGAReadHeaderState(); - break; - - - - case FPGA_STATE_WRITE_ALL_ACTUATORS: - fpgaState = handleFPGAWriteAllActuatorsState(); - break; - - case FPGA_STATE_FAILED: - // do nothing - we'll be stuck here - break; - - default: - if ( fpgaState >= NUM_OF_FPGA_STATES ) - { - // TODO - s/w fault - } - else - { - // ok, some states handled in the incoming state machine - } - break; - } -} - -/************************************************************************* - * @brief handleFPGAReadHeaderState - * The handleFPGAReadHeaderState function handles the FPGA state where \n - * the read header registers command is sent to the FPGA. - * @details - * Inputs : none - * Outputs : read command sent to FPGA - * @param none - * @return next FPGA state - *************************************************************************/ -static FPGA_STATE_T handleFPGAReadHeaderState( void ) -{ - FPGA_STATE_T result = FPGA_STATE_RCV_HEADER; - U16 crc; - - // 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[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 ); - // 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 ); - setupDMAForReadCmd( FPGA_READ_CMD_HDR_LEN + FPGA_CRC_LEN ); - startDMAReceiptOfReadResp(); - startDMAReadCmd(); - - return result; -} - -/************************************************************************* - * @brief handleFPGAReceiveHeaderState - * The handleFPGAReceiveHeaderState function handles the FPGA state \n - * where the header registers read response should be ready to take in. - * @details - * Inputs : none - * Outputs : header register values updated - * @param none - * @return next FPGA state - *************************************************************************/ -static FPGA_STATE_T handleFPGAReceiveHeaderState( void ) -{ - FPGA_STATE_T result = FPGA_STATE_READ_HEADER; - - // did we get an FPGA response? - if ( TRUE == fpgaReadCommandResponseReceived ) - { - // did FPGA Ack the read command? - if ( fpgaReadResponseBuffer[0] == FPGA_READ_CMD_ACK ) - { - // does the FPGA response CRC check out? - if ( 1 ) // TODO - check response CRC - { // capture the read values - memcpy( &fpgaHeader, &fpgaReadResponseBuffer[1], sizeof(FPGA_HEADER_T) ); - result = FPGA_STATE_WRITE_ALL_ACTUATORS; - } - } - } - else // - { - - } - - // shouldn't be any data received at this time - consumeUnexpectedData(); - - return result; -} - -/************************************************************************* - * @brief handleFPGAWriteAllActuatorsState - * The handleFPGAWriteAllActuatorsState function handles the FPGA state \n - * where the bulk write command is sent to the FPGA. - * @details - * Inputs : actuator set points - * Outputs : actuator set points sent to FPGA - * @param none - * @return next FPGA state - *************************************************************************/ -static FPGA_STATE_T handleFPGAWriteAllActuatorsState( void ) -{ - FPGA_STATE_T result = FPGA_STATE_RCV_ALL_SENSORS; - U16 crc; - - // 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] = 0x02; // 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) - // 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[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 ); - // 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 - setupDMAForWriteResp( FPGA_WRITE_RSP_HDR_LEN ); - // prep DMA for sending the bulk read cmd and receiving its response - setupDMAForReadCmd( FPGA_READ_CMD_HDR_LEN + FPGA_CRC_LEN ); - setupDMAForReadResp( FPGA_READ_RSP_HDR_LEN + sizeof(FPGA_SENSORS_T) + FPGA_CRC_LEN ); - // set fpga comm flags for bulk write cmd and follow-up bulk read command - fpgaWriteCommandInProgress = TRUE; - fpgaBulkWriteAndReadInProgress = TRUE; - // initiate bulk write command and it's receipt - read will follow - startDMAReceiptOfWriteResp(); - startDMAWriteCmd(); - - return result; -} - -/************************************************************************* - * @brief handleFPGAReceiveAllSensorsState - * The handleFPGAReceiveAllSensorsState function handles the FPGA state \n - * where the bulk read response should be ready to parse. - * @details - * Inputs : none - * Outputs : sensor values updated - * @param none - * @return next FPGA state - *************************************************************************/ -static FPGA_STATE_T handleFPGAReceiveAllSensorsState( void ) -{ - FPGA_STATE_T result = FPGA_STATE_WRITE_ALL_ACTUATORS; - - // check bulk write command success - if ( ( FALSE == fpgaWriteCommandResponseReceived ) || ( fpgaWriteResponseBuffer[0] != FPGA_WRITE_CMD_ACK ) ) - { - // TODO - ??? - } - - // if bulk read command is ACK'd, collect the readings - if ( TRUE == fpgaReadCommandResponseReceived ) - { - // did FPGA Ack the read command? - if ( fpgaReadResponseBuffer[0] == FPGA_READ_CMD_ACK ) - { - // does the FPGA response CRC check out? - if ( 1 ) // TODO - check response CRC - { // capture the read values - memcpy( &fpgaSensorReadings, fpgaReadResponseBuffer, sizeof(FPGA_SENSORS_T) ); - result = FPGA_STATE_WRITE_ALL_ACTUATORS; - } - } - } - else - { - // TODO - ??? - } - - // shouldn't be any data received at this time - consumeUnexpectedData(); - - return result; -} - -/************************************************************************* - * @brief execFPGATest - * The execFPGATest function executes the FPGA self-test. \n - * @details - * Inputs : fpgaHeader - * Outputs : none - * @param none - * @return passed, or failed - *************************************************************************/ -SELF_TEST_STATUS_T execFPGATest( void ) -{ - SELF_TEST_STATUS_T result = SELF_TEST_STATUS_FAILED; - - // check FPGA reported correct ID - if ( FPGA_EXPECTED_ID == fpgaHeader.fpgaId ) - { - result = SELF_TEST_STATUS_PASSED; - } - - return result; -} - -/************************************************************************* - * @brief setupDMAForWriteCmd - * The setupDMAForWriteCmd function sets the byte count for the next DMA \n - * write command to the FPGA. - * @details - * Inputs : none - * Outputs : # of bytes for next FPGA write command is set - * @param bytes2Transmit : # of bytes to be transmitted via DMA to the FPGA. - * @return none - *************************************************************************/ -static void setupDMAForWriteCmd( U32 bytes2Transmit ) -{ - fpgaDMAWriteControlRecord.FRCNT = bytes2Transmit; -} - -/************************************************************************* - * @brief startDMAWriteCmd - * The startDMAWriteCmd function initiates the DMA transmit for the next \n - * DMA write command to the FPGA. - * @details - * Inputs : none - * Outputs : DMA write command to FPGA is initiated - * @param none - * @return none - *************************************************************************/ -static void startDMAWriteCmd( void ) -{ - dmaSetCtrlPacket( DMA_CH2, fpgaDMAWriteControlRecord ); - dmaSetChEnable( DMA_CH2, DMA_HW ); - setSCI2DMATransmitInterrupt(); -} - -/************************************************************************* - * @brief setupDMAForWriteResp - * The setupDMAForWriteResp function sets the expected byte count for the \n - * next DMA write command response from the FPGA. - * @details - * Inputs : none - * Outputs : # of expected bytes for next FPGA write command response is set - * @param bytes2Receive : # of bytes expected to be transmitted via DMA from the FPGA. - * @return none - *************************************************************************/ -static void setupDMAForWriteResp( U32 bytes2Receive ) -{ - fpgaDMAWriteRespControlRecord.FRCNT = bytes2Receive; -} - -/************************************************************************* - * @brief startDMAReceiptOfWriteResp - * The startDMAReceiptOfWriteResp function initiates readiness of the DMA \n - * receiver for the next DMA write command response from the FPGA. - * @details - * Inputs : none - * Outputs : DMA write command response is ready to be received from the FPGA - * @param none - * @return none - *************************************************************************/ -static void startDMAReceiptOfWriteResp( void ) -{ - dmaSetCtrlPacket( DMA_CH0, fpgaDMAWriteRespControlRecord ); - dmaSetChEnable( DMA_CH0, DMA_HW ); - setSCI2DMAReceiveInterrupt(); -} - -/************************************************************************* - * @brief setupDMAForReadCmd - * The setupDMAForReadCmd function sets the byte count for the next DMA \n - * read command to the FPGA. - * @details - * Inputs : none - * Outputs : # of bytes for next FPGA read command is set - * @param bytes2Transmit : # of bytes to be transmitted via DMA to the FPGA. - * @return none - *************************************************************************/ -static void setupDMAForReadCmd( U32 bytes2Transmit ) -{ - fpgaDMAReadControlRecord.FRCNT = bytes2Transmit; -} - -/************************************************************************* - * @brief startDMAReadCmd - * The startDMAReadCmd function initiates the DMA transmit for the next \n - * DMA read command to the FPGA. - * @details - * Inputs : none - * Outputs : DMA read command to FPGA is initiated - * @param none - * @return none - *************************************************************************/ -static void startDMAReadCmd( void ) -{ - dmaSetCtrlPacket( DMA_CH2, fpgaDMAReadControlRecord ); - dmaSetChEnable( DMA_CH2, DMA_HW ); - setSCI2DMATransmitInterrupt(); -} - -/************************************************************************* - * @brief setupDMAForReadResp - * The setupDMAForReadResp function sets the expected byte count for the \n - * next DMA read command response from the FPGA. - * @details - * Inputs : none - * Outputs : # of expected bytes for next FPGA read command response is set - * @param bytes2Receive : # of expected bytes to be transmitted via DMA from the FPGA. - * @return none - *************************************************************************/ -static void setupDMAForReadResp( U32 bytes2Receive ) -{ - fpgaDMAReadRespControlRecord.FRCNT = bytes2Receive; -} - -/************************************************************************* - * @brief startDMAReceiptOfReadResp - * The startDMAReceiptOfReadResp function initiates readiness of the DMA \n - * receiver for the next DMA read command response from the FPGA. - * @details - * Inputs : none - * Outputs : DMA read command response is ready to be received from the FPGA - * @param none - * @return none - *************************************************************************/ -static void startDMAReceiptOfReadResp( void ) -{ - dmaSetCtrlPacket( DMA_CH0, fpgaDMAReadRespControlRecord ); - dmaSetChEnable( DMA_CH0, DMA_HW ); - setSCI2DMAReceiveInterrupt(); -} - -/************************************************************************* - * @brief getFPGAId - * The getFPGAId function gets the version read from the Id register \n - * of the FPGA. - * @details - * Inputs : fpgaHeader - * Outputs : none - * @param none - * @return Id - *************************************************************************/ -U08 getFPGAId( void ) -{ - return fpgaHeader.fpgaId; -} - -/************************************************************************* - * @brief getFPGARev - * The getFPGARev function gets the revision read from the Rev register \n - * of the FPGA. - * @details - * Inputs : fpgaHeader - * Outputs : none - * @param none - * @return Revision - *************************************************************************/ -U08 getFPGARev( void ) -{ - return fpgaHeader.fpgaRev; -} - -/************************************************************************* - * @brief getFPGADiag - * The getFPGADiag function gets the version read from the diagnostic register \n - * of the FPGA. - * @details - * Inputs : fpgaHeader - * Outputs : none - * @param none - * @return fpgaDiag - *************************************************************************/ -U08 getFPGADiag( void ) -{ - return fpgaHeader.fpgaDiag; -} - -/************************************************************************* - * @brief getFPGAStatus - * The getFPGAStatus function gets the version read from the diagnostic register \n - * of the FPGA. - * @details - * Inputs : fpgaHeader - * Outputs : none - * @param none - * @return fpgaDiag - *************************************************************************/ -U16 getFPGAStatus( void ) -{ - return fpgaHeader.fpgaStatus; -} - -/************************************************************************* - * @brief getFPGADiag - * The getFPGADiag function gets the version read from the diagnostic register \n - * of the FPGA. - * @details - * Inputs : fpgaHeader - * Outputs : none - * @param none - * @return fpgaDiag - *************************************************************************/ -void setFPGAControl( U16 ctrl ) -{ - fpgaHeader.fpgaControl = ctrl; -} - -/************************************************************************* - * @brief consumeUnexpectedData - * 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 ( 0 != sciIsRxReady( scilinREG ) ) - { - sciReceiveByte( scilinREG ); - } -} - + +/************************************************************************** +* +* Copyright (c) 2019-2022 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file FPGA.c +* +* @author (last) Dara Navaei +* @date (last) 24-May-2022 +* +* @author (original) Dara Navaei +* @date (original) 05-Nov-2019 +* +***************************************************************************/ + +#include // for memset(), memcpy() + +#include "gio.h" +#include "sci.h" +#include "sys_dma.h" + +#include "Comm.h" +#include "Compatible.h" +#include "FPGA.h" +#include "NVDataMgmt.h" +#include "OperationModes.h" +#include "PersistentAlarm.h" +#include "SystemCommMessages.h" +#include "Utilities.h" + +/** + * @addtogroup FPGA + * @{ + */ + +// ********** private definitions ********** + +/// List of FPGA states. +typedef enum FPGA_States +{ + FPGA_STATE_START = 0, ///< FPGA start state + FPGA_STATE_READ_HEADER, ///< FPGA read header state + FPGA_STATE_RCV_HEADER, ///< FPGA receive header state + FPGA_STATE_WRITE_ALL_ACTUATORS, ///< FPGA write all actuators state + FPGA_STATE_RCV_ALL_SENSORS, ///< FPGA receive all sensors state + FPGA_STATE_FAILED, ///< FPGA failed state + NUM_OF_FPGA_STATES ///< Number of FPGA states +} FPGA_STATE_T; + +#define FPGA_PAGE_SIZE 256 ///< FPGA page size. +#define FPGA_EXPECTED_ID 0x61 ///< FPGA expected ID. + +#define FPGA_HEADER_START_ADDR 0x0000 ///< FPGA header start address. +#define FPGA_BULK_READ_START_ADDR 0x0100 ///< FPGA bulk read start address. +#define FPGA_BULK_WRITE_START_ADDR 0x000C ///< FPGA bulk write start address. + +#define FPGA_WRITE_CMD_BUFFER_LEN ( FPGA_PAGE_SIZE + 8 ) ///< FPGA write command buffer length. +#define FPGA_READ_CMD_BUFFER_LEN 8 ///< FPGA read command buffer length. +#define FPGA_WRITE_RSP_BUFFER_LEN 8 ///< FPGA write response buffer length. +#define FPGA_READ_RSP_BUFFER_LEN ( FPGA_PAGE_SIZE + 8 ) ///< FPGA read response buffer length. + +#define FPGA_WRITE_CMD_CODE 0x55 ///< FPGA write command code. +#define FPGA_READ_CMD_CODE 0x5A ///< FPGA read command code. +#define FPGA_WRITE_CMD_ACK 0xA5 ///< FPGA write command ack. +#define FPGA_READ_CMD_ACK 0xAA ///< FPGA read command ack. +#define FPGA_CMD_NAK 0xEE ///< FPGA command nack. + +#define FPGA_CRC_LEN 2 ///< FPGA crc length. +#define FPGA_WRITE_CMD_HDR_LEN 4 ///< FPGA write command header length. +#define FPGA_READ_CMD_HDR_LEN 4 ///< FPGA read command header length. +#define FPGA_WRITE_RSP_HDR_LEN 3 ///< FPGA write response header length. +#define FPGA_READ_RSP_HDR_LEN 3 ///< FPGA read response header length. + +#define SCI2_RECEIVE_DMA_REQUEST 28 ///< SCI2 receive DMA request +#define SCI2_TRANSMIT_DMA_REQUEST 29 ///< SCI2 transmit DMA request + +#define MAX_COMM_ERROR_RETRIES 5 ///< Maximum number of communication error retries + +#define DRAIN_PUMP_DAC_SHIFT_BITS 4 ///< Drain pump DAC shift bits. + +#define FPGA_FLUIDLEAK_STATE_MASK 0x0004 ///< Bit mask for fluid leak detector. + +#define CONCENTRATE_CAP_SWITCH_MASK 0x10 ///< Concentrate cap switch bit mask. +#define DIALYSATE_CAP_SWITCH_MASK 0x20 ///< Dialysate cap switch bit mask. +#define FPGA_THD_CONTROL_COMMAND 0X01 ///< FPGA THd control command. +#define FPGA_POWER_OUT_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< FPGA power out timeout in milliseconds. +#define FPGA_GPIO_POWER_STATUS_PIN 7 ///< FPGA GPIO power status pin. +#define FPGA_READ_V3_START_BYTE_NUM 256 ///< FPGA V3 read sensors start byte number. +#define FPGA_READ_V3_END_BYTE_NUM 420 ///< FPGA V3 read sensors end byte number. +/// FPGA size of V3 read bytes. +#define FPGA_SIZE_OF_V3_READ_BYTES ( FPGA_READ_V3_END_BYTE_NUM - FPGA_READ_V3_START_BYTE_NUM ) + +// FPGA header struct. +#pragma pack(push,1) +typedef struct +{ + U08 fpgaId; ///< Reg 0. FPGA ID code. Checked against expected value at power up to verify basic FPGA communication and operation + U08 fpgaRevMinor; ///< Reg 1. FPGA revision (minor) being reported + U08 fpgaRevMajor; ///< Reg 2. FPGA revision (major) being reported + U08 fpgaRevLab; ///< Reg 3. FPGA revision (lab) being reported +} FPGA_HEADER_T; // read only on FPGA + +/// FPGA sensors' readings struct. +typedef struct +{ + 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 + + 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 + + U32 fpgaCD1Temp; ///< Reg 280. ADC RTD channel 0 - conductivity sensor 1 temperature + U32 fpgaCD2Temp; ///< Reg 284. ADC RTD channel 1 - conductivity sensor 2 temperature + + U32 fpgaTPoTemp; ///< Reg 288. ADC RTD channel 2 - conductivity sensor CPo temperature + U32 fpgaTPiTemp; ///< Reg 292. ADC RTD channel 3 - conductivity sensor CPi temperature + U32 fpgaRTDTemp; ///< Reg 296. ADC RTD channel 4 - internal temperature + + U32 fpgaTRo; ///< Reg 300. ADC TRo channel 0 - temperature + U32 fpgaTRoTemp; ///< Reg 304. ADC TRo 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. CPo conductivity sensor value + U32 fpgaCPi; ///< Reg 320. CPi conductivity sensor value + + 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. Error count for processor communications + U08 fpgaIOErrorCntPC; ///< Reg 353. Error count for PC communications + U08 fpgaADC1ReadCnt; ///< Reg 354. + U08 fpgaADC1ErrorCnt; ///< Reg 355. + U08 fpgaADC2ReadCnt; ///< Reg 356. + U08 fpgaADC2ErrorCnt; ///< Reg 357. + U08 fpgaRTDReadCnt; ///< Reg 358. Temperature sensors read count + U08 fpgaRTDErrorCnt; ///< Reg 359. Temperature sensors error count + U08 fpgaTRoReadCnt; ///< Reg 360. Redundant outlet temperature sensor read count + U08 fpgaTRoErrorCnt; ///< Reg 361. Redundant outlet temperature sensor error count + U08 fpgaTDiReadCnt; ///< Reg 362. Dialysate inlet temperature sensor read count + U08 fpgaTDiErrorCnt; ///< Reg 363. Dialysate inlet temperature sensor error count + U08 fpgaPrimaryHeaterFlags; ///< Reg 364. Primary heater flags + U08 fpgaPrimaryHeaterReadCnt; ///< Reg 365. Primary heater read count + U08 fpgaTrimmerHeaterFlags; ///< Reg 366. Trimmer heater flags + U08 fpgaTrimmerHeaterReadCnt; ///< Reg 367. Trimmer heater read count + + U08 fpgaCPoFault; ///< Reg 368. CPo conductivity sensor fault + U08 fpgaCPoReadCnt; ///< Reg 369. CPo conductivity sensor read count + U08 fpgaCPoErrorCnt; ///< Reg 370. CPo conductivity sensor error count + U08 fpgaCPiFault; ///< Reg 371. CPi conductivity sensor fault + U08 fpgaCPiReadCnt; ///< Reg 372. CPi conductivity sensor read count + U08 fpgaCPiErrorCnt; ///< Reg 373. CPi conductivity sensor error count + U08 fpgaCP1CP2Fault; ///< Reg 374. Concentrate pump fault register for CP1 and CP2 + U08 fpgaReserved1; ///< Reg 375. Reserved + + U16 fpgaValveStates; ///< Reg 376. Valves states + U16 fpgaFanIn1Pulse; ///< Reg 378. Fan inlet 1 pulse time in 2.5 us resolution + U16 fpgaFanOut1Pulse; ///< Reg 380. Fan outlet 1 pulse time in 2.5 us resolution + + U08 fpgaCD1CD2EmstatOutByte; ///< Reg 382. Emstat output FIFO - data from the Emstat device + U08 fpgaCD1CD2EmstatRxErrorCount; ///< Reg 383. Number of receive errors since power-up + U16 fpgaCD1CD2EmstatTxFifoCount; ///< Reg 384. Number of bytes in the Emstat Tx FIFO buffer + U16 fpgaCD1CD2EmstatRxFifoCount; ///< Reg 386. Number of bytes in the Emstat Rx FIFO buffer + U16 fpgaCP1HallSense; ///< Reg 388. Concentrate pump CP1 hall sensor pulse width + U16 fpgaCP2HallSense; ///< Reg 390. Concentrate pump CP2 hall sensor pulse width + + U08 fpgaGPIO; ///< Reg 392. FGPA GPIO register + U08 fpgaDummyByte2Addr; ///< Reg 393. Dummy byte address to maintain an even addressing scheme + U16 fpgaADCTemp; ///< Reg 394. Internal FPGA die temperature ADC + + U16 fpgaFanIn2Pulse; ///< Reg 396. Fan inlet 2 pulse time in 2.5 resolution + U16 fpgaFanOut2Pulse; ///< Reg 398. Fan outlet 2 pulse time in 2.5 resolution + U16 fpgaFanIn3Pulse; ///< Reg 400. Fan inlet 3 pulse time in 2.5 resolution + U16 fpgaFanOut3Pulse; ///< Reg 402. Fan outlet 3 pulse time in 2.5 resolution + U16 fpgaTimerCountMS; ///< Reg 404. Internal FPGA timer count in milliseconds + U16 fpgaADCVccInt; ///< Reg 406. Internal FPGA Vcc Voltage. + U16 fpgaADCVccAux; ///< Reg 408. Internal FPGA Vcc auxiliary voltage + U16 fpgaADCVPVN; ///< Reg 410. Internal FPGA VPVN voltage + U16 fpgaDialysateFlowRate; ///< Reg 412. Dialysate flow rate measurement + U16 fpgaROFlowSensorEdgeCount; ///< Reg 414. RO flow sensor edge count + U16 fpgaDialysateFlowSensorEdgeCount; ///< Reg 416. Dialysate flow sensor edge count + + // DVT changes + U16 fpgaDrainPumpSpeedFeedback; ///< Reg 418. Drain pump speed feedback + U16 fpgaDrainPumpCurrentFeedback; ///< Reg 420. Drain pump current feedback + U08 fpgaBaroReadCount; ///< Reg 422. Barometric sensor read count + U08 fpgaBaroErrorCount; ///< Reg 423. Barometric sensor error count + U16 fpgaBaroManufacInfo; ///< Reg 424. Barometric sensor manufacturing information + U16 fpgaBaroPROMCoeff1; ///< Reg 426. Barometric sensor PROM coefficient 1 + U16 fpgaBaroPROMCoeff2; ///< Reg 428. Barometric sensor PROM coefficient 2 + U16 fpgaBaroPROMCoeff3; ///< Reg 430. Barometric sensor PROM coefficient 3 + U16 fpgaBaroPROMCoeff4; ///< Reg 432. Barometric sensor PROM coefficient 4 + U16 fpgaBaroPROMCoeff5; ///< Reg 434. Barometric sensor PROM coefficient 5 + U16 fpgaBaroPROMCoeff6; ///< Reg 436. Barometric sensor PROM coefficient 6 + U16 fpgaBaroPROMCRC; ///< Reg 438. Barometric sensor PROM CRC + U32 fpgaBaroPressure; ///< Reg 440. Barometric sensor pressure value + U32 fpgaBaroTemperature; ///< Reg 444. Barometric sensor temperature sensor + U08 fpgaTHdRTDReadCount; ///< Reg 448. THD RTD read count + U08 fpgaTHdRTDErrorCount; ///< Reg 449. THD RTD error count + U32 fpgaTHdTemp; ///< Reg 450. THD channel 0 read data - temperature sensor + U32 fpgaTHdInternalTemp; ///< Reg 454. THD channel 1 read data - ADC internal temperature sensor + U08 fpgaCPiCPoEmstatOutByte; ///< Reg 458. CPi/CPo Emstat out byte + U08 fpgaCPiCPoEmstatRxErrCount; ///< Reg 459. CPi/CPo Emstat Rx error count + U16 fpgaCPiCPoEmstatTxFIFOCount; ///< Reg 460. CPi/CPo Emstat Tx FIFO count + U16 fpgaCPiCPoEmstatRxFIFOCount; ///< Reg 462. CPi/CPo Emstat Rx FIFO count + U16 fpgaHeaterGateADC; ///< Reg 464. Heater gate ADC + U16 fpgaHeaterGNDADC; ///< Reg 466. Heater ground ADC + U08 fpgaHeater1ADCReadCount; ///< Reg 468. Heater 1 ADC read count + U08 fpgaHeater1ADCErrorCount; ///< Reg 469. Heater 1 ADC error count + U16 fpgaPowerSupply2; ///< Reg 470. Power supply 2 count + U16 fpgaOnBoardThermistor; ///< Reg 472. Onboard thermistor + U16 fpgaCompatibilityRev; ///< Reg 474. Compatibility revision +} DG_FPGA_SENSORS_T; + +typedef struct +{ + U08 fpgaCPoControlReg; ///< Reg 12. CPo control register + U08 fpgaCPiControlReg; ///< Reg 13. CPi control register + U16 fpgaCPoProbeType; ///< Reg 14. CPo probe type + U16 fpgaCPiProbeType; ///< Reg 16. CPi probe type + U16 fpgaDrainPumpSetSpeed; ///< Reg 18. Drain pump control register + U16 fpgaValveStates; ///< Reg 20. Valve control register + U08 fpgaAcclCmd; ///< Reg 22. Accelerometer interface command register + U08 fpgaCP1Control; ///< Reg 23. Concentrate pump CP1 control register + U16 fpgaCP1StepSpeed; ///< Reg 24. Concentrate pump CP1 step speed register + U16 fpgaCP2StepSpeed; ///< Reg 26. Concentrate pump CP2 step speed register + U08 fpgaCP2Control; ///< Reg 28. Concentrate pump CP2 control register + U08 fpgaEmstatControl; ///< Reg 29. Emstat conductivity sensor control register + U16 fpgaVRfPWMLow; ///< Reg 30. VRf PWM low + U16 fpgaVRfPWMPeriod; ///< Reg 32. VRf PWM period + U16 fpgaVRiPWMLow; ///< Reg 34. VRi PWM low + U16 fpgaVRiPWMPeriod; ///< Reg 36. VRi PWM period + U16 fpgaVRdPWMLow; ///< Reg 38. VRd PWM low + U16 fpgaVRdPWMPeriod; ///< Reg 40. VRD PWM period + U16 fpgaVRoPWMLow; ///< Reg 42. VRo PWM low + U16 fpgaVRoPWMPeriod; ///< Reg 44. VRo PWM period + U16 fpgaVPoPWMLow; ///< Reg 46. VPo PWM low + U16 fpgaVPoPWMPeriod; ///< Reg 48. VPo PWM period + U16 fpgaVBfPWMLow; ///< Reg 50. VBf PWM low + U16 fpgaVBFPWMPeriod; ///< Reg 52. VBf PWM period + U16 fpgaVRcPWMLow; ///< Reg 54. VRc PWM low + U16 fpgaVRcPWMPeriod; ///< Reg 56. VRc PWM period + U16 fpgaVDrPWMLow; ///< Reg 58. VDr PWM Low + U16 fpgaVDrPWMPeriod; ///< Reg 60. VDr PWM period + U16 fpgaVPiPWMLow; ///< Reg 62. VPi PWM low + U16 fpgaVPiPWMPeriod; ///< Reg 64. VPi PWM period + U16 fpgaVSPPWMLow; ///< Reg 66. VSP PWM low + U16 fpgaVSPPWMPeriod; ///< Reg 68. VSP PWM period + U16 fpgaVRd1PWMLow; ///< Reg 70. VRd1 PWM low + U16 fpgaVRd1PWMPeriod; ///< Reg 72. VRd1 PWM period + U16 fpgaVRd2PWMLow; ///< Reg 74. VRd2 PWM low + U16 fpgaVRd2PWMPeriod; ///< Reg 76. VRd2 PWM period + U16 fpgaVPdPWMLow; ///< Reg 78. VPd PWM low + U16 fpgaVPdPWMPeriod; ///< Reg 80. VPd PWM period + U16 fpgaVSOLPWMLow; ///< Reg 82. VSOL PWM low + U16 fpgaVSOLPWMPeriod; ///< Reg 84. VSOL PWM period + U16 fpgaVRfPWMPullin; ///< Reg 86. VRf PWM pull in + U16 fpgaVRiPWMPullin; ///< Reg 88. VRi PWM pull in + U16 fpgaVRdPWMPullin; ///< Reg 90. VRd PWM pull in + U16 fpgaVRoPWMPullin; ///< Reg 92. VRo PWM pull in + U16 fpgaVPoPWMPullin; ///< Reg 94. VPo PWM pull in + U16 fpgaVBfPWMPullin; ///< Reg 96. VBf PWM pull in + U16 fpgaVRcPWMPullin; ///< Reg 98. VRc PWM pull in + U16 fpgaVDrPWMPullin; ///< Reg 100. VDr PWM pull in + U16 fpgaVPiPWMPullin; ///< Reg 102. VPi PWM pull in + U16 fpgaVSPPWMPullin; ///< Reg 104. VSP PWM pull in + U16 fpgaVRd1PWMPullin; ///< Reg 106. VRd1 PWM pull in + U16 fpgaVRd2PWMPullin; ///< Reg 108. VRd2 PWM pull in + U16 fpgaVPdPWMPullin; ///< Reg 110. VPd PWM pull in + U16 fpgaVSPR2PWMPullin; ///< Reg 112. VSPR2 PWM pull in + U16 fpgaValvePWMEnable; ///< Reg 114. valve PWM enable + + // DVT Registers + U08 fpgaTHdControlReg; ///< Reg 116. THd control register + U08 fpgaCPiCPoEmstatControl; ///< Reg 117. CPi/CPo Emstat control + U16 fpgaDACRegBIn; ///< Reg 118. Debug DAC channel B output + U16 fpgaDACRegCIn; ///< Reg 120. Debug DAC channel C output + U16 fpgaDACRegDIn; ///< Reg 122. Debug DAC channel D output + U16 fpgaDACRegEIn; ///< Reg 124. Debug DAC channel E output + U16 fpgaDACRegFIn; ///< Reg 126. Debug DAC channel F output + U16 fpgaDACRegGIn; ///< Reg 128. Debug DAC channel G output + U16 fpgaDACRegHIn; ///< Reg 130. Debug DAC channel H output + U08 fgpaNewCP2Control; ///< Reg 132. Concentrate pump 2 control + U08 fpgaNewCP1Control; ///< Reg 133. Concentrate pump 1 control +} FPGA_ACTUATORS_T; +#pragma pack(pop) + +// ********** private data ********** + +static FPGA_STATE_T fpgaState = FPGA_STATE_START; ///< FPGA current state. +static U32 fpgaCommRetryCount = 0; ///< FPGA communication retry count. +static U32 fpgaReceiptCounter = 0; ///< FPGA receipt completed counter. +static U32 fpgaTransmitCounter = 0; ///< FPGA transmit completed counter. +static BOOL fpgaWriteCommandInProgress = FALSE; ///< Flag indicates whether a FPGA write command is in progress. +static BOOL fpgaReadCommandInProgress = FALSE; ///< Flag indicates whether a FPGA read command is in progress. +static BOOL fpgaBulkWriteAndReadInProgress = FALSE; ///< Flag indicates whether a FPGA bulk write and read is in progress. +static BOOL fpgaWriteCommandResponseReceived = FALSE; ///< Flag indicates whether a FPGA write command response has been received. +static BOOL fpgaReadCommandResponseReceived = FALSE; ///< Flag indicates whether a FPGA read command response has been received. + +// FPGA comm buffers +static U08 fpgaWriteCmdBuffer[ FPGA_WRITE_CMD_BUFFER_LEN ]; ///< FPGA write command buffer. +static U08 fpgaReadCmdBuffer[ FPGA_READ_CMD_BUFFER_LEN ]; ///< FPGA read command buffer. +static U08 fpgaWriteResponseBuffer[ FPGA_WRITE_RSP_BUFFER_LEN ]; ///< FPGA write response buffer. +static U08 fpgaReadResponseBuffer[ FPGA_READ_RSP_BUFFER_LEN ]; ///< FPGA read response buffer. + +// DMA control records +static g_dmaCTRL fpgaDMAWriteControlRecord; ///< FPGA DMA write control record. +static g_dmaCTRL fpgaDMAWriteRespControlRecord; ///< FPGA DMA write response control record. +static g_dmaCTRL fpgaDMAReadControlRecord; ///< FPGA DMA read control record. +static g_dmaCTRL fpgaDMAReadRespControlRecord; ///< FPGA DMA read response control record. + +// FPGA data +static FPGA_HEADER_T fpgaHeader; ///< FPGA header structure. +static DG_FPGA_SENSORS_T fpgaSensorReadings; ///< DG FPGA sensors structure. +static FPGA_ACTUATORS_T fpgaActuatorSetPoints; ///< FPGA actuator set points structure. +static U08 fpgaReadByteSize; ///< FPGA read byte size. + +// ********** private function prototypes ********** + +static FPGA_STATE_T handleFPGAReadHeaderState( void ); +static FPGA_STATE_T handleFPGAReceiveHeaderState( void ); +static FPGA_STATE_T handleFPGAWriteAllActuatorsState( void ); +static FPGA_STATE_T handleFPGAReceiveAllSensorsState( void ); + +static void resetFPGACommFlags( void ); +static void setupDMAForWriteCmd( U32 bytes2Transmit ); +static void startDMAWriteCmd( void ); +static void setupDMAForWriteResp( U32 bytes2Receive ); +static void startDMAReceiptOfWriteResp( void ); +static void setupDMAForReadCmd( U32 bytes2Transmit ); +static void startDMAReadCmd( void ); +static void setupDMAForReadResp( U32 bytes2Receive ); +static void startDMAReceiptOfReadResp( void ); + +static void consumeUnexpectedData( void ); +static void monitorFPGAPowerStatus( void ); + +/*********************************************************************//** + * @brief + * The initFPGA function initializes the FPGA module. + * @details Inputs: none + * @details Outputs: FPGA module initialized. + * @return none + *************************************************************************/ +void initFPGA( void ) +{ + // initialize fpga data structures + memset( &fpgaHeader, 0, sizeof(FPGA_HEADER_T) ); + memset( &fpgaSensorReadings, 0, sizeof(DG_FPGA_SENSORS_T) ); + memset( &fpgaActuatorSetPoints, 0, sizeof(FPGA_ACTUATORS_T) ); + + // Set the THd control register to 0x1 to make sure its ADC is running + fpgaActuatorSetPoints.fpgaTHdControlReg = FPGA_THD_CONTROL_COMMAND; + + // 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 ); + memset( &fpgaWriteResponseBuffer, 0, FPGA_WRITE_RSP_BUFFER_LEN ); + memset( &fpgaReadResponseBuffer, 0, FPGA_READ_RSP_BUFFER_LEN ); + + // Assume the read byte size is set for V3 since V3 contains less number of bytes. + // Once the V3 or DVT build switch is set resize the number of bytes to read. + fpgaReadByteSize = FPGA_SIZE_OF_V3_READ_BYTES; + + // enable interrupt notifications for FPGA serial port + sciEnableNotification( scilinREG, SCI_OE_INT | SCI_FE_INT ); + + // assign DMA channels to h/w DMA requests + dmaReqAssign( DMA_CH0, SCI2_RECEIVE_DMA_REQUEST ); + dmaReqAssign( DMA_CH2, SCI2_TRANSMIT_DMA_REQUEST ); + // set DMA channel priorities + dmaSetPriority( DMA_CH0, HIGHPRIORITY ); + dmaSetPriority( DMA_CH2, LOWPRIORITY ); + // Enable DMA block transfer complete interrupts + dmaEnableInterrupt( DMA_CH0, BTC ); + dmaEnableInterrupt( DMA_CH2, BTC ); + + // initialize FPGA DMA Write Control Record + fpgaDMAWriteControlRecord.PORTASGN = 4; // port B (only choice per datasheet) + fpgaDMAWriteControlRecord.SADD = (U32)fpgaWriteCmdBuffer; // transfer source address + fpgaDMAWriteControlRecord.DADD = (U32)(&(scilinREG->TD)); // dest. is SCI2 xmit register + fpgaDMAWriteControlRecord.CHCTRL = 0; // no chaining + fpgaDMAWriteControlRecord.ELCNT = 1; // frame is 1 element + fpgaDMAWriteControlRecord.FRCNT = 0; // block is TBD frames - will be populated later when known + fpgaDMAWriteControlRecord.RDSIZE = ACCESS_8_BIT; // element size is 1 byte + fpgaDMAWriteControlRecord.WRSIZE = ACCESS_8_BIT; // + fpgaDMAWriteControlRecord.TTYPE = FRAME_TRANSFER; // transfer type is block transfer + fpgaDMAWriteControlRecord.ADDMODERD = ADDR_INC1; // source addressing mode is post-increment + fpgaDMAWriteControlRecord.ADDMODEWR = ADDR_FIXED; // dest. addressing mode is fixed + fpgaDMAWriteControlRecord.AUTOINIT = AUTOINIT_OFF; // auto-init off + fpgaDMAWriteControlRecord.ELSOFFSET = 0; // not used + fpgaDMAWriteControlRecord.ELDOFFSET = 0; // not used + fpgaDMAWriteControlRecord.FRSOFFSET = 0; // not used + fpgaDMAWriteControlRecord.FRDOFFSET = 0; // not used + + // initialize FPGA DMA Write Response Control Record + fpgaDMAWriteRespControlRecord.PORTASGN = 4; // port B (only choice per datasheet) + fpgaDMAWriteRespControlRecord.SADD = (U32)(&(scilinREG->RD));// source is SCI2 recv register + fpgaDMAWriteRespControlRecord.DADD = (U32)fpgaWriteResponseBuffer; // transfer destination address + fpgaDMAWriteRespControlRecord.CHCTRL = 0; // no chaining + fpgaDMAWriteRespControlRecord.ELCNT = 1; // frame is 1 element + fpgaDMAWriteRespControlRecord.FRCNT = 0; // block is TBD frames - will be populated later when known + fpgaDMAWriteRespControlRecord.RDSIZE = ACCESS_8_BIT; // element size is 1 byte + fpgaDMAWriteRespControlRecord.WRSIZE = ACCESS_8_BIT; // + fpgaDMAWriteRespControlRecord.TTYPE = FRAME_TRANSFER; // transfer type is block transfer + fpgaDMAWriteRespControlRecord.ADDMODERD = ADDR_FIXED; // source addressing mode is fixed + fpgaDMAWriteRespControlRecord.ADDMODEWR = ADDR_INC1; // dest. addressing mode is post-increment + fpgaDMAWriteRespControlRecord.AUTOINIT = AUTOINIT_OFF; // auto-init off + fpgaDMAWriteRespControlRecord.ELDOFFSET = 0; // not used + fpgaDMAWriteRespControlRecord.ELSOFFSET = 0; // not used + fpgaDMAWriteRespControlRecord.FRDOFFSET = 0; // not used + fpgaDMAWriteRespControlRecord.FRSOFFSET = 0; // not used + + // initialize FPGA DMA Read Control Record + fpgaDMAReadControlRecord.PORTASGN = 4; // port B (only choice per datasheet) + fpgaDMAReadControlRecord.SADD = (U32)fpgaReadCmdBuffer; // transfer source address + fpgaDMAReadControlRecord.DADD = (U32)(&(scilinREG->TD)); // dest. is SCI2 xmit register + fpgaDMAReadControlRecord.CHCTRL = 0; // no chaining + fpgaDMAReadControlRecord.ELCNT = 1; // frame is 1 element + fpgaDMAReadControlRecord.FRCNT = 0; // block is TBD frames - will be populated later when known + fpgaDMAReadControlRecord.RDSIZE = ACCESS_8_BIT; // element size is 1 byte + fpgaDMAReadControlRecord.WRSIZE = ACCESS_8_BIT; // + fpgaDMAReadControlRecord.TTYPE = FRAME_TRANSFER; // transfer type is block transfer + fpgaDMAReadControlRecord.ADDMODERD = ADDR_INC1; // source addressing mode is post-increment + fpgaDMAReadControlRecord.ADDMODEWR = ADDR_FIXED; // dest. addressing mode is fixed + fpgaDMAReadControlRecord.AUTOINIT = AUTOINIT_OFF; // auto-init off + fpgaDMAReadControlRecord.ELSOFFSET = 0; // not used + fpgaDMAReadControlRecord.ELDOFFSET = 0; // not used + fpgaDMAReadControlRecord.FRSOFFSET = 0; // not used + fpgaDMAReadControlRecord.FRDOFFSET = 0; // not used + + // initialize FPGA DMA Read Response Control Record + fpgaDMAReadRespControlRecord.PORTASGN = 4; // port B (only choice per datasheet) + fpgaDMAReadRespControlRecord.SADD = (U32)(&(scilinREG->RD)); // source is SCI2 recv register + fpgaDMAReadRespControlRecord.DADD = (U32)fpgaReadResponseBuffer; // transfer destination address + fpgaDMAReadRespControlRecord.CHCTRL = 0; // no chaining + fpgaDMAReadRespControlRecord.ELCNT = 1; // frame is 1 element + fpgaDMAReadRespControlRecord.FRCNT = 0; // block is TBD frames - will be populated later when known + fpgaDMAReadRespControlRecord.RDSIZE = ACCESS_8_BIT; // element size is 1 byte + fpgaDMAReadRespControlRecord.WRSIZE = ACCESS_8_BIT; // + fpgaDMAReadRespControlRecord.TTYPE = FRAME_TRANSFER; // transfer type is block transfer + fpgaDMAReadRespControlRecord.ADDMODERD = ADDR_FIXED; // source addressing mode is fixed + fpgaDMAReadRespControlRecord.ADDMODEWR = ADDR_INC1; // dest. addressing mode is post-increment + fpgaDMAReadRespControlRecord.AUTOINIT = AUTOINIT_OFF; // auto-init off + fpgaDMAReadRespControlRecord.ELDOFFSET = 0; // not used + fpgaDMAReadRespControlRecord.ELSOFFSET = 0; // not used + fpgaDMAReadRespControlRecord.FRDOFFSET = 0; // not used + fpgaDMAReadRespControlRecord.FRSOFFSET = 0; // not used + + // there shouldn't be any data pending yet + consumeUnexpectedData(); + + // Initialize the persistent alarm for FPGA power out + initPersistentAlarm( ALARM_ID_DG_FPGA_POWER_OUT_TIMEOUT, FPGA_POWER_OUT_TIMEOUT_MS, FPGA_POWER_OUT_TIMEOUT_MS ); +} + +/*********************************************************************//** + * @brief + * The resetFPGACommFlags function resets the various fpga comm flags and counters. + * @details Inputs: none + * @details Outputs: fpga comm flags & counters reset + * @return none + *************************************************************************/ +static void resetFPGACommFlags( void ) +{ + fpgaWriteCommandResponseReceived = FALSE; + fpgaReadCommandResponseReceived = FALSE; + fpgaWriteCommandInProgress = FALSE; + fpgaReadCommandInProgress = FALSE; + fpgaBulkWriteAndReadInProgress = FALSE; + fpgaTransmitCounter = 0; + fpgaReceiptCounter = 0; +} + +/*********************************************************************//** + * @brief + * The signalFPGAReceiptCompleted function increments a counter to indicate + * that another DMA receipt from the FPGA has completed. + * @details Inputs: none + * @details Outputs: fpgaReceiptCounter + * @return none + *************************************************************************/ +void signalFPGAReceiptCompleted( void ) +{ + fpgaReceiptCounter++; + // did FPGA Ack last command? + if ( TRUE == fpgaWriteCommandInProgress ) + { + fpgaWriteCommandInProgress = FALSE; + fpgaWriteCommandResponseReceived = TRUE; + } + else if ( TRUE == fpgaReadCommandInProgress ) + { + fpgaReadCommandInProgress = FALSE; + fpgaReadCommandResponseReceived = TRUE; + } + + // see if we want to follow up with a bulk read command + if ( TRUE == fpgaBulkWriteAndReadInProgress ) + { + fpgaBulkWriteAndReadInProgress = FALSE; + fpgaReadCommandInProgress = TRUE; + // initiate bulk read command + startDMAReceiptOfReadResp(); + startDMAReadCmd(); + } +} + +/*********************************************************************//** + * @brief + * The signalFPGATransmitCompleted function increments a counter to indicate + * that another DMA transmit to the FPGA has completed. + * @details Inputs: none + * @details Outputs: fpgaReceiptCounter + * @return none + *************************************************************************/ +void signalFPGATransmitCompleted( void ) +{ + fpgaTransmitCounter++; +} + +/*********************************************************************//** + * @brief + * The execFPGA function manages incoming data exchanges with the FPGA. + * @details Inputs: fpgaState + * @details Outputs: fpgaState + * @return none + *************************************************************************/ +void execFPGAIn( void ) +{ + fpgaReadByteSize = sizeof( DG_FPGA_SENSORS_T ); + +#ifndef _RELEASE_ + if( ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_ENABLE_V3_SYSTEM ) ) && ( getCurrentOperationMode() != DG_MODE_INIT ) ) + { + fpgaReadByteSize = FPGA_SIZE_OF_V3_READ_BYTES; + } +#endif + + // FPGA incoming state machine + switch ( fpgaState ) + { + case FPGA_STATE_START: + fpgaState = FPGA_STATE_READ_HEADER; + break; + + case FPGA_STATE_RCV_HEADER: + fpgaState = handleFPGAReceiveHeaderState(); + break; + + // TODO - sensor/ADC init/configuration states + + case FPGA_STATE_RCV_ALL_SENSORS: + fpgaState = handleFPGAReceiveAllSensorsState(); + break; + + case FPGA_STATE_FAILED: + // do nothing - we'll be stuck here + break; + + default: + if ( fpgaState >= NUM_OF_FPGA_STATES ) + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_FPGA_INVALID_IN_STATE, fpgaState ) + } + else + { + // ok, some states handled in the outgoing state machine + } + break; + } + + // if retries for commands exceeds limit or FPGA reports comm error, fault + if ( ( fpgaCommRetryCount > MAX_COMM_ERROR_RETRIES ) +#ifdef _RELEASE_ + || ( fpgaSensorReadings.fpgaIOErrorCntProcessor > MAX_COMM_ERROR_RETRIES ) ) +#else + ) +#endif + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_FPGA_COMM_TIMEOUT, fpgaCommRetryCount, (U32)fpgaSensorReadings.fpgaIOErrorCntProcessor ) + } + + // reset comm flags after processing incoming responses + resetFPGACommFlags(); + + // Check the FPGA power status + monitorFPGAPowerStatus(); +} + +/*********************************************************************//** + * @brief + * The execFPGAOut function manages outgoing data exchanges with the FPGA. + * @details Inputs: fpgaState + * @details Outputs: fpgaState + * @return none + *************************************************************************/ +void execFPGAOut( void ) +{ + fpgaReadByteSize = FPGA_SIZE_OF_V3_READ_BYTES; + +#ifndef _RELEASE_ + if( ( SW_CONFIG_ENABLE_VALUE != getSoftwareConfigStatus( SW_CONFIG_ENABLE_V3_SYSTEM ) ) && ( getCurrentOperationMode() != DG_MODE_INIT ) ) + { + fpgaReadByteSize = sizeof( DG_FPGA_SENSORS_T ); + } +#endif + + // FPGA outgoing state machine + switch ( fpgaState ) + { + case FPGA_STATE_READ_HEADER: + fpgaState = handleFPGAReadHeaderState(); + break; + + // TODO - sensor/ADC init/configuration states + + case FPGA_STATE_WRITE_ALL_ACTUATORS: + fpgaState = handleFPGAWriteAllActuatorsState(); + break; + + case FPGA_STATE_FAILED: + // do nothing - we'll be stuck here + break; + + default: + if ( fpgaState >= NUM_OF_FPGA_STATES ) + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_FPGA_INVALID_OUT_STATE, fpgaState ) + } + else + { + // ok, some states handled in the incoming state machine + } + break; + } +} + +/*********************************************************************//** + * @brief + * The handleFPGAReadHeaderState function handles the FPGA state where + * the read header registers command is sent to the FPGA. + * @details Inputs: none + * @details Outputs: read command sent to FPGA + * @return next FPGA state + *************************************************************************/ +static FPGA_STATE_T handleFPGAReadHeaderState( void ) +{ + FPGA_STATE_T result = FPGA_STATE_RCV_HEADER; + U16 crc; + + // construct read command to read 3 registers starting at address 0 + fpgaReadCmdBuffer[ 0 ] = FPGA_READ_CMD_CODE; + 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 ); + 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 ); + setupDMAForReadCmd( FPGA_READ_CMD_HDR_LEN + FPGA_CRC_LEN ); + startDMAReceiptOfReadResp(); + startDMAReadCmd(); + + return result; +} + +/*********************************************************************//** + * @brief + * The handleFPGAReceiveHeaderState function handles the FPGA state + * where the header registers read response should be ready to take in. + * @details Inputs: none + * @details Outputs: header register values updated + * @return next FPGA state + *************************************************************************/ +static FPGA_STATE_T handleFPGAReceiveHeaderState( void ) +{ + FPGA_STATE_T result = FPGA_STATE_READ_HEADER; + + // did we get an FPGA response? + if ( TRUE == fpgaReadCommandResponseReceived ) + { + // did FPGA Ack the read command? + if ( fpgaReadResponseBuffer[ 0 ] == FPGA_READ_CMD_ACK ) + { + U32 rspSize = FPGA_READ_RSP_HDR_LEN + sizeof( FPGA_HEADER_T ); + U32 crcPos = rspSize; + U16 crc = MAKE_WORD_OF_BYTES( fpgaReadResponseBuffer[ crcPos ], fpgaReadResponseBuffer[ crcPos + 1 ] ); + + // does the FPGA response CRC check out? + if ( crc == crc16( fpgaReadResponseBuffer, rspSize ) ) + { + fpgaCommRetryCount = 0; + // capture the read values + memcpy( &fpgaHeader, &fpgaReadResponseBuffer[ FPGA_READ_RSP_HDR_LEN ], sizeof( FPGA_HEADER_T ) ); + result = FPGA_STATE_WRITE_ALL_ACTUATORS; + } + else + { + fpgaCommRetryCount++; + } + } + else // header read was NAK'd + { + fpgaCommRetryCount++; + } + } + else // no response to read command + { + fpgaCommRetryCount++; + } + + // There should not be any data received at this time + consumeUnexpectedData(); + + return result; +} + +/*********************************************************************//** + * @brief + * The handleFPGAWriteAllActuatorsState function handles the FPGA state + * where the bulk write command is sent to the FPGA. + * @details Inputs: actuator set points + * @details Outputs: actuator set points sent to FPGA + * @return next FPGA state + *************************************************************************/ +static FPGA_STATE_T handleFPGAWriteAllActuatorsState( void ) +{ + FPGA_STATE_T result = FPGA_STATE_RCV_ALL_SENSORS; + U16 crc; + + // 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 ] = 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 ] = GET_LSB_OF_WORD( FPGA_BULK_READ_START_ADDR ); + fpgaReadCmdBuffer[ 2 ] = GET_MSB_OF_WORD( FPGA_BULK_READ_START_ADDR ); + fpgaReadCmdBuffer[ 3 ] = fpgaReadByteSize; //sizeof( DG_FPGA_SENSORS_T ); + crc = crc16( fpgaReadCmdBuffer, FPGA_READ_CMD_HDR_LEN ); + 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 + 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 ); + setupDMAForReadResp( FPGA_READ_RSP_HDR_LEN + fpgaReadByteSize /*sizeof( DG_FPGA_SENSORS_T )*/ + FPGA_CRC_LEN ); + + // set fpga comm flags for bulk write cmd and follow-up bulk read command + fpgaWriteCommandInProgress = TRUE; + fpgaBulkWriteAndReadInProgress = TRUE; + // initiate bulk write command and it's receipt - read will follow + startDMAReceiptOfWriteResp(); + startDMAWriteCmd(); + + return result; +} + +/*********************************************************************//** + * @brief + * The handleFPGAReceiveAllSensorsState function handles the FPGA state + * where the bulk read response should be ready to parse. + * @details Inputs: none + * @details Outputs: sensor values updated + * @return next FPGA state + *************************************************************************/ +static FPGA_STATE_T handleFPGAReceiveAllSensorsState( void ) +{ + FPGA_STATE_T result = FPGA_STATE_WRITE_ALL_ACTUATORS; + + // check bulk write command success + if ( ( FALSE == fpgaWriteCommandResponseReceived ) || ( fpgaWriteResponseBuffer[ 0 ] != FPGA_WRITE_CMD_ACK ) ) + { + fpgaCommRetryCount++; + } + + // if bulk read command is ACK'd, collect the readings + if ( TRUE == fpgaReadCommandResponseReceived ) + { + // did FPGA Ack the read command? + if ( fpgaReadResponseBuffer[ 0 ] == FPGA_READ_CMD_ACK ) + { + U32 rspSize = FPGA_READ_RSP_HDR_LEN + fpgaReadByteSize; //sizeof( DG_FPGA_SENSORS_T ); + U32 crcPos = rspSize; + U16 crc = MAKE_WORD_OF_BYTES( fpgaReadResponseBuffer[ crcPos ], fpgaReadResponseBuffer[ crcPos + 1 ] ); + + // does the FPGA response CRC check out? + if ( crc == crc16( fpgaReadResponseBuffer, rspSize ) ) + { + fpgaCommRetryCount = 0; + // capture the read values + memcpy( &fpgaSensorReadings, &fpgaReadResponseBuffer[ FPGA_READ_RSP_HDR_LEN ], fpgaReadByteSize /*sizeof( DG_FPGA_SENSORS_T )*/ ); + result = FPGA_STATE_WRITE_ALL_ACTUATORS; + } + else // bad CRC + { + fpgaCommRetryCount++; + } + } + else // read command was NAK'd + { + fpgaCommRetryCount++; + } + } + else // no response to read command + { + fpgaCommRetryCount++; + } + + // There should not be any data received at this time + consumeUnexpectedData(); + + return result; +} + +/*********************************************************************//** + * @brief + * The execFPGATest function executes the FPGA self-test. + * @details Inputs: fpgaHeader + * @details Outputs: none + * @return passed, or failed + *************************************************************************/ +SELF_TEST_STATUS_T execFPGATest( void ) +{ + SELF_TEST_STATUS_T result; + + // check FPGA reported correct ID + if ( FPGA_EXPECTED_ID == fpgaHeader.fpgaId ) + { + // Check FPGA compatibility w/ firmware + if ( DG_FPGA_COMPATIBILITY_REV == fpgaSensorReadings.fpgaCompatibilityRev ) + { + result = SELF_TEST_STATUS_PASSED; + } + else + { + result = SELF_TEST_STATUS_FAILED; + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_FPGA_POST_TEST_FAILED, (U32)DG_FPGA_COMPATIBILITY_REV, (U32)fpgaSensorReadings.fpgaCompatibilityRev ) + } + } + else + { + result = SELF_TEST_STATUS_FAILED; + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_FPGA_POST_TEST_FAILED, (U32)fpgaHeader.fpgaId ) + } + + return result; +} + +/*********************************************************************//** + * @brief + * The setupDMAForWriteCmd function sets the byte count for the next DMA + * write command to the FPGA. + * @details Inputs: none + * @details Outputs: number of bytes for next FPGA write command is set + * @param bytes2Transmit number of bytes to be transmitted via DMA to the FPGA. + * @return none + *************************************************************************/ +static void setupDMAForWriteCmd( U32 bytes2Transmit ) +{ + // verify # of bytes does not exceed buffer length + if ( bytes2Transmit <= FPGA_WRITE_CMD_BUFFER_LEN ) + { + fpgaDMAWriteControlRecord.FRCNT = bytes2Transmit; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_FPGA_WRITE_CMD_TOO_MUCH_DATA, bytes2Transmit ) + } +} + +/*********************************************************************//** + * @brief + * The startDMAWriteCmd function initiates the DMA transmit for the next + * DMA write command to the FPGA. + * @details Inputs: none + * @details Outputs: DMA write command to FPGA is initiated + * @return none + *************************************************************************/ +static void startDMAWriteCmd( void ) +{ + dmaSetCtrlPacket( DMA_CH2, fpgaDMAWriteControlRecord ); + dmaSetChEnable( DMA_CH2, DMA_HW ); + setSCI2DMATransmitInterrupt(); +} + +/*********************************************************************//** + * @brief + * The setupDMAForWriteResp function sets the expected byte count for the + * next DMA write command response from the FPGA. + * @details Inputs: none + * @details Outputs: number of expected bytes for next FPGA write command response is set + * @param bytes2Receive number of bytes expected to be transmitted via DMA from the FPGA. + * @return none + *************************************************************************/ +static void setupDMAForWriteResp( U32 bytes2Receive ) +{ + // verify # of bytes does not exceed buffer length + if ( bytes2Receive <= FPGA_WRITE_RSP_BUFFER_LEN ) + { + fpgaDMAWriteRespControlRecord.FRCNT = bytes2Receive; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_FPGA_WRITE_RSP_TOO_MUCH_DATA, bytes2Receive ) + } +} + +/*********************************************************************//** + * @brief + * The startDMAReceiptOfWriteResp function initiates readiness of the DMA + * receiver for the next DMA write command response from the FPGA. + * @details Inputs: none + * @details Outputs: DMA write command response is ready to be received from the FPGA + * @return none + *************************************************************************/ +static void startDMAReceiptOfWriteResp( void ) +{ + dmaSetCtrlPacket( DMA_CH0, fpgaDMAWriteRespControlRecord ); + dmaSetChEnable( DMA_CH0, DMA_HW ); + setSCI2DMAReceiveInterrupt(); +} + +/*********************************************************************//** + * @brief + * The setupDMAForReadCmd function sets the byte count for the next DMA + * read command to the FPGA. + * @details Inputs: none + * @details Outputs: number of bytes for next FPGA read command is set + * @param bytes2Transmit number of bytes to be transmitted via DMA to the FPGA. + * @return none + *************************************************************************/ +static void setupDMAForReadCmd( U32 bytes2Transmit ) +{ + // verify # of bytes does not exceed buffer length + if ( bytes2Transmit <= FPGA_READ_CMD_BUFFER_LEN ) + { + fpgaDMAReadControlRecord.FRCNT = bytes2Transmit; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_FPGA_READ_CMD_TOO_MUCH_DATA, bytes2Transmit ) + } +} + +/*********************************************************************//** + * @brief + * The startDMAReadCmd function initiates the DMA transmit for the next + * DMA read command to the FPGA. + * @details Inputs: none + * @details Outputs: DMA read command to FPGA is initiated + * @return none + *************************************************************************/ +static void startDMAReadCmd( void ) +{ + dmaSetCtrlPacket( DMA_CH2, fpgaDMAReadControlRecord ); + dmaSetChEnable( DMA_CH2, DMA_HW ); + setSCI2DMATransmitInterrupt(); +} + +/*********************************************************************//** + * @brief + * The setupDMAForReadResp function sets the expected byte count for the + * next DMA read command response from the FPGA. + * @details Inputs: none + * @details Outputs: number of expected bytes for next FPGA read command response is set + * @param bytes2Receive number of expected bytes to be transmitted via DMA from the FPGA. + * @return none + *************************************************************************/ +static void setupDMAForReadResp( U32 bytes2Receive ) +{ + // verify # of bytes does not exceed buffer length + if ( bytes2Receive <= FPGA_READ_RSP_BUFFER_LEN ) + { + fpgaDMAReadRespControlRecord.FRCNT = bytes2Receive; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_FPGA_READ_RSP_TOO_MUCH_DATA, bytes2Receive ) + } +} + +/*********************************************************************//** + * @brief + * The startDMAReceiptOfReadResp function initiates readiness of the DMA + * receiver for the next DMA read command response from the FPGA. + * @details Inputs: none + * @details Outputs: DMA read command response is ready to be received from the FPGA + * @return none + *************************************************************************/ +static void startDMAReceiptOfReadResp( void ) +{ + dmaSetCtrlPacket( DMA_CH0, fpgaDMAReadRespControlRecord ); + dmaSetChEnable( DMA_CH0, DMA_HW ); + setSCI2DMAReceiveInterrupt(); +} + +/*********************************************************************//** + * @brief + * The consumeUnexpectedData function checks to see if a byte is sitting in + * the SCI2 received data register. + * @details Inputs: fpgaHeader + * @details Outputs: 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 monitorFPGAPowerStatus function monitors the status of the FPGA power source. + * @details Inputs: none + * @details Outputs: none + * @return none + *************************************************************************/ +static void monitorFPGAPowerStatus( void ) +{ + // If the GIO bit returned a 0 it mean the power is out, otherwise the power is not out + BOOL isPowerOut = ( TRUE == (BOOL)gioGetBit( gioPORTA, FPGA_GPIO_POWER_STATUS_PIN ) ? FALSE : TRUE ); + + // TODO check to make sure alarm is not raised when the power is good + checkPersistentAlarm( ALARM_ID_DG_FPGA_POWER_OUT_TIMEOUT, isPowerOut, 0, FPGA_POWER_OUT_TIMEOUT_MS ); +} + +/*********************************************************************//** + * @brief + * The setFPGAValveStates function sets the DG valve states with a 16-bit + * set of states - one bit per valve, with a 1 meaning "energized" and a 0 + * meaning "de-energized". The bit positions for these bit states are as follows: + * 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 + * @details Outputs: fpgaActuatorSetPoints.fpgaValveStates + * @param valveStates bit mask for the various valve states + * @return none + *************************************************************************/ +void setFPGAValveStates( U16 valveStates ) +{ + fpgaActuatorSetPoints.fpgaValveStates = valveStates; +} + +/*********************************************************************//** + * @brief + * The setFPGADrainPumpSpeed function sets the drain pump target speed. + * The drain pump DAC value should be set to 1 count for each 12.94 RPM desired. + * @details Inputs: none + * @details Outputs: fpgaActuatorSetPoints.fpgaDrainPumpSetSpeed + * @param drainPumpDAC DAC value to command for the drain pump + * @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 setFPGACPoProbeType function sets the CPo sensor probe type and + * sets the control register to write probe type to the device. + * @details Inputs: none + * @details Outputs: fpgaActuatorSetPoints.fpgaCPoProbeType, fpgaActuatorSetPoints.fpgaCPoControlReg + * @param probeType The probe cell constant value to set to + * @return none + *************************************************************************/ +void setFPGACPoProbeType( U16 probeType ) +{ + fpgaActuatorSetPoints.fpgaCPoProbeType = probeType; + fpgaActuatorSetPoints.fpgaCPoControlReg = 0x1; +} + +/*********************************************************************//** + * @brief + * The setFPGACPiProbeType function sets the CPi sensor probe type and + * sets the control register to write probe type to the device. + * @details Inputs: none + * @details Outputs: fpgaActuatorSetPoints.fpgaCPiProbeType, fpgaActuatorSetPoints.fpgaCPiControlReg + * @param probeType The probe cell constant value to set to + * @return none + *************************************************************************/ +void setFPGACPiProbeType( U16 probeType ) +{ + fpgaActuatorSetPoints.fpgaCPiProbeType = probeType; + fpgaActuatorSetPoints.fpgaCPiControlReg = 0x1; +} + +/*********************************************************************//** + * @brief + * The setFPGAcidPumpControl function sets the control configuration for + * concentrate pump CP1. + * @details Inputs: none + * @details Outputs: fpgaActuatorSetPoints.fpgaCP1Control + * @param pumpControl The concentrate pump control configuration + * @return none + *************************************************************************/ +void setFPGAV3AcidPumpControl( U08 pumpControl ) +{ + fpgaActuatorSetPoints.fpgaCP1Control = pumpControl; +} + +/*********************************************************************//** + * @brief + * The setFPGABicarbPumpControl function sets the control configuration for + * concentrate pump CP2. + * @details Inputs: none + * @details Outputs: fpgaActuatorSetPoints.fpgaCP2Control + * @param pumpControl The concentrate pump control configuration + * @return none + *************************************************************************/ +void setFPGAV3BicarbPumpControl( U08 pumpControl ) +{ + fpgaActuatorSetPoints.fpgaCP2Control = pumpControl; +} + +/*********************************************************************//** + * @brief + * The setFPGAAcidPumpSetStepSpeed function sets the step speed period for + * concentrate pump CP1. + * @details Inputs: none + * @details Outputs: fpgaActuatorSetPoints.fpgaCP1StepSpeed + * @param stepSpeed The concentrate pump step speed period + * @return none + *************************************************************************/ +void setFPGAAcidPumpSetStepSpeed( U16 stepSpeed ) +{ + fpgaActuatorSetPoints.fpgaCP1StepSpeed = stepSpeed; +} + +/*********************************************************************//** + * @brief + * The setFPGABicarbSetStepSpeed function sets the step speed period for + * concentrate pump CP2. + * @details Inputs: none + * @details Outputs: fpgaActuatorSetPoints.fpgaCP2StepSpeed + * @param stepSpeed The concentrate pump step speed period + * @return none + *************************************************************************/ +void setFPGABicarbSetStepSpeed( U16 stepSpeed ) +{ + fpgaActuatorSetPoints.fpgaCP2StepSpeed = stepSpeed; +} + +/****************************DVT Functions*******************************************/ + +/*********************************************************************//** + * @brief + * The setFPGAAcidPumpControl function sets the DVT concentrate pump 1 + * (acid pump) control mode. + * @details Inputs: none + * @details Outputs: fpgaActuatorSetPoints.fpgaNewCP1Control + * @param control Concentrate pump control set + * @return none + *************************************************************************/ +void setFPGAAcidPumpControl( U08 control ) +{ + fpgaActuatorSetPoints.fpgaNewCP1Control = control; +} + +/*********************************************************************//** + * @brief + * The setFPGABicarbPumpControl function sets the DVT concentrate pump 2 + * (bicarb pump) control mode. + * @details Inputs: none + * @details Outputs: fpgaActuatorSetPoints.fgpaNewCP2Control + * @param control Concentrate pump control set + * @return none + *************************************************************************/ +void setFPGABicarbPumpControl( U08 control ) +{ + fpgaActuatorSetPoints.fgpaNewCP2Control = control; +} + +/*********************************************************************//** + * @brief + * The getFPGAVersions function gets the FPGA version numbers. + * @details Inputs: fpgaHeader + * @details Outputs: none + * @return none + *************************************************************************/ +void getFPGAVersions( U08 *Id, U08 *Maj, U08 *Min, U08 *Lab ) +{ + *Id = fpgaHeader.fpgaId; + *Maj = fpgaHeader.fpgaRevMajor; + *Min = fpgaHeader.fpgaRevMinor; + *Lab = fpgaHeader.fpgaRevLab; +} + +/*********************************************************************//** + * @brief + * The getFPGALoadCellA1 function gets the latest load cell A 1 reading. + * Least significant 24 bits are the reading. Most significant bit indicates + * CRC or status error. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return last load cell A 1 reading + *************************************************************************/ +U32 getFPGALoadCellA1( void ) +{ + return fpgaSensorReadings.fpgaLCA1; +} + +/*********************************************************************//** + * @brief + * The getFPGALoadCellA2 function gets the latest load cell A 2 reading. + * Least significant 24 bits are the reading. Most significant bit indicates + * CRC or status error. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return last load cell A 2 reading + *************************************************************************/ +U32 getFPGALoadCellA2( void ) +{ + return fpgaSensorReadings.fpgaLCA2; +} + +/*********************************************************************//** + * @brief + * The getFPGALoadCellB1 function gets the latest load cell B 1 reading. + * Least significant 24 bits are the reading. Most significant bit indicates + * CRC or status error. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return last load cell B 1 reading + *************************************************************************/ +U32 getFPGALoadCellB1( void ) +{ + return fpgaSensorReadings.fpgaLCB1; +} + +/*********************************************************************//** + * @brief + * The getFPGALoadCellB2 function gets the latest load cell B 2 reading. + * Least significant 24 bits are the reading. Most significant bit indicates + * CRC or status error. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return last load cell B 2 reading + *************************************************************************/ +U32 getFPGALoadCellB2( void ) +{ + return fpgaSensorReadings.fpgaLCB2; +} + +/*********************************************************************//** + * @brief + * The getFPGAValveStates function gets the latest sensed valve states. + * See setFPGAValveStates for valve state bit positions. + * @details Inputs: fpgaSensorReadings.fpgaValveStates + * @details Outputs: none + * @return last valve states reading + *************************************************************************/ +U16 getFPGAValveStates( void ) +{ + return fpgaSensorReadings.fpgaValveStates; +} + +/*********************************************************************//** + * @brief + * The getFPGAROPumpFlowRate function gets the latest RO flow rate. + * @details Inputs: fpgaSensorReadings.fpgaROFlowRate + * @details Outputs: none + * @return last RO flow rate reading + *************************************************************************/ +U16 getFPGAROPumpFlowRate( void ) +{ + return fpgaSensorReadings.fpgaROFlowRate; +} + +/*********************************************************************//** + * @brief + * The getFPGADialysateFlowRate function gets the latest dialysate flow rate. + * @details Inputs: fpgaSensorReadings.fpgaDialysateFlowRate + * @details Outputs: none + * @return last dialysate flow rate reading + *************************************************************************/ +U16 getFPGADialysateFlowRate( void ) +{ + return fpgaSensorReadings.fpgaDialysateFlowRate; +} + +/*********************************************************************//** + * @brief + * The getFPGADrainPumpSpeed function gets the latest sensed drain pump speed. + * @details Inputs: fpgaSensorReadings.fpgaDrainPumpSpeed + * @details Outputs: none + * @return last drain pump speed reading + *************************************************************************/ +U16 getFPGADrainPumpSpeed( void ) +{ + return fpgaSensorReadings.fpgaDrainPumpSpeed; +} + +/*********************************************************************//** + * @brief + * The getFPGATPiTemp function gets the latest primary heater inlet temperature reading. + * @details Inputs: fpgaSensorReadings.fpgaTPiTemp + * @details Outputs: none + * @return last primary heater inlet temperature reading + *************************************************************************/ +U32 getFPGATPiTemp( void ) +{ + return fpgaSensorReadings.fpgaTPiTemp; +} + +/*********************************************************************//** + * @brief + * The getFPGATPoTemp function gets the latest primary heater outlet temperature reading. + * @details Inputs: fpgaSensorReadings.fpgaTPoTemp + * @details Outputs: none + * @return last primary heater outlet temperature reading + *************************************************************************/ +U32 getFPGATPoTemp( void ) +{ + return fpgaSensorReadings.fpgaTPoTemp; +} + +/*********************************************************************//** + * @brief + * The getFPGATD1Temp function gets the latest conductivity sensor 1 + * temperature reading in ADC. + * @details Inputs: fpgaSensorReadings.fpgaCD1Temp + * @details Outputs: none + * @return last conductivity sensor 1 outlet temperature reading + *************************************************************************/ +U32 getFPGACD1Temp( void ) +{ + return fpgaSensorReadings.fpgaCD1Temp; +} + +/*********************************************************************//** + * @brief + * The getFPGATD2Temp function gets the latest conductivity sensor 2 + * temperature reading in ADC. + * @details Inputs: fpgaSensorReadings.fpgaCD2Temp + * @details Outputs: none + * @return last conductivity sensor 2 outlet temperature reading + *************************************************************************/ +U32 getFPGACD2Temp( void ) +{ + return fpgaSensorReadings.fpgaCD2Temp; +} + +/*********************************************************************//** + * @brief + * The getFPGARTDErrorCount function gets error count of the RTD. It covers + * all the four temperature sensors associates with conductivity sensors. + * @details Inputs: fpgaSensorReadings.fpgaRTDErrorCnt + * @details Outputs: none + * @return Last error count of the RTD temperature sensors + *************************************************************************/ +U08 getFPGARTDErrorCount( void ) +{ + return fpgaSensorReadings.fpgaRTDErrorCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGARTDReadCount function gets the read count of the RTD + * temperature sensors. It covers all the four temperature sensors associates + * with conductivity sensors. + * @details Inputs: fpgaSensorReadings.fpgaRTDReadCnt + * @details Outputs: none + * @return Last read count of the RTC temperature sensors + *************************************************************************/ +U08 getFPGARTDReadCount( void ) +{ + return fpgaSensorReadings.fpgaRTDReadCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGATRoTemp function gets the latest redundant sensor outlet + * temperature reading in ADC. + * @details Inputs: fpgaSensorReadings.fpgaTRo + * @details Outputs: none + * @return Last redundant sensor outlet temperature reading + *************************************************************************/ +U32 getFPGATRoTemp( void ) +{ + return fpgaSensorReadings.fpgaTRo; +} + +/*********************************************************************//** + * @brief + * The getFPGATRoErrorCount gets the error count of the THDo (redundant) temperature sensor. + * @details Inputs: fpgaSensorReadings.fpgaTRoErrorCnt + * @details Outputs: none + * @return Last redundant sensor outlet temperature error count + *************************************************************************/ +U08 getFPGATRoErrorCount( void ) +{ + return fpgaSensorReadings.fpgaTRoErrorCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGATRoReadCount gets the read count of the THDo (redundant) temperature sensor. + * @details Inputs: fpgaSensorReadings.fpgaTRoReadCnt + * @details Outputs: none + * @return Last redundant sensor outlet temperature error count reading + *************************************************************************/ +U08 getFPGATRoReadCount( void ) +{ + return fpgaSensorReadings.fpgaTRoReadCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGATDiTemp function gets the latest dialysate inlet temperature reading in ADC. + * @details Inputs: fpgaSensorReadings.fpgaTDiTemp + * @details Outputs: none + * @return last primary heater outlet temperature reading + *************************************************************************/ +U32 getFPGATDiTemp( void ) +{ + return fpgaSensorReadings.fpgaTDi; +} + +/*********************************************************************//** + * @brief + * The getFPGATDiErrorCount function gets the latest dialysate inlet temperature error count. + * @details Inputs: fpgaSensorReadings.fpgaTDiErrorCnt + * @details Outputs: none + * @return Last dialysate inlet error count + *************************************************************************/ +U08 getFPGATDiErrorCount( void ) +{ + return fpgaSensorReadings.fpgaTDiErrorCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGATDiReadCount function gets the latest dialysate inlet temperature read count. + * @details Inputs: fpgaSensorReadings.fpgaTDiReadCnt + * @details Outputs: none + * @return Last dialysate inlet read count + *************************************************************************/ +U08 getFPGATDiReadCount( void ) +{ + return fpgaSensorReadings.fpgaTDiReadCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGAPrimaryHeaterTemp function gets the latest primary heater + * internal temperature reading. + * @details Inputs: fpgaSensorReadings.fpgaPrimaryHeaterIntTemp + * @details Outputs: none + * @return last primary heater temperature reading + *************************************************************************/ +U16 getFPGAPrimaryHeaterTemp( void ) +{ + return fpgaSensorReadings.fpgaPrimaryHeaterIntTemp; +} + +/*********************************************************************//** + * @brief + * The getFPGAPrimaryHeaterFlags function gets the latest primary heater + * internal temperature sensor flags read. + * @details Inputs: fpgaSensorReadings.fpgaPrimaryHeaterFlags + * @details Outputs: 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 + * internal temperature sensor read count. + * @details Inputs: fpgaSensorReadings.fpgaPrimaryHeaterReadCnt + * @details Outputs: 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 + * internal temperature sensor reading. + * @details Inputs: fpgaSensorReadings.fpgaTrimmerHeaterIntTemp + * @details Outputs: none + * @return last trimmer heater temperature reading + *************************************************************************/ +U16 getFPGATrimmerHeaterTemp( void ) +{ + return fpgaSensorReadings.fpgaTrimmerHeaterIntTemp; +} + +/*********************************************************************//** + * @brief + * The getFPGATrimmerHeaterFlags function gets the latest trimmer heater + * internal temperature flags read. + * @details Inputs: fpgaSensorReadings.fpgaTrimmerHeaterFlags + * @details Outputs: none + * @return Last trimmer heater internal temperature flags read + *************************************************************************/ +U08 getFPGATrimmerHeaterFlags( void ) +{ + return fpgaSensorReadings.fpgaTrimmerHeaterFlags; +} + +/*********************************************************************//** + * @brief + * The getFPGATrimmerHeaterReadCount function gets the latest trimmer heater + * internal temperature read count. + * @details Inputs: fpgaSensorReadings.fpgaTrimmerHeaterReadCnt + * @details Outputs: 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 + * @details Outputs: 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 + * @details Outputs: none + * @return Last trimmer cold junction temperature + *************************************************************************/ +U16 getFPGATrimmerColdJunctionTemp( void ) +{ + return fpgaSensorReadings.fpgaTrimmerHeaterIntJunctionTemp; +} + +/*********************************************************************//** + * @brief + * The getFPGAAccelAxes function gets the accelerometer axis readings. + * Axis readings are in ADC counts. 0.004 g per LSB. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @param x Populate this param with X axis reading + * @param y Populate this param with Y axis reading + * @param z Populate this param with Z axis reading + * @return none + *************************************************************************/ +void getFPGAAccelAxes( S16 *x, S16 *y, S16 *z ) +{ + *x = (S16)fpgaSensorReadings.accelX; + *y = (S16)fpgaSensorReadings.accelY; + *z = (S16)fpgaSensorReadings.accelZ; +} + +/*********************************************************************//** + * @brief + * The getFPGAAccelMaxes function gets the maximum accelerometer axis readings from + * last FPGA read (every 10 ms). Axis readings are in ADC counts. 0.004 g per LSB. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @param x Populate this param with maximum X axis reading + * @param y Populate this param with maximum Y axis reading + * @param z Populate this param with maximum Z axis reading + * @return none + *************************************************************************/ +void getFPGAAccelMaxes( S16 *xmax, S16*ymax, S16*zmax ) +{ + *xmax = (S16)fpgaSensorReadings.accelXMax; + *ymax = (S16)fpgaSensorReadings.accelYMax; + *zmax = (S16)fpgaSensorReadings.accelZMax; +} + +/*********************************************************************//** + * @brief + * The getFPGAAccelStatus function gets the accelerometer reading count + * and error register values. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @param cnt Populate this param with latest sample counter value + * @param err Populate this param with latest error + * @return none + *************************************************************************/ +void getFPGAAccelStatus( U16 *cnt, U16 *err ) +{ + *cnt = fpgaSensorReadings.accelSampleCounter; + *err = fpgaSensorReadings.accelFaultRegister; +} + +/*********************************************************************//** + * @brief + * The getFPGACPiFault function gets CPi conductivity sensor fault. + * @details Inputs: fpgaSensorReadings.fpgaCPiFault + * @details Outputs: none + * @return Latest CPi conductivity sensor fault + *************************************************************************/ +U08 getFPGACPiFault( void ) +{ + return fpgaSensorReadings.fpgaCPiFault; +} + +/*********************************************************************//** + * @brief + * The getFPGACPiReadCount function gets CPi conductivity sensor read count. + * @details Inputs: fpgaSensorReadings.fpgaCPiReadCnt + * @details Outputs: none + * @return Latest CPi conductivity sensor read count + *************************************************************************/ +U08 getFPGACPiReadCount( void ) +{ + return fpgaSensorReadings.fpgaCPiReadCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGACPiErrorCount function gets CPi conductivity sensor error count. + * @details Inputs: fpgaSensorReadings.fpgaCPiErrorCnt + * @details Outputs: none + * @return Latest CPi conductivity sensor read error count + *************************************************************************/ +U08 getFPGACPiErrorCount( void ) +{ + return fpgaSensorReadings.fpgaCPiErrorCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGACPi function gets CPi conductivity sensor value. + * @details Inputs: fpgaSensorReadings.fpgaCPi + * @details Outputs: none + * @return Latest CPi conductivity sensor value + *************************************************************************/ +U32 getFPGACPi( void ) +{ + return fpgaSensorReadings.fpgaCPi; +} + +/*********************************************************************//** + * @brief + * The getFPGACPoFault function gets CPo conductivity sensor fault. + * @details Inputs: fpgaSensorReadings.fpgaCPoFault + * @details Outputs: none + * @return Latest CPo sensor fault + *************************************************************************/ +U08 getFPGACPoFault( void ) +{ + return fpgaSensorReadings.fpgaCPoFault; +} + +/*********************************************************************//** + * @brief + * The getFPGACPoReadCount function gets CPo conductivity sensor read count. + * @details Inputs: fpgaSensorReadings.fpgaCPoReadCnt + * @details Outputs: none + * @return Latest CPo conductivity sensor read count + *************************************************************************/ +U08 getFPGACPoReadCount( void ) +{ + return fpgaSensorReadings.fpgaCPoReadCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGACPoErrorCount function gets CPo conductivity sensor error count. + * error count + * @details Inputs: fpgaSensorReadings.fpgaCPoErrorCnt + * @details Outputs: none + * @return Latest CPo conductivity sensor read error count + *************************************************************************/ +U08 getFPGACPoErrorCount( void ) +{ + return fpgaSensorReadings.fpgaCPoErrorCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGACPo function gets CPo conductivity sensor value. + * @details Inputs: fpgaSensorReadings.fpgaCPo + * @details Outputs: none + * @return Latest CPo conductivity sensor value + *************************************************************************/ +U32 getFPGACPo( void ) +{ + return fpgaSensorReadings.fpgaCPo; +} + +/*********************************************************************//** + * @brief + * The getFPGAConcentratePumpsFault function gets concentrate pumps fault + * reported by FGPA. + * @details Inputs: fpgaSensorReadings.fpgaCP1CP2Fault + * @details Outputs: none + * @return Latest concentrate pumps fault value + *************************************************************************/ +U08 getFPGAConcentratePumpsFault( void ) +{ + return fpgaSensorReadings.fpgaCP1CP2Fault; +} + +/*********************************************************************//** + * @brief + * The getFPGAEmstatOutByte function gets Emstat conductivity sensor output byte. + * @details Inputs: fpgaSensorReadings.fpgaEmstatOutByte + * @details Outputs: none + * @return Emstat conductivity sensor output byte + *************************************************************************/ +U08 getFPGAEmstatCD1CD2OutByte( void ) +{ + return fpgaSensorReadings.fpgaCD1CD2EmstatOutByte; +} + +/*********************************************************************//** + * @brief + * The getFPGAEmstatCD1CD2RxErrCount function gets Emstat conductivity sensor + * error count. + * @details Inputs: fpgaSensorReadings.fpgaEmstatRxErrorCount + * @details Outputs: none + * @return Emstat conductivity sensor receive error count + *************************************************************************/ +U08 getFPGAEmstatCD1CD2RxErrCount( void ) +{ + return fpgaSensorReadings.fpgaCD1CD2EmstatRxErrorCount; +} + +/*********************************************************************//** + * @brief + * The getFPGAEmstatCD1CD2RxFifoCount function gets Emstat conductivity + * sensor receive fifo buffer count. + * @details Inputs: fpgaSensorReadings.fpgaEmstatTxFifoCount + * @details Outputs: none + * @return Emstat conductivity sensor receive fifo buffer count + *************************************************************************/ +U16 getFPGAEmstatCD1CD2RxFifoCount( void ) +{ + return fpgaSensorReadings.fpgaCD1CD2EmstatRxFifoCount; +} + +/*********************************************************************//** + * @brief + * The getFPGACP1HallSensePulseWidth function gets concentrate pump CP1 + * hall sense pulse width. + * @details Inputs: fpgaSensorReadings.fpgaCP1HallSense + * @details Outputs: none + * @return concentrate pump CP1 hall sense pulse width + *************************************************************************/ +U16 getFPGACP1HallSensePulseWidth( void ) +{ + return fpgaSensorReadings.fpgaCP1HallSense; +} + +/*********************************************************************//** + * @brief + * The getFPGACP1HallSensePulseWidth function gets concentrate pump CP2 + * hall sense pulse width. + * @details Inputs: fpgaSensorReadings.fpgaCP2HallSense + * @details Outputs: none + * @return concentrate pump CP2 hall sense pulse width + *************************************************************************/ +U16 getFPGACP2HallSensePulseWidth( void ) +{ + return fpgaSensorReadings.fpgaCP2HallSense; +} + +/*********************************************************************//** + * @brief + * The getFPGAFan1Pulse function gets inlet fan 1 pulse value. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return inlet fan 1 pulse value + *************************************************************************/ +U16 getFPGAInletFan1TogglePeriod( void ) +{ + return fpgaSensorReadings.fpgaFanIn1Pulse; +} + +/*********************************************************************//** + * @brief + * The getFPGAFan2Pulse function gets inlet fan 2 pulse value. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return inlet fan 2 pulse value + *************************************************************************/ +U16 getFPGAInletFan2TogglePeriod( void ) +{ + return fpgaSensorReadings.fpgaFanIn2Pulse; +} + +/*********************************************************************//** + * @brief + * The getFPGAInletFan3Pulse function gets inlet fan 3 pulse value. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return inlet fan 3 pulse value + *************************************************************************/ +U16 getFPGAInletFan3TogglePeriod( void ) +{ + return fpgaSensorReadings.fpgaFanIn3Pulse; +} + +/*********************************************************************//** + * @brief + * The getFPGAOutletFan1Pulse function gets outlet fan 1 pulse value. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return outlet fan 1 pulse value + *************************************************************************/ +U16 getFPGAOutletFan1TogglePeriod( void ) +{ + return fpgaSensorReadings.fpgaFanOut1Pulse; +} + +/*********************************************************************//** + * @brief + * The getFPGAOutletFan2Pulse function gets outlet fan 2 pulse value. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return outlet fan 2 pulse value + *************************************************************************/ +U16 getFPGAOutletFan2TogglePeriod( void ) +{ + return fpgaSensorReadings.fpgaFanOut2Pulse; +} + +/*********************************************************************//** + * @brief + * The getFPGAOutletFan3Pulse function gets outlet fan 3 pulse value. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return outlet fan 3 pulse value + *************************************************************************/ +U16 getFPGAOutletFan3TogglePeriod( void ) +{ + return fpgaSensorReadings.fpgaFanOut3Pulse; +} + +/*********************************************************************//** + * @brief + * The getFPGABoardTemp function gets FPGA board temperature reading. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return FPGA board temperature reading in ADC counts + *************************************************************************/ +U16 getFPGABoardTemp( void ) +{ + return fpgaSensorReadings.fpgaADCTemp; +} + +/*********************************************************************//** + * @brief + * The getFPGAA1B1Temp function gets load cells A1/B1 temperature reading. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return load cells A1/B1 temperature reading in ADC counts + *************************************************************************/ +U32 getFPGALoadCellsA1B1Temp( void ) +{ + return fpgaSensorReadings.fpgaADC1Temp; +} + +/*********************************************************************//** + * @brief + * The getFPGAA1B1Temp function gets load cells A2/B2 temperature reading. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return load cells A2/B2 temperature reading in ADC counts + *************************************************************************/ +U32 getFPGALoadCellsA2B2Temp( void ) +{ + return fpgaSensorReadings.fpgaADC2Temp; +} + +/*********************************************************************//** + * @brief + * The getFPGATRoInternalTemp function gets TRo internal temperature reading. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return TRo internal temperature reading in ADC counts + *************************************************************************/ +U32 getFPGATRoInternalTemp( void ) +{ + return fpgaSensorReadings.fpgaTRoTemp; +} + +/*********************************************************************//** + * @brief + * The getFPGATDiInternalTemp function gets TDi internal temperature reading. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return TDi internal temperature reading in ADC counts + *************************************************************************/ +U32 getFPGATDiInternalTemp( void ) +{ + return fpgaSensorReadings.fpgaTDiTemp; +} + +/*********************************************************************//** + * @brief + * The getFPGAConductivitySnsrInternalTemp function gets conductivity sensor + * internal temperature reading. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return conductivity sensor temperature reading in ADC counts + *************************************************************************/ +U32 getFPGACondSnsrInternalTemp( void ) +{ + return fpgaSensorReadings.fpgaRTDTemp; +} + +/*********************************************************************//** + * @brief + * The getFPGAADC1ReadCount function gets the FPGA ADC1 read count. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return FPGA ADC1 read count + *************************************************************************/ +U08 getFPGAADC1ReadCount( void ) +{ + return fpgaSensorReadings.fpgaADC1ReadCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGAADC1ErrorCount function gets the FPGA ADC1 error count. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return FPGA ADC1 error count + *************************************************************************/ +U08 getFPGAADC1ErrorCount( void ) +{ + return fpgaSensorReadings.fpgaADC1ErrorCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGAADC2ReadCount function gets the FPGA ADC2 read count. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return FPGA ADC2 read count + *************************************************************************/ +U08 getFPGAADC2ReadCount( void ) +{ + return fpgaSensorReadings.fpgaADC2ReadCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGAADC2ErrorCount function gets the FPGA ADC2 error count. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return FPGA ADC2 error count + *************************************************************************/ +U08 getFPGAADC2ErrorCount( void ) +{ + return fpgaSensorReadings.fpgaADC2ErrorCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGATimerCount function gets the latest FPGA timer millisecond count. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return last FPGA timer count + *************************************************************************/ +U16 getFPGATimerCount( void ) +{ + return fpgaSensorReadings.fpgaTimerCountMS; +} + +/*********************************************************************//** + * @brief + * The noFluidLeakDetected function returns TRUE if no fluid leak has been + * detected (dry) and FALSE if a fluid leak has been detected (wet). + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return noFluidLeakDetected + *************************************************************************/ +BOOL noFPGAFluidLeakDetected( void ) +{ + U16 noFluidLeakDetected = fpgaSensorReadings.fpgaGPIO & FPGA_FLUIDLEAK_STATE_MASK; + + return ( 0 == noFluidLeakDetected ? FALSE : TRUE ); +} + +/*********************************************************************//** + * @brief + * The getFPGADialysateCapStatus function gets the FPGA dialysate cap status + * bit. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return dialysate cap status bit + *************************************************************************/ +U08 getFPGADialysateCapStatus( void ) +{ + return ( fpgaSensorReadings.fpgaGPIO & DIALYSATE_CAP_SWITCH_MASK ); +} + +/*********************************************************************//** + * @brief + * The getFPGAConcentrateCapStatus function gets the FPGA concentrate cap + * status bit. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return concentrate cap status bit + *************************************************************************/ +U08 getFPGAConcentrateCapStatus( void ) +{ + return ( fpgaSensorReadings.fpgaGPIO & CONCENTRATE_CAP_SWITCH_MASK ); +} + +/*********************************************************************//** + * @brief + * The getFPGABaroReadCount function gets the FPGA barometric sensor read count. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return barometric pressure sensor read count + *************************************************************************/ +U08 getFPGABaroReadCount( void ) +{ + return fpgaSensorReadings.fpgaBaroReadCount; +} + +/*********************************************************************//** + * @brief + * The getFPGABaroErrorCount function gets the FPGA barometric sensor error count. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return barometric pressure sensor error count + *************************************************************************/ +U08 getFPGABaroErrorCount( void ) +{ + return fpgaSensorReadings.fpgaBaroErrorCount; +} + +/*********************************************************************//** + * @brief + * The getFPGABaroPressureSensitivity function gets the FPGA barometric pressure + * sensor sensitivity. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return barometric pressure sensor sensitivity + *************************************************************************/ +U16 getFPGABaroPressureSensitivity( void ) +{ + return fpgaSensorReadings.fpgaBaroPROMCoeff1; +} + +/*********************************************************************//** + * @brief + * The getFPGABaroPressureOffset function gets the FPGA barometric pressure + * sensor offset. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return barometric pressure sensor offset + *************************************************************************/ +U16 getFPGABaroPressureOffset( void ) +{ + return fpgaSensorReadings.fpgaBaroPROMCoeff2; +} + +/*********************************************************************//** + * @brief + * The getFPGABaroTempCoeffOfPressSensitvity function gets the FPGA barometric + * pressure sensor temperature coefficient of pressure sensitivity. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return barometric pressure sensor temperature coefficient of pressure sensitivity + *************************************************************************/ +U16 getFPGABaroTempCoeffOfPressSensitvity( void ) +{ + return fpgaSensorReadings.fpgaBaroPROMCoeff3; +} + +/*********************************************************************//** + * @brief + * The getFPGABaroTempCoeffOfPressOffset function gets the FPGA barometric + * pressure sensor temperature coefficient of pressure offset. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return barometric pressure sensor temperature coefficient of pressure offset + *************************************************************************/ +U16 getFPGABaroTempCoeffOfPressOffset( void ) +{ + return fpgaSensorReadings.fpgaBaroPROMCoeff4; +} + +/*********************************************************************//** + * @brief + * The getFPGABaroReferenceTemperature function gets the FPGA barometric pressure + * sensor reference temperature. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return barometric pressure sensor reference temperature + *************************************************************************/ +U16 getFPGABaroReferenceTemperature( void ) +{ + return fpgaSensorReadings.fpgaBaroPROMCoeff5; +} + +/*********************************************************************//** + * @brief + * The getFPGABaroTempCoeffOfTemperature function gets the FPGA barometric pressure + * sensor temperature coefficient of temperature. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return barometric pressure sensor temperature coefficient of temperature + *************************************************************************/ +U16 getFPGABaroTempCoeffOfTemperature( void ) +{ + return fpgaSensorReadings.fpgaBaroPROMCoeff6; +} + +/*********************************************************************//** + * @brief + * The getFPGABaroPressure function gets the FPGA barometric pressure sensor + * pressure. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return barometric pressure sensor pressure + *************************************************************************/ +U32 getFPGABaroPressure( void ) +{ + return ( fpgaSensorReadings.fpgaBaroPressure & MASK_OFF_U32_MSB ); +} + +/*********************************************************************//** + * @brief + * The getFPGABaroTemperature function gets the FPGA barometric pressure sensor + * temperature. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return barometric pressure sensor temperature + *************************************************************************/ +U32 getFPGABaroTemperature( void ) +{ + return ( fpgaSensorReadings.fpgaBaroTemperature & MASK_OFF_U32_MSB ); +} + +/*********************************************************************//** + * @brief + * The getFPGAEmstatCPiCPoByteOut function gets the FPGA Emstat CPi/CPo + * byte out data. + * @details Inputs: fpgaSensorReadings.fpgaCPiCPoEmstatOutByte + * @details Outputs: none + * @return CPi/CPo Emstat byte out + *************************************************************************/ +U08 getFPGAEmstatCPiCPoByteOut( void ) +{ + return fpgaSensorReadings.fpgaCPiCPoEmstatOutByte; +} + +/*********************************************************************//** + * @brief + * The getFPGAEmstatCPiCPoRxFifoCount function gets the FPGA Emstat CPi/CPo + * receive FIFO count. + * @details Inputs: fpgaSensorReadings.fpgaCD1CD2EmstatRxFifoCount + * @details Outputs: none + * @return CPi/CPo Rx FIFO count + *************************************************************************/ +U16 getFPGAEmstatCPiCPoRxFifoCount( void ) +{ + return fpgaSensorReadings.fpgaCPiCPoEmstatRxFIFOCount; +} + +/*********************************************************************//** + * @brief + * The getFPGAEmstatCPiCPoRxErrCount function gets the FPGA Emstat CPi/CPo + * receive FIFO error count. + * @details Inputs: fpgaSensorReadings.fpgaCD1CD2EmstatRxErrorCount + * @details Outputs: none + * @return CPi/CPo Rx FIFO error count + *************************************************************************/ +U08 getFPGAEmstatCPiCPoRxErrCount( void ) +{ + return fpgaSensorReadings.fpgaCPiCPoEmstatRxErrCount; +} + +/*********************************************************************//** + * @brief + * The getFPGATHdTemp function gets the FPGA THd temperature sensor. + * @details Inputs: fpgaSensorReadings.fpgaTHdTemp + * @details Outputs: none + * @return THd temperature sensor + *************************************************************************/ +U32 getFPGATHdTemp( void ) +{ + return fpgaSensorReadings.fpgaTHdTemp; +} + +/*********************************************************************//** + * @brief + * The getFPGATHdInternalTemp function gets the FPGA THd internal ADC temperature sensor. + * @details Inputs: fpgaSensorReadings.fpgaTHdInternalTemp + * @details Outputs: none + * @return THd internal ADC temperature sensor + *************************************************************************/ +U32 getFPGATHdInternalTemp( void ) +{ + return fpgaSensorReadings.fpgaTHdInternalTemp; +} + +/*********************************************************************//** + * @brief + * The getFPGATHdReadCount function gets the FPGA THd temperature sensor read + * count. + * @details Inputs: fpgaSensorReadings.fpgaTHdRTDReadCount + * @details Outputs: none + * @return THd FPGA read count + *************************************************************************/ +U08 getFPGATHdReadCount( void ) +{ + return fpgaSensorReadings.fpgaTHdRTDReadCount; +} + +/*********************************************************************//** + * @brief + * The getFPGATHdErrorCount function gets the FPGA THd temperature sensor error + * count. + * @details Inputs: fpgaSensorReadings.fpgaTHdRTDErrorCount + * @details Outputs: none + * @return THd FPGA error count + *************************************************************************/ +U08 getFPGATHdErrorCount( void ) +{ + return fpgaSensorReadings.fpgaTHdRTDErrorCount; +} + +/*********************************************************************//** + * @brief + * The getFPGAROFlowSensorEdgeCount function gets the FPGA RO flow sensor + * edge count. + * @details Inputs: fpgaSensorReadings.fpgaROFlowSensorEdgeCount + * @details Outputs: none + * @return RO flow sensor edge count + *************************************************************************/ +U16 getFPGAROFlowSensorEdgeCount( void ) +{ + return fpgaSensorReadings.fpgaROFlowSensorEdgeCount; +} + +/*********************************************************************//** + * @brief + * The getFPGADialysateFlowSensorEdgeCount function gets the FPGA dialysate + * flow sensor edge count + * @details Inputs: fpgaSensorReadings.fpgaDialysateFlowSensorEdgeCount + * @details Outputs: none + * @return Dialysate flow sensor edge count + *************************************************************************/ +U16 getFPGADialysateFlowSensorEdgeCount( void ) +{ + return fpgaSensorReadings.fpgaDialysateFlowSensorEdgeCount; +} + +/**@}*/