Index: firmware/App/Drivers/ConductivityTeensy.c =================================================================== diff -u -r11dbd4210f75d1587be89117e60409cf1b4d1085 -r1768e1d302978a3748ab1e684576f208472e4a54 --- firmware/App/Drivers/ConductivityTeensy.c (.../ConductivityTeensy.c) (revision 11dbd4210f75d1587be89117e60409cf1b4d1085) +++ firmware/App/Drivers/ConductivityTeensy.c (.../ConductivityTeensy.c) (revision 1768e1d302978a3748ab1e684576f208472e4a54) @@ -25,101 +25,105 @@ #include "ConductivityTeensy.h" #include "Timers.h" -#define SCI_RECEIVE_DMA_REQUEST 30 ///< Serial port receive DMA request line. -#define SCI_TRANSMIT_DMA_REQUEST 31 ///< Serial port transmit DMA request line. +#define SCI_RECEIVE_DMA_REQUEST 30 ///< Serial port receive DMA request line. +#define SCI_TRANSMIT_DMA_REQUEST 31 ///< Serial port transmit DMA request line. -#define COND_CMD_Q_LEN 8 ///< Maximum number of cmds that can be queue'd. -#define QUEUE_START_INDEX 0U ///< Queue start index. +#define COND_CMD_Q_LEN 8 ///< Maximum number of cmds that can be queue'd. +#define QUEUE_START_INDEX 0U ///< Queue start index. -#define COND_WRITE_CMD_BUFFER_LEN 256 ///< Conductivity transmit buffer length in bytes. -#define COND_WRITE_RSP_BUFFER_LEN 256 ///< Conductivity receive buffer length in bytes. +#define COND_WRITE_CMD_BUFFER_LEN 256 ///< Conductivity DMA transmit buffer length in bytes. +#define COND_WRITE_RSP_BUFFER_LEN 256 ///< Conductivity DMA receive buffer length in bytes. -#define COND_TX_BUFFER_LEN 256 ///< Conductivity transmit buffer length in bytes. -#define COND_RX_BUFFER_LEN 256 ///< Conductivity receive buffer length in bytes. +#define COND_TX_BUFFER_LEN 256 ///< Conductivity transmit buffer length in bytes. +#define COND_RX_BUFFER_LEN 256 ///< Conductivity receive buffer length in bytes. -#define RX_SIZE_INIT_SENSOR 2 -#define RX_SIZE_GET_INIT_STATUS 1 -#define RX_SIZE_UPDATE_EEPROM 1 -#define RX_SIZE_GET_EEPROM ( sizeof( CONDUCTIVITY_EEPROM_DATA_T ) ) -#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 0 -#define RX_SIZE_GET_ALL_MEASUREMENTS ( 6 * RX_SIZE_GET_MEASUREMENT ) -#define RX_SIZE_SELECT_SENSOR 0 -#define RX_SIZE_GET_SINGLE_MEASUREMENT ( sizeof( CONDUCTIVITY_SENSOR_DATA_T ) ) +#define RX_SIZE_INIT_SENSOR 2 ///< Expected response bytes length of init sensor cmd. +#define RX_SIZE_GET_INIT_STATUS 1 ///< Expected response bytes length of get init status cmd. +#define RX_SIZE_UPDATE_EEPROM 1 ///< Expected response bytes length of update eeprom cmd. +#define RX_SIZE_GET_EEPROM ( sizeof( COND_EEPROM_DATA_T ) ) ///< Expected response bytes length of get eeprom data cmd. +#define RX_SIZE_UPDATE_MEASUREMENT_SETTINGS 1 ///< Expected response bytes length of update measurement settings cmd. +#define RX_SIZE_GET_MEASUREMENT_SETTNGS ( sizeof( COND_MEASUREMENT_SETTINGS_T ) ) ///< Expected response bytes length of get measurement settings cmd. +#define RX_SIZE_START_MEASUREMENT ( sizeof( COND_SENSOR_DATA_T ) ) ///< Expected response bytes length of start measurement cmd. +#define RX_SIZE_STOP_MEASUREMENT 0 ///< Expected response bytes length of stop measurement cmd. +#define RX_SIZE_GET_ALL_MEASUREMENTS ( 6 * RX_SIZE_START_MEASUREMENT ) ///< Expected response bytes length of get all sensor measurements cmd +#define RX_SIZE_SELECT_SENSOR 0 ///< Expected response bytes length of select sensor cmd. +#define RX_SIZE_GET_SINGLE_MEASUREMENT ( sizeof( COND_SENSOR_DATA_T ) ) ///< Expected response bytes length of get single sensor measurement cmd. -#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 ( 10 * MS_PER_SECOND ) ///< Timeout before which we should receive INIT_STATUS_INITIALIZED or INIT_STATUS_FAILED from teensy +#define COND_STATUS_TIMEOUT_MS ( 10 * MS_PER_SECOND ) ///< Timeout before which we should receive acknowledgment from teensy +#define COND_DATA_TIMEOUT_MS ( 10 * MS_PER_SECOND ) ///< Timeout before which we should receive data from teensy // ********** private data ********** -static CONDUCTIVITY_COMM_STATE_T conductivityCommState = 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 COND_COMM_STATE_T condCommState; +static U32 condResponseTime; ///< Tracks duration between cmd sent and its response received. +static U32 condReceiptCounter; ///< Conductivity response receipt counter. +static U32 condTransmitCounter; ///< Conductivity command transmit counter. +static BOOL condAutomatedDataPolling; ///< Flag indicating automated conductivity measurements polling has started. +static BOOL condWriteCommandInProgress; ///< Flag indicating an Conductivity write command is in progress. +static BOOL condReadCommandInProgress; ///< Flag indicating an Conductivity read command is in progress. +static BOOL condBulkWriteAndReadInProgress; ///< Flag indicating an Conductivity bulk write and read command are in progress. +static BOOL condWriteCmdRspnsRcvd; ///< Flag indicating a response to an Conductivity write 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 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 condTxBuffer[ COND_TX_BUFFER_LEN ]; ///< Conductivity transmit buffer. -static U08 condRxBuffer[ COND_RX_BUFFER_LEN ]; ///< Conductivity receive buffer +static U08 condTxBuffer[ COND_TX_BUFFER_LEN ]; ///< Conductivity transmit buffer. +static U08 condRxBuffer[ COND_RX_BUFFER_LEN ]; ///< Conductivity receive buffer // Conductivity queue buffer and supporting variables. -static TEENSY_CMD_INDEX_T condCmdQ[ COND_CMD_Q_LEN ]; ///< Conductivity command queue buffer. -static U08 queueCount; ///< Queue count. -static U08 queueRearIndex; ///< Queue rear index. -static U08 queueFrontIndex; ///< Queue front index. -static TEENSY_CMD_INDEX_T currentCmd; +static TEENSY_CMD_INDEX_T condCmdQ[ COND_CMD_Q_LEN ]; ///< Conductivity command queue buffer. +static U08 queueCount; ///< Queue count. +static U08 queueRearIndex; ///< Queue rear index. +static U08 queueFrontIndex; ///< Queue front index. +static TEENSY_CMD_INDEX_T currentCmd; ///< Current command being executed in the state machine // 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 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 CONDUCTIVITY_INIT_STATUS_T conductivityInitStatus; -static CONDUCTIVITY_UPDATE_EEPROM_STATUS_T condUpdateEEPROMstatus; -static CONDUCTIVITY_UPDATE_MST_STATUS_T condUpdateSettingStatus[MAX_COND_MST_PARAM_IDX]; -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]; +// Conductivity cmd data structs +static COND_INIT_STATUS_T condInitStatus; ///< Received teensy and all sensors initialization status. +static COND_UPDATE_EEPROM_STATUS_T condUpdateEEPROMstatus; ///< Received update EEPROM status. +static COND_UPDATE_MST_STATUS_T condUpdateSettingStatus[ MAX_COND_MST_PARAM_IDX ]; ///< Received update measurement settings status. +static U08 condStopMeasurementSatus; ///< Received acknowledgment of stop measurement command +static COND_SENSOR_DATA_T condRawMeasurement[ MAX_TEENSY_SENSOR ]; ///< Received raw sensor values (includes impedance and rtd). +static COND_CALCULATED_MEASUREMENTS_T condCalculatedMeasurement[ MAX_TEENSY_SENSOR ]; ///< Calculated conductivity and temperature values +static COND_COEFF_T condCoeff[ MAX_TEENSY_SENSOR ]; ///< Coefficients used to calculate conductivity and temperature values. -static const CONDUCTIVITY_CMD_DATA_T teensyCmdMap[] = { +static TEENSY_SENSOR_INDEX_T currentSelectedSensor; ///< Current selected sensor to get measurement of single sensor. +static COND_EEPROM_DATA_T eePromDataTX; ///< Transmitted EEPROM data to Teensy for update EEPROM cmd. +static COND_EEPROM_DATA_T eePromDataRX; ///< Received EEPROM data by get EEPROM data cmd. +static COND_MEASUREMENT_SETTINGS_T measurementSettingsTX; ///< Transmitted measurement settings to Teensy for update measurement settings cmd. +static COND_MEASUREMENT_SETTINGS_T measurementSettingsRX; ///< Received measurement settings by get measurement settings cmd. + +// Command Map +static const COND_CMD_DATA_T teensyCmdMap[] = { // Command Index / Sub state Command Length of expected response data - { TEENSY_CMD_INIT_SENSOR , (U08*)"a" , RX_SIZE_INIT_SENSOR }, - { TEENSY_CMD_GET_INIT_STATUS , (U08*)"l" , RX_SIZE_GET_INIT_STATUS }, - { TEENSY_CMD_UPDATE_EEPROM_DATA , (U08*)"upe" , RX_SIZE_UPDATE_EEPROM }, - { TEENSY_CMD_GET_EEPROM_DATA , (U08*)"e" , RX_SIZE_GET_EEPROM }, - { TEENSY_CMD_UPDATE_MEASUREMENT_SETTINGS , (U08*)"mst" , RX_SIZE_UPDATE_MEASUREMENT_SETTINGS }, - { TEENSY_CMD_GET_MEASUREMENT_SETTINGS , (U08*)"k" , RX_SIZE_GET_MEASUREMENT_SETTNGS }, - { TEENSY_CMD_GET_MEASUREMENT , (U08*)"m" , RX_SIZE_GET_MEASUREMENT }, - { TEENSY_CMD_STOP_MEASUREMENT , (U08*)"n" , RX_SIZE_STOP_MEASUREMENT }, - { TEENSY_CMD_GET_ALL_MEASUREMENTS , (U08*)"g" , RX_SIZE_GET_ALL_MEASUREMENTS }, - { TEENSY_CMD_SELECT_SENSOR , (U08*)"j" , RX_SIZE_SELECT_SENSOR }, - { TEENSY_CMD_GET_SINGLE_MEASUREMENT , (U08*)"h" , RX_SIZE_GET_SINGLE_MEASUREMENT }, + { TEENSY_CMD_INIT_SENSOR , ( U08* )"a" , RX_SIZE_INIT_SENSOR }, + { TEENSY_CMD_GET_INIT_STATUS , ( U08* )"l" , RX_SIZE_GET_INIT_STATUS }, + { TEENSY_CMD_UPDATE_EEPROM_DATA , ( U08* )"upe" , RX_SIZE_UPDATE_EEPROM }, + { TEENSY_CMD_GET_EEPROM_DATA , ( U08* )"e" , RX_SIZE_GET_EEPROM }, + { TEENSY_CMD_UPDATE_MEASUREMENT_SETTINGS , ( U08* )"mst" , RX_SIZE_UPDATE_MEASUREMENT_SETTINGS }, + { TEENSY_CMD_GET_MEASUREMENT_SETTINGS , ( U08* )"k" , RX_SIZE_GET_MEASUREMENT_SETTNGS }, + { TEENSY_CMD_START_MEASUREMENT , ( U08* )"m" , RX_SIZE_START_MEASUREMENT }, + { TEENSY_CMD_STOP_MEASUREMENT , ( U08* )"n" , RX_SIZE_STOP_MEASUREMENT }, + { TEENSY_CMD_GET_ALL_MEASUREMENTS , ( U08* )"g" , RX_SIZE_GET_ALL_MEASUREMENTS }, + { TEENSY_CMD_SELECT_SENSOR , ( U08* )"j" , RX_SIZE_SELECT_SENSOR }, + { TEENSY_CMD_GET_SINGLE_MEASUREMENT , ( U08* )"h" , RX_SIZE_GET_SINGLE_MEASUREMENT }, }; -// Conductivity cmd data structs -TEENSY_SENSOR_INDEX_T currentSelectedSensor; -CONDUCTIVITY_EEPROM_DATA_T eePromDataTX; -CONDUCTIVITY_EEPROM_DATA_T eePromDataRX; -CONDUCTIVITY_MEASUREMENT_SETTINGS_T measurementSettingsTX; -CONDUCTIVITY_MEASUREMENT_SETTINGS_T measurementSettingsRX; - // ********** private function prototypes ********** -static void initConductivityDMAchannels( void ); + +static void initCondDMAchannels( 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 COND_COMM_STATE_T handleConductivityIdle( void ); +static COND_COMM_STATE_T handleConductivityTX( void ); +static COND_COMM_STATE_T handleConductivityRX( void ); +static COND_COMM_STATE_T handleFailedState( void ); static void consumeUnexpectedConductivityData( void ); static void setupConductivityDMAForWriteCmd( U32 bytes2Transmit ); @@ -135,62 +139,89 @@ static BOOL txTeensyWriteCmd( TEENSY_CMD_INDEX_T cmdIndex, const U08* param ); static BOOL rxTeensyReadRsp( TEENSY_CMD_INDEX_T cmdIndex ); -static CONDUCTIVITY_COMM_STATE_T txInitSensor( void ); -static CONDUCTIVITY_COMM_STATE_T rxInitSensor( void ); +static COND_COMM_STATE_T txInitSensor( void ); +static COND_COMM_STATE_T rxInitSensor( void ); -static CONDUCTIVITY_COMM_STATE_T txGetInitStatus( void ); -static CONDUCTIVITY_COMM_STATE_T rxGetInitStatus( void ); +static COND_COMM_STATE_T txGetInitStatus( void ); +static COND_COMM_STATE_T rxGetInitStatus( void ); -static CONDUCTIVITY_COMM_STATE_T txUpdateEEPROMdata( void ); -static CONDUCTIVITY_COMM_STATE_T rxUpdateEEPROMdata( void ); +static COND_COMM_STATE_T txUpdateEEPROMdata( void ); +static COND_COMM_STATE_T rxUpdateEEPROMdata( void ); -static CONDUCTIVITY_COMM_STATE_T txGetEEPROMdata( void ); -static CONDUCTIVITY_COMM_STATE_T rxGetEEPROMdata( void ); +static COND_COMM_STATE_T txGetEEPROMdata( void ); +static COND_COMM_STATE_T rxGetEEPROMdata( void ); -static CONDUCTIVITY_COMM_STATE_T txUpdateMeasurementSettings( void ); -static CONDUCTIVITY_COMM_STATE_T rxUpdateMeasurementSettings( void ); +static COND_COMM_STATE_T txUpdateMeasurementSettings( void ); +static COND_COMM_STATE_T rxUpdateMeasurementSettings( void ); -static CONDUCTIVITY_COMM_STATE_T txGetMeasurementSettings( void ); -static CONDUCTIVITY_COMM_STATE_T rxGetMeasurementSettings( void ); +static COND_COMM_STATE_T txGetMeasurementSettings( void ); +static COND_COMM_STATE_T rxGetMeasurementSettings( void ); -static CONDUCTIVITY_COMM_STATE_T txGetMeasurements( void ); -static CONDUCTIVITY_COMM_STATE_T rxGetMeasurements( void ); +static COND_COMM_STATE_T txStartMeasurements( void ); +static COND_COMM_STATE_T rxStartMeasurements( void ); -static CONDUCTIVITY_COMM_STATE_T txStopMeasurement( void ); -static CONDUCTIVITY_COMM_STATE_T rxStopMeasurement( void ); +static COND_COMM_STATE_T txStopMeasurement( void ); +static COND_COMM_STATE_T rxStopMeasurement( void ); -static CONDUCTIVITY_COMM_STATE_T txGetAllMeasurements( void ); -static CONDUCTIVITY_COMM_STATE_T rxGetAllMeasurements( void ); +static COND_COMM_STATE_T txGetAllMeasurements( void ); +static COND_COMM_STATE_T rxGetAllMeasurements( void ); -static CONDUCTIVITY_COMM_STATE_T txSelectSensor( TEENSY_SENSOR_INDEX_T sensorNum ); -static CONDUCTIVITY_COMM_STATE_T rxSelectSensor( TEENSY_SENSOR_INDEX_T sensorNum ); +static COND_COMM_STATE_T txSelectSensor( TEENSY_SENSOR_INDEX_T sensorNum ); +static COND_COMM_STATE_T rxSelectSensor( TEENSY_SENSOR_INDEX_T sensorNum ); -static CONDUCTIVITY_COMM_STATE_T txGetSingleMeasurement( TEENSY_SENSOR_INDEX_T sensorNum ); -static CONDUCTIVITY_COMM_STATE_T rxGetSingleMeasurement( TEENSY_SENSOR_INDEX_T sensorNum ); +static COND_COMM_STATE_T txGetSingleMeasurement( TEENSY_SENSOR_INDEX_T sensorNum ); +static COND_COMM_STATE_T rxGetSingleMeasurement( TEENSY_SENSOR_INDEX_T sensorNum ); -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 COND_PARSE_STATUS parseMeasurementSettings( const U08 *buffer, U32 len ); +static COND_PARSE_STATUS parseEEPROMdata( const U08 *buffer, U32 len ); +static COND_PARSE_STATUS parseConductivityMeasurements( const U08 *buffer, U32 len ); static U32 getTeensyCondId( CONDUCTIVITY_SENSORS_T sensorId ); static void calculateConductivity( U32 sensorNum ); static void calculateTemperature( U32 sensorNum ); - -void initCondTeensy( void ) +/*********************************************************************//** + * @brief + * The initConductivityTeensy function initializes ConductivityTeensy unit + * @details \b Inputs: none + * @details \b Outputs: ConductivityTeensy unit variables initialized + * @param none + * @return none + *************************************************************************/ +void initConductivityTeensy( void ) { - conductivityCommState = COND_COMM_STATE_IDLE; + condCommState = COND_COMM_STATE_IDLE; + condResponseTime = 0; condReceiptCounter = 0; condTransmitCounter = 0; - condResponseTime = 0; condAutomatedDataPolling = FALSE; + condWriteCommandInProgress = FALSE; + condReadCommandInProgress = FALSE; + condBulkWriteAndReadInProgress = FALSE; + condWriteCmdRspnsRcvd = FALSE; - // initialize Conductivity comm buffers + memset( &condWriteCmdBuffer, 0, COND_WRITE_CMD_BUFFER_LEN ); + memset( &condWriteResponseBuffer, 0, COND_WRITE_RSP_BUFFER_LEN ); memset( &condTxBuffer, 0, COND_TX_BUFFER_LEN ); memset( &condRxBuffer, 0, COND_RX_BUFFER_LEN ); + memset( &condCmdQ, 0, COND_CMD_Q_LEN ); - initConductivityDMAchannels(); + memset( &condUpdateSettingStatus, 0, MAX_COND_MST_PARAM_IDX ); + memset( &condRawMeasurement, 0, MAX_TEENSY_SENSOR ); + memset( &condCalculatedMeasurement, 0, MAX_TEENSY_SENSOR ); + memset( &condCoeff, 0, MAX_TEENSY_SENSOR ); + queueCount = 0; + queueRearIndex = 0; + queueFrontIndex = 0; + currentCmd = TEENSY_CMD_INIT_SENSOR; + + condInitStatus = COND_INIT_STATUS_UNITIALIZED; + condUpdateEEPROMstatus = COND_UPDATE_EEPROM_STATUS_UNITIALIZED; + currentSelectedSensor = TEENSY_SENSOR_0; + + initCondDMAchannels(); + // add init conductivity commands enqueue( TEENSY_CMD_STOP_MEASUREMENT ); enqueue( TEENSY_CMD_INIT_SENSOR ); @@ -200,7 +231,15 @@ } -static void initConductivityDMAchannels( void ) +/*********************************************************************//** + * @brief + * The initCondDMAchannels function configures DMA based SCI communication. + * @details \b Inputs: none + * @details \b Outputs: none + * @param none + * @return none + *************************************************************************/ +static void initCondDMAchannels( void ) { memset( &condWriteCmdBuffer, 0, COND_WRITE_CMD_BUFFER_LEN ); memset( &condWriteResponseBuffer, 0, COND_WRITE_RSP_BUFFER_LEN ); @@ -217,45 +256,54 @@ dmaEnableInterrupt( DMA_CH3, BTC ); // Initialize Conductivity DMA Write Control Record - condDMAWriteControlRecord.PORTASGN = 4; // Port B (only choice per datasheet) - condDMAWriteControlRecord.SADD = (U32)condWriteCmdBuffer; // Transfer source address - condDMAWriteControlRecord.DADD = (U32)(&(sciREG->TD)); // Dest. is SCI xmit register - condDMAWriteControlRecord.CHCTRL = 0; // No chaining - condDMAWriteControlRecord.ELCNT = 1; // Frame is 1 element - condDMAWriteControlRecord.FRCNT = 0; // Block is TBD frames - will be populated later when known - condDMAWriteControlRecord.RDSIZE = ACCESS_8_BIT; // Element size is 1 byte for read - condDMAWriteControlRecord.WRSIZE = ACCESS_8_BIT; // Element size is 1 byte for write - condDMAWriteControlRecord.TTYPE = FRAME_TRANSFER; // Transfer type is block transfer - condDMAWriteControlRecord.ADDMODERD = ADDR_INC1; // Source addressing mode is post-increment - condDMAWriteControlRecord.ADDMODEWR = ADDR_FIXED; // Dest. addressing mode is fixed - condDMAWriteControlRecord.AUTOINIT = AUTOINIT_OFF; // Auto-init off - condDMAWriteControlRecord.ELSOFFSET = 0; // Not used - condDMAWriteControlRecord.ELDOFFSET = 0; // Not used - condDMAWriteControlRecord.FRSOFFSET = 0; // Not used - condDMAWriteControlRecord.FRDOFFSET = 0; // Not used + condDMAWriteControlRecord.PORTASGN = 4; // Port B (only choice per datasheet) + condDMAWriteControlRecord.SADD = ( U32 )condWriteCmdBuffer; // Transfer source address + condDMAWriteControlRecord.DADD = ( U32 )( &( sciREG->TD ) ); // Dest. is SCI xmit register + condDMAWriteControlRecord.CHCTRL = 0; // No chaining + condDMAWriteControlRecord.ELCNT = 1; // Frame is 1 element + condDMAWriteControlRecord.FRCNT = 0; // Block is TBD frames - will be populated later when known + condDMAWriteControlRecord.RDSIZE = ACCESS_8_BIT; // Element size is 1 byte for read + condDMAWriteControlRecord.WRSIZE = ACCESS_8_BIT; // Element size is 1 byte for write + condDMAWriteControlRecord.TTYPE = FRAME_TRANSFER; // Transfer type is block transfer + condDMAWriteControlRecord.ADDMODERD = ADDR_INC1; // Source addressing mode is post-increment + condDMAWriteControlRecord.ADDMODEWR = ADDR_FIXED; // Dest. addressing mode is fixed + condDMAWriteControlRecord.AUTOINIT = AUTOINIT_OFF; // Auto-init off + condDMAWriteControlRecord.ELSOFFSET = 0; // Not used + condDMAWriteControlRecord.ELDOFFSET = 0; // Not used + condDMAWriteControlRecord.FRSOFFSET = 0; // Not used + condDMAWriteControlRecord.FRDOFFSET = 0; // Not used // Initialize Conductivity DMA Write Response Control Record - condDMAWriteRespControlRecord.PORTASGN = 4; // Port B (only choice per datasheet) - condDMAWriteRespControlRecord.SADD = (U32)(&(sciREG->RD)); // Source is SCI recv register - condDMAWriteRespControlRecord.DADD = (U32)condWriteResponseBuffer; // Transfer destination address - condDMAWriteRespControlRecord.CHCTRL = 0; // No chaining - condDMAWriteRespControlRecord.ELCNT = 1; // Frame is 1 element - condDMAWriteRespControlRecord.FRCNT = 0; // Block is TBD frames - will be populated later when known - condDMAWriteRespControlRecord.RDSIZE = ACCESS_8_BIT; // Element size is 1 byte - condDMAWriteRespControlRecord.WRSIZE = ACCESS_8_BIT; // - condDMAWriteRespControlRecord.TTYPE = FRAME_TRANSFER; // Transfer type is block transfer - condDMAWriteRespControlRecord.ADDMODERD = ADDR_FIXED; // Source addressing mode is fixed - condDMAWriteRespControlRecord.ADDMODEWR = ADDR_INC1; // Dest. addressing mode is post-increment - condDMAWriteRespControlRecord.AUTOINIT = AUTOINIT_OFF; // Auto-init off - condDMAWriteRespControlRecord.ELDOFFSET = 0; // Not used - condDMAWriteRespControlRecord.ELSOFFSET = 0; // Not used - condDMAWriteRespControlRecord.FRDOFFSET = 0; // Not used - condDMAWriteRespControlRecord.FRSOFFSET = 0; // Not used + condDMAWriteRespControlRecord.PORTASGN = 4; // Port B (only choice per datasheet) + condDMAWriteRespControlRecord.SADD = ( U32 )( &( sciREG->RD ) ); // Source is SCI recv register + condDMAWriteRespControlRecord.DADD = ( U32 )condWriteResponseBuffer; // Transfer destination address + condDMAWriteRespControlRecord.CHCTRL = 0; // No chaining + condDMAWriteRespControlRecord.ELCNT = 1; // Frame is 1 element + condDMAWriteRespControlRecord.FRCNT = 0; // Block is TBD frames - will be populated later when known + condDMAWriteRespControlRecord.RDSIZE = ACCESS_8_BIT; // Element size is 1 byte + condDMAWriteRespControlRecord.WRSIZE = ACCESS_8_BIT; // + condDMAWriteRespControlRecord.TTYPE = FRAME_TRANSFER; // Transfer type is block transfer + condDMAWriteRespControlRecord.ADDMODERD = ADDR_FIXED; // Source addressing mode is fixed + condDMAWriteRespControlRecord.ADDMODEWR = ADDR_INC1; // Dest. addressing mode is post-increment + condDMAWriteRespControlRecord.AUTOINIT = AUTOINIT_OFF; // Auto-init off + condDMAWriteRespControlRecord.ELDOFFSET = 0; // Not used + condDMAWriteRespControlRecord.ELSOFFSET = 0; // Not used + condDMAWriteRespControlRecord.FRDOFFSET = 0; // Not used + condDMAWriteRespControlRecord.FRSOFFSET = 0; // Not used // There should not be any data pending yet consumeUnexpectedConductivityData(); } +/*********************************************************************//** + * @brief + * The initEEPROMdata function populates eePromDataTX structure and enqueues + * update EEPROM data command in the the command queue. + * @details \b Inputs: eePromDataTX : EEPROM data to be updated on Teensy. + * @details \b Outputs: none + * @param none + * @return none + *************************************************************************/ static void initEEPROMdata( void ) { // TODO Update real values in eePromDataTX @@ -289,6 +337,15 @@ } +/*********************************************************************//** + * @brief + * The initMeasurementSettings function populates measurementSettingsTX structure and enqueues + * update measurement settings command in the the command queue. + * @details \b Inputs:measurementSettingsTX - MEasurememt settings data to updated on Teensy. + * @details \b Outputs: + * @param + * @return + *************************************************************************/ static void initMeasurementSettings( void ) { // TODO Update real values in measurementSettingsTX @@ -307,32 +364,32 @@ * @brief * The execConductivityTeensy function manages incoming data exchanges with * the Teensy board over UART. - * @details \b Inputs: conductivityCommState - * @details \b Outputs: conductivityCommState + * @details \b Inputs: condCommState - Current state. + * @details \b Outputs: condCommState - Next state. * @return none *************************************************************************/ void execConductivityTeensy( void ) { - switch ( conductivityCommState ) + switch ( condCommState ) { case COND_COMM_STATE_IDLE: - conductivityCommState = handleConductivityIdle(); + condCommState = handleConductivityIdle(); break; case COND_COMM_STATE_TX: - conductivityCommState = handleConductivityTX(); + condCommState = handleConductivityTX(); break; case COND_COMM_STATE_RX: - conductivityCommState = handleConductivityRX(); + condCommState = handleConductivityRX(); break; case COND_COMM_STATE_FAILED: - conductivityCommState = handleFailedState(); + condCommState = handleFailedState(); break; default: - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, (U32)conductivityCommState ) + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, ( U32 )condCommState ) break; } } @@ -341,13 +398,13 @@ * @brief * The handleConductivityIdle handles the command queue and transitions to the respective * comm state. - * @details \b Inputs: TBD - * @details \b Outputs: TBD - * @return none + * @details \b Inputs: condAutomatedDataPolling + * @details \b Outputs: none + * @return state - Next state. *************************************************************************/ -static CONDUCTIVITY_COMM_STATE_T handleConductivityIdle( void ) +static COND_COMM_STATE_T handleConductivityIdle( void ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_IDLE; + COND_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 ); @@ -374,7 +431,7 @@ else { condAutomatedDataPolling = TRUE; - enqueue( TEENSY_CMD_GET_MEASUREMENT ); + enqueue( TEENSY_CMD_START_MEASUREMENT ); } } @@ -385,13 +442,13 @@ * @brief * The handleConductivityTX handles the transmission of data over UART * to the Teensy board. - * @details \b Inputs: TBD - * @details \b Outputs: TBD - * @return none + * @details \b Inputs: currentCmd - Current command being executed (transmitted). + * @details \b Outputs: none + * @return state - Next state. *************************************************************************/ -static CONDUCTIVITY_COMM_STATE_T handleConductivityTX( void ) +static COND_COMM_STATE_T handleConductivityTX( void ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_TX; + COND_COMM_STATE_T state = COND_COMM_STATE_TX; switch ( currentCmd ) { @@ -413,8 +470,8 @@ case TEENSY_CMD_GET_MEASUREMENT_SETTINGS: state = txGetMeasurementSettings(); break; - case TEENSY_CMD_GET_MEASUREMENT: - state = txGetMeasurements(); + case TEENSY_CMD_START_MEASUREMENT: + state = txStartMeasurements(); break; case TEENSY_CMD_STOP_MEASUREMENT: state = txStopMeasurement(); @@ -440,13 +497,14 @@ * @brief * The handleConductivityRX handles the receiving of data over UART * to the Teensy board. - * @details \b Inputs: TBD - * @details \b Outputs: TBD - * @return none + * @details \b Inputs: currentCmd - Current command for which response is + * being received. + * @details \b Outputs: none + * @return state - Next state. *************************************************************************/ -static CONDUCTIVITY_COMM_STATE_T handleConductivityRX( void ) +static COND_COMM_STATE_T handleConductivityRX( void ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_RX; + COND_COMM_STATE_T state = COND_COMM_STATE_RX; switch ( currentCmd ) { @@ -468,8 +526,8 @@ case TEENSY_CMD_GET_MEASUREMENT_SETTINGS: state = rxGetMeasurementSettings(); break; - case TEENSY_CMD_GET_MEASUREMENT: - state = rxGetMeasurements(); + case TEENSY_CMD_START_MEASUREMENT: + state = rxStartMeasurements(); break; case TEENSY_CMD_STOP_MEASUREMENT: state = rxStopMeasurement(); @@ -488,11 +546,20 @@ return state; } -static CONDUCTIVITY_COMM_STATE_T handleFailedState( void ) +/*********************************************************************//** + * @brief + * The handleFailedState function handles failure or errors of the states. + * @details \b Inputs: currentCmd - Current command being executed. + * The error occurred during TX or RX phase of this command. + * @details \b Outputs: none + * @details \b Outputs: none + * @return state - Next state. + *************************************************************************/ +static COND_COMM_STATE_T handleFailedState( void ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_FAILED; + COND_COMM_STATE_T state = COND_COMM_STATE_FAILED; - switch( state ) + switch ( currentCmd ) { case TEENSY_CMD_INIT_SENSOR: break; @@ -506,7 +573,7 @@ break; case TEENSY_CMD_GET_MEASUREMENT_SETTINGS: break; - case TEENSY_CMD_GET_MEASUREMENT: + case TEENSY_CMD_START_MEASUREMENT: break; case TEENSY_CMD_STOP_MEASUREMENT: break; @@ -523,6 +590,14 @@ return state; } +/*********************************************************************//** + * @brief + * The consumeUnexpectedConductivityData function checks to see if a byte is sitting in + * the SCI received data register and consumes the byte if found. + * @details \b Inputs: SCI FLR register + * @details \b Outputs: SCI errors cleared, unexpected byte consumed + * @return none + *************************************************************************/ static void consumeUnexpectedConductivityData( void ) { // Clear any errors @@ -535,6 +610,15 @@ } } +/*********************************************************************//** + * @brief + * The setupConductivityDMAForWriteCmd function sets the byte count for the + * next DMA write command. + * @details \b Inputs: condDMAWriteControlRecord + * @details \b Outputs: number of bytes for next Teensy command is set + * @param bytes2Transmit number of bytes to be transmitted via DMA to the Teensy. + * @return none + *************************************************************************/ static void setupConductivityDMAForWriteCmd( U32 bytes2Transmit ) { // Verify # of bytes does not exceed buffer length @@ -544,14 +628,31 @@ } } +/*********************************************************************//** + * @brief + * The startConductivityDMAWriteCmd function initiates the DMA transmit for + * the next DMA write command to the Teensy. + * @details \b Inputs: condDMAWriteControlRecord + * @details \b Outputs: DMA write command is initiated + * @param none + * @return none + *************************************************************************/ static void startConductivityDMAWriteCmd( void ) { dmaSetCtrlPacket( DMA_CH3, condDMAWriteControlRecord ); dmaSetChEnable( DMA_CH3, DMA_HW ); setSCIDMATransmitInterrupt(); } - +/*********************************************************************//** + * @brief + * The setupConductivityDMAForWriteResp function sets the expected byte count for the + * next DMA write command response from the Teensy. + * @details \b Inputs: none + * @details \b Outputs: condDMAWriteRespControlRecord + * @param bytes2Receive number of bytes expected to be transmitted via DMA from Teensy + * @return none + *************************************************************************/ static void setupConductivityDMAForWriteResp( U32 bytes2Receive ) { // Verify # of bytes does not exceed buffer length @@ -561,6 +662,15 @@ } } +/*********************************************************************//** + * @brief + * The startConductivityDMAReceiptOfWriteResp function initiates readiness of the DMA + * receiver for the next DMA write command response from the Teensy. + * @details \b Inputs: condDMAWriteRespControlRecord + * @details \b Outputs: DMA write command response is made ready to be received from + * the Teensy + * @return none + *************************************************************************/ static void startConductivityDMAReceiptOfWriteResp( void ) { dmaSetCtrlPacket( DMA_CH1, condDMAWriteRespControlRecord ); @@ -571,8 +681,8 @@ /*********************************************************************//** * @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. + * that another DMA receipt from the Teensy has completed and sets comm flags + * indicating pending response from Teensy is completed. * @details \b Inputs: none * @details \b Outputs: condReceiptCounter, condWriteCommandInProgress, * condWriteCmdRspnsRcvd @@ -592,7 +702,7 @@ /*********************************************************************//** * @brief * The signalConductivityTransmitCompleted function increments a counter to indicate - * that another DMA transmit to the Conductivity has completed. + * that another DMA transmit to the Teensy has completed. * @details \b Inputs: none * @details \b Outputs: condTransmitCounter * @return none @@ -608,7 +718,7 @@ * it will return a true. * @details Inputs: queueCount * @details Outputs: none - * @return TRUE is queue is full + * @return TRUE if queue is full. Otherwise, FALSE. *************************************************************************/ static BOOL isQueueFull ( void ) { @@ -644,7 +754,7 @@ /*********************************************************************//** * @brief - * The dequeue function adds a cmd from the cmd queue if it is not full. + * The enqueue function adds a cmd from the cmd queue if it is not full. * @details Inputs: condCmdQ[], queueRearIndex, queueCount * @details Outputs: condCmdQ[], queueRearIndex, queueCount * @param cmd the Cmd ID to be queue'd @@ -669,7 +779,7 @@ /*********************************************************************//** * @brief - * The dequeue function removes a job from the job queue if it is not empty. + * The dequeue function removes a cmd from the cmd queue if it is not empty. * @details Inputs: condCmdQ[], queueFrontIndex, queueCount * @details Outputs: condCmdQ[], queueFrontIndex, queueCount, currentCmd * @return none @@ -692,34 +802,36 @@ _enable_IRQ(); } -/** - * @brief Writes a command (with optional parameters) to the write buffer. - * +/*********************************************************************//** + * @brief + * The txTeensyWriteCmd function writes a command (with optional parameters) to the write buffer. + * @details \b Inputs: teensyCmdMap, condTxBuffer + * @details \b Outputs: condWriteCmdBuffer * @param cmdIndex Index of the command in teensyCmd[]. * @param param Optional parameter string to append after the command. * @return TRUE if the command was successfully written to the write buffer, FALSE otherwise. - */ + *************************************************************************/ static BOOL txTeensyWriteCmd( TEENSY_CMD_INDEX_T cmdIndex, const U08* param ) { - const U08* baseCmd = (const U08*)teensyCmdMap[ cmdIndex ].teensyCMD; + const U08* baseCmd = ( const U08* )teensyCmdMap[ cmdIndex ].teensyCMD; BOOL success = FALSE; U16 written = 0; // Format command with optional parameter - if ( ( NULL != param ) && ( strlen( (const char*)param ) > 0 ) ) + if ( ( NULL != param ) && ( strlen( ( const char* )param ) > 0 ) ) { - written = snprintf( (char*)condTxBuffer, + written = snprintf( ( char* )condTxBuffer, COND_TX_BUFFER_LEN, "%s,%s", - (const char*)baseCmd, - (const char*)param ); + ( const char* )baseCmd, + ( const char* )param ); } else { - written = snprintf( (char*)condTxBuffer, + written = snprintf( ( char* )condTxBuffer, COND_TX_BUFFER_LEN, "%s", - (const char*)baseCmd ); + ( const char* )baseCmd ); } if ( written > 0 ) @@ -739,12 +851,15 @@ return success; } -/** - * @brief Writes a command (without parameters) to the read buffer. - * +/*********************************************************************//** + * @brief + * The rxTeensyReadRsp functions writes the response of a command in the response buffer. + * @details \b Inputs: condWriteResponseBuffer + * @details \b Outputs: condRxBuffer * @param cmdIndex Index of the command in teensyCmd[]. - * @return TRUE if the command was successfully written to the read buffer, FALSE otherwise. - */ + * @return TRUE if the response was successfully written to the response buffer, + * FALSE otherwise. + *************************************************************************/ static BOOL rxTeensyReadRsp( TEENSY_CMD_INDEX_T cmdIndex ) { BOOL success = FALSE; @@ -762,9 +877,17 @@ return success; } -static CONDUCTIVITY_COMM_STATE_T txInitSensor( void ) +/*********************************************************************//** + * @brief + * The txInitSensor function sends initialize sensors command to the Teesny. + * @details \b Inputs: none + * @details \b Outputs: condResponseTime - Time at which command was transmitted. + * @param none + * @return state - Next state. + *************************************************************************/ +static COND_COMM_STATE_T txInitSensor( void ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_TX; + COND_COMM_STATE_T state = COND_COMM_STATE_TX; // If the init sensor cmd was sent successfully if ( TRUE == txTeensyWriteCmd( TEENSY_CMD_INIT_SENSOR, NULL ) ) @@ -782,41 +905,49 @@ } return state; - } -static CONDUCTIVITY_COMM_STATE_T rxInitSensor( void ) +/*********************************************************************//** + * @brief + * The rxInitSensor function handles received response of initialize sensor command. + * @details \b Inputs: condResponseTime - Time at which command was transmitted, + * @details \b Inputs: condRxBuffer - Received response buffer + * @details \b Outputs: condInitStatus - Sensor Initialization status. + * @param none + * @return state - Next state. + *************************************************************************/ +static COND_COMM_STATE_T rxInitSensor( void ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_RX; - CONDUCTIVITY_INIT_STATUS_T initStatusInProgress = CONDUCTIVITY_INIT_STATUS_FAILED; // set to fail for testing - CONDUCTIVITY_INIT_STATUS_T initStatusInitialized = CONDUCTIVITY_INIT_STATUS_FAILED; // if data populates + COND_COMM_STATE_T state = COND_COMM_STATE_RX; + COND_INIT_STATUS_T initStatusInProgress = COND_INIT_STATUS_FAILED; // set to fail for testing + COND_INIT_STATUS_T initStatusInitialized = COND_INIT_STATUS_FAILED; // if data populates BOOL recvComplete = rxTeensyReadRsp( TEENSY_CMD_INIT_SENSOR ); if ( TRUE == recvComplete ) { // Reset the timer for next use. condResponseTime = 0; // Read the data from the receive buffer - initStatusInProgress = (CONDUCTIVITY_INIT_STATUS_T)condRxBuffer[0]; - initStatusInitialized = (CONDUCTIVITY_INIT_STATUS_T)condRxBuffer[1]; + initStatusInProgress = ( COND_INIT_STATUS_T )condRxBuffer[ 0 ]; + initStatusInitialized = ( COND_INIT_STATUS_T )condRxBuffer[ 1 ]; // Store the init status - conductivityInitStatus = initStatusInitialized; + condInitStatus = initStatusInitialized; - switch( conductivityInitStatus ) + switch ( condInitStatus ) { - case CONDUCTIVITY_INIT_STATUS_UNITIALIZED: + case COND_INIT_STATUS_UNITIALIZED: break; - case CONDUCTIVITY_INIT_STATUS_IN_PROGRESS: + case COND_INIT_STATUS_IN_PROGRESS: state = COND_COMM_STATE_IDLE; break; - case CONDUCTIVITY_INIT_STATUS_INITIALIZED: + case COND_INIT_STATUS_INITIALIZED: state = COND_COMM_STATE_IDLE; break; - case CONDUCTIVITY_INIT_STATUS_FAILED: + case COND_INIT_STATUS_FAILED: default: state = COND_COMM_STATE_IDLE; break; @@ -835,9 +966,18 @@ return state; } -static CONDUCTIVITY_COMM_STATE_T txGetInitStatus( void ) +/*********************************************************************//** +* @brief +* The txGetInitStatus function sends get sensor initialization status command +* to the Teesny. +* @details \b Inputs: none +* @details \b Outputs: condResponseTime - Time at which command was transmitted. +* @param none +* @return state - Next state. +*************************************************************************/ +static COND_COMM_STATE_T txGetInitStatus( void ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_TX; + COND_COMM_STATE_T state = COND_COMM_STATE_TX; // If the get init status cmd was sent successfully if ( TRUE == txTeensyWriteCmd( TEENSY_CMD_GET_INIT_STATUS, NULL ) ) @@ -857,9 +997,19 @@ return state; } -static CONDUCTIVITY_COMM_STATE_T rxGetInitStatus( void ) +/*********************************************************************//** + * @brief + * The rxGetInitStatus function handles received response of get sensor + * initialization status command. + * @details \b Inputs: condResponseTime - Time at which command was transmitted, + * @details \b Inputs: condRxBuffer - Received response buffer + * @details \b Outputs: condInitStatus - Sensor Initialization status. + * @param none + * @return state - Next state. + *************************************************************************/ +static COND_COMM_STATE_T rxGetInitStatus( void ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_RX; + COND_COMM_STATE_T state = COND_COMM_STATE_RX; // Check if a response is received in the RX buffer BOOL recvComplete = rxTeensyReadRsp( TEENSY_CMD_GET_INIT_STATUS ); @@ -869,23 +1019,23 @@ condResponseTime = 0; // Read the data from the receive buffer - memcpy(&conductivityInitStatus, &condRxBuffer, teensyCmdMap[ TEENSY_CMD_GET_INIT_STATUS ].rxSize); -// conductivityInitStatus = (CONDUCTIVITY_INIT_STATUS_T)condRxBuffer[0]; + memcpy(&condInitStatus, &condRxBuffer, teensyCmdMap[ TEENSY_CMD_GET_INIT_STATUS ].rxSize ); +// condInitStatus = ( cOND_INIT_STATUS_T )condRxBuffer[ 0 ]; - switch(conductivityInitStatus) + switch ( condInitStatus ) { - case CONDUCTIVITY_INIT_STATUS_UNITIALIZED: + case COND_INIT_STATUS_UNITIALIZED: break; - case CONDUCTIVITY_INIT_STATUS_IN_PROGRESS: + case COND_INIT_STATUS_IN_PROGRESS: state = COND_COMM_STATE_IDLE; break; - case CONDUCTIVITY_INIT_STATUS_INITIALIZED: + case COND_INIT_STATUS_INITIALIZED: state = COND_COMM_STATE_IDLE; break; - case CONDUCTIVITY_INIT_STATUS_FAILED: + case COND_INIT_STATUS_FAILED: default: state = COND_COMM_STATE_IDLE; break; @@ -905,30 +1055,38 @@ return state; } -static CONDUCTIVITY_COMM_STATE_T txUpdateEEPROMdata( void ) +/*********************************************************************//** + * @brief + * The txUpdateEEPROMdata function sends update EEPRPM data command to Teensy. + * @details \b Inputs: eePromDataTX - EEPROM data to be updated in Teensy. + * @details \b Outputs: condResponseTime - Time at which command was transmitted. + * @param none + * @return state - Next state. + *************************************************************************/ +static COND_COMM_STATE_T txUpdateEEPROMdata( void ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_TX; + COND_COMM_STATE_T state = COND_COMM_STATE_TX; // Format EEPROM data into a string - U08 paramStr[256]; + U08 paramStr[ 256 ]; U16 offset = 0; U16 i = 0; // Pack the command and EEPROM data for ( i = 0; i < DOUBLE_COUNT; ++i ) { - offset += snprintf( (char*)(paramStr + offset), - sizeof(paramStr) - offset, + offset += snprintf( ( char* )( paramStr + offset ), + sizeof( paramStr ) - offset, "%.6f,", - eePromDataTX.doubleValue[i] ); + eePromDataTX.doubleValue[ i ] ); } for ( i = 0; i < FLOAT_COUNT; ++i ) { - offset += snprintf( (char*)(paramStr + offset), - sizeof(paramStr) - offset, + offset += snprintf( ( char* )( paramStr + offset ), + sizeof( paramStr ) - offset, "%.6f,", - eePromDataTX.floatValue[i] ); + eePromDataTX.floatValue[ i ] ); } // Remove trailing comma if needed @@ -955,9 +1113,18 @@ return state; } -static CONDUCTIVITY_COMM_STATE_T rxUpdateEEPROMdata( void ) +/*********************************************************************//** + * @brief + * The rxUpdateEEPROMdata function handles received response of update EEPRPM data command. + * @details \b Inputs: condResponseTime - Time at which command was transmitted, + * @details \b Inputs: condRxBuffer - Received response buffer + * @details \b Outputs: condUpdateEEPROMstatus - Update EEPRPM data status. + * @param none + * @return state - Next state. + *************************************************************************/ +static COND_COMM_STATE_T rxUpdateEEPROMdata( void ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_RX; + COND_COMM_STATE_T state = COND_COMM_STATE_RX; // Check if a response is received in the RX buffer BOOL recvComplete = rxTeensyReadRsp( TEENSY_CMD_UPDATE_EEPROM_DATA ); @@ -967,8 +1134,8 @@ condResponseTime = 0; // Read the data from the receive buffer - memcpy(&condUpdateEEPROMstatus, &condRxBuffer, teensyCmdMap[ TEENSY_CMD_UPDATE_EEPROM_DATA ].rxSize); -// condUpdateEEPROMstatus = (CONDUCTIVITY_UPDATE_EEPROM_STATUS_T)condRxBuffer[0]; + memcpy(&condUpdateEEPROMstatus, &condRxBuffer, teensyCmdMap[ TEENSY_CMD_UPDATE_EEPROM_DATA ].rxSize ); +// condUpdateEEPROMstatus = ( CONDUCTIVITY_UPDATE_EEPROM_STATUS_T )condRxBuffer[ 0 ]; // Go to the idle state to execute next cmd in the queue state = COND_COMM_STATE_IDLE; @@ -986,9 +1153,18 @@ return state; } -static CONDUCTIVITY_COMM_STATE_T txGetEEPROMdata( void ) +/*********************************************************************//** + * @brief + * The txGetEEPROMdata function sends get EEPROM data command to the Teesny. + * @details \b Inputs: none + * @details \b Outputs: condResponseTime - Time at which command was transmitted. + * @param none + * @return state - Next state. + *************************************************************************/ + +static COND_COMM_STATE_T txGetEEPROMdata( void ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_TX; + COND_COMM_STATE_T state = COND_COMM_STATE_TX; // If the get EEPROM data cmd was sent successfully if ( TRUE == txTeensyWriteCmd( TEENSY_CMD_GET_EEPROM_DATA, NULL ) ) @@ -1008,10 +1184,19 @@ return state; } -static CONDUCTIVITY_COMM_STATE_T rxGetEEPROMdata( void ) +/*********************************************************************//** + * @brief + * The rxGetEEPROMdata function handles received response of get EEPROM data command. + * @details \b Inputs: condResponseTime - Time at which command was transmitted, + * @details \b Inputs: condRxBuffer - Received response buffer + * @details \b Outputs: eePromDataRX - Received EEPROM data. + * @param none + * @return state - Next state. + *************************************************************************/ +static COND_COMM_STATE_T rxGetEEPROMdata( void ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_RX; - CONDUCTIVITY_PARSE_STATUS parseStatus = CONDUCTIVITY_PARSE_NONE; + COND_COMM_STATE_T state = COND_COMM_STATE_RX; + COND_PARSE_STATUS parseStatus = COND_PARSE_NONE; state = COND_COMM_STATE_IDLE; // Check if a response is received in the RX buffer @@ -1022,11 +1207,11 @@ condResponseTime = 0; // Read the data from the receive buffer - memcpy(&eePromDataRX, &condRxBuffer, teensyCmdMap[ TEENSY_CMD_GET_EEPROM_DATA ].rxSize); + memcpy(&eePromDataRX, &condRxBuffer, teensyCmdMap[ TEENSY_CMD_GET_EEPROM_DATA ].rxSize ); // parseStatus = parseEEPROMdata( condRxBuffer, COND_RX_BUFFER_LEN ); // Check if parsing was done successfully - if(CONDUCTIVITY_PARSE_SUCCESS == parseStatus) + if ( COND_PARSE_SUCCESS == parseStatus ) { // Go to the idle state to execute next cmd in the queue state = COND_COMM_STATE_IDLE; @@ -1050,10 +1235,20 @@ return state; } -static CONDUCTIVITY_COMM_STATE_T txUpdateMeasurementSettings( void ) +/*********************************************************************//** + * @brief + * The txUpdateMeasurementSettings function sends update measurement settings command + * to the Teesny. + * @details \b Inputs: none + * @details \b Outputs: condResponseTime - Time at which command was transmitted. + * @param none + * @return state - Next state. + *************************************************************************/ + +static COND_COMM_STATE_T txUpdateMeasurementSettings( void ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_TX; - U08 paramStr[128]; + COND_COMM_STATE_T state = COND_COMM_STATE_TX; + U08 paramStr[ 128 ]; snprintf( ( char * )paramStr, sizeof( paramStr ), "%.4f,%.4f,%.4f,%lu,%lu,%lu,%lu", @@ -1083,9 +1278,19 @@ return state; } -static CONDUCTIVITY_COMM_STATE_T rxUpdateMeasurementSettings( void ) +/*********************************************************************//** + * @brief + * The rxUpdateMeasurementSettings function handles received response of + * update measurement settings command. + * @details \b Inputs: condResponseTime - Time at which command was transmitted, + * @details \b Inputs: condRxBuffer - Received response buffer + * @details \b Outputs: condUpdateSettingStatus - Update measurement settings status. + * @param none + * @return state - Next state. + *************************************************************************/ +static COND_COMM_STATE_T rxUpdateMeasurementSettings( void ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_RX; + COND_COMM_STATE_T state = COND_COMM_STATE_RX; // Check if a response is received in the RX buffer BOOL recvComplete = rxTeensyReadRsp( TEENSY_CMD_UPDATE_MEASUREMENT_SETTINGS ); @@ -1095,8 +1300,8 @@ condResponseTime = 0; // Read the data from the receive buffer - memcpy(&condUpdateSettingStatus, &condRxBuffer, teensyCmdMap[ TEENSY_CMD_UPDATE_MEASUREMENT_SETTINGS ].rxSize); -// updateSettingStatus = ( CONDUCTIVITY_UPDATE_MST_STATUS_T )condTxBuffer[0]; + memcpy(&condUpdateSettingStatus, &condRxBuffer, teensyCmdMap[ TEENSY_CMD_UPDATE_MEASUREMENT_SETTINGS ].rxSize ); +// updateSettingStatus = ( CONDUCTIVITY_UPDATE_MST_STATUS_T )condTxBuffer[ 0 ]; // Move to TX state to update the next param. state = COND_COMM_STATE_TX; @@ -1115,9 +1320,19 @@ return state; } -static CONDUCTIVITY_COMM_STATE_T txGetMeasurementSettings( void ) +/*********************************************************************//** + * @brief + * The txGetMeasurementSettings function sends get measurement settings command + * to the Teesny. + * @details \b Inputs: none + * @details \b Outputs: condResponseTime - Time at which command was transmitted. + * @param none + * @return state - Next state. + *************************************************************************/ + +static COND_COMM_STATE_T txGetMeasurementSettings( void ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_TX; + COND_COMM_STATE_T state = COND_COMM_STATE_TX; // If get measurement settings cmd was sent successfully if ( TRUE == txTeensyWriteCmd( TEENSY_CMD_GET_MEASUREMENT_SETTINGS, NULL ) ) @@ -1137,10 +1352,20 @@ return state; } -static CONDUCTIVITY_COMM_STATE_T rxGetMeasurementSettings( void ) +/*********************************************************************//** + * @brief + * The rxGetMeasurementSettings function handles received response of + * get measurement settings command. + * @details \b Inputs: condResponseTime - Time at which command was transmitted, + * @details \b Inputs: condRxBuffer - Received response buffer + * @details \b Outputs: measurementSettingsRX - Received Measurement Settings + * @param none + * @return state - Next state. + *************************************************************************/ +static COND_COMM_STATE_T rxGetMeasurementSettings( void ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_RX; - CONDUCTIVITY_PARSE_STATUS parseStatus = CONDUCTIVITY_PARSE_NONE; + COND_COMM_STATE_T state = COND_COMM_STATE_RX; + COND_PARSE_STATUS parseStatus = COND_PARSE_NONE; state = COND_COMM_STATE_IDLE; // Check if a response is received in the RX buffer @@ -1151,11 +1376,11 @@ condResponseTime = 0; // Read the data from the receive buffer - memcpy(&measurementSettingsRX, &condRxBuffer, teensyCmdMap[ TEENSY_CMD_GET_MEASUREMENT_SETTINGS ].rxSize); + memcpy(&measurementSettingsRX, &condRxBuffer, teensyCmdMap[ TEENSY_CMD_GET_MEASUREMENT_SETTINGS ].rxSize ); // parseStatus = parseMeasurementSettings( condRxBuffer, COND_RX_BUFFER_LEN ); // Check if parsing was done successfully - if(CONDUCTIVITY_PARSE_SUCCESS == parseStatus) + if ( COND_PARSE_SUCCESS == parseStatus ) { // Go to the idle state to execute next cmd in the queue state = COND_COMM_STATE_IDLE; @@ -1179,13 +1404,26 @@ return state; } -static CONDUCTIVITY_COMM_STATE_T txGetMeasurements( void ) +/*********************************************************************//** + * @brief + * The txStartMeasurements function sends start measurements command to the Teesny. + * This command will start the automated Conductivity measurements polling. + * @details \b Inputs: none + * @details \b Outputs: condResponseTime - Time at which command was transmitted. + * @details \b Outputs: condAutomatedDataPolling set to TRUE. + * @param none + * @return state - Next state. + *************************************************************************/ + +static COND_COMM_STATE_T txStartMeasurements( void ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_TX; + COND_COMM_STATE_T state = COND_COMM_STATE_TX; // If get measurement settings cmd was sent successfully - if ( TRUE == txTeensyWriteCmd( TEENSY_CMD_GET_MEASUREMENT, NULL ) ) + if ( TRUE == txTeensyWriteCmd( TEENSY_CMD_START_MEASUREMENT, NULL ) ) { + // Set the flag to indicate that automated conductivity data polling has started. + condAutomatedDataPolling = TRUE; // Get the current time condResponseTime = getMSTimerCount(); @@ -1200,12 +1438,23 @@ return state; } -static CONDUCTIVITY_COMM_STATE_T rxGetMeasurements( void ) +/*********************************************************************//** + * @brief + * The rxStartMeasurements function handles received response of start measurements command. + * @details \b Inputs: condResponseTime - Time at which command was transmitted or + * previous conductivity measurements data was received. + * @details \b Inputs: condRxBuffer - Received response buffer + * @details \b Outputs: condRawMeasurement - Raw Conductivity Measurements (includes impedance and rtd) + * @details \b Outputs: condCalculatedMeasurement - Calculated Conductivity and temperature. + * @param none + * @return state - Next state. + *************************************************************************/ +static COND_COMM_STATE_T rxStartMeasurements( void ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_RX; - CONDUCTIVITY_PARSE_STATUS parseStatus; + COND_COMM_STATE_T state = COND_COMM_STATE_RX; + COND_PARSE_STATUS parseStatus; // Check if a response is received in the RX buffer - BOOL recvComplete = rxTeensyReadRsp( TEENSY_CMD_GET_MEASUREMENT ); + BOOL recvComplete = rxTeensyReadRsp( TEENSY_CMD_START_MEASUREMENT ); if ( TRUE == recvComplete ) { @@ -1216,7 +1465,7 @@ parseStatus = parseConductivityMeasurements( condRxBuffer, COND_RX_BUFFER_LEN ); // Check if parsing was done successfully - if( CONDUCTIVITY_PARSE_SUCCESS == parseStatus ) + if ( COND_PARSE_SUCCESS == parseStatus ) { // Go to the idle state to execute next cmd in the queue state = COND_COMM_STATE_IDLE; @@ -1235,10 +1484,20 @@ return state; } +/*********************************************************************//** + * @brief + * The txStopMeasurement function sends stop measurements command to the Teesny. + * This command will stop the automated polling of conductivity measurements data. + * @details \b Inputs: none + * @details \b Outputs: condResponseTime - Time at which command was transmitted. + * @details \b Outputs: condAutomatedDataPolling set to FALSE. + * @param none + * @return state - Next state. + *************************************************************************/ -static CONDUCTIVITY_COMM_STATE_T txStopMeasurement( void ) +static COND_COMM_STATE_T txStopMeasurement( void ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_TX; + COND_COMM_STATE_T state = COND_COMM_STATE_TX; if ( TRUE == txTeensyWriteCmd( TEENSY_CMD_STOP_MEASUREMENT, NULL ) ) { @@ -1250,9 +1509,18 @@ return state; } -static CONDUCTIVITY_COMM_STATE_T rxStopMeasurement( void ) +/*********************************************************************//** + * @brief + * The rxStopMeasurement function handles received response of stop measurements command. + * @details \b Inputs: condResponseTime - Time at which command was transmitted, + * @details \b Inputs: condRxBuffer - Received response buffer + * @details \b Outputs: condStopMeasurementSatus - Stop measurement status + * @param none + * @return state - Next state. + *************************************************************************/ +static COND_COMM_STATE_T rxStopMeasurement( void ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_RX; + COND_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 @@ -1264,9 +1532,19 @@ return state; } -static CONDUCTIVITY_COMM_STATE_T txGetAllMeasurements( void ) +/*********************************************************************//** + * @brief + * The txGetAllMeasurements function sends command to get measurements of all sensors + * connected to the Teesny. + * @details \b Inputs: none + * @details \b Outputs: condResponseTime - Time at which command was transmitted. + * @param none + * @return state - Next state. + *************************************************************************/ + +static COND_COMM_STATE_T txGetAllMeasurements( void ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_TX; + COND_COMM_STATE_T state = COND_COMM_STATE_TX; if ( TRUE == txTeensyWriteCmd( TEENSY_CMD_GET_ALL_MEASUREMENTS, NULL ) ) { @@ -1277,9 +1555,20 @@ return state; } -static CONDUCTIVITY_COMM_STATE_T rxGetAllMeasurements( void ) +/*********************************************************************//** + * @brief + * The rxGetAllMeasurements function handles received response of + * get all sensor measurements command. + * @details \b Inputs: condResponseTime - Time at which command was transmitted, + * @details \b Inputs: condRxBuffer - Received response buffer + * @details \b Outputs: condRawMeasurement - Raw Conductivity Measurements (includes impedance and rtd) + * @details \b Outputs: condCalculatedMeasurement - Calculated Conductivity and temperature. + * @param none + * @return state - Next state. + *************************************************************************/ +static COND_COMM_STATE_T rxGetAllMeasurements( void ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_RX; + COND_COMM_STATE_T state = COND_COMM_STATE_RX; // Check if a response is received in the RX buffer BOOL recvComplete = rxTeensyReadRsp( TEENSY_CMD_GET_ALL_MEASUREMENTS ); @@ -1289,10 +1578,10 @@ condResponseTime = 0; // Read the data from the receive buffer - CONDUCTIVITY_PARSE_STATUS parseStatus = parseConductivityMeasurements( condRxBuffer, COND_RX_BUFFER_LEN ); + COND_PARSE_STATUS parseStatus = parseConductivityMeasurements( condRxBuffer, COND_RX_BUFFER_LEN ); // Check if parsing was done successfully - if(CONDUCTIVITY_PARSE_SUCCESS == parseStatus) + if ( COND_PARSE_SUCCESS == parseStatus ) { // Go to the idle state to execute next cmd in the queue state = COND_COMM_STATE_IDLE; @@ -1316,12 +1605,22 @@ return state; } -static CONDUCTIVITY_COMM_STATE_T txSelectSensor( TEENSY_SENSOR_INDEX_T sensorNum ) +/*********************************************************************//** + * @brief + * The txSelectSensor function sends select sensor for single sensor measurement + * to the Teesny. Always call this function before calling txGetSingleMeasurement(). + * @details \b Inputs: none + * @details \b Outputs: condResponseTime - Time at which command was transmitted. + * @param none + * @return state - Next state. + *************************************************************************/ + +static COND_COMM_STATE_T txSelectSensor( TEENSY_SENSOR_INDEX_T sensorNum ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_TX; + COND_COMM_STATE_T state = COND_COMM_STATE_TX; - U08 paramStr[8]; - snprintf( (char*)paramStr, sizeof(paramStr), "%d", sensorNum ); + U08 paramStr[ 8 ]; + snprintf( ( char* )paramStr, sizeof( paramStr ), "%d", sensorNum ); if ( TRUE == txTeensyWriteCmd( TEENSY_CMD_SELECT_SENSOR, paramStr ) ) { @@ -1331,16 +1630,35 @@ return state; } -static CONDUCTIVITY_COMM_STATE_T rxSelectSensor( TEENSY_SENSOR_INDEX_T sensorNum ) +/*********************************************************************//** + * @brief + * The rxSelectSensor function handles received response of select sensor command. + * @details \b Inputs: condResponseTime - Time at which command was transmitted, + * @details \b Inputs: condRxBuffer - Received response buffer + * @details \b Outputs: currentSelectedSensor - Current selected sensor. + * @param none + * @return state - Next state. + *************************************************************************/ +static COND_COMM_STATE_T rxSelectSensor( TEENSY_SENSOR_INDEX_T sensorNum ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_RX; + COND_COMM_STATE_T state = COND_COMM_STATE_RX; return state; } -static CONDUCTIVITY_COMM_STATE_T txGetSingleMeasurement( TEENSY_SENSOR_INDEX_T sensorNum ) +/*********************************************************************//** + * @brief + * The txGetSingleMeasurement function sends get single sensor measurement command + * to the Teesny. Always call txSelectSensor() function before calling this function. + * @details \b Inputs: none + * @details \b Outputs: condResponseTime - Time at which command was transmitted. + * @param none + * @return state - Next state. + *************************************************************************/ + +static COND_COMM_STATE_T txGetSingleMeasurement( TEENSY_SENSOR_INDEX_T sensorNum ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_TX; + COND_COMM_STATE_T state = COND_COMM_STATE_TX; // Assumes sensor has already been selected if ( TRUE == txTeensyWriteCmd( TEENSY_CMD_GET_SINGLE_MEASUREMENT, NULL ) ) @@ -1352,9 +1670,20 @@ return state; } -static CONDUCTIVITY_COMM_STATE_T rxGetSingleMeasurement( TEENSY_SENSOR_INDEX_T sensorNum ) +/*********************************************************************//** + * @brief + * The rxGetSingleMeasurement function handles received response of + * get single sensor measurement command. + * @details \b Inputs: condResponseTime - Time at which command was transmitted, + * @details \b Inputs: condRxBuffer - Received response buffer + * @details \b Outputs: condRawMeasurement - Raw Conductivity Measurements (includes impedance and rtd) + * @details \b Outputs: condCalculatedMeasurement - Calculated Conductivity and temperature. + * @param none + * @return state - Next state. + *************************************************************************/ +static COND_COMM_STATE_T rxGetSingleMeasurement( TEENSY_SENSOR_INDEX_T sensorNum ) { - CONDUCTIVITY_COMM_STATE_T state = COND_COMM_STATE_RX; + COND_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 ); @@ -1364,10 +1693,10 @@ condResponseTime = 0; // Read the data from the receive buffer - CONDUCTIVITY_PARSE_STATUS parseStatus = parseConductivityMeasurements( condRxBuffer, COND_RX_BUFFER_LEN ); + COND_PARSE_STATUS parseStatus = parseConductivityMeasurements( condRxBuffer, COND_RX_BUFFER_LEN ); // Check if parsing was done successfully - if(CONDUCTIVITY_PARSE_SUCCESS == parseStatus) + if ( COND_PARSE_SUCCESS == parseStatus ) { // Go to the idle state to execute next cmd in the queue state = COND_COMM_STATE_IDLE; @@ -1394,32 +1723,32 @@ /*********************************************************************//** * @brief * The parseMeasurementSettings Reads measurement settings from buffer and - * stores in conductivityMeasurementSettings. + * stores in measurementSettingsRX. * @details \b Inputs : none - * @details \b Outputs: conductivityMeasurementSettings - Measurement Settings + * @details \b Outputs: measurementSettingsRX - Received 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. + * @return COND_PARSE_STATUS to tell if parsing was successful or not. *************************************************************************/ -static CONDUCTIVITY_PARSE_STATUS parseMeasurementSettings(const U08 *buffer, U32 len) +static COND_PARSE_STATUS parseMeasurementSettings( const U08 *buffer, U32 len ) { - CONDUCTIVITY_PARSE_STATUS parseStatus = CONDUCTIVITY_PARSE_NONE; - U32 expectedDataLength = sizeof(CONDUCTIVITY_MEASUREMENT_SETTINGS_T); + COND_PARSE_STATUS parseStatus = COND_PARSE_NONE; + U32 expectedDataLength = sizeof( COND_MEASUREMENT_SETTINGS_T ); // Validate buffer - if (buffer == NULL) + if ( buffer == NULL ) { - parseStatus = CONDUCTIVITY_PARSE_ERROR_NULL_BUFFER; + parseStatus = COND_PARSE_ERROR_NULL_BUFFER; } - else if (len != expectedDataLength) + else if ( len != expectedDataLength ) { - parseStatus = CONDUCTIVITY_PARSE_ERROR_INVALID_LENGTH; + parseStatus = COND_PARSE_ERROR_INVALID_LENGTH; } else { // Parse and store the data - memcpy(&measurementSettingsRX, buffer, expectedDataLength); - parseStatus = CONDUCTIVITY_PARSE_SUCCESS; + memcpy(&measurementSettingsRX, buffer, expectedDataLength ); + parseStatus = COND_PARSE_SUCCESS; } return parseStatus; @@ -1428,33 +1757,33 @@ /*********************************************************************//** * @brief * The parseEEPROMdata Reads EEPROM data from buffer and - * stores in conductivityEEPROMdata. + * stores in eePromDataRX. * @details \b Inputs : none - * @details \b Outputs: conductivityEEPROMdata - EEPROM data + * @details \b Outputs: eePromDataRX - Received 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. + * @return COND_PARSE_STATUS to tell if parsing was successful or not. *************************************************************************/ -static CONDUCTIVITY_PARSE_STATUS parseEEPROMdata(const U08 *buffer, U32 len) +static COND_PARSE_STATUS parseEEPROMdata( const U08 *buffer, U32 len ) { - CONDUCTIVITY_PARSE_STATUS parseStatus = CONDUCTIVITY_PARSE_NONE; - U32 expectedDataLength = sizeof(CONDUCTIVITY_EEPROM_DATA_T); + COND_PARSE_STATUS parseStatus = COND_PARSE_NONE; + U32 expectedDataLength = sizeof( COND_EEPROM_DATA_T ); // Validate buffer - if (buffer == NULL) + if ( buffer == NULL) { - parseStatus = CONDUCTIVITY_PARSE_ERROR_NULL_BUFFER; + parseStatus = COND_PARSE_ERROR_NULL_BUFFER; } // Validate buffer length - else if (len != expectedDataLength) + else if ( len != expectedDataLength ) { - parseStatus = CONDUCTIVITY_PARSE_ERROR_INVALID_LENGTH; + parseStatus = COND_PARSE_ERROR_INVALID_LENGTH; } else { // Parse and Store the data - memcpy(&eePromDataRX, buffer, expectedDataLength); - parseStatus = CONDUCTIVITY_PARSE_SUCCESS; + memcpy(&eePromDataRX, buffer, expectedDataLength ); + parseStatus = COND_PARSE_SUCCESS; } return parseStatus; @@ -1463,22 +1792,24 @@ /*********************************************************************//** * @brief * The parseConductivityMeasurements Reads Conductivity Measurements / Sensor readings - * from buffer and stores in rawConductivityValues. + * from buffer and stores in condRawMeasurement. + * Calculates the conductivity and temperature and stores in condCalculatedMeasurement. * @details \b Inputs : none - * @details \b Outputs: rawConductivityValues - Raw Conductivity Measurements / Sensor readings + * @details \b Outputs: condRawMeasurement - Raw Conductivity Measurements (includes impedance and rtd) + * @details \b Outputs: condCalculatedMeasurement - Calculated Conductivity and temperature. * @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. + * @return COND_PARSE_STATUS to tell if parsing was successful or not. *************************************************************************/ -static CONDUCTIVITY_PARSE_STATUS parseConductivityMeasurements(const U08 *buffer, U32 len) +static COND_PARSE_STATUS parseConductivityMeasurements( const U08 *buffer, U32 len ) { - CONDUCTIVITY_PARSE_STATUS parseStatus = CONDUCTIVITY_PARSE_NONE; - CONDUCTIVITY_SENSOR_DATA_T tempSensor; + COND_PARSE_STATUS parseStatus = COND_PARSE_NONE; + COND_SENSOR_DATA_T tempSensor; // Validate buffer if ( NULL == buffer ) { - parseStatus = CONDUCTIVITY_PARSE_ERROR_INVALID_SENSOR_NUM; + parseStatus = COND_PARSE_ERROR_INVALID_SENSOR_NUM; } else { @@ -1488,21 +1819,29 @@ // Check if the received sensor number is valid if ( ( tempSensor.sensorNum < 1 ) || ( tempSensor.sensorNum > MAX_TEENSY_SENSOR ) ) { - parseStatus = CONDUCTIVITY_PARSE_ERROR_INVALID_SENSOR_NUM; + parseStatus = COND_PARSE_ERROR_INVALID_SENSOR_NUM; } else { - // Store value in array index for position (sensorNum - 1) - rawConductivityValues[tempSensor.sensorNum - 1] = tempSensor; + // Store value in array index for position ( sensorNum - 1 ) + condRawMeasurement[ tempSensor.sensorNum - 1 ] = tempSensor; calculateConductivity( tempSensor.sensorNum - 1 ); calculateTemperature( tempSensor.sensorNum - 1 ); - parseStatus = CONDUCTIVITY_PARSE_SUCCESS; + parseStatus = COND_PARSE_SUCCESS; } } return parseStatus; } +/*********************************************************************//** + * @brief + * The getTeensyCondId function maps Teensy Sensor Index to Conductivity Sensors. + * @details \b Inputs: + * @details \b Outputs: + * @param + * @return + *************************************************************************/ static U32 getTeensyCondId( CONDUCTIVITY_SENSORS_T sensorId ) { U32 sensorNum = 0; @@ -1531,11 +1870,12 @@ return sensorNum; } + /*********************************************************************//** * @brief * The getConductivityValue function gets the current calculated conductivity / impedance value. - * @details \b Inputs: calculatedMeasurement + * @details \b Inputs: condCalculatedMeasurement * @details \b Outputs: none * @param sensor ID of conductivity sensor to get conductivity. * @return The current conductivity sensor conductivity of a given conductivity sensor. @@ -1547,7 +1887,7 @@ if ( D74_COND != sensorId ) { - result = (F32)calculatedMeasurement[sensorNum].Conductivity; + result = ( F32 )condCalculatedMeasurement[ sensorNum ].Conductivity; } return result; @@ -1557,7 +1897,7 @@ * @brief * The getTemperatureValue function gets the current conductivity sensor * temperature for a given conductivity sensor. - * @details \b Inputs: calculatedMeasurement + * @details \b Inputs: condCalculatedMeasurement * @details \b Outputs: none * @param sensorId ID of conductivity sensor to get temperature. * @return The current conductivity sensor temperature of a given conductivity sensor. @@ -1569,46 +1909,60 @@ if ( D74_COND != sensorId ) { - result = (F32)calculatedMeasurement[sensorNum].Temperature; + result = ( F32 )condCalculatedMeasurement[ sensorNum ].Temperature; } return result; } +/*********************************************************************//** + * @brief + * The calculateConductivity function + * @details \b Inputs: + * @details \b Outputs: + * @param + * @return + *************************************************************************/ static void calculateConductivity( U32 sensorNum ) { 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; + F64 B3 = condCoeff[ sensorNum ].B3; + F64 B2 = condCoeff[ sensorNum ].B2; + F64 B1 = condCoeff[ sensorNum ].B1; + F64 B0 = condCoeff[ sensorNum ].B0; + F64 R = condRawMeasurement[ sensorNum ].impRzMag; + F64 Z = condRawMeasurement[ sensorNum ].rtdRzMag; calculatedConductivity = ( ( B3 * ( 1000.0 / R ) ) + ( B2 * ( Z / R ) ) + ( B1 * ( ( 100 * log( Z ) ) / R ) ) + B0 ); - calculatedMeasurement[sensorNum].Conductivity = calculatedConductivity; + condCalculatedMeasurement[ sensorNum ].Conductivity = calculatedConductivity; } +/*********************************************************************//** + * @brief + * The calculateTemperature function + * @details \b Inputs: + * @details \b Outputs: + * @param + * @return + *************************************************************************/ static void calculateTemperature( U32 sensorNum ) { F64 calculatedTemperature = 0.0; - F64 A1 = conductivityCoeff[ sensorNum ].A1; - F64 A0 = conductivityCoeff[ sensorNum ].A0; - F64 Z = rawConductivityValues[ sensorNum ].rtdRzMag; + F64 A1 = condCoeff[ sensorNum ].A1; + F64 A0 = condCoeff[ sensorNum ].A0; + F64 Z = condRawMeasurement[ sensorNum ].rtdRzMag; calculatedTemperature = ( ( A1 * Z ) + A0 ); - calculatedMeasurement[sensorNum].Temperature = calculatedTemperature; + condCalculatedMeasurement[ sensorNum ].Temperature = calculatedTemperature; } - /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ -