ADISense1000 Version 2.1 code base

Fork of AdiSense1000_V21 by Sean Wilson

Committer:
kevin1990
Date:
Tue Nov 28 11:22:24 2017 +0000
Revision:
14:81f059dc75d0
Parent:
13:176ca4f0ca20
Child:
15:78f3f517417f
Rename config file

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kevin1990 13:176ca4f0ca20 1 /*
kevin1990 13:176ca4f0ca20 2 ******************************************************************************
kevin1990 13:176ca4f0ca20 3 * file: main.cpp
kevin1990 13:176ca4f0ca20 4 *-----------------------------------------------------------------------------
kevin1990 13:176ca4f0ca20 5 *
kevin1990 13:176ca4f0ca20 6 Copyright (c) 2017 Emutex Ltd. / Analog Devices, Inc.
kevin1990 13:176ca4f0ca20 7
kevin1990 13:176ca4f0ca20 8 All rights reserved.
kevin1990 13:176ca4f0ca20 9
kevin1990 13:176ca4f0ca20 10 Redistribution and use in source and binary forms, with or without modification,
kevin1990 13:176ca4f0ca20 11 are permitted provided that the following conditions are met:
kevin1990 13:176ca4f0ca20 12 - Redistributions of source code must retain the above copyright notice,
kevin1990 13:176ca4f0ca20 13 this list of conditions and the following disclaimer.
kevin1990 13:176ca4f0ca20 14 - Redistributions in binary form must reproduce the above copyright notice,
kevin1990 13:176ca4f0ca20 15 this list of conditions and the following disclaimer in the documentation
kevin1990 13:176ca4f0ca20 16 and/or other materials provided with the distribution.
kevin1990 13:176ca4f0ca20 17 - Modified versions of the software must be conspicuously marked as such.
kevin1990 13:176ca4f0ca20 18 - This software is licensed solely and exclusively for use with processors
kevin1990 13:176ca4f0ca20 19 manufactured by or for Analog Devices, Inc.
kevin1990 13:176ca4f0ca20 20 - This software may not be combined or merged with other code in any manner
kevin1990 13:176ca4f0ca20 21 that would cause the software to become subject to terms and conditions
kevin1990 13:176ca4f0ca20 22 which differ from those listed here.
kevin1990 13:176ca4f0ca20 23 - Neither the name of Analog Devices, Inc. nor the names of its
kevin1990 13:176ca4f0ca20 24 contributors may be used to endorse or promote products derived
kevin1990 13:176ca4f0ca20 25 from this software without specific prior written permission.
kevin1990 13:176ca4f0ca20 26 - The use of this software may or may not infringe the patent rights of one
kevin1990 13:176ca4f0ca20 27 or more patent holders. This license does not release you from the
kevin1990 13:176ca4f0ca20 28 requirement that you obtain separate licenses from these patent holders
kevin1990 13:176ca4f0ca20 29 to use this software.
kevin1990 13:176ca4f0ca20 30
kevin1990 13:176ca4f0ca20 31 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND ANY
kevin1990 13:176ca4f0ca20 32 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
kevin1990 13:176ca4f0ca20 33 TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
kevin1990 13:176ca4f0ca20 34 NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
kevin1990 13:176ca4f0ca20 35 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES
kevin1990 13:176ca4f0ca20 36 (INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL
kevin1990 13:176ca4f0ca20 37 PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
kevin1990 13:176ca4f0ca20 38 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
kevin1990 13:176ca4f0ca20 39 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
kevin1990 13:176ca4f0ca20 40 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
kevin1990 13:176ca4f0ca20 41 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
kevin1990 13:176ca4f0ca20 42 *
kevin1990 13:176ca4f0ca20 43 *****************************************************************************/
kevin1990 13:176ca4f0ca20 44 #include "mbed.h"
kevin1990 13:176ca4f0ca20 45 #include "inc/adi_sense_api.h"
kevin1990 13:176ca4f0ca20 46 #include "inc/adi_sense_1000/adi_sense_1000_api.h"
kevin1990 13:176ca4f0ca20 47 #include "inc/adi_sense_log.h"
kevin1990 13:176ca4f0ca20 48 #include "common/utils.h"
kevin1990 13:176ca4f0ca20 49
kevin1990 13:176ca4f0ca20 50 extern ADI_SENSE_CONFIG sensor0_rtd_2w_pt100_config;
kevin1990 14:81f059dc75d0 51 extern ADI_SENSE_CONFIG sensor0_rtd_2w_pt100_unity_lut_config;
kevin1990 13:176ca4f0ca20 52 extern ADI_SENSE_CONFIG sensor1_typeK_cjc1_config;
kevin1990 13:176ca4f0ca20 53 extern ADI_SENSE_CONFIG sensor1_rtd_3w_pt100_config;
kevin1990 13:176ca4f0ca20 54 extern ADI_SENSE_CONFIG sensor2_typeT_cjc0_config;
kevin1990 13:176ca4f0ca20 55 extern ADI_SENSE_CONFIG sensor2_bridge_6w_pressure_config;
kevin1990 13:176ca4f0ca20 56 extern ADI_SENSE_CONFIG sensor3_typeJ_cjc0_config;
kevin1990 13:176ca4f0ca20 57 extern ADI_SENSE_CONFIG sensor3_thermistor_10k_ntc_config;
kevin1990 13:176ca4f0ca20 58 extern ADI_SENSE_CONFIG voltage_honeywellPressure_config;
kevin1990 13:176ca4f0ca20 59 extern ADI_SENSE_CONFIG current_honeywellPressure_config;
kevin1990 13:176ca4f0ca20 60 extern ADI_SENSE_CONFIG i2c0_honeywellHumidicon_config;
kevin1990 13:176ca4f0ca20 61 extern ADI_SENSE_CONFIG i2c0_sensirionSHT3X_config;
kevin1990 13:176ca4f0ca20 62 extern ADI_SENSE_CONFIG spi0_honeywellTrustability_config;
kevin1990 13:176ca4f0ca20 63 extern ADI_SENSE_CONFIG spi0_adiAdxl362_config;
kevin1990 13:176ca4f0ca20 64 extern ADI_SENSE_CONFIG multichannel_continuous_config;
kevin1990 13:176ca4f0ca20 65 extern ADI_SENSE_CONFIG multichannel_multicycle_config;
kevin1990 13:176ca4f0ca20 66 extern ADI_SENSE_CONFIG multichannel_singlecycle_config;
kevin1990 13:176ca4f0ca20 67
kevin1990 13:176ca4f0ca20 68 /* Change the following pointer to select any of the configurations above */
kevin1990 13:176ca4f0ca20 69 static ADI_SENSE_CONFIG *pSelectedConfig = &sensor0_rtd_2w_pt100_config;
kevin1990 12:97457cf77bcb 70
kevin1990 13:176ca4f0ca20 71 static ADI_SENSE_CONNECTION connectionInfo = {
kevin1990 13:176ca4f0ca20 72 .type = ADI_SENSE_CONNECTION_TYPE_SPI,
kevin1990 13:176ca4f0ca20 73 .spi = {
kevin1990 13:176ca4f0ca20 74 .mosiPin = SPI_MOSI,
kevin1990 13:176ca4f0ca20 75 .misoPin = SPI_MISO,
kevin1990 13:176ca4f0ca20 76 .sckPin = SPI_SCK,
kevin1990 13:176ca4f0ca20 77 .csPin = D10,
kevin1990 13:176ca4f0ca20 78 .maxSpeedHz = 2000000,
kevin1990 13:176ca4f0ca20 79 },
kevin1990 13:176ca4f0ca20 80 .gpio = {
kevin1990 13:176ca4f0ca20 81 .resetPin = D6,
kevin1990 13:176ca4f0ca20 82 .errorPin = D3,
kevin1990 13:176ca4f0ca20 83 .alertPin = D4,
kevin1990 13:176ca4f0ca20 84 .datareadyPin = D5,
kevin1990 13:176ca4f0ca20 85 },
kevin1990 13:176ca4f0ca20 86 };
kevin1990 13:176ca4f0ca20 87
kevin1990 13:176ca4f0ca20 88 int main()
kevin1990 13:176ca4f0ca20 89 {
kevin1990 13:176ca4f0ca20 90 ADI_SENSE_RESULT res;
kevin1990 13:176ca4f0ca20 91 ADI_SENSE_DEVICE_HANDLE hDevice;
kevin1990 13:176ca4f0ca20 92 bool_t bHealthCheckMode = false;
kevin1990 13:176ca4f0ca20 93 bool_t bDeviceReady;
kevin1990 13:176ca4f0ca20 94
kevin1990 13:176ca4f0ca20 95 /*
kevin1990 13:176ca4f0ca20 96 * Open an ADI Sense device instance.
kevin1990 13:176ca4f0ca20 97 */
kevin1990 13:176ca4f0ca20 98 res = adi_sense_Open(0, &connectionInfo, &hDevice);
kevin1990 13:176ca4f0ca20 99 if (res != ADI_SENSE_SUCCESS)
kevin1990 13:176ca4f0ca20 100 {
kevin1990 13:176ca4f0ca20 101 ADI_SENSE_LOG_ERROR("Failed to open device instance");
kevin1990 13:176ca4f0ca20 102 return res;
kevin1990 13:176ca4f0ca20 103 }
kevin1990 13:176ca4f0ca20 104
kevin1990 13:176ca4f0ca20 105 /*
kevin1990 13:176ca4f0ca20 106 * Reset the given ADI Sense device....
kevin1990 13:176ca4f0ca20 107 */
kevin1990 13:176ca4f0ca20 108 ADI_SENSE_LOG_INFO("Resetting ADI Sense device, please wait...");
kevin1990 13:176ca4f0ca20 109 res = adi_sense_Reset(hDevice);
kevin1990 13:176ca4f0ca20 110 if (res != ADI_SENSE_SUCCESS)
kevin1990 13:176ca4f0ca20 111 {
kevin1990 13:176ca4f0ca20 112 ADI_SENSE_LOG_ERROR("Failed to reset device");
kevin1990 13:176ca4f0ca20 113 return res;
kevin1990 13:176ca4f0ca20 114 }
kevin1990 13:176ca4f0ca20 115 /*
kevin1990 13:176ca4f0ca20 116 * ...and wait until the device is ready.
kevin1990 13:176ca4f0ca20 117 */
kevin1990 13:176ca4f0ca20 118 do {
kevin1990 13:176ca4f0ca20 119 wait_ms(100);
kevin1990 13:176ca4f0ca20 120 res = adi_sense_GetDeviceReadyState(hDevice, &bDeviceReady);
kevin1990 13:176ca4f0ca20 121 if (res != ADI_SENSE_SUCCESS)
kevin1990 13:176ca4f0ca20 122 {
kevin1990 13:176ca4f0ca20 123 ADI_SENSE_LOG_ERROR("Failed to get device ready-state");
kevin1990 13:176ca4f0ca20 124 return res;
kevin1990 13:176ca4f0ca20 125 }
kevin1990 13:176ca4f0ca20 126 } while (! bDeviceReady);
kevin1990 13:176ca4f0ca20 127 ADI_SENSE_LOG_INFO("ADI Sense device ready");
kevin1990 13:176ca4f0ca20 128
kevin1990 13:176ca4f0ca20 129 /*
kevin1990 13:176ca4f0ca20 130 * Write configuration settings to the device registers.
kevin1990 13:176ca4f0ca20 131 * Settings are not applied until adi_sense_ApplyConfigUpdates() is called.
kevin1990 13:176ca4f0ca20 132 */
kevin1990 13:176ca4f0ca20 133 ADI_SENSE_LOG_INFO("Setting device configuration");
kevin1990 13:176ca4f0ca20 134 res = adi_sense_SetConfig(hDevice, pSelectedConfig);
kevin1990 13:176ca4f0ca20 135 if (res != ADI_SENSE_SUCCESS)
kevin1990 13:176ca4f0ca20 136 {
kevin1990 13:176ca4f0ca20 137 ADI_SENSE_LOG_ERROR("Failed to set device configuration");
kevin1990 13:176ca4f0ca20 138 return res;
kevin1990 13:176ca4f0ca20 139 }
kevin1990 13:176ca4f0ca20 140 res = adi_sense_ApplyConfigUpdates(hDevice);
kevin1990 13:176ca4f0ca20 141 if (res != ADI_SENSE_SUCCESS)
kevin1990 13:176ca4f0ca20 142 {
kevin1990 13:176ca4f0ca20 143 ADI_SENSE_LOG_ERROR("Failed to apply device configuration");
kevin1990 13:176ca4f0ca20 144 return res;
kevin1990 13:176ca4f0ca20 145 }
kevin1990 13:176ca4f0ca20 146
kevin1990 13:176ca4f0ca20 147 /*
kevin1990 13:176ca4f0ca20 148 * Kick off the measurement cycle here
kevin1990 13:176ca4f0ca20 149 */
kevin1990 13:176ca4f0ca20 150 ADI_SENSE_LOG_INFO("Configuration completed, starting measurement cycles");
kevin1990 13:176ca4f0ca20 151 utils_runMeasurement(hDevice, bHealthCheckMode);
kevin1990 13:176ca4f0ca20 152
kevin1990 13:176ca4f0ca20 153 /*
kevin1990 13:176ca4f0ca20 154 * Clean up and exit
kevin1990 13:176ca4f0ca20 155 */
kevin1990 13:176ca4f0ca20 156 res = adi_sense_Close(hDevice);
kevin1990 13:176ca4f0ca20 157 if (res != ADI_SENSE_SUCCESS)
kevin1990 13:176ca4f0ca20 158 {
kevin1990 13:176ca4f0ca20 159 ADI_SENSE_LOG_ERROR("Failed to close device instance");
kevin1990 13:176ca4f0ca20 160 return res;
kevin1990 13:176ca4f0ca20 161 }
kevin1990 13:176ca4f0ca20 162
kevin1990 13:176ca4f0ca20 163 return 0;
kevin1990 13:176ca4f0ca20 164 }