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.
main.cpp
00001 00002 /* 00003 Copyright 2019 (c) Analog Devices, Inc. 00004 00005 All rights reserved. 00006 00007 Redistribution and use in source and binary forms, with or without 00008 modification, are permitted provided that the following conditions are met: 00009 - Redistributions of source code must retain the above copyright 00010 notice, this list of conditions and the following disclaimer. 00011 - Redistributions in binary form must reproduce the above copyright 00012 notice, this list of conditions and the following disclaimer in 00013 the documentation and/or other materials provided with the 00014 distribution. 00015 - Neither the name of Analog Devices, Inc. nor the names of its 00016 contributors may be used to endorse or promote products derived 00017 from this software without specific prior written permission. 00018 - The use of this software may or may not infringe the patent rights 00019 of one or more patent holders. This license does not release you 00020 from the requirement that you obtain separate licenses from these 00021 patent holders to use this software. 00022 - Use of the software either in source or binary form, must be run 00023 on or directly connected to an Analog Devices Inc. component. 00024 00025 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 00026 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 00027 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00028 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 00029 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00030 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 00031 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00032 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00033 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00034 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 00036 *****************************************************************************/ 00037 /*! 00038 ****************************************************************************** 00039 * @file: 00040 *----------------------------------------------------------------------------- 00041 * 00042 */ 00043 #include "mbed.h" 00044 #include "admw_api.h" 00045 #include "admw1001/admw1001_api.h" 00046 #include "admw_log.h" 00047 #include "common/utils.h" 00048 #include "common/platform.h" 00049 #include "admw1001/ADMW1001_REGISTERS_typedefs.h" 00050 #include "admw1001/ADMW1001_REGISTERS.h" 00051 #include "admw1001/admw1001_lut_data.h" 00052 #include "admw1001/admw1001_host_comms.h" 00053 #include "mbedVersion.h" 00054 00055 extern ADMW_CONFIG thermocouple_typeK_cjc0_config; 00056 extern ADMW_CONFIG thermocouple_typeT_cjc0_config; 00057 extern ADMW_CONFIG thermocouple_typeJ_cjc0_config; 00058 extern ADMW_CONFIG rtd_3w_pt100_config; 00059 extern ADMW_CONFIG rtd_4w_config; 00060 extern ADMW_CONFIG bridge_4w_load_cell_config; 00061 extern ADMW_CONFIG multichannel_continuous_config; 00062 extern ADMW_CONFIG multichannel_singlecycle_config; 00063 extern ADMW_CONFIG i2c0_sensirionSHT3X_config; 00064 /* Use the following config if adding a configuration file from measureware designer*/ 00065 extern ADMW_CONFIG measureware_config; 00066 00067 /* Change the following pointer to load or change the configurations */ 00068 static ADMW_CONFIG *pSelectedConfig = &multichannel_continuous_config; 00069 00070 /* use the following to load LUT */ 00071 extern ADMW1001_LUT_DESCRIPTOR *lut_desc_list[]; 00072 extern ADMW1001_LUT_TABLE_DATA *lut_data_list[]; 00073 extern unsigned lut_num_tables; 00074 00075 static ADMW_CONNECTION connectionInfo = PLATFORM_CONNECTION_INFO; 00076 00077 00078 int main() 00079 { 00080 ADMW_RESULT res; 00081 ADMW_STATUS status; 00082 ADMW_DEVICE_HANDLE hDevice; 00083 ADMW_MEASUREMENT_MODE eMeasurementMode = ADMW_MEASUREMENT_MODE_NORMAL ; 00084 bool bDeviceReady; 00085 00086 /* 00087 * Open an ADMW1001 device instance. 00088 */ 00089 res = admw_Open(0, &connectionInfo, &hDevice); 00090 if (res != ADMW_SUCCESS ) { 00091 ADMW_LOG_ERROR("Failed to open device instance"); 00092 return res; 00093 } 00094 ADMW_LOG_INFO("Mbed Firmware version is %X.%X.%X",MBED_HOST_MAJOR,MBED_HOST_MINOR,MBED_HOST_BUILD); 00095 /* 00096 * Reset the given ADMW1001 device.... 00097 */ 00098 ADMW_LOG_INFO("Resetting ADMW1001 device, please wait..."); 00099 res = admw_Reset(hDevice); 00100 if (res != ADMW_SUCCESS ) { 00101 ADMW_LOG_ERROR("Failed to reset device"); 00102 return res; 00103 } 00104 /* 00105 * ...and wait until the device is ready. 00106 */ 00107 do { 00108 wait_ms(100); 00109 res = admw_GetDeviceReadyState(hDevice, &bDeviceReady); 00110 if (res != ADMW_SUCCESS ) { 00111 ADMW_LOG_ERROR("Failed to get device ready-state"); 00112 return res; 00113 } 00114 } while (! bDeviceReady); 00115 ADMW_LOG_INFO("ADMW1001 device ready"); 00116 /* 00117 * Write configuration settings to the device registers. 00118 * Settings are not applied until admw_ApplyConfigUpdates() is called. 00119 */ 00120 ADMW_LOG_INFO("Setting device configuration"); 00121 res = admw_SetConfig(hDevice, pSelectedConfig); 00122 if (res != ADMW_SUCCESS ) { 00123 ADMW_LOG_ERROR("Failed to set device configuration"); 00124 return res; 00125 } 00126 unsigned lutBufferSize = ADMW_LUT_MAX_SIZE; 00127 ADMW1001_LUT *pLutBuffer = (ADMW1001_LUT *) malloc(lutBufferSize); 00128 if (pLutBuffer == NULL) { 00129 return 1; 00130 } 00131 00132 res=admw1001_AssembleLutData(pLutBuffer, lutBufferSize, 00133 lut_num_tables, 00134 lut_desc_list, 00135 lut_data_list); 00136 if( res != ADMW_SUCCESS ) { 00137 ADMW_LOG_ERROR("Failed to assemble user-defined LUT data"); 00138 return res; 00139 } 00140 00141 res=admw1001_SetLutData(hDevice, 00142 pLutBuffer); 00143 if( res != ADMW_SUCCESS ) { 00144 ADMW_LOG_ERROR("Failed to set user-defined LUT data"); 00145 } 00146 00147 free( pLutBuffer ); 00148 res = admw_ApplyConfigUpdates(hDevice); 00149 if (res != ADMW_SUCCESS ) { 00150 ADMW_LOG_ERROR("Failed to apply device configuration"); 00151 return res; 00152 } 00153 /* 00154 * Check device status after updating the configuration 00155 */ 00156 res = admw_GetStatus(hDevice, &status); 00157 admw_deviceInformation(hDevice); 00158 if (res != ADMW_SUCCESS ) { 00159 ADMW_LOG_ERROR("Failed to retrieve device status"); 00160 return res; 00161 } 00162 if (status.deviceStatus & 00163 (ADMW_DEVICE_STATUS_ERROR | ADMW_DEVICE_STATUS_ALERT )) { 00164 utils_printStatus(&status); 00165 } 00166 00167 /* 00168 * Kick off the measurement cycle here 00169 */ 00170 ADMW_LOG_INFO("Configuration completed, starting measurement cycles"); 00171 utils_runMeasurement(hDevice, eMeasurementMode); 00172 00173 /* 00174 * Clean up and exit 00175 */ 00176 res = admw_Close(hDevice); 00177 if (res != ADMW_SUCCESS ) { 00178 ADMW_LOG_ERROR("Failed to close device instance"); 00179 return res; 00180 } 00181 00182 return 0; 00183 } 00184
Generated on Wed Jul 13 2022 05:15:07 by
1.7.2