Test, please delete

Committer:
Dan O'Donovan
Date:
Tue Jun 12 21:27:34 2018 +0100
Branch:
v2.0
Revision:
30:119ff4f3aef6
Parent:
29:57edca10d78c
Child:
31:de49744b57a6
Adding host library and example code for v2.0 release to v2.0 branch

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kevin1990 15:78f3f517417f 1 /*
Dan O'Donovan 27:567abf893938 2 CONFIDENTIAL AND PROPRIETARY INFORMATION
Dan O'Donovan 27:567abf893938 3
Dan O'Donovan 27:567abf893938 4 Copyright (c) 2018 Emutex Ltd. All rights reserved.
Dan O'Donovan 27:567abf893938 5 This software and documentation contain confidential and
Dan O'Donovan 27:567abf893938 6 proprietary information that is the property of
Dan O'Donovan 27:567abf893938 7 Emutex Ltd. The software and documentation are
Dan O'Donovan 27:567abf893938 8 furnished under a license agreement and may be used
Dan O'Donovan 27:567abf893938 9 or copied only in accordance with the terms of the license
Dan O'Donovan 27:567abf893938 10 agreement. No part of the software and documentation
Dan O'Donovan 27:567abf893938 11 may be reproduced, transmitted, or translated, in any
Dan O'Donovan 27:567abf893938 12 form or by any means, electronic, mechanical, manual,
Dan O'Donovan 27:567abf893938 13 optical, or otherwise, without prior written permission
Dan O'Donovan 27:567abf893938 14 of Emutex Ltd., or as expressly provided by the license agreement.
Dan O'Donovan 27:567abf893938 15 Reverse engineering is prohibited, and reproduction,
Dan O'Donovan 27:567abf893938 16 disclosure or use without specific written authorization
Dan O'Donovan 27:567abf893938 17 of Emutex Ltd. is strictly forbidden.
kevin1990 15:78f3f517417f 18 *
danodonovan 23:2adb6216b001 19 Copyright 2017 (c) Analog Devices, Inc.
kevin1990 15:78f3f517417f 20
kevin1990 15:78f3f517417f 21 All rights reserved.
kevin1990 15:78f3f517417f 22
danodonovan 23:2adb6216b001 23 Redistribution and use in source and binary forms, with or without
danodonovan 23:2adb6216b001 24 modification, are permitted provided that the following conditions are met:
danodonovan 23:2adb6216b001 25 - Redistributions of source code must retain the above copyright
danodonovan 23:2adb6216b001 26 notice, this list of conditions and the following disclaimer.
danodonovan 23:2adb6216b001 27 - Redistributions in binary form must reproduce the above copyright
danodonovan 23:2adb6216b001 28 notice, this list of conditions and the following disclaimer in
danodonovan 23:2adb6216b001 29 the documentation and/or other materials provided with the
danodonovan 23:2adb6216b001 30 distribution.
kevin1990 15:78f3f517417f 31 - Neither the name of Analog Devices, Inc. nor the names of its
kevin1990 15:78f3f517417f 32 contributors may be used to endorse or promote products derived
kevin1990 15:78f3f517417f 33 from this software without specific prior written permission.
danodonovan 23:2adb6216b001 34 - The use of this software may or may not infringe the patent rights
danodonovan 23:2adb6216b001 35 of one or more patent holders. This license does not release you
danodonovan 23:2adb6216b001 36 from the requirement that you obtain separate licenses from these
danodonovan 23:2adb6216b001 37 patent holders to use this software.
danodonovan 23:2adb6216b001 38 - Use of the software either in source or binary form, must be run
danodonovan 23:2adb6216b001 39 on or directly connected to an Analog Devices Inc. component.
kevin1990 15:78f3f517417f 40
danodonovan 23:2adb6216b001 41 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
danodonovan 23:2adb6216b001 42 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
danodonovan 23:2adb6216b001 43 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
danodonovan 23:2adb6216b001 44 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
danodonovan 23:2adb6216b001 45 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
danodonovan 23:2adb6216b001 46 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
danodonovan 23:2adb6216b001 47 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
danodonovan 23:2adb6216b001 48 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
danodonovan 23:2adb6216b001 49 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
danodonovan 23:2adb6216b001 50 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
kevin1990 15:78f3f517417f 51 *
kevin1990 15:78f3f517417f 52 *****************************************************************************/
Dan O'Donovan 27:567abf893938 53 /*!
Dan O'Donovan 27:567abf893938 54 ******************************************************************************
Dan O'Donovan 27:567abf893938 55 * @file:
Dan O'Donovan 27:567abf893938 56 *-----------------------------------------------------------------------------
Dan O'Donovan 27:567abf893938 57 *
Dan O'Donovan 27:567abf893938 58 */
kevin1990 15:78f3f517417f 59 #include "mbed.h"
kevin1990 15:78f3f517417f 60 #include "inc/adi_sense_api.h"
kevin1990 15:78f3f517417f 61 #include "inc/adi_sense_1000/adi_sense_1000_api.h"
kevin1990 15:78f3f517417f 62 #include "inc/adi_sense_log.h"
kevin1990 15:78f3f517417f 63 #include "common/utils.h"
kevin1990 15:78f3f517417f 64
kevin1990 29:57edca10d78c 65 extern ADI_SENSE_CONFIG cjc0_thermistor_10k_ntc_config;
kevin1990 15:78f3f517417f 66 extern ADI_SENSE_CONFIG sensor0_rtd_2w_pt100_config;
Dan O'Donovan 27:567abf893938 67 extern ADI_SENSE_CONFIG sensor0_microphone_config;
Dan O'Donovan 27:567abf893938 68 extern ADI_SENSE_CONFIG sensor0_diode_2c_config;
kevin1990 15:78f3f517417f 69 extern ADI_SENSE_CONFIG sensor1_typeK_cjc1_config;
kevin1990 15:78f3f517417f 70 extern ADI_SENSE_CONFIG sensor1_rtd_3w_pt100_config;
Dan O'Donovan 27:567abf893938 71 extern ADI_SENSE_CONFIG sensor1_diode_3c_config;
kevin1990 15:78f3f517417f 72 extern ADI_SENSE_CONFIG sensor2_typeT_cjc0_config;
kevin1990 15:78f3f517417f 73 extern ADI_SENSE_CONFIG sensor2_bridge_6w_pressure_config;
kevin1990 15:78f3f517417f 74 extern ADI_SENSE_CONFIG sensor3_typeJ_cjc0_config;
kevin1990 15:78f3f517417f 75 extern ADI_SENSE_CONFIG sensor3_thermistor_10k_ntc_config;
kevin1990 15:78f3f517417f 76 extern ADI_SENSE_CONFIG voltage_honeywellPressure_config;
kevin1990 15:78f3f517417f 77 extern ADI_SENSE_CONFIG current_honeywellPressure_config;
kevin1990 15:78f3f517417f 78 extern ADI_SENSE_CONFIG i2c0_honeywellHumidicon_config;
kevin1990 15:78f3f517417f 79 extern ADI_SENSE_CONFIG i2c0_sensirionSHT3X_config;
Dan O'Donovan 27:567abf893938 80 extern ADI_SENSE_CONFIG i2c0_onsemiNOA1305_config;
kevin1990 15:78f3f517417f 81 extern ADI_SENSE_CONFIG spi0_honeywellTrustability_config;
kevin1990 15:78f3f517417f 82 extern ADI_SENSE_CONFIG spi0_adiAdxl362_config;
Dan O'Donovan 27:567abf893938 83 extern ADI_SENSE_CONFIG spi0_adiAdxl355_config;
kevin1990 29:57edca10d78c 84 extern ADI_SENSE_CONFIG uart_cozirCO2_config;
kevin1990 15:78f3f517417f 85 extern ADI_SENSE_CONFIG multichannel_continuous_config;
kevin1990 15:78f3f517417f 86 extern ADI_SENSE_CONFIG multichannel_multicycle_config;
kevin1990 15:78f3f517417f 87 extern ADI_SENSE_CONFIG multichannel_singlecycle_config;
kevin1990 15:78f3f517417f 88
kevin1990 15:78f3f517417f 89 /* Change the following pointer to select any of the configurations above */
kevin1990 15:78f3f517417f 90 static ADI_SENSE_CONFIG *pSelectedConfig = &sensor0_rtd_2w_pt100_config;
kevin1990 15:78f3f517417f 91
kevin1990 15:78f3f517417f 92 static ADI_SENSE_CONNECTION connectionInfo = {
kevin1990 15:78f3f517417f 93 .type = ADI_SENSE_CONNECTION_TYPE_SPI,
kevin1990 15:78f3f517417f 94 .spi = {
kevin1990 15:78f3f517417f 95 .mosiPin = SPI_MOSI,
kevin1990 15:78f3f517417f 96 .misoPin = SPI_MISO,
kevin1990 15:78f3f517417f 97 .sckPin = SPI_SCK,
kevin1990 15:78f3f517417f 98 .csPin = D10,
kevin1990 15:78f3f517417f 99 .maxSpeedHz = 2000000,
kevin1990 15:78f3f517417f 100 },
kevin1990 15:78f3f517417f 101 .gpio = {
kevin1990 15:78f3f517417f 102 .resetPin = D6,
kevin1990 15:78f3f517417f 103 .errorPin = D3,
kevin1990 15:78f3f517417f 104 .alertPin = D4,
kevin1990 15:78f3f517417f 105 .datareadyPin = D5,
kevin1990 15:78f3f517417f 106 },
kevin1990 29:57edca10d78c 107 .log = {
kevin1990 29:57edca10d78c 108 .txPin = PA_11,
kevin1990 29:57edca10d78c 109 .rxPin = PA_12,
kevin1990 29:57edca10d78c 110 .baudRate = 115200,
kevin1990 29:57edca10d78c 111 .disableLogs = false,
kevin1990 29:57edca10d78c 112 },
kevin1990 15:78f3f517417f 113 };
kevin1990 15:78f3f517417f 114
kevin1990 15:78f3f517417f 115 int main()
kevin1990 15:78f3f517417f 116 {
kevin1990 15:78f3f517417f 117 ADI_SENSE_RESULT res;
Dan O'Donovan 27:567abf893938 118 ADI_SENSE_STATUS status;
kevin1990 15:78f3f517417f 119 ADI_SENSE_DEVICE_HANDLE hDevice;
kevin1990 15:78f3f517417f 120 ADI_SENSE_MEASUREMENT_MODE eMeasurementMode = ADI_SENSE_MEASUREMENT_MODE_NORMAL;
Dan O'Donovan 30:119ff4f3aef6 121 bool bDeviceReady;
kevin1990 15:78f3f517417f 122
kevin1990 15:78f3f517417f 123 /*
kevin1990 15:78f3f517417f 124 * Open an ADI Sense device instance.
kevin1990 15:78f3f517417f 125 */
kevin1990 15:78f3f517417f 126 res = adi_sense_Open(0, &connectionInfo, &hDevice);
kevin1990 15:78f3f517417f 127 if (res != ADI_SENSE_SUCCESS)
kevin1990 15:78f3f517417f 128 {
kevin1990 15:78f3f517417f 129 ADI_SENSE_LOG_ERROR("Failed to open device instance");
kevin1990 15:78f3f517417f 130 return res;
kevin1990 15:78f3f517417f 131 }
kevin1990 15:78f3f517417f 132
kevin1990 15:78f3f517417f 133 /*
kevin1990 15:78f3f517417f 134 * Reset the given ADI Sense device....
kevin1990 15:78f3f517417f 135 */
kevin1990 15:78f3f517417f 136 ADI_SENSE_LOG_INFO("Resetting ADI Sense device, please wait...");
kevin1990 15:78f3f517417f 137 res = adi_sense_Reset(hDevice);
kevin1990 15:78f3f517417f 138 if (res != ADI_SENSE_SUCCESS)
kevin1990 15:78f3f517417f 139 {
kevin1990 15:78f3f517417f 140 ADI_SENSE_LOG_ERROR("Failed to reset device");
kevin1990 15:78f3f517417f 141 return res;
kevin1990 15:78f3f517417f 142 }
kevin1990 15:78f3f517417f 143 /*
kevin1990 15:78f3f517417f 144 * ...and wait until the device is ready.
kevin1990 15:78f3f517417f 145 */
kevin1990 15:78f3f517417f 146 do {
kevin1990 15:78f3f517417f 147 wait_ms(100);
kevin1990 15:78f3f517417f 148 res = adi_sense_GetDeviceReadyState(hDevice, &bDeviceReady);
kevin1990 15:78f3f517417f 149 if (res != ADI_SENSE_SUCCESS)
kevin1990 15:78f3f517417f 150 {
kevin1990 15:78f3f517417f 151 ADI_SENSE_LOG_ERROR("Failed to get device ready-state");
kevin1990 15:78f3f517417f 152 return res;
kevin1990 15:78f3f517417f 153 }
kevin1990 15:78f3f517417f 154 } while (! bDeviceReady);
kevin1990 15:78f3f517417f 155 ADI_SENSE_LOG_INFO("ADI Sense device ready");
kevin1990 15:78f3f517417f 156
kevin1990 15:78f3f517417f 157 /*
kevin1990 15:78f3f517417f 158 * Write configuration settings to the device registers.
kevin1990 15:78f3f517417f 159 * Settings are not applied until adi_sense_ApplyConfigUpdates() is called.
kevin1990 15:78f3f517417f 160 */
kevin1990 15:78f3f517417f 161 ADI_SENSE_LOG_INFO("Setting device configuration");
kevin1990 15:78f3f517417f 162 res = adi_sense_SetConfig(hDevice, pSelectedConfig);
kevin1990 15:78f3f517417f 163 if (res != ADI_SENSE_SUCCESS)
kevin1990 15:78f3f517417f 164 {
kevin1990 15:78f3f517417f 165 ADI_SENSE_LOG_ERROR("Failed to set device configuration");
kevin1990 15:78f3f517417f 166 return res;
kevin1990 15:78f3f517417f 167 }
kevin1990 15:78f3f517417f 168 res = adi_sense_ApplyConfigUpdates(hDevice);
kevin1990 15:78f3f517417f 169 if (res != ADI_SENSE_SUCCESS)
kevin1990 15:78f3f517417f 170 {
kevin1990 15:78f3f517417f 171 ADI_SENSE_LOG_ERROR("Failed to apply device configuration");
kevin1990 15:78f3f517417f 172 return res;
kevin1990 15:78f3f517417f 173 }
Dan O'Donovan 27:567abf893938 174 /*
Dan O'Donovan 27:567abf893938 175 * Check device status after updating the configuration
Dan O'Donovan 27:567abf893938 176 */
Dan O'Donovan 27:567abf893938 177 res = adi_sense_GetStatus(hDevice, &status);
Dan O'Donovan 27:567abf893938 178 if (res != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 179 {
Dan O'Donovan 27:567abf893938 180 ADI_SENSE_LOG_ERROR("Failed to retrieve device status");
Dan O'Donovan 27:567abf893938 181 return res;
Dan O'Donovan 27:567abf893938 182 }
Dan O'Donovan 27:567abf893938 183 if (status.deviceStatus &
Dan O'Donovan 27:567abf893938 184 (ADI_SENSE_DEVICE_STATUS_ERROR | ADI_SENSE_DEVICE_STATUS_ALERT))
Dan O'Donovan 27:567abf893938 185 {
Dan O'Donovan 27:567abf893938 186 utils_printStatus(&status);
Dan O'Donovan 27:567abf893938 187 }
kevin1990 15:78f3f517417f 188
kevin1990 15:78f3f517417f 189 /*
kevin1990 15:78f3f517417f 190 * Kick off the measurement cycle here
kevin1990 15:78f3f517417f 191 */
kevin1990 15:78f3f517417f 192 ADI_SENSE_LOG_INFO("Configuration completed, starting measurement cycles");
kevin1990 15:78f3f517417f 193 utils_runMeasurement(hDevice, eMeasurementMode);
kevin1990 15:78f3f517417f 194
kevin1990 15:78f3f517417f 195 /*
kevin1990 15:78f3f517417f 196 * Clean up and exit
kevin1990 15:78f3f517417f 197 */
kevin1990 15:78f3f517417f 198 res = adi_sense_Close(hDevice);
kevin1990 15:78f3f517417f 199 if (res != ADI_SENSE_SUCCESS)
kevin1990 15:78f3f517417f 200 {
kevin1990 15:78f3f517417f 201 ADI_SENSE_LOG_ERROR("Failed to close device instance");
kevin1990 15:78f3f517417f 202 return res;
kevin1990 15:78f3f517417f 203 }
kevin1990 15:78f3f517417f 204
kevin1990 15:78f3f517417f 205 return 0;
kevin1990 15:78f3f517417f 206 }