Host API Example for the ADMW1001

Committer:
Vkadaba
Date:
Mon Jul 15 13:04:34 2019 +0000
Revision:
11:8e6023d2e584
Parent:
10:14954555be2a
sensor2_bridge_4w_load_cell_config.c file is updated and able to download the bin file .

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ADIJake 0:85855ecd3257 1 /*
ADIJake 0:85855ecd3257 2 Copyright 2018 (c) Analog Devices, Inc.
ADIJake 0:85855ecd3257 3
ADIJake 0:85855ecd3257 4 All rights reserved.
ADIJake 0:85855ecd3257 5
ADIJake 0:85855ecd3257 6 Redistribution and use in source and binary forms, with or without
ADIJake 0:85855ecd3257 7 modification, are permitted provided that the following conditions are met:
ADIJake 0:85855ecd3257 8 - Redistributions of source code must retain the above copyright
ADIJake 0:85855ecd3257 9 notice, this list of conditions and the following disclaimer.
ADIJake 0:85855ecd3257 10 - Redistributions in binary form must reproduce the above copyright
ADIJake 0:85855ecd3257 11 notice, this list of conditions and the following disclaimer in
ADIJake 0:85855ecd3257 12 the documentation and/or other materials provided with the
ADIJake 0:85855ecd3257 13 distribution.
ADIJake 0:85855ecd3257 14 - Neither the name of Analog Devices, Inc. nor the names of its
ADIJake 0:85855ecd3257 15 contributors may be used to endorse or promote products derived
ADIJake 0:85855ecd3257 16 from this software without specific prior written permission.
ADIJake 0:85855ecd3257 17 - The use of this software may or may not infringe the patent rights
ADIJake 0:85855ecd3257 18 of one or more patent holders. This license does not release you
ADIJake 0:85855ecd3257 19 from the requirement that you obtain separate licenses from these
ADIJake 0:85855ecd3257 20 patent holders to use this software.
ADIJake 0:85855ecd3257 21 - Use of the software either in source or binary form, must be run
ADIJake 0:85855ecd3257 22 on or directly connected to an Analog Devices Inc. component.
ADIJake 0:85855ecd3257 23
ADIJake 0:85855ecd3257 24 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
ADIJake 0:85855ecd3257 25 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
ADIJake 0:85855ecd3257 26 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
ADIJake 0:85855ecd3257 27 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
ADIJake 0:85855ecd3257 28 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
ADIJake 0:85855ecd3257 29 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
ADIJake 0:85855ecd3257 30 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
ADIJake 0:85855ecd3257 31 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
ADIJake 0:85855ecd3257 32 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
ADIJake 0:85855ecd3257 33 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ADIJake 0:85855ecd3257 34 *
ADIJake 0:85855ecd3257 35 Copyright 2017 (c) Analog Devices, Inc.
ADIJake 0:85855ecd3257 36
ADIJake 0:85855ecd3257 37 All rights reserved.
ADIJake 0:85855ecd3257 38
ADIJake 0:85855ecd3257 39 Redistribution and use in source and binary forms, with or without
ADIJake 0:85855ecd3257 40 modification, are permitted provided that the following conditions are met:
ADIJake 0:85855ecd3257 41 - Redistributions of source code must retain the above copyright
ADIJake 0:85855ecd3257 42 notice, this list of conditions and the following disclaimer.
ADIJake 0:85855ecd3257 43 - Redistributions in binary form must reproduce the above copyright
ADIJake 0:85855ecd3257 44 notice, this list of conditions and the following disclaimer in
ADIJake 0:85855ecd3257 45 the documentation and/or other materials provided with the
ADIJake 0:85855ecd3257 46 distribution.
ADIJake 0:85855ecd3257 47 - Neither the name of Analog Devices, Inc. nor the names of its
ADIJake 0:85855ecd3257 48 contributors may be used to endorse or promote products derived
ADIJake 0:85855ecd3257 49 from this software without specific prior written permission.
ADIJake 0:85855ecd3257 50 - The use of this software may or may not infringe the patent rights
ADIJake 0:85855ecd3257 51 of one or more patent holders. This license does not release you
ADIJake 0:85855ecd3257 52 from the requirement that you obtain separate licenses from these
ADIJake 0:85855ecd3257 53 patent holders to use this software.
ADIJake 0:85855ecd3257 54 - Use of the software either in source or binary form, must be run
ADIJake 0:85855ecd3257 55 on or directly connected to an Analog Devices Inc. component.
ADIJake 0:85855ecd3257 56
ADIJake 0:85855ecd3257 57 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
ADIJake 0:85855ecd3257 58 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
ADIJake 0:85855ecd3257 59 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
ADIJake 0:85855ecd3257 60 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
ADIJake 0:85855ecd3257 61 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
ADIJake 0:85855ecd3257 62 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
ADIJake 0:85855ecd3257 63 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
ADIJake 0:85855ecd3257 64 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
ADIJake 0:85855ecd3257 65 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
ADIJake 0:85855ecd3257 66 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ADIJake 0:85855ecd3257 67 *
ADIJake 0:85855ecd3257 68 *****************************************************************************/
ADIJake 0:85855ecd3257 69 /*!
ADIJake 0:85855ecd3257 70 ******************************************************************************
ADIJake 0:85855ecd3257 71 * @file:
ADIJake 0:85855ecd3257 72 *-----------------------------------------------------------------------------
ADIJake 0:85855ecd3257 73 *
ADIJake 0:85855ecd3257 74 */
ADIJake 0:85855ecd3257 75 #include "mbed.h"
Vkadaba 5:0728bde67bdb 76 #include "admw_api.h"
Vkadaba 5:0728bde67bdb 77 #include "admw1001/admw1001_api.h"
Vkadaba 5:0728bde67bdb 78 #include "admw_log.h"
ADIJake 0:85855ecd3257 79 #include "common/utils.h"
ADIJake 0:85855ecd3257 80 #include "common/platform.h"
ADIJake 0:85855ecd3257 81
Vkadaba 5:0728bde67bdb 82
Vkadaba 5:0728bde67bdb 83
Vkadaba 5:0728bde67bdb 84
Vkadaba 5:0728bde67bdb 85 extern ADMW_CONFIG sensor0_typeK_cjc0_config;
Vkadaba 5:0728bde67bdb 86 extern ADMW_CONFIG sensor1_rtd_3w_pt100_config;
Vkadaba 5:0728bde67bdb 87 extern ADMW_CONFIG sensor2_typeT_cjc0_config;
Vkadaba 5:0728bde67bdb 88 extern ADMW_CONFIG sensor3_typeJ_cjc0_config;
Vkadaba 5:0728bde67bdb 89 extern ADMW_CONFIG i2c0_sensirionSHT3X_config;
Vkadaba 5:0728bde67bdb 90 extern ADMW_CONFIG spi0_adiAdxl362_config;
Vkadaba 5:0728bde67bdb 91 extern ADMW_CONFIG multichannel_continuous_config;
Vkadaba 5:0728bde67bdb 92 extern ADMW_CONFIG multichannel_multicycle_config;
Vkadaba 5:0728bde67bdb 93 extern ADMW_CONFIG multichannel_singlecycle_config;
ADIJake 0:85855ecd3257 94
ADIJake 0:85855ecd3257 95 /* Change the following pointer to select any of the configurations above */
Vkadaba 11:8e6023d2e584 96 static ADMW_CONFIG *pSelectedConfig = &sensor1_rtd_3w_pt100_config;
ADIJake 0:85855ecd3257 97
Vkadaba 5:0728bde67bdb 98 static ADMW_CONNECTION connectionInfo = PLATFORM_CONNECTION_INFO;
ADIJake 0:85855ecd3257 99
ADIJake 0:85855ecd3257 100 int main()
ADIJake 0:85855ecd3257 101 {
Vkadaba 5:0728bde67bdb 102 ADMW_RESULT res;
Vkadaba 5:0728bde67bdb 103 ADMW_STATUS status;
Vkadaba 5:0728bde67bdb 104 ADMW_DEVICE_HANDLE hDevice;
Vkadaba 5:0728bde67bdb 105 ADMW_MEASUREMENT_MODE eMeasurementMode = ADMW_MEASUREMENT_MODE_NORMAL;
ADIJake 0:85855ecd3257 106 bool bDeviceReady;
ADIJake 0:85855ecd3257 107
ADIJake 0:85855ecd3257 108 /*
ADIJake 0:85855ecd3257 109 * Open an ADI Sense device instance.
ADIJake 0:85855ecd3257 110 */
Vkadaba 5:0728bde67bdb 111 res = admw_Open(0, &connectionInfo, &hDevice);
Vkadaba 5:0728bde67bdb 112 if (res != ADMW_SUCCESS)
ADIJake 0:85855ecd3257 113 {
Vkadaba 5:0728bde67bdb 114 ADMW_LOG_ERROR("Failed to open device instance");
ADIJake 0:85855ecd3257 115 return res;
ADIJake 0:85855ecd3257 116 }
ADIJake 0:85855ecd3257 117
ADIJake 0:85855ecd3257 118 /*
ADIJake 0:85855ecd3257 119 * Reset the given ADI Sense device....
ADIJake 0:85855ecd3257 120 */
Vkadaba 5:0728bde67bdb 121 ADMW_LOG_INFO("Resetting ADI Sense device, please wait...");
Vkadaba 5:0728bde67bdb 122 res = admw_Reset(hDevice);
Vkadaba 5:0728bde67bdb 123 if (res != ADMW_SUCCESS)
ADIJake 0:85855ecd3257 124 {
Vkadaba 5:0728bde67bdb 125 ADMW_LOG_ERROR("Failed to reset device");
ADIJake 0:85855ecd3257 126 return res;
ADIJake 0:85855ecd3257 127 }
ADIJake 0:85855ecd3257 128 /*
ADIJake 0:85855ecd3257 129 * ...and wait until the device is ready.
ADIJake 0:85855ecd3257 130 */
ADIJake 0:85855ecd3257 131 do {
ADIJake 0:85855ecd3257 132 wait_ms(100);
Vkadaba 5:0728bde67bdb 133 res = admw_GetDeviceReadyState(hDevice, &bDeviceReady);
Vkadaba 5:0728bde67bdb 134 if (res != ADMW_SUCCESS)
ADIJake 0:85855ecd3257 135 {
Vkadaba 5:0728bde67bdb 136 ADMW_LOG_ERROR("Failed to get device ready-state");
ADIJake 0:85855ecd3257 137 return res;
ADIJake 0:85855ecd3257 138 }
ADIJake 0:85855ecd3257 139 } while (! bDeviceReady);
Vkadaba 5:0728bde67bdb 140 ADMW_LOG_INFO("ADI Sense device ready");
ADIJake 0:85855ecd3257 141
ADIJake 0:85855ecd3257 142 /*
ADIJake 0:85855ecd3257 143 * Write configuration settings to the device registers.
Vkadaba 5:0728bde67bdb 144 * Settings are not applied until admw_ApplyConfigUpdates() is called.
ADIJake 0:85855ecd3257 145 */
Vkadaba 5:0728bde67bdb 146 ADMW_LOG_INFO("Setting device configuration");
Vkadaba 5:0728bde67bdb 147 res = admw_SetConfig(hDevice, pSelectedConfig);
Vkadaba 5:0728bde67bdb 148 if (res != ADMW_SUCCESS)
ADIJake 0:85855ecd3257 149 {
Vkadaba 5:0728bde67bdb 150 ADMW_LOG_ERROR("Failed to set device configuration");
ADIJake 0:85855ecd3257 151 return res;
ADIJake 0:85855ecd3257 152 }
Vkadaba 5:0728bde67bdb 153 res = admw_ApplyConfigUpdates(hDevice);
Vkadaba 5:0728bde67bdb 154 if (res != ADMW_SUCCESS)
ADIJake 0:85855ecd3257 155 {
Vkadaba 5:0728bde67bdb 156 ADMW_LOG_ERROR("Failed to apply device configuration");
ADIJake 0:85855ecd3257 157 return res;
ADIJake 0:85855ecd3257 158 }
ADIJake 0:85855ecd3257 159 /*
ADIJake 0:85855ecd3257 160 * Check device status after updating the configuration
ADIJake 0:85855ecd3257 161 */
Vkadaba 5:0728bde67bdb 162 res = admw_GetStatus(hDevice, &status);
Vkadaba 5:0728bde67bdb 163 if (res != ADMW_SUCCESS)
ADIJake 0:85855ecd3257 164 {
Vkadaba 5:0728bde67bdb 165 ADMW_LOG_ERROR("Failed to retrieve device status");
ADIJake 0:85855ecd3257 166 return res;
ADIJake 0:85855ecd3257 167 }
ADIJake 0:85855ecd3257 168 if (status.deviceStatus &
Vkadaba 5:0728bde67bdb 169 (ADMW_DEVICE_STATUS_ERROR | ADMW_DEVICE_STATUS_ALERT))
ADIJake 0:85855ecd3257 170 {
ADIJake 0:85855ecd3257 171 utils_printStatus(&status);
ADIJake 0:85855ecd3257 172 }
ADIJake 0:85855ecd3257 173
ADIJake 0:85855ecd3257 174 /*
ADIJake 0:85855ecd3257 175 * Kick off the measurement cycle here
ADIJake 0:85855ecd3257 176 */
Vkadaba 5:0728bde67bdb 177 ADMW_LOG_INFO("Configuration completed, starting measurement cycles");
ADIJake 0:85855ecd3257 178 utils_runMeasurement(hDevice, eMeasurementMode);
ADIJake 0:85855ecd3257 179
ADIJake 0:85855ecd3257 180 /*
ADIJake 0:85855ecd3257 181 * Clean up and exit
ADIJake 0:85855ecd3257 182 */
Vkadaba 5:0728bde67bdb 183 res = admw_Close(hDevice);
Vkadaba 5:0728bde67bdb 184 if (res != ADMW_SUCCESS)
ADIJake 0:85855ecd3257 185 {
Vkadaba 5:0728bde67bdb 186 ADMW_LOG_ERROR("Failed to close device instance");
ADIJake 0:85855ecd3257 187 return res;
ADIJake 0:85855ecd3257 188 }
ADIJake 0:85855ecd3257 189
ADIJake 0:85855ecd3257 190 return 0;
ADIJake 0:85855ecd3257 191 }
ADIJake 0:85855ecd3257 192