Vybhav Kadaba
/
EV-PRO-MW1001_dec12
MWARE-1930 fixed
Diff: src/admw_1001.c
- Revision:
- 41:df78b7d7b675
- Parent:
- 36:54e2418e7620
- Child:
- 42:c9c5a22e539e
--- a/src/admw_1001.c Thu Nov 21 13:37:24 2019 +0000 +++ b/src/admw_1001.c Tue Dec 10 08:43:37 2019 +0000 @@ -903,11 +903,14 @@ ADMW_CORE_Mode_t modeReg; READ_REG_U8(hDevice, modeReg.VALUE8, CORE_MODE); - if (eMeasurementMode == (modeReg.Conversion_Mode == CORE_MODE_SINGLECYCLE)) - *peOperatingMode = ADMW1001_OPERATING_MODE_SINGLECYCLE; - else - *peOperatingMode = ADMW1001_OPERATING_MODE_CONTINUOUS; + if(eMeasurementMode==ADMW_MEASUREMENT_MODE_NORMAL) { + if (modeReg.Conversion_Mode == CORE_MODE_SINGLECYCLE) + *peOperatingMode = ADMW1001_OPERATING_MODE_SINGLECYCLE; + else + *peOperatingMode = ADMW1001_OPERATING_MODE_CONTINUOUS; + } + if (eMeasurementMode == ADMW_MEASUREMENT_MODE_OMIT_RAW) { *pnBytesPerSample = 5; } else { @@ -926,12 +929,10 @@ 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) - { + if (channelCountReg.Channel_Enable && !sensorDetailsReg.Do_Not_Publish) { unsigned nActualChannels = 1; - if (chId == ADMW1001_CH_ID_DIG_SPI_0) - { + if (chId == ADMW1001_CH_ID_DIG_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 @@ -943,12 +944,11 @@ ADMW_CORE_Sensor_Type_t sensorTypeReg; READ_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(chId)); - + if ((sensorTypeReg.Sensor_Type >= - CORE_SENSOR_TYPE_SPI_ACCELEROMETER_A) && - (sensorTypeReg.Sensor_Type <= - CORE_SENSOR_TYPE_SPI_ACCELEROMETER_B)) - { + CORE_SENSOR_TYPE_SPI_ACCELEROMETER_A) && + (sensorTypeReg.Sensor_Type <= + CORE_SENSOR_TYPE_SPI_ACCELEROMETER_B)) { nActualChannels += 2; } #endif @@ -1038,13 +1038,13 @@ ADMW_DEVICE_HANDLE hDevice, float32_t RSenseValue) { - ADMW_CORE_External_Reference_Resistor_t RefResistorConfigReg; - - RefResistorConfigReg.Ext_Refin1_Value = RSenseValue; - - WRITE_REG_FLOAT(hDevice, RefResistorConfigReg.VALUE32, CORE_EXTERNAL_REFERENCE_RESISTOR); - - return ADMW_SUCCESS; + ADMW_CORE_External_Reference_Resistor_t RefResistorConfigReg; + + RefResistorConfigReg.Ext_Refin1_Value = RSenseValue; + + WRITE_REG_FLOAT(hDevice, RefResistorConfigReg.VALUE32, CORE_EXTERNAL_REFERENCE_RESISTOR); + + return ADMW_SUCCESS; } static ADMW_RESULT admw_SetMode( @@ -1156,19 +1156,17 @@ } eRet = admw_SetRSenseValue(hDevice, pMeasConfig->RSenseValue); - if (eRet != ADMW_SUCCESS) - { + if (eRet != ADMW_SUCCESS) { ADMW_LOG_ERROR("Failed to set RSenseValue"); return eRet; } - + eRet = admw_SetExternalReferenceVoltage(hDevice, pMeasConfig->externalRefVoltage); - if (eRet != ADMW_SUCCESS) - { + if (eRet != ADMW_SUCCESS) { ADMW_LOG_ERROR("Failed to set External reference Voltage"); return eRet; - } - + } + return ADMW_SUCCESS; } @@ -1185,24 +1183,23 @@ else diagnosticsControlReg.Diag_Meas_En = 1; - switch (pDiagnosticsConfig->osdFrequency) - { - case ADMW1001_OPEN_SENSOR_DIAGNOSTICS_DISABLED: - diagnosticsControlReg.Diag_OSD_Freq = CORE_DIAGNOSTICS_CONTROL_OCD_OFF; - break; - case ADMW1001_OPEN_SENSOR_DIAGNOSTICS_PER_CYCLE: - diagnosticsControlReg.Diag_OSD_Freq = CORE_DIAGNOSTICS_CONTROL_OCD_PER_1_CYCLE; - break; - case ADMW1001_OPEN_SENSOR_DIAGNOSTICS_PER_100_CYCLES: - diagnosticsControlReg.Diag_OSD_Freq = CORE_DIAGNOSTICS_CONTROL_OCD_PER_10_CYCLES; - break; - case ADMW1001_OPEN_SENSOR_DIAGNOSTICS_PER_1000_CYCLES: - diagnosticsControlReg.Diag_OSD_Freq = CORE_DIAGNOSTICS_CONTROL_OCD_PER_100_CYCLES; - break; - default: - ADMW_LOG_ERROR("Invalid open-sensor diagnostic frequency %d specified", - pDiagnosticsConfig->osdFrequency); - return ADMW_INVALID_PARAM; + switch (pDiagnosticsConfig->osdFrequency) { + case ADMW1001_OPEN_SENSOR_DIAGNOSTICS_DISABLED: + diagnosticsControlReg.Diag_OSD_Freq = CORE_DIAGNOSTICS_CONTROL_OCD_OFF; + break; + case ADMW1001_OPEN_SENSOR_DIAGNOSTICS_PER_CYCLE: + diagnosticsControlReg.Diag_OSD_Freq = CORE_DIAGNOSTICS_CONTROL_OCD_PER_1_CYCLE; + break; + case ADMW1001_OPEN_SENSOR_DIAGNOSTICS_PER_100_CYCLES: + diagnosticsControlReg.Diag_OSD_Freq = CORE_DIAGNOSTICS_CONTROL_OCD_PER_10_CYCLES; + break; + case ADMW1001_OPEN_SENSOR_DIAGNOSTICS_PER_1000_CYCLES: + diagnosticsControlReg.Diag_OSD_Freq = CORE_DIAGNOSTICS_CONTROL_OCD_PER_100_CYCLES; + break; + default: + ADMW_LOG_ERROR("Invalid open-sensor diagnostic frequency %d specified", + pDiagnosticsConfig->osdFrequency); + return ADMW_INVALID_PARAM; } WRITE_REG_U8(hDevice, diagnosticsControlReg.VALUE8, CORE_DIAGNOSTICS_CONTROL); @@ -1323,8 +1320,7 @@ case ADMW1001_ADC_SENSOR_SINGLE_ENDED_RATIO: case ADMW1001_ADC_SENSOR_DIFFERENTIAL_RATIO: if (! (ADMW1001_CHANNEL_IS_ADC_SENSOR(eChannelId) || - ADMW1001_CHANNEL_IS_ADC_CJC(eChannelId) || ADMW1001_CHANNEL_IS_ADC(eChannelId) )) - { + ADMW1001_CHANNEL_IS_ADC_CJC(eChannelId) || ADMW1001_CHANNEL_IS_ADC(eChannelId) )) { ADMW_LOG_ERROR( "Invalid ADC sensor type %d specified for channel %d", sensorType, eChannelId); @@ -1518,7 +1514,7 @@ MeasSetupReg.VALUE32 = REG_RESET_VAL(CORE_MEASUREMENT_SETUPn); MeasSetupReg.PST_MEAS_EXC_CTRL = pAdcChannelConfig->current.excitationState; MeasSetupReg.Buffer_Bypass = pAdcChannelConfig->bufferBypass; - + if (pFilterConfig->type == ADMW1001_ADC_FILTER_SINC4) { MeasSetupReg.ADC_Filter_Type = CORE_MEASUREMENT_SETUP_ENABLE_SINC4; MeasSetupReg.ADC_SF = pFilterConfig->sf; @@ -1617,7 +1613,7 @@ } eRet = admw_SetChannelAdcMeasurementSetup(hDevice, eChannelId, - pAdcChannelConfig); + pAdcChannelConfig); if (eRet != ADMW_SUCCESS) { ADMW_LOG_ERROR("Failed to set ADC filter for channel %d", eChannelId); @@ -2266,8 +2262,7 @@ } eRet = admw1001_SetDiagnosticsConfig(hDevice, &pDeviceConfig->diagnostics); - if (eRet) - { + if (eRet) { ADMW_LOG_ERROR("Failed to set diagnostics configuration"); return eRet; }