Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ADISense1000_Example_FW by
Revision 1:982f6f565e14, committed 2018-08-24
- Comitter:
- nfathurr
- Date:
- Fri Aug 24 09:01:59 2018 +0000
- Parent:
- 0:76fed7dd9235
- Commit message:
- Prosiwft with Temperature, Humidity, and Accelerometer
Changed in this revision
--- a/ADISense1000_MBED.c Thu Jan 25 16:00:23 2018 +0000 +++ b/ADISense1000_MBED.c Fri Aug 24 09:01:59 2018 +0000 @@ -1,114 +1,167 @@ -/*! - ****************************************************************************** - * @file: config.c - * @brief: - *----------------------------------------------------------------------------- - * -Copyright (c) 2017 Emutex Ltd. / Analog Devices, Inc. - -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - Modified versions of the software must be conspicuously marked as such. - - This software is licensed solely and exclusively for use with processors - manufactured by or for Analog Devices, Inc. - - This software may not be combined or merged with other code in any manner - that would cause the software to become subject to terms and conditions - which differ from those listed here. - - Neither the name of Analog Devices, Inc. nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - - The use of this software may or may not infringe the patent rights of one - or more patent holders. This license does not release you from the - requirement that you obtain separate licenses from these patent holders - to use this software. - -THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, -TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN -NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL -PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - *****************************************************************************/ - -#include "inc/adi_sense_config_types.h" - -ADI_SENSE_CONFIG config = { - .versionId = { .major = 1, .minor = 4 }, - .adisense1000 = { - .power = { - .powerMode = ADI_SENSE_1000_POWER_MODE_FULL, - .supplyVoltage = 3.3, - }, - .measurement = { - .operatingMode = ADI_SENSE_1000_OPERATING_MODE_CONTINUOUS, - .dataReadyMode = ADI_SENSE_1000_DATAREADY_PER_CYCLE, - .cycleInterval = 0, - }, - .channels = { - [ADI_SENSE_1000_CHANNEL_ID_SENSOR_0] = { - .enableChannel = true, - .disablePublishing = false, - .compensationChannel = ADI_SENSE_1000_CHANNEL_ID_CJC_0, - .measurementsPerCycle = 1, - .extraSettlingTime = 0.0000, - .measurementUnit = ADI_SENSE_1000_MEASUREMENT_UNIT_CELSIUS, - .adcChannelConfig = { - .sensor = ADI_SENSE_1000_ADC_SENSOR_THERMOCOUPLE_T_DEF_L1, - .gain = ADI_SENSE_1000_ADC_GAIN_128X, - .current = { - .outputLevel = ADI_SENSE_1000_ADC_EXC_CURRENT_NONE, - .swapOption = ADI_SENSE_1000_ADC_EXC_CURRENT_SWAP_NONE, - }, - .filter = { - .type = ADI_SENSE_1000_ADC_FILTER_SINC4, - .fs = 1920, - }, - .reference = { - .type = ADI_SENSE_1000_ADC_REFERENCE_VOLTAGE_INTERNAL, - .disableBuffer = false, - }, - .enableVbias = true, - }, - }, - [ADI_SENSE_1000_CHANNEL_ID_CJC_0] = { - .enableChannel = true, - .disablePublishing = false, - .compensationChannel = ADI_SENSE_1000_CHANNEL_ID_NONE, - .measurementsPerCycle = 1, - .extraSettlingTime = 0.0000, - .measurementUnit = ADI_SENSE_1000_MEASUREMENT_UNIT_CELSIUS, - .adcChannelConfig = { - .sensor = ADI_SENSE_1000_ADC_SENSOR_RTD_2WIRE_PT100_DEF_L1, - .gain = ADI_SENSE_1000_ADC_GAIN_128X, - .current = { - .outputLevel = ADI_SENSE_1000_ADC_EXC_CURRENT_500uA, - .swapOption = ADI_SENSE_1000_ADC_EXC_CURRENT_SWAP_NONE, - }, - .filter = { - .type = ADI_SENSE_1000_ADC_FILTER_SINC4, - .fs = 1920, - }, - .reference = { - .type = ADI_SENSE_1000_ADC_REFERENCE_RESISTOR_INTERNAL_1, - .disableBuffer = false, - }, - .enableVbias = false, - }, - }, - }, - }, -}; +/*! + ****************************************************************************** + * @file: config.c + * @brief: + *----------------------------------------------------------------------------- + * +Copyright (c) 2018 Analog Devices, Inc. + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + - Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + - Modified versions of the software must be conspicuously marked as such. + - This software is licensed solely and exclusively for use with processors + manufactured by or for Analog Devices, Inc. + - This software may not be combined or merged with other code in any manner + that would cause the software to become subject to terms and conditions + which differ from those listed here. + - Neither the name of Analog Devices, Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + - The use of this software may or may not infringe the patent rights of one + or more patent holders. This license does not release you from the + requirement that you obtain separate licenses from these patent holders + to use this software. + +THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, +TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN +NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL +PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *****************************************************************************/ + +#include "inc/adi_sense_config_types.h" +ADI_SENSE_CONFIG config = { + .versionId = { .major = 1, .minor = 4 }, + .productId = ADI_SENSE_PRODUCT_ID_1000, + .adisense1000 = { + .power = { + .powerMode = ADI_SENSE_1000_POWER_MODE_FULL, + .supplyVoltage = 3.3, + }, + .measurement = { + .operatingMode = ADI_SENSE_1000_OPERATING_MODE_CONTINUOUS, + .dataReadyMode = ADI_SENSE_1000_DATAREADY_PER_CYCLE, + .cycleInterval = 0, + }, + .channels = { + //RTD PT100 + [ADI_SENSE_1000_CHANNEL_ID_CJC_0] = { + .enableChannel = true, + .disablePublishing = false, + .compensationChannel = ADI_SENSE_1000_CHANNEL_ID_NONE, + .measurementsPerCycle = 1, + .extraSettlingTime = 0.0000, + .measurementUnit = ADI_SENSE_1000_MEASUREMENT_UNIT_CELSIUS, + .adcChannelConfig = { + .sensor = ADI_SENSE_1000_ADC_SENSOR_RTD_2WIRE_PT100_DEF_L1, + .gain = ADI_SENSE_1000_ADC_GAIN_32X, + .current = { + .outputLevel = ADI_SENSE_1000_ADC_EXC_CURRENT_500uA, + .swapOption = ADI_SENSE_1000_ADC_EXC_CURRENT_SWAP_NONE, + }, + .filter = { + .type = ADI_SENSE_1000_ADC_FILTER_FIR_25SPS, + .fs = 0, + //.type = ADI_SENSE_1000_ADC_FILTER_SINC4, + //.fs = 1920, + }, + .reference = { + .type = ADI_SENSE_1000_ADC_REFERENCE_RESISTOR_INTERNAL_1, + .disableBuffer = false, + }, + .enableVbias = false, + }, + }, + //THERMOCOUPLE + [ADI_SENSE_1000_CHANNEL_ID_SENSOR_0] = { + .enableChannel = true, + .disablePublishing = false, + .compensationChannel = ADI_SENSE_1000_CHANNEL_ID_CJC_0, + .measurementsPerCycle = 1, + .extraSettlingTime = 0.0000, + .measurementUnit = ADI_SENSE_1000_MEASUREMENT_UNIT_CELSIUS, + .adcChannelConfig = { + .sensor = ADI_SENSE_1000_ADC_SENSOR_THERMOCOUPLE_K_DEF_L1, + .gain = ADI_SENSE_1000_ADC_GAIN_128X, + .current = { + .outputLevel = ADI_SENSE_1000_ADC_EXC_CURRENT_NONE, + .swapOption = ADI_SENSE_1000_ADC_EXC_CURRENT_SWAP_NONE, + }, + .filter = { + //.type = ADI_SENSE_1000_ADC_FILTER_FIR_25SPS, + //.fs = 0, + .type = ADI_SENSE_1000_ADC_FILTER_SINC4, + .fs = 1920, + }, + .reference = { + .type = ADI_SENSE_1000_ADC_REFERENCE_VOLTAGE_INTERNAL, + .disableBuffer = false, + }, + .enableVbias = true, + }, + }, + //HUMIDITY SENSOR + [ADI_SENSE_1000_CHANNEL_ID_I2C_0] = { + .enableChannel = true, + .disablePublishing = false, + .compensationChannel = ADI_SENSE_1000_CHANNEL_ID_NONE, + .measurementsPerCycle = 1, + .extraSettlingTime = 0.0000, + .i2cChannelConfig = { + .sensor = ADI_SENSE_1000_I2C_SENSOR_HUMIDITY_SENSIRION_SHT3X, + .deviceAddress = 0x44, + }, + }, + //ACCELEROMETER + [ADI_SENSE_1000_CHANNEL_ID_SPI_0] = { //X-Axis + .enableChannel = true, + .disablePublishing = false, + .compensationChannel = ADI_SENSE_1000_CHANNEL_ID_NONE, + .measurementsPerCycle = 1, + .extraSettlingTime = 1000, + .offsetAdjustment = +0.03, + + .lowThreshold = -6.0, + .highThreshold = 6.0, + .spiChannelConfig = { + .sensor = ADI_SENSE_1000_SPI_SENSOR_ACCELEROMETER_ADI_ADXL362, + .configurationCommand = { + .command = { 0x0A, 0x2C, 0x03 }, + .commandLength = 3, + }, + }, + }, + [ADI_SENSE_1000_CHANNEL_ID_SPI_1] = { //Y-Axis + .enableChannel = true, + .offsetAdjustment = -0.014, + + .lowThreshold = -6.0, + .highThreshold = 6.0, + }, + [ADI_SENSE_1000_CHANNEL_ID_SPI_2] = { //Z-Axis + + .enableChannel = true, + + .offsetAdjustment = -0.23, + .lowThreshold = -6, + .highThreshold = 6, + }, + }, + }, +}; +
--- a/common/utils.c Thu Jan 25 16:00:23 2018 +0000 +++ b/common/utils.c Fri Aug 24 09:01:59 2018 +0000 @@ -1,389 +1,449 @@ -#include <stdlib.h> - -#include "utils.h" -#include "inc/adi_sense_log.h" - -void utils_printStatus( - ADI_SENSE_STATUS *pStatus) -{ - ADI_SENSE_LOG_INFO("Status Summary:"); - - if (pStatus->deviceStatus == 0) - { - ADI_SENSE_LOG_INFO("\tNo errors detected"); - } - else - { - if (pStatus->deviceStatus & ADI_SENSE_DEVICE_STATUS_BUSY) - ADI_SENSE_LOG_INFO("\tCommand running"); - if (pStatus->deviceStatus & ADI_SENSE_DEVICE_STATUS_DATAREADY) - ADI_SENSE_LOG_INFO("\tData ready"); - if (pStatus->deviceStatus & ADI_SENSE_DEVICE_STATUS_ERROR) - ADI_SENSE_LOG_INFO("\tActive Errors - RESET REQUIRED"); - if (pStatus->deviceStatus & ADI_SENSE_DEVICE_STATUS_FIFO_ERROR) - ADI_SENSE_LOG_INFO("\tActive FIFO Errors - ATTENTION REQUIRED"); - if (pStatus->deviceStatus & ADI_SENSE_DEVICE_STATUS_CONFIG_ERROR) - ADI_SENSE_LOG_INFO("\tActive Configuration Errors - ATTENTION REQUIRED"); - if (pStatus->deviceStatus & ADI_SENSE_DEVICE_STATUS_LUT_ERROR) - ADI_SENSE_LOG_INFO("\tActive Look-Up Table Errors - ATTENTION REQUIRED"); - - if (pStatus->deviceStatus & ADI_SENSE_DEVICE_STATUS_ERROR) - { - ADI_SENSE_LOG_INFO("\tActive Errors - ATTENTION REQUIRED"); - ADI_SENSE_LOG_INFO("\t\tLast Error Code: %u (0x%X)", - pStatus->errorCode, pStatus->errorCode); - - if (pStatus->diagnosticsStatus == 0) - { - ADI_SENSE_LOG_INFO("\t\tNo diagnostics faults detected"); - } - else - { - ADI_SENSE_LOG_INFO("\t\tActive diagnostics faults:"); - - if (pStatus->diagnosticsStatus & ADI_SENSE_DIAGNOSTICS_STATUS_CHECKSUM_ERROR) - ADI_SENSE_LOG_INFO("\t\t\tInternal Checksum fault detected"); - if (pStatus->diagnosticsStatus & ADI_SENSE_DIAGNOSTICS_STATUS_COMMS_ERROR) - ADI_SENSE_LOG_INFO("\t\t\tInternal Communications fault detected"); - if (pStatus->diagnosticsStatus & ADI_SENSE_DIAGNOSTICS_STATUS_SUPPLY_MONITOR_ERROR) - ADI_SENSE_LOG_INFO("\t\t\tSupply Monitor fault detected"); - if (pStatus->diagnosticsStatus & ADI_SENSE_DIAGNOSTICS_STATUS_SUPPLY_CAP_ERROR) - ADI_SENSE_LOG_INFO("\t\t\tSupply Regulator Capacitor fault detected"); - if (pStatus->diagnosticsStatus & ADI_SENSE_DIAGNOSTICS_STATUS_AINM_UV_ERROR) - ADI_SENSE_LOG_INFO("\t\t\tNegative Analog Input Under-Voltage fault detected"); - if (pStatus->diagnosticsStatus & ADI_SENSE_DIAGNOSTICS_STATUS_AINM_OV_ERROR) - ADI_SENSE_LOG_INFO("\t\t\tNegative Analog Input Over-Voltage fault detected"); - if (pStatus->diagnosticsStatus & ADI_SENSE_DIAGNOSTICS_STATUS_AINP_UV_ERROR) - ADI_SENSE_LOG_INFO("\t\t\tPositive Analog Input Under-Voltage fault detected"); - if (pStatus->diagnosticsStatus & ADI_SENSE_DIAGNOSTICS_STATUS_AINP_OV_ERROR) - ADI_SENSE_LOG_INFO("\t\t\tPositive Analog Input Over-Voltage fault detected"); - if (pStatus->diagnosticsStatus & ADI_SENSE_DIAGNOSTICS_STATUS_CONVERSION_ERROR) - ADI_SENSE_LOG_INFO("\t\t\tInternal ADC Conversions fault detected"); - if (pStatus->diagnosticsStatus & ADI_SENSE_DIAGNOSTICS_STATUS_CALIBRATION_ERROR) - ADI_SENSE_LOG_INFO("\t\t\tInternal Device Calibrations fault detected"); - } - } - - if (pStatus->deviceStatus & ADI_SENSE_DEVICE_STATUS_ALERT) - { - ADI_SENSE_LOG_INFO("\tActive Alerts - ATTENTION REQUIRED:"); - ADI_SENSE_LOG_INFO("\t\tLast Alert Code: %u (0x%X)", - pStatus->alertCode, pStatus->alertCode); - - for (unsigned i = 0; i < ADI_SENSE_1000_MAX_CHANNELS; i++) - { - if (pStatus->channelAlerts[i] == 0) - continue; - - ADI_SENSE_LOG_INFO("\t\tChannel #%u:", i); - ADI_SENSE_LOG_INFO("\t\t\tLast Alert Code: %u (0x%X)", - pStatus->channelAlertCodes[i], - pStatus->channelAlertCodes[i]); - if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_TIMEOUT) - ADI_SENSE_LOG_INFO("\t\t\tTimeout alert detected"); - if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_UNDER_RANGE) - ADI_SENSE_LOG_INFO("\t\t\tUnder Range alert detected"); - if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_OVER_RANGE) - ADI_SENSE_LOG_INFO("\t\t\tOver Range alert detected"); - if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_LOW_LIMIT) - ADI_SENSE_LOG_INFO("\t\t\tLow limit alert detected"); - if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_HIGH_LIMIT) - ADI_SENSE_LOG_INFO("\t\t\tHigh Limit alert detected"); - if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_SENSOR_OPEN) - ADI_SENSE_LOG_INFO("\t\t\tSensor Fault alert detected"); - if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_REF_DETECT) - ADI_SENSE_LOG_INFO("\t\t\tReference Detection alert detected"); - if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_CONFIG_ERR) - ADI_SENSE_LOG_INFO("\t\t\tConfiguration Error alert detected"); - if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_LUT_ERR) - ADI_SENSE_LOG_INFO("\t\t\tLook-Up Table Error alert detected"); - if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_SENSOR_NOT_READY) - ADI_SENSE_LOG_INFO("\t\t\tSensor Not Ready alert detected"); - if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_COMP_NOT_READY) - ADI_SENSE_LOG_INFO("\t\t\tCompensation Channel Not Ready alert detected"); - if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_UNDER_VOLTAGE) - ADI_SENSE_LOG_INFO("\t\t\tUnder Voltage alert detected"); - if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_OVER_VOLTAGE) - ADI_SENSE_LOG_INFO("\t\t\tOver Voltage alert detected"); - if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_LUT_UNDER_RANGE) - ADI_SENSE_LOG_INFO("\t\t\tUnder Look-Up Table Range alert detected"); - if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_LUT_OVER_RANGE) - ADI_SENSE_LOG_INFO("\t\t\tOver Look-Up Table Range alert detected"); - } - } - } -} - -void utils_printSamples( - ADI_SENSE_DATA_SAMPLE *pSampleBuffer, - uint32_t nNumSamples) -{ - for (uint32_t i = 0; i < nNumSamples; i++) - { - ADI_SENSE_LOG_INFO("Sample # %2d Channel # %2d :: Raw %8d :: Processed %.7f :: flags: %s %s", - i+1, - pSampleBuffer[i].channelId, - pSampleBuffer[i].rawValue, - pSampleBuffer[i].processedValue, - pSampleBuffer[i].status & ADI_SENSE_DEVICE_STATUS_ERROR ? "ERROR" : "", - pSampleBuffer[i].status & ADI_SENSE_DEVICE_STATUS_ALERT ? "ALERT" : ""); - } -} - -static void gpioCallbackFn(ADI_SENSE_GPIO_PIN ePinId, void * pArg) -{ - volatile bool_t *pbFlag = (volatile bool_t *)pArg; - *pbFlag = true; -} - -ADI_SENSE_RESULT utils_registerCallbacks( - ADI_SENSE_DEVICE_HANDLE hDevice, - volatile bool_t *pbDataReady, - volatile bool_t *pbError, - volatile bool_t *pbAlert) -{ - ADI_SENSE_RESULT res; - - res = adi_sense_RegisterGpioCallback(hDevice, ADI_SENSE_GPIO_PIN_DATAREADY, - gpioCallbackFn, (void *)pbDataReady); - if (res != ADI_SENSE_SUCCESS) - { - ADI_SENSE_LOG_ERROR("Failed to register DATAREADY callback"); - return res; - } - - res = adi_sense_RegisterGpioCallback(hDevice, ADI_SENSE_GPIO_PIN_ERROR, - gpioCallbackFn, (void *)pbError); - if (res != ADI_SENSE_SUCCESS) - { - ADI_SENSE_LOG_ERROR("Failed to register ERROR callback"); - return res; - } - - res = adi_sense_RegisterGpioCallback(hDevice, ADI_SENSE_GPIO_PIN_ALERT, - gpioCallbackFn, (void *)pbAlert); - if (res != ADI_SENSE_SUCCESS) - { - ADI_SENSE_LOG_ERROR("Failed to register ALERT callback"); - return res; - } - - return ADI_SENSE_SUCCESS; -} - -ADI_SENSE_RESULT utils_deregisterCallbacks( - ADI_SENSE_DEVICE_HANDLE hDevice) -{ - ADI_SENSE_RESULT res; - - res = adi_sense_RegisterGpioCallback(hDevice, ADI_SENSE_GPIO_PIN_DATAREADY, - NULL, NULL); - if (res != ADI_SENSE_SUCCESS) - { - ADI_SENSE_LOG_ERROR("Failed to deregister DATAREADY callback"); - return res; - } - - res = adi_sense_RegisterGpioCallback(hDevice, ADI_SENSE_GPIO_PIN_ERROR, - NULL, NULL); - if (res != ADI_SENSE_SUCCESS) - { - ADI_SENSE_LOG_ERROR("Failed to deregister ERROR callback"); - return res; - } - - res = adi_sense_RegisterGpioCallback(hDevice, ADI_SENSE_GPIO_PIN_ALERT, - NULL, NULL); - if (res != ADI_SENSE_SUCCESS) - { - ADI_SENSE_LOG_INFO("Failed to deregister ALERT callback"); - return res; - } - - return ADI_SENSE_SUCCESS; -} - -ADI_SENSE_RESULT utils_runMeasurement( - ADI_SENSE_DEVICE_HANDLE hDevice, - ADI_SENSE_MEASUREMENT_MODE eMeasurementMode) -{ - ADI_SENSE_RESULT res; - - volatile bool_t bDataReady = false; - volatile bool_t bError = false; - volatile bool_t bAlert = false; - res = utils_registerCallbacks(hDevice, &bDataReady, &bError, &bAlert); - if (res != ADI_SENSE_SUCCESS) - return res; - - /* - * Retrieve the number of samples per cycle, per DATAREADY pulse, etc. for this configuration. - */ - ADI_SENSE_1000_OPERATING_MODE eOperatingMode; - ADI_SENSE_1000_DATAREADY_MODE eDataReadyMode; - uint32_t nSamplesPerDataready; - uint32_t nSamplesPerCycle; - res = adi_sense_1000_GetDataReadyModeInfo(hDevice, - eMeasurementMode, - &eOperatingMode, - &eDataReadyMode, - &nSamplesPerDataready, - &nSamplesPerCycle); - if (res != ADI_SENSE_SUCCESS) - return res; - - /* - * Allocate a buffer to store the samples retrieved on each DATAREADY pulse - * However, if the DATAREADY pulse is per-conversion, allocate a bigger buffer - * to accumulate a full cycle of samples before printing them - */ - ADI_SENSE_DATA_SAMPLE *pSampleBuffer; - if (eDataReadyMode == ADI_SENSE_1000_DATAREADY_PER_CONVERSION) - pSampleBuffer = malloc(sizeof(ADI_SENSE_DATA_SAMPLE) * nSamplesPerCycle); - else - pSampleBuffer = malloc(sizeof(ADI_SENSE_DATA_SAMPLE) * nSamplesPerDataready); - if (pSampleBuffer == NULL) - { - ADI_SENSE_LOG_ERROR("Failed to allocate sample buffer"); - return ADI_SENSE_NO_MEM; - } - - /* - * Kick off the measurement cycle(s) here - */ - res = adi_sense_StartMeasurement(hDevice, eMeasurementMode); - if (res != ADI_SENSE_SUCCESS) - { - ADI_SENSE_LOG_ERROR("Failed to start measurement"); - return res; - } - - /* - * Loop continuously unless operating mode is single-cycle - */ - do { - ADI_SENSE_STATUS status; - uint32_t nCurrentSamples; - uint32_t nReturned; - nCurrentSamples = 0; - - /* - * Accumulate the samples from a cycle and print them - * NOTE: requires a sufficient idle time between cycles to allow printing to occur - */ - do { - /* - * Wait for the cycle to complete, continuously checking DATAREADY until it is asserted - */ - while (! (bDataReady || bError)) - ; - - if (! bError) - { - /* - * Retrieve the data samples from the measurement cycle, if no error has occurred - */ - bDataReady = false; - res = adi_sense_GetData(hDevice, eMeasurementMode, &pSampleBuffer[nCurrentSamples], nSamplesPerDataready, &nReturned); - nCurrentSamples += nReturned; - if (res != ADI_SENSE_SUCCESS) - { - if (res == ADI_SENSE_INCOMPLETE) - { - /* For this case, let's get the device status and print - * any samples we did get */ - ADI_SENSE_LOG_WARN("Failed to retrieve all requested data samples"); - break; - } - else - { - ADI_SENSE_LOG_WARN("Failed to retrieve data samples from device"); - return res; - } - } - } - } while (!bError && (nCurrentSamples < nSamplesPerCycle)); - - /* - * Display the data samples - */ - utils_printSamples(pSampleBuffer, nCurrentSamples); - - /* - * Check and print device status if errors/alerts have been triggered - */ - if (bError || bAlert) - { - res = adi_sense_GetStatus(hDevice, &status); - if (res != ADI_SENSE_SUCCESS) - { - ADI_SENSE_LOG_ERROR("Failed to retrieve device status"); - return res; - } - - if (status.deviceStatus & - (ADI_SENSE_DEVICE_STATUS_ERROR | ADI_SENSE_DEVICE_STATUS_ALERT)) - { - utils_printStatus(&status); - - /* Break out of the loop if any errors are raised */ - if (bError) - break; - } - } - } while (eOperatingMode != ADI_SENSE_1000_OPERATING_MODE_SINGLECYCLE); - - res = adi_sense_StopMeasurement(hDevice); - if (res != ADI_SENSE_SUCCESS) - { - ADI_SENSE_LOG_ERROR("Failed to send stop measurement"); - return res; - } - - free(pSampleBuffer); - - res = utils_deregisterCallbacks(hDevice); - if (res != ADI_SENSE_SUCCESS) - return res; - - return ADI_SENSE_SUCCESS; -} - -ADI_SENSE_RESULT utils_printCalTable( - ADI_SENSE_DEVICE_HANDLE hDevice) -{ - ADI_SENSE_RESULT res; - unsigned dataLen, nRows, nColumns, maxLen = 1024; - - float *pCalDataBuffer = malloc(maxLen); - if (pCalDataBuffer == NULL) - { - ADI_SENSE_LOG_ERROR("Failed to allocate calibration data buffer"); - return ADI_SENSE_NO_MEM; - } - - res = adi_sense_1000_ReadCalTable(hDevice, - pCalDataBuffer, maxLen, - &dataLen, &nRows, &nColumns); - if (res != ADI_SENSE_SUCCESS) - { - ADI_SENSE_LOG_ERROR("Failed to read calibration data"); - free(pCalDataBuffer); - return res; - } - - ADI_SENSE_LOG_INFO("Calibration Table:\r\n"); - ADI_SENSE_LOG_INFO("%6s| %10s | %10s | %10s |", "index", "25", "-40", "85"); - for (unsigned row = 0; row < nRows; row++) - { - ADI_SENSE_LOG_INFO("%6d| %10f | %10f | %10f |", - row, - pCalDataBuffer[(row * nColumns) + 0], - pCalDataBuffer[(row * nColumns) + 1], - pCalDataBuffer[(row * nColumns) + 2]); - } - - free(pCalDataBuffer); - return ADI_SENSE_SUCCESS; -} +#include <stdlib.h> + +#include "utils.h" +#include "inc/adi_sense_log.h" + +void utils_printStatus( + ADI_SENSE_STATUS *pStatus) +{ + ADI_SENSE_LOG_INFO("Status Summary:"); + + if (pStatus->deviceStatus == 0) + { + ADI_SENSE_LOG_INFO("\tNo errors detected"); + } + else + { + if (pStatus->deviceStatus & ADI_SENSE_DEVICE_STATUS_BUSY) + ADI_SENSE_LOG_INFO("\tCommand running"); + if (pStatus->deviceStatus & ADI_SENSE_DEVICE_STATUS_DATAREADY) + ADI_SENSE_LOG_INFO("\tData ready"); + if (pStatus->deviceStatus & ADI_SENSE_DEVICE_STATUS_ERROR) + ADI_SENSE_LOG_INFO("\tActive Errors - RESET REQUIRED"); + if (pStatus->deviceStatus & ADI_SENSE_DEVICE_STATUS_FIFO_ERROR) + ADI_SENSE_LOG_INFO("\tActive FIFO Errors - ATTENTION REQUIRED"); + if (pStatus->deviceStatus & ADI_SENSE_DEVICE_STATUS_CONFIG_ERROR) + ADI_SENSE_LOG_INFO("\tActive Configuration Errors - ATTENTION REQUIRED"); + if (pStatus->deviceStatus & ADI_SENSE_DEVICE_STATUS_LUT_ERROR) + ADI_SENSE_LOG_INFO("\tActive Look-Up Table Errors - ATTENTION REQUIRED"); + + if (pStatus->deviceStatus & ADI_SENSE_DEVICE_STATUS_ERROR) + { + ADI_SENSE_LOG_INFO("\tActive Errors - ATTENTION REQUIRED"); + ADI_SENSE_LOG_INFO("\t\tLast Error Code: %u (0x%X)", + pStatus->errorCode, pStatus->errorCode); + + if (pStatus->diagnosticsStatus == 0) + { + ADI_SENSE_LOG_INFO("\t\tNo diagnostics faults detected"); + } + else + { + ADI_SENSE_LOG_INFO("\t\tActive diagnostics faults:"); + + if (pStatus->diagnosticsStatus & ADI_SENSE_DIAGNOSTICS_STATUS_CHECKSUM_ERROR) + ADI_SENSE_LOG_INFO("\t\t\tInternal Checksum fault detected"); + if (pStatus->diagnosticsStatus & ADI_SENSE_DIAGNOSTICS_STATUS_COMMS_ERROR) + ADI_SENSE_LOG_INFO("\t\t\tInternal Communications fault detected"); + if (pStatus->diagnosticsStatus & ADI_SENSE_DIAGNOSTICS_STATUS_SUPPLY_MONITOR_ERROR) + ADI_SENSE_LOG_INFO("\t\t\tSupply Monitor fault detected"); + if (pStatus->diagnosticsStatus & ADI_SENSE_DIAGNOSTICS_STATUS_SUPPLY_CAP_ERROR) + ADI_SENSE_LOG_INFO("\t\t\tSupply Regulator Capacitor fault detected"); + if (pStatus->diagnosticsStatus & ADI_SENSE_DIAGNOSTICS_STATUS_AINM_UV_ERROR) + ADI_SENSE_LOG_INFO("\t\t\tNegative Analog Input Under-Voltage fault detected"); + if (pStatus->diagnosticsStatus & ADI_SENSE_DIAGNOSTICS_STATUS_AINM_OV_ERROR) + ADI_SENSE_LOG_INFO("\t\t\tNegative Analog Input Over-Voltage fault detected"); + if (pStatus->diagnosticsStatus & ADI_SENSE_DIAGNOSTICS_STATUS_AINP_UV_ERROR) + ADI_SENSE_LOG_INFO("\t\t\tPositive Analog Input Under-Voltage fault detected"); + if (pStatus->diagnosticsStatus & ADI_SENSE_DIAGNOSTICS_STATUS_AINP_OV_ERROR) + ADI_SENSE_LOG_INFO("\t\t\tPositive Analog Input Over-Voltage fault detected"); + if (pStatus->diagnosticsStatus & ADI_SENSE_DIAGNOSTICS_STATUS_CONVERSION_ERROR) + ADI_SENSE_LOG_INFO("\t\t\tInternal ADC Conversions fault detected"); + if (pStatus->diagnosticsStatus & ADI_SENSE_DIAGNOSTICS_STATUS_CALIBRATION_ERROR) + ADI_SENSE_LOG_INFO("\t\t\tInternal Device Calibrations fault detected"); + } + } + + if (pStatus->deviceStatus & ADI_SENSE_DEVICE_STATUS_ALERT) + { + ADI_SENSE_LOG_INFO("\tActive Alerts - ATTENTION REQUIRED:"); + ADI_SENSE_LOG_INFO("\t\tLast Alert Code: %u (0x%X)", + pStatus->alertCode, pStatus->alertCode); + + for (unsigned i = 0; i < ADI_SENSE_1000_MAX_CHANNELS; i++) + { + if (pStatus->channelAlerts[i] == 0) + continue; + + ADI_SENSE_LOG_INFO("\t\tChannel #%u:", i); + ADI_SENSE_LOG_INFO("\t\t\tLast Alert Code: %u (0x%X)", + pStatus->channelAlertCodes[i], + pStatus->channelAlertCodes[i]); + if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_TIMEOUT) + ADI_SENSE_LOG_INFO("\t\t\tTimeout alert detected"); + if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_UNDER_RANGE) + ADI_SENSE_LOG_INFO("\t\t\tUnder Range alert detected"); + if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_OVER_RANGE) + ADI_SENSE_LOG_INFO("\t\t\tOver Range alert detected"); + if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_LOW_LIMIT) + ADI_SENSE_LOG_INFO("\t\t\tLow limit alert detected"); + if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_HIGH_LIMIT) + ADI_SENSE_LOG_INFO("\t\t\tHigh Limit alert detected"); + if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_SENSOR_OPEN) + ADI_SENSE_LOG_INFO("\t\t\tSensor Fault alert detected"); + if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_REF_DETECT) + ADI_SENSE_LOG_INFO("\t\t\tReference Detection alert detected"); + if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_CONFIG_ERR) + ADI_SENSE_LOG_INFO("\t\t\tConfiguration Error alert detected"); + if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_LUT_ERR) + ADI_SENSE_LOG_INFO("\t\t\tLook-Up Table Error alert detected"); + if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_SENSOR_NOT_READY) + ADI_SENSE_LOG_INFO("\t\t\tSensor Not Ready alert detected"); + if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_COMP_NOT_READY) + ADI_SENSE_LOG_INFO("\t\t\tCompensation Channel Not Ready alert detected"); + if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_UNDER_VOLTAGE) + ADI_SENSE_LOG_INFO("\t\t\tUnder Voltage alert detected"); + if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_OVER_VOLTAGE) + ADI_SENSE_LOG_INFO("\t\t\tOver Voltage alert detected"); + if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_LUT_UNDER_RANGE) + ADI_SENSE_LOG_INFO("\t\t\tUnder Look-Up Table Range alert detected"); + if (pStatus->channelAlerts[i] & ADI_SENSE_CHANNEL_ALERT_LUT_OVER_RANGE) + ADI_SENSE_LOG_INFO("\t\t\tOver Look-Up Table Range alert detected"); + } + } + } +} + +void utils_printSamples( + ADI_SENSE_DATA_SAMPLE *pSampleBuffer, + uint32_t nNumSamples) +{ + for (uint32_t i = 0; i < nNumSamples; i++) + { + ADI_SENSE_LOG_INFO("Sample # %2d Channel # %2d :: Raw %8d :: Processed %.7f :: flags: %s %s", + i+1, + pSampleBuffer[i].channelId, + pSampleBuffer[i].rawValue, + pSampleBuffer[i].processedValue, + pSampleBuffer[i].status & ADI_SENSE_DEVICE_STATUS_ERROR ? "ERROR" : "", + pSampleBuffer[i].status & ADI_SENSE_DEVICE_STATUS_ALERT ? "ALERT" : ""); + } +} + +void utils_printSamples_alt( + ADI_SENSE_DATA_SAMPLE *pSampleBuffer, + uint32_t nNumSamples) +{ + //for (uint32_t i = 0; i < nNumSamples; i++) + //{ + //temp_comp temp pressure himidity AccX AccY AccZ + ADI_SENSE_LOG_INFO("%8d\t%.5f\t%8d\t%.5f\t%8d\t%.5f\t%8d\t%.5f\t%8d\t%.5f\t%8d\t%.5f", + //temp_comp + pSampleBuffer[0].rawValue, + pSampleBuffer[0].processedValue, + //temp + pSampleBuffer[1].rawValue, + pSampleBuffer[1].processedValue, + //humidity + pSampleBuffer[2].rawValue, + pSampleBuffer[2].processedValue, + //AccX + pSampleBuffer[3].rawValue, + pSampleBuffer[3].processedValue, + //AccY + pSampleBuffer[4].rawValue, + pSampleBuffer[4].processedValue, + //AccZ + pSampleBuffer[5].rawValue, + pSampleBuffer[5].processedValue); + //} +} + +void utils_printSamples_pro( + ADI_SENSE_DATA_SAMPLE *pSampleBuffer, + uint32_t nNumSamples) +{ + //for (uint32_t i = 0; i < nNumSamples; i++) + //{ + //temp_comp temp pressure himidity AccX AccY AccZ + ADI_SENSE_LOG_INFO("%.5f %.5f %.5f %.5f %.5f %.5f", + //temp_comp + //pSampleBuffer[0].rawValue, + pSampleBuffer[0].processedValue, + //temp + //pSampleBuffer[1].rawValue, + pSampleBuffer[1].processedValue, + //humidity + //pSampleBuffer[3].rawValue, + pSampleBuffer[2].processedValue, + //AccX + //pSampleBuffer[4].rawValue, + pSampleBuffer[3].processedValue, + //AccY + //pSampleBuffer[5].rawValue, + pSampleBuffer[4].processedValue, + //AccZ + //pSampleBuffer[6].rawValue, + pSampleBuffer[5].processedValue); + //} +} + +static void gpioCallbackFn(ADI_SENSE_GPIO_PIN ePinId, void * pArg) +{ + volatile bool_t *pbFlag = (volatile bool_t *)pArg; + *pbFlag = true; +} + +ADI_SENSE_RESULT utils_registerCallbacks( + ADI_SENSE_DEVICE_HANDLE hDevice, + volatile bool_t *pbDataReady, + volatile bool_t *pbError, + volatile bool_t *pbAlert) +{ + ADI_SENSE_RESULT res; + + res = adi_sense_RegisterGpioCallback(hDevice, ADI_SENSE_GPIO_PIN_DATAREADY, + gpioCallbackFn, (void *)pbDataReady); + if (res != ADI_SENSE_SUCCESS) + { + ADI_SENSE_LOG_ERROR("Failed to register DATAREADY callback"); + return res; + } + + res = adi_sense_RegisterGpioCallback(hDevice, ADI_SENSE_GPIO_PIN_ERROR, + gpioCallbackFn, (void *)pbError); + if (res != ADI_SENSE_SUCCESS) + { + ADI_SENSE_LOG_ERROR("Failed to register ERROR callback"); + return res; + } + res = adi_sense_RegisterGpioCallback(hDevice, ADI_SENSE_GPIO_PIN_ALERT, + gpioCallbackFn, (void *)pbAlert); + if (res != ADI_SENSE_SUCCESS) + { + ADI_SENSE_LOG_ERROR("Failed to register ALERT callback"); + return res; + } + + return ADI_SENSE_SUCCESS; +} + +ADI_SENSE_RESULT utils_deregisterCallbacks( + ADI_SENSE_DEVICE_HANDLE hDevice) +{ + ADI_SENSE_RESULT res; + + res = adi_sense_RegisterGpioCallback(hDevice, ADI_SENSE_GPIO_PIN_DATAREADY, + NULL, NULL); + if (res != ADI_SENSE_SUCCESS) + { + ADI_SENSE_LOG_ERROR("Failed to deregister DATAREADY callback"); + return res; + } + + res = adi_sense_RegisterGpioCallback(hDevice, ADI_SENSE_GPIO_PIN_ERROR, + NULL, NULL); + if (res != ADI_SENSE_SUCCESS) + { + ADI_SENSE_LOG_ERROR("Failed to deregister ERROR callback"); + return res; + } + + res = adi_sense_RegisterGpioCallback(hDevice, ADI_SENSE_GPIO_PIN_ALERT, + NULL, NULL); + if (res != ADI_SENSE_SUCCESS) + { + ADI_SENSE_LOG_INFO("Failed to deregister ALERT callback"); + return res; + } + + return ADI_SENSE_SUCCESS; +} + +ADI_SENSE_RESULT utils_runMeasurement( + ADI_SENSE_DEVICE_HANDLE hDevice, + ADI_SENSE_MEASUREMENT_MODE eMeasurementMode) +{ + ADI_SENSE_RESULT res; + + volatile bool_t bDataReady = false; + volatile bool_t bError = false; + volatile bool_t bAlert = false; + res = utils_registerCallbacks(hDevice, &bDataReady, &bError, &bAlert); + if (res != ADI_SENSE_SUCCESS) + return res; + + /* + * Retrieve the number of samples per cycle, per DATAREADY pulse, etc. for this configuration. + */ + ADI_SENSE_1000_OPERATING_MODE eOperatingMode; + ADI_SENSE_1000_DATAREADY_MODE eDataReadyMode; + uint32_t nSamplesPerDataready; + uint32_t nSamplesPerCycle; + res = adi_sense_1000_GetDataReadyModeInfo(hDevice, + eMeasurementMode, + &eOperatingMode, + &eDataReadyMode, + &nSamplesPerDataready, + &nSamplesPerCycle); + if (res != ADI_SENSE_SUCCESS) + return res; + + /* + * Allocate a buffer to store the samples retrieved on each DATAREADY pulse + * However, if the DATAREADY pulse is per-conversion, allocate a bigger buffer + * to accumulate a full cycle of samples before printing them + */ + ADI_SENSE_DATA_SAMPLE *pSampleBuffer; + if (eDataReadyMode == ADI_SENSE_1000_DATAREADY_PER_CONVERSION) + pSampleBuffer = malloc(sizeof(ADI_SENSE_DATA_SAMPLE) * nSamplesPerCycle); + else + pSampleBuffer = malloc(sizeof(ADI_SENSE_DATA_SAMPLE) * nSamplesPerDataready); + if (pSampleBuffer == NULL) + { + ADI_SENSE_LOG_ERROR("Failed to allocate sample buffer"); + return ADI_SENSE_NO_MEM; + } + + /* + * Kick off the measurement cycle(s) here + */ + res = adi_sense_StartMeasurement(hDevice, eMeasurementMode); + if (res != ADI_SENSE_SUCCESS) + { + ADI_SENSE_LOG_ERROR("Failed to start measurement"); + return res; + } + + /* + * Loop continuously unless operating mode is single-cycle + */ + do { + ADI_SENSE_STATUS status; + uint32_t nCurrentSamples; + uint32_t nReturned; + nCurrentSamples = 0; + + /* + * Accumulate the samples from a cycle and print them + * NOTE: requires a sufficient idle time between cycles to allow printing to occur + */ + do { + /* + * Wait for the cycle to complete, continuously checking DATAREADY until it is asserted + */ + while (! (bDataReady || bError)) + ; + + if (! bError) + { + /* + * Retrieve the data samples from the measurement cycle, if no error has occurred + */ + bDataReady = false; + res = adi_sense_GetData(hDevice, eMeasurementMode, &pSampleBuffer[nCurrentSamples], nSamplesPerDataready, &nReturned); + nCurrentSamples += nReturned; + if (res != ADI_SENSE_SUCCESS) + { + if (res == ADI_SENSE_INCOMPLETE) + { + /* For this case, let's get the device status and print + * any samples we did get */ + ADI_SENSE_LOG_WARN("Failed to retrieve all requested data samples"); + break; + } + else + { + ADI_SENSE_LOG_WARN("Failed to retrieve data samples from device"); + return res; + } + } + } + } while (!bError && (nCurrentSamples < nSamplesPerCycle)); + + /* + * Display the data samples + */ + utils_printSamples(pSampleBuffer, nCurrentSamples); + //use alternative print utils + //utils_printSamples_alt(pSampleBuffer, nCurrentSamples); + //utils_printSamples_pro(pSampleBuffer, nCurrentSamples); + /* + * Check and print device status if errors/alerts have been triggered + */ + if (bError || bAlert) + { + res = adi_sense_GetStatus(hDevice, &status); + if (res != ADI_SENSE_SUCCESS) + { + ADI_SENSE_LOG_ERROR("Failed to retrieve device status"); + return res; + } + + if (status.deviceStatus & + (ADI_SENSE_DEVICE_STATUS_ERROR | ADI_SENSE_DEVICE_STATUS_ALERT)) + { + utils_printStatus(&status); + + /* Break out of the loop if any errors are raised */ + if (bError) + break; + } + } + } while (eOperatingMode != ADI_SENSE_1000_OPERATING_MODE_SINGLECYCLE); + + res = adi_sense_StopMeasurement(hDevice); + if (res != ADI_SENSE_SUCCESS) + { + ADI_SENSE_LOG_ERROR("Failed to send stop measurement"); + return res; + } + + free(pSampleBuffer); + + res = utils_deregisterCallbacks(hDevice); + if (res != ADI_SENSE_SUCCESS) + return res; + + return ADI_SENSE_SUCCESS; +} + +ADI_SENSE_RESULT utils_printCalTable( + ADI_SENSE_DEVICE_HANDLE hDevice) +{ + ADI_SENSE_RESULT res; + unsigned dataLen, nRows, nColumns, maxLen = 1024; + + float *pCalDataBuffer = malloc(maxLen); + if (pCalDataBuffer == NULL) + { + ADI_SENSE_LOG_ERROR("Failed to allocate calibration data buffer"); + return ADI_SENSE_NO_MEM; + } + + res = adi_sense_1000_ReadCalTable(hDevice, + pCalDataBuffer, maxLen, + &dataLen, &nRows, &nColumns); + if (res != ADI_SENSE_SUCCESS) + { + ADI_SENSE_LOG_ERROR("Failed to read calibration data"); + free(pCalDataBuffer); + return res; + } + + ADI_SENSE_LOG_INFO("Calibration Table:\r\n"); + ADI_SENSE_LOG_INFO("%6s| %10s | %10s | %10s |", "index", "25", "-40", "85"); + for (unsigned row = 0; row < nRows; row++) + { + ADI_SENSE_LOG_INFO("%6d| %10f | %10f | %10f |", + row, + pCalDataBuffer[(row * nColumns) + 0], + pCalDataBuffer[(row * nColumns) + 1], + pCalDataBuffer[(row * nColumns) + 2]); + } + + free(pCalDataBuffer); + return ADI_SENSE_SUCCESS; +} +
--- a/common/utils.h Thu Jan 25 16:00:23 2018 +0000 +++ b/common/utils.h Fri Aug 24 09:01:59 2018 +0000 @@ -1,46 +1,56 @@ -#ifndef __UTILS_H__ -#define __UTILS_H__ - -#include "inc/adi_sense_api.h" -#include "inc/adi_sense_1000/adi_sense_1000_api.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* Utility function to print the status read from the ADI Sense device */ -void utils_printStatus( - ADI_SENSE_STATUS *pStatus); - -/* Utility function to print data samples read from the ADI Sense device */ -void utils_printSamples( - ADI_SENSE_DATA_SAMPLE *pSampleBuffer, - uint32_t numSamples); - -/* Utility function to register callbacks for ADI Sense device notification signals */ -ADI_SENSE_RESULT utils_registerCallbacks( - ADI_SENSE_DEVICE_HANDLE hDevice, - volatile bool_t *pbDataReady, - volatile bool_t *pbError, - volatile bool_t *pbAlert); - -/* Utility function to de-register callbacks for ADI Sense device notification signals */ -ADI_SENSE_RESULT utils_deregisterCallbacks( - ADI_SENSE_DEVICE_HANDLE hDevice); - -/* Utility function to run measurements on ADI Sense device, according to its current - * configuration, and display data samples and device status following each cycle */ -ADI_SENSE_RESULT utils_runMeasurement( - ADI_SENSE_DEVICE_HANDLE hDevice, - ADI_SENSE_MEASUREMENT_MODE eMeasurementMode); - -/* Utility function to retrieve and print the factory calibration coefficients table from the ADI Sense device */ -ADI_SENSE_RESULT utils_printCalTable( - ADI_SENSE_DEVICE_HANDLE hDevice); - -#ifdef __cplusplus -} -#endif - -#endif /* __UTILS_H__ */ +#ifndef __UTILS_H__ +#define __UTILS_H__ + +#include "inc/adi_sense_api.h" +#include "inc/adi_sense_1000/adi_sense_1000_api.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Utility function to print the status read from the ADI Sense device */ +void utils_printStatus( + ADI_SENSE_STATUS *pStatus); +/* Utility function to print data samples read from the ADI Sense device */ +void utils_printSamples( + ADI_SENSE_DATA_SAMPLE *pSampleBuffer, + uint32_t numSamples); + +/* Alternative print utility */ +void utils_printSamples_alt( + ADI_SENSE_DATA_SAMPLE *pSampleBuffer, + uint32_t numSamples); + +/* Alternative print utility */ +void utils_printSamples_pro( + ADI_SENSE_DATA_SAMPLE *pSampleBuffer, + uint32_t numSamples); + +/* Utility function to register callbacks for ADI Sense device notification signals */ +ADI_SENSE_RESULT utils_registerCallbacks( + ADI_SENSE_DEVICE_HANDLE hDevice, + volatile bool_t *pbDataReady, + volatile bool_t *pbError, + volatile bool_t *pbAlert); + +/* Utility function to de-register callbacks for ADI Sense device notification signals */ +ADI_SENSE_RESULT utils_deregisterCallbacks( + ADI_SENSE_DEVICE_HANDLE hDevice); + +/* Utility function to run measurements on ADI Sense device, according to its current + * configuration, and display data samples and device status following each cycle */ +ADI_SENSE_RESULT utils_runMeasurement( + ADI_SENSE_DEVICE_HANDLE hDevice, + ADI_SENSE_MEASUREMENT_MODE eMeasurementMode); + +/* Utility function to retrieve and print the factory calibration coefficients table from the ADI Sense device */ +ADI_SENSE_RESULT utils_printCalTable( + ADI_SENSE_DEVICE_HANDLE hDevice); + +#ifdef __cplusplus +} +#endif + +#endif /* __UTILS_H__ */ +
--- a/main.cpp Thu Jan 25 16:00:23 2018 +0000 +++ b/main.cpp Fri Aug 24 09:01:59 2018 +0000 @@ -39,12 +39,16 @@ *****************************************************************************/ #include "mbed.h" #include "inc/adi_sense_api.h" -#include "inc/adi_sense_1000/adi_sense_1000_api.h" #include "inc/adi_sense_log.h" #include "common/utils.h" extern ADI_SENSE_CONFIG config; +ADI_SENSE_RESULT res; +ADI_SENSE_DEVICE_HANDLE hDevice; +ADI_SENSE_MEASUREMENT_MODE eMeasurementMode = ADI_SENSE_MEASUREMENT_MODE_NORMAL; +bool_t bDeviceReady; + /* Change the following pointer to select any of the configurations above */ static ADI_SENSE_CONFIG *pSelectedConfig = &config; @@ -65,16 +69,10 @@ }, }; -int main() +uint8_t adisense1000_boot(void) { - ADI_SENSE_RESULT res; - ADI_SENSE_DEVICE_HANDLE hDevice; - ADI_SENSE_MEASUREMENT_MODE eMeasurementMode = ADI_SENSE_MEASUREMENT_MODE_NORMAL; - bool_t bDeviceReady; + bool_t bDeviceReady; - /* - * Open an ADI Sense device instance. - */ res = adi_sense_Open(0, &connectionInfo, &hDevice); if (res != ADI_SENSE_SUCCESS) { @@ -82,9 +80,6 @@ return res; } - /* - * Reset the given ADI Sense device.... - */ ADI_SENSE_LOG_INFO("Resetting ADI Sense device, please wait..."); res = adi_sense_Reset(hDevice); if (res != ADI_SENSE_SUCCESS) @@ -92,9 +87,7 @@ ADI_SENSE_LOG_ERROR("Failed to reset device"); return res; } - /* - * ...and wait until the device is ready. - */ + do { wait_ms(100); res = adi_sense_GetDeviceReadyState(hDevice, &bDeviceReady); @@ -106,10 +99,6 @@ } while (! bDeviceReady); ADI_SENSE_LOG_INFO("ADI Sense device ready"); - /* - * Write configuration settings to the device registers. - * Settings are not applied until adi_sense_ApplyConfigUpdates() is called. - */ ADI_SENSE_LOG_INFO("Setting device configuration"); res = adi_sense_SetConfig(hDevice, pSelectedConfig); if (res != ADI_SENSE_SUCCESS) @@ -123,23 +112,36 @@ ADI_SENSE_LOG_ERROR("Failed to apply device configuration"); return res; } - - /* - * Kick off the measurement cycle here - */ - ADI_SENSE_LOG_INFO("Configuration completed, starting measurement cycles"); - utils_runMeasurement(hDevice, eMeasurementMode); - - /* - * Clean up and exit - */ - res = adi_sense_Close(hDevice); - if (res != ADI_SENSE_SUCCESS) - { - ADI_SENSE_LOG_ERROR("Failed to close device instance"); - return res; - } - return 0; } +void blink_led() +{ + DigitalOut led1(LED1); + int i=0; + for(i=0; i<10; i++) { + led1 = !led1; + wait(0.5); + } +} + +int main() +{ + wait(0.5); + blink_led(); + + adisense1000_boot(); + ADI_SENSE_LOG_INFO("Configuration Set Success"); + wait(0.5); + + ADI_SENSE_LOG_INFO("~ Get Data\n\r"); + + //temp_comp temp pressure himidity AccX AccY AccZ + + ADI_SENSE_LOG_INFO("tc_raw\ttc_pro\tt_raw\tt_pro\tp_raw\tp_pro\th_raw\th_pro\tax_raw\tax_pro\tay_raw\tay_pro\taz_raw\taz_pro"); + //ADI_SENSE_LOG_INFO("tc_pro t_pro h_pro ax_pro ay_pro az_pro"); + + utils_runMeasurement(hDevice, eMeasurementMode); + +} +