Vybhav Kadaba
/
EV-PRO-MW1001_MWARE_2042
Adding mbed FW version and release notes
main.cpp@28:8a7a908a8fdb, 2019-10-03 (annotated)
- Committer:
- Vkadaba
- Date:
- Thu Oct 03 05:55:23 2019 +0000
- Revision:
- 28:8a7a908a8fdb
- Parent:
- 23:bb685f35b08b
- Child:
- 29:713c24b07795
Code clean up and config files updated
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ADIJake | 0:85855ecd3257 | 1 | /* |
Vkadaba | 15:b5d57daeb7c0 | 2 | Copyright 2019 (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 | *****************************************************************************/ |
ADIJake | 0:85855ecd3257 | 36 | /*! |
ADIJake | 0:85855ecd3257 | 37 | ****************************************************************************** |
ADIJake | 0:85855ecd3257 | 38 | * @file: |
ADIJake | 0:85855ecd3257 | 39 | *----------------------------------------------------------------------------- |
ADIJake | 0:85855ecd3257 | 40 | * |
ADIJake | 0:85855ecd3257 | 41 | */ |
ADIJake | 0:85855ecd3257 | 42 | #include "mbed.h" |
Vkadaba | 5:0728bde67bdb | 43 | #include "admw_api.h" |
Vkadaba | 5:0728bde67bdb | 44 | #include "admw1001/admw1001_api.h" |
Vkadaba | 5:0728bde67bdb | 45 | #include "admw_log.h" |
ADIJake | 0:85855ecd3257 | 46 | #include "common/utils.h" |
ADIJake | 0:85855ecd3257 | 47 | #include "common/platform.h" |
Vkadaba | 14:266ab283b086 | 48 | #include "admw1001/ADMW1001_REGISTERS.h" |
Vkadaba | 5:0728bde67bdb | 49 | |
Vkadaba | 5:0728bde67bdb | 50 | extern ADMW_CONFIG sensor0_typeK_cjc0_config; |
Vkadaba | 5:0728bde67bdb | 51 | extern ADMW_CONFIG sensor1_rtd_3w_pt100_config; |
Vkadaba | 5:0728bde67bdb | 52 | extern ADMW_CONFIG sensor2_typeT_cjc0_config; |
Vkadaba | 5:0728bde67bdb | 53 | extern ADMW_CONFIG sensor3_typeJ_cjc0_config; |
Vkadaba | 5:0728bde67bdb | 54 | extern ADMW_CONFIG i2c0_sensirionSHT3X_config; |
Vkadaba | 5:0728bde67bdb | 55 | extern ADMW_CONFIG multichannel_continuous_config; |
Vkadaba | 5:0728bde67bdb | 56 | extern ADMW_CONFIG multichannel_multicycle_config; |
Vkadaba | 5:0728bde67bdb | 57 | extern ADMW_CONFIG multichannel_singlecycle_config; |
Vkadaba | 16:327cea5a86e9 | 58 | extern ADMW_CONFIG sensor2_bridge_4w_load_cell_config; |
Vkadaba | 17:2f0028880874 | 59 | extern ADMW_CONFIG config; |
ADIJake | 0:85855ecd3257 | 60 | /* Change the following pointer to select any of the configurations above */ |
Vkadaba | 22:2835e9e9f59f | 61 | static ADMW_CONFIG *pSelectedConfig = &multichannel_continuous_config; |
ADIJake | 0:85855ecd3257 | 62 | |
Vkadaba | 5:0728bde67bdb | 63 | static ADMW_CONNECTION connectionInfo = PLATFORM_CONNECTION_INFO; |
ADIJake | 0:85855ecd3257 | 64 | |
Vkadaba | 14:266ab283b086 | 65 | |
ADIJake | 0:85855ecd3257 | 66 | int main() |
ADIJake | 0:85855ecd3257 | 67 | { |
Vkadaba | 5:0728bde67bdb | 68 | ADMW_RESULT res; |
Vkadaba | 5:0728bde67bdb | 69 | ADMW_STATUS status; |
Vkadaba | 5:0728bde67bdb | 70 | ADMW_DEVICE_HANDLE hDevice; |
Vkadaba | 5:0728bde67bdb | 71 | ADMW_MEASUREMENT_MODE eMeasurementMode = ADMW_MEASUREMENT_MODE_NORMAL; |
ADIJake | 0:85855ecd3257 | 72 | bool bDeviceReady; |
Vkadaba | 23:bb685f35b08b | 73 | |
ADIJake | 0:85855ecd3257 | 74 | /* |
Vkadaba | 19:09d58952b65d | 75 | * Open an ADMW1001 device instance. |
ADIJake | 0:85855ecd3257 | 76 | */ |
Vkadaba | 5:0728bde67bdb | 77 | res = admw_Open(0, &connectionInfo, &hDevice); |
Vkadaba | 23:bb685f35b08b | 78 | if (res != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 79 | ADMW_LOG_ERROR("Failed to open device instance"); |
ADIJake | 0:85855ecd3257 | 80 | return res; |
ADIJake | 0:85855ecd3257 | 81 | } |
Vkadaba | 23:bb685f35b08b | 82 | |
ADIJake | 0:85855ecd3257 | 83 | /* |
Vkadaba | 19:09d58952b65d | 84 | * Reset the given ADMW1001 device.... |
ADIJake | 0:85855ecd3257 | 85 | */ |
Vkadaba | 19:09d58952b65d | 86 | ADMW_LOG_INFO("Resetting ADMW1001 device, please wait..."); |
Vkadaba | 5:0728bde67bdb | 87 | res = admw_Reset(hDevice); |
Vkadaba | 23:bb685f35b08b | 88 | if (res != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 89 | ADMW_LOG_ERROR("Failed to reset device"); |
ADIJake | 0:85855ecd3257 | 90 | return res; |
ADIJake | 0:85855ecd3257 | 91 | } |
ADIJake | 0:85855ecd3257 | 92 | /* |
ADIJake | 0:85855ecd3257 | 93 | * ...and wait until the device is ready. |
ADIJake | 0:85855ecd3257 | 94 | */ |
ADIJake | 0:85855ecd3257 | 95 | do { |
ADIJake | 0:85855ecd3257 | 96 | wait_ms(100); |
Vkadaba | 5:0728bde67bdb | 97 | res = admw_GetDeviceReadyState(hDevice, &bDeviceReady); |
Vkadaba | 23:bb685f35b08b | 98 | if (res != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 99 | ADMW_LOG_ERROR("Failed to get device ready-state"); |
ADIJake | 0:85855ecd3257 | 100 | return res; |
ADIJake | 0:85855ecd3257 | 101 | } |
ADIJake | 0:85855ecd3257 | 102 | } while (! bDeviceReady); |
Vkadaba | 19:09d58952b65d | 103 | ADMW_LOG_INFO("ADMW1001 device ready"); |
ADIJake | 0:85855ecd3257 | 104 | /* |
ADIJake | 0:85855ecd3257 | 105 | * Write configuration settings to the device registers. |
Vkadaba | 5:0728bde67bdb | 106 | * Settings are not applied until admw_ApplyConfigUpdates() is called. |
ADIJake | 0:85855ecd3257 | 107 | */ |
Vkadaba | 5:0728bde67bdb | 108 | ADMW_LOG_INFO("Setting device configuration"); |
Vkadaba | 5:0728bde67bdb | 109 | res = admw_SetConfig(hDevice, pSelectedConfig); |
Vkadaba | 23:bb685f35b08b | 110 | if (res != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 111 | ADMW_LOG_ERROR("Failed to set device configuration"); |
ADIJake | 0:85855ecd3257 | 112 | return res; |
ADIJake | 0:85855ecd3257 | 113 | } |
Vkadaba | 5:0728bde67bdb | 114 | res = admw_ApplyConfigUpdates(hDevice); |
Vkadaba | 23:bb685f35b08b | 115 | if (res != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 116 | ADMW_LOG_ERROR("Failed to apply device configuration"); |
ADIJake | 0:85855ecd3257 | 117 | return res; |
ADIJake | 0:85855ecd3257 | 118 | } |
ADIJake | 0:85855ecd3257 | 119 | /* |
ADIJake | 0:85855ecd3257 | 120 | * Check device status after updating the configuration |
ADIJake | 0:85855ecd3257 | 121 | */ |
Vkadaba | 5:0728bde67bdb | 122 | res = admw_GetStatus(hDevice, &status); |
Vkadaba | 14:266ab283b086 | 123 | deviceInformation(hDevice); |
Vkadaba | 23:bb685f35b08b | 124 | if (res != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 125 | ADMW_LOG_ERROR("Failed to retrieve device status"); |
ADIJake | 0:85855ecd3257 | 126 | return res; |
ADIJake | 0:85855ecd3257 | 127 | } |
ADIJake | 0:85855ecd3257 | 128 | if (status.deviceStatus & |
Vkadaba | 23:bb685f35b08b | 129 | (ADMW_DEVICE_STATUS_ERROR | ADMW_DEVICE_STATUS_ALERT)) { |
ADIJake | 0:85855ecd3257 | 130 | utils_printStatus(&status); |
ADIJake | 0:85855ecd3257 | 131 | } |
ADIJake | 0:85855ecd3257 | 132 | |
ADIJake | 0:85855ecd3257 | 133 | /* |
ADIJake | 0:85855ecd3257 | 134 | * Kick off the measurement cycle here |
ADIJake | 0:85855ecd3257 | 135 | */ |
Vkadaba | 5:0728bde67bdb | 136 | ADMW_LOG_INFO("Configuration completed, starting measurement cycles"); |
ADIJake | 0:85855ecd3257 | 137 | utils_runMeasurement(hDevice, eMeasurementMode); |
ADIJake | 0:85855ecd3257 | 138 | |
ADIJake | 0:85855ecd3257 | 139 | /* |
ADIJake | 0:85855ecd3257 | 140 | * Clean up and exit |
ADIJake | 0:85855ecd3257 | 141 | */ |
Vkadaba | 5:0728bde67bdb | 142 | res = admw_Close(hDevice); |
Vkadaba | 23:bb685f35b08b | 143 | if (res != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 144 | ADMW_LOG_ERROR("Failed to close device instance"); |
ADIJake | 0:85855ecd3257 | 145 | return res; |
ADIJake | 0:85855ecd3257 | 146 | } |
ADIJake | 0:85855ecd3257 | 147 | |
ADIJake | 0:85855ecd3257 | 148 | return 0; |
ADIJake | 0:85855ecd3257 | 149 | } |
ADIJake | 0:85855ecd3257 | 150 |