Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -r325e67dab10f6666702bf0f1256015b31e58de4f -rd305a91c82fe89a76d9accbb8faa3d81e3106341 --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 325e67dab10f6666702bf0f1256015b31e58de4f) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision d305a91c82fe89a76d9accbb8faa3d81e3106341) @@ -404,7 +404,11 @@ if ( ++primaryTargetTempAdjCounter >= D5_TARGET_TEMP_ADJUST_INTERVAL_MS ) { F32 targetTempfromTD = getTDTargetDialysateTemperature(); +#ifdef __TEENSY_CONDUCTIVITY_DRIVER__ + F32 measuredTempAtDialyzer = getTeensyConductivityTemperatureValue( D27_COND ); +#else F32 measuredTempAtDialyzer = getConductivityTemperatureValue( D27_COND ); +#endif F32 calcTargetTemp = getHeaterTargetTemperature( D5_HEAT ); F32 dialysateFlowrate = getTDDialysateFlowrate(); F32 deltaTempC = targetTempfromTD - measuredTempAtDialyzer; Index: firmware/App/DDCommon.h =================================================================== diff -u -re156ebe15a34ef907fe8d118c92237659cf6b4e5 -rd305a91c82fe89a76d9accbb8faa3d81e3106341 --- firmware/App/DDCommon.h (.../DDCommon.h) (revision e156ebe15a34ef907fe8d118c92237659cf6b4e5) +++ firmware/App/DDCommon.h (.../DDCommon.h) (revision d305a91c82fe89a76d9accbb8faa3d81e3106341) @@ -54,6 +54,8 @@ //Uncomment below to disable heaters debug message #define __HEATERS_DEBUG__ 1 +//Uncomment below to disable Teensy conductivity driver +#define __TEENSY_CONDUCTIVITY_DRIVER__ 1 #include #include Index: firmware/App/Drivers/ConductivitySensors.c =================================================================== diff -u -r18f5ac036baf7dca352e881bdd64d6fd742d8c58 -rd305a91c82fe89a76d9accbb8faa3d81e3106341 --- firmware/App/Drivers/ConductivitySensors.c (.../ConductivitySensors.c) (revision 18f5ac036baf7dca352e881bdd64d6fd742d8c58) +++ firmware/App/Drivers/ConductivitySensors.c (.../ConductivitySensors.c) (revision d305a91c82fe89a76d9accbb8faa3d81e3106341) @@ -18,7 +18,6 @@ #include // For memcpy #include "ConductivitySensors.h" -#include "ConductivityTeensy.h" #include "FpgaDD.h" #include "MessageSupport.h" #include "Messaging.h" @@ -81,23 +80,14 @@ static CONDUCTIVITY_SENSOR_CONTROL_T conductivitySensorControl[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Conductivity sensor Control for reset, init, read and write operations. -static const TEENSY_SENSOR_INDEX_T teensySensorMapping[NUM_OF_CONDUCTIVITY_SENSORS] = { - [D17_COND] = TEENSY_SENSOR_0, - [D27_COND] = TEENSY_SENSOR_1, - [D43_COND] = TEENSY_SENSOR_2, - [D74_COND] = TEENSY_SENSOR_3, - [P9_COND] = TEENSY_SENSOR_4, - [P18_COND] = TEENSY_SENSOR_5 -}; - // ********** private function prototypes ********** static void checkConductivitySensors( void ); static CONDUCTIVITY_READ_STATE_T handleConductivitySensorsReadInitiate( CONDUCTIVITY_SENSORS_T sensorID ); static CONDUCTIVITY_WRITE_STATE_T handleConductivitySensorsWriteComplete( CONDUCTIVITY_SENSORS_T sensorID ); static CONDUCTIVITY_WRITE_STATE_T handleConductivitySensorsWriteInitiate( CONDUCTIVITY_SENSORS_T sensorID ); static CONDUCTIVITY_READ_STATE_T handleConductivitySensorsReadComplete( CONDUCTIVITY_SENSORS_T sensorID ); -static TEENSY_SENSOR_INDEX_T getTeensySensorNum( CONDUCTIVITY_SENSORS_T sensorID ); + /*********************************************************************//** * @brief * The initConductivitySensors function initializes the ConductivitySensors unit. @@ -157,7 +147,7 @@ //initFPGAPersistentAlarm( FPGA_PERS_ERROR_P9_COND_SENSOR, ALARM_ID_FP_P9_SENSOR_FPGA_FAULT, COND_SENSORS_FPGA_ERROR_TIMEOUT_MS, COND_SENSORS_FPGA_ERROR_TIMEOUT_MS ); //initFPGAPersistentAlarm( FPGA_PERS_ERROR_P18_COND_SENSOR, ALARM_ID_FP_P18_SENSOR_FPGA_FAULT, COND_SENSORS_FPGA_ERROR_TIMEOUT_MS, COND_SENSORS_FPGA_ERROR_TIMEOUT_MS ); - initCondTeensy(); + } @@ -1002,16 +992,6 @@ return state; } -static TEENSY_SENSOR_INDEX_T getTeensySensorNum( CONDUCTIVITY_SENSORS_T sensorID ) -{ - if ( sensorID >= NUM_OF_CONDUCTIVITY_SENSORS ) - { - return MAX_TEENSY_SENSOR; // Invalid sensor ID - } - return teensySensorMapping[ sensorID ]; -} - - /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ Index: firmware/App/Drivers/ConductivityTeensy.c =================================================================== diff -u -r7aafdc16c133bcd4cb0ce5fe08079c1969cc67d2 -rd305a91c82fe89a76d9accbb8faa3d81e3106341 --- firmware/App/Drivers/ConductivityTeensy.c (.../ConductivityTeensy.c) (revision 7aafdc16c133bcd4cb0ce5fe08079c1969cc67d2) +++ firmware/App/Drivers/ConductivityTeensy.c (.../ConductivityTeensy.c) (revision d305a91c82fe89a76d9accbb8faa3d81e3106341) @@ -44,34 +44,29 @@ #define RX_SIZE_UPDATE_MEASUREMENT_SETTINGS 1 #define RX_SIZE_GET_MEASUREMENT_SETTNGS ( sizeof( CONDUCTIVITY_MEASUREMENT_SETTINGS_T ) ) #define RX_SIZE_GET_MEASUREMENT ( sizeof( CONDUCTIVITY_SENSOR_DATA_T ) ) -#define RX_SIZE_STOP_MEASUREMENT 1 +#define RX_SIZE_STOP_MEASUREMENT 0 #define RX_SIZE_GET_ALL_MEASUREMENTS ( 6 * RX_SIZE_GET_MEASUREMENT ) -#define RX_SIZE_SELECT_SENSOR 1 +#define RX_SIZE_SELECT_SENSOR 0 #define RX_SIZE_GET_SINGLE_MEASUREMENT ( sizeof( CONDUCTIVITY_SENSOR_DATA_T ) ) #define COND_STATUS_TIMEOUT_MS ( 10 * MS_PER_SECOND ) ///< Timeout before which we should receive INIT_STATUS_IN_PROGRESS from teensy -#define COND_DATA_TIMEOUT_MS ( 5 * MS_PER_SECOND ) ///< Timeout before which we should receive INIT_STATUS_INITIALIZED or INIT_STATUS_FAILED from teensy +#define COND_DATA_TIMEOUT_MS ( 10 * MS_PER_SECOND ) ///< Timeout before which we should receive INIT_STATUS_INITIALIZED or INIT_STATUS_FAILED from teensy // ********** private data ********** static CONDUCTIVITY_COMM_STATE_T conductivityCommState = COND_COMM_STATE_IDLE; -static CONDUCTIVITY_COMM_STATE_T currentFailedState = COND_COMM_STATE_IDLE; static U32 condResponseTime = 0; - static U32 condReceiptCounter = 0; ///< Conductivity response receipt counter. static U32 condTransmitCounter = 0; ///< Conductivity command transmit counter. static BOOL condAutomatedDataPolling = FALSE; static BOOL condWriteCommandInProgress = FALSE; ///< Flag indicating an Conductivity write command is in progress. static BOOL condReadCommandInProgress = FALSE; ///< Flag indicating an Conductivity read command is in progress. static BOOL condBulkWriteAndReadInProgress = FALSE; ///< Flag indicating an Conductivity bulk write and read command are in progress. static BOOL condWriteCmdRspnsRcvd = FALSE; ///< Flag indicating a response to an Conductivity write command has been received. -static BOOL condReadCmdRspnsRcvd = FALSE; ///< Flag indicating a response to an Conductivity read command has been received. // Conductivity comm buffers static U08 condWriteCmdBuffer[ COND_WRITE_CMD_BUFFER_LEN ]; ///< Conductivity write command buffer. Holds the next Conductivity write command to be transmitted. static U08 condWriteResponseBuffer[ COND_WRITE_RSP_BUFFER_LEN ]; ///< Conductivity write command response buffer. Memory reserved to capture the response to the last Conductivity write command. -//static U08 condReadCmdBuffer[ COND_READ_CMD_BUFFER_LEN ]; ///< Conductivity read command buffer. Holds the next Conductivity read command to be transmitted. -//static U08 condReadResponseBuffer[ COND_READ_RSP_BUFFER_LEN ]; ///< Conductivity read command response buffer. Memory reserved to capture the response to the last Conductivity read command. static U08 condTxBuffer[ COND_TX_BUFFER_LEN ]; ///< Conductivity transmit buffer. static U08 condRxBuffer[ COND_RX_BUFFER_LEN ]; ///< Conductivity receive buffer @@ -87,8 +82,6 @@ // Conductivity DMA control records static g_dmaCTRL condDMAWriteControlRecord; ///< DMA record for controlling a DMA write command transmission from buffer. static g_dmaCTRL condDMAWriteRespControlRecord; ///< DMA record for controlling a DMA write command reception to buffer. -static g_dmaCTRL condDMAReadControlRecord; ///< DMA record for controlling a DMA read command transmission from buffer. -static g_dmaCTRL condDMAReadRespControlRecord; ///< DMA record for controlling a DMA read command reception to buffer. static CONDUCTIVITY_INIT_STATUS_T conductivityInitStatus; static CONDUCTIVITY_UPDATE_EEPROM_STATUS_T condUpdateEEPROMstatus; @@ -119,7 +112,7 @@ "rtia", "pga", "dftnum", - "avgnum" + "avgnum", }; // Conductivity cmd data structs @@ -133,30 +126,23 @@ static void initConductivityDMAchannels( void ); static void initEEPROMdata( void ); static void initMeasurementSettings( void ); + static CONDUCTIVITY_COMM_STATE_T handleConductivityIdle( void ); static CONDUCTIVITY_COMM_STATE_T handleConductivityTX( void ); static CONDUCTIVITY_COMM_STATE_T handleConductivityRX( void ); static CONDUCTIVITY_COMM_STATE_T handleFailedState( void ); + static void consumeUnexpectedConductivityData( void ); +static void setupConductivityDMAForWriteCmd( U32 bytes2Transmit ); +static void startConductivityDMAWriteCmd( void ); +static void setupConductivityDMAForWriteResp( U32 bytes2Receive ); +static void startConductivityDMAReceiptOfWriteResp( void ); static BOOL isQueueFull ( void ); static BOOL isQueueEmpty ( void ); static BOOL enqueue ( TEENSY_CMD_INDEX_T cmd ); static void dequeue( void ); -static void setupConductivityDMAForWriteCmd( U32 bytes2Transmit ); -static void startConductivityDMAWriteCmd( void ); -static void setupConductivityDMAForWriteResp( U32 bytes2Receive ); -static void startConductivityDMAReceiptOfWriteResp( void ); -static void setupConductivityDMAForReadCmd( U32 bytes2Transmit ); -static void startConductivityDMAReadCmd( void ); -static void setupConductivityDMAForReadResp( U32 bytes2Receive ); -static void startConductivityDMAReceiptOfReadResp( void ); - -static CONDUCTIVITY_PARSE_STATUS parseMeasurementSettings(const U08 *buffer, U32 len ); -static CONDUCTIVITY_PARSE_STATUS parseEEPROMdata( const U08 *buffer, U32 len ); -static CONDUCTIVITY_PARSE_STATUS parseConductivityMeasurements( const U08 *buffer, U32 len ); - static BOOL txTeensyWriteCmd( TEENSY_CMD_INDEX_T cmdIndex, const U08* param ); static BOOL rxTeensyReadRsp( TEENSY_CMD_INDEX_T cmdIndex ); @@ -193,14 +179,13 @@ static CONDUCTIVITY_COMM_STATE_T txGetSingleMeasurement( TEENSY_SENSOR_INDEX_T sensorNum ); static CONDUCTIVITY_COMM_STATE_T rxGetSingleMeasurement( TEENSY_SENSOR_INDEX_T sensorNum ); -static CONDUCTIVITY_INIT_STATUS_T getInitStatus( void ); -static const CONDUCTIVITY_EEPROM_DATA_T* getEEPROMdata( void ); -static const CONDUCTIVITY_MEASUREMENT_SETTINGS_T* getMeasurementSettings( void ); -static const CONDUCTIVITY_SENSOR_DATA_T* getSingleMeasurement( TEENSY_SENSOR_INDEX_T sensorNum ); -static const CONDUCTIVITY_SENSOR_DATA_T* getAllMeasurements( void ); +static CONDUCTIVITY_PARSE_STATUS parseMeasurementSettings(const U08 *buffer, U32 len ); +static CONDUCTIVITY_PARSE_STATUS parseEEPROMdata( const U08 *buffer, U32 len ); +static CONDUCTIVITY_PARSE_STATUS parseConductivityMeasurements( const U08 *buffer, U32 len ); -static void calculateConductivity( TEENSY_SENSOR_INDEX_T sensorNum ); -static void calculateTemperature( TEENSY_SENSOR_INDEX_T sensorNum ); +static U32 getTeensyCondId( CONDUCTIVITY_SENSORS_T sensorId ); +static void calculateConductivity( U32 sensorNum ); +static void calculateTemperature( U32 sensorNum ); void initCondTeensy( void ) @@ -212,22 +197,17 @@ condAutomatedDataPolling = FALSE; // initialize Conductivity comm buffers -// memset( &condWriteCmdBuffer, 0, COND_WRITE_CMD_BUFFER_LEN ); -// memset( &condReadCmdBuffer, 0, COND_READ_CMD_BUFFER_LEN ); - memset( &condTxBuffer, 0, COND_TX_BUFFER_LEN ); memset( &condRxBuffer, 0, COND_RX_BUFFER_LEN ); initConductivityDMAchannels(); // add init conductivity commands + enqueue( TEENSY_CMD_STOP_MEASUREMENT ); enqueue( TEENSY_CMD_INIT_SENSOR ); enqueue( TEENSY_CMD_GET_INIT_STATUS ); initEEPROMdata( ); - enqueue( TEENSY_CMD_GET_EEPROM_DATA ); initMeasurementSettings( ); - enqueue( TEENSY_CMD_GET_MEASUREMENT_SETTINGS ); - enqueue( TEENSY_CMD_GET_MEASUREMENT ); } @@ -283,42 +263,6 @@ condDMAWriteRespControlRecord.FRDOFFSET = 0; // Not used condDMAWriteRespControlRecord.FRSOFFSET = 0; // Not used -// // Initialize Conductivity DMA Read Control RecordfpgaReadCmdBuffer -// condDMAReadControlRecord.PORTASGN = 4; // Port B (only choice per datasheet) -// condDMAReadControlRecord.SADD = (U32)condRxBuffer; // Transfer source address -// condDMAReadControlRecord.DADD = (U32)(&(sciREG->TD)); // Dest. is SCI xmit register -// condDMAReadControlRecord.CHCTRL = 0; // No chaining -// condDMAReadControlRecord.ELCNT = 1; // Frame is 1 element -// condDMAReadControlRecord.FRCNT = 0; // Block is TBD frames - will be populated later when known -// condDMAReadControlRecord.RDSIZE = ACCESS_8_BIT; // Element size is 1 byte -// condDMAReadControlRecord.WRSIZE = ACCESS_8_BIT; // -// condDMAReadControlRecord.TTYPE = FRAME_TRANSFER; // Transfer type is block transfer -// condDMAReadControlRecord.ADDMODERD = ADDR_INC1; // Source addressing mode is post-increment -// condDMAReadControlRecord.ADDMODEWR = ADDR_FIXED; // Dest. addressing mode is fixed -// condDMAReadControlRecord.AUTOINIT = AUTOINIT_OFF; // Auto-init off -// condDMAReadControlRecord.ELSOFFSET = 0; // Not used -// condDMAReadControlRecord.ELDOFFSET = 0; // Not used -// condDMAReadControlRecord.FRSOFFSET = 0; // Not used -// condDMAReadControlRecord.FRDOFFSET = 0; // Not used -// -// // Initialize Conductivity DMA Read Response Control Record -// condDMAReadRespControlRecord.PORTASGN = 4; // Port B (only choice per datasheet) -// condDMAReadRespControlRecord.SADD = (U32)(&(sciREG->RD)); // Source is SCI recv register -// condDMAReadRespControlRecord.DADD = (U32)condRxBuffer; // Transfer destination address -// condDMAReadRespControlRecord.CHCTRL = 0; // No chaining -// condDMAReadRespControlRecord.ELCNT = 1; // Frame is 1 element -// condDMAReadRespControlRecord.FRCNT = 0; // Block is TBD frames - will be populated later when known -// condDMAReadRespControlRecord.RDSIZE = ACCESS_8_BIT; // Element size is 1 byte -// condDMAReadRespControlRecord.WRSIZE = ACCESS_8_BIT; // -// condDMAReadRespControlRecord.TTYPE = FRAME_TRANSFER; // Transfer type is block transfer -// condDMAReadRespControlRecord.ADDMODERD = ADDR_FIXED; // Source addressing mode is fixed -// condDMAReadRespControlRecord.ADDMODEWR = ADDR_INC1; // Dest. addressing mode is post-increment -// condDMAReadRespControlRecord.AUTOINIT = AUTOINIT_OFF; // Auto-init off -// condDMAReadRespControlRecord.ELDOFFSET = 0; // Not used -// condDMAReadRespControlRecord.ELSOFFSET = 0; // Not used -// condDMAReadRespControlRecord.FRDOFFSET = 0; // Not used -// condDMAReadRespControlRecord.FRSOFFSET = 0; // Not used - // There should not be any data pending yet consumeUnexpectedConductivityData(); } @@ -415,6 +359,13 @@ static CONDUCTIVITY_COMM_STATE_T handleConductivityIdle( void ) { CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_IDLE; + + // If we are in idle, we are expecting new data next cycle. Clear buffers + memset( &condTxBuffer, 0, COND_TX_BUFFER_LEN ); + memset( &condRxBuffer, 0, COND_RX_BUFFER_LEN ); + memset( &condWriteResponseBuffer, 0, COND_WRITE_RSP_BUFFER_LEN ); + memset( &condWriteCmdBuffer, 0, COND_WRITE_CMD_BUFFER_LEN ); + if ( !isQueueEmpty() ) { dequeue(); @@ -424,17 +375,17 @@ { // If queue is empty, q automated polling data cmd // otherwise, we are already polling data, move to recv next data packet - if ( condAutomatedDataPolling == TRUE ) + if ( ( condAutomatedDataPolling == TRUE ) && ( currentCmd != TEENSY_CMD_STOP_MEASUREMENT ) ) { - state = COND_COMM_STATE_RX; + condWriteCommandInProgress = TRUE; // set to TRUE for recv interrupt to trigger with no sent msg setupConductivityDMAForWriteResp( teensyCmdMap[ currentCmd ].rxSize ); startConductivityDMAReceiptOfWriteResp(); + state = COND_COMM_STATE_RX; } else { condAutomatedDataPolling = TRUE; enqueue( TEENSY_CMD_GET_MEASUREMENT ); - state = COND_COMM_STATE_TX; } } @@ -453,7 +404,6 @@ { CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_TX; - switch ( currentCmd ) { case TEENSY_CMD_INIT_SENSOR: @@ -478,16 +428,16 @@ state = txGetMeasurements(); break; case TEENSY_CMD_STOP_MEASUREMENT: - txStopMeasurement(); + state = txStopMeasurement(); break; case TEENSY_CMD_GET_ALL_MEASUREMENTS: - txGetAllMeasurements(); + state = txGetAllMeasurements(); break; case TEENSY_CMD_SELECT_SENSOR: - txSelectSensor( currentSelectedSensor ); + state = txSelectSensor( currentSelectedSensor ); break; case TEENSY_CMD_GET_SINGLE_MEASUREMENT: - txGetSingleMeasurement( currentSelectedSensor ); + state = txGetSingleMeasurement( currentSelectedSensor ); break; default: @@ -533,16 +483,16 @@ state = rxGetMeasurements(); break; case TEENSY_CMD_STOP_MEASUREMENT: - rxStopMeasurement(); + state = rxStopMeasurement(); break; case TEENSY_CMD_GET_ALL_MEASUREMENTS: - rxGetAllMeasurements(); + state = rxGetAllMeasurements(); break; case TEENSY_CMD_SELECT_SENSOR: - rxSelectSensor( currentSelectedSensor ); + state = rxSelectSensor( currentSelectedSensor ); break; case TEENSY_CMD_GET_SINGLE_MEASUREMENT: - rxGetSingleMeasurement( currentSelectedSensor ); + state = rxGetSingleMeasurement( currentSelectedSensor ); break; } @@ -579,21 +529,64 @@ break; default: break; - } return state; } +static void consumeUnexpectedConductivityData( void ) +{ + // Clear any errors + sciRxError( sciREG ); + + // If a byte is pending read, read it + if ( sciIsRxReady( sciREG ) != 0 ) + { + sciReceiveByte( sciREG ); + } +} + +static void setupConductivityDMAForWriteCmd( U32 bytes2Transmit ) +{ + // Verify # of bytes does not exceed buffer length + if ( bytes2Transmit <= COND_TX_BUFFER_LEN ) + { + condDMAWriteControlRecord.FRCNT = bytes2Transmit; + } +} + +static void startConductivityDMAWriteCmd( void ) +{ + dmaSetCtrlPacket( DMA_CH3, condDMAWriteControlRecord ); + dmaSetChEnable( DMA_CH3, DMA_HW ); + setSCIDMATransmitInterrupt(); +} + + +static void setupConductivityDMAForWriteResp( U32 bytes2Receive ) +{ + // Verify # of bytes does not exceed buffer length + if ( bytes2Receive <= COND_RX_BUFFER_LEN ) + { + condDMAWriteRespControlRecord.FRCNT = bytes2Receive; + } +} + +static void startConductivityDMAReceiptOfWriteResp( void ) +{ + dmaSetCtrlPacket( DMA_CH1, condDMAWriteRespControlRecord ); + dmaSetChEnable( DMA_CH1, DMA_HW ); + setSCIDMAReceiveInterrupt(); +} + /*********************************************************************//** * @brief * The signalConductivityReceiptCompleted function increments a counter to indicate * that another DMA receipt from the Conductivity has completed and sets comm flags * indicating pending response from Conductivity is completed. * @details \b Inputs: none * @details \b Outputs: condReceiptCounter, condWriteCommandInProgress, - * condWriteCmdRspnsRcvd, condReadCommandInProgress, - * condReadCmdRspnsRcvd, condBulkWriteAndReadInProgress + * condWriteCmdRspnsRcvd * @return none *************************************************************************/ void signalConductivityReceiptCompleted( void ) @@ -605,21 +598,6 @@ condWriteCommandInProgress = FALSE; condWriteCmdRspnsRcvd = TRUE; } - else if ( TRUE == condReadCommandInProgress ) - { - condReadCommandInProgress = FALSE; - condReadCmdRspnsRcvd = TRUE; - } - - // See if we want to follow up with a bulk read command - if ( TRUE == condBulkWriteAndReadInProgress ) - { - condBulkWriteAndReadInProgress = FALSE; - condReadCommandInProgress = TRUE; - // Initiate bulk read command - //startConductivityDMAReceiptOfReadResp(); - //startConductivityDMAReadCmd(); - } } /*********************************************************************//** @@ -637,36 +615,6 @@ /*********************************************************************//** * @brief - * The getImpedanceValue function gets the current calculated conductivity / - impedance value. - * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT if given sensor is invalid. - * @details \b Inputs: lastConductivityErrorCounter - * @details \b Outputs: none - * @param sensor ID of conductivity sensor to get error count for. - * @return The current conductivity sensor error count of a given conductivity sensor. - *************************************************************************/ -F64 getImpedanceValue( U32 sensorNum ) -{ - return calculatedMeasurement[sensorNum].Conductivity; -} - -/*********************************************************************//** - * @brief - * The getRTDValue function gets the current conductivity sensor - * error count for a given conductivity sensor. - * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT if given sensor is invalid. - * @details \b Inputs: lastConductivityErrorCounter - * @details \b Outputs: none - * @param sensor ID of conductivity sensor to get error count for. - * @return The current conductivity sensor error count of a given conductivity sensor. - *************************************************************************/ -F64 getRTDValue( U32 sensorNum ) -{ - return calculatedMeasurement[sensorNum].Temperature; -} - -/*********************************************************************//** - * @brief * The isQueueFull checks whether the queue is full and if it is full, * it will return a true. * @details Inputs: queueCount @@ -755,205 +703,6 @@ _enable_IRQ(); } -static void consumeUnexpectedConductivityData( void ) -{ - // Clear any errors - sciRxError( sciREG ); - - // If a byte is pending read, read it - if ( sciIsRxReady( sciREG ) != 0 ) - { - sciReceiveByte( sciREG ); - } -} - -static void setupConductivityDMAForWriteCmd( U32 bytes2Transmit ) -{ - // Verify # of bytes does not exceed buffer length - if ( bytes2Transmit <= COND_TX_BUFFER_LEN ) - { - condDMAWriteControlRecord.FRCNT = bytes2Transmit; - } -} - -static void startConductivityDMAWriteCmd( void ) -{ - dmaSetCtrlPacket( DMA_CH3, condDMAWriteControlRecord ); - dmaSetChEnable( DMA_CH3, DMA_HW ); - setSCIDMATransmitInterrupt(); -} - - -static void setupConductivityDMAForWriteResp( U32 bytes2Receive ) -{ - // Verify # of bytes does not exceed buffer length - if ( bytes2Receive <= COND_RX_BUFFER_LEN ) - { - condDMAWriteRespControlRecord.FRCNT = bytes2Receive; - } -} - -static void startConductivityDMAReceiptOfWriteResp( void ) -{ - dmaSetCtrlPacket( DMA_CH1, condDMAWriteRespControlRecord ); - dmaSetChEnable( DMA_CH1, DMA_HW ); - setSCIDMAReceiveInterrupt(); -} - -//static void setupConductivityDMAForReadCmd( U32 bytes2Transmit ) -//{ -// // Verify # of bytes does not exceed buffer length -// if ( bytes2Transmit <= COND_RX_BUFFER_LEN ) -// { -// condDMAReadControlRecord.FRCNT = bytes2Transmit; -// } -//} -// -//static void startConductivityDMAReadCmd( void ) -//{ -// dmaSetCtrlPacket( DMA_CH3, condDMAReadControlRecord ); -// dmaSetChEnable( DMA_CH3, DMA_HW ); -// setSCIDMATransmitInterrupt(); -//} -// -//static void setupConductivityDMAForReadResp( U32 bytes2Receive ) -//{ -// // Verify # of bytes does not exceed buffer length -// if ( bytes2Receive <= COND_RX_BUFFER_LEN ) -// { -// condDMAReadRespControlRecord.FRCNT = bytes2Receive; -// } -//} -//static void startConductivityDMAReceiptOfReadResp( void ) -//{ -// dmaSetCtrlPacket( DMA_CH1, condDMAReadRespControlRecord ); -// dmaSetChEnable( DMA_CH1, DMA_HW ); -// setSCIDMAReceiveInterrupt(); -//} - -/*********************************************************************//** - * @brief - * The parseMeasurementSettings Reads measurement settings from buffer and - * stores in conductivityMeasurementSettings. - * @details \b Inputs : none - * @details \b Outputs: conductivityMeasurementSettings - Measurement Settings - * @param buffer - Data to be parsed and stored. - * len - Length of the input data. - * @return CONDUCTIVITY_PARSE_STATUS to tell if parsing was successful or not. - *************************************************************************/ -static CONDUCTIVITY_PARSE_STATUS parseMeasurementSettings(const U08 *buffer, U32 len) -{ - CONDUCTIVITY_PARSE_STATUS parseStatus = CONDUCTIVITY_PARSE_NONE; - U32 expectedDataLength = sizeof(CONDUCTIVITY_MEASUREMENT_SETTINGS_T); - - // Validate buffer - if (buffer == NULL) - { - parseStatus = CONDUCTIVITY_PARSE_ERROR_NULL_BUFFER; - } - else if (len != expectedDataLength) - { - parseStatus = CONDUCTIVITY_PARSE_ERROR_INVALID_LENGTH; - } - else - { - // Parse and store the data - memcpy(&measurementSettingsRX, buffer, expectedDataLength); - parseStatus = CONDUCTIVITY_PARSE_SUCCESS; - } - - return parseStatus; -} - -/*********************************************************************//** - * @brief - * The parseEEPROMdata Reads EEPROM data from buffer and - * stores in conductivityEEPROMdata. - * @details \b Inputs : none - * @details \b Outputs: conductivityEEPROMdata - EEPROM data - * @param buffer - Data to be parsed and stored. - * len - Length of the input data. - * @return CONDUCTIVITY_PARSE_STATUS to tell if parsing was successful or not. - *************************************************************************/ -static CONDUCTIVITY_PARSE_STATUS parseEEPROMdata(const U08 *buffer, U32 len) -{ - CONDUCTIVITY_PARSE_STATUS parseStatus = CONDUCTIVITY_PARSE_NONE; - U32 expectedDataLength = sizeof(CONDUCTIVITY_EEPROM_DATA_T); - - // Validate buffer - if (buffer == NULL) - { - parseStatus = CONDUCTIVITY_PARSE_ERROR_NULL_BUFFER; - } - // Validate buffer length - else if (len != expectedDataLength) - { - parseStatus = CONDUCTIVITY_PARSE_ERROR_INVALID_LENGTH; - } - else - { - // Parse and Store the data - memcpy(&eePromDataRX, buffer, expectedDataLength); - parseStatus = CONDUCTIVITY_PARSE_SUCCESS; - } - - return parseStatus; -} - -/*********************************************************************//** - * @brief - * The parseConductivityMeasurements Reads Conductivity Measurements / Sensor readings - * from buffer and stores in rawConductivityValues. - * @details \b Inputs : none - * @details \b Outputs: rawConductivityValues - Raw Conductivity Measurements / Sensor readings - * @param buffer - Data to be parsed and stored. - * len - Length of the input data. - * @return CONDUCTIVITY_PARSE_STATUS to tell if parsing was successful or not. - *************************************************************************/ -static CONDUCTIVITY_PARSE_STATUS parseConductivityMeasurements(const U08 *buffer, U32 len) -{ - CONDUCTIVITY_PARSE_STATUS parseStatus = CONDUCTIVITY_PARSE_NONE; - - // Validate buffer - if ( NULL == buffer ) - { - parseStatus = CONDUCTIVITY_PARSE_ERROR_INVALID_SENSOR_NUM; - } - // Validate buffer length - else if ( ( len % expectedDataLength ) != 0 ) - { - parseStatus = CONDUCTIVITY_PARSE_ERROR_INVALID_LENGTH; - } - else - { - // Calculate the number of sensors for which we have received the data - sensorCount = len / expectedDataLength; - - // Parse the data and store in conductivityMeasurements[] - for ( sensorIdx = 0; sensorIdx < sensorCount; sensorIdx++ ) - { - // Read the sensor data temporarily - CONDUCTIVITY_SENSOR_DATA_T tempSensor; - memcpy( &tempSensor, ( buffer + ( sensorIdx * expectedDataLength ) ), expectedDataLength ); - - // Check if the received sensor number is valid - if ( ( tempSensor.sensorNum < 1 ) || ( tempSensor.sensorNum > MAX_TEENSY_SENSOR ) ) - { - parseStatus = CONDUCTIVITY_PARSE_ERROR_INVALID_SENSOR_NUM; - break; - } - else - { - // Store value in array index for position (sensorNum - 1) - rawConductivityValues[tempSensor.sensorNum - 1] = tempSensor; - parseStatus = CONDUCTIVITY_PARSE_SUCCESS; - } - } - } - - return parseStatus; -} - /** * @brief Writes a command (with optional parameters) to the write buffer. * @@ -963,53 +712,38 @@ */ static BOOL txTeensyWriteCmd( TEENSY_CMD_INDEX_T cmdIndex, const U08* param ) { + const U08* baseCmd = (const U08*)teensyCmdMap[ cmdIndex ].teensyCMD; BOOL success = FALSE; U16 written = 0; - // Validate command index and ensure command string exists - if ( ( cmdIndex >= MAX_NUM_OF_TEENSY_CMDS ) || - ( NULL == teensyCmdMap[ cmdIndex ].teensyCMD ) ) + // Format command with optional parameter + if ( ( NULL != param ) && ( strlen( (const char*)param ) > 0 ) ) { - success = FALSE; + written = snprintf( (char*)condTxBuffer, + COND_TX_BUFFER_LEN, + "%s,%s", + (const char*)baseCmd, + (const char*)param ); } else { - const U08* baseCmd = (const U08*)teensyCmdMap[ cmdIndex ].teensyCMD; - - // Clear the write buffer before writing - memset( &condTxBuffer, 0, COND_TX_BUFFER_LEN ); - - // Format command with optional parameter - if ( ( NULL != param ) && ( strlen( (const char*)param ) > 0 ) ) - { - written = snprintf( (char*)condTxBuffer, - COND_TX_BUFFER_LEN, - "%s,%s", - (const char*)baseCmd, - (const char*)param ); - } - else - { - written = snprintf( (char*)condTxBuffer, - COND_TX_BUFFER_LEN, - "%s", - (const char*)baseCmd ); - } + written = snprintf( (char*)condTxBuffer, + COND_TX_BUFFER_LEN, + "%s", + (const char*)baseCmd ); } if ( written > 0 ) { - memset( &condWriteCmdBuffer, 0, COND_WRITE_CMD_BUFFER_LEN ); memcpy( &condWriteCmdBuffer, &condTxBuffer, written ); success = TRUE; + condWriteCommandInProgress = TRUE; + setupConductivityDMAForWriteCmd( written ); + setupConductivityDMAForWriteResp( teensyCmdMap[ cmdIndex ].rxSize ); + startConductivityDMAReceiptOfWriteResp(); + startConductivityDMAWriteCmd(); } - condWriteCommandInProgress = TRUE; - setupConductivityDMAForWriteCmd( written ); - setupConductivityDMAForWriteResp( teensyCmdMap[ cmdIndex ].rxSize ); - - startConductivityDMAReceiptOfWriteResp(); - startConductivityDMAWriteCmd(); return success; } @@ -1025,10 +759,8 @@ if ( TRUE == condWriteCmdRspnsRcvd ) { - // Clear the read buffer before writing - memset( &condRxBuffer, 0, COND_RX_BUFFER_LEN ); memcpy( &condRxBuffer, &condWriteResponseBuffer, teensyCmdMap[ cmdIndex ].rxSize ); - memset( &condWriteResponseBuffer, 0, COND_WRITE_RSP_BUFFER_LEN ); + condWriteCmdRspnsRcvd = FALSE; success = TRUE; } @@ -1480,16 +1212,16 @@ { CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_RX; CONDUCTIVITY_PARSE_STATUS parseStatus; - // Check if a response is received in the RX buffer BOOL recvComplete = rxTeensyReadRsp( TEENSY_CMD_GET_MEASUREMENT ); + if ( TRUE == recvComplete ) { // Get the time stamp for next sensor packet condResponseTime = getMSTimerCount(); // Read the data from the receive buffer - CONDUCTIVITY_PARSE_STATUS parseStatus = parseConductivityMeasurements( condRxBuffer, COND_RX_BUFFER_LEN ); + parseStatus = parseConductivityMeasurements( condRxBuffer, COND_RX_BUFFER_LEN ); // Check if parsing was done successfully if( CONDUCTIVITY_PARSE_SUCCESS == parseStatus ) @@ -1500,14 +1232,9 @@ else { // Go to failed state - state = COND_COMM_STATE_FAILED; + state = COND_COMM_STATE_IDLE; } } - else if ( TRUE == didTimeout( condResponseTime, COND_DATA_TIMEOUT_MS ) ) - { - // Go to failed state - state = COND_COMM_STATE_FAILED; - } else { // Do Nothing. Wait until we either receive a response OR timeout happens. @@ -1523,7 +1250,9 @@ if ( TRUE == txTeensyWriteCmd( TEENSY_CMD_STOP_MEASUREMENT, NULL ) ) { - + state = COND_COMM_STATE_RX; + condAutomatedDataPolling = FALSE; + condResponseTime = getMSTimerCount(); } return state; @@ -1532,6 +1261,14 @@ static CONDUCTIVITY_COMM_STATE_T rxStopMeasurement( void ) { CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_RX; + + // Wait 1s so we can q next cmd. + // TODO wait for reply via DMA from teensy once implemented + if ( TRUE == didTimeout( condResponseTime, 1000 ) ) + { + // Go to failed state + state = COND_COMM_STATE_IDLE; + } return state; } @@ -1628,42 +1365,226 @@ CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_RX; // Check if a response is received in the RX buffer - BOOL recvComplete = rxTeensyReadRsp( TEENSY_CMD_GET_SINGLE_MEASUREMENT ); - if ( TRUE == recvComplete ) - { - // Reset the timer for next use. - condResponseTime = 0; + BOOL recvComplete = rxTeensyReadRsp( TEENSY_CMD_GET_SINGLE_MEASUREMENT ); + if ( TRUE == recvComplete ) + { + // Reset the timer for next use. + condResponseTime = 0; - // Read the data from the receive buffer - CONDUCTIVITY_PARSE_STATUS parseStatus = parseConductivityMeasurements( condRxBuffer, COND_RX_BUFFER_LEN ); + // Read the data from the receive buffer + CONDUCTIVITY_PARSE_STATUS parseStatus = parseConductivityMeasurements( condRxBuffer, COND_RX_BUFFER_LEN ); - // Check if parsing was done successfully - if(CONDUCTIVITY_PARSE_SUCCESS == parseStatus) - { - // Go to the idle state to execute next cmd in the queue - state = COND_COMM_STATE_IDLE; - } - else - { - // Go to failed state - state = COND_COMM_STATE_FAILED; - } + // Check if parsing was done successfully + if(CONDUCTIVITY_PARSE_SUCCESS == parseStatus) + { + // Go to the idle state to execute next cmd in the queue + state = COND_COMM_STATE_IDLE; } - else if ( TRUE == didTimeout( condResponseTime, COND_DATA_TIMEOUT_MS ) ) + else { // Go to failed state state = COND_COMM_STATE_FAILED; } + } + else if ( TRUE == didTimeout( condResponseTime, COND_DATA_TIMEOUT_MS ) ) + { + // Go to failed state + state = COND_COMM_STATE_FAILED; + } + else + { + // Do Nothing. Wait until we either receive a response OR timeout happens. + } + + return state; +} + +/*********************************************************************//** + * @brief + * The parseMeasurementSettings Reads measurement settings from buffer and + * stores in conductivityMeasurementSettings. + * @details \b Inputs : none + * @details \b Outputs: conductivityMeasurementSettings - Measurement Settings + * @param buffer - Data to be parsed and stored. + * len - Length of the input data. + * @return CONDUCTIVITY_PARSE_STATUS to tell if parsing was successful or not. + *************************************************************************/ +static CONDUCTIVITY_PARSE_STATUS parseMeasurementSettings(const U08 *buffer, U32 len) +{ + CONDUCTIVITY_PARSE_STATUS parseStatus = CONDUCTIVITY_PARSE_NONE; + U32 expectedDataLength = sizeof(CONDUCTIVITY_MEASUREMENT_SETTINGS_T); + + // Validate buffer + if (buffer == NULL) + { + parseStatus = CONDUCTIVITY_PARSE_ERROR_NULL_BUFFER; + } + else if (len != expectedDataLength) + { + parseStatus = CONDUCTIVITY_PARSE_ERROR_INVALID_LENGTH; + } + else + { + // Parse and store the data + memcpy(&measurementSettingsRX, buffer, expectedDataLength); + parseStatus = CONDUCTIVITY_PARSE_SUCCESS; + } + + return parseStatus; +} + +/*********************************************************************//** + * @brief + * The parseEEPROMdata Reads EEPROM data from buffer and + * stores in conductivityEEPROMdata. + * @details \b Inputs : none + * @details \b Outputs: conductivityEEPROMdata - EEPROM data + * @param buffer - Data to be parsed and stored. + * len - Length of the input data. + * @return CONDUCTIVITY_PARSE_STATUS to tell if parsing was successful or not. + *************************************************************************/ +static CONDUCTIVITY_PARSE_STATUS parseEEPROMdata(const U08 *buffer, U32 len) +{ + CONDUCTIVITY_PARSE_STATUS parseStatus = CONDUCTIVITY_PARSE_NONE; + U32 expectedDataLength = sizeof(CONDUCTIVITY_EEPROM_DATA_T); + + // Validate buffer + if (buffer == NULL) + { + parseStatus = CONDUCTIVITY_PARSE_ERROR_NULL_BUFFER; + } + // Validate buffer length + else if (len != expectedDataLength) + { + parseStatus = CONDUCTIVITY_PARSE_ERROR_INVALID_LENGTH; + } + else + { + // Parse and Store the data + memcpy(&eePromDataRX, buffer, expectedDataLength); + parseStatus = CONDUCTIVITY_PARSE_SUCCESS; + } + + return parseStatus; +} + +/*********************************************************************//** + * @brief + * The parseConductivityMeasurements Reads Conductivity Measurements / Sensor readings + * from buffer and stores in rawConductivityValues. + * @details \b Inputs : none + * @details \b Outputs: rawConductivityValues - Raw Conductivity Measurements / Sensor readings + * @param buffer - Data to be parsed and stored. + * len - Length of the input data. + * @return CONDUCTIVITY_PARSE_STATUS to tell if parsing was successful or not. + *************************************************************************/ +static CONDUCTIVITY_PARSE_STATUS parseConductivityMeasurements(const U08 *buffer, U32 len) +{ + CONDUCTIVITY_PARSE_STATUS parseStatus = CONDUCTIVITY_PARSE_NONE; + CONDUCTIVITY_SENSOR_DATA_T tempSensor; + + // Validate buffer + if ( NULL == buffer ) + { + parseStatus = CONDUCTIVITY_PARSE_ERROR_INVALID_SENSOR_NUM; + } + else + { + // Read the sensor data temporarily + memcpy( &tempSensor, buffer, teensyCmdMap[ currentCmd ].rxSize ); + + // Check if the received sensor number is valid + if ( ( tempSensor.sensorNum < 1 ) || ( tempSensor.sensorNum > MAX_TEENSY_SENSOR ) ) + { + parseStatus = CONDUCTIVITY_PARSE_ERROR_INVALID_SENSOR_NUM; + } else { - // Do Nothing. Wait until we either receive a response OR timeout happens. + // Store value in array index for position (sensorNum - 1) + rawConductivityValues[tempSensor.sensorNum - 1] = tempSensor; + calculateConductivity( tempSensor.sensorNum - 1 ); + calculateTemperature( tempSensor.sensorNum - 1 ); + parseStatus = CONDUCTIVITY_PARSE_SUCCESS; } + } - return state; + return parseStatus; } -static void calculateConductivity( TEENSY_SENSOR_INDEX_T sensorNum ) +static U32 getTeensyCondId( CONDUCTIVITY_SENSORS_T sensorId ) { + U32 sensorNum = 0; + + switch ( sensorId ) + { + case P9_COND: + sensorNum = TEENSY_SENSOR_0; + break; + case P18_COND: + sensorNum = TEENSY_SENSOR_1; + break; + case D17_COND: + sensorNum = TEENSY_SENSOR_2; + break; + case D27_COND: + sensorNum = TEENSY_SENSOR_3; + break; + case D29_COND: + sensorNum = TEENSY_SENSOR_4; + break; + case D43_COND: + sensorNum = TEENSY_SENSOR_5; + break; + } + + return sensorNum; +} +/*********************************************************************//** + * @brief + * The getConductivityValue function gets the current calculated conductivity / + impedance value. + * @details \b Inputs: calculatedMeasurement + * @details \b Outputs: none + * @param sensor ID of conductivity sensor to get conductivity. + * @return The current conductivity sensor conductivity of a given conductivity sensor. + *************************************************************************/ +F32 getTeensyConductivityValue( CONDUCTIVITY_SENSORS_T sensorId ) +{ + U32 sensorNum = getTeensyCondId( sensorId ); + F32 result = 0.0F; + + if ( D74_COND != sensorId ) + { + result = (F32)calculatedMeasurement[sensorNum].Conductivity; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getTemperatureValue function gets the current conductivity sensor + * temperature for a given conductivity sensor. + * @details \b Inputs: calculatedMeasurement + * @details \b Outputs: none + * @param sensorId ID of conductivity sensor to get temperature. + * @return The current conductivity sensor temperature of a given conductivity sensor. + *************************************************************************/ +F32 getTeensyConductivityTemperatureValue( CONDUCTIVITY_SENSORS_T sensorId ) +{ + U32 sensorNum = getTeensyCondId( sensorId ); + F32 result = 0.0F; + + if ( D74_COND != sensorId ) + { + result = (F32)calculatedMeasurement[sensorNum].Temperature; + } + + return result; +} + +static void calculateConductivity( U32 sensorNum ) +{ F64 calculatedConductivity = 0.0; F64 B3 = conductivityCoeff[ sensorNum ].B3; F64 B2 = conductivityCoeff[ sensorNum ].B2; @@ -1682,7 +1603,7 @@ } -static void calculateTemperature( TEENSY_SENSOR_INDEX_T sensorNum ) +static void calculateTemperature( U32 sensorNum ) { F64 calculatedTemperature = 0.0; F64 A1 = conductivityCoeff[ sensorNum ].A1; @@ -1695,4 +1616,7 @@ } +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ Index: firmware/App/Drivers/ConductivityTeensy.h =================================================================== diff -u -r7aafdc16c133bcd4cb0ce5fe08079c1969cc67d2 -rd305a91c82fe89a76d9accbb8faa3d81e3106341 --- firmware/App/Drivers/ConductivityTeensy.h (.../ConductivityTeensy.h) (revision 7aafdc16c133bcd4cb0ce5fe08079c1969cc67d2) +++ firmware/App/Drivers/ConductivityTeensy.h (.../ConductivityTeensy.h) (revision d305a91c82fe89a76d9accbb8faa3d81e3106341) @@ -24,6 +24,23 @@ #define DOUBLE_COUNT 8 ///< Number of double values in Teensy EEPROM data #define FLOAT_COUNT 16 ///< Number of float values in Teensy EEPROM data +/// Enumeration of conductivity sensors. +typedef enum ConductivitySensors +{ + D17_COND = 0, ///< Bicarb only conductivity sensor - 1 + FIRST_DD_COND_SENSOR = D17_COND, ///< First conductivity sensor + D27_COND, ///< Acid and Bicarb mix conductivity sensor - 1 + D29_COND, ///< Acid and Bicarb mix conductivity sensor - 2 + D43_COND, ///< Spent dialysate conductivity sensor + D74_COND, ///< Bicarb only conductivity sensor - 2 + LAST_DD_COND_SENSOR = D74_COND, ///< Last conductivity sensor + P9_COND, ///< Inlet water conductivity sensor + FIRST_FP_COND_SENSOR = P9_COND, ///< First FP conductivity sensor + P18_COND, ///< RO outlet water conductivity sensor + LAST_FP_COND_SENSOR = P18_COND, ///< Last FP conductivity sensor + NUM_OF_CONDUCTIVITY_SENSORS ///< Number of conductivity sensors +} CONDUCTIVITY_SENSORS_T; + typedef enum TeensySensorIndex { TEENSY_SENSOR_0 = 0, ///< Maps to P9_COND @@ -180,7 +197,7 @@ void signalConductivityReceiptCompleted( void ); void signalConductivityTransmitCompleted( void ); void addToCmdQ(U08 teensyCmd); -F64 getImpedanceValue( U32 sensorNum ); -F64 getRTDValue( U32 sensorNum ); +F32 getTeensyConductivityValue( CONDUCTIVITY_SENSORS_T sensorId ); +F32 getTeensyConductivityTemperatureValue( CONDUCTIVITY_SENSORS_T sensorId ); #endif /* _CONDUCTIVITY_TEENSY_H_ */ Index: firmware/App/Modes/ModeGenDialysate.c =================================================================== diff -u -r2e0901de8e802fe4c567b0164238bf324014c1cf -rd305a91c82fe89a76d9accbb8faa3d81e3106341 --- firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision 2e0901de8e802fe4c567b0164238bf324014c1cf) +++ firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision d305a91c82fe89a76d9accbb8faa3d81e3106341) @@ -929,7 +929,11 @@ *************************************************************************/ static void checkDialysateTemperature( void ) { +#ifdef __TEENSY_CONDUCTIVITY_DRIVER__ + F32 dialysateTemp = getTeensyConductivityTemperatureValue( D29_COND ); // Assuming the closest temp sensor to dialyzer +#else F32 dialysateTemp = getConductivityTemperatureValue( D29_COND ); // Assuming the closest temp sensor to dialyzer +#endif F32 targetTemp = getTDTargetDialysateTemperature(); BOOL isDialTempAboveHighSafety = ( dialysateTemp >= DIALYSATE_TEMP_UPPER_MAX_SAFETY_LIMIT_C ? TRUE : FALSE ); BOOL isDialTempAboveLowSafety = ( dialysateTemp > DIALYSATE_TEMP_UPPER_SAFETY_LIMIT_C ? TRUE : FALSE ); Index: firmware/App/Monitors/Conductivity.c =================================================================== diff -u -r7aafdc16c133bcd4cb0ce5fe08079c1969cc67d2 -rd305a91c82fe89a76d9accbb8faa3d81e3106341 --- firmware/App/Monitors/Conductivity.c (.../Conductivity.c) (revision 7aafdc16c133bcd4cb0ce5fe08079c1969cc67d2) +++ firmware/App/Monitors/Conductivity.c (.../Conductivity.c) (revision d305a91c82fe89a76d9accbb8faa3d81e3106341) @@ -18,7 +18,6 @@ #include // For memcpy #include "Conductivity.h" -#include "ConductivityTeensy.h" #include "MessageSupport.h" #include "Messaging.h" #include "OperationModes.h" @@ -68,16 +67,6 @@ static U32 fpConductivityPublishTimerCounter; ///< FP Conductivity data publication counter. static OVERRIDE_U32_T fpConductivityDataPublishInterval; ///< FP Conductivity sensors publish time interval override. -static const CONDUCTIVITY_SENSORS_T teensyCondMap[] = -{ - P9_COND, - P18_COND, - D17_COND, - D27_COND, - D29_COND, - D43_COND, -}; - // ********** private function prototypes ********** static void publishConductivitySensorsData( void ); @@ -96,7 +85,8 @@ { CONDUCTIVITY_SENSORS_T sensor; - initConductivitySensors(); + //initConductivitySensors(); + initCondTeensy(); ddConductivityPublishTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; fpConductivityPublishTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; @@ -146,8 +136,12 @@ void execConductivity( void ) { //read conductivity sensors raw value +#ifdef __TEENSY_CONDUCTIVITY_DRIVER__ + execConductivityTeensy(); +#else readConductivitySensors(); +#endif //control conductivity sensor // TODO : need more clarity on why and when to execute following control. #if 0 @@ -157,8 +151,6 @@ execConductivitySensorRead(); #endif - execConductivityTeensy(); - filterConductivitySensors(); // publish conductivity sensors publishConductivitySensorsData(); @@ -224,7 +216,11 @@ for ( sensor = FIRST_DD_COND_SENSOR; sensor < NUM_OF_CONDUCTIVITY_SENSORS; sensor++ ) { - F32 rawCond = (F32)getConductivityValue( sensor ); +#ifdef __TEENSY_CONDUCTIVITY_DRIVER__ + F32 rawCond = getTeensyConductivityValue( sensor ); +#else + F32 rawCond = getConductivityValue( sensor ); +#endif // TODO - calibrate @@ -284,7 +280,11 @@ for ( sensor = FIRST_DD_COND_SENSOR; sensor < NUM_OF_CONDUCTIVITY_SENSORS; sensor++ ) { - F32 rawTemp = (F32)getConductivityTemperatureValue( sensor ); +#ifdef __TEENSY_CONDUCTIVITY_DRIVER__ + F32 rawTemp = getTeensyConductivityTemperatureValue( sensor ); +#else + F32 rawTemp = getConductivityTemperatureValue( sensor ); +#endif // TODO - calibrate @@ -317,11 +317,11 @@ { DD_CONDUCTIVITY_DATA_T data; - data.d17Cond = getConductivityValue( D17_COND ); - data.d27Cond = getConductivityValue( D27_COND ); - data.d29Cond = getConductivityValue( D29_COND ); - data.d43Cond = getConductivityValue( D43_COND ); - data.d74Cond = getConductivityValue( D74_COND ); + data.d17Cond = getFilteredConductivity( D17_COND ); + data.d27Cond = getFilteredConductivity( D27_COND ); + data.d29Cond = getFilteredConductivity( D29_COND ); + data.d43Cond = getFilteredConductivity( D43_COND ); + data.d74Cond = getFilteredConductivity( D74_COND ); ddConductivityPublishTimerCounter = 0; broadcastData( MSG_ID_DD_CONDUCTIVITY_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( DD_CONDUCTIVITY_DATA_T ) ); Index: firmware/App/Monitors/Conductivity.h =================================================================== diff -u -r89f18a07a6d5837bf9b4559a69046e2b06f32c35 -rd305a91c82fe89a76d9accbb8faa3d81e3106341 --- firmware/App/Monitors/Conductivity.h (.../Conductivity.h) (revision 89f18a07a6d5837bf9b4559a69046e2b06f32c35) +++ firmware/App/Monitors/Conductivity.h (.../Conductivity.h) (revision d305a91c82fe89a76d9accbb8faa3d81e3106341) @@ -19,7 +19,11 @@ #define __CONDUCTIVITY_H__ #include "DDCommon.h" -#include "ConductivitySensors.h" +#ifdef __TEENSY_CONDUCTIVITY_DRIVER__ +#include "ConductivityTeensy.h" +#else +#include "ConductivitySensor.h" +#endif /** * @defgroup Conductivity Conductivity Index: firmware/App/Monitors/Temperature.c =================================================================== diff -u -r325e67dab10f6666702bf0f1256015b31e58de4f -rd305a91c82fe89a76d9accbb8faa3d81e3106341 --- firmware/App/Monitors/Temperature.c (.../Temperature.c) (revision 325e67dab10f6666702bf0f1256015b31e58de4f) +++ firmware/App/Monitors/Temperature.c (.../Temperature.c) (revision d305a91c82fe89a76d9accbb8faa3d81e3106341) @@ -16,7 +16,11 @@ ***************************************************************************/ #include "BalancingChamber.h" -#include "ConductivitySensors.h" +#ifdef __TEENSY_CONDUCTIVITY_DRIVER__ +#include "ConductivityTeensy.h" +#else +#include "ConductivitySensor.h" +#endif #include "Conductivity.h" #include "Flow.h" #include "Messaging.h" @@ -347,7 +351,11 @@ else if ( TRUE == didTimeout( dialTempMovingAvgData[ i ].dialTempDataColStartTimeMS, D28_D30_DATA_COLLECTION_TIME_MS ) ) { CONDUCTIVITY_SENSORS_T sensor = ( DIAL_TEMP_D28 == i ? D27_COND : D29_COND ); +#ifdef __TEENSY_CONDUCTIVITY_DRIVER__ + F32 temperatureC = getTeensyConductivityTemperatureValue( sensor ); +#else F32 temperatureC = getConductivityTemperatureValue( sensor ); +#endif U32 currentIndex = dialTempMovingAvgData[ i ].dialTempSamplesNextIndex; F32 prevSampleToRemoveC = dialTempMovingAvgData[ i ].dialTempSamplesC[ currentIndex ]; @@ -467,11 +475,19 @@ // TODO: update the following lines after Baro Sensor data is read from TD data.baroTemp = 0.0F; // data.baroTemp = getTemperatureValue( BARO_TEMP ); +#ifdef __TEENSY_CONDUCTIVITY_DRIVER__ + data.d16CondTemp = getTeensyConductivityTemperatureValue( D17_COND ); + data.d28CondTemp = getTeensyConductivityTemperatureValue( D27_COND ); + data.d30CondTemp = getTeensyConductivityTemperatureValue( D29_COND ); + data.d44CondTemp = getTeensyConductivityTemperatureValue( D43_COND ); + data.d75CondTemp = getTeensyConductivityTemperatureValue( D74_COND ); +#else data.d16CondTemp = getConductivityTemperatureValue( D17_COND ); data.d28CondTemp = getConductivityTemperatureValue( D27_COND ); data.d30CondTemp = getConductivityTemperatureValue( D29_COND ); data.d44CondTemp = getConductivityTemperatureValue( D43_COND ); data.d75CondTemp = getConductivityTemperatureValue( D74_COND ); +#endif data.d4AvgTemp = getD4AverageTemperature(); data.d50AvgTemp = getD50AverageTemperature(); data.d28AvgTemp = dialTempMovingAvgData[ DIAL_TEMP_D28 ].dialTempAvgC; Index: firmware/App/Services/Messaging.c =================================================================== diff -u -r0bd88516052944cca76c6eb6ef4be851929e1215 -rd305a91c82fe89a76d9accbb8faa3d81e3106341 --- firmware/App/Services/Messaging.c (.../Messaging.c) (revision 0bd88516052944cca76c6eb6ef4be851929e1215) +++ firmware/App/Services/Messaging.c (.../Messaging.c) (revision d305a91c82fe89a76d9accbb8faa3d81e3106341) @@ -123,11 +123,18 @@ { MSG_ID_DD_PRESSURE_SENSOR_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testDDPressureSensorDataPublishIntervalOverride }, { MSG_ID_DD_PRESSURE_SENSOR_FILTER_READINGS_OVERRIDE_REQUEST, &testDDPressureSensorFilteredReadingsOverride }, { MSG_ID_DD_PRESSURE_SENSOR_FILTER_TEMPERATURE_OVERRIDE_REQUEST, &testDDPressureSensorFilteredTemperatureReadingsOverride }, +#ifndef __TEENSY_CONDUCTIVITY_DRIVER__ { MSG_ID_DD_CONDUCTIVITY_SENSOR_READINGS_OVERRIDE_REQUEST, &testDDConductivitySensorReadingsOverride }, { MSG_ID_DD_CONDUCTIVITY_SENSOR_TEMPERATURE_OVERRIDE_REQUEST, &testDDConductivitySensorTemperatureReadingsOverride }, { MSG_ID_DD_CONDUCTIVITY_SENSOR_READ_COUNTER_OVERRIDE_REQUEST, &testDDConductivitySensorReadCounterOverride }, { MSG_ID_DD_CONDUCTIVITY_SENSOR_ERROR_COUNTER_OVERRIDE_REQUEST, &testDDConductivitySensorErrorCounterOverride }, { MSG_ID_DD_CONDUCTIVITY_SENSOR_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testDDConductivitySensorDataPublishIntervalOverride }, + { MSG_ID_FP_CONDUCTIVITY_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testFPConductivitySensorDataPublishIntervalOverride }, + { MSG_ID_FP_CONDUCTIVITY_OVERRIDE_REQUEST, &testFPConductivitySensorReadingsOverride }, + { MSG_ID_FP_CONDUCTIVITY_TEMP_OVERRIDE_REQUEST, &testFPConductivitySensorTemperatureReadingsOverride }, + { MSG_ID_FP_CONDUCTIVITY_READ_COUNT_OVERRIDE_REQUEST, &testFPConductivitySensorReadCounterOverride }, + { MSG_ID_FP_CONDUCTIVITY_ERROR_COUNT_OVERRIDE_REQUEST, &testFPConductivitySensorErrorCounterOverride }, +#endif { MSG_ID_DD_CONCENTRATE_PUMP_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testConcentratePumpDataPublishIntervalOverride }, { MSG_ID_DD_CONCENTRATE_PUMP_TARGET_SPEED_OVERRIDE_REQUEST, &testConcentratePumpTargetSpeedOverride }, { MSG_ID_DD_CONCENTRATE_PUMP_MEASURED_SPEED_OVERRIDE_REQUEST, &testConcentratePumpMeasuredSpeedOverride }, @@ -223,11 +230,6 @@ { MSG_ID_FP_FILTERED_FLOW_TEMP_OVERRIDE_REQUEST, &testFlowSensorFilteredTemperatureReadingsOverride }, { MSG_ID_FP_ALARM_STATE_OVERRIDE_REQUEST, &testAlarmStateOverride }, { MSG_ID_FP_ALARM_CLEAR_ALL_ALARMS_REQUEST, &testFPClearAllAlarms }, - { MSG_ID_FP_CONDUCTIVITY_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testFPConductivitySensorDataPublishIntervalOverride }, - { MSG_ID_FP_CONDUCTIVITY_OVERRIDE_REQUEST, &testFPConductivitySensorReadingsOverride }, - { MSG_ID_FP_CONDUCTIVITY_TEMP_OVERRIDE_REQUEST, &testFPConductivitySensorTemperatureReadingsOverride }, - { MSG_ID_FP_CONDUCTIVITY_READ_COUNT_OVERRIDE_REQUEST, &testFPConductivitySensorReadCounterOverride }, - { MSG_ID_FP_CONDUCTIVITY_ERROR_COUNT_OVERRIDE_REQUEST, &testFPConductivitySensorErrorCounterOverride }, { MSG_ID_FP_FILTERED_COND_SENSOR_READINGS_OVERRIDE_REQUEST, &testFPConductivitySensorFilteredReadingsOverride }, { MSG_ID_FP_FILTERED_COND_SENSOR_TEMPERATURE_OVERRIDE_REQUEST, &testFPConductivitySensorFilteredTemperatureReadingsOverride }, { MSG_ID_DD_VOLTAGE_DATA_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testVoltageDataPublishIntervalOverride },