Vybhav Kadaba
/
EV-PRO-MW1001_dec12
MWARE-1930 fixed
Diff: src/admw_1001.c
- Revision:
- 6:9d393a9677f4
- Parent:
- 5:0728bde67bdb
- Child:
- 8:2f2775c34640
--- a/src/admw_1001.c Wed Jun 05 05:39:15 2019 +0000 +++ b/src/admw_1001.c Sat Jun 15 14:30:49 2019 +0000 @@ -90,7 +90,8 @@ #include "admw1001/admw1001_host_comms.h" #include "crc16.h" - +#define VERSIONID_MAJOR 1 +#define VERSIONID_MINOR 7 uint32_t getDataCnt = 0; @@ -106,13 +107,13 @@ /* Checks if a value is outside the bounds of the specified register field */ #define CHECK_REG_FIELD_VAL(_field, _val) \ do { \ - uint32_t _mask = BITM_##_field; \ - uint32_t _shift = BITP_##_field; \ + uint32_t _mask = BITM_##_field; \ + uint32_t _shift = BITP_##_field; \ if ((((_val) << _shift) & ~(_mask)) != 0) { \ - ADMW_LOG_ERROR("Value 0x%08X invalid for register field %s", \ + ADMW_LOG_ERROR("Value 0x%08X invalid for register field %s",\ (uint32_t)(_val), \ - STRINGIFY(ADMW_##_field)); \ - return ADMW_INVALID_PARAM; \ + STRINGIFY(ADMW_##_field)); \ + return ADMW_INVALID_PARAM; \ } \ } while(false) @@ -122,26 +123,26 @@ */ #define WRITE_REG(_hdev, _val, _name, _type) \ do { \ - ADMW_RESULT _res; \ + ADMW_RESULT _res; \ _type _regval = _val; \ - _res = admw1001_WriteRegister((_hdev), \ - REG_##_name, \ + _res = admw1001_WriteRegister((_hdev), \ + REG_##_name, \ &_regval, sizeof(_regval)); \ - if (_res != ADMW_SUCCESS) \ + if (_res != ADMW_SUCCESS) \ return _res; \ } while(false) /* Wrapper macro to write a value to a uint32_t register */ -#define WRITE_REG_U32(_hdev, _val, _name) \ +#define WRITE_REG_U32(_hdev, _val, _name) \ WRITE_REG(_hdev, _val, _name, uint32_t) /* Wrapper macro to write a value to a uint16_t register */ -#define WRITE_REG_U16(_hdev, _val, _name) \ +#define WRITE_REG_U16(_hdev, _val, _name) \ WRITE_REG(_hdev, _val, _name, uint16_t) /* Wrapper macro to write a value to a uint8_t register */ -#define WRITE_REG_U8(_hdev, _val, _name) \ +#define WRITE_REG_U8(_hdev, _val, _name) \ WRITE_REG(_hdev, _val, _name, uint8_t) /* Wrapper macro to write a value to a float32_t register */ -#define WRITE_REG_FLOAT(_hdev, _val, _name) \ +#define WRITE_REG_FLOAT(_hdev, _val, _name) \ WRITE_REG(_hdev, _val, _name, float32_t) /* @@ -150,27 +151,27 @@ */ #define READ_REG(_hdev, _val, _name, _type) \ do { \ - ADMW_RESULT _res; \ + ADMW_RESULT _res; \ _type _regval; \ - _res = admw1001_ReadRegister((_hdev), \ - REG_##_name, \ + _res = admw1001_ReadRegister((_hdev), \ + REG_##_name, \ &_regval, sizeof(_regval)); \ - if (_res != ADMW_SUCCESS) \ + if (_res != ADMW_SUCCESS) \ return _res; \ _val = _regval; \ } while(false) /* Wrapper macro to read a value from a uint32_t register */ -#define READ_REG_U32(_hdev, _val, _name) \ +#define READ_REG_U32(_hdev, _val, _name) \ READ_REG(_hdev, _val, _name, uint32_t) /* Wrapper macro to read a value from a uint16_t register */ -#define READ_REG_U16(_hdev, _val, _name) \ +#define READ_REG_U16(_hdev, _val, _name) \ READ_REG(_hdev, _val, _name, uint16_t) /* Wrapper macro to read a value from a uint8_t register */ -#define READ_REG_U8(_hdev, _val, _name) \ +#define READ_REG_U8(_hdev, _val, _name) \ READ_REG(_hdev, _val, _name, uint8_t) /* Wrapper macro to read a value from a float32_t register */ -#define READ_REG_FLOAT(_hdev, _val, _name) \ +#define READ_REG_FLOAT(_hdev, _val, _name) \ READ_REG(_hdev, _val, _name, float32_t) /* @@ -178,45 +179,45 @@ * NOTE - this is intended only for writing to a keyhole data register */ #define WRITE_REG_U8_ARRAY(_hdev, _arr, _len, _name) \ - do { \ - ADMW_RESULT _res; \ - _res = admw1001_WriteRegister(_hdev, \ - REG_##_name, \ - _arr, _len); \ - if (_res != ADMW_SUCCESS) \ - return _res; \ + do { \ + ADMW_RESULT _res; \ + _res = admw1001_WriteRegister(_hdev, \ + REG_##_name, \ + _arr, _len); \ + if (_res != ADMW_SUCCESS) \ + return _res; \ } while(false) /* * Wrapper macro to read an array of values from a uint8_t register * NOTE - this is intended only for reading from a keyhole data register */ -#define READ_REG_U8_ARRAY(_hdev, _arr, _len, _name) \ - do { \ - ADMW_RESULT _res; \ - _res = admw1001_ReadRegister((_hdev), \ - REG_##_name, \ - _arr, _len); \ - if (_res != ADMW_SUCCESS) \ - return _res; \ +#define READ_REG_U8_ARRAY(_hdev, _arr, _len, _name) \ + do { \ + ADMW_RESULT _res; \ + _res = admw1001_ReadRegister((_hdev), \ + REG##_name, \ + _arr, _len); \ + if (_res != ADMW_SUCCESS) \ + return _res; \ } while(false) -#define ADMW1001_CHANNEL_IS_ADC(c) \ - ((c) >= ADMW1001_CHANNEL_ID_CJC_0 && (c) <= ADMW1001_CHANNEL_ID_CURRENT_0) - -#define ADMW1001_CHANNEL_IS_ADC_CJC(c) \ - ((c) >= ADMW1001_CHANNEL_ID_CJC_0 && (c) <= ADMW1001_CHANNEL_ID_CJC_1) - -#define ADMW1001_CHANNEL_IS_ADC_SENSOR(c) \ - ((c) >= ADMW1001_CHANNEL_ID_SENSOR_0 && (c) <= ADMW1001_CHANNEL_ID_SENSOR_3) - -#define ADMW1001_CHANNEL_IS_ADC_VOLTAGE(c) \ - ((c) == ADMW1001_CHANNEL_ID_VOLTAGE_0) - -#define ADMW1001_CHANNEL_IS_ADC_CURRENT(c) \ - ((c) == ADMW1001_CHANNEL_ID_CURRENT_0) - -#define ADMW1001_CHANNEL_IS_VIRTUAL(c) \ +#define ADMW1001_CHANNEL_IS_ADC(c) \ + ((c) >= ADMW1001_CHANNEL_ID_ANALOG_1_UNIVERSAL && (c) <= ADMW1001_CHANNEL_ID_ANALOG_2_DIFFERENTIAL) + +#define ADMW1001_CHANNEL_IS_ADC_CJC(c) \ + ((c) >= ADMW1001_CHANNEL_ID_ANALOG_1_UNIVERSAL && (c) <= ADMW1001_CHANNEL_ID_ANALOG_2_UNIVERSAL) + +#define ADMW1001_CHANNEL_IS_ADC_SENSOR(c) \ + ((c) >= ADMW1001_CHANNEL_ID_ANALOG_1_UNIVERSAL && (c) <= ADMW1001_CHANNEL_ID_ANALOG_2_UNIVERSAL) + +#define ADMW1001_CHANNEL_IS_ADC_VOLTAGE(c) \ + ((c) == ADMW1001_CHANNEL_ID_ANALOG_1_DIFFERENTIAL || ADMW1001_CHANNEL_ID_ANALOG_2_DIFFERENTIAL) + +#define ADMW1001_CHANNEL_IS_ADC_CURRENT(c) \ + ((c) == ADMW1001_CHANNEL_ID_ANALOG_1_UNIVERSAL || (c) == ADMW1001_CHANNEL_ID_ANALOG_2_UNIVERSAL) + +#define ADMW1001_CHANNEL_IS_VIRTUAL(c) \ ((c) == ADMW1001_CHANNEL_ID_SPI_1 || (c) == ADMW1001_CHANNEL_ID_SPI_2) typedef struct @@ -353,8 +354,6 @@ pStatus->deviceStatus |= ADMW_DEVICE_STATUS_DATAREADY; if (statusReg.FIFO_Error) pStatus->deviceStatus |= ADMW_DEVICE_STATUS_FIFO_ERROR; - if (alert2Reg.Ext_Flash_Error) - pStatus->deviceStatus |= ADMW_DEVICE_STATUS_EXT_FLASH_ERROR; if (statusReg.Alert_Active) { pStatus->deviceStatus |= ADMW_DEVICE_STATUS_ALERT; @@ -427,12 +426,6 @@ if (diagStatusReg.Diag_Checksum_Error) pStatus->diagnosticsStatus |= ADMW_DIAGNOSTICS_STATUS_CHECKSUM_ERROR; - if (diagStatusReg.Diag_Comms_Error) - pStatus->diagnosticsStatus |= ADMW_DIAGNOSTICS_STATUS_COMMS_ERROR; - if (diagStatusReg.Diag_Supply_Monitor_Error) - pStatus->diagnosticsStatus |= ADMW_DIAGNOSTICS_STATUS_SUPPLY_MONITOR_ERROR; - if (diagStatusReg.Diag_Supply_Cap_Error) - pStatus->diagnosticsStatus |= ADMW_DIAGNOSTICS_STATUS_SUPPLY_CAP_ERROR; if (diagStatusReg.Diag_Conversion_Error) pStatus->diagnosticsStatus |= ADMW_DIAGNOSTICS_STATUS_CONVERSION_ERROR; if (diagStatusReg.Diag_Calibration_Error) @@ -477,10 +470,10 @@ /* * Don't allow another command to be issued if one is already running, but - * make an exception for CORE_COMMAND_NOP which can be used to + * make an exception for ENUM_CORE_COMMAND_NOP which can be used to * request a running command to be stopped (e.g. continuous measurement) */ - if (command != CORE_COMMAND_NOP) + if (command != ENUM_CORE_COMMAND_NOP) { eRet = admw_GetCommandRunningState(hDevice, &bCommandRunning); if (eRet) @@ -542,14 +535,10 @@ { switch (eMeasurementMode) { - case ADMW_MEASUREMENT_MODE_HEALTHCHECK: - return executeCommand(hDevice, CORE_COMMAND_SYSTEM_CHECK, false); case ADMW_MEASUREMENT_MODE_NORMAL: return executeCommand(hDevice, CORE_COMMAND_CONVERT_WITH_RAW, false); case ADMW_MEASUREMENT_MODE_OMIT_RAW: return executeCommand(hDevice, CORE_COMMAND_CONVERT, false); - case ADMW_MEASUREMENT_MODE_FFT: - return executeCommand(hDevice, CORE_COMMAND_CONVERT_FFT, false); default: ADMW_LOG_ERROR("Invalid measurement mode %d specified", eMeasurementMode); @@ -571,12 +560,6 @@ { case ADMW_FLASH_CONFIG_1: return executeCommand(hDevice, CORE_COMMAND_SAVE_CONFIG_1, true); - case ADMW_FLASH_CONFIG_2: - return executeCommand(hDevice, CORE_COMMAND_SAVE_CONFIG_2, true); - case ADMW_FLASH_CONFIG_3: - return executeCommand(hDevice, CORE_COMMAND_SAVE_CONFIG_3, true); - case ADMW_FLASH_CONFIG_4: - return executeCommand(hDevice, CORE_COMMAND_SAVE_CONFIG_4, true); default: ADMW_LOG_ERROR("Invalid user config target slot %d specified", eSlotId); @@ -596,12 +579,6 @@ { case ADMW_FLASH_CONFIG_1: return executeCommand(hDevice, CORE_COMMAND_LOAD_CONFIG_1, true); - case ADMW_FLASH_CONFIG_2: - return executeCommand(hDevice, CORE_COMMAND_LOAD_CONFIG_2, true); - case ADMW_FLASH_CONFIG_3: - return executeCommand(hDevice, CORE_COMMAND_LOAD_CONFIG_3, true); - case ADMW_FLASH_CONFIG_4: - return executeCommand(hDevice, CORE_COMMAND_LOAD_CONFIG_4, true); default: ADMW_LOG_ERROR("Invalid user config source slot %d specified", eSlotId); @@ -610,126 +587,6 @@ } /* - * Erase the entire external flash memory. - * No other command must be running when this is called. - */ -ADMW_RESULT admw_EraseExternalFlash( - ADMW_DEVICE_HANDLE const hDevice) -{ - return executeCommand(hDevice, CORE_COMMAND_ERASE_EXTERNAL_FLASH, true); -} - -/* - * Read the number of samples stored in external flash memory. - * No other command must be running when this is called. - */ -ADMW_RESULT admw_GetExternalFlashSampleCount( - ADMW_DEVICE_HANDLE const hDevice, - uint32_t * nSampleCount) -{ - CORE_Ext_Flash_Sample_Count_t nCount; - - READ_REG_U32(hDevice, nCount.VALUE32, CORE_EXT_FLASH_SAMPLE_COUNT); - - *nSampleCount = nCount.VALUE32; - - return ADMW_SUCCESS; -} - -// DEBUG - TO BE DELETED -ADMW_RESULT admw_SetExternalFlashIndex( - ADMW_DEVICE_HANDLE const hDevice, - uint32_t nStartIndex) -{ - WRITE_REG_U32(hDevice, nStartIndex, CORE_EXT_FLASH_INDEX); - - return ADMW_SUCCESS; -} - -/* - * Read a set of data samples stored in the device external flash memory. - * This may be called at any time. - */ -ADMW_RESULT admw_GetExternalFlashData( - ADMW_DEVICE_HANDLE const hDevice, - ADMW_DATA_SAMPLE * const pSamples, - uint32_t const nStartIndex, - uint32_t const nRequested, - uint32_t * const pnReturned) -{ - ADMW_DEVICE_CONTEXT *pCtx = hDevice; - uint16_t command = ADMW1001_HOST_COMMS_READ_CMD | - (REG_CORE_EXT_FLASH_DATA & ADMW1001_HOST_COMMS_ADR_MASK); - uint8_t commandData[2] = { - command >> 8, - command & 0xFF - }; - uint8_t commandResponse[2]; - unsigned nValidSamples = 0; - ADMW_RESULT eRet = ADMW_SUCCESS; - - /* Setup initial sample */ - WRITE_REG_U32(hDevice, nStartIndex, CORE_EXT_FLASH_INDEX); - - /* Send flash read command */ - do { - eRet = admw_SpiTransfer(pCtx->hSpi, commandData, commandResponse, - sizeof(command), false); - if (eRet) - { - ADMW_LOG_ERROR("Failed to send read command for external flash"); - return eRet; - } - - admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); - } while ((commandResponse[0] != ADMW1001_HOST_COMMS_CMD_RESP_0) || - (commandResponse[1] != ADMW1001_HOST_COMMS_CMD_RESP_1)); - - /* Read samples from external flash memory */ - for (unsigned i = 0; i < nRequested; i++) - { - ADMW1001_Sensor_Result_t sensorResult; - bool bHoldCs = true; - - /* Keep the CS signal asserted for all but the last sample */ - if ((i + 1) == nRequested) - bHoldCs = false; - - eRet = admw_SpiTransfer(pCtx->hSpi, NULL, (uint8_t *) (&sensorResult), - 8, bHoldCs); - if (eRet) - { - ADMW_LOG_ERROR("Failed to read data from external flash"); - return eRet; - } - - ADMW_DATA_SAMPLE *pSample = &pSamples[nValidSamples]; - - pSample->status = (ADMW_DEVICE_STATUS_FLAGS)0; - if (sensorResult.Ch_Error) - pSample->status |= ADMW_DEVICE_STATUS_ERROR; - if (sensorResult.Ch_Alert) - pSample->status |= ADMW_DEVICE_STATUS_ALERT; - - if (sensorResult.Ch_Raw) - pSample->rawValue = sensorResult.Raw_Sample; - else - pSample->rawValue = 0; - - pSample->channelId = sensorResult.Channel_ID; - pSample->processedValue = sensorResult.Sensor_Result; - - nValidSamples++; - } - *pnReturned = nValidSamples; - - admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); - - return eRet; -} - - -/* * Store the LUT data to persistent memory on the device. * No other command must be running when this is called. * Do not power down the device while this command is running. @@ -761,28 +618,6 @@ } /* - * Run built-in diagnostic checks on the device. - * Diagnostics are executed according to the current applied settings. - * No other command must be running when this is called. - */ -ADMW_RESULT admw_RunDiagnostics( - ADMW_DEVICE_HANDLE const hDevice) -{ - return executeCommand(hDevice, CORE_COMMAND_RUN_DIAGNOSTICS, true); -} - -/* - * Run self-calibration routines on the device. - * Calibration is executed according to the current applied settings. - * No other command must be running when this is called. - */ -ADMW_RESULT admw_RunCalibration( - ADMW_DEVICE_HANDLE const hDevice) -{ - return executeCommand(hDevice, CORE_COMMAND_SELF_CALIBRATION, true); -} - -/* * Run digital calibration routines on the device. * Calibration is executed according to the current applied settings. * No other command must be running when this is called. @@ -942,6 +777,48 @@ return ADMW_SUCCESS; } +ADMW_RESULT admw1001_Write_Debug_Register( + ADMW_DEVICE_HANDLE hDevice, + uint16_t nAddress, + void *pData, + unsigned nLength) +{ + ADMW_RESULT eRet; + ADMW_DEVICE_CONTEXT *pCtx = hDevice; + uint16_t command = ADMW1001_HOST_COMMS_DEBUG_WRITE_CMD | + (nAddress & ADMW1001_HOST_COMMS_ADR_MASK); + uint8_t commandData[2] = { + command >> 8, + command & 0xFF + }; + uint8_t commandResponse[2]; + + do { + eRet = admw_SpiTransfer(pCtx->hSpi, commandData, commandResponse, + sizeof(command), false); + if (eRet) + { + ADMW_LOG_ERROR("Failed to send write command for register %u", + nAddress); + return eRet; + } + + admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); + } while ((commandResponse[0] != ADMW1001_HOST_COMMS_CMD_RESP_0) || + (commandResponse[1] != ADMW1001_HOST_COMMS_CMD_RESP_1)); + + eRet = admw_SpiTransfer(pCtx->hSpi, pData, NULL, nLength, false); + if (eRet) + { + ADMW_LOG_ERROR("Failed to write data (%dB) to register %u", + nLength, nAddress); + return eRet; + } + + admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); + + return ADMW_SUCCESS; +} ADMW_RESULT admw1001_ReadRegister( ADMW_DEVICE_HANDLE hDevice, uint16_t nAddress, @@ -985,6 +862,48 @@ return ADMW_SUCCESS; } +ADMW_RESULT admw1001_Read_Debug_Register( + ADMW_DEVICE_HANDLE hDevice, + uint16_t nAddress, + void *pData, + unsigned nLength) +{ + ADMW_RESULT eRet; + ADMW_DEVICE_CONTEXT *pCtx = hDevice; + uint16_t command = ADMW1001_HOST_COMMS_DEBUG_READ_CMD | + (nAddress & ADMW1001_HOST_COMMS_ADR_MASK); + uint8_t commandData[2] = { + command >> 8, + command & 0xFF + }; + uint8_t commandResponse[2]; + + do { + eRet = admw_SpiTransfer(pCtx->hSpi, commandData, commandResponse, + sizeof(command), false); + if (eRet) + { + ADMW_LOG_ERROR("Failed to send read command for register %u", + nAddress); + return eRet; + } + + admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); + } while ((commandResponse[0] != ADMW1001_HOST_COMMS_CMD_RESP_0) || + (commandResponse[1] != ADMW1001_HOST_COMMS_CMD_RESP_1)); + + eRet = admw_SpiTransfer(pCtx->hSpi, NULL, pData, nLength, false); + if (eRet) + { + ADMW_LOG_ERROR("Failed to read data (%uB) from register %u", + nLength, nAddress); + return eRet; + } + + admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); + + return ADMW_SUCCESS; +} ADMW_RESULT admw_GetDeviceReadyState( ADMW_DEVICE_HANDLE const hDevice, bool * const bReady) @@ -1013,167 +932,94 @@ CORE_Mode_t modeReg; READ_REG_U8(hDevice, modeReg.VALUE8, CORE_MODE); - if ((eMeasurementMode == ADMW_MEASUREMENT_MODE_HEALTHCHECK) || - (modeReg.Conversion_Mode == CORE_MODE_SINGLECYCLE)) + if (eMeasurementMode == (modeReg.Conversion_Mode == CORE_MODE_SINGLECYCLE)) *peOperatingMode = ADMW1001_OPERATING_MODE_SINGLECYCLE; else if (modeReg.Conversion_Mode == CORE_MODE_MULTICYCLE) *peOperatingMode = ADMW1001_OPERATING_MODE_MULTICYCLE; else *peOperatingMode = ADMW1001_OPERATING_MODE_CONTINUOUS; - - /* FFT mode is quite different to the other modes: - * - Each FFT result produces a batch of samples - * - The size of the batch depends on selected FFT size and output config options - * - DATAREADY will fire for each FFT result (once per channel) - * - The size of the cycle depends on the number of channels enabled for FFT - */ - if (eMeasurementMode == ADMW_MEASUREMENT_MODE_FFT) + if (eMeasurementMode == ADMW_MEASUREMENT_MODE_OMIT_RAW) { - CORE_FFT_Config_t fftConfigReg; - - unsigned nFftChannels; - unsigned nSamplesPerChannel; - - READ_REG_U32(hDevice, fftConfigReg.VALUE32, CORE_FFT_CONFIG); - - nFftChannels = fftConfigReg.FFT_Num_Channels + 1; - - if (fftConfigReg.FFT_Output == CORE_FFT_CONFIG_FFT_OUTPUT_MAX16) - { - nSamplesPerChannel = 16; - *pnBytesPerSample = 8; - } - else if (fftConfigReg.FFT_Output == CORE_FFT_CONFIG_FFT_OUTPUT_FULL) - { - nSamplesPerChannel = (256 << fftConfigReg.FFT_Num_Bins) >> 1; - *pnBytesPerSample = 5; - } - else if (fftConfigReg.FFT_Output == CORE_FFT_CONFIG_FFT_OUTPUT_FULL_WITH_RAW) - { - nSamplesPerChannel = (256 << fftConfigReg.FFT_Num_Bins); - *pnBytesPerSample = 8; - } - else - { - ADMW_LOG_ERROR("Invalid FFT output format option %d configured", - fftConfigReg.FFT_Output); - return ADMW_INVALID_PARAM; - } - - *pnSamplesPerDataready = nSamplesPerChannel; - *pnSamplesPerCycle = nSamplesPerChannel * nFftChannels; - - *peDataReadyMode = ADMW1001_DATAREADY_PER_CYCLE; - - if (modeReg.FFT_Mode == CORE_MODE_FFT_MODE_CONTINUOUS) - { - *peOperatingMode = ADMW1001_OPERATING_MODE_CONTINUOUS; - } - else - { - *peOperatingMode = ADMW1001_OPERATING_MODE_SINGLECYCLE; - } + *pnBytesPerSample = 5; } else { - if (eMeasurementMode == ADMW_MEASUREMENT_MODE_OMIT_RAW) - { - *pnBytesPerSample = 5; - } - else - { - *pnBytesPerSample = 8; - } - - for (ADMW1001_CHANNEL_ID chId = ADMW1001_CHANNEL_ID_CJC_0; - chId < ADMW1001_MAX_CHANNELS; - chId++) + *pnBytesPerSample = 8; + } + + for (ADMW1001_CHANNEL_ID chId = ADMW1001_CHANNEL_ID_ANALOG_1_UNIVERSAL; + chId < ADMW1001_MAX_CHANNELS; + chId++) + { + CORE_Sensor_Details_t sensorDetailsReg; + CORE_Channel_Count_t channelCountReg; + + if (ADMW1001_CHANNEL_IS_VIRTUAL(chId)) + continue; + + READ_REG_U8(hDevice, channelCountReg.VALUE8, CORE_CHANNEL_COUNTn(chId)); + READ_REG_U32(hDevice, sensorDetailsReg.VALUE32, CORE_SENSOR_DETAILSn(chId)); + + if (channelCountReg.Channel_Enable && !sensorDetailsReg.Do_Not_Publish) + { + CORE_Sensor_Type_t sensorTypeReg; + unsigned nActualChannels = 1; + + READ_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(chId)); + + if (chId == ADMW1001_CHANNEL_ID_SPI_0) { - CORE_Sensor_Details_t sensorDetailsReg; - CORE_Channel_Count_t channelCountReg; - - if (ADMW1001_CHANNEL_IS_VIRTUAL(chId)) - continue; - - READ_REG_U8(hDevice, channelCountReg.VALUE8, CORE_CHANNEL_COUNTn(chId)); - READ_REG_U32(hDevice, sensorDetailsReg.VALUE32, CORE_SENSOR_DETAILSn(chId)); - - if (channelCountReg.Channel_Enable && !sensorDetailsReg.Do_Not_Publish) - { - CORE_Sensor_Type_t sensorTypeReg; - unsigned nActualChannels = 1; - - READ_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(chId)); - - if (chId == ADMW1001_CHANNEL_ID_SPI_0) - { - /* Some sensors automatically generate samples on additional "virtual" channels - * so these channels must be counted as active when those sensors are selected - * and we use the count from the corresponding "physical" channel */ - if ((sensorTypeReg.Sensor_Type >= - CORE_SENSOR_TYPE_SENSOR_SPI_ACCELEROMETER_A_DEF_L1) && - (sensorTypeReg.Sensor_Type <= - CORE_SENSOR_TYPE_SENSOR_SPI_ACCELEROMETER_B_ADV_L2)) - nActualChannels += 2; - } - - nChannelsEnabled += nActualChannels; - if (eMeasurementMode == ADMW_MEASUREMENT_MODE_HEALTHCHECK) - /* Assume a single sample per channel in test mode */ - nSamplesPerCycle += nActualChannels; - else - nSamplesPerCycle += nActualChannels * - (channelCountReg.Channel_Count + 1); - } + /* Some sensors automatically generate samples on additional "virtual" channels + * so these channels must be counted as active when those sensors are selected + * and we use the count from the corresponding "physical" channel */ + if ((sensorTypeReg.Sensor_Type >= + CORE_SENSOR_TYPE_SPI_ACCELEROMETER_A) && + (sensorTypeReg.Sensor_Type <= + CORE_SENSOR_TYPE_SPI_ACCELEROMETER_B)) + nActualChannels += 2; } - - if (nChannelsEnabled == 0) - { - *pnSamplesPerDataready = 0; - *pnSamplesPerCycle = 0; - return ADMW_SUCCESS; - } - - *pnSamplesPerCycle = nSamplesPerCycle; - - if (modeReg.Drdy_Mode == CORE_MODE_DRDY_PER_CONVERSION) - { - *pnSamplesPerDataready = 1; - } - else if (modeReg.Drdy_Mode == CORE_MODE_DRDY_PER_CYCLE) - { - *pnSamplesPerDataready = nSamplesPerCycle; - } - else - { - /* Assume DRDY will be asserted after max. 1 cycle in test mode */ - if (eMeasurementMode == ADMW_MEASUREMENT_MODE_HEALTHCHECK) - { - *pnSamplesPerDataready = nSamplesPerCycle; - } - else - { - CORE_Fifo_Num_Cycles_t fifoNumCyclesReg; - READ_REG_U8(hDevice, fifoNumCyclesReg.VALUE8, CORE_FIFO_NUM_CYCLES); - - *pnSamplesPerDataready = - nSamplesPerCycle * fifoNumCyclesReg.Fifo_Num_Cycles; - } - } - - if (modeReg.Drdy_Mode == CORE_MODE_DRDY_PER_CONVERSION) - *peDataReadyMode = ADMW1001_DATAREADY_PER_CONVERSION; - else if (modeReg.Drdy_Mode == CORE_MODE_DRDY_PER_CYCLE) - *peDataReadyMode = ADMW1001_DATAREADY_PER_CYCLE; - else - { - /* Assume DRDY will be asserted after max. 1 cycle in test mode */ - if (eMeasurementMode == ADMW_MEASUREMENT_MODE_HEALTHCHECK) - *peDataReadyMode = ADMW1001_DATAREADY_PER_CYCLE; - else - *peDataReadyMode = ADMW1001_DATAREADY_PER_MULTICYCLE_BURST; - } + + nChannelsEnabled += nActualChannels; + + nSamplesPerCycle += nActualChannels * + (channelCountReg.Channel_Count + 1); + } + } + + if (nChannelsEnabled == 0) + { + *pnSamplesPerDataready = 0; + *pnSamplesPerCycle = 0; + return ADMW_SUCCESS; + } + + *pnSamplesPerCycle = nSamplesPerCycle; + + if (modeReg.Drdy_Mode == ENUM_CORE_MODE_DRDY_PER_CONVERSION) + { + *pnSamplesPerDataready = 1; + } + else if (modeReg.Drdy_Mode == ENUM_CORE_MODE_DRDY_PER_CYCLE) + { + *pnSamplesPerDataready = nSamplesPerCycle; + } + else + { + CORE_Fifo_Num_Cycles_t fifoNumCyclesReg; + READ_REG_U8(hDevice, fifoNumCyclesReg.VALUE8, CORE_FIFO_NUM_CYCLES); + + *pnSamplesPerDataready = + nSamplesPerCycle * fifoNumCyclesReg.Fifo_Num_Cycles; + } + + if (modeReg.Drdy_Mode == ENUM_CORE_MODE_DRDY_PER_CONVERSION) + *peDataReadyMode = ADMW1001_DATAREADY_PER_CONVERSION; + else if (modeReg.Drdy_Mode == ENUM_CORE_MODE_DRDY_PER_CYCLE) + *peDataReadyMode = ADMW1001_DATAREADY_PER_CYCLE; + else + { + *peDataReadyMode = ADMW1001_DATAREADY_PER_MULTICYCLE_BURST; } return ADMW_SUCCESS; @@ -1200,17 +1046,13 @@ { CORE_Power_Config_t powerConfigReg; - if (powerMode == ADMW1001_POWER_MODE_LOW) - { - powerConfigReg.Power_Mode_ADC = CORE_POWER_CONFIG_ADC_LOW_POWER; - } - else if (powerMode == ADMW1001_POWER_MODE_MID) + if (powerMode == ADMW1001_POWER_MODE_HIBERNATION) { - powerConfigReg.Power_Mode_ADC = CORE_POWER_CONFIG_ADC_MID_POWER; + powerConfigReg.Power_Mode_MCU = CORE_POWER_CONFIG_HIBERNATION; } - else if (powerMode == ADMW1001_POWER_MODE_FULL) + else if (powerMode == ADMW1001_POWER_MODE_ACTIVE) { - powerConfigReg.Power_Mode_ADC = CORE_POWER_CONFIG_ADC_FULL_POWER; + powerConfigReg.Power_Mode_MCU = CORE_POWER_CONFIG_ACTIVE_MODE; } else { @@ -1243,7 +1085,6 @@ ADMW_DEVICE_HANDLE hDevice, ADMW1001_OPERATING_MODE eOperatingMode, ADMW1001_DATAREADY_MODE eDataReadyMode, - ADMW1001_CALIBRATION_MODE eCalibrationMode, bool bEnableExtFlash) { CORE_Mode_t modeReg; @@ -1297,25 +1138,6 @@ return ADMW_INVALID_PARAM; } - if (eCalibrationMode == ADMW1001_NO_CALIBRATION) - { - modeReg.Calibration_Method = CORE_MODE_NO_CAL; - } - else if (eCalibrationMode == ADMW1001_DO_CALIBRATION) - { - modeReg.Calibration_Method = CORE_MODE_DO_CAL; - } - else - { - ADMW_LOG_ERROR("Invalid calibration mode %d specified", - eCalibrationMode); - return ADMW_INVALID_PARAM; - } - - modeReg.Ext_Flash_Store = (bEnableExtFlash ? - CORE_MODE_EXT_FLASH_USED : - CORE_MODE_EXT_FLASH_NOT_USED); - WRITE_REG_U8(hDevice, modeReg.VALUE8, CORE_MODE); return ADMW_SUCCESS; @@ -1323,13 +1145,13 @@ ADMW_RESULT admw_SetCycleControl( ADMW_DEVICE_HANDLE hDevice, - uint32_t nCycleInterval, + uint32_t nCycleInterval #ifdef __V2_3_CFG_FMT__ - ADMW1001_CYCLE_TYPE eCycleType, + , ADMW1001_CYCLE_TYPE eCycleType, ADMW1001_FILTER_SETTLING eFilterSettling) #else - ADMW1001_CYCLE_TYPE eCycleType) + ) #endif { CORE_Cycle_Control_t cycleControlReg; @@ -1354,20 +1176,6 @@ CHECK_REG_FIELD_VAL(CORE_CYCLE_CONTROL_CYCLE_TIME, nCycleInterval); cycleControlReg.Cycle_Time = nCycleInterval; - if (eCycleType == ADMW1001_CYCLE_TYPE_SWITCH) - { - cycleControlReg.Cycle_Type = CORE_CYCLE_CONTROL_CYCLE_TYPE_SWITCH; - } - else if (eCycleType == ADMW1001_CYCLE_TYPE_FULL) - { - cycleControlReg.Cycle_Type = CORE_CYCLE_CONTROL_CYCLE_TYPE_FULL; - } - else - { - ADMW_LOG_ERROR("Invalid cycle type %d specified", eCycleType); - return ADMW_INVALID_PARAM; - } - #ifdef __V2_3_CFG_FMT__ if (eFilterSettling == ADMW1001_FILTER_SETTLING_ALWAYS) { @@ -1407,11 +1215,9 @@ static ADMW_RESULT admw_SetExternalReferenceValues( ADMW_DEVICE_HANDLE hDevice, - float32_t externalRef1Value, - float32_t externalRef2Value) + float32_t externalRef1Value) { - WRITE_REG_FLOAT(hDevice, externalRef1Value, CORE_EXTERNAL_REFERENCE1); - WRITE_REG_FLOAT(hDevice, externalRef2Value, CORE_EXTERNAL_REFERENCE2); + WRITE_REG_FLOAT(hDevice, externalRef1Value, CORE_EXTERNAL_REFERENCE_RESISTOR); return ADMW_SUCCESS; } @@ -1425,7 +1231,6 @@ eRet = admw_SetMode(hDevice, pMeasConfig->operatingMode, pMeasConfig->dataReadyMode, - pMeasConfig->calibrationMode, pMeasConfig->enableExternalFlash); if (eRet != ADMW_SUCCESS) { @@ -1434,8 +1239,7 @@ } eRet = admw_SetCycleControl(hDevice, - pMeasConfig->cycleInterval, - pMeasConfig->cycleType); + pMeasConfig->cycleInterval); if (eRet != ADMW_SUCCESS) { ADMW_LOG_ERROR("Failed to set cycle control"); @@ -1452,10 +1256,12 @@ return eRet; } } - - eRet = admw_SetExternalReferenceValues(hDevice, - pMeasConfig->externalRef1Value, - pMeasConfig->externalRef2Value); + if(pMeasConfig->externalRef1Value>0) + eRet = admw_SetExternalReferenceValues(hDevice, + pMeasConfig->externalRef1Value); + else + ; + if (eRet != ADMW_SUCCESS) { ADMW_LOG_ERROR("Failed to set external reference values"); @@ -1508,118 +1314,6 @@ return ADMW_SUCCESS; } -ADMW_RESULT admw1001_SetFftConfig( - ADMW_DEVICE_HANDLE hDevice, - ADMW1001_FFT_CONFIG *pFftConfig, - ADMW1001_CHANNEL_CONFIG *pChannels) -{ - CORE_FFT_Config_t fftConfigReg; - CORE_Mode_t modeReg; - uint32_t numFftChannels = 0; - - fftConfigReg.VALUE32 = REG_RESET_VAL(CORE_FFT_CONFIG); - - for (ADMW1001_CHANNEL_ID id = ADMW1001_CHANNEL_ID_CJC_0; - id < ADMW1001_MAX_CHANNELS; - id++) - { - if (pChannels[id].enableFFT) - { - if (numFftChannels >= 4) /* TODO - temporary limit */ - { - ADMW_LOG_ERROR("Maximum limit of 4 FFT channels exceeded"); - return ADMW_INVALID_PARAM; - } - - numFftChannels++; - } - } - - if (numFftChannels > 0) - { - fftConfigReg.FFT_Num_Channels = numFftChannels - 1; - - switch (pFftConfig->size) - { - case ADMW1001_FFT_SIZE_256: - fftConfigReg.FFT_Num_Bins = CORE_FFT_CONFIG_FFT_BINS_256; - break; - case ADMW1001_FFT_SIZE_512: - fftConfigReg.FFT_Num_Bins = CORE_FFT_CONFIG_FFT_BINS_512; - break; - case ADMW1001_FFT_SIZE_1024: - fftConfigReg.FFT_Num_Bins = CORE_FFT_CONFIG_FFT_BINS_1024; - break; - case ADMW1001_FFT_SIZE_2048: - fftConfigReg.FFT_Num_Bins = CORE_FFT_CONFIG_FFT_BINS_2048; - break; - default: - ADMW_LOG_ERROR("Invalid FFT size option %d specified", - pFftConfig->size); - return ADMW_INVALID_PARAM; - } - - switch (pFftConfig->window) - { - case ADMW1001_FFT_WINDOW_NONE: - fftConfigReg.FFT_Window = CORE_FFT_CONFIG_FFT_WINDOW_NONE; - break; - case ADMW1001_FFT_WINDOW_HANN: - fftConfigReg.FFT_Window = CORE_FFT_CONFIG_FFT_WINDOW_HANN; - break; - case ADMW1001_FFT_WINDOW_BLACKMAN_HARRIS: - fftConfigReg.FFT_Window = CORE_FFT_CONFIG_FFT_WINDOW_BLACKMANN_HARRIS; - break; - default: - ADMW_LOG_ERROR("Invalid FFT window option %d specified", - pFftConfig->window); - return ADMW_INVALID_PARAM; - } - - switch (pFftConfig->output) - { - case ADMW1001_FFT_OUTPUT_FULL: - fftConfigReg.FFT_Output = CORE_FFT_CONFIG_FFT_OUTPUT_FULL; - break; - case ADMW1001_FFT_OUTPUT_MAX16: - fftConfigReg.FFT_Output = CORE_FFT_CONFIG_FFT_OUTPUT_MAX16; - break; - case ADMW1001_FFT_OUTPUT_FULL_WITH_RAW: - fftConfigReg.FFT_Output = CORE_FFT_CONFIG_FFT_OUTPUT_FULL_WITH_RAW; - break; - default: - ADMW_LOG_ERROR("Invalid FFT output format option %d specified", - pFftConfig->output); - return ADMW_INVALID_PARAM; - } - } - WRITE_REG_U32(hDevice, fftConfigReg.VALUE32, CORE_FFT_CONFIG); - - if (numFftChannels > 0) - { - READ_REG_U8(hDevice, modeReg.VALUE8, CORE_MODE); - - if (pFftConfig->mode == ADMW1001_FFT_MODE_SINGLE) - { - modeReg.FFT_Mode = CORE_MODE_FFT_MODE_SINGLE; - } - else if (pFftConfig->mode == ADMW1001_FFT_MODE_CONTINUOUS) - { - modeReg.FFT_Mode = CORE_MODE_FFT_MODE_CONTINUOUS; - } - else - { - ADMW_LOG_ERROR("Invalid FFT mode %d specified", - pFftConfig->mode); - return ADMW_INVALID_PARAM; - } - - WRITE_REG_U8(hDevice, modeReg.VALUE8, CORE_MODE); - } - - return ADMW_SUCCESS; -} - ADMW_RESULT admw1001_SetChannelCount( ADMW_DEVICE_HANDLE hDevice, ADMW1001_CHANNEL_ID eChannelId, @@ -1652,8 +1346,7 @@ ADMW_RESULT admw1001_SetChannelOptions( ADMW_DEVICE_HANDLE hDevice, ADMW1001_CHANNEL_ID eChannelId, - ADMW1001_CHANNEL_PRIORITY ePriority, - bool bEnableFft) + ADMW1001_CHANNEL_PRIORITY ePriority) { CORE_Channel_Options_t channelOptionsReg; @@ -1661,7 +1354,6 @@ CHECK_REG_FIELD_VAL(CORE_CHANNEL_OPTIONS_CHANNEL_PRIORITY, ePriority); channelOptionsReg.Channel_Priority = ePriority; - channelOptionsReg.FFT_Enable_Ch = bEnableFft ? 1 : 0; WRITE_REG_U8(hDevice, channelOptionsReg.VALUE8, CORE_CHANNEL_OPTIONSn(eChannelId)); @@ -1698,153 +1390,145 @@ /* Ensure that the sensor type is valid for this channel */ switch(sensorType) { - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_J_DEF_L1: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_K_DEF_L1: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_T_DEF_L1: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_1_DEF_L2: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_2_DEF_L2: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_3_DEF_L2: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_4_DEF_L2: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_J_ADV_L1: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_K_ADV_L1: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_T_ADV_L1: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_1_ADV_L2: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_2_ADV_L2: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_3_ADV_L2: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_4_ADV_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_1_DEF_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_2_DEF_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_3_DEF_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_4_DEF_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_1_ADV_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_2_ADV_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_3_ADV_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_4_ADV_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_1_DEF_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_2_DEF_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_3_DEF_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_4_DEF_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_1_ADV_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_2_ADV_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_3_ADV_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_4_ADV_L2: - if (! ADMW1001_CHANNEL_IS_ADC_SENSOR(eChannelId)) - { - ADMW_LOG_ERROR( - "Invalid ADC sensor type %d specified for channel %d", - sensorType, eChannelId); + case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT100_DEF_L1: + case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT1000_DEF_L1: + case ADMW1001_ADC_SENSOR_RTD_3WIRE_1_DEF_L2: + case ADMW1001_ADC_SENSOR_RTD_3WIRE_2_DEF_L2: + case ADMW1001_ADC_SENSOR_RTD_3WIRE_3_DEF_L2: + case ADMW1001_ADC_SENSOR_RTD_3WIRE_4_DEF_L2: + case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT100_ADV_L1: + case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT1000_ADV_L1: + case ADMW1001_ADC_SENSOR_RTD_3WIRE_1_ADV_L2: + case ADMW1001_ADC_SENSOR_RTD_3WIRE_2_ADV_L2: + case ADMW1001_ADC_SENSOR_RTD_3WIRE_3_ADV_L2: + case ADMW1001_ADC_SENSOR_RTD_3WIRE_4_ADV_L2: + case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT100_DEF_L1: + case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT1000_DEF_L1: + case ADMW1001_ADC_SENSOR_RTD_4WIRE_1_DEF_L2: + case ADMW1001_ADC_SENSOR_RTD_4WIRE_2_DEF_L2: + case ADMW1001_ADC_SENSOR_RTD_4WIRE_3_DEF_L2: + case ADMW1001_ADC_SENSOR_RTD_4WIRE_4_DEF_L2: + case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT100_ADV_L1: + case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT1000_ADV_L1: + case ADMW1001_ADC_SENSOR_RTD_4WIRE_1_ADV_L2: + case ADMW1001_ADC_SENSOR_RTD_4WIRE_2_ADV_L2: + case ADMW1001_ADC_SENSOR_RTD_4WIRE_3_ADV_L2: + case ADMW1001_ADC_SENSOR_RTD_4WIRE_4_ADV_L2: + case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_1_DEF_L2: + case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_2_DEF_L2: + case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_3_DEF_L2: + case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_4_DEF_L2: + case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_1_ADV_L2: + case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_2_ADV_L2: + case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_3_ADV_L2: + case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_4_ADV_L2: + case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_1_DEF_L2: + case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_2_DEF_L2: + case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_3_DEF_L2: + case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_4_DEF_L2: + case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_1_ADV_L2: + case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_2_ADV_L2: + case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_3_ADV_L2: + case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_4_ADV_L2: + case ADMW1001_ADC_SENSOR_MICROPHONE_A_DEF_L1: + case ADMW1001_ADC_SENSOR_MICROPHONE_B_DEF_L1: + case ADMW1001_ADC_SENSOR_MICROPHONE_1_DEF_L2: + case ADMW1001_ADC_SENSOR_MICROPHONE_2_DEF_L2: + case ADMW1001_ADC_SENSOR_MICROPHONE_A_ADV_L1: + case ADMW1001_ADC_SENSOR_MICROPHONE_B_ADV_L1: + case ADMW1001_ADC_SENSOR_MICROPHONE_1_ADV_L2: + case ADMW1001_ADC_SENSOR_MICROPHONE_2_ADV_L2: + case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT100_DEF_L1: + case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT1000_DEF_L1: + case ADMW1001_ADC_SENSOR_RTD_2WIRE_1_DEF_L2: + case ADMW1001_ADC_SENSOR_RTD_2WIRE_2_DEF_L2: + case ADMW1001_ADC_SENSOR_RTD_2WIRE_3_DEF_L2: + case ADMW1001_ADC_SENSOR_RTD_2WIRE_4_DEF_L2: + case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT100_ADV_L1: + case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT1000_ADV_L1: + case ADMW1001_ADC_SENSOR_RTD_2WIRE_1_ADV_L2: + case ADMW1001_ADC_SENSOR_RTD_2WIRE_2_ADV_L2: + case ADMW1001_ADC_SENSOR_RTD_2WIRE_3_ADV_L2: + case ADMW1001_ADC_SENSOR_RTD_2WIRE_4_ADV_L2: + case ADMW1001_ADC_SENSOR_DIODE_2C_TYPEA_DEF_L1: + case ADMW1001_ADC_SENSOR_DIODE_3C_TYPEA_DEF_L1: + case ADMW1001_ADC_SENSOR_DIODE_2C_1_DEF_L2: + case ADMW1001_ADC_SENSOR_DIODE_3C_1_DEF_L2: + case ADMW1001_ADC_SENSOR_DIODE_2C_TYPEA_ADV_L1: + case ADMW1001_ADC_SENSOR_DIODE_3C_TYPEA_ADV_L1: + case ADMW1001_ADC_SENSOR_DIODE_2C_1_ADV_L2: + case ADMW1001_ADC_SENSOR_DIODE_3C_1_ADV_L2: + case ADMW1001_ADC_SENSOR_THERMISTOR_A_10K_DEF_L1: + case ADMW1001_ADC_SENSOR_THERMISTOR_B_10K_DEF_L1: + case ADMW1001_ADC_SENSOR_THERMISTOR_1_DEF_L2: + case ADMW1001_ADC_SENSOR_THERMISTOR_2_DEF_L2: + case ADMW1001_ADC_SENSOR_THERMISTOR_3_DEF_L2: + case ADMW1001_ADC_SENSOR_THERMISTOR_4_DEF_L2: + case ADMW1001_ADC_SENSOR_THERMISTOR_A_10K_ADV_L1: + case ADMW1001_ADC_SENSOR_THERMISTOR_B_10K_ADV_L1: + case ADMW1001_ADC_SENSOR_THERMISTOR_1_ADV_L2: + case ADMW1001_ADC_SENSOR_THERMISTOR_2_ADV_L2: + case ADMW1001_ADC_SENSOR_THERMISTOR_3_ADV_L2: + case ADMW1001_ADC_SENSOR_THERMISTOR_4_ADV_L2: + if (! (ADMW1001_CHANNEL_IS_ADC_SENSOR(eChannelId) || + ADMW1001_CHANNEL_IS_ADC_CJC(eChannelId))) + { + ADMW_LOG_ERROR( + "Invalid ADC sensor type %d specified for channel %d", + sensorType, eChannelId); + return ADMW_INVALID_PARAM; + } + break; + case ADMW1001_ADC_SENSOR_VOLTAGE: + case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_A_DEF_L1: + case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_B_DEF_L1: + case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_1_DEF_L2: + case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_2_DEF_L2: + case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_A_ADV_L1: + case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_B_ADV_L1: + case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_1_ADV_L2: + case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_2_ADV_L2: + case ADMW1001_ADC_SENSOR_THERMOCOUPLE_J_DEF_L1: + case ADMW1001_ADC_SENSOR_THERMOCOUPLE_K_DEF_L1: + case ADMW1001_ADC_SENSOR_THERMOCOUPLE_T_DEF_L1: + case ADMW1001_ADC_SENSOR_THERMOCOUPLE_1_DEF_L2: + case ADMW1001_ADC_SENSOR_THERMOCOUPLE_2_DEF_L2: + case ADMW1001_ADC_SENSOR_THERMOCOUPLE_3_DEF_L2: + case ADMW1001_ADC_SENSOR_THERMOCOUPLE_4_DEF_L2: + case ADMW1001_ADC_SENSOR_THERMOCOUPLE_J_ADV_L1: + case ADMW1001_ADC_SENSOR_THERMOCOUPLE_K_ADV_L1: + case ADMW1001_ADC_SENSOR_THERMOCOUPLE_T_ADV_L1: + case ADMW1001_ADC_SENSOR_THERMOCOUPLE_1_ADV_L2: + case ADMW1001_ADC_SENSOR_THERMOCOUPLE_2_ADV_L2: + case ADMW1001_ADC_SENSOR_THERMOCOUPLE_3_ADV_L2: + case ADMW1001_ADC_SENSOR_THERMOCOUPLE_4_ADV_L2: + if (! ADMW1001_CHANNEL_IS_ADC_VOLTAGE(eChannelId)) + { + ADMW_LOG_ERROR( + "Invalid ADC sensor type %d specified for channel %d", + sensorType, eChannelId); + return ADMW_INVALID_PARAM; + } + break; + case ADMW1001_ADC_SENSOR_CURRENT: + case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_A_DEF_L1: + case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_1_DEF_L2: + case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_2_DEF_L2: + case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_A_ADV_L1: + case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_1_ADV_L2: + case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_2_ADV_L2: + if (! ADMW1001_CHANNEL_IS_ADC_CURRENT(eChannelId)) + { + ADMW_LOG_ERROR( + "Invalid ADC sensor type %d specified for channel %d", + sensorType, eChannelId); + return ADMW_INVALID_PARAM; + } + break; + default: + ADMW_LOG_ERROR("Invalid/unsupported ADC sensor type %d specified", + sensorType); return ADMW_INVALID_PARAM; - } - break; - case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT100_DEF_L1: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT1000_DEF_L1: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_1_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_2_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_3_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_4_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT100_ADV_L1: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT1000_ADV_L1: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_1_ADV_L2: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_2_ADV_L2: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_3_ADV_L2: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_4_ADV_L2: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT100_DEF_L1: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT1000_DEF_L1: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_1_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_2_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_3_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_4_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT100_ADV_L1: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT1000_ADV_L1: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_1_ADV_L2: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_2_ADV_L2: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_3_ADV_L2: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_4_ADV_L2: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT100_DEF_L1: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT1000_DEF_L1: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_1_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_2_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_3_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_4_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT100_ADV_L1: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT1000_ADV_L1: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_1_ADV_L2: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_2_ADV_L2: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_3_ADV_L2: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_4_ADV_L2: - if (!ADMW1001_CHANNEL_IS_ADC_CJC(eChannelId)) - { - ADMW_LOG_ERROR( - "Invalid ADC sensor type %d specified for channel %d", - sensorType, eChannelId); - return ADMW_INVALID_PARAM; - } - break; - case ADMW1001_ADC_SENSOR_DIODE_2C_TYPEA_DEF_L1: - case ADMW1001_ADC_SENSOR_DIODE_3C_TYPEA_DEF_L1: - case ADMW1001_ADC_SENSOR_DIODE_2C_1_DEF_L2: - case ADMW1001_ADC_SENSOR_DIODE_3C_1_DEF_L2: - case ADMW1001_ADC_SENSOR_DIODE_2C_TYPEA_ADV_L1: - case ADMW1001_ADC_SENSOR_DIODE_3C_TYPEA_ADV_L1: - case ADMW1001_ADC_SENSOR_DIODE_2C_1_ADV_L2: - case ADMW1001_ADC_SENSOR_DIODE_3C_1_ADV_L2: - case ADMW1001_ADC_SENSOR_THERMISTOR_A_10K_DEF_L1: - case ADMW1001_ADC_SENSOR_THERMISTOR_B_10K_DEF_L1: - case ADMW1001_ADC_SENSOR_THERMISTOR_1_DEF_L2: - case ADMW1001_ADC_SENSOR_THERMISTOR_2_DEF_L2: - case ADMW1001_ADC_SENSOR_THERMISTOR_3_DEF_L2: - case ADMW1001_ADC_SENSOR_THERMISTOR_4_DEF_L2: - case ADMW1001_ADC_SENSOR_THERMISTOR_A_10K_ADV_L1: - case ADMW1001_ADC_SENSOR_THERMISTOR_B_10K_ADV_L1: - case ADMW1001_ADC_SENSOR_THERMISTOR_1_ADV_L2: - case ADMW1001_ADC_SENSOR_THERMISTOR_2_ADV_L2: - case ADMW1001_ADC_SENSOR_THERMISTOR_3_ADV_L2: - case ADMW1001_ADC_SENSOR_THERMISTOR_4_ADV_L2: - if (! (ADMW1001_CHANNEL_IS_ADC_SENSOR(eChannelId) || - ADMW1001_CHANNEL_IS_ADC_CJC(eChannelId))) - { - ADMW_LOG_ERROR( - "Invalid ADC sensor type %d specified for channel %d", - sensorType, eChannelId); - return ADMW_INVALID_PARAM; - } - break; - case ADMW1001_ADC_SENSOR_VOLTAGE: - case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_A_DEF_L1: - case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_B_DEF_L1: - case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_1_DEF_L2: - case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_2_DEF_L2: - case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_A_ADV_L1: - case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_B_ADV_L1: - case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_1_ADV_L2: - case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_2_ADV_L2: - if (! ADMW1001_CHANNEL_IS_ADC_VOLTAGE(eChannelId)) - { - ADMW_LOG_ERROR( - "Invalid ADC sensor type %d specified for channel %d", - sensorType, eChannelId); - return ADMW_INVALID_PARAM; - } - break; - case ADMW1001_ADC_SENSOR_CURRENT: - case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_A_DEF_L1: - case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_1_DEF_L2: - case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_2_DEF_L2: - case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_A_ADV_L1: - case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_1_ADV_L2: - case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_2_ADV_L2: - if (! ADMW1001_CHANNEL_IS_ADC_CURRENT(eChannelId)) - { - ADMW_LOG_ERROR( - "Invalid ADC sensor type %d specified for channel %d", - sensorType, eChannelId); - return ADMW_INVALID_PARAM; - } - break; - default: - ADMW_LOG_ERROR("Invalid/unsupported ADC sensor type %d specified", - sensorType); - return ADMW_INVALID_PARAM; } sensorTypeReg.Sensor_Type = sensorType; @@ -1908,10 +1592,7 @@ switch(pRefConfig->type) { case ADMW1001_ADC_REFERENCE_RESISTOR_INTERNAL_1: - sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_RINT1; - break; - case ADMW1001_ADC_REFERENCE_RESISTOR_INTERNAL_2: - sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_RINT2; + sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_INT; break; case ADMW1001_ADC_REFERENCE_VOLTAGE_INTERNAL: sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_INT; @@ -1922,15 +1603,6 @@ case ADMW1001_ADC_REFERENCE_RESISTOR_EXTERNAL_1: sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_REXT1; break; - case ADMW1001_ADC_REFERENCE_RESISTOR_EXTERNAL_2: - sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_REXT2; - break; - case ADMW1001_ADC_REFERENCE_VOLTAGE_EXTERNAL_1: - sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_VEXT1; - break; - case ADMW1001_ADC_REFERENCE_VOLTAGE_EXTERNAL_2: - sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_VEXT2; - break; case ADMW1001_ADC_REFERENCE_BRIDGE_EXCITATION: sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_EXC; break; @@ -1939,7 +1611,7 @@ pRefConfig->type); return ADMW_INVALID_PARAM; } - + switch(pAdcChannelConfig->gain) { case ADMW1001_ADC_GAIN_1X: @@ -1972,16 +1644,31 @@ return ADMW_INVALID_PARAM; } + switch(pAdcChannelConfig->rtdCurve) + { + case ADMW1001_ADC_RTD_CURVE_EUROPEAN: + sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_EUROPEAN_CURVE; + break; + case ADMW1001_ADC_RTD_CURVE_AMERICAN: + sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_AMERICAN_CURVE; + break; + case ADMW1001_ADC_RTD_CURVE_JAPANESE: + sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_JAPANESE_CURVE; + break; + case ADMW1001_ADC_RTD_CURVE_ITS90: + sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_ITS90_CURVE; + break; + default: + ADMW_LOG_ERROR("Invalid RTD Curve %d specified", + pAdcChannelConfig->rtdCurve); + return ADMW_INVALID_PARAM; + } + if (pAdcChannelConfig->enableVbias) sensorDetailsReg.Vbias = 1; else sensorDetailsReg.Vbias = 0; - if (pAdcChannelConfig->reference.disableBuffer) - sensorDetailsReg.Reference_Buffer_Disable = 1; - else - sensorDetailsReg.Reference_Buffer_Disable = 0; - if (pChannelConfig->disablePublishing) sensorDetailsReg.Do_Not_Publish = 1; else @@ -2002,22 +1689,18 @@ ADMW1001_CHANNEL_ID eChannelId, ADMW1001_ADC_FILTER_CONFIG *pFilterConfig) { - CORE_Filter_Select_t filterSelectReg; - - filterSelectReg.VALUE32 = REG_RESET_VAL(CORE_FILTER_SELECTn); + CORE_Measurement_Setup_t MeasSetupReg; + MeasSetupReg.VALUE32 = REG_RESET_VAL(CORE_MEASUREMENT_SETUPn); if (pFilterConfig->type == ADMW1001_ADC_FILTER_SINC4) { - filterSelectReg.ADC_Filter_Type = CORE_FILTER_SELECT_FILTER_SINC4; - filterSelectReg.ADC_FS = pFilterConfig->fs; + MeasSetupReg.ADC_Filter_Type = CORE_MEASUREMENT_SETUP_ENABLE_SINC4; + MeasSetupReg.ADC_SF = pFilterConfig->sf; } - else if (pFilterConfig->type == ADMW1001_ADC_FILTER_FIR_20SPS) + else if (pFilterConfig->type == ADMW1001_ADC_FILTER_SINC3) { - filterSelectReg.ADC_Filter_Type = CORE_FILTER_SELECT_FILTER_FIR_20SPS; - } - else if (pFilterConfig->type == ADMW1001_ADC_FILTER_FIR_25SPS) - { - filterSelectReg.ADC_Filter_Type = CORE_FILTER_SELECT_FILTER_FIR_25SPS; + MeasSetupReg.ADC_Filter_Type = CORE_MEASUREMENT_SETUP_ENABLE_SINC3; + MeasSetupReg.ADC_SF = pFilterConfig->sf; } else { @@ -2025,8 +1708,32 @@ pFilterConfig->type); return ADMW_INVALID_PARAM; } - - WRITE_REG_U32(hDevice, filterSelectReg.VALUE32, CORE_FILTER_SELECTn(eChannelId)); + + if(pFilterConfig->filterChop) + MeasSetupReg.Chop_Mode = 1; + else + MeasSetupReg.Chop_Mode = 1; + + if(pFilterConfig->notch1p2) + MeasSetupReg.NOTCH_EN_2 = 1; + else + MeasSetupReg.NOTCH_EN_2 = 0; + + switch(pFilterConfig->groundSwitch) + { + case ADMW1001_ADC_GND_SW_OPEN: + MeasSetupReg.GND_SW = CORE_MEASUREMENT_SETUP_GND_SW_OPEN; + break; + case ADMW1001_ADC_GND_SW_CLOSED: + MeasSetupReg.GND_SW = CORE_MEASUREMENT_SETUP_GND_SW_CLOSED; + break; + default: + ADMW_LOG_ERROR("Invalid ground switch state %d specified", + pFilterConfig->groundSwitch); + return ADMW_INVALID_PARAM; + } + + WRITE_REG_U32(hDevice, MeasSetupReg.VALUE32, CORE_MEASUREMENT_SETUPn(eChannelId)); return ADMW_SUCCESS; } @@ -2038,44 +1745,61 @@ { CORE_Channel_Excitation_t channelExcitationReg; - channelExcitationReg.VALUE8 = REG_RESET_VAL(CORE_CHANNEL_EXCITATIONn); - - if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_NONE) - { - channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_OFF; - } + channelExcitationReg.VALUE16 = REG_RESET_VAL(CORE_CHANNEL_EXCITATIONn); + + + if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_EXTERNAL) + channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_EXTERNAL; + if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_50uA) + channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_50UA; + else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_100uA) + channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_100UA; + else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_250uA) + channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_250UA; + else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_500uA) + channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_500UA; + else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_1000uA) + channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_1000UA; else { - if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_50uA) - channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_50UA; - else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_100uA) - channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_100UA; - else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_250uA) - channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_250UA; - else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_500uA) - channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_500UA; - else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_750uA) - channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_750UA; - else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_1000uA) - channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_1000UA; - else - { - ADMW_LOG_ERROR("Invalid ADC excitation current %d specified", - pCurrentConfig->outputLevel); - return ADMW_INVALID_PARAM; - } + ADMW_LOG_ERROR("Invalid ADC excitation current %d specified", + pCurrentConfig->outputLevel); + return ADMW_INVALID_PARAM; } - if (pCurrentConfig->diodeRatio == ADMW1001_ADC_EXC_CURRENT_IOUT_DIODE_DEFAULT) - { - channelExcitationReg.IOUT_Diode_Ratio = 0; + + switch(pCurrentConfig->diodeRatio) { + case ADMW1001_ADC_EXC_CURRENT_IOUT_DIODE_10UA_100UA: + channelExcitationReg.IOUT_Diode_Ratio = CORE_CHANNEL_EXCITATION_DIODE_2PT_10UA_100UA; + break; + case ADMW1001_ADC_EXC_CURRENT_IOUT_DIODE_20UA_160UA: + channelExcitationReg.IOUT_Diode_Ratio = CORE_CHANNEL_EXCITATION_DIODE_2PT_20UA_160UA; + break; + case ADMW1001_ADC_EXC_CURRENT_IOUT_DIODE_50UA_300UA: + channelExcitationReg.IOUT_Diode_Ratio = CORE_CHANNEL_EXCITATION_DIODE_2PT_50UA_300UA; + break; + case ADMW1001_ADC_EXC_CURRENT_IOUT_DIODE_100UA_600UA: + channelExcitationReg.IOUT_Diode_Ratio = CORE_CHANNEL_EXCITATION_DIODE_2PT_100UA_600UA; + break; + case ADMW1001_ADC_EXC_CURRENT_IOUT_DIODE_10UA_50UA_100UA: + channelExcitationReg.IOUT_Diode_Ratio = CORE_CHANNEL_EXCITATION_DIODE_3PT_10UA_50UA_100UA; + break; + case ADMW1001_ADC_EXC_CURRENT_IOUT_DIODE_20UA_100UA_160UA: + channelExcitationReg.IOUT_Diode_Ratio = CORE_CHANNEL_EXCITATION_DIODE_3PT_20UA_100UA_160UA; + break; + case ADMW1001_ADC_EXC_CURRENT_IOUT_DIODE_50UA_150UA_300UA: + channelExcitationReg.IOUT_Diode_Ratio = CORE_CHANNEL_EXCITATION_DIODE_3PT_50UA_150UA_300UA; + break; + case ADMW1001_ADC_EXC_CURRENT_IOUT_DIODE_100UA_300UA_600UA: + channelExcitationReg.IOUT_Diode_Ratio = CORE_CHANNEL_EXCITATION_DIODE_3PT_100UA_300UA_600UA; + break; + default: + ADMW_LOG_ERROR("Invalid diode ratio %d specified", + pCurrentConfig->diodeRatio); + return ADMW_INVALID_PARAM; } - else - { - channelExcitationReg.IOUT_Diode_Ratio = 1; - } - - WRITE_REG_U8(hDevice, channelExcitationReg.VALUE8, CORE_CHANNEL_EXCITATIONn(eChannelId)); + + WRITE_REG_U16(hDevice, channelExcitationReg.VALUE16, CORE_CHANNEL_EXCITATIONn(eChannelId)); return ADMW_SUCCESS; } @@ -2169,7 +1893,6 @@ sensorDetailsReg.Unity_LUT_Select = 0; sensorDetailsReg.Vbias = 0; - sensorDetailsReg.Reference_Buffer_Disable = 1; WRITE_REG_U32(hDevice, sensorDetailsReg.VALUE32, CORE_SENSOR_DETAILSn(eChannelId)); @@ -2512,73 +2235,6 @@ pDigitalComms->spiClock); return ADMW_INVALID_PARAM; } - - switch (pDigitalComms->uartLineConfig) - { - case ADMW1001_DIGITAL_SENSOR_COMMS_UART_LINE_CONFIG_8N1: - digitalSensorComms.Uart_Mode = CORE_DIGITAL_SENSOR_COMMS_LINECONTROL_8N1; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_UART_LINE_CONFIG_8N2: - digitalSensorComms.Uart_Mode = CORE_DIGITAL_SENSOR_COMMS_LINECONTROL_8N2; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_UART_LINE_CONFIG_8N3: - digitalSensorComms.Uart_Mode = CORE_DIGITAL_SENSOR_COMMS_LINECONTROL_8N3; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_UART_LINE_CONFIG_8E1: - digitalSensorComms.Uart_Mode = CORE_DIGITAL_SENSOR_COMMS_LINECONTROL_8E1; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_UART_LINE_CONFIG_8E2: - digitalSensorComms.Uart_Mode = CORE_DIGITAL_SENSOR_COMMS_LINECONTROL_8E2; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_UART_LINE_CONFIG_8E3: - digitalSensorComms.Uart_Mode = CORE_DIGITAL_SENSOR_COMMS_LINECONTROL_8E3; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_UART_LINE_CONFIG_8O1: - digitalSensorComms.Uart_Mode = CORE_DIGITAL_SENSOR_COMMS_LINECONTROL_8O1; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_UART_LINE_CONFIG_8O2: - digitalSensorComms.Uart_Mode = CORE_DIGITAL_SENSOR_COMMS_LINECONTROL_8O2; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_UART_LINE_CONFIG_8O3: - digitalSensorComms.Uart_Mode = CORE_DIGITAL_SENSOR_COMMS_LINECONTROL_8O3; - break; - default: - ADMW_LOG_ERROR("Invalid UART mode %d specified", - pDigitalComms->uartLineConfig); - return ADMW_INVALID_PARAM; - } - - switch (pDigitalComms->uartBaudRate) - { - case ADMW1001_DIGITAL_SENSOR_COMMS_UART_BAUD_RATE_115200: - digitalSensorComms.Uart_Baud = CORE_DIGITAL_SENSOR_COMMS_UART_115200; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_UART_BAUD_RATE_57600: - digitalSensorComms.Uart_Baud = CORE_DIGITAL_SENSOR_COMMS_UART_57600; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_UART_BAUD_RATE_38400: - digitalSensorComms.Uart_Baud = CORE_DIGITAL_SENSOR_COMMS_UART_38400; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_UART_BAUD_RATE_19200: - digitalSensorComms.Uart_Baud = CORE_DIGITAL_SENSOR_COMMS_UART_19200; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_UART_BAUD_RATE_9600: - digitalSensorComms.Uart_Baud = CORE_DIGITAL_SENSOR_COMMS_UART_9600; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_UART_BAUD_RATE_4800: - digitalSensorComms.Uart_Baud = CORE_DIGITAL_SENSOR_COMMS_UART_4800; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_UART_BAUD_RATE_2400: - digitalSensorComms.Uart_Baud = CORE_DIGITAL_SENSOR_COMMS_UART_2400; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_UART_BAUD_RATE_1200: - digitalSensorComms.Uart_Baud = CORE_DIGITAL_SENSOR_COMMS_UART_1200; - break; - default: - ADMW_LOG_ERROR("Invalid UART baud rate %d specified", - pDigitalComms->uartBaudRate); - return ADMW_INVALID_PARAM; - } } else { @@ -2769,87 +2425,6 @@ return ADMW_SUCCESS; } -static ADMW_RESULT admw_SetChannelUartSensorType( - ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, - ADMW1001_UART_SENSOR_TYPE sensorType) -{ - CORE_Sensor_Type_t sensorTypeReg; - - sensorTypeReg.VALUE16 = REG_RESET_VAL(CORE_SENSOR_TYPEn); - - /* Ensure that the sensor type is valid for this channel */ - switch(sensorType) - { - case ADMW1001_UART_SENSOR_UART_CO2_A_DEF_L1: - case ADMW1001_UART_SENSOR_UART_CO2_B_DEF_L1: - case ADMW1001_UART_SENSOR_UART_CO2_A_DEF_L2: - case ADMW1001_UART_SENSOR_UART_CO2_B_DEF_L2: - case ADMW1001_UART_SENSOR_UART_CO2_A_ADV_L1: - case ADMW1001_UART_SENSOR_UART_CO2_B_ADV_L1: - case ADMW1001_UART_SENSOR_UART_CO2_A_ADV_L2: - case ADMW1001_UART_SENSOR_UART_CO2_B_ADV_L2: - sensorTypeReg.Sensor_Type = sensorType; - break; - default: - ADMW_LOG_ERROR("Unsupported UART sensor type %d specified", sensorType); - return ADMW_INVALID_PARAM; - } - - WRITE_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(eChannelId)); - - return ADMW_SUCCESS; -} - -ADMW_RESULT admw_SetUartChannelConfig( - ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, - ADMW1001_CHANNEL_CONFIG *pChannelConfig) -{ - ADMW_RESULT eRet; - ADMW1001_UART_CHANNEL_CONFIG *pUartChannelConfig = - &pChannelConfig->uartChannelConfig; - - eRet = admw_SetChannelUartSensorType(hDevice, eChannelId, - pUartChannelConfig->sensor); - if (eRet != ADMW_SUCCESS) - { - ADMW_LOG_ERROR("Failed to set UART sensor type for channel %d", - eChannelId); - return eRet; - } - - eRet = admw_SetChannelDigitalSensorDetails(hDevice, eChannelId, - pChannelConfig); - if (eRet != ADMW_SUCCESS) - { - ADMW_LOG_ERROR("Failed to set UART sensor details for channel %d", - eChannelId); - return eRet; - } - - eRet = admw_SetDigitalCalibrationParam(hDevice, eChannelId, - &pUartChannelConfig->digitalCalibrationParam); - if (eRet != ADMW_SUCCESS) - { - ADMW_LOG_ERROR("Failed to set UART digital calibration param for channel %d", - eChannelId); - return eRet; - } - - eRet = admw_SetDigitalChannelComms(hDevice, eChannelId, - &pUartChannelConfig->configureComms); - if (eRet != ADMW_SUCCESS) - { - ADMW_LOG_ERROR("Failed to set UART comms for channel %d", - eChannelId); - return eRet; - } - - - return ADMW_SUCCESS; -} - ADMW_RESULT admw1001_SetChannelThresholdLimits( ADMW_DEVICE_HANDLE hDevice, ADMW1001_CHANNEL_ID eChannelId, @@ -2962,8 +2537,7 @@ } eRet = admw1001_SetChannelOptions(hDevice, eChannelId, - pChannelConfig->priority, - pChannelConfig->enableFFT); + pChannelConfig->priority); if (eRet != ADMW_SUCCESS) { ADMW_LOG_ERROR("Failed to set priority for channel %d", @@ -2972,7 +2546,7 @@ } /* If the channel is not enabled, we can skip the following steps */ - if (pChannelConfig->enableChannel || pChannelConfig->enableFFT) + if (pChannelConfig->enableChannel) { eRet = admw1001_SetChannelSkipCount(hDevice, eChannelId, pChannelConfig->cycleSkipCount); @@ -2985,14 +2559,10 @@ switch (eChannelId) { - case ADMW1001_CHANNEL_ID_CJC_0: - case ADMW1001_CHANNEL_ID_CJC_1: - case ADMW1001_CHANNEL_ID_SENSOR_0: - case ADMW1001_CHANNEL_ID_SENSOR_1: - case ADMW1001_CHANNEL_ID_SENSOR_2: - case ADMW1001_CHANNEL_ID_SENSOR_3: - case ADMW1001_CHANNEL_ID_VOLTAGE_0: - case ADMW1001_CHANNEL_ID_CURRENT_0: + case ADMW1001_CHANNEL_ID_ANALOG_1_UNIVERSAL: + case ADMW1001_CHANNEL_ID_ANALOG_2_UNIVERSAL: + case ADMW1001_CHANNEL_ID_ANALOG_1_DIFFERENTIAL: + case ADMW1001_CHANNEL_ID_ANALOG_2_DIFFERENTIAL: eRet = admw_SetAdcChannelConfig(hDevice, eChannelId, pChannelConfig); break; case ADMW1001_CHANNEL_ID_I2C_0: @@ -3002,9 +2572,6 @@ case ADMW1001_CHANNEL_ID_SPI_0: eRet = admw_SetSpiChannelConfig(hDevice, eChannelId, pChannelConfig); break; - case ADMW1001_CHANNEL_ID_UART: - eRet = admw_SetUartChannelConfig(hDevice, eChannelId, pChannelConfig); - break; default: ADMW_LOG_ERROR("Invalid channel ID %d specified", eChannelId); return ADMW_INVALID_PARAM; @@ -3021,7 +2588,7 @@ } } - if (pChannelConfig->enableChannel || pChannelConfig->enableFFT) + if (pChannelConfig->enableChannel) { /* Threshold limits can be configured individually for virtual channels */ eRet = admw1001_SetChannelThresholdLimits(hDevice, eChannelId, @@ -3073,7 +2640,15 @@ pConfig->productId, ADMW_PRODUCT_ID_ADMW1001); return ADMW_INVALID_PARAM; } - + + if(!((pConfig->versionId.major==VERSIONID_MAJOR) && (pConfig->versionId.minor==VERSIONID_MINOR))) + { + ADMW_LOG_ERROR("Configuration Version ID (0x%X) is not supported", + pConfig->versionId); + return ADMW_INVALID_PARAM; + } + + /* Check that the actual Product ID is a match? */ eRet = admw_GetProductID(hDevice, &productId); if (eRet) @@ -3111,7 +2686,7 @@ return eRet; } - for (ADMW1001_CHANNEL_ID id = ADMW1001_CHANNEL_ID_CJC_0; + for (ADMW1001_CHANNEL_ID id = ADMW1001_CHANNEL_ID_ANALOG_1_UNIVERSAL; id < ADMW1001_MAX_CHANNELS; id++) { @@ -3124,17 +2699,10 @@ } } - eRet = admw1001_SetFftConfig(hDevice, &pDeviceConfig->fft, - pDeviceConfig->channels); - if (eRet) - { - ADMW_LOG_ERROR("Failed to set FFT configuration"); - return eRet; - } - return ADMW_SUCCESS; } + ADMW_RESULT admw1001_SetLutData( ADMW_DEVICE_HANDLE const hDevice, ADMW1001_LUT * const pLutData) @@ -3339,4 +2907,3 @@ return ADMW_SUCCESS; } -