Index: firmware/App/Drivers/ConductivitySensors.c =================================================================== diff -u -r89c78ab89ac3909d5fe74f491f6f3b3cadd0ccf8 -rd48829521f698f5fe55157bc688ca196a9376faa --- firmware/App/Drivers/ConductivitySensors.c (.../ConductivitySensors.c) (revision 89c78ab89ac3909d5fe74f491f6f3b3cadd0ccf8) +++ firmware/App/Drivers/ConductivitySensors.c (.../ConductivitySensors.c) (revision d48829521f698f5fe55157bc688ca196a9376faa) @@ -18,6 +18,7 @@ #include // For memcpy #include "ConductivitySensors.h" +#include "ConductivityTeensy.h" #include "FpgaDD.h" #include "MessageSupport.h" #include "Messaging.h" @@ -80,13 +81,6 @@ static CONDUCTIVITY_SENSOR_CONTROL_T conductivitySensorControl[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Conductivity sensor Control for reset, init, read and write operations. -static CONDUCTIVITY_INIT_STATUS_T conductivityInitStatus; -static CONDUCTIVITY_EEPROM_DATA_T conductivityEEPROMdata; -static CONDUCTIVITY_MEASUREMENT_SETTINGS_T conductivityMeasurementSettings; -static CONDUCTIVITY_SENSOR_DATA_T rawConductivityValues[ MAX_TEENSY_SENSOR ]; -static CONDUCTIVITY_CALCULATED_MEASUREMENTS_T calculatedMeasurement[ MAX_TEENSY_SENSOR ]; -static CONDUCTIVITY_COEFFICIENTS_T conductivityCoeff[MAX_TEENSY_SENSOR]; - static const TEENSY_SENSOR_INDEX_T teensySensorMapping[NUM_OF_CONDUCTIVITY_SENSORS] = { [D17_COND] = TEENSY_SENSOR_0, [D27_COND] = TEENSY_SENSOR_1, @@ -96,45 +90,14 @@ [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 CONDUCTIVITY_PARSE_STATUS parseMeasurementSettings(const U32 *buffer, U32 len ); -static CONDUCTIVITY_PARSE_STATUS parseEEPROMdata( const U32 *buffer, U32 len ); -static CONDUCTIVITY_PARSE_STATUS parseConductivityMeasurements( const U32 *buffer, U32 len ); - -static void sendCmd_getInitStatus( void ); -static void sendCmd_updateEEPROMdata( CONDUCTIVITY_EEPROM_DATA_T eepromData); -static void sendCmd_getEEPROMdata( void ); -static void sendCmd_updateMeasurementSettings( CONDUCTIVITY_MEASUREMENT_SETTINGS_T measurememtSettings ); -static void sendCmd_getMeasurementSettings( void ); -static void sendCmd_getSingleMeasurement( CONDUCTIVITY_SENSORS_T sensorID ); -static void sendCmd_getAllMeasurements( void ); - -static void receiveResponse_getInitStatus( void ); -static void receiveResponse_updateEEPROMdata( void ); -static void receiveResponse_getEEPROMdata( void ); -static void receiveResponse_updateMeasurementSettings( void ); -static void receiveResponse_getMeasurementSettings( void ); -static void receiveResponse_getSingleMeasurement( CONDUCTIVITY_SENSORS_T sensorID ); -static void receiveResponse_getAllMeasurements( void ); - -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( CONDUCTIVITY_SENSORS_T sensorID ); -static const CONDUCTIVITY_SENSOR_DATA_T* getAllMeasurements( void ); - -static void calculateConductivity( CONDUCTIVITY_SENSORS_T sensorID ); -static void calculateTemperature( CONDUCTIVITY_SENSORS_T sensorID ); static TEENSY_SENSOR_INDEX_T getTeensySensorNum( CONDUCTIVITY_SENSORS_T sensorID ); - /*********************************************************************//** * @brief * The initConductivitySensors function initializes the ConductivitySensors unit. @@ -193,8 +156,11 @@ initFPGAPersistentAlarm( FPGA_PERS_ERROR_D74_COND_SENSOR, ALARM_ID_DD_D74_COND_SENSOR_FPGA_FAULT, COND_SENSORS_FPGA_ERROR_TIMEOUT_MS, COND_SENSORS_FPGA_ERROR_TIMEOUT_MS ); //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 ); + + initConductivityDMAchannels(); } + /*********************************************************************//** * @brief * The readConductivitySensors function gets the current conductivity reading @@ -410,36 +376,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 requestConductivitySensorReset function commands the given * the conductivity sensor to go for reset. * @details \b Inputs: none @@ -1066,277 +1002,6 @@ 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 U32 *buffer, U32 len ) -{ - CONDUCTIVITY_PARSE_STATUS parseStatus = CONDUCTIVITY_PARSE_SUCCESS; - U32 expectedDataLength = sizeof( CONDUCTIVITY_MEASUREMENT_SETTINGS_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( &conductivityMeasurementSettings, buffer, expectedDataLength ); - } - - 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 U32 *buffer, U32 len ) -{ - CONDUCTIVITY_PARSE_STATUS parseStatus = CONDUCTIVITY_PARSE_SUCCESS; - 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( &conductivityEEPROMdata, buffer, expectedDataLength ); - } - - 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 U32 *buffer, U32 len ) -{ - CONDUCTIVITY_PARSE_STATUS parseStatus = CONDUCTIVITY_PARSE_SUCCESS; - U32 expectedDataLength = sizeof( CONDUCTIVITY_SENSOR_DATA_T ); - U32 sensorCount = 0; - U16 sensorIdx = 0; - - // // Validate buffer - if ( NULL == buffer ) - { - parseStatus = CONDUCTIVITY_PARSE_ERROR_NULL_BUFFER; - } - - // 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 ); - - // And check if the received sensor number id valid - if ( (tempSensor.sensorNum < 1 ) || - ( tempSensor.sensorNum > MAX_TEENSY_SENSOR ) ) - { - parseStatus = CONDUCTIVITY_PARSE_ERROR_INVALID_SENSOR_NUM; - break; - } - else - { - // The received data value contains sensor values from 1 to 6. - // So store value in array index for position (sensorNum - 1) i.e. 0 to 5. - rawConductivityValues[tempSensor.sensorNum - 1] = tempSensor; - } - } - } - - return parseStatus; -} - -static void sendCmd_getInitStatus( void ) -{ - -} - -static void sendCmd_updateEEPROMdata(CONDUCTIVITY_EEPROM_DATA_T eepromData) -{ - -} - -static void sendCmd_getEEPROMdata( void ) -{ - -} - -static void sendCmd_updateMeasurementSettings( CONDUCTIVITY_MEASUREMENT_SETTINGS_T measurememtSettings ) -{ - -} - -static void sendCmd_getMeasurementSettings( void ) -{ - -} - -static void sendCmd_getSingleMeasurement( CONDUCTIVITY_SENSORS_T sensorID ) -{ - TEENSY_SENSOR_INDEX_T sensorNum = getTeensySensorNum(sensorID); -} - -static void sendCmd_getAllMeasurements( void ) -{ - -} - - -static void receiveResponse_getInitStatus( void ) -{ - -} - -static void receiveResponse_updateEEPROMdata( void ) -{ - -} - -static void receiveResponse_getEEPROMdata( void ) -{ - -} - -static void receiveResponse_updateMeasurementSettings( void ) -{ - -} - -static void receiveResponse_getMeasurementSettings( void ) -{ - -} - -static void receiveResponse_getSingleMeasurement( CONDUCTIVITY_SENSORS_T sensorID ) -{ - TEENSY_SENSOR_INDEX_T sensorNum = getTeensySensorNum(sensorID); -} - -static void receiveResponse_getAllMeasurements( void ) -{ - -} - -static CONDUCTIVITY_INIT_STATUS_T getInitStatus( void ) -{ - sendInitStatusCommand(); - receiveInitStatusResponse(); - return conductivityInitStatus; -} - -static const CONDUCTIVITY_EEPROM_DATA_T* getEEPROMdata(void) -{ - return &conductivityEEPROMdata; -} - - -static const CONDUCTIVITY_MEASUREMENT_SETTINGS_T* getMeasurementSettings(void) -{ - return &conductivityMeasurementSettings; -} - -static const CONDUCTIVITY_SENSOR_DATA_T* getSingleMeasurement( CONDUCTIVITY_SENSORS_T sensorID ) -{ - const CONDUCTIVITY_SENSOR_DATA_T* result = NULL; - - TEENSY_SENSOR_INDEX_T sensorNum = getTeensySensorNum( sensorID ); - - if (sensorNum < MAX_TEENSY_SENSOR) - { - result = &rawConductivityValues[ sensorNum ]; - } - - return result; -} - - - -static const CONDUCTIVITY_SENSOR_DATA_T* getAllMeasurements( void ) -{ - return rawConductivityValues; -} - -static void calculateConductivity( CONDUCTIVITY_SENSORS_T sensorID ) -{ - TEENSY_SENSOR_INDEX_T sensorNum = getTeensySensorNum( sensorID ); - F64 calculatedConductivity = 0.0; - F64 B3 = conductivityCoeff[ sensorNum ].B3; - F64 B2 = conductivityCoeff[ sensorNum ].B2; - F64 B1 = conductivityCoeff[ sensorNum ].B1; - F64 B0 = conductivityCoeff[ sensorNum ].B0; - F64 R = rawConductivityValues[ sensorNum ].impRzMag; - F64 Z = rawConductivityValues[ sensorNum ].rtdRzMag; - - calculatedConductivity = ( ( B3 * ( 1000.0 / R ) ) + - ( B2 * ( Z / R ) ) + - ( B1 * ( ( 100 * log( Z ) ) / R ) ) + - B0 - ); - - calculatedMeasurement[sensorNum].Conductivity = calculatedConductivity; - -} - -static void calculateTemperature( CONDUCTIVITY_SENSORS_T sensorID ) -{ - TEENSY_SENSOR_INDEX_T sensorNum = getTeensySensorNum( sensorID ); - F64 calculatedTemperature = 0.0; - F64 A1 = conductivityCoeff[ sensorNum ].A1; - F64 A0 = conductivityCoeff[ sensorNum ].A0; - F64 Z = rawConductivityValues[ sensorNum ].rtdRzMag; - - calculatedTemperature = ( ( A1 * Z ) + A0 ); - - calculatedMeasurement[sensorNum].Temperature = calculatedTemperature; -} - static TEENSY_SENSOR_INDEX_T getTeensySensorNum( CONDUCTIVITY_SENSORS_T sensorID ) { if ( sensorID >= NUM_OF_CONDUCTIVITY_SENSORS )