Vybhav Kadaba
/
EV-PRO-MW1001_Development_v11775
Minor changes to support ADMW FWv1.17.75
main.cpp@55:215da406282b, 2020-02-24 (annotated)
- Committer:
- Vkadaba
- Date:
- Mon Feb 24 07:04:35 2020 +0000
- Revision:
- 55:215da406282b
- Parent:
- 54:31921ad29828
- Child:
- 56:38b36e947602
Added readMbedVersion functionality
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Vkadaba | 55:215da406282b | 1 | |
ADIJake | 0:85855ecd3257 | 2 | /* |
Vkadaba | 15:b5d57daeb7c0 | 3 | Copyright 2019 (c) Analog Devices, Inc. |
ADIJake | 0:85855ecd3257 | 4 | |
ADIJake | 0:85855ecd3257 | 5 | All rights reserved. |
ADIJake | 0:85855ecd3257 | 6 | |
ADIJake | 0:85855ecd3257 | 7 | Redistribution and use in source and binary forms, with or without |
ADIJake | 0:85855ecd3257 | 8 | modification, are permitted provided that the following conditions are met: |
ADIJake | 0:85855ecd3257 | 9 | - Redistributions of source code must retain the above copyright |
ADIJake | 0:85855ecd3257 | 10 | notice, this list of conditions and the following disclaimer. |
ADIJake | 0:85855ecd3257 | 11 | - Redistributions in binary form must reproduce the above copyright |
ADIJake | 0:85855ecd3257 | 12 | notice, this list of conditions and the following disclaimer in |
ADIJake | 0:85855ecd3257 | 13 | the documentation and/or other materials provided with the |
ADIJake | 0:85855ecd3257 | 14 | distribution. |
ADIJake | 0:85855ecd3257 | 15 | - Neither the name of Analog Devices, Inc. nor the names of its |
ADIJake | 0:85855ecd3257 | 16 | contributors may be used to endorse or promote products derived |
ADIJake | 0:85855ecd3257 | 17 | from this software without specific prior written permission. |
ADIJake | 0:85855ecd3257 | 18 | - The use of this software may or may not infringe the patent rights |
ADIJake | 0:85855ecd3257 | 19 | of one or more patent holders. This license does not release you |
ADIJake | 0:85855ecd3257 | 20 | from the requirement that you obtain separate licenses from these |
ADIJake | 0:85855ecd3257 | 21 | patent holders to use this software. |
ADIJake | 0:85855ecd3257 | 22 | - Use of the software either in source or binary form, must be run |
ADIJake | 0:85855ecd3257 | 23 | on or directly connected to an Analog Devices Inc. component. |
ADIJake | 0:85855ecd3257 | 24 | |
ADIJake | 0:85855ecd3257 | 25 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
ADIJake | 0:85855ecd3257 | 26 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
ADIJake | 0:85855ecd3257 | 27 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
ADIJake | 0:85855ecd3257 | 28 | IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
ADIJake | 0:85855ecd3257 | 29 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
ADIJake | 0:85855ecd3257 | 30 | LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
ADIJake | 0:85855ecd3257 | 31 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
ADIJake | 0:85855ecd3257 | 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
ADIJake | 0:85855ecd3257 | 33 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
ADIJake | 0:85855ecd3257 | 34 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
ADIJake | 0:85855ecd3257 | 35 | |
ADIJake | 0:85855ecd3257 | 36 | *****************************************************************************/ |
ADIJake | 0:85855ecd3257 | 37 | /*! |
ADIJake | 0:85855ecd3257 | 38 | ****************************************************************************** |
ADIJake | 0:85855ecd3257 | 39 | * @file: |
ADIJake | 0:85855ecd3257 | 40 | *----------------------------------------------------------------------------- |
ADIJake | 0:85855ecd3257 | 41 | * |
ADIJake | 0:85855ecd3257 | 42 | */ |
ADIJake | 0:85855ecd3257 | 43 | #include "mbed.h" |
Vkadaba | 5:0728bde67bdb | 44 | #include "admw_api.h" |
Vkadaba | 5:0728bde67bdb | 45 | #include "admw1001/admw1001_api.h" |
Vkadaba | 5:0728bde67bdb | 46 | #include "admw_log.h" |
ADIJake | 0:85855ecd3257 | 47 | #include "common/utils.h" |
ADIJake | 0:85855ecd3257 | 48 | #include "common/platform.h" |
Vkadaba | 54:31921ad29828 | 49 | #include "admw1001/ADMW1001_REGISTERS_typedefs.h" |
Vkadaba | 14:266ab283b086 | 50 | #include "admw1001/ADMW1001_REGISTERS.h" |
Vkadaba | 54:31921ad29828 | 51 | #include "admw1001/admw1001_lut_data.h" |
Vkadaba | 54:31921ad29828 | 52 | #include "admw1001/admw1001_host_comms.h" |
Vkadaba | 5:0728bde67bdb | 53 | |
Vkadaba | 34:b60ee1e0af2b | 54 | extern ADMW_CONFIG thermocouple_typeK_cjc0_config; |
Vkadaba | 34:b60ee1e0af2b | 55 | extern ADMW_CONFIG thermocouple_typeT_cjc0_config; |
Vkadaba | 34:b60ee1e0af2b | 56 | extern ADMW_CONFIG thermocouple_typeJ_cjc0_config; |
Vkadaba | 34:b60ee1e0af2b | 57 | extern ADMW_CONFIG rtd_3w_pt100_config; |
Vkadaba | 34:b60ee1e0af2b | 58 | extern ADMW_CONFIG rtd_4w_config; |
Vkadaba | 34:b60ee1e0af2b | 59 | extern ADMW_CONFIG bridge_4w_load_cell_config; |
Vkadaba | 5:0728bde67bdb | 60 | extern ADMW_CONFIG multichannel_continuous_config; |
Vkadaba | 5:0728bde67bdb | 61 | extern ADMW_CONFIG multichannel_singlecycle_config; |
Vkadaba | 34:b60ee1e0af2b | 62 | extern ADMW_CONFIG i2c0_sensirionSHT3X_config; |
Vkadaba | 47:5b42b9f9d1eb | 63 | /* Use the following config if adding a configuration file from measureware designer*/ |
Vkadaba | 47:5b42b9f9d1eb | 64 | extern ADMW_CONFIG measureware_config; |
Vkadaba | 47:5b42b9f9d1eb | 65 | |
Vkadaba | 49:c31473bc013e | 66 | /* Change the following pointer to load or change the configurations */ |
Vkadaba | 54:31921ad29828 | 67 | static ADMW_CONFIG *pSelectedConfig = &bridge_4w_load_cell_config; |
Vkadaba | 54:31921ad29828 | 68 | |
Vkadaba | 54:31921ad29828 | 69 | /* use the following to load LUT */ |
Vkadaba | 54:31921ad29828 | 70 | extern ADMW1001_LUT_DESCRIPTOR *lut_desc_list[]; |
Vkadaba | 54:31921ad29828 | 71 | extern ADMW1001_LUT_TABLE_DATA *lut_data_list[]; |
Vkadaba | 54:31921ad29828 | 72 | extern unsigned lut_num_tables; |
ADIJake | 0:85855ecd3257 | 73 | |
Vkadaba | 5:0728bde67bdb | 74 | static ADMW_CONNECTION connectionInfo = PLATFORM_CONNECTION_INFO; |
ADIJake | 0:85855ecd3257 | 75 | |
Vkadaba | 14:266ab283b086 | 76 | |
ADIJake | 0:85855ecd3257 | 77 | int main() |
ADIJake | 0:85855ecd3257 | 78 | { |
Vkadaba | 50:d84305e5e1c0 | 79 | |
Vkadaba | 5:0728bde67bdb | 80 | ADMW_RESULT res; |
Vkadaba | 5:0728bde67bdb | 81 | ADMW_STATUS status; |
Vkadaba | 5:0728bde67bdb | 82 | ADMW_DEVICE_HANDLE hDevice; |
Vkadaba | 5:0728bde67bdb | 83 | ADMW_MEASUREMENT_MODE eMeasurementMode = ADMW_MEASUREMENT_MODE_NORMAL; |
ADIJake | 0:85855ecd3257 | 84 | bool bDeviceReady; |
Vkadaba | 55:215da406282b | 85 | admw_readMbedVersion(); |
ADIJake | 0:85855ecd3257 | 86 | /* |
Vkadaba | 19:09d58952b65d | 87 | * Open an ADMW1001 device instance. |
ADIJake | 0:85855ecd3257 | 88 | */ |
Vkadaba | 5:0728bde67bdb | 89 | res = admw_Open(0, &connectionInfo, &hDevice); |
Vkadaba | 23:bb685f35b08b | 90 | if (res != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 91 | ADMW_LOG_ERROR("Failed to open device instance"); |
ADIJake | 0:85855ecd3257 | 92 | return res; |
ADIJake | 0:85855ecd3257 | 93 | } |
Vkadaba | 23:bb685f35b08b | 94 | |
ADIJake | 0:85855ecd3257 | 95 | /* |
Vkadaba | 19:09d58952b65d | 96 | * Reset the given ADMW1001 device.... |
ADIJake | 0:85855ecd3257 | 97 | */ |
Vkadaba | 19:09d58952b65d | 98 | ADMW_LOG_INFO("Resetting ADMW1001 device, please wait..."); |
Vkadaba | 5:0728bde67bdb | 99 | res = admw_Reset(hDevice); |
Vkadaba | 23:bb685f35b08b | 100 | if (res != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 101 | ADMW_LOG_ERROR("Failed to reset device"); |
ADIJake | 0:85855ecd3257 | 102 | return res; |
ADIJake | 0:85855ecd3257 | 103 | } |
ADIJake | 0:85855ecd3257 | 104 | /* |
ADIJake | 0:85855ecd3257 | 105 | * ...and wait until the device is ready. |
ADIJake | 0:85855ecd3257 | 106 | */ |
ADIJake | 0:85855ecd3257 | 107 | do { |
ADIJake | 0:85855ecd3257 | 108 | wait_ms(100); |
Vkadaba | 5:0728bde67bdb | 109 | res = admw_GetDeviceReadyState(hDevice, &bDeviceReady); |
Vkadaba | 23:bb685f35b08b | 110 | if (res != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 111 | ADMW_LOG_ERROR("Failed to get device ready-state"); |
ADIJake | 0:85855ecd3257 | 112 | return res; |
ADIJake | 0:85855ecd3257 | 113 | } |
ADIJake | 0:85855ecd3257 | 114 | } while (! bDeviceReady); |
Vkadaba | 19:09d58952b65d | 115 | ADMW_LOG_INFO("ADMW1001 device ready"); |
ADIJake | 0:85855ecd3257 | 116 | /* |
ADIJake | 0:85855ecd3257 | 117 | * Write configuration settings to the device registers. |
Vkadaba | 5:0728bde67bdb | 118 | * Settings are not applied until admw_ApplyConfigUpdates() is called. |
ADIJake | 0:85855ecd3257 | 119 | */ |
Vkadaba | 5:0728bde67bdb | 120 | ADMW_LOG_INFO("Setting device configuration"); |
Vkadaba | 5:0728bde67bdb | 121 | res = admw_SetConfig(hDevice, pSelectedConfig); |
Vkadaba | 23:bb685f35b08b | 122 | if (res != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 123 | ADMW_LOG_ERROR("Failed to set device configuration"); |
ADIJake | 0:85855ecd3257 | 124 | return res; |
ADIJake | 0:85855ecd3257 | 125 | } |
Vkadaba | 54:31921ad29828 | 126 | unsigned lutBufferSize = ADMW_LUT_MAX_SIZE; |
Vkadaba | 54:31921ad29828 | 127 | ADMW1001_LUT *pLutBuffer = (ADMW1001_LUT *) malloc(lutBufferSize); |
Vkadaba | 54:31921ad29828 | 128 | if (pLutBuffer == NULL) { |
Vkadaba | 54:31921ad29828 | 129 | return 1; |
Vkadaba | 54:31921ad29828 | 130 | } |
Vkadaba | 54:31921ad29828 | 131 | |
Vkadaba | 54:31921ad29828 | 132 | res=admw1001_AssembleLutData(pLutBuffer, lutBufferSize, |
Vkadaba | 54:31921ad29828 | 133 | lut_num_tables, |
Vkadaba | 54:31921ad29828 | 134 | lut_desc_list, |
Vkadaba | 54:31921ad29828 | 135 | lut_data_list); |
Vkadaba | 54:31921ad29828 | 136 | if( res != ADMW_SUCCESS ) { |
Vkadaba | 54:31921ad29828 | 137 | ADMW_LOG_ERROR("Failed to assemble user-defined LUT data"); |
Vkadaba | 54:31921ad29828 | 138 | return res; |
Vkadaba | 54:31921ad29828 | 139 | } |
Vkadaba | 54:31921ad29828 | 140 | |
Vkadaba | 54:31921ad29828 | 141 | res=admw1001_SetLutData(hDevice, |
Vkadaba | 54:31921ad29828 | 142 | pLutBuffer); |
Vkadaba | 54:31921ad29828 | 143 | if( res != ADMW_SUCCESS ) { |
Vkadaba | 54:31921ad29828 | 144 | ADMW_LOG_ERROR("Failed to set user-defined LUT data"); |
Vkadaba | 54:31921ad29828 | 145 | } |
Vkadaba | 54:31921ad29828 | 146 | |
Vkadaba | 54:31921ad29828 | 147 | free( pLutBuffer ); |
Vkadaba | 5:0728bde67bdb | 148 | res = admw_ApplyConfigUpdates(hDevice); |
Vkadaba | 23:bb685f35b08b | 149 | if (res != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 150 | ADMW_LOG_ERROR("Failed to apply device configuration"); |
ADIJake | 0:85855ecd3257 | 151 | return res; |
ADIJake | 0:85855ecd3257 | 152 | } |
ADIJake | 0:85855ecd3257 | 153 | /* |
ADIJake | 0:85855ecd3257 | 154 | * Check device status after updating the configuration |
ADIJake | 0:85855ecd3257 | 155 | */ |
Vkadaba | 5:0728bde67bdb | 156 | res = admw_GetStatus(hDevice, &status); |
Vkadaba | 50:d84305e5e1c0 | 157 | admw_deviceInformation(hDevice); |
Vkadaba | 23:bb685f35b08b | 158 | if (res != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 159 | ADMW_LOG_ERROR("Failed to retrieve device status"); |
ADIJake | 0:85855ecd3257 | 160 | return res; |
ADIJake | 0:85855ecd3257 | 161 | } |
ADIJake | 0:85855ecd3257 | 162 | if (status.deviceStatus & |
Vkadaba | 23:bb685f35b08b | 163 | (ADMW_DEVICE_STATUS_ERROR | ADMW_DEVICE_STATUS_ALERT)) { |
ADIJake | 0:85855ecd3257 | 164 | utils_printStatus(&status); |
ADIJake | 0:85855ecd3257 | 165 | } |
ADIJake | 0:85855ecd3257 | 166 | |
ADIJake | 0:85855ecd3257 | 167 | /* |
ADIJake | 0:85855ecd3257 | 168 | * Kick off the measurement cycle here |
ADIJake | 0:85855ecd3257 | 169 | */ |
Vkadaba | 5:0728bde67bdb | 170 | ADMW_LOG_INFO("Configuration completed, starting measurement cycles"); |
ADIJake | 0:85855ecd3257 | 171 | utils_runMeasurement(hDevice, eMeasurementMode); |
ADIJake | 0:85855ecd3257 | 172 | |
ADIJake | 0:85855ecd3257 | 173 | /* |
ADIJake | 0:85855ecd3257 | 174 | * Clean up and exit |
ADIJake | 0:85855ecd3257 | 175 | */ |
Vkadaba | 5:0728bde67bdb | 176 | res = admw_Close(hDevice); |
Vkadaba | 23:bb685f35b08b | 177 | if (res != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 178 | ADMW_LOG_ERROR("Failed to close device instance"); |
ADIJake | 0:85855ecd3257 | 179 | return res; |
ADIJake | 0:85855ecd3257 | 180 | } |
ADIJake | 0:85855ecd3257 | 181 | |
ADIJake | 0:85855ecd3257 | 182 | return 0; |
ADIJake | 0:85855ecd3257 | 183 | } |
ADIJake | 0:85855ecd3257 | 184 |