Vybhav Kadaba
/
EV-PRO-MW1001_Development_code_cleaup
Removed unwanted enums and unused functions
Diff: src/admw_1001.c
- Revision:
- 63:6d048b2f3f32
- Parent:
- 61:0f16a2e3b58b
--- a/src/admw_1001.c Wed Apr 08 10:05:08 2020 +0000 +++ b/src/admw_1001.c Thu Apr 09 12:01:25 2020 +0000 @@ -53,7 +53,6 @@ #include "admw1001/admw1001_lut_data.h" #include "admw1001/admw1001_host_comms.h" #include "inc/mbedVersion.h" -#include "crc16.h" #define VERSIONID_MAJOR 2 #define VERSIONID_MINOR 0 @@ -184,8 +183,6 @@ #define ADMW1001_CHANNEL_IS_ADC_CURRENT(c) \ ((c) == ADMW1001_CH_ID_ANLG_1_UNIVERSAL || (c) == ADMW1001_CH_ID_ANLG_2_UNIVERSAL) -#define ADMW1001_CHANNEL_IS_VIRTUAL(c) \ - ((c) == ADMW1001_CH_ID_DIG_SPI_1 || (c) == ADMW1001_CH_ID_DIG_SPI_2) //typedef struct { // unsigned nDeviceIndex; @@ -552,64 +549,6 @@ return executeCommand(hDevice, CORE_COMMAND_NOP, true); } -/* - * - */ -ADMW_RESULT admw1001_sendRun( ADMW_DEVICE_HANDLE const hDevice) -{ - bool bitCommand; - ADMW_RESULT eRet; - uint8_t pinreg = 0x1; - - ADMW_DEVICE_CONTEXT *pCtx = hDevice; - static uint8_t DataBuffer[SPI_BUFFER_SIZE] = {0}; - uint16_t nSize; - - //Construct Read Status command - DataBuffer[0] = 0x07; - DataBuffer[1] = 0x0E; //Packet ID - - DataBuffer[2] = 0x00; - DataBuffer[3] = 0x00; //Data words - - DataBuffer[4] = 0x45; - DataBuffer[5] = 0x00; //Command ID - - DataBuffer[6] = 0x00; - DataBuffer[7] = 0x50; - DataBuffer[8] = 0x00; - DataBuffer[9] = 0x00; //Address - - DataBuffer[10] = 0x95; - DataBuffer[11] = 0x00; - DataBuffer[12] = 0x00; - DataBuffer[13] = 0x00; //Checksum - - nSize = SFL_READ_STATUS_HDR_SIZE; - - do { - // Get the SFL command irq pin to check if SFL is ready to receive commands - // Status pin is not checked since SFL is just booted, there should not be any issue with SFL - eRet = admw_GetGpioState( hDevice, ADMW_GPIO_PIN_DATAREADY, &bitCommand ); - if( eRet != ADMW_SUCCESS) { - return eRet; - } - - // Command IRQ pin should be low and Status IRQ pin should be high for SFL to be in good state and ready to recieve commands - // pinreg == '0x00' - Error occured in SFL - // pinreg == '0x01' - SFL is ready to recieve commands - // pinreg == '0x02' - Error occured in handling any commands in SFL - // pinreg == '0x03' - SFL not booted - - pinreg = (bitCommand); - - } while(pinreg != 0x0u); - - eRet = admw_SpiTransfer(pCtx->hSpi, DataBuffer, NULL, - nSize, false); - - return eRet; -} /* * Read a set of data samples from the device. @@ -754,46 +693,6 @@ 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; - } - wait_ms(100); - //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, @@ -835,46 +734,6 @@ 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) @@ -920,37 +779,12 @@ ADMW_CORE_Sensor_Details_t sensorDetailsReg; ADMW_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) { unsigned nActualChannels = 1; - 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 - * from the corresponding "physical" channel - */ -#if 0 /* SPI sensors arent supported at present to be added back once there is - * support for these sensors - */ - 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)) { - nActualChannels += 2; - } -#endif - } - nChannelsEnabled += nActualChannels; nSamplesPerCycle += nActualChannels * @@ -1515,9 +1349,6 @@ case ADMW1001_ADC_GAIN_64X: sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_64; break; - case ADMW1001_ADC_GAIN_128X: - sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_128; - break; default: ADMW_LOG_ERROR("Invalid ADC gain %d specified", pAdcChannelConfig->gain); @@ -1769,30 +1600,6 @@ return ADMW_SUCCESS; } -static ADMW_RESULT admw_SetDigitalCalibrationParam( - ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CH_ID eChannelId, - ADMW1001_DIGITAL_CALIBRATION_COMMAND *pCalibrationParam) -{ -// ADMW_CORE_Calibration_Parameter_t calibrationParamReg; -// -// calibrationParamReg.VALUE32 = REG_RESET_VAL(CORE_CALIBRATION_PARAMETERn); -// -// if (pCalibrationParam->enableCalibrationParam == false) -// calibrationParamReg.Calibration_Parameter_Enable = 0; -// else -// calibrationParamReg.Calibration_Parameter_Enable = 1; -// -// CHECK_REG_FIELD_VAL(CORE_CALIBRATION_PARAMETER_CALIBRATION_PARAMETER, -// pCalibrationParam->calibrationParam); -// -// calibrationParamReg.Calibration_Parameter = pCalibrationParam->calibrationParam; -// -// WRITE_REG_U32(hDevice, calibrationParamReg.VALUE32, -// CORE_CALIBRATION_PARAMETERn(eChannelId)); -// - return ADMW_SUCCESS; -} static ADMW_RESULT admw_SetChannelI2cSensorType( ADMW_DEVICE_HANDLE hDevice, @@ -1850,78 +1657,8 @@ pDigitalComms->i2cClockSpeed); return ADMW_INVALID_PARAM; } - - if(pDigitalComms->spiMode == ADMW1001_DIGITAL_SENSOR_COMMS_SPI_MODE_0) { - digitalSensorComms.SPI_Mode = CORE_DIGITAL_SENSOR_COMMS_SPI_MODE_0; - } else if(pDigitalComms->spiMode == ADMW1001_DIGITAL_SENSOR_COMMS_SPI_MODE_1) { - digitalSensorComms.SPI_Mode = CORE_DIGITAL_SENSOR_COMMS_SPI_MODE_1; - } else if(pDigitalComms->spiMode == ADMW1001_DIGITAL_SENSOR_COMMS_SPI_MODE_2) { - digitalSensorComms.SPI_Mode = CORE_DIGITAL_SENSOR_COMMS_SPI_MODE_2; - } else if(pDigitalComms->spiMode == ADMW1001_DIGITAL_SENSOR_COMMS_SPI_MODE_3) { - digitalSensorComms.SPI_Mode = CORE_DIGITAL_SENSOR_COMMS_SPI_MODE_3; - } else { - ADMW_LOG_ERROR("Invalid SPI mode %d specified", - pDigitalComms->spiMode); - return ADMW_INVALID_PARAM; - } - - switch (pDigitalComms->spiClock) { - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_8MHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_8MHZ; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_4MHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_4MHZ; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_2MHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_2MHZ; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_1MHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_1MHZ; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_500KHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_500KHZ; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_250KHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_250KHZ; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_125KHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_125KHZ; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_62P5KHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_62P5KHZ; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_31P3KHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_31P3KHZ; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_15P6KHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_15P6KHZ; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_7P8KHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_7P8KHZ; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_3P9KHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_3P9KHZ; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_1P9KHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_1P9KHZ; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_977HZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_977HZ; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_488HZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_488HZ; - break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_244HZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_244HZ; - break; - default: - ADMW_LOG_ERROR("Invalid SPI clock %d specified", - pDigitalComms->spiClock); - return ADMW_INVALID_PARAM; - } } - WRITE_REG_U16(hDevice, digitalSensorComms.VALUE16, CORE_DIGITAL_SENSOR_COMMSn(eChannelId)); return ADMW_SUCCESS; @@ -1968,14 +1705,6 @@ return eRet; } - eRet = admw_SetDigitalCalibrationParam(hDevice, eChannelId, - &pI2cChannelConfig->digitalCalibrationParam); - if (eRet != ADMW_SUCCESS) { - ADMW_LOG_ERROR("Failed to set I2C digital calibration param for channel %d", - eChannelId); - return eRet; - } - eRet = admw_SetDigitalChannelComms(hDevice, eChannelId, &pI2cChannelConfig->configureComms); if (eRet != ADMW_SUCCESS) { @@ -1987,83 +1716,6 @@ return ADMW_SUCCESS; } -static ADMW_RESULT admw_SetChannelSpiSensorType( - ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CH_ID eChannelId, - ADMW1001_SPI_SENSOR_TYPE sensorType) -{ - ADMW_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_SPI_SENSOR: - - sensorTypeReg.Sensor_Type = sensorType; - break; - default: - ADMW_LOG_ERROR("Unsupported SPI 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_SetSpiChannelConfig( - ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CH_ID eChannelId, - ADMW1001_CHANNEL_CONFIG *pChannelConfig) -{ - ADMW_RESULT eRet; - ADMW1001_SPI_CHANNEL_CONFIG *pSpiChannelConfig = - &pChannelConfig->spiChannelConfig; - - eRet = admw_SetChannelSpiSensorType(hDevice, eChannelId, - pSpiChannelConfig->sensor); - if (eRet != ADMW_SUCCESS) { - ADMW_LOG_ERROR("Failed to set SPI sensor type for channel %d", - eChannelId); - return eRet; - } - - eRet = admw_SetChannelDigitalSensorDetails(hDevice, eChannelId, - pChannelConfig); - if (eRet != ADMW_SUCCESS) { - ADMW_LOG_ERROR("Failed to set SPI sensor details for channel %d", - eChannelId); - return eRet; - } - - eRet = admw_SetDigitalSensorFormat(hDevice, eChannelId, - &pSpiChannelConfig->dataFormat); - if (eRet != ADMW_SUCCESS) { - ADMW_LOG_ERROR("Failed to set SPI sensor data format for channel %d", - eChannelId); - return eRet; - } - - eRet = admw_SetDigitalCalibrationParam(hDevice, eChannelId, - &pSpiChannelConfig->digitalCalibrationParam); - if (eRet != ADMW_SUCCESS) { - ADMW_LOG_ERROR("Failed to set SPI digital calibration param for channel %d", - eChannelId); - return eRet; - } - - eRet = admw_SetDigitalChannelComms(hDevice, eChannelId, - &pSpiChannelConfig->configureComms); - if (eRet != ADMW_SUCCESS) { - ADMW_LOG_ERROR("Failed to set SPI comms for channel %d", - eChannelId); - return eRet; - } - - return ADMW_SUCCESS; -} - ADMW_RESULT admw1001_SetChannelThresholdLimits( ADMW_DEVICE_HANDLE hDevice, ADMW1001_CH_ID eChannelId, @@ -2145,70 +1797,65 @@ { ADMW_RESULT eRet; - if (! ADMW1001_CHANNEL_IS_VIRTUAL(eChannelId)) { - eRet = admw1001_SetChannelCount(hDevice, eChannelId, - pChannelConfig->enableChannel ? - pChannelConfig->measurementsPerCycle : 0); + eRet = admw1001_SetChannelCount(hDevice, eChannelId, + pChannelConfig->enableChannel ? + pChannelConfig->measurementsPerCycle : 0); + if (eRet != ADMW_SUCCESS) { + ADMW_LOG_ERROR("Failed to set measurement count for channel %d", + eChannelId); + return eRet; + } + + eRet = admw1001_SetChannelOptions(hDevice, eChannelId, + pChannelConfig->priority); + if (eRet != ADMW_SUCCESS) { + ADMW_LOG_ERROR("Failed to set priority for channel %d", + eChannelId); + return eRet; + } + + /* If the channel is not enabled, we can skip the following steps */ + if (pChannelConfig->enableChannel) { + eRet = admw1001_SetChannelSkipCount(hDevice, eChannelId, + pChannelConfig->cycleSkipCount); if (eRet != ADMW_SUCCESS) { - ADMW_LOG_ERROR("Failed to set measurement count for channel %d", - eChannelId); - return eRet; - } - - eRet = admw1001_SetChannelOptions(hDevice, eChannelId, - pChannelConfig->priority); - if (eRet != ADMW_SUCCESS) { - ADMW_LOG_ERROR("Failed to set priority for channel %d", + ADMW_LOG_ERROR("Failed to set cycle skip count for channel %d", eChannelId); return eRet; } - /* If the channel is not enabled, we can skip the following steps */ - if (pChannelConfig->enableChannel) { - eRet = admw1001_SetChannelSkipCount(hDevice, eChannelId, - pChannelConfig->cycleSkipCount); - if (eRet != ADMW_SUCCESS) { - ADMW_LOG_ERROR("Failed to set cycle skip count for channel %d", - eChannelId); - return eRet; - } + switch (eChannelId) { + case ADMW1001_CH_ID_ANLG_1_UNIVERSAL: + case ADMW1001_CH_ID_ANLG_2_UNIVERSAL: + case ADMW1001_CH_ID_ANLG_1_DIFFERENTIAL: + case ADMW1001_CH_ID_ANLG_2_DIFFERENTIAL: + eRet = admw_SetAdcChannelConfig(hDevice, eChannelId, pChannelConfig); + break; + case ADMW1001_CH_ID_DIG_I2C_0: + case ADMW1001_CH_ID_DIG_I2C_1: + eRet = admw_SetI2cChannelConfig(hDevice, eChannelId, pChannelConfig); + break; + default: + ADMW_LOG_ERROR("Invalid channel ID %d specified", eChannelId); + eRet = ADMW_INVALID_PARAM; +#if 0 + /* when using i2c sensors there is an error ( dataformat->length=0) + the code below catches this error and this causes further problems.*/ + break; + } + if (eRet != ADMW_SUCCESS) { + ADMW_LOG_ERROR("Failed to set config for channel %d", + eChannelId); + return eRet; +#endif + } - switch (eChannelId) { - case ADMW1001_CH_ID_ANLG_1_UNIVERSAL: - case ADMW1001_CH_ID_ANLG_2_UNIVERSAL: - case ADMW1001_CH_ID_ANLG_1_DIFFERENTIAL: - case ADMW1001_CH_ID_ANLG_2_DIFFERENTIAL: - eRet = admw_SetAdcChannelConfig(hDevice, eChannelId, pChannelConfig); - break; - case ADMW1001_CH_ID_DIG_I2C_0: - case ADMW1001_CH_ID_DIG_I2C_1: - eRet = admw_SetI2cChannelConfig(hDevice, eChannelId, pChannelConfig); - break; - case ADMW1001_CH_ID_DIG_SPI_0: - eRet = admw_SetSpiChannelConfig(hDevice, eChannelId, pChannelConfig); - break; - default: - ADMW_LOG_ERROR("Invalid channel ID %d specified", eChannelId); - eRet = ADMW_INVALID_PARAM; -#if 0 - /* when using i2c sensors there is an error ( dataformat->length=0) - the code below catches this error and this causes further problems.*/ - break; - } - if (eRet != ADMW_SUCCESS) { - ADMW_LOG_ERROR("Failed to set config for channel %d", - eChannelId); - return eRet; -#endif - } - - eRet = admw1001_SetChannelSettlingTime(hDevice, eChannelId, - pChannelConfig->extraSettlingTime); - if (eRet != ADMW_SUCCESS) { - ADMW_LOG_ERROR("Failed to set settling time for channel %d", - eChannelId); - return eRet; - } + eRet = admw1001_SetChannelSettlingTime(hDevice, eChannelId, + pChannelConfig->extraSettlingTime); + if (eRet != ADMW_SUCCESS) { + ADMW_LOG_ERROR("Failed to set settling time for channel %d", + eChannelId); + return eRet; } } @@ -2245,7 +1892,6 @@ return ADMW_SUCCESS; } - ADMW_RESULT admw_SetConfig( ADMW_DEVICE_HANDLE const hDevice, ADMW_CONFIG * const pConfig) @@ -2329,10 +1975,6 @@ unsigned *pLength) { switch (pDesc->geometry) { - case ADMW1001_LUT_GEOMETRY_COEFFS: - if (pDesc->equation == ADMW1001_LUT_EQUATION_BIVARIATE_POLYN) - *pLength = ADMW1001_LUT_COEFF_LIST_SIZE(pData->coeffList); - break; case ADMW1001_LUT_GEOMETRY_NES_1D: *pLength = ADMW1001_LUT_1D_NES_SIZE(pData->lut1dNes); break; @@ -2355,8 +1997,7 @@ ADMW1001_LUT_HEADER *pHdr = &pLutBuffer->header; uint8_t *pLutTableData = (uint8_t *)pLutBuffer + sizeof(*pHdr); - if (sizeof(*pHdr) > nLutBufferSize) - { + if (sizeof(*pHdr) > nLutBufferSize) { ADMW_LOG_ERROR("Insufficient LUT buffer size provided"); return ADMW_INVALID_PARAM; } @@ -2372,8 +2013,7 @@ * Walk through the list of table pointers provided, appending the table * descriptor+data from each one to the provided LUT buffer */ - for (unsigned i = 0; i < nNumTables; i++) - { + for (unsigned i = 0; i < nNumTables; i++) { ADMW1001_LUT_DESCRIPTOR * const pDesc = ppDesc[i]; ADMW1001_LUT_TABLE_DATA * const pData = ppData[i]; ADMW_RESULT res; @@ -2387,8 +2027,7 @@ /* Fill in the table descriptor length and CRC fields */ pDesc->length = dataLength; - if ((sizeof(*pHdr) + pHdr->totalLength + sizeof(*pDesc) + dataLength) > nLutBufferSize) - { + if ((sizeof(*pHdr) + pHdr->totalLength + sizeof(*pDesc) + dataLength) > nLutBufferSize) { ADMW_LOG_ERROR("Insufficient LUT buffer size provided"); return ADMW_INVALID_PARAM; } @@ -2414,56 +2053,50 @@ unsigned actualLength = 0; - if (pLutData->header.signature != ADMW_LUT_SIGNATURE) - { + if (pLutData->header.signature != ADMW_LUT_SIGNATURE) { ADMW_LOG_ERROR("LUT signature incorrect (expected 0x%X, actual 0x%X)", - ADMW_LUT_SIGNATURE, pLutHeader->signature); + ADMW_LUT_SIGNATURE, pLutHeader->signature); return ADMW_INVALID_SIGNATURE; } if ((pLutData->tables->descriptor.geometry!= ADMW1001_LUT_GEOMETRY_NES_1D) && - (pLutData->tables->data.lut1dNes.nElements > MAX_LUT_NUM_ENTRIES)) - { + (pLutData->tables->data.lut1dNes.nElements > MAX_LUT_NUM_ENTRIES)) { return ADMW_INVALID_PARAM; } - for (unsigned i = 0; i < pLutHeader->numTables; i++) - { + for (unsigned i = 0; i < pLutHeader->numTables; i++) { ADMW1001_LUT_DESCRIPTOR *pDesc = &pLutTable->descriptor; - switch (pDesc->geometry) - { - case ADMW1001_LUT_GEOMETRY_COEFFS: - switch (pDesc->equation) - { - case ADMW1001_LUT_EQUATION_POLYN: - case ADMW1001_LUT_EQUATION_POLYNEXP: - case ADMW1001_LUT_EQUATION_QUADRATIC: - case ADMW1001_LUT_EQUATION_STEINHART: - case ADMW1001_LUT_EQUATION_LOGARITHMIC: - case ADMW1001_LUT_EQUATION_BIVARIATE_POLYN: + switch (pDesc->geometry) { + case ADMW1001_LUT_GEOMETRY_COEFFS: + switch (pDesc->equation) { + case ADMW1001_LUT_EQUATION_POLYN: + case ADMW1001_LUT_EQUATION_POLYNEXP: + case ADMW1001_LUT_EQUATION_QUADRATIC: + case ADMW1001_LUT_EQUATION_STEINHART: + case ADMW1001_LUT_EQUATION_LOGARITHMIC: + case ADMW1001_LUT_EQUATION_BIVARIATE_POLYN: + break; + default: + ADMW_LOG_ERROR("Invalid equation %u specified for LUT table %u", + pDesc->equation, i); + return ADMW_INVALID_PARAM; + } break; - default: - ADMW_LOG_ERROR("Invalid equation %u specified for LUT table %u", - pDesc->equation, i); - return ADMW_INVALID_PARAM; - } - break; - case ADMW1001_LUT_GEOMETRY_NES_1D: - break; - default: - ADMW_LOG_ERROR("Invalid geometry %u specified for LUT table %u", - pDesc->geometry, i); - return ADMW_INVALID_PARAM; + case ADMW1001_LUT_GEOMETRY_NES_1D: + break; + default: + ADMW_LOG_ERROR("Invalid geometry %u specified for LUT table %u", + pDesc->geometry, i); + return ADMW_INVALID_PARAM; } - switch (pDesc->dataType) - { - case ADMW1001_LUT_DATA_TYPE_FLOAT32: - case ADMW1001_LUT_DATA_TYPE_FLOAT64: - break; - default: - ADMW_LOG_ERROR("Invalid vector format %u specified for LUT table %u", - pDesc->dataType, i); - return ADMW_INVALID_PARAM; + switch (pDesc->dataType) { + case ADMW1001_LUT_DATA_TYPE_FLOAT32: + case ADMW1001_LUT_DATA_TYPE_FLOAT64: + break; + default: + ADMW_LOG_ERROR("Invalid vector format %u specified for LUT table %u", + pDesc->dataType, i); + return ADMW_INVALID_PARAM; } @@ -2473,17 +2106,15 @@ pLutTable = (ADMW1001_LUT_TABLE *)((uint8_t *)pLutTable + sizeof(*pDesc) + pDesc->length); } - if (actualLength != pLutHeader->totalLength) - { + if (actualLength != pLutHeader->totalLength) { ADMW_LOG_ERROR("LUT table length mismatch (expected %u, actual %u)", - pLutHeader->totalLength, actualLength); + pLutHeader->totalLength, actualLength); return ADMW_WRONG_SIZE; } - if (sizeof(*pLutHeader) + pLutHeader->totalLength > ADMW_LUT_MAX_SIZE) - { + if (sizeof(*pLutHeader) + pLutHeader->totalLength > ADMW_LUT_MAX_SIZE) { ADMW_LOG_ERROR("Maximum LUT table length (%u bytes) exceeded", - ADMW_LUT_MAX_SIZE); + ADMW_LUT_MAX_SIZE); return ADMW_WRONG_SIZE; }