Vybhav Kadaba
/
EV-PRO-MW1001_Development_updateFW
Bumped Mbed FW version to 01.20.0080
Diff: src/admw_1001.c
- Revision:
- 32:52445bef314d
- Parent:
- 23:bb685f35b08b
- Child:
- 33:df7a00f1b8e1
--- a/src/admw_1001.c Wed Oct 23 16:18:50 2019 +0000 +++ b/src/admw_1001.c Fri Oct 25 05:08:19 2019 +0000 @@ -58,7 +58,10 @@ #define VERSIONID_MINOR 0 uint32_t getDataCnt = 0; +#define ADMW_VERSION_REG_VAL_SIZE 4u +#define ADMW_FORMATTED_VERSION_SIZE 11u +#define ADMW_SFL_READ_STATUS_SIZE 42u /* * The following macros are used to encapsulate the register access code * to improve readability in the functions further below in this file @@ -184,12 +187,12 @@ #define ADMW1001_CHANNEL_IS_VIRTUAL(c) \ ((c) == ADMW1001_CH_ID_DIG_SPI_1 || (c) == ADMW1001_CH_ID_DIG_SPI_2) -typedef struct { - unsigned nDeviceIndex; - ADMW_SPI_HANDLE hSpi; - ADMW_GPIO_HANDLE hGpio; - -} ADMW_DEVICE_CONTEXT; +//typedef struct { +// unsigned nDeviceIndex; +// ADMW_SPI_HANDLE hSpi; +// ADMW_GPIO_HANDLE hGpio; +// +//} ADMW_DEVICE_CONTEXT; static ADMW_DEVICE_CONTEXT gDeviceCtx[ADMW_PLATFORM_MAX_DEVICES]; @@ -312,9 +315,6 @@ ADMW_CORE_Status_t statusReg; READ_REG_U8(hDevice, statusReg.VALUE8, CORE_STATUS); - ADMW_CORE_Alert_Status_2_t alert2Reg; - READ_REG_U16(hDevice, alert2Reg.VALUE16, CORE_ALERT_STATUS_2); - memset(pStatus, 0, sizeof(*pStatus)); if (!statusReg.Cmd_Running) /* Active-low, so invert it */ @@ -326,56 +326,37 @@ if (statusReg.Alert_Active) { pStatus->deviceStatus |= ADMW_DEVICE_STATUS_ALERT; - ADMW_CORE_Alert_Code_t alertCodeReg; - READ_REG_U16(hDevice, alertCodeReg.VALUE16, CORE_ALERT_CODE); - pStatus->alertCode = alertCodeReg.Alert_Code; - ADMW_CORE_Channel_Alert_Status_t channelAlertStatusReg; READ_REG_U16(hDevice, channelAlertStatusReg.VALUE16, CORE_CHANNEL_ALERT_STATUS); for (unsigned i = 0; i < ADMW1001_MAX_CHANNELS; i++) { if (channelAlertStatusReg.VALUE16 & (1 << i)) { - ADMW_CORE_Alert_Code_Ch_t channelAlertCodeReg; - READ_REG_U16(hDevice, channelAlertCodeReg.VALUE16, CORE_ALERT_CODE_CHn(i)); - pStatus->channelAlertCodes[i] = channelAlertCodeReg.Alert_Code_Ch; - ADMW_CORE_Alert_Detail_Ch_t alertDetailReg; READ_REG_U16(hDevice, alertDetailReg.VALUE16, CORE_ALERT_DETAIL_CHn(i)); - if (alertDetailReg.Time_Out) - pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_TIMEOUT; - if (alertDetailReg.Under_Range) - pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_UNDER_RANGE; - if (alertDetailReg.Over_Range) - pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_OVER_RANGE; - if (alertDetailReg.Low_Limit) - pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_LOW_LIMIT; - if (alertDetailReg.High_Limit) - pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_HIGH_LIMIT; - if (alertDetailReg.Sensor_Open) - pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_SENSOR_OPEN; - if (alertDetailReg.Ref_Detect) - pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_REF_DETECT; - if (alertDetailReg.Config_Err) - pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_CONFIG_ERR; - if (alertDetailReg.LUT_Error_Ch) - pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_LUT_ERR; - if (alertDetailReg.Sensor_Not_Ready) - pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_SENSOR_NOT_READY; - if (alertDetailReg.Comp_Not_Ready) - pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_COMP_NOT_READY; - if (alertDetailReg.Correction_UnderRange) - pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_LUT_UNDER_RANGE; - if (alertDetailReg.Correction_OverRange) - pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_LUT_OVER_RANGE; + if (alertDetailReg.ADC_Near_Overrange) + pStatus->channelAlerts[i] |= ADMW_ALERT_DETAIL_CH_ADC_NEAR_OVERRANGE; + if (alertDetailReg.Sensor_UnderRange) + pStatus->channelAlerts[i] |= ADMW_ALERT_DETAIL_CH_SENSOR_UNDERRANGE; + if (alertDetailReg.Sensor_OverRange) + pStatus->channelAlerts[i] |= ADMW_ALERT_DETAIL_CH_SENSOR_OVERRANGE ; + if (alertDetailReg.CJ_Soft_Fault) + pStatus->channelAlerts[i] |= ADMW_ALERT_DETAIL_CH_CJ_SOFT_FAULT ; + if (alertDetailReg.CJ_Hard_Fault) + pStatus->channelAlerts[i] |= ADMW_ALERT_DETAIL_CH_CJ_HARD_FAULT; + if (alertDetailReg.ADC_Input_OverRange) + pStatus->channelAlerts[i] |= ADMW_ALERT_DETAIL_CH_ADC_INPUT_OVERRANGE ; + if (alertDetailReg.Sensor_HardFault) + pStatus->channelAlerts[i] |= ADMW_ALERT_DETAIL_CH_SENSOR_HARDFAULT; + } } - if (alert2Reg.Configuration_Error) + if (statusReg.Configuration_Error) pStatus->deviceStatus |= ADMW_DEVICE_STATUS_CONFIG_ERROR; - if (alert2Reg.LUT_Error) + if (statusReg.LUT_Error) pStatus->deviceStatus |= ADMW_DEVICE_STATUS_LUT_ERROR; } @@ -386,23 +367,7 @@ READ_REG_U16(hDevice, errorCodeReg.VALUE16, CORE_ERROR_CODE); pStatus->errorCode = errorCodeReg.Error_Code; - ADMW_CORE_Diagnostics_Status_t diagStatusReg; - READ_REG_U16(hDevice, diagStatusReg.VALUE16, CORE_DIAGNOSTICS_STATUS); - - if (diagStatusReg.Diag_Checksum_Error) - pStatus->diagnosticsStatus |= ADMW_DIAGNOSTICS_STATUS_CHECKSUM_ERROR; - if (diagStatusReg.Diag_Conversion_Error) - pStatus->diagnosticsStatus |= ADMW_DIAGNOSTICS_STATUS_CONVERSION_ERROR; - if (diagStatusReg.Diag_Calibration_Error) - pStatus->diagnosticsStatus |= ADMW_DIAGNOSTICS_STATUS_CALIBRATION_ERROR; } - - if (statusReg.Alert_Active || statusReg.Error) { - ADMW_CORE_Debug_Code_t debugCodeReg; - READ_REG_U32(hDevice, debugCodeReg.VALUE32, CORE_DEBUG_CODE); - pStatus->debugCode = debugCodeReg.Debug_Code; - } - return ADMW_SUCCESS; } @@ -423,6 +388,23 @@ return ADMW_SUCCESS; } +ADMW_RESULT deviceInformation(ADMW_DEVICE_HANDLE hDevice) +{ + uint16_t nAddress = REG_CORE_REVISION; + char nData[ADMW_VERSION_REG_VAL_SIZE]; //4 Bytes of version register data + ADMW_RESULT res; + res=admw1001_ReadRegister(hDevice,nAddress,nData,sizeof(nData)); + if(res != ADMW_SUCCESS) { + //if reading version register failed, sending 00.00.0000 as ADMW1001 firmware version + //strcat(nData, ADMW1001_FIRMWARE_VERSION_DEFAULT); + ADMW_LOG_INFO("Firmware Version Id is %X.%X",nData[2],nData[0]); + } else { + char buffer[ADMW_FORMATTED_VERSION_SIZE]; //00.00.0000 8 digits + 2 Bytes "." + one null character at the end + strcat(nData, buffer); + ADMW_LOG_INFO("Firmware Version Id is %X.%X",nData[2],nData[0]); + } + return ADMW_SUCCESS; +} static ADMW_RESULT executeCommand( ADMW_DEVICE_HANDLE const hDevice, ADMW_CORE_Command_Special_Command const command, @@ -463,13 +445,6 @@ return ADMW_SUCCESS; } -ADMW_RESULT admw_Shutdown( - ADMW_DEVICE_HANDLE const hDevice) -{ - return executeCommand(hDevice, CORE_COMMAND_POWER_DOWN, false); -} - - ADMW_RESULT admw_ApplyConfigUpdates( ADMW_DEVICE_HANDLE const hDevice) { @@ -577,9 +552,69 @@ } /* + * + */ +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. * This may be called at any time. */ + ADMW_RESULT admw_GetData( ADMW_DEVICE_HANDLE const hDevice, ADMW_MEASUREMENT_MODE const eMeasurementMode, @@ -903,12 +938,16 @@ * 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 + */ if ((sensorTypeReg.Sensor_Type >= CORE_SENSOR_TYPE_SPI_ACCELEROMETER_A) && (sensorTypeReg.Sensor_Type <= CORE_SENSOR_TYPE_SPI_ACCELEROMETER_B)) { nActualChannels += 2; } +#endif } nChannelsEnabled += nActualChannels; @@ -1094,47 +1133,7 @@ return ADMW_SUCCESS; } -ADMW_RESULT admw1001_SetDiagnosticsConfig( - ADMW_DEVICE_HANDLE hDevice, - ADMW1001_DIAGNOSTICS_CONFIG *pDiagnosticsConfig) -{ - ADMW_CORE_Diagnostics_Control_t diagnosticsControlReg; - diagnosticsControlReg.VALUE16 = REG_RESET_VAL(CORE_DIAGNOSTICS_CONTROL); - - if (pDiagnosticsConfig->disableGlobalDiag) - diagnosticsControlReg.Diag_Global_En = 0; - else - diagnosticsControlReg.Diag_Global_En = 1; - - if (pDiagnosticsConfig->disableMeasurementDiag) - diagnosticsControlReg.Diag_Meas_En = 0; - 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_100_CYCLES; - break; - case ADMW1001_OPEN_SENSOR_DIAGNOSTICS_PER_1000_CYCLES: - diagnosticsControlReg.Diag_OSD_Freq = CORE_DIAGNOSTICS_CONTROL_OCD_PER_1000_CYCLES; - break; - default: - ADMW_LOG_ERROR("Invalid open-sensor diagnostic frequency %d specified", - pDiagnosticsConfig->osdFrequency); - return ADMW_INVALID_PARAM; - } - - WRITE_REG_U16(hDevice, diagnosticsControlReg.VALUE16, CORE_DIAGNOSTICS_CONTROL); - - return ADMW_SUCCESS; -} ADMW_RESULT admw1001_SetChannelCount( ADMW_DEVICE_HANDLE hDevice, @@ -1504,39 +1503,6 @@ return ADMW_INVALID_PARAM; } - - - 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; - } - WRITE_REG_U16(hDevice, channelExcitationReg.VALUE16, CORE_CHANNEL_EXCITATIONn(eChannelId)); return ADMW_SUCCESS; @@ -1620,88 +1586,6 @@ return ADMW_SUCCESS; } -static ADMW_RESULT admw_SetDigitalSensorCommands( - ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CH_ID eChannelId, - ADMW1001_DIGITAL_SENSOR_COMMAND *pConfigCommand, - ADMW1001_DIGITAL_SENSOR_COMMAND *pDataRequestCommand) -{ - ADMW_CORE_Digital_Sensor_Num_Cmds_t numCmdsReg; - - numCmdsReg.VALUE8 = REG_RESET_VAL(CORE_DIGITAL_SENSOR_NUM_CMDSn); - - CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_NUM_CMDS_DIGITAL_SENSOR_NUM_CFG_CMDS, - pConfigCommand->commandLength); - CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_NUM_CMDS_DIGITAL_SENSOR_NUM_READ_CMDS, - pDataRequestCommand->commandLength); - - numCmdsReg.Digital_Sensor_Num_Cfg_Cmds = pConfigCommand->commandLength; - numCmdsReg.Digital_Sensor_Num_Read_Cmds = pDataRequestCommand->commandLength; - - WRITE_REG_U8(hDevice, numCmdsReg.VALUE8, - CORE_DIGITAL_SENSOR_NUM_CMDSn(eChannelId)); - - /* - * NOTE - the fall-through cases in the switch statement below are - * intentional. - */ - switch (pConfigCommand->commandLength) { - case 7: - WRITE_REG_U8(hDevice, pConfigCommand->command[6], - CORE_DIGITAL_SENSOR_COMMAND7n(eChannelId)); - case 6: - WRITE_REG_U8(hDevice, pConfigCommand->command[5], - CORE_DIGITAL_SENSOR_COMMAND6n(eChannelId)); - case 5: - WRITE_REG_U8(hDevice, pConfigCommand->command[4], - CORE_DIGITAL_SENSOR_COMMAND5n(eChannelId)); - case 4: - WRITE_REG_U8(hDevice, pConfigCommand->command[3], - CORE_DIGITAL_SENSOR_COMMAND4n(eChannelId)); - case 3: - WRITE_REG_U8(hDevice, pConfigCommand->command[2], - CORE_DIGITAL_SENSOR_COMMAND3n(eChannelId)); - case 2: - WRITE_REG_U8(hDevice, pConfigCommand->command[1], - CORE_DIGITAL_SENSOR_COMMAND2n(eChannelId)); - case 1: - WRITE_REG_U8(hDevice, pConfigCommand->command[0], - CORE_DIGITAL_SENSOR_COMMAND1n(eChannelId)); - case 0: - default: - break; - }; - - switch (pDataRequestCommand->commandLength) { - case 7: - WRITE_REG_U8(hDevice, pDataRequestCommand->command[6], - CORE_DIGITAL_SENSOR_READ_CMD7n(eChannelId)); - case 6: - WRITE_REG_U8(hDevice, pDataRequestCommand->command[5], - CORE_DIGITAL_SENSOR_READ_CMD6n(eChannelId)); - case 5: - WRITE_REG_U8(hDevice, pDataRequestCommand->command[4], - CORE_DIGITAL_SENSOR_READ_CMD5n(eChannelId)); - case 4: - WRITE_REG_U8(hDevice, pDataRequestCommand->command[3], - CORE_DIGITAL_SENSOR_READ_CMD4n(eChannelId)); - case 3: - WRITE_REG_U8(hDevice, pDataRequestCommand->command[2], - CORE_DIGITAL_SENSOR_READ_CMD3n(eChannelId)); - case 2: - WRITE_REG_U8(hDevice, pDataRequestCommand->command[1], - CORE_DIGITAL_SENSOR_READ_CMD2n(eChannelId)); - case 1: - WRITE_REG_U8(hDevice, pDataRequestCommand->command[0], - CORE_DIGITAL_SENSOR_READ_CMD1n(eChannelId)); - case 0: - default: - break; - }; - - return ADMW_SUCCESS; -} - static ADMW_RESULT admw_SetDigitalSensorFormat( ADMW_DEVICE_HANDLE hDevice, ADMW1001_CH_ID eChannelId, @@ -1764,23 +1648,23 @@ 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)); - +// 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; } @@ -1952,15 +1836,6 @@ return eRet; } - eRet = admw_SetDigitalSensorCommands(hDevice, eChannelId, - &pI2cChannelConfig->configurationCommand, - &pI2cChannelConfig->dataRequestCommand); - if (eRet != ADMW_SUCCESS) { - ADMW_LOG_ERROR("Failed to set I2C sensor commands for channel %d", - eChannelId); - return eRet; - } - eRet = admw_SetDigitalSensorFormat(hDevice, eChannelId, &pI2cChannelConfig->dataFormat); if (eRet != ADMW_SUCCESS) { @@ -2040,15 +1915,6 @@ return eRet; } - eRet = admw_SetDigitalSensorCommands(hDevice, eChannelId, - &pSpiChannelConfig->configurationCommand, - &pSpiChannelConfig->dataRequestCommand); - if (eRet != ADMW_SUCCESS) { - ADMW_LOG_ERROR("Failed to set SPI sensor commands for channel %d", - eChannelId); - return eRet; - } - eRet = admw_SetDigitalSensorFormat(hDevice, eChannelId, &pSpiChannelConfig->dataFormat); if (eRet != ADMW_SUCCESS) { @@ -2130,7 +1996,7 @@ if (fSensorParam == 0.0f) fSensorParam = NAN; - WRITE_REG_FLOAT(hDevice, fSensorParam, CORE_SENSOR_PARAMETERn(eChannelId)); + //WRITE_REG_FLOAT(hDevice, fSensorParam, CORE_SENSOR_PARAMETERn(eChannelId)); return ADMW_SUCCESS; } @@ -2211,7 +2077,17 @@ break; default: ADMW_LOG_ERROR("Invalid channel ID %d specified", eChannelId); - return ADMW_INVALID_PARAM; + 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, @@ -2306,11 +2182,12 @@ return eRet; } - eRet = admw1001_SetDiagnosticsConfig(hDevice, &pDeviceConfig->diagnostics); - if (eRet) { - ADMW_LOG_ERROR("Failed to set diagnostics configuration"); - return eRet; - } +// eRet = admw1001_SetDiagnosticsConfig(hDevice, &pDeviceConfig->diagnostics); +// if (eRet) +// { +// ADMW_LOG_ERROR("Failed to set diagnostics configuration"); +// return eRet; +// } for (ADMW1001_CH_ID id = ADMW1001_CH_ID_ANLG_1_UNIVERSAL; id < ADMW1001_MAX_CHANNELS; @@ -2518,161 +2395,3 @@ return ADMW_SUCCESS; } - -ADMW_RESULT deviceInformation(ADMW_DEVICE_HANDLE hDevice) -{ - uint16_t nAddress = REG_CORE_REVISION; - char nData[ADMW_VERSION_REG_VAL_SIZE]; //4 Bytes of version register data - ADMW_RESULT res; - res=admw1001_ReadRegister(hDevice,nAddress,nData,sizeof(nData)); - if(res != ADMW_SUCCESS) { - //if reading version register failed, sending 00.00.0000 as ADMW1001 firmware version - //strcat(nData, ADMW1001_FIRMWARE_VERSION_DEFAULT); - ADMW_LOG_INFO("Firmware Version Id is %X.%X",nData[2],nData[0]); - } else { - char buffer[ADMW_FORMATTED_VERSION_SIZE]; //00.00.0000 8 digits + 2 Bytes "." + one null character at the end - strcat(nData, buffer); - ADMW_LOG_INFO("Firmware Version Id is %X.%X",nData[2],nData[0]); - } - return ADMW_SUCCESS; -} - -ADMW_RESULT admw1001_getFirmwareStatus( - ADMW_DEVICE_HANDLE const hDevice, - bool * const bFirmwareStatus) -{ - 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] = 0x53; - DataBuffer[5] = 0x00; //Command ID - - DataBuffer[6] = 0x00; - DataBuffer[7] = 0x00; - DataBuffer[8] = 0x00; - DataBuffer[9] = 0x00; //Address - - DataBuffer[10] = 0x53; - 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); - if (eRet) { - return eRet; - } - - //wait for command irq line to go low after sending read status header - wait_ms( 100 ); - - 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); - - nSize = SFL_READ_STATUS_RESPONSE_SIZE; - - eRet = admw_SpiReceive(pCtx->hSpi, NULL, DataBuffer, - nSize, false); - - if (eRet) { - return eRet; - } - - //Verifying the application version from the response to check if firmware is present or not - /* - Flash Memory description - ______________ - | Secure | 0x0000 0000 - | Flashloader | - |______________| 0x0000 3BFF - | Security |------------------ - | Page | 0x0000 3C00 - | | - |______________| 0x0000 3FFF - | |------------------ - | App Info | 0x0000 4000 - | Page | - |______________| 0x0000 4800 - | |------------------ - | Application | - | Image | Application resides only in this region - |______________|------------------ - | Reserved | 0x0003 FFF8 - | for | Reserved memory region - | Signature | 0x0003 FFFF - |______________|------------------ - - Application version is stored in the App Info Page, the app version is updated in this region everytime the new application firmware is downloaded. - Here we verify if Application version is present in the Read Status response - If the app version bytes value is 0xFFFFFFFF then there is no firmware else there exist a firmware - - Read Status Response: - ____________________________________________________________________________________________________________________________________ - | | | | | | - |uint16_t nFlashLoaderVersion | uint16_t nStatus | uint32_t nApplicationVersion | uint32_t nApplicationHash[8] | uint16_t nChecksum | - |_____________________________|__________________|______________________________|______________________________|_____________________| - - */ - - if( ((DataBuffer[4] == 0xFF) && - (DataBuffer[5] == 0xFF) && - (DataBuffer[6] == 0xFF) && - (DataBuffer[7] == 0xFF)) || - ((DataBuffer[4] == 0x00) && - (DataBuffer[5] == 0x00) && - (DataBuffer[6] == 0x00) && - (DataBuffer[7] == 0x00))) { - *bFirmwareStatus = false; - } else { - *bFirmwareStatus = true; - } - - return eRet; -} \ No newline at end of file