Vybhav Kadaba
/
EV-PRO-MW1001_Development_code_cleanup2
Code clean up, removed unwanted enums and configurations
src/admw_1001.c@66:cc7069bc0ead, 2020-04-14 (annotated)
- Committer:
- Vkadaba
- Date:
- Tue Apr 14 11:43:05 2020 +0000
- Revision:
- 66:cc7069bc0ead
- Parent:
- 65:d91e1d63153d
changed the MBED version to 1.17.75
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ADIJake | 0:85855ecd3257 | 1 | /* |
Vkadaba | 8:2f2775c34640 | 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: |
Vkadaba | 8:2f2775c34640 | 39 | * @brief: API implementation for ADMW1001 |
ADIJake | 0:85855ecd3257 | 40 | *----------------------------------------------------------------------------- |
ADIJake | 0:85855ecd3257 | 41 | */ |
ADIJake | 0:85855ecd3257 | 42 | |
ADIJake | 0:85855ecd3257 | 43 | #include <float.h> |
ADIJake | 0:85855ecd3257 | 44 | #include <math.h> |
ADIJake | 0:85855ecd3257 | 45 | #include <string.h> |
ADIJake | 0:85855ecd3257 | 46 | |
Vkadaba | 5:0728bde67bdb | 47 | #include "admw_platform.h" |
Vkadaba | 5:0728bde67bdb | 48 | #include "admw_api.h" |
Vkadaba | 5:0728bde67bdb | 49 | #include "admw1001/admw1001_api.h" |
Vkadaba | 5:0728bde67bdb | 50 | |
Vkadaba | 5:0728bde67bdb | 51 | #include "admw1001/ADMW1001_REGISTERS_typedefs.h" |
Vkadaba | 5:0728bde67bdb | 52 | #include "admw1001/ADMW1001_REGISTERS.h" |
Vkadaba | 5:0728bde67bdb | 53 | #include "admw1001/admw1001_lut_data.h" |
Vkadaba | 5:0728bde67bdb | 54 | #include "admw1001/admw1001_host_comms.h" |
Vkadaba | 55:215da406282b | 55 | #include "inc/mbedVersion.h" |
Vkadaba | 13:97cb32670539 | 56 | #define VERSIONID_MAJOR 2 |
Vkadaba | 13:97cb32670539 | 57 | #define VERSIONID_MINOR 0 |
ADIJake | 0:85855ecd3257 | 58 | |
ADIJake | 0:85855ecd3257 | 59 | uint32_t getDataCnt = 0; |
Vkadaba | 32:52445bef314d | 60 | #define ADMW_VERSION_REG_VAL_SIZE 4u |
Vkadaba | 32:52445bef314d | 61 | #define ADMW_FORMATTED_VERSION_SIZE 11u |
ADIJake | 0:85855ecd3257 | 62 | |
Vkadaba | 32:52445bef314d | 63 | #define ADMW_SFL_READ_STATUS_SIZE 42u |
ADIJake | 0:85855ecd3257 | 64 | /* |
ADIJake | 0:85855ecd3257 | 65 | * The following macros are used to encapsulate the register access code |
ADIJake | 0:85855ecd3257 | 66 | * to improve readability in the functions further below in this file |
ADIJake | 0:85855ecd3257 | 67 | */ |
ADIJake | 0:85855ecd3257 | 68 | #define STRINGIFY(name) #name |
ADIJake | 0:85855ecd3257 | 69 | |
ADIJake | 0:85855ecd3257 | 70 | /* Expand the full name of the reset value macro for the specified register */ |
Vkadaba | 5:0728bde67bdb | 71 | #define REG_RESET_VAL(_name) REG_##_name##_RESET |
ADIJake | 0:85855ecd3257 | 72 | |
ADIJake | 0:85855ecd3257 | 73 | /* Checks if a value is outside the bounds of the specified register field */ |
ADIJake | 0:85855ecd3257 | 74 | #define CHECK_REG_FIELD_VAL(_field, _val) \ |
ADIJake | 0:85855ecd3257 | 75 | do { \ |
Vkadaba | 8:2f2775c34640 | 76 | uint32_t _mask = BITM_##_field; \ |
Vkadaba | 8:2f2775c34640 | 77 | uint32_t _shift = BITP_##_field; \ |
ADIJake | 0:85855ecd3257 | 78 | if ((((_val) << _shift) & ~(_mask)) != 0) { \ |
Vkadaba | 6:9d393a9677f4 | 79 | ADMW_LOG_ERROR("Value 0x%08X invalid for register field %s",\ |
ADIJake | 0:85855ecd3257 | 80 | (uint32_t)(_val), \ |
Vkadaba | 6:9d393a9677f4 | 81 | STRINGIFY(ADMW_##_field)); \ |
Vkadaba | 8:2f2775c34640 | 82 | return ADMW_INVALID_PARAM; \ |
ADIJake | 0:85855ecd3257 | 83 | } \ |
ADIJake | 0:85855ecd3257 | 84 | } while(false) |
ADIJake | 0:85855ecd3257 | 85 | |
ADIJake | 0:85855ecd3257 | 86 | /* |
ADIJake | 0:85855ecd3257 | 87 | * Encapsulates the write to a specified register |
ADIJake | 0:85855ecd3257 | 88 | * NOTE - this will cause the calling function to return on error |
ADIJake | 0:85855ecd3257 | 89 | */ |
ADIJake | 0:85855ecd3257 | 90 | #define WRITE_REG(_hdev, _val, _name, _type) \ |
ADIJake | 0:85855ecd3257 | 91 | do { \ |
Vkadaba | 8:2f2775c34640 | 92 | ADMW_RESULT _res; \ |
ADIJake | 0:85855ecd3257 | 93 | _type _regval = _val; \ |
Vkadaba | 8:2f2775c34640 | 94 | _res = admw1001_WriteRegister((_hdev), \ |
Vkadaba | 8:2f2775c34640 | 95 | REG_##_name, \ |
ADIJake | 0:85855ecd3257 | 96 | &_regval, sizeof(_regval)); \ |
Vkadaba | 8:2f2775c34640 | 97 | if (_res != ADMW_SUCCESS) \ |
ADIJake | 0:85855ecd3257 | 98 | return _res; \ |
ADIJake | 0:85855ecd3257 | 99 | } while(false) |
ADIJake | 0:85855ecd3257 | 100 | |
ADIJake | 0:85855ecd3257 | 101 | /* Wrapper macro to write a value to a uint32_t register */ |
Vkadaba | 8:2f2775c34640 | 102 | #define WRITE_REG_U32(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 103 | WRITE_REG(_hdev, _val, _name, uint32_t) |
ADIJake | 0:85855ecd3257 | 104 | /* Wrapper macro to write a value to a uint16_t register */ |
Vkadaba | 8:2f2775c34640 | 105 | #define WRITE_REG_U16(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 106 | WRITE_REG(_hdev, _val, _name, uint16_t) |
ADIJake | 0:85855ecd3257 | 107 | /* Wrapper macro to write a value to a uint8_t register */ |
Vkadaba | 8:2f2775c34640 | 108 | #define WRITE_REG_U8(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 109 | WRITE_REG(_hdev, _val, _name, uint8_t) |
ADIJake | 0:85855ecd3257 | 110 | /* Wrapper macro to write a value to a float32_t register */ |
Vkadaba | 8:2f2775c34640 | 111 | #define WRITE_REG_FLOAT(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 112 | WRITE_REG(_hdev, _val, _name, float32_t) |
ADIJake | 0:85855ecd3257 | 113 | |
ADIJake | 0:85855ecd3257 | 114 | /* |
ADIJake | 0:85855ecd3257 | 115 | * Encapsulates the read from a specified register |
ADIJake | 0:85855ecd3257 | 116 | * NOTE - this will cause the calling function to return on error |
ADIJake | 0:85855ecd3257 | 117 | */ |
ADIJake | 0:85855ecd3257 | 118 | #define READ_REG(_hdev, _val, _name, _type) \ |
ADIJake | 0:85855ecd3257 | 119 | do { \ |
Vkadaba | 8:2f2775c34640 | 120 | ADMW_RESULT _res; \ |
ADIJake | 0:85855ecd3257 | 121 | _type _regval; \ |
Vkadaba | 8:2f2775c34640 | 122 | _res = admw1001_ReadRegister((_hdev), \ |
Vkadaba | 8:2f2775c34640 | 123 | REG_##_name, \ |
ADIJake | 0:85855ecd3257 | 124 | &_regval, sizeof(_regval)); \ |
Vkadaba | 8:2f2775c34640 | 125 | if (_res != ADMW_SUCCESS) \ |
ADIJake | 0:85855ecd3257 | 126 | return _res; \ |
ADIJake | 0:85855ecd3257 | 127 | _val = _regval; \ |
ADIJake | 0:85855ecd3257 | 128 | } while(false) |
ADIJake | 0:85855ecd3257 | 129 | |
ADIJake | 0:85855ecd3257 | 130 | /* Wrapper macro to read a value from a uint32_t register */ |
Vkadaba | 8:2f2775c34640 | 131 | #define READ_REG_U32(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 132 | READ_REG(_hdev, _val, _name, uint32_t) |
ADIJake | 0:85855ecd3257 | 133 | /* Wrapper macro to read a value from a uint16_t register */ |
Vkadaba | 8:2f2775c34640 | 134 | #define READ_REG_U16(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 135 | READ_REG(_hdev, _val, _name, uint16_t) |
ADIJake | 0:85855ecd3257 | 136 | /* Wrapper macro to read a value from a uint8_t register */ |
Vkadaba | 8:2f2775c34640 | 137 | #define READ_REG_U8(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 138 | READ_REG(_hdev, _val, _name, uint8_t) |
ADIJake | 0:85855ecd3257 | 139 | /* Wrapper macro to read a value from a float32_t register */ |
Vkadaba | 8:2f2775c34640 | 140 | #define READ_REG_FLOAT(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 141 | READ_REG(_hdev, _val, _name, float32_t) |
ADIJake | 0:85855ecd3257 | 142 | |
ADIJake | 0:85855ecd3257 | 143 | /* |
ADIJake | 0:85855ecd3257 | 144 | * Wrapper macro to write an array of values to a uint8_t register |
ADIJake | 0:85855ecd3257 | 145 | * NOTE - this is intended only for writing to a keyhole data register |
ADIJake | 0:85855ecd3257 | 146 | */ |
Vkadaba | 8:2f2775c34640 | 147 | #define WRITE_REG_U8_ARRAY(_hdev, _arr, _len, _name) \ |
Vkadaba | 6:9d393a9677f4 | 148 | do { \ |
Vkadaba | 8:2f2775c34640 | 149 | ADMW_RESULT _res; \ |
Vkadaba | 8:2f2775c34640 | 150 | _res = admw1001_WriteRegister(_hdev, \ |
Vkadaba | 8:2f2775c34640 | 151 | REG_##_name, \ |
Vkadaba | 6:9d393a9677f4 | 152 | _arr, _len); \ |
Vkadaba | 8:2f2775c34640 | 153 | if (_res != ADMW_SUCCESS) \ |
Vkadaba | 6:9d393a9677f4 | 154 | return _res; \ |
ADIJake | 0:85855ecd3257 | 155 | } while(false) |
ADIJake | 0:85855ecd3257 | 156 | |
ADIJake | 0:85855ecd3257 | 157 | /* |
ADIJake | 0:85855ecd3257 | 158 | * Wrapper macro to read an array of values from a uint8_t register |
ADIJake | 0:85855ecd3257 | 159 | * NOTE - this is intended only for reading from a keyhole data register |
ADIJake | 0:85855ecd3257 | 160 | */ |
Vkadaba | 6:9d393a9677f4 | 161 | #define READ_REG_U8_ARRAY(_hdev, _arr, _len, _name) \ |
Vkadaba | 6:9d393a9677f4 | 162 | do { \ |
Vkadaba | 8:2f2775c34640 | 163 | ADMW_RESULT _res; \ |
Vkadaba | 8:2f2775c34640 | 164 | _res = admw1001_ReadRegister((_hdev), \ |
Vkadaba | 8:2f2775c34640 | 165 | REG##_name, \ |
Vkadaba | 6:9d393a9677f4 | 166 | _arr, _len); \ |
Vkadaba | 8:2f2775c34640 | 167 | if (_res != ADMW_SUCCESS) \ |
Vkadaba | 6:9d393a9677f4 | 168 | return _res; \ |
ADIJake | 0:85855ecd3257 | 169 | } while(false) |
ADIJake | 0:85855ecd3257 | 170 | |
Vkadaba | 8:2f2775c34640 | 171 | #define ADMW1001_CHANNEL_IS_ADC(c) \ |
Vkadaba | 8:2f2775c34640 | 172 | ((c) >= ADMW1001_CH_ID_ANLG_1_UNIVERSAL && (c) <= ADMW1001_CH_ID_ANLG_2_DIFFERENTIAL) |
Vkadaba | 6:9d393a9677f4 | 173 | |
Vkadaba | 8:2f2775c34640 | 174 | #define ADMW1001_CHANNEL_IS_ADC_CJC(c) \ |
Vkadaba | 8:2f2775c34640 | 175 | ((c) >= ADMW1001_CH_ID_ANLG_1_UNIVERSAL && (c) <= ADMW1001_CH_ID_ANLG_2_UNIVERSAL) |
Vkadaba | 6:9d393a9677f4 | 176 | |
Vkadaba | 8:2f2775c34640 | 177 | #define ADMW1001_CHANNEL_IS_ADC_SENSOR(c) \ |
Vkadaba | 8:2f2775c34640 | 178 | ((c) >= ADMW1001_CH_ID_ANLG_1_UNIVERSAL && (c) <= ADMW1001_CH_ID_ANLG_2_UNIVERSAL) |
Vkadaba | 6:9d393a9677f4 | 179 | |
Vkadaba | 8:2f2775c34640 | 180 | #define ADMW1001_CHANNEL_IS_ADC_VOLTAGE(c) \ |
Vkadaba | 8:2f2775c34640 | 181 | ((c) == ADMW1001_CH_ID_ANLG_1_DIFFERENTIAL || ADMW1001_CH_ID_ANLG_2_DIFFERENTIAL) |
Vkadaba | 6:9d393a9677f4 | 182 | |
Vkadaba | 8:2f2775c34640 | 183 | #define ADMW1001_CHANNEL_IS_ADC_CURRENT(c) \ |
Vkadaba | 8:2f2775c34640 | 184 | ((c) == ADMW1001_CH_ID_ANLG_1_UNIVERSAL || (c) == ADMW1001_CH_ID_ANLG_2_UNIVERSAL) |
Vkadaba | 6:9d393a9677f4 | 185 | |
ADIJake | 0:85855ecd3257 | 186 | |
Vkadaba | 32:52445bef314d | 187 | //typedef struct { |
Vkadaba | 32:52445bef314d | 188 | // unsigned nDeviceIndex; |
Vkadaba | 32:52445bef314d | 189 | // ADMW_SPI_HANDLE hSpi; |
Vkadaba | 32:52445bef314d | 190 | // ADMW_GPIO_HANDLE hGpio; |
Vkadaba | 32:52445bef314d | 191 | // |
Vkadaba | 32:52445bef314d | 192 | //} ADMW_DEVICE_CONTEXT; |
Vkadaba | 5:0728bde67bdb | 193 | |
Vkadaba | 5:0728bde67bdb | 194 | static ADMW_DEVICE_CONTEXT gDeviceCtx[ADMW_PLATFORM_MAX_DEVICES]; |
ADIJake | 0:85855ecd3257 | 195 | |
ADIJake | 0:85855ecd3257 | 196 | /* |
Vkadaba | 5:0728bde67bdb | 197 | * Open an ADMW device instance. |
ADIJake | 0:85855ecd3257 | 198 | */ |
Vkadaba | 5:0728bde67bdb | 199 | ADMW_RESULT admw_Open( |
Vkadaba | 8:2f2775c34640 | 200 | unsigned const nDeviceIndex, |
Vkadaba | 5:0728bde67bdb | 201 | ADMW_CONNECTION * const pConnectionInfo, |
Vkadaba | 5:0728bde67bdb | 202 | ADMW_DEVICE_HANDLE * const phDevice) |
ADIJake | 0:85855ecd3257 | 203 | { |
Vkadaba | 5:0728bde67bdb | 204 | ADMW_DEVICE_CONTEXT *pCtx; |
Vkadaba | 5:0728bde67bdb | 205 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 206 | |
Vkadaba | 5:0728bde67bdb | 207 | if (nDeviceIndex >= ADMW_PLATFORM_MAX_DEVICES) |
Vkadaba | 5:0728bde67bdb | 208 | return ADMW_INVALID_DEVICE_NUM; |
ADIJake | 0:85855ecd3257 | 209 | |
ADIJake | 0:85855ecd3257 | 210 | pCtx = &gDeviceCtx[nDeviceIndex]; |
ADIJake | 0:85855ecd3257 | 211 | pCtx->nDeviceIndex = nDeviceIndex; |
ADIJake | 0:85855ecd3257 | 212 | |
Vkadaba | 5:0728bde67bdb | 213 | eRet = admw_LogOpen(&pConnectionInfo->log); |
Vkadaba | 5:0728bde67bdb | 214 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 215 | return eRet; |
ADIJake | 0:85855ecd3257 | 216 | |
Vkadaba | 5:0728bde67bdb | 217 | eRet = admw_GpioOpen(&pConnectionInfo->gpio, &pCtx->hGpio); |
Vkadaba | 5:0728bde67bdb | 218 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 219 | return eRet; |
ADIJake | 0:85855ecd3257 | 220 | |
Vkadaba | 5:0728bde67bdb | 221 | eRet = admw_SpiOpen(&pConnectionInfo->spi, &pCtx->hSpi); |
Vkadaba | 5:0728bde67bdb | 222 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 223 | return eRet; |
ADIJake | 0:85855ecd3257 | 224 | |
ADIJake | 0:85855ecd3257 | 225 | *phDevice = pCtx; |
Vkadaba | 5:0728bde67bdb | 226 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 227 | } |
ADIJake | 0:85855ecd3257 | 228 | |
ADIJake | 0:85855ecd3257 | 229 | /* |
ADIJake | 0:85855ecd3257 | 230 | * Get the current state of the specified GPIO input signal. |
ADIJake | 0:85855ecd3257 | 231 | */ |
Vkadaba | 5:0728bde67bdb | 232 | ADMW_RESULT admw_GetGpioState( |
Vkadaba | 5:0728bde67bdb | 233 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 234 | ADMW_GPIO_PIN const ePinId, |
ADIJake | 0:85855ecd3257 | 235 | bool * const pbAsserted) |
ADIJake | 0:85855ecd3257 | 236 | { |
Vkadaba | 5:0728bde67bdb | 237 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 5:0728bde67bdb | 238 | |
Vkadaba | 5:0728bde67bdb | 239 | return admw_GpioGet(pCtx->hGpio, ePinId, pbAsserted); |
ADIJake | 0:85855ecd3257 | 240 | } |
ADIJake | 0:85855ecd3257 | 241 | |
ADIJake | 0:85855ecd3257 | 242 | /* |
ADIJake | 0:85855ecd3257 | 243 | * Register an application-defined callback function for GPIO interrupts. |
ADIJake | 0:85855ecd3257 | 244 | */ |
Vkadaba | 5:0728bde67bdb | 245 | ADMW_RESULT admw_RegisterGpioCallback( |
Vkadaba | 5:0728bde67bdb | 246 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 247 | ADMW_GPIO_PIN const ePinId, |
Vkadaba | 5:0728bde67bdb | 248 | ADMW_GPIO_CALLBACK const callbackFunction, |
ADIJake | 0:85855ecd3257 | 249 | void * const pCallbackParam) |
ADIJake | 0:85855ecd3257 | 250 | { |
Vkadaba | 5:0728bde67bdb | 251 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
ADIJake | 0:85855ecd3257 | 252 | |
Vkadaba | 23:bb685f35b08b | 253 | if (callbackFunction) { |
Vkadaba | 5:0728bde67bdb | 254 | return admw_GpioIrqEnable(pCtx->hGpio, ePinId, callbackFunction, |
Vkadaba | 23:bb685f35b08b | 255 | pCallbackParam); |
Vkadaba | 23:bb685f35b08b | 256 | } else { |
Vkadaba | 5:0728bde67bdb | 257 | return admw_GpioIrqDisable(pCtx->hGpio, ePinId); |
ADIJake | 0:85855ecd3257 | 258 | } |
ADIJake | 0:85855ecd3257 | 259 | } |
ADIJake | 0:85855ecd3257 | 260 | |
Vkadaba | 8:2f2775c34640 | 261 | /*! |
Vkadaba | 8:2f2775c34640 | 262 | * @brief Reset the specified ADMW device. |
Vkadaba | 8:2f2775c34640 | 263 | * |
Vkadaba | 8:2f2775c34640 | 264 | * @param[in] hDevice - handle of ADMW device to reset. |
Vkadaba | 8:2f2775c34640 | 265 | * |
Vkadaba | 8:2f2775c34640 | 266 | * @return Status |
Vkadaba | 8:2f2775c34640 | 267 | * - #ADMW_SUCCESS Call completed successfully. |
Vkadaba | 8:2f2775c34640 | 268 | * - #ADMW_FAILURE If reseet faisl |
Vkadaba | 8:2f2775c34640 | 269 | * |
Vkadaba | 23:bb685f35b08b | 270 | * @details Toggle reset pin of the ADMW device low for a |
Vkadaba | 8:2f2775c34640 | 271 | * minimum of 4 usec. |
Vkadaba | 8:2f2775c34640 | 272 | * |
ADIJake | 0:85855ecd3257 | 273 | */ |
Vkadaba | 8:2f2775c34640 | 274 | ADMW_RESULT admw_Reset(ADMW_DEVICE_HANDLE const hDevice) |
ADIJake | 0:85855ecd3257 | 275 | { |
Vkadaba | 5:0728bde67bdb | 276 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 5:0728bde67bdb | 277 | ADMW_RESULT eRet; |
ADIJake | 0:85855ecd3257 | 278 | |
ADIJake | 0:85855ecd3257 | 279 | /* Pulse the Reset GPIO pin low for a minimum of 4 microseconds */ |
Vkadaba | 5:0728bde67bdb | 280 | eRet = admw_GpioSet(pCtx->hGpio, ADMW_GPIO_PIN_RESET, false); |
Vkadaba | 5:0728bde67bdb | 281 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 282 | return eRet; |
ADIJake | 0:85855ecd3257 | 283 | |
Vkadaba | 5:0728bde67bdb | 284 | admw_TimeDelayUsec(4); |
Vkadaba | 5:0728bde67bdb | 285 | |
Vkadaba | 5:0728bde67bdb | 286 | eRet = admw_GpioSet(pCtx->hGpio, ADMW_GPIO_PIN_RESET, true); |
Vkadaba | 5:0728bde67bdb | 287 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 288 | return eRet; |
ADIJake | 0:85855ecd3257 | 289 | |
Vkadaba | 5:0728bde67bdb | 290 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 291 | } |
ADIJake | 0:85855ecd3257 | 292 | |
ADIJake | 0:85855ecd3257 | 293 | /*! |
Vkadaba | 8:2f2775c34640 | 294 | * @brief Get general status of ADMW module. |
ADIJake | 0:85855ecd3257 | 295 | * |
ADIJake | 0:85855ecd3257 | 296 | * @param[in] |
ADIJake | 0:85855ecd3257 | 297 | * @param[out] pStatus : Pointer to CORE Status struct. |
ADIJake | 0:85855ecd3257 | 298 | * |
ADIJake | 0:85855ecd3257 | 299 | * @return Status |
Vkadaba | 5:0728bde67bdb | 300 | * - #ADMW_SUCCESS Call completed successfully. |
Vkadaba | 5:0728bde67bdb | 301 | * - #ADMW_FAILURE If status register read fails. |
ADIJake | 0:85855ecd3257 | 302 | * |
Vkadaba | 8:2f2775c34640 | 303 | * @details Read the general status register for the ADMW |
ADIJake | 0:85855ecd3257 | 304 | * module. Indicates Error, Alert conditions, data ready |
ADIJake | 0:85855ecd3257 | 305 | * and command running. |
ADIJake | 0:85855ecd3257 | 306 | * |
ADIJake | 0:85855ecd3257 | 307 | */ |
Vkadaba | 5:0728bde67bdb | 308 | ADMW_RESULT admw_GetStatus( |
Vkadaba | 5:0728bde67bdb | 309 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 310 | ADMW_STATUS * const pStatus) |
ADIJake | 0:85855ecd3257 | 311 | { |
Vkadaba | 8:2f2775c34640 | 312 | ADMW_CORE_Status_t statusReg; |
ADIJake | 0:85855ecd3257 | 313 | READ_REG_U8(hDevice, statusReg.VALUE8, CORE_STATUS); |
ADIJake | 0:85855ecd3257 | 314 | |
ADIJake | 0:85855ecd3257 | 315 | memset(pStatus, 0, sizeof(*pStatus)); |
ADIJake | 0:85855ecd3257 | 316 | |
ADIJake | 0:85855ecd3257 | 317 | if (!statusReg.Cmd_Running) /* Active-low, so invert it */ |
Vkadaba | 5:0728bde67bdb | 318 | pStatus->deviceStatus |= ADMW_DEVICE_STATUS_BUSY; |
ADIJake | 0:85855ecd3257 | 319 | if (statusReg.Drdy) |
Vkadaba | 5:0728bde67bdb | 320 | pStatus->deviceStatus |= ADMW_DEVICE_STATUS_DATAREADY; |
ADIJake | 0:85855ecd3257 | 321 | if (statusReg.FIFO_Error) |
Vkadaba | 5:0728bde67bdb | 322 | pStatus->deviceStatus |= ADMW_DEVICE_STATUS_FIFO_ERROR; |
Vkadaba | 23:bb685f35b08b | 323 | if (statusReg.Alert_Active) { |
Vkadaba | 5:0728bde67bdb | 324 | pStatus->deviceStatus |= ADMW_DEVICE_STATUS_ALERT; |
Vkadaba | 5:0728bde67bdb | 325 | |
Vkadaba | 8:2f2775c34640 | 326 | ADMW_CORE_Channel_Alert_Status_t channelAlertStatusReg; |
ADIJake | 0:85855ecd3257 | 327 | READ_REG_U16(hDevice, channelAlertStatusReg.VALUE16, |
ADIJake | 0:85855ecd3257 | 328 | CORE_CHANNEL_ALERT_STATUS); |
ADIJake | 0:85855ecd3257 | 329 | |
Vkadaba | 23:bb685f35b08b | 330 | for (unsigned i = 0; i < ADMW1001_MAX_CHANNELS; i++) { |
Vkadaba | 23:bb685f35b08b | 331 | if (channelAlertStatusReg.VALUE16 & (1 << i)) { |
Vkadaba | 8:2f2775c34640 | 332 | ADMW_CORE_Alert_Detail_Ch_t alertDetailReg; |
ADIJake | 0:85855ecd3257 | 333 | READ_REG_U16(hDevice, alertDetailReg.VALUE16, |
ADIJake | 0:85855ecd3257 | 334 | CORE_ALERT_DETAIL_CHn(i)); |
ADIJake | 0:85855ecd3257 | 335 | |
Vkadaba | 32:52445bef314d | 336 | if (alertDetailReg.ADC_Near_Overrange) |
Vkadaba | 32:52445bef314d | 337 | pStatus->channelAlerts[i] |= ADMW_ALERT_DETAIL_CH_ADC_NEAR_OVERRANGE; |
Vkadaba | 32:52445bef314d | 338 | if (alertDetailReg.Sensor_UnderRange) |
Vkadaba | 32:52445bef314d | 339 | pStatus->channelAlerts[i] |= ADMW_ALERT_DETAIL_CH_SENSOR_UNDERRANGE; |
Vkadaba | 32:52445bef314d | 340 | if (alertDetailReg.Sensor_OverRange) |
Vkadaba | 32:52445bef314d | 341 | pStatus->channelAlerts[i] |= ADMW_ALERT_DETAIL_CH_SENSOR_OVERRANGE ; |
Vkadaba | 32:52445bef314d | 342 | if (alertDetailReg.CJ_Soft_Fault) |
Vkadaba | 32:52445bef314d | 343 | pStatus->channelAlerts[i] |= ADMW_ALERT_DETAIL_CH_CJ_SOFT_FAULT ; |
Vkadaba | 32:52445bef314d | 344 | if (alertDetailReg.CJ_Hard_Fault) |
Vkadaba | 32:52445bef314d | 345 | pStatus->channelAlerts[i] |= ADMW_ALERT_DETAIL_CH_CJ_HARD_FAULT; |
Vkadaba | 32:52445bef314d | 346 | if (alertDetailReg.ADC_Input_OverRange) |
Vkadaba | 32:52445bef314d | 347 | pStatus->channelAlerts[i] |= ADMW_ALERT_DETAIL_CH_ADC_INPUT_OVERRANGE ; |
Vkadaba | 32:52445bef314d | 348 | if (alertDetailReg.Sensor_HardFault) |
Vkadaba | 32:52445bef314d | 349 | pStatus->channelAlerts[i] |= ADMW_ALERT_DETAIL_CH_SENSOR_HARDFAULT; |
Vkadaba | 32:52445bef314d | 350 | |
ADIJake | 0:85855ecd3257 | 351 | } |
ADIJake | 0:85855ecd3257 | 352 | } |
ADIJake | 0:85855ecd3257 | 353 | |
Vkadaba | 32:52445bef314d | 354 | if (statusReg.Configuration_Error) |
Vkadaba | 5:0728bde67bdb | 355 | pStatus->deviceStatus |= ADMW_DEVICE_STATUS_CONFIG_ERROR; |
Vkadaba | 32:52445bef314d | 356 | if (statusReg.LUT_Error) |
Vkadaba | 5:0728bde67bdb | 357 | pStatus->deviceStatus |= ADMW_DEVICE_STATUS_LUT_ERROR; |
ADIJake | 0:85855ecd3257 | 358 | } |
ADIJake | 0:85855ecd3257 | 359 | |
Vkadaba | 23:bb685f35b08b | 360 | if (statusReg.Error) { |
Vkadaba | 5:0728bde67bdb | 361 | pStatus->deviceStatus |= ADMW_DEVICE_STATUS_ERROR; |
Vkadaba | 5:0728bde67bdb | 362 | |
Vkadaba | 8:2f2775c34640 | 363 | ADMW_CORE_Error_Code_t errorCodeReg; |
ADIJake | 0:85855ecd3257 | 364 | READ_REG_U16(hDevice, errorCodeReg.VALUE16, CORE_ERROR_CODE); |
ADIJake | 0:85855ecd3257 | 365 | pStatus->errorCode = errorCodeReg.Error_Code; |
ADIJake | 0:85855ecd3257 | 366 | |
ADIJake | 0:85855ecd3257 | 367 | } |
Vkadaba | 5:0728bde67bdb | 368 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 369 | } |
ADIJake | 0:85855ecd3257 | 370 | |
Vkadaba | 5:0728bde67bdb | 371 | ADMW_RESULT admw_GetCommandRunningState( |
Vkadaba | 5:0728bde67bdb | 372 | ADMW_DEVICE_HANDLE hDevice, |
ADIJake | 0:85855ecd3257 | 373 | bool *pbCommandRunning) |
ADIJake | 0:85855ecd3257 | 374 | { |
Vkadaba | 8:2f2775c34640 | 375 | ADMW_CORE_Status_t statusReg; |
ADIJake | 0:85855ecd3257 | 376 | |
ADIJake | 0:85855ecd3257 | 377 | READ_REG_U8(hDevice, statusReg.VALUE8, CORE_STATUS); |
ADIJake | 0:85855ecd3257 | 378 | |
ADIJake | 0:85855ecd3257 | 379 | /* We should never normally see 0xFF here if the module is operational */ |
ADIJake | 0:85855ecd3257 | 380 | if (statusReg.VALUE8 == 0xFF) |
Vkadaba | 5:0728bde67bdb | 381 | return ADMW_ERR_NOT_INITIALIZED; |
ADIJake | 0:85855ecd3257 | 382 | |
ADIJake | 0:85855ecd3257 | 383 | *pbCommandRunning = !statusReg.Cmd_Running; /* Active-low, so invert it */ |
ADIJake | 0:85855ecd3257 | 384 | |
Vkadaba | 5:0728bde67bdb | 385 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 386 | } |
ADIJake | 0:85855ecd3257 | 387 | |
Vkadaba | 50:d84305e5e1c0 | 388 | ADMW_RESULT admw_deviceInformation(ADMW_DEVICE_HANDLE hDevice) |
Vkadaba | 32:52445bef314d | 389 | { |
Vkadaba | 32:52445bef314d | 390 | uint16_t nAddress = REG_CORE_REVISION; |
Vkadaba | 32:52445bef314d | 391 | char nData[ADMW_VERSION_REG_VAL_SIZE]; //4 Bytes of version register data |
Vkadaba | 32:52445bef314d | 392 | ADMW_RESULT res; |
Vkadaba | 32:52445bef314d | 393 | res=admw1001_ReadRegister(hDevice,nAddress,nData,sizeof(nData)); |
Vkadaba | 32:52445bef314d | 394 | if(res != ADMW_SUCCESS) { |
Vkadaba | 32:52445bef314d | 395 | //if reading version register failed, sending 00.00.0000 as ADMW1001 firmware version |
Vkadaba | 32:52445bef314d | 396 | //strcat(nData, ADMW1001_FIRMWARE_VERSION_DEFAULT); |
Vkadaba | 32:52445bef314d | 397 | ADMW_LOG_INFO("Firmware Version Id is %X.%X",nData[2],nData[0]); |
Vkadaba | 32:52445bef314d | 398 | } else { |
Vkadaba | 32:52445bef314d | 399 | char buffer[ADMW_FORMATTED_VERSION_SIZE]; //00.00.0000 8 digits + 2 Bytes "." + one null character at the end |
Vkadaba | 32:52445bef314d | 400 | strcat(nData, buffer); |
Vkadaba | 42:c9c5a22e539e | 401 | ADMW_LOG_INFO("Firmware Version Id is %X.%X.%X",nData[3],nData[2],nData[0]); |
Vkadaba | 32:52445bef314d | 402 | } |
Vkadaba | 32:52445bef314d | 403 | return ADMW_SUCCESS; |
Vkadaba | 32:52445bef314d | 404 | } |
Vkadaba | 55:215da406282b | 405 | |
Vkadaba | 5:0728bde67bdb | 406 | static ADMW_RESULT executeCommand( |
Vkadaba | 5:0728bde67bdb | 407 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 8:2f2775c34640 | 408 | ADMW_CORE_Command_Special_Command const command, |
ADIJake | 0:85855ecd3257 | 409 | bool const bWaitForCompletion) |
ADIJake | 0:85855ecd3257 | 410 | { |
Vkadaba | 8:2f2775c34640 | 411 | ADMW_CORE_Command_t commandReg; |
ADIJake | 0:85855ecd3257 | 412 | bool bCommandRunning; |
Vkadaba | 5:0728bde67bdb | 413 | ADMW_RESULT eRet; |
ADIJake | 0:85855ecd3257 | 414 | |
ADIJake | 0:85855ecd3257 | 415 | /* |
ADIJake | 0:85855ecd3257 | 416 | * Don't allow another command to be issued if one is already running, but |
Vkadaba | 6:9d393a9677f4 | 417 | * make an exception for ENUM_CORE_COMMAND_NOP which can be used to |
ADIJake | 0:85855ecd3257 | 418 | * request a running command to be stopped (e.g. continuous measurement) |
ADIJake | 0:85855ecd3257 | 419 | */ |
Vkadaba | 23:bb685f35b08b | 420 | if (command != ENUM_CORE_COMMAND_NOP) { |
Vkadaba | 5:0728bde67bdb | 421 | eRet = admw_GetCommandRunningState(hDevice, &bCommandRunning); |
ADIJake | 0:85855ecd3257 | 422 | if (eRet) |
ADIJake | 0:85855ecd3257 | 423 | return eRet; |
ADIJake | 0:85855ecd3257 | 424 | |
ADIJake | 0:85855ecd3257 | 425 | if (bCommandRunning) |
Vkadaba | 5:0728bde67bdb | 426 | return ADMW_IN_USE; |
ADIJake | 0:85855ecd3257 | 427 | } |
ADIJake | 0:85855ecd3257 | 428 | |
ADIJake | 0:85855ecd3257 | 429 | commandReg.Special_Command = command; |
ADIJake | 0:85855ecd3257 | 430 | WRITE_REG_U8(hDevice, commandReg.VALUE8, CORE_COMMAND); |
ADIJake | 0:85855ecd3257 | 431 | |
Vkadaba | 23:bb685f35b08b | 432 | if (bWaitForCompletion) { |
ADIJake | 0:85855ecd3257 | 433 | do { |
Vkadaba | 50:d84305e5e1c0 | 434 | /* Allow a minimum 100usec delay for status update before checking */ |
Vkadaba | 50:d84305e5e1c0 | 435 | admw_TimeDelayUsec(100); |
Vkadaba | 5:0728bde67bdb | 436 | |
Vkadaba | 5:0728bde67bdb | 437 | eRet = admw_GetCommandRunningState(hDevice, &bCommandRunning); |
ADIJake | 0:85855ecd3257 | 438 | if (eRet) |
ADIJake | 0:85855ecd3257 | 439 | return eRet; |
ADIJake | 0:85855ecd3257 | 440 | } while (bCommandRunning); |
ADIJake | 0:85855ecd3257 | 441 | } |
ADIJake | 0:85855ecd3257 | 442 | |
Vkadaba | 5:0728bde67bdb | 443 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 444 | } |
ADIJake | 0:85855ecd3257 | 445 | |
Vkadaba | 5:0728bde67bdb | 446 | ADMW_RESULT admw_ApplyConfigUpdates( |
Vkadaba | 5:0728bde67bdb | 447 | ADMW_DEVICE_HANDLE const hDevice) |
ADIJake | 0:85855ecd3257 | 448 | { |
Vkadaba | 5:0728bde67bdb | 449 | return executeCommand(hDevice, CORE_COMMAND_LATCH_CONFIG, true); |
ADIJake | 0:85855ecd3257 | 450 | } |
ADIJake | 0:85855ecd3257 | 451 | |
ADIJake | 0:85855ecd3257 | 452 | /*! |
ADIJake | 0:85855ecd3257 | 453 | * @brief Start a measurement cycle. |
ADIJake | 0:85855ecd3257 | 454 | * |
ADIJake | 0:85855ecd3257 | 455 | * @param[out] |
ADIJake | 0:85855ecd3257 | 456 | * |
ADIJake | 0:85855ecd3257 | 457 | * @return Status |
Vkadaba | 5:0728bde67bdb | 458 | * - #ADMW_SUCCESS Call completed successfully. |
Vkadaba | 5:0728bde67bdb | 459 | * - #ADMW_FAILURE |
ADIJake | 0:85855ecd3257 | 460 | * |
ADIJake | 0:85855ecd3257 | 461 | * @details Sends the latch config command. Configuration for channels in |
ADIJake | 0:85855ecd3257 | 462 | * conversion cycle should be completed before this function. |
ADIJake | 0:85855ecd3257 | 463 | * Channel enabled bit should be set before this function. |
ADIJake | 0:85855ecd3257 | 464 | * Starts a conversion and configures the format of the sample. |
ADIJake | 0:85855ecd3257 | 465 | * |
ADIJake | 0:85855ecd3257 | 466 | */ |
Vkadaba | 5:0728bde67bdb | 467 | ADMW_RESULT admw_StartMeasurement( |
Vkadaba | 5:0728bde67bdb | 468 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 469 | ADMW_MEASUREMENT_MODE const eMeasurementMode) |
ADIJake | 0:85855ecd3257 | 470 | { |
Vkadaba | 23:bb685f35b08b | 471 | switch (eMeasurementMode) { |
Vkadaba | 23:bb685f35b08b | 472 | case ADMW_MEASUREMENT_MODE_NORMAL: |
Vkadaba | 23:bb685f35b08b | 473 | return executeCommand(hDevice, CORE_COMMAND_CONVERT_WITH_RAW, false); |
Vkadaba | 23:bb685f35b08b | 474 | case ADMW_MEASUREMENT_MODE_OMIT_RAW: |
Vkadaba | 23:bb685f35b08b | 475 | return executeCommand(hDevice, CORE_COMMAND_CONVERT, false); |
Vkadaba | 23:bb685f35b08b | 476 | default: |
Vkadaba | 23:bb685f35b08b | 477 | ADMW_LOG_ERROR("Invalid measurement mode %d specified", |
Vkadaba | 23:bb685f35b08b | 478 | eMeasurementMode); |
Vkadaba | 23:bb685f35b08b | 479 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 480 | } |
ADIJake | 0:85855ecd3257 | 481 | } |
ADIJake | 0:85855ecd3257 | 482 | |
ADIJake | 0:85855ecd3257 | 483 | /* |
ADIJake | 0:85855ecd3257 | 484 | * Store the configuration settings to persistent memory on the device. |
ADIJake | 0:85855ecd3257 | 485 | * The settings can be saved to 4 different flash memory areas (slots). |
ADIJake | 0:85855ecd3257 | 486 | * No other command must be running when this is called. |
ADIJake | 0:85855ecd3257 | 487 | * Do not power down the device while this command is running. |
ADIJake | 0:85855ecd3257 | 488 | */ |
Vkadaba | 5:0728bde67bdb | 489 | ADMW_RESULT admw_SaveConfig( |
Vkadaba | 5:0728bde67bdb | 490 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 491 | ADMW_USER_CONFIG_SLOT const eSlotId) |
ADIJake | 0:85855ecd3257 | 492 | { |
Vkadaba | 23:bb685f35b08b | 493 | switch (eSlotId) { |
Vkadaba | 5:0728bde67bdb | 494 | case ADMW_FLASH_CONFIG_1: |
Vkadaba | 5:0728bde67bdb | 495 | return executeCommand(hDevice, CORE_COMMAND_SAVE_CONFIG_1, true); |
ADIJake | 0:85855ecd3257 | 496 | default: |
Vkadaba | 5:0728bde67bdb | 497 | ADMW_LOG_ERROR("Invalid user config target slot %d specified", |
Vkadaba | 23:bb685f35b08b | 498 | eSlotId); |
Vkadaba | 5:0728bde67bdb | 499 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 500 | } |
ADIJake | 0:85855ecd3257 | 501 | } |
ADIJake | 0:85855ecd3257 | 502 | |
ADIJake | 0:85855ecd3257 | 503 | /* |
ADIJake | 0:85855ecd3257 | 504 | * Restore the configuration settings from persistent memory on the device. |
ADIJake | 0:85855ecd3257 | 505 | * No other command must be running when this is called. |
ADIJake | 0:85855ecd3257 | 506 | */ |
Vkadaba | 5:0728bde67bdb | 507 | ADMW_RESULT admw_RestoreConfig( |
Vkadaba | 5:0728bde67bdb | 508 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 509 | ADMW_USER_CONFIG_SLOT const eSlotId) |
ADIJake | 0:85855ecd3257 | 510 | { |
Vkadaba | 23:bb685f35b08b | 511 | switch (eSlotId) { |
Vkadaba | 5:0728bde67bdb | 512 | case ADMW_FLASH_CONFIG_1: |
Vkadaba | 5:0728bde67bdb | 513 | return executeCommand(hDevice, CORE_COMMAND_LOAD_CONFIG_1, true); |
ADIJake | 0:85855ecd3257 | 514 | default: |
Vkadaba | 5:0728bde67bdb | 515 | ADMW_LOG_ERROR("Invalid user config source slot %d specified", |
Vkadaba | 23:bb685f35b08b | 516 | eSlotId); |
Vkadaba | 5:0728bde67bdb | 517 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 518 | } |
ADIJake | 0:85855ecd3257 | 519 | } |
ADIJake | 0:85855ecd3257 | 520 | |
ADIJake | 0:85855ecd3257 | 521 | /* |
ADIJake | 0:85855ecd3257 | 522 | * Store the LUT data to persistent memory on the device. |
ADIJake | 0:85855ecd3257 | 523 | * No other command must be running when this is called. |
ADIJake | 0:85855ecd3257 | 524 | * Do not power down the device while this command is running. |
ADIJake | 0:85855ecd3257 | 525 | */ |
Vkadaba | 5:0728bde67bdb | 526 | ADMW_RESULT admw_SaveLutData( |
Vkadaba | 5:0728bde67bdb | 527 | ADMW_DEVICE_HANDLE const hDevice) |
ADIJake | 0:85855ecd3257 | 528 | { |
Vkadaba | 5:0728bde67bdb | 529 | return executeCommand(hDevice, CORE_COMMAND_SAVE_LUT, true); |
ADIJake | 0:85855ecd3257 | 530 | } |
ADIJake | 0:85855ecd3257 | 531 | |
ADIJake | 0:85855ecd3257 | 532 | /* |
ADIJake | 0:85855ecd3257 | 533 | * Restore the LUT data from persistent memory on the device. |
ADIJake | 0:85855ecd3257 | 534 | * No other command must be running when this is called. |
ADIJake | 0:85855ecd3257 | 535 | */ |
Vkadaba | 5:0728bde67bdb | 536 | ADMW_RESULT admw_RestoreLutData( |
Vkadaba | 5:0728bde67bdb | 537 | ADMW_DEVICE_HANDLE const hDevice) |
ADIJake | 0:85855ecd3257 | 538 | { |
Vkadaba | 5:0728bde67bdb | 539 | return executeCommand(hDevice, CORE_COMMAND_LOAD_LUT, true); |
ADIJake | 0:85855ecd3257 | 540 | } |
ADIJake | 0:85855ecd3257 | 541 | |
ADIJake | 0:85855ecd3257 | 542 | /* |
ADIJake | 0:85855ecd3257 | 543 | * Stop the measurement cycles on the device. |
ADIJake | 0:85855ecd3257 | 544 | * To be used only if a measurement command is currently running. |
ADIJake | 0:85855ecd3257 | 545 | */ |
Vkadaba | 5:0728bde67bdb | 546 | ADMW_RESULT admw_StopMeasurement( |
Vkadaba | 5:0728bde67bdb | 547 | ADMW_DEVICE_HANDLE const hDevice) |
ADIJake | 0:85855ecd3257 | 548 | { |
Vkadaba | 5:0728bde67bdb | 549 | return executeCommand(hDevice, CORE_COMMAND_NOP, true); |
ADIJake | 0:85855ecd3257 | 550 | } |
ADIJake | 0:85855ecd3257 | 551 | |
ADIJake | 0:85855ecd3257 | 552 | /* |
Vkadaba | 32:52445bef314d | 553 | * |
Vkadaba | 32:52445bef314d | 554 | */ |
Vkadaba | 32:52445bef314d | 555 | ADMW_RESULT admw1001_sendRun( ADMW_DEVICE_HANDLE const hDevice) |
Vkadaba | 32:52445bef314d | 556 | { |
Vkadaba | 32:52445bef314d | 557 | bool bitCommand; |
Vkadaba | 32:52445bef314d | 558 | ADMW_RESULT eRet; |
Vkadaba | 32:52445bef314d | 559 | uint8_t pinreg = 0x1; |
Vkadaba | 32:52445bef314d | 560 | |
Vkadaba | 32:52445bef314d | 561 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 32:52445bef314d | 562 | static uint8_t DataBuffer[SPI_BUFFER_SIZE] = {0}; |
Vkadaba | 32:52445bef314d | 563 | uint16_t nSize; |
Vkadaba | 32:52445bef314d | 564 | |
Vkadaba | 32:52445bef314d | 565 | //Construct Read Status command |
Vkadaba | 32:52445bef314d | 566 | DataBuffer[0] = 0x07; |
Vkadaba | 32:52445bef314d | 567 | DataBuffer[1] = 0x0E; //Packet ID |
Vkadaba | 32:52445bef314d | 568 | |
Vkadaba | 32:52445bef314d | 569 | DataBuffer[2] = 0x00; |
Vkadaba | 32:52445bef314d | 570 | DataBuffer[3] = 0x00; //Data words |
Vkadaba | 32:52445bef314d | 571 | |
Vkadaba | 32:52445bef314d | 572 | DataBuffer[4] = 0x45; |
Vkadaba | 32:52445bef314d | 573 | DataBuffer[5] = 0x00; //Command ID |
Vkadaba | 32:52445bef314d | 574 | |
Vkadaba | 32:52445bef314d | 575 | DataBuffer[6] = 0x00; |
Vkadaba | 32:52445bef314d | 576 | DataBuffer[7] = 0x50; |
Vkadaba | 32:52445bef314d | 577 | DataBuffer[8] = 0x00; |
Vkadaba | 32:52445bef314d | 578 | DataBuffer[9] = 0x00; //Address |
Vkadaba | 32:52445bef314d | 579 | |
Vkadaba | 32:52445bef314d | 580 | DataBuffer[10] = 0x95; |
Vkadaba | 32:52445bef314d | 581 | DataBuffer[11] = 0x00; |
Vkadaba | 32:52445bef314d | 582 | DataBuffer[12] = 0x00; |
Vkadaba | 32:52445bef314d | 583 | DataBuffer[13] = 0x00; //Checksum |
Vkadaba | 32:52445bef314d | 584 | |
Vkadaba | 32:52445bef314d | 585 | nSize = SFL_READ_STATUS_HDR_SIZE; |
Vkadaba | 32:52445bef314d | 586 | |
Vkadaba | 32:52445bef314d | 587 | do { |
Vkadaba | 32:52445bef314d | 588 | // Get the SFL command irq pin to check if SFL is ready to receive commands |
Vkadaba | 32:52445bef314d | 589 | // Status pin is not checked since SFL is just booted, there should not be any issue with SFL |
Vkadaba | 32:52445bef314d | 590 | eRet = admw_GetGpioState( hDevice, ADMW_GPIO_PIN_DATAREADY, &bitCommand ); |
Vkadaba | 32:52445bef314d | 591 | if( eRet != ADMW_SUCCESS) { |
Vkadaba | 32:52445bef314d | 592 | return eRet; |
Vkadaba | 32:52445bef314d | 593 | } |
Vkadaba | 32:52445bef314d | 594 | |
Vkadaba | 32:52445bef314d | 595 | // Command IRQ pin should be low and Status IRQ pin should be high for SFL to be in good state and ready to recieve commands |
Vkadaba | 32:52445bef314d | 596 | // pinreg == '0x00' - Error occured in SFL |
Vkadaba | 32:52445bef314d | 597 | // pinreg == '0x01' - SFL is ready to recieve commands |
Vkadaba | 32:52445bef314d | 598 | // pinreg == '0x02' - Error occured in handling any commands in SFL |
Vkadaba | 32:52445bef314d | 599 | // pinreg == '0x03' - SFL not booted |
Vkadaba | 32:52445bef314d | 600 | |
Vkadaba | 32:52445bef314d | 601 | pinreg = (bitCommand); |
Vkadaba | 32:52445bef314d | 602 | |
Vkadaba | 32:52445bef314d | 603 | } while(pinreg != 0x0u); |
Vkadaba | 32:52445bef314d | 604 | |
Vkadaba | 32:52445bef314d | 605 | eRet = admw_SpiTransfer(pCtx->hSpi, DataBuffer, NULL, |
Vkadaba | 32:52445bef314d | 606 | nSize, false); |
Vkadaba | 32:52445bef314d | 607 | |
Vkadaba | 32:52445bef314d | 608 | return eRet; |
Vkadaba | 32:52445bef314d | 609 | } |
Vkadaba | 32:52445bef314d | 610 | |
Vkadaba | 32:52445bef314d | 611 | /* |
ADIJake | 0:85855ecd3257 | 612 | * Read a set of data samples from the device. |
ADIJake | 0:85855ecd3257 | 613 | * This may be called at any time. |
ADIJake | 0:85855ecd3257 | 614 | */ |
Vkadaba | 32:52445bef314d | 615 | |
Vkadaba | 5:0728bde67bdb | 616 | ADMW_RESULT admw_GetData( |
Vkadaba | 5:0728bde67bdb | 617 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 618 | ADMW_MEASUREMENT_MODE const eMeasurementMode, |
Vkadaba | 5:0728bde67bdb | 619 | ADMW_DATA_SAMPLE * const pSamples, |
ADIJake | 0:85855ecd3257 | 620 | uint8_t const nBytesPerSample, |
ADIJake | 0:85855ecd3257 | 621 | uint32_t const nRequested, |
ADIJake | 0:85855ecd3257 | 622 | uint32_t * const pnReturned) |
ADIJake | 0:85855ecd3257 | 623 | { |
Vkadaba | 5:0728bde67bdb | 624 | ADMW1001_Sensor_Result_t sensorResult; |
Vkadaba | 5:0728bde67bdb | 625 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 5:0728bde67bdb | 626 | uint16_t command = ADMW1001_HOST_COMMS_READ_CMD | |
Vkadaba | 23:bb685f35b08b | 627 | (REG_CORE_DATA_FIFO & ADMW1001_HOST_COMMS_ADR_MASK); |
ADIJake | 0:85855ecd3257 | 628 | uint8_t commandData[2] = { |
ADIJake | 0:85855ecd3257 | 629 | command >> 8, |
ADIJake | 0:85855ecd3257 | 630 | command & 0xFF |
ADIJake | 0:85855ecd3257 | 631 | }; |
ADIJake | 0:85855ecd3257 | 632 | uint8_t commandResponse[2]; |
ADIJake | 0:85855ecd3257 | 633 | unsigned nValidSamples = 0; |
Vkadaba | 5:0728bde67bdb | 634 | ADMW_RESULT eRet = ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 635 | |
ADIJake | 0:85855ecd3257 | 636 | do { |
Vkadaba | 5:0728bde67bdb | 637 | eRet = admw_SpiTransfer(pCtx->hSpi, commandData, commandResponse, |
Vkadaba | 23:bb685f35b08b | 638 | sizeof(command), false); |
Vkadaba | 23:bb685f35b08b | 639 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 640 | ADMW_LOG_ERROR("Failed to send read command for FIFO register"); |
ADIJake | 0:85855ecd3257 | 641 | return eRet; |
ADIJake | 0:85855ecd3257 | 642 | } |
Vkadaba | 5:0728bde67bdb | 643 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 5:0728bde67bdb | 644 | } while ((commandResponse[0] != ADMW1001_HOST_COMMS_CMD_RESP_0) || |
Vkadaba | 5:0728bde67bdb | 645 | (commandResponse[1] != ADMW1001_HOST_COMMS_CMD_RESP_1)); |
Vkadaba | 50:d84305e5e1c0 | 646 | |
Vkadaba | 23:bb685f35b08b | 647 | for (unsigned i = 0; i < nRequested; i++) { |
Vkadaba | 65:d91e1d63153d | 648 | |
ADIJake | 0:85855ecd3257 | 649 | bool bHoldCs = true; |
ADIJake | 0:85855ecd3257 | 650 | /* Keep the CS signal asserted for all but the last sample */ |
ADIJake | 0:85855ecd3257 | 651 | if ((i + 1) == nRequested) |
ADIJake | 0:85855ecd3257 | 652 | bHoldCs = false; |
ADIJake | 0:85855ecd3257 | 653 | |
ADIJake | 0:85855ecd3257 | 654 | getDataCnt++; |
ADIJake | 0:85855ecd3257 | 655 | |
Vkadaba | 5:0728bde67bdb | 656 | eRet = admw_SpiTransfer(pCtx->hSpi, NULL, &sensorResult, |
Vkadaba | 23:bb685f35b08b | 657 | nBytesPerSample, bHoldCs); |
Vkadaba | 23:bb685f35b08b | 658 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 659 | ADMW_LOG_ERROR("Failed to read data from FIFO register"); |
ADIJake | 0:85855ecd3257 | 660 | return eRet; |
ADIJake | 0:85855ecd3257 | 661 | } |
ADIJake | 0:85855ecd3257 | 662 | |
Vkadaba | 23:bb685f35b08b | 663 | if (! sensorResult.Ch_Valid) { |
ADIJake | 0:85855ecd3257 | 664 | /* |
ADIJake | 0:85855ecd3257 | 665 | * Reading an invalid sample indicates that there are no |
ADIJake | 0:85855ecd3257 | 666 | * more samples available or we've lost sync with the device. |
ADIJake | 0:85855ecd3257 | 667 | * In the latter case, it might be recoverable, but return here |
ADIJake | 0:85855ecd3257 | 668 | * to let the application check the device status and decide itself. |
ADIJake | 0:85855ecd3257 | 669 | */ |
Vkadaba | 5:0728bde67bdb | 670 | eRet = ADMW_INCOMPLETE; |
ADIJake | 0:85855ecd3257 | 671 | break; |
ADIJake | 0:85855ecd3257 | 672 | } |
ADIJake | 0:85855ecd3257 | 673 | |
Vkadaba | 5:0728bde67bdb | 674 | ADMW_DATA_SAMPLE *pSample = &pSamples[nValidSamples]; |
Vkadaba | 65:d91e1d63153d | 675 | memcpy(pSample,&sensorResult,sizeof(sensorResult)); |
ADIJake | 0:85855ecd3257 | 676 | nValidSamples++; |
ADIJake | 0:85855ecd3257 | 677 | |
Vkadaba | 50:d84305e5e1c0 | 678 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
ADIJake | 0:85855ecd3257 | 679 | } |
ADIJake | 0:85855ecd3257 | 680 | *pnReturned = nValidSamples; |
ADIJake | 0:85855ecd3257 | 681 | |
ADIJake | 0:85855ecd3257 | 682 | return eRet; |
ADIJake | 0:85855ecd3257 | 683 | } |
ADIJake | 0:85855ecd3257 | 684 | |
ADIJake | 0:85855ecd3257 | 685 | /* |
Vkadaba | 5:0728bde67bdb | 686 | * Close the given ADMW device. |
ADIJake | 0:85855ecd3257 | 687 | */ |
Vkadaba | 5:0728bde67bdb | 688 | ADMW_RESULT admw_Close( |
Vkadaba | 5:0728bde67bdb | 689 | ADMW_DEVICE_HANDLE const hDevice) |
ADIJake | 0:85855ecd3257 | 690 | { |
Vkadaba | 5:0728bde67bdb | 691 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 5:0728bde67bdb | 692 | |
Vkadaba | 5:0728bde67bdb | 693 | admw_GpioClose(pCtx->hGpio); |
Vkadaba | 5:0728bde67bdb | 694 | admw_SpiClose(pCtx->hSpi); |
Vkadaba | 5:0728bde67bdb | 695 | admw_LogClose(); |
Vkadaba | 5:0728bde67bdb | 696 | |
Vkadaba | 5:0728bde67bdb | 697 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 698 | } |
ADIJake | 0:85855ecd3257 | 699 | |
Vkadaba | 5:0728bde67bdb | 700 | ADMW_RESULT admw1001_WriteRegister( |
Vkadaba | 5:0728bde67bdb | 701 | ADMW_DEVICE_HANDLE hDevice, |
ADIJake | 0:85855ecd3257 | 702 | uint16_t nAddress, |
ADIJake | 0:85855ecd3257 | 703 | void *pData, |
ADIJake | 0:85855ecd3257 | 704 | unsigned nLength) |
ADIJake | 0:85855ecd3257 | 705 | { |
Vkadaba | 5:0728bde67bdb | 706 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 707 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 5:0728bde67bdb | 708 | uint16_t command = ADMW1001_HOST_COMMS_WRITE_CMD | |
Vkadaba | 23:bb685f35b08b | 709 | (nAddress & ADMW1001_HOST_COMMS_ADR_MASK); |
ADIJake | 0:85855ecd3257 | 710 | uint8_t commandData[2] = { |
ADIJake | 0:85855ecd3257 | 711 | command >> 8, |
ADIJake | 0:85855ecd3257 | 712 | command & 0xFF |
ADIJake | 0:85855ecd3257 | 713 | }; |
ADIJake | 0:85855ecd3257 | 714 | uint8_t commandResponse[2]; |
ADIJake | 0:85855ecd3257 | 715 | |
ADIJake | 0:85855ecd3257 | 716 | do { |
Vkadaba | 5:0728bde67bdb | 717 | eRet = admw_SpiTransfer(pCtx->hSpi, commandData, commandResponse, |
Vkadaba | 23:bb685f35b08b | 718 | sizeof(command), false); |
Vkadaba | 23:bb685f35b08b | 719 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 720 | ADMW_LOG_ERROR("Failed to send write command for register %u", |
Vkadaba | 23:bb685f35b08b | 721 | nAddress); |
ADIJake | 0:85855ecd3257 | 722 | return eRet; |
ADIJake | 0:85855ecd3257 | 723 | } |
ADIJake | 0:85855ecd3257 | 724 | |
Vkadaba | 5:0728bde67bdb | 725 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 5:0728bde67bdb | 726 | } while ((commandResponse[0] != ADMW1001_HOST_COMMS_CMD_RESP_0) || |
Vkadaba | 5:0728bde67bdb | 727 | (commandResponse[1] != ADMW1001_HOST_COMMS_CMD_RESP_1)); |
Vkadaba | 5:0728bde67bdb | 728 | |
Vkadaba | 5:0728bde67bdb | 729 | eRet = admw_SpiTransfer(pCtx->hSpi, pData, NULL, nLength, false); |
Vkadaba | 23:bb685f35b08b | 730 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 731 | ADMW_LOG_ERROR("Failed to write data (%dB) to register %u", |
Vkadaba | 23:bb685f35b08b | 732 | nLength, nAddress); |
ADIJake | 0:85855ecd3257 | 733 | return eRet; |
ADIJake | 0:85855ecd3257 | 734 | } |
ADIJake | 0:85855ecd3257 | 735 | |
Vkadaba | 5:0728bde67bdb | 736 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 5:0728bde67bdb | 737 | |
Vkadaba | 5:0728bde67bdb | 738 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 739 | } |
ADIJake | 0:85855ecd3257 | 740 | |
Vkadaba | 64:e8670e971e22 | 741 | ADMW_RESULT admw_GetDeviceReadyState( |
Vkadaba | 64:e8670e971e22 | 742 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 64:e8670e971e22 | 743 | bool * const bReady) |
Vkadaba | 6:9d393a9677f4 | 744 | { |
Vkadaba | 64:e8670e971e22 | 745 | ADMW_SPI_Chip_Type_t chipTypeReg; |
Vkadaba | 6:9d393a9677f4 | 746 | |
Vkadaba | 64:e8670e971e22 | 747 | READ_REG_U8(hDevice, chipTypeReg.VALUE8, SPI_CHIP_TYPE); |
Vkadaba | 64:e8670e971e22 | 748 | /* If we read this register successfully, assume the device is ready */ |
Vkadaba | 64:e8670e971e22 | 749 | *bReady = (chipTypeReg.VALUE8 == REG_SPI_CHIP_TYPE_RESET); |
Vkadaba | 6:9d393a9677f4 | 750 | |
Vkadaba | 6:9d393a9677f4 | 751 | return ADMW_SUCCESS; |
Vkadaba | 6:9d393a9677f4 | 752 | } |
Vkadaba | 64:e8670e971e22 | 753 | |
Vkadaba | 5:0728bde67bdb | 754 | ADMW_RESULT admw1001_ReadRegister( |
Vkadaba | 5:0728bde67bdb | 755 | ADMW_DEVICE_HANDLE hDevice, |
ADIJake | 0:85855ecd3257 | 756 | uint16_t nAddress, |
ADIJake | 0:85855ecd3257 | 757 | void *pData, |
ADIJake | 0:85855ecd3257 | 758 | unsigned nLength) |
ADIJake | 0:85855ecd3257 | 759 | { |
Vkadaba | 5:0728bde67bdb | 760 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 761 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 5:0728bde67bdb | 762 | uint16_t command = ADMW1001_HOST_COMMS_READ_CMD | |
Vkadaba | 23:bb685f35b08b | 763 | (nAddress & ADMW1001_HOST_COMMS_ADR_MASK); |
ADIJake | 0:85855ecd3257 | 764 | uint8_t commandData[2] = { |
ADIJake | 0:85855ecd3257 | 765 | command >> 8, |
ADIJake | 0:85855ecd3257 | 766 | command & 0xFF |
ADIJake | 0:85855ecd3257 | 767 | }; |
ADIJake | 0:85855ecd3257 | 768 | uint8_t commandResponse[2]; |
ADIJake | 0:85855ecd3257 | 769 | |
ADIJake | 0:85855ecd3257 | 770 | do { |
Vkadaba | 5:0728bde67bdb | 771 | eRet = admw_SpiTransfer(pCtx->hSpi, commandData, commandResponse, |
Vkadaba | 23:bb685f35b08b | 772 | sizeof(command), false); |
Vkadaba | 23:bb685f35b08b | 773 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 774 | ADMW_LOG_ERROR("Failed to send read command for register %u", |
Vkadaba | 23:bb685f35b08b | 775 | nAddress); |
ADIJake | 0:85855ecd3257 | 776 | return eRet; |
ADIJake | 0:85855ecd3257 | 777 | } |
ADIJake | 0:85855ecd3257 | 778 | |
Vkadaba | 5:0728bde67bdb | 779 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 5:0728bde67bdb | 780 | } while ((commandResponse[0] != ADMW1001_HOST_COMMS_CMD_RESP_0) || |
Vkadaba | 5:0728bde67bdb | 781 | (commandResponse[1] != ADMW1001_HOST_COMMS_CMD_RESP_1)); |
Vkadaba | 5:0728bde67bdb | 782 | |
Vkadaba | 5:0728bde67bdb | 783 | eRet = admw_SpiTransfer(pCtx->hSpi, NULL, pData, nLength, false); |
Vkadaba | 23:bb685f35b08b | 784 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 785 | ADMW_LOG_ERROR("Failed to read data (%uB) from register %u", |
Vkadaba | 23:bb685f35b08b | 786 | nLength, nAddress); |
ADIJake | 0:85855ecd3257 | 787 | return eRet; |
ADIJake | 0:85855ecd3257 | 788 | } |
ADIJake | 0:85855ecd3257 | 789 | |
Vkadaba | 5:0728bde67bdb | 790 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 5:0728bde67bdb | 791 | |
Vkadaba | 5:0728bde67bdb | 792 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 793 | } |
ADIJake | 0:85855ecd3257 | 794 | |
Vkadaba | 5:0728bde67bdb | 795 | ADMW_RESULT admw1001_GetDataReadyModeInfo( |
Vkadaba | 8:2f2775c34640 | 796 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 8:2f2775c34640 | 797 | ADMW_MEASUREMENT_MODE const eMeasurementMode, |
Vkadaba | 5:0728bde67bdb | 798 | ADMW1001_OPERATING_MODE * const peOperatingMode, |
Vkadaba | 5:0728bde67bdb | 799 | ADMW1001_DATAREADY_MODE * const peDataReadyMode, |
Vkadaba | 8:2f2775c34640 | 800 | uint32_t * const pnSamplesPerDataready, |
Vkadaba | 8:2f2775c34640 | 801 | uint32_t * const pnSamplesPerCycle, |
Vkadaba | 8:2f2775c34640 | 802 | uint8_t * const pnBytesPerSample) |
ADIJake | 0:85855ecd3257 | 803 | { |
ADIJake | 0:85855ecd3257 | 804 | unsigned nChannelsEnabled = 0; |
ADIJake | 0:85855ecd3257 | 805 | unsigned nSamplesPerCycle = 0; |
ADIJake | 0:85855ecd3257 | 806 | |
Vkadaba | 8:2f2775c34640 | 807 | ADMW_CORE_Mode_t modeReg; |
ADIJake | 0:85855ecd3257 | 808 | READ_REG_U8(hDevice, modeReg.VALUE8, CORE_MODE); |
ADIJake | 0:85855ecd3257 | 809 | |
Vkadaba | 57:c6275de14bc5 | 810 | if (modeReg.Conversion_Mode == CORE_MODE_SINGLECYCLE) |
Vkadaba | 50:d84305e5e1c0 | 811 | *peOperatingMode = ADMW1001_OPERATING_MODE_SINGLECYCLE; |
Vkadaba | 50:d84305e5e1c0 | 812 | else |
Vkadaba | 50:d84305e5e1c0 | 813 | *peOperatingMode = ADMW1001_OPERATING_MODE_CONTINUOUS; |
ADIJake | 0:85855ecd3257 | 814 | |
Vkadaba | 23:bb685f35b08b | 815 | if (eMeasurementMode == ADMW_MEASUREMENT_MODE_OMIT_RAW) { |
Vkadaba | 50:d84305e5e1c0 | 816 | *pnBytesPerSample = 8; |
Vkadaba | 23:bb685f35b08b | 817 | } else { |
Vkadaba | 50:d84305e5e1c0 | 818 | *pnBytesPerSample = 12; |
Vkadaba | 6:9d393a9677f4 | 819 | } |
Vkadaba | 23:bb685f35b08b | 820 | |
Vkadaba | 8:2f2775c34640 | 821 | for (ADMW1001_CH_ID chId = ADMW1001_CH_ID_ANLG_1_UNIVERSAL; |
Vkadaba | 23:bb685f35b08b | 822 | chId < ADMW1001_MAX_CHANNELS; |
Vkadaba | 23:bb685f35b08b | 823 | chId++) { |
Vkadaba | 8:2f2775c34640 | 824 | ADMW_CORE_Sensor_Details_t sensorDetailsReg; |
Vkadaba | 8:2f2775c34640 | 825 | ADMW_CORE_Channel_Count_t channelCountReg; |
Vkadaba | 23:bb685f35b08b | 826 | |
Vkadaba | 23:bb685f35b08b | 827 | |
Vkadaba | 8:2f2775c34640 | 828 | READ_REG_U8(hDevice, channelCountReg.VALUE8, CORE_CHANNEL_COUNTn(chId)); |
Vkadaba | 8:2f2775c34640 | 829 | READ_REG_U32(hDevice, sensorDetailsReg.VALUE32, CORE_SENSOR_DETAILSn(chId)); |
Vkadaba | 23:bb685f35b08b | 830 | |
Vkadaba | 41:df78b7d7b675 | 831 | if (channelCountReg.Channel_Enable && !sensorDetailsReg.Do_Not_Publish) { |
Vkadaba | 8:2f2775c34640 | 832 | unsigned nActualChannels = 1; |
Vkadaba | 63:2655a04c00f5 | 833 | |
Vkadaba | 8:2f2775c34640 | 834 | nChannelsEnabled += nActualChannels; |
Vkadaba | 23:bb685f35b08b | 835 | |
Vkadaba | 8:2f2775c34640 | 836 | nSamplesPerCycle += nActualChannels * |
Vkadaba | 8:2f2775c34640 | 837 | (channelCountReg.Channel_Count + 1); |
ADIJake | 0:85855ecd3257 | 838 | } |
Vkadaba | 6:9d393a9677f4 | 839 | } |
Vkadaba | 23:bb685f35b08b | 840 | |
Vkadaba | 23:bb685f35b08b | 841 | if (nChannelsEnabled == 0) { |
Vkadaba | 8:2f2775c34640 | 842 | *pnSamplesPerDataready = 0; |
Vkadaba | 8:2f2775c34640 | 843 | *pnSamplesPerCycle = 0; |
Vkadaba | 8:2f2775c34640 | 844 | return ADMW_SUCCESS; |
Vkadaba | 6:9d393a9677f4 | 845 | } |
Vkadaba | 23:bb685f35b08b | 846 | |
Vkadaba | 6:9d393a9677f4 | 847 | *pnSamplesPerCycle = nSamplesPerCycle; |
Vkadaba | 23:bb685f35b08b | 848 | |
Vkadaba | 23:bb685f35b08b | 849 | if (modeReg.Drdy_Mode == CORE_MODE_DRDY_PER_CONVERSION) { |
Vkadaba | 8:2f2775c34640 | 850 | *pnSamplesPerDataready = 1; |
Vkadaba | 50:d84305e5e1c0 | 851 | } else if (modeReg.Drdy_Mode == CORE_MODE_DRDY_PER_CYCLE) { |
Vkadaba | 50:d84305e5e1c0 | 852 | *pnSamplesPerDataready = nSamplesPerCycle; |
Vkadaba | 50:d84305e5e1c0 | 853 | } else if (modeReg.Drdy_Mode == CORE_MODE_DRDY_PER_FIFO_FILL) { |
Vkadaba | 50:d84305e5e1c0 | 854 | ADMW_CORE_Fifo_Num_Cycles_t fifoNumCyclesReg; |
Vkadaba | 50:d84305e5e1c0 | 855 | |
Vkadaba | 50:d84305e5e1c0 | 856 | READ_REG_U8(hDevice, fifoNumCyclesReg.VALUE8, CORE_FIFO_NUM_CYCLES); |
Vkadaba | 50:d84305e5e1c0 | 857 | |
Vkadaba | 50:d84305e5e1c0 | 858 | *pnSamplesPerDataready = nSamplesPerCycle * fifoNumCyclesReg.Fifo_Num_Cycles; |
Vkadaba | 23:bb685f35b08b | 859 | } else { |
Vkadaba | 50:d84305e5e1c0 | 860 | ADMW_LOG_ERROR("Invalid DRDY mode %d specified", |
Vkadaba | 50:d84305e5e1c0 | 861 | modeReg.Drdy_Mode); |
Vkadaba | 50:d84305e5e1c0 | 862 | return ADMW_INVALID_PARAM; |
Vkadaba | 6:9d393a9677f4 | 863 | } |
Vkadaba | 23:bb685f35b08b | 864 | |
Vkadaba | 23:bb685f35b08b | 865 | if (modeReg.Drdy_Mode == CORE_MODE_DRDY_PER_CONVERSION) { |
Vkadaba | 8:2f2775c34640 | 866 | *peDataReadyMode = ADMW1001_DATAREADY_PER_CONVERSION; |
Vkadaba | 50:d84305e5e1c0 | 867 | } else if (modeReg.Drdy_Mode == CORE_MODE_DRDY_PER_CYCLE) { |
Vkadaba | 50:d84305e5e1c0 | 868 | *peDataReadyMode = ADMW1001_DATAREADY_PER_CYCLE; |
Vkadaba | 50:d84305e5e1c0 | 869 | } else if (modeReg.Drdy_Mode == CORE_MODE_DRDY_PER_FIFO_FILL) { |
Vkadaba | 50:d84305e5e1c0 | 870 | *peDataReadyMode = ADMW1001_DATAREADY_PER_FIFO_FILL; |
Vkadaba | 23:bb685f35b08b | 871 | } else { |
Vkadaba | 50:d84305e5e1c0 | 872 | ADMW_LOG_ERROR("Invalid DRDY mode %d specified", |
Vkadaba | 50:d84305e5e1c0 | 873 | modeReg.Drdy_Mode); |
Vkadaba | 50:d84305e5e1c0 | 874 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 875 | } |
Vkadaba | 23:bb685f35b08b | 876 | |
Vkadaba | 5:0728bde67bdb | 877 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 878 | } |
ADIJake | 0:85855ecd3257 | 879 | |
Vkadaba | 5:0728bde67bdb | 880 | ADMW_RESULT admw_GetProductID( |
Vkadaba | 5:0728bde67bdb | 881 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 882 | ADMW_PRODUCT_ID *pProductId) |
ADIJake | 0:85855ecd3257 | 883 | { |
Vkadaba | 5:0728bde67bdb | 884 | ADMW_SPI_Product_ID_L_t productIdLoReg; |
Vkadaba | 5:0728bde67bdb | 885 | ADMW_SPI_Product_ID_H_t productIdHiReg; |
ADIJake | 0:85855ecd3257 | 886 | |
ADIJake | 0:85855ecd3257 | 887 | READ_REG_U8(hDevice, productIdLoReg.VALUE8, SPI_PRODUCT_ID_L); |
ADIJake | 0:85855ecd3257 | 888 | READ_REG_U8(hDevice, productIdHiReg.VALUE8, SPI_PRODUCT_ID_H); |
ADIJake | 0:85855ecd3257 | 889 | |
Vkadaba | 23:bb685f35b08b | 890 | *pProductId = (ADMW_PRODUCT_ID)((productIdHiReg.VALUE8 << 8) | |
Vkadaba | 8:2f2775c34640 | 891 | productIdLoReg.VALUE8); |
Vkadaba | 5:0728bde67bdb | 892 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 893 | } |
ADIJake | 0:85855ecd3257 | 894 | |
Vkadaba | 5:0728bde67bdb | 895 | static ADMW_RESULT admw_SetPowerMode( |
Vkadaba | 5:0728bde67bdb | 896 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 897 | ADMW1001_POWER_MODE powerMode) |
ADIJake | 0:85855ecd3257 | 898 | { |
Vkadaba | 50:d84305e5e1c0 | 899 | ADMW_CORE_Power_Config_t powerConfigReg = { 0 }; |
Vkadaba | 5:0728bde67bdb | 900 | |
Vkadaba | 23:bb685f35b08b | 901 | if (powerMode == ADMW1001_POWER_MODE_HIBERNATION) { |
Vkadaba | 6:9d393a9677f4 | 902 | powerConfigReg.Power_Mode_MCU = CORE_POWER_CONFIG_HIBERNATION; |
Vkadaba | 23:bb685f35b08b | 903 | } else if (powerMode == ADMW1001_POWER_MODE_ACTIVE) { |
Vkadaba | 6:9d393a9677f4 | 904 | powerConfigReg.Power_Mode_MCU = CORE_POWER_CONFIG_ACTIVE_MODE; |
Vkadaba | 23:bb685f35b08b | 905 | } else { |
Vkadaba | 5:0728bde67bdb | 906 | ADMW_LOG_ERROR("Invalid power mode %d specified", powerMode); |
Vkadaba | 5:0728bde67bdb | 907 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 908 | } |
ADIJake | 0:85855ecd3257 | 909 | |
ADIJake | 0:85855ecd3257 | 910 | WRITE_REG_U8(hDevice, powerConfigReg.VALUE8, CORE_POWER_CONFIG); |
ADIJake | 0:85855ecd3257 | 911 | |
Vkadaba | 5:0728bde67bdb | 912 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 913 | } |
ADIJake | 0:85855ecd3257 | 914 | |
Vkadaba | 5:0728bde67bdb | 915 | ADMW_RESULT admw1001_SetPowerConfig( |
Vkadaba | 5:0728bde67bdb | 916 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 917 | ADMW1001_POWER_CONFIG *pPowerConfig) |
ADIJake | 0:85855ecd3257 | 918 | { |
Vkadaba | 5:0728bde67bdb | 919 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 920 | |
Vkadaba | 5:0728bde67bdb | 921 | eRet = admw_SetPowerMode(hDevice, pPowerConfig->powerMode); |
Vkadaba | 23:bb685f35b08b | 922 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 923 | ADMW_LOG_ERROR("Failed to set power mode"); |
ADIJake | 0:85855ecd3257 | 924 | return eRet; |
ADIJake | 0:85855ecd3257 | 925 | } |
ADIJake | 0:85855ecd3257 | 926 | |
Vkadaba | 5:0728bde67bdb | 927 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 928 | } |
ADIJake | 0:85855ecd3257 | 929 | |
Vkadaba | 33:df7a00f1b8e1 | 930 | static ADMW_RESULT admw_SetRSenseValue( |
Vkadaba | 33:df7a00f1b8e1 | 931 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 33:df7a00f1b8e1 | 932 | float32_t RSenseValue) |
Vkadaba | 33:df7a00f1b8e1 | 933 | { |
Vkadaba | 41:df78b7d7b675 | 934 | ADMW_CORE_External_Reference_Resistor_t RefResistorConfigReg; |
Vkadaba | 41:df78b7d7b675 | 935 | |
Vkadaba | 41:df78b7d7b675 | 936 | RefResistorConfigReg.Ext_Refin1_Value = RSenseValue; |
Vkadaba | 41:df78b7d7b675 | 937 | |
Vkadaba | 41:df78b7d7b675 | 938 | WRITE_REG_FLOAT(hDevice, RefResistorConfigReg.VALUE32, CORE_EXTERNAL_REFERENCE_RESISTOR); |
Vkadaba | 41:df78b7d7b675 | 939 | |
Vkadaba | 41:df78b7d7b675 | 940 | return ADMW_SUCCESS; |
Vkadaba | 33:df7a00f1b8e1 | 941 | |
Vkadaba | 33:df7a00f1b8e1 | 942 | } |
Vkadaba | 5:0728bde67bdb | 943 | static ADMW_RESULT admw_SetMode( |
Vkadaba | 5:0728bde67bdb | 944 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 945 | ADMW1001_OPERATING_MODE eOperatingMode, |
Vkadaba | 8:2f2775c34640 | 946 | ADMW1001_DATAREADY_MODE eDataReadyMode) |
ADIJake | 0:85855ecd3257 | 947 | { |
Vkadaba | 8:2f2775c34640 | 948 | ADMW_CORE_Mode_t modeReg; |
ADIJake | 0:85855ecd3257 | 949 | |
ADIJake | 0:85855ecd3257 | 950 | modeReg.VALUE8 = REG_RESET_VAL(CORE_MODE); |
ADIJake | 0:85855ecd3257 | 951 | |
Vkadaba | 23:bb685f35b08b | 952 | if (eOperatingMode == ADMW1001_OPERATING_MODE_SINGLECYCLE) { |
Vkadaba | 5:0728bde67bdb | 953 | modeReg.Conversion_Mode = CORE_MODE_SINGLECYCLE; |
Vkadaba | 23:bb685f35b08b | 954 | } else if (eOperatingMode == ADMW1001_OPERATING_MODE_CONTINUOUS) { |
Vkadaba | 5:0728bde67bdb | 955 | modeReg.Conversion_Mode = CORE_MODE_CONTINUOUS; |
Vkadaba | 23:bb685f35b08b | 956 | } else { |
Vkadaba | 5:0728bde67bdb | 957 | ADMW_LOG_ERROR("Invalid operating mode %d specified", |
Vkadaba | 23:bb685f35b08b | 958 | eOperatingMode); |
Vkadaba | 5:0728bde67bdb | 959 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 960 | } |
ADIJake | 0:85855ecd3257 | 961 | |
Vkadaba | 23:bb685f35b08b | 962 | if (eDataReadyMode == ADMW1001_DATAREADY_PER_CONVERSION) { |
Vkadaba | 5:0728bde67bdb | 963 | modeReg.Drdy_Mode = CORE_MODE_DRDY_PER_CONVERSION; |
Vkadaba | 23:bb685f35b08b | 964 | } else if (eDataReadyMode == ADMW1001_DATAREADY_PER_CYCLE) { |
Vkadaba | 5:0728bde67bdb | 965 | modeReg.Drdy_Mode = CORE_MODE_DRDY_PER_CYCLE; |
Vkadaba | 50:d84305e5e1c0 | 966 | } else if (eDataReadyMode == ADMW1001_DATAREADY_PER_FIFO_FILL) { |
Vkadaba | 50:d84305e5e1c0 | 967 | modeReg.Drdy_Mode = CORE_MODE_DRDY_PER_FIFO_FILL; |
Vkadaba | 23:bb685f35b08b | 968 | } else { |
Vkadaba | 5:0728bde67bdb | 969 | ADMW_LOG_ERROR("Invalid data-ready mode %d specified", eDataReadyMode); |
Vkadaba | 5:0728bde67bdb | 970 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 971 | } |
ADIJake | 0:85855ecd3257 | 972 | |
ADIJake | 0:85855ecd3257 | 973 | WRITE_REG_U8(hDevice, modeReg.VALUE8, CORE_MODE); |
ADIJake | 0:85855ecd3257 | 974 | |
Vkadaba | 5:0728bde67bdb | 975 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 976 | } |
ADIJake | 0:85855ecd3257 | 977 | |
Vkadaba | 8:2f2775c34640 | 978 | ADMW_RESULT admw_SetCycleControl(ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 979 | uint32_t nCycleInterval, |
Vkadaba | 50:d84305e5e1c0 | 980 | bool vBiasEnable, |
Vkadaba | 43:e1789b7214cf | 981 | bool vPostExecCurrentState, |
Vkadaba | 43:e1789b7214cf | 982 | bool vGroundSwitch) |
ADIJake | 0:85855ecd3257 | 983 | { |
Vkadaba | 8:2f2775c34640 | 984 | ADMW_CORE_Cycle_Control_t cycleControlReg; |
ADIJake | 0:85855ecd3257 | 985 | |
ADIJake | 0:85855ecd3257 | 986 | cycleControlReg.VALUE16 = REG_RESET_VAL(CORE_CYCLE_CONTROL); |
ADIJake | 0:85855ecd3257 | 987 | |
Vkadaba | 43:e1789b7214cf | 988 | if (nCycleInterval < (1 << 12)) { |
Vkadaba | 43:e1789b7214cf | 989 | cycleControlReg.Cycle_Time_Units = CORE_CYCLE_CONTROL_SECONDS; |
Vkadaba | 23:bb685f35b08b | 990 | } else { |
Vkadaba | 43:e1789b7214cf | 991 | ADMW_LOG_ERROR("Invalid nCycleInterval %d specified", nCycleInterval); |
Vkadaba | 50:d84305e5e1c0 | 992 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 993 | } |
ADIJake | 0:85855ecd3257 | 994 | |
Vkadaba | 23:bb685f35b08b | 995 | if (vBiasEnable == true) { |
Vkadaba | 8:2f2775c34640 | 996 | cycleControlReg.Vbias = 1; |
Vkadaba | 8:2f2775c34640 | 997 | } |
ADIJake | 0:85855ecd3257 | 998 | CHECK_REG_FIELD_VAL(CORE_CYCLE_CONTROL_CYCLE_TIME, nCycleInterval); |
ADIJake | 0:85855ecd3257 | 999 | cycleControlReg.Cycle_Time = nCycleInterval; |
Vkadaba | 50:d84305e5e1c0 | 1000 | |
Vkadaba | 50:d84305e5e1c0 | 1001 | switch(vPostExecCurrentState) { |
Vkadaba | 50:d84305e5e1c0 | 1002 | case ADMW1001_ADC_EXC_STATE_CYCLE_POWER: |
Vkadaba | 50:d84305e5e1c0 | 1003 | cycleControlReg.PST_MEAS_EXC_CTRL = CORE_CYCLE_CONTROL_POWERCYCLE; |
Vkadaba | 50:d84305e5e1c0 | 1004 | break; |
Vkadaba | 50:d84305e5e1c0 | 1005 | case ADMW1001_ADC_EXC_STATE_ALWAYS_ON: |
Vkadaba | 50:d84305e5e1c0 | 1006 | cycleControlReg.PST_MEAS_EXC_CTRL = CORE_CYCLE_CONTROL_ALWAYSON; |
Vkadaba | 50:d84305e5e1c0 | 1007 | break; |
Vkadaba | 50:d84305e5e1c0 | 1008 | default: |
Vkadaba | 50:d84305e5e1c0 | 1009 | ADMW_LOG_ERROR("Invalid Post measurement Excitation Current state %d specified", |
Vkadaba | 50:d84305e5e1c0 | 1010 | vPostExecCurrentState); |
Vkadaba | 50:d84305e5e1c0 | 1011 | return ADMW_INVALID_PARAM; |
Vkadaba | 43:e1789b7214cf | 1012 | } |
Vkadaba | 50:d84305e5e1c0 | 1013 | |
Vkadaba | 50:d84305e5e1c0 | 1014 | switch(vGroundSwitch) { |
Vkadaba | 50:d84305e5e1c0 | 1015 | case ADMW1001_ADC_GND_SW_OPEN: |
Vkadaba | 50:d84305e5e1c0 | 1016 | cycleControlReg.GND_SW_CTRL = CORE_CYCLE_CONTROL_OPEN_SW; |
Vkadaba | 50:d84305e5e1c0 | 1017 | break; |
Vkadaba | 50:d84305e5e1c0 | 1018 | case ADMW1001_ADC_GND_SW_CLOSED: |
Vkadaba | 50:d84305e5e1c0 | 1019 | cycleControlReg.GND_SW_CTRL = CORE_CYCLE_CONTROL_CLOSE_SW; |
Vkadaba | 50:d84305e5e1c0 | 1020 | break; |
Vkadaba | 50:d84305e5e1c0 | 1021 | default: |
Vkadaba | 50:d84305e5e1c0 | 1022 | ADMW_LOG_ERROR("Invalid ground switch state %d specified", |
Vkadaba | 50:d84305e5e1c0 | 1023 | vGroundSwitch); |
Vkadaba | 50:d84305e5e1c0 | 1024 | return ADMW_INVALID_PARAM; |
Vkadaba | 43:e1789b7214cf | 1025 | } |
Vkadaba | 50:d84305e5e1c0 | 1026 | |
ADIJake | 0:85855ecd3257 | 1027 | WRITE_REG_U16(hDevice, cycleControlReg.VALUE16, CORE_CYCLE_CONTROL); |
ADIJake | 0:85855ecd3257 | 1028 | |
Vkadaba | 5:0728bde67bdb | 1029 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1030 | } |
Vkadaba | 36:54e2418e7620 | 1031 | static ADMW_RESULT admw_SetExternalReferenceVoltage( |
Vkadaba | 36:54e2418e7620 | 1032 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 36:54e2418e7620 | 1033 | float32_t externalRefVoltage) |
Vkadaba | 36:54e2418e7620 | 1034 | { |
Vkadaba | 36:54e2418e7620 | 1035 | WRITE_REG_FLOAT(hDevice, externalRefVoltage, CORE_EXTERNAL_VOLTAGE_REFERENCE); |
Vkadaba | 36:54e2418e7620 | 1036 | |
Vkadaba | 36:54e2418e7620 | 1037 | return ADMW_SUCCESS; |
Vkadaba | 36:54e2418e7620 | 1038 | } |
Vkadaba | 50:d84305e5e1c0 | 1039 | static ADMW_RESULT admw_SetFifoNumCycles( |
Vkadaba | 50:d84305e5e1c0 | 1040 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 50:d84305e5e1c0 | 1041 | uint8_t fifoNumCycles) |
Vkadaba | 50:d84305e5e1c0 | 1042 | { |
Vkadaba | 50:d84305e5e1c0 | 1043 | WRITE_REG_U8(hDevice, fifoNumCycles, CORE_FIFO_NUM_CYCLES); |
Vkadaba | 50:d84305e5e1c0 | 1044 | |
Vkadaba | 50:d84305e5e1c0 | 1045 | return ADMW_SUCCESS; |
Vkadaba | 50:d84305e5e1c0 | 1046 | } |
ADIJake | 0:85855ecd3257 | 1047 | |
Vkadaba | 5:0728bde67bdb | 1048 | static ADMW_RESULT admw_SetExternalReferenceValues( |
Vkadaba | 5:0728bde67bdb | 1049 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 6:9d393a9677f4 | 1050 | float32_t externalRef1Value) |
ADIJake | 0:85855ecd3257 | 1051 | { |
Vkadaba | 6:9d393a9677f4 | 1052 | WRITE_REG_FLOAT(hDevice, externalRef1Value, CORE_EXTERNAL_REFERENCE_RESISTOR); |
ADIJake | 0:85855ecd3257 | 1053 | |
Vkadaba | 5:0728bde67bdb | 1054 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1055 | } |
Vkadaba | 45:f5f553b8c0d5 | 1056 | static ADMW_RESULT admw_SetAVDDVoltage( |
Vkadaba | 50:d84305e5e1c0 | 1057 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 50:d84305e5e1c0 | 1058 | float32_t AVDDVoltage) |
Vkadaba | 50:d84305e5e1c0 | 1059 | { |
Vkadaba | 45:f5f553b8c0d5 | 1060 | |
Vkadaba | 50:d84305e5e1c0 | 1061 | WRITE_REG_FLOAT(hDevice, AVDDVoltage, CORE_AVDD_VOLTAGE); |
Vkadaba | 45:f5f553b8c0d5 | 1062 | |
Vkadaba | 50:d84305e5e1c0 | 1063 | return ADMW_SUCCESS; |
Vkadaba | 50:d84305e5e1c0 | 1064 | } |
ADIJake | 0:85855ecd3257 | 1065 | |
Vkadaba | 5:0728bde67bdb | 1066 | ADMW_RESULT admw1001_SetMeasurementConfig( |
Vkadaba | 5:0728bde67bdb | 1067 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1068 | ADMW1001_MEASUREMENT_CONFIG *pMeasConfig) |
ADIJake | 0:85855ecd3257 | 1069 | { |
Vkadaba | 5:0728bde67bdb | 1070 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 1071 | |
Vkadaba | 5:0728bde67bdb | 1072 | eRet = admw_SetMode(hDevice, |
Vkadaba | 8:2f2775c34640 | 1073 | pMeasConfig->operatingMode, |
Vkadaba | 8:2f2775c34640 | 1074 | pMeasConfig->dataReadyMode); |
Vkadaba | 23:bb685f35b08b | 1075 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1076 | ADMW_LOG_ERROR("Failed to set operating mode"); |
ADIJake | 0:85855ecd3257 | 1077 | return eRet; |
ADIJake | 0:85855ecd3257 | 1078 | } |
ADIJake | 0:85855ecd3257 | 1079 | |
Vkadaba | 8:2f2775c34640 | 1080 | eRet = admw_SetCycleControl(hDevice, pMeasConfig->cycleInterval, |
Vkadaba | 43:e1789b7214cf | 1081 | pMeasConfig->vBiasEnable, |
Vkadaba | 43:e1789b7214cf | 1082 | pMeasConfig->excitationState, |
Vkadaba | 43:e1789b7214cf | 1083 | pMeasConfig->groundSwitch ); |
Vkadaba | 23:bb685f35b08b | 1084 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1085 | ADMW_LOG_ERROR("Failed to set cycle control"); |
ADIJake | 0:85855ecd3257 | 1086 | return eRet; |
ADIJake | 0:85855ecd3257 | 1087 | } |
ADIJake | 0:85855ecd3257 | 1088 | |
Vkadaba | 50:d84305e5e1c0 | 1089 | if (pMeasConfig->fifoNumCycles > 0) { |
Vkadaba | 50:d84305e5e1c0 | 1090 | eRet = admw_SetFifoNumCycles(hDevice, |
Vkadaba | 50:d84305e5e1c0 | 1091 | pMeasConfig->fifoNumCycles); |
Vkadaba | 50:d84305e5e1c0 | 1092 | } |
Vkadaba | 50:d84305e5e1c0 | 1093 | |
Vkadaba | 50:d84305e5e1c0 | 1094 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 50:d84305e5e1c0 | 1095 | ADMW_LOG_ERROR("Failed to set the FIFO number of cycles."); |
Vkadaba | 50:d84305e5e1c0 | 1096 | return eRet; |
Vkadaba | 50:d84305e5e1c0 | 1097 | } |
Vkadaba | 50:d84305e5e1c0 | 1098 | |
Vkadaba | 43:e1789b7214cf | 1099 | if(pMeasConfig->externalRef1Value > 0) { |
Vkadaba | 8:2f2775c34640 | 1100 | eRet = admw_SetExternalReferenceValues(hDevice, |
Vkadaba | 8:2f2775c34640 | 1101 | pMeasConfig->externalRef1Value); |
ADIJake | 0:85855ecd3257 | 1102 | } |
Vkadaba | 50:d84305e5e1c0 | 1103 | |
Vkadaba | 50:d84305e5e1c0 | 1104 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 50:d84305e5e1c0 | 1105 | ADMW_LOG_ERROR("Failed to set external reference values"); |
Vkadaba | 50:d84305e5e1c0 | 1106 | return eRet; |
Vkadaba | 50:d84305e5e1c0 | 1107 | } |
Vkadaba | 50:d84305e5e1c0 | 1108 | |
Vkadaba | 50:d84305e5e1c0 | 1109 | if((pMeasConfig->AVDDVoltage >= 3.0) && (pMeasConfig->AVDDVoltage <= 3.6)) { |
Vkadaba | 45:f5f553b8c0d5 | 1110 | eRet = admw_SetAVDDVoltage(hDevice, |
Vkadaba | 45:f5f553b8c0d5 | 1111 | pMeasConfig->AVDDVoltage); |
Vkadaba | 45:f5f553b8c0d5 | 1112 | } |
Vkadaba | 50:d84305e5e1c0 | 1113 | |
Vkadaba | 23:bb685f35b08b | 1114 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 50:d84305e5e1c0 | 1115 | ADMW_LOG_ERROR("Failed to set AVDD Voltge"); |
ADIJake | 0:85855ecd3257 | 1116 | return eRet; |
ADIJake | 0:85855ecd3257 | 1117 | } |
ADIJake | 0:85855ecd3257 | 1118 | |
Vkadaba | 33:df7a00f1b8e1 | 1119 | eRet = admw_SetRSenseValue(hDevice, pMeasConfig->RSenseValue); |
Vkadaba | 41:df78b7d7b675 | 1120 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 33:df7a00f1b8e1 | 1121 | ADMW_LOG_ERROR("Failed to set RSenseValue"); |
Vkadaba | 33:df7a00f1b8e1 | 1122 | return eRet; |
Vkadaba | 33:df7a00f1b8e1 | 1123 | } |
Vkadaba | 41:df78b7d7b675 | 1124 | |
Vkadaba | 36:54e2418e7620 | 1125 | eRet = admw_SetExternalReferenceVoltage(hDevice, pMeasConfig->externalRefVoltage); |
Vkadaba | 41:df78b7d7b675 | 1126 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 36:54e2418e7620 | 1127 | ADMW_LOG_ERROR("Failed to set External reference Voltage"); |
Vkadaba | 36:54e2418e7620 | 1128 | return eRet; |
Vkadaba | 41:df78b7d7b675 | 1129 | } |
Vkadaba | 41:df78b7d7b675 | 1130 | |
Vkadaba | 5:0728bde67bdb | 1131 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1132 | } |
Vkadaba | 36:54e2418e7620 | 1133 | ADMW_RESULT admw1001_SetDiagnosticsConfig( |
Vkadaba | 36:54e2418e7620 | 1134 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 36:54e2418e7620 | 1135 | ADMW1001_DIAGNOSTICS_CONFIG *pDiagnosticsConfig) |
Vkadaba | 36:54e2418e7620 | 1136 | { |
Vkadaba | 36:54e2418e7620 | 1137 | ADMW_CORE_Diagnostics_Control_t diagnosticsControlReg; |
ADIJake | 0:85855ecd3257 | 1138 | |
Vkadaba | 36:54e2418e7620 | 1139 | diagnosticsControlReg.VALUE8 = REG_RESET_VAL(CORE_DIAGNOSTICS_CONTROL); |
Vkadaba | 36:54e2418e7620 | 1140 | |
Vkadaba | 36:54e2418e7620 | 1141 | if (pDiagnosticsConfig->disableMeasurementDiag) |
Vkadaba | 36:54e2418e7620 | 1142 | diagnosticsControlReg.Diag_Meas_En = 0; |
Vkadaba | 36:54e2418e7620 | 1143 | else |
Vkadaba | 36:54e2418e7620 | 1144 | diagnosticsControlReg.Diag_Meas_En = 1; |
Vkadaba | 36:54e2418e7620 | 1145 | |
Vkadaba | 55:215da406282b | 1146 | if(pDiagnosticsConfig->osdFrequency <= 0x7F) { |
Vkadaba | 55:215da406282b | 1147 | diagnosticsControlReg.Diag_OSD_Freq = pDiagnosticsConfig->osdFrequency; |
Vkadaba | 55:215da406282b | 1148 | } else { |
Vkadaba | 44:94bdfaefddac | 1149 | ADMW_LOG_ERROR("Invalid open-sensor diagnostic frequency %d specified", |
Vkadaba | 55:215da406282b | 1150 | pDiagnosticsConfig->osdFrequency); |
Vkadaba | 44:94bdfaefddac | 1151 | return ADMW_INVALID_PARAM; |
Vkadaba | 44:94bdfaefddac | 1152 | } |
Vkadaba | 36:54e2418e7620 | 1153 | WRITE_REG_U8(hDevice, diagnosticsControlReg.VALUE8, CORE_DIAGNOSTICS_CONTROL); |
Vkadaba | 36:54e2418e7620 | 1154 | |
Vkadaba | 36:54e2418e7620 | 1155 | return ADMW_SUCCESS; |
Vkadaba | 36:54e2418e7620 | 1156 | } |
ADIJake | 0:85855ecd3257 | 1157 | |
Vkadaba | 5:0728bde67bdb | 1158 | ADMW_RESULT admw1001_SetChannelCount( |
Vkadaba | 5:0728bde67bdb | 1159 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1160 | ADMW1001_CH_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 1161 | uint32_t nMeasurementsPerCycle) |
ADIJake | 0:85855ecd3257 | 1162 | { |
Vkadaba | 8:2f2775c34640 | 1163 | ADMW_CORE_Channel_Count_t channelCountReg; |
ADIJake | 0:85855ecd3257 | 1164 | |
ADIJake | 0:85855ecd3257 | 1165 | channelCountReg.VALUE8 = REG_RESET_VAL(CORE_CHANNEL_COUNTn); |
ADIJake | 0:85855ecd3257 | 1166 | |
Vkadaba | 23:bb685f35b08b | 1167 | if (nMeasurementsPerCycle > 0) { |
ADIJake | 0:85855ecd3257 | 1168 | nMeasurementsPerCycle -= 1; |
ADIJake | 0:85855ecd3257 | 1169 | |
ADIJake | 0:85855ecd3257 | 1170 | CHECK_REG_FIELD_VAL(CORE_CHANNEL_COUNT_CHANNEL_COUNT, |
ADIJake | 0:85855ecd3257 | 1171 | nMeasurementsPerCycle); |
ADIJake | 0:85855ecd3257 | 1172 | |
ADIJake | 0:85855ecd3257 | 1173 | channelCountReg.Channel_Enable = 1; |
ADIJake | 0:85855ecd3257 | 1174 | channelCountReg.Channel_Count = nMeasurementsPerCycle; |
Vkadaba | 23:bb685f35b08b | 1175 | } else { |
ADIJake | 0:85855ecd3257 | 1176 | channelCountReg.Channel_Enable = 0; |
ADIJake | 0:85855ecd3257 | 1177 | } |
ADIJake | 0:85855ecd3257 | 1178 | |
ADIJake | 0:85855ecd3257 | 1179 | WRITE_REG_U8(hDevice, channelCountReg.VALUE8, CORE_CHANNEL_COUNTn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1180 | |
Vkadaba | 5:0728bde67bdb | 1181 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1182 | } |
ADIJake | 0:85855ecd3257 | 1183 | |
Vkadaba | 5:0728bde67bdb | 1184 | ADMW_RESULT admw1001_SetChannelOptions( |
Vkadaba | 5:0728bde67bdb | 1185 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1186 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 6:9d393a9677f4 | 1187 | ADMW1001_CHANNEL_PRIORITY ePriority) |
ADIJake | 0:85855ecd3257 | 1188 | { |
Vkadaba | 8:2f2775c34640 | 1189 | ADMW_CORE_Channel_Options_t channelOptionsReg; |
ADIJake | 0:85855ecd3257 | 1190 | |
ADIJake | 0:85855ecd3257 | 1191 | channelOptionsReg.VALUE8 = REG_RESET_VAL(CORE_CHANNEL_OPTIONSn); |
ADIJake | 0:85855ecd3257 | 1192 | |
ADIJake | 0:85855ecd3257 | 1193 | CHECK_REG_FIELD_VAL(CORE_CHANNEL_OPTIONS_CHANNEL_PRIORITY, ePriority); |
ADIJake | 0:85855ecd3257 | 1194 | channelOptionsReg.Channel_Priority = ePriority; |
ADIJake | 0:85855ecd3257 | 1195 | |
ADIJake | 0:85855ecd3257 | 1196 | WRITE_REG_U8(hDevice, channelOptionsReg.VALUE8, CORE_CHANNEL_OPTIONSn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1197 | |
Vkadaba | 5:0728bde67bdb | 1198 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1199 | } |
ADIJake | 0:85855ecd3257 | 1200 | |
Vkadaba | 5:0728bde67bdb | 1201 | ADMW_RESULT admw1001_SetChannelSkipCount( |
Vkadaba | 5:0728bde67bdb | 1202 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1203 | ADMW1001_CH_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 1204 | uint32_t nCycleSkipCount) |
ADIJake | 0:85855ecd3257 | 1205 | { |
Vkadaba | 8:2f2775c34640 | 1206 | ADMW_CORE_Channel_Skip_t channelSkipReg; |
ADIJake | 0:85855ecd3257 | 1207 | |
ADIJake | 0:85855ecd3257 | 1208 | channelSkipReg.VALUE16 = REG_RESET_VAL(CORE_CHANNEL_SKIPn); |
ADIJake | 0:85855ecd3257 | 1209 | |
ADIJake | 0:85855ecd3257 | 1210 | CHECK_REG_FIELD_VAL(CORE_CHANNEL_SKIP_CHANNEL_SKIP, nCycleSkipCount); |
ADIJake | 0:85855ecd3257 | 1211 | |
ADIJake | 0:85855ecd3257 | 1212 | channelSkipReg.Channel_Skip = nCycleSkipCount; |
ADIJake | 0:85855ecd3257 | 1213 | |
ADIJake | 0:85855ecd3257 | 1214 | WRITE_REG_U16(hDevice, channelSkipReg.VALUE16, CORE_CHANNEL_SKIPn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1215 | |
Vkadaba | 5:0728bde67bdb | 1216 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1217 | } |
ADIJake | 0:85855ecd3257 | 1218 | |
Vkadaba | 5:0728bde67bdb | 1219 | static ADMW_RESULT admw_SetChannelAdcSensorType( |
Vkadaba | 8:2f2775c34640 | 1220 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1221 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 8:2f2775c34640 | 1222 | ADMW1001_ADC_SENSOR_TYPE sensorType) |
ADIJake | 0:85855ecd3257 | 1223 | { |
Vkadaba | 8:2f2775c34640 | 1224 | ADMW_CORE_Sensor_Type_t sensorTypeReg; |
ADIJake | 0:85855ecd3257 | 1225 | |
ADIJake | 0:85855ecd3257 | 1226 | sensorTypeReg.VALUE16 = REG_RESET_VAL(CORE_SENSOR_TYPEn); |
ADIJake | 0:85855ecd3257 | 1227 | |
ADIJake | 0:85855ecd3257 | 1228 | /* Ensure that the sensor type is valid for this channel */ |
Vkadaba | 23:bb685f35b08b | 1229 | switch(sensorType) { |
Vkadaba | 50:d84305e5e1c0 | 1230 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT10: |
Vkadaba | 50:d84305e5e1c0 | 1231 | |
Vkadaba | 50:d84305e5e1c0 | 1232 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT50: |
Vkadaba | 50:d84305e5e1c0 | 1233 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT100: |
Vkadaba | 50:d84305e5e1c0 | 1234 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT200: |
Vkadaba | 50:d84305e5e1c0 | 1235 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT500: |
Vkadaba | 50:d84305e5e1c0 | 1236 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT1000: |
Vkadaba | 50:d84305e5e1c0 | 1237 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT1000_0P00375: |
Vkadaba | 50:d84305e5e1c0 | 1238 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_NI120: |
Vkadaba | 50:d84305e5e1c0 | 1239 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_CUSTOM: |
Vkadaba | 50:d84305e5e1c0 | 1240 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT10: |
Vkadaba | 50:d84305e5e1c0 | 1241 | |
Vkadaba | 50:d84305e5e1c0 | 1242 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT50: |
Vkadaba | 50:d84305e5e1c0 | 1243 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT100: |
Vkadaba | 50:d84305e5e1c0 | 1244 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT200: |
Vkadaba | 50:d84305e5e1c0 | 1245 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT500: |
Vkadaba | 50:d84305e5e1c0 | 1246 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT1000: |
Vkadaba | 50:d84305e5e1c0 | 1247 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT1000_0P00375: |
Vkadaba | 50:d84305e5e1c0 | 1248 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_NI120: |
Vkadaba | 50:d84305e5e1c0 | 1249 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_CUSTOM: |
Vkadaba | 50:d84305e5e1c0 | 1250 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT10: |
Vkadaba | 50:d84305e5e1c0 | 1251 | |
Vkadaba | 50:d84305e5e1c0 | 1252 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT50: |
Vkadaba | 8:2f2775c34640 | 1253 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT100: |
Vkadaba | 50:d84305e5e1c0 | 1254 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT200: |
Vkadaba | 50:d84305e5e1c0 | 1255 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT500: |
Vkadaba | 8:2f2775c34640 | 1256 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT1000: |
Vkadaba | 50:d84305e5e1c0 | 1257 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT1000_0P00375 : |
Vkadaba | 50:d84305e5e1c0 | 1258 | |
Vkadaba | 50:d84305e5e1c0 | 1259 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_NI120: |
Vkadaba | 50:d84305e5e1c0 | 1260 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_CUSTOM: |
Vkadaba | 58:aa9cd5072f66 | 1261 | case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE: |
Vkadaba | 58:aa9cd5072f66 | 1262 | case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE: |
Vkadaba | 50:d84305e5e1c0 | 1263 | case ADMW1001_ADC_SENSOR_DIODE: |
Vkadaba | 50:d84305e5e1c0 | 1264 | case ADMW1001_ADC_SENSOR_THERMISTOR_44004_44033_2P252K_AT_25C: |
Vkadaba | 50:d84305e5e1c0 | 1265 | case ADMW1001_ADC_SENSOR_THERMISTOR_44005_44030_3K_AT_25C: |
Vkadaba | 50:d84305e5e1c0 | 1266 | case ADMW1001_ADC_SENSOR_THERMISTOR_44007_44034_5K_AT_25C: |
Vkadaba | 50:d84305e5e1c0 | 1267 | case ADMW1001_ADC_SENSOR_THERMISTOR_44006_44031_10K_AT_25C: |
Vkadaba | 50:d84305e5e1c0 | 1268 | case ADMW1001_ADC_SENSOR_THERMISTOR_44008_44032_30K_AT_25C: |
Vkadaba | 50:d84305e5e1c0 | 1269 | case ADMW1001_ADC_SENSOR_THERMISTOR_YSI_400: |
Vkadaba | 50:d84305e5e1c0 | 1270 | case ADMW1001_ADC_SENSOR_THERMISTOR_SPECTRUM_1003K_1K: |
Vkadaba | 50:d84305e5e1c0 | 1271 | case ADMW1001_ADC_SENSOR_THERMISTOR_CUSTOM_STEINHART_HART: |
Vkadaba | 50:d84305e5e1c0 | 1272 | case ADMW1001_ADC_SENSOR_THERMISTOR_CUSTOM_TABLE: |
Vkadaba | 36:54e2418e7620 | 1273 | case ADMW1001_ADC_SENSOR_SINGLE_ENDED_ABSOLUTE: |
Vkadaba | 36:54e2418e7620 | 1274 | case ADMW1001_ADC_SENSOR_DIFFERENTIAL_ABSOLUTE: |
Vkadaba | 36:54e2418e7620 | 1275 | case ADMW1001_ADC_SENSOR_SINGLE_ENDED_RATIO: |
Vkadaba | 36:54e2418e7620 | 1276 | case ADMW1001_ADC_SENSOR_DIFFERENTIAL_RATIO: |
Vkadaba | 50:d84305e5e1c0 | 1277 | |
Vkadaba | 50:d84305e5e1c0 | 1278 | if (! (ADMW1001_CHANNEL_IS_ADC_CJC(eChannelId) || |
Vkadaba | 50:d84305e5e1c0 | 1279 | ADMW1001_CHANNEL_IS_ADC(eChannelId) )) { |
Vkadaba | 6:9d393a9677f4 | 1280 | ADMW_LOG_ERROR( |
Vkadaba | 6:9d393a9677f4 | 1281 | "Invalid ADC sensor type %d specified for channel %d", |
Vkadaba | 6:9d393a9677f4 | 1282 | sensorType, eChannelId); |
Vkadaba | 6:9d393a9677f4 | 1283 | return ADMW_INVALID_PARAM; |
Vkadaba | 6:9d393a9677f4 | 1284 | } |
Vkadaba | 6:9d393a9677f4 | 1285 | break; |
Vkadaba | 8:2f2775c34640 | 1286 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_J: |
Vkadaba | 8:2f2775c34640 | 1287 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_K: |
Vkadaba | 8:2f2775c34640 | 1288 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_T: |
Vkadaba | 50:d84305e5e1c0 | 1289 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_E: |
Vkadaba | 50:d84305e5e1c0 | 1290 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_N: |
Vkadaba | 50:d84305e5e1c0 | 1291 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_R: |
Vkadaba | 50:d84305e5e1c0 | 1292 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_S: |
Vkadaba | 50:d84305e5e1c0 | 1293 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_B: |
Vkadaba | 50:d84305e5e1c0 | 1294 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_CUSTOM: |
Vkadaba | 23:bb685f35b08b | 1295 | if (! ADMW1001_CHANNEL_IS_ADC_VOLTAGE(eChannelId)) { |
Vkadaba | 6:9d393a9677f4 | 1296 | ADMW_LOG_ERROR( |
Vkadaba | 6:9d393a9677f4 | 1297 | "Invalid ADC sensor type %d specified for channel %d", |
Vkadaba | 6:9d393a9677f4 | 1298 | sensorType, eChannelId); |
Vkadaba | 6:9d393a9677f4 | 1299 | return ADMW_INVALID_PARAM; |
Vkadaba | 6:9d393a9677f4 | 1300 | } |
Vkadaba | 6:9d393a9677f4 | 1301 | break; |
Vkadaba | 6:9d393a9677f4 | 1302 | default: |
Vkadaba | 6:9d393a9677f4 | 1303 | ADMW_LOG_ERROR("Invalid/unsupported ADC sensor type %d specified", |
Vkadaba | 23:bb685f35b08b | 1304 | sensorType); |
Vkadaba | 5:0728bde67bdb | 1305 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1306 | } |
ADIJake | 0:85855ecd3257 | 1307 | |
ADIJake | 0:85855ecd3257 | 1308 | sensorTypeReg.Sensor_Type = sensorType; |
ADIJake | 0:85855ecd3257 | 1309 | |
ADIJake | 0:85855ecd3257 | 1310 | WRITE_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1311 | |
Vkadaba | 5:0728bde67bdb | 1312 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1313 | } |
ADIJake | 0:85855ecd3257 | 1314 | |
Vkadaba | 5:0728bde67bdb | 1315 | static ADMW_RESULT admw_SetChannelAdcSensorDetails( |
Vkadaba | 8:2f2775c34640 | 1316 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1317 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1318 | ADMW1001_CHANNEL_CONFIG *pChannelConfig) |
ADIJake | 0:85855ecd3257 | 1319 | /* |
ADIJake | 0:85855ecd3257 | 1320 | * TODO - it would be nice if the general- vs. ADC-specific sensor details could be split into separate registers |
ADIJake | 0:85855ecd3257 | 1321 | * General details: |
ADIJake | 0:85855ecd3257 | 1322 | * - Measurement_Units |
ADIJake | 0:85855ecd3257 | 1323 | * - Compensation_Channel |
ADIJake | 0:85855ecd3257 | 1324 | * - CJC_Publish (if "CJC" was removed from the name) |
ADIJake | 0:85855ecd3257 | 1325 | * ADC-specific details: |
ADIJake | 0:85855ecd3257 | 1326 | * - PGA_Gain |
ADIJake | 0:85855ecd3257 | 1327 | * - Reference_Select |
ADIJake | 0:85855ecd3257 | 1328 | * - Reference_Buffer_Disable |
ADIJake | 0:85855ecd3257 | 1329 | */ |
ADIJake | 0:85855ecd3257 | 1330 | { |
Vkadaba | 5:0728bde67bdb | 1331 | ADMW1001_ADC_CHANNEL_CONFIG *pAdcChannelConfig = &pChannelConfig->adcChannelConfig; |
Vkadaba | 8:2f2775c34640 | 1332 | ADMW1001_ADC_REFERENCE_TYPE refType = pAdcChannelConfig->reference; |
Vkadaba | 8:2f2775c34640 | 1333 | ADMW_CORE_Sensor_Details_t sensorDetailsReg; |
ADIJake | 0:85855ecd3257 | 1334 | |
ADIJake | 0:85855ecd3257 | 1335 | sensorDetailsReg.VALUE32 = REG_RESET_VAL(CORE_SENSOR_DETAILSn); |
ADIJake | 0:85855ecd3257 | 1336 | |
Vkadaba | 23:bb685f35b08b | 1337 | switch(pChannelConfig->measurementUnit) { |
Vkadaba | 8:2f2775c34640 | 1338 | case ADMW1001_MEASUREMENT_UNIT_FAHRENHEIT: |
Vkadaba | 8:2f2775c34640 | 1339 | sensorDetailsReg.Measurement_Units = CORE_SENSOR_DETAILS_UNITS_DEGF; |
Vkadaba | 8:2f2775c34640 | 1340 | break; |
Vkadaba | 8:2f2775c34640 | 1341 | case ADMW1001_MEASUREMENT_UNIT_CELSIUS: |
Vkadaba | 8:2f2775c34640 | 1342 | sensorDetailsReg.Measurement_Units = CORE_SENSOR_DETAILS_UNITS_DEGC; |
Vkadaba | 8:2f2775c34640 | 1343 | break; |
Vkadaba | 8:2f2775c34640 | 1344 | case ADMW1001_MEASUREMENT_UNIT_UNSPECIFIED: |
Vkadaba | 8:2f2775c34640 | 1345 | sensorDetailsReg.Measurement_Units = CORE_SENSOR_DETAILS_UNITS_UNSPECIFIED; |
Vkadaba | 8:2f2775c34640 | 1346 | break; |
Vkadaba | 8:2f2775c34640 | 1347 | default: |
Vkadaba | 8:2f2775c34640 | 1348 | ADMW_LOG_ERROR("Invalid measurement unit %d specified", |
Vkadaba | 8:2f2775c34640 | 1349 | pChannelConfig->measurementUnit); |
Vkadaba | 8:2f2775c34640 | 1350 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1351 | } |
ADIJake | 0:85855ecd3257 | 1352 | |
Vkadaba | 23:bb685f35b08b | 1353 | if (pChannelConfig->compensationChannel == ADMW1001_CH_ID_NONE) { |
ADIJake | 0:85855ecd3257 | 1354 | sensorDetailsReg.Compensation_Disable = 1; |
ADIJake | 0:85855ecd3257 | 1355 | sensorDetailsReg.Compensation_Channel = 0; |
Vkadaba | 23:bb685f35b08b | 1356 | } else { |
ADIJake | 0:85855ecd3257 | 1357 | sensorDetailsReg.Compensation_Disable = 0; |
ADIJake | 0:85855ecd3257 | 1358 | sensorDetailsReg.Compensation_Channel = pChannelConfig->compensationChannel; |
ADIJake | 0:85855ecd3257 | 1359 | } |
ADIJake | 0:85855ecd3257 | 1360 | |
Vkadaba | 23:bb685f35b08b | 1361 | switch(refType) { |
Vkadaba | 8:2f2775c34640 | 1362 | case ADMW1001_ADC_REFERENCE_VOLTAGE_INTERNAL: |
Vkadaba | 8:2f2775c34640 | 1363 | sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_VINT; |
Vkadaba | 8:2f2775c34640 | 1364 | break; |
Vkadaba | 8:2f2775c34640 | 1365 | case ADMW1001_ADC_REFERENCE_VOLTAGE_EXTERNAL_1: |
Vkadaba | 8:2f2775c34640 | 1366 | sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_VEXT1; |
Vkadaba | 8:2f2775c34640 | 1367 | break; |
Vkadaba | 8:2f2775c34640 | 1368 | case ADMW1001_ADC_REFERENCE_VOLTAGE_AVDD: |
Vkadaba | 8:2f2775c34640 | 1369 | sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_AVDD; |
Vkadaba | 8:2f2775c34640 | 1370 | break; |
Vkadaba | 8:2f2775c34640 | 1371 | default: |
Vkadaba | 8:2f2775c34640 | 1372 | ADMW_LOG_ERROR("Invalid ADC reference type %d specified", refType); |
Vkadaba | 8:2f2775c34640 | 1373 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1374 | } |
Vkadaba | 23:bb685f35b08b | 1375 | |
Vkadaba | 23:bb685f35b08b | 1376 | switch(pAdcChannelConfig->gain) { |
Vkadaba | 8:2f2775c34640 | 1377 | case ADMW1001_ADC_GAIN_1X: |
Vkadaba | 8:2f2775c34640 | 1378 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_1; |
Vkadaba | 8:2f2775c34640 | 1379 | break; |
Vkadaba | 8:2f2775c34640 | 1380 | case ADMW1001_ADC_GAIN_2X: |
Vkadaba | 8:2f2775c34640 | 1381 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_2; |
Vkadaba | 8:2f2775c34640 | 1382 | break; |
Vkadaba | 8:2f2775c34640 | 1383 | case ADMW1001_ADC_GAIN_4X: |
Vkadaba | 8:2f2775c34640 | 1384 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_4; |
Vkadaba | 8:2f2775c34640 | 1385 | break; |
Vkadaba | 8:2f2775c34640 | 1386 | case ADMW1001_ADC_GAIN_8X: |
Vkadaba | 8:2f2775c34640 | 1387 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_8; |
Vkadaba | 8:2f2775c34640 | 1388 | break; |
Vkadaba | 8:2f2775c34640 | 1389 | case ADMW1001_ADC_GAIN_16X: |
Vkadaba | 8:2f2775c34640 | 1390 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_16; |
Vkadaba | 8:2f2775c34640 | 1391 | break; |
Vkadaba | 8:2f2775c34640 | 1392 | case ADMW1001_ADC_GAIN_32X: |
Vkadaba | 8:2f2775c34640 | 1393 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_32; |
Vkadaba | 8:2f2775c34640 | 1394 | break; |
Vkadaba | 8:2f2775c34640 | 1395 | case ADMW1001_ADC_GAIN_64X: |
Vkadaba | 8:2f2775c34640 | 1396 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_64; |
Vkadaba | 8:2f2775c34640 | 1397 | break; |
Vkadaba | 8:2f2775c34640 | 1398 | default: |
Vkadaba | 8:2f2775c34640 | 1399 | ADMW_LOG_ERROR("Invalid ADC gain %d specified", |
Vkadaba | 23:bb685f35b08b | 1400 | pAdcChannelConfig->gain); |
Vkadaba | 8:2f2775c34640 | 1401 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1402 | } |
ADIJake | 0:85855ecd3257 | 1403 | |
Vkadaba | 23:bb685f35b08b | 1404 | switch(pAdcChannelConfig->rtdCurve) { |
Vkadaba | 8:2f2775c34640 | 1405 | case ADMW1001_ADC_RTD_CURVE_EUROPEAN: |
Vkadaba | 8:2f2775c34640 | 1406 | sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_EUROPEAN_CURVE; |
Vkadaba | 8:2f2775c34640 | 1407 | break; |
Vkadaba | 8:2f2775c34640 | 1408 | case ADMW1001_ADC_RTD_CURVE_AMERICAN: |
Vkadaba | 8:2f2775c34640 | 1409 | sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_AMERICAN_CURVE; |
Vkadaba | 8:2f2775c34640 | 1410 | break; |
Vkadaba | 8:2f2775c34640 | 1411 | case ADMW1001_ADC_RTD_CURVE_JAPANESE: |
Vkadaba | 8:2f2775c34640 | 1412 | sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_JAPANESE_CURVE; |
Vkadaba | 8:2f2775c34640 | 1413 | break; |
Vkadaba | 8:2f2775c34640 | 1414 | case ADMW1001_ADC_RTD_CURVE_ITS90: |
Vkadaba | 8:2f2775c34640 | 1415 | sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_ITS90_CURVE; |
Vkadaba | 8:2f2775c34640 | 1416 | break; |
Vkadaba | 8:2f2775c34640 | 1417 | default: |
Vkadaba | 8:2f2775c34640 | 1418 | ADMW_LOG_ERROR("Invalid RTD Curve %d specified", |
Vkadaba | 23:bb685f35b08b | 1419 | pAdcChannelConfig->rtdCurve); |
Vkadaba | 8:2f2775c34640 | 1420 | return ADMW_INVALID_PARAM; |
Vkadaba | 6:9d393a9677f4 | 1421 | } |
Vkadaba | 6:9d393a9677f4 | 1422 | |
Vkadaba | 23:bb685f35b08b | 1423 | if (pChannelConfig->disablePublishing) { |
ADIJake | 0:85855ecd3257 | 1424 | sensorDetailsReg.Do_Not_Publish = 1; |
Vkadaba | 23:bb685f35b08b | 1425 | } else { |
ADIJake | 0:85855ecd3257 | 1426 | sensorDetailsReg.Do_Not_Publish = 0; |
Vkadaba | 8:2f2775c34640 | 1427 | } |
Vkadaba | 23:bb685f35b08b | 1428 | |
Vkadaba | 23:bb685f35b08b | 1429 | switch (pChannelConfig->lutSelect) { |
Vkadaba | 8:2f2775c34640 | 1430 | case ADMW1001_LUT_DEFAULT: |
Vkadaba | 8:2f2775c34640 | 1431 | case ADMW1001_LUT_CUSTOM: |
Vkadaba | 8:2f2775c34640 | 1432 | sensorDetailsReg.LUT_Select = pChannelConfig->lutSelect; |
Vkadaba | 8:2f2775c34640 | 1433 | break; |
Vkadaba | 8:2f2775c34640 | 1434 | default: |
Vkadaba | 8:2f2775c34640 | 1435 | ADMW_LOG_ERROR("Invalid LUT selection %d specified", |
Vkadaba | 23:bb685f35b08b | 1436 | pChannelConfig->lutSelect); |
Vkadaba | 23:bb685f35b08b | 1437 | return ADMW_INVALID_PARAM; |
Vkadaba | 8:2f2775c34640 | 1438 | } |
Vkadaba | 23:bb685f35b08b | 1439 | |
ADIJake | 0:85855ecd3257 | 1440 | WRITE_REG_U32(hDevice, sensorDetailsReg.VALUE32, CORE_SENSOR_DETAILSn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1441 | |
Vkadaba | 5:0728bde67bdb | 1442 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1443 | } |
ADIJake | 0:85855ecd3257 | 1444 | |
Vkadaba | 33:df7a00f1b8e1 | 1445 | static ADMW_RESULT admw_SetChannelAdcMeasurementSetup( |
Vkadaba | 5:0728bde67bdb | 1446 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1447 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 33:df7a00f1b8e1 | 1448 | ADMW1001_ADC_CHANNEL_CONFIG *pAdcChannelConfig) |
ADIJake | 0:85855ecd3257 | 1449 | { |
Vkadaba | 8:2f2775c34640 | 1450 | ADMW_CORE_Measurement_Setup_t MeasSetupReg; |
Vkadaba | 33:df7a00f1b8e1 | 1451 | ADMW1001_ADC_FILTER_CONFIG *pFilterConfig = &pAdcChannelConfig->filter; |
Vkadaba | 6:9d393a9677f4 | 1452 | MeasSetupReg.VALUE32 = REG_RESET_VAL(CORE_MEASUREMENT_SETUPn); |
Vkadaba | 33:df7a00f1b8e1 | 1453 | MeasSetupReg.Buffer_Bypass = pAdcChannelConfig->bufferBypass; |
Vkadaba | 41:df78b7d7b675 | 1454 | |
Vkadaba | 23:bb685f35b08b | 1455 | if (pFilterConfig->type == ADMW1001_ADC_FILTER_SINC4) { |
Vkadaba | 6:9d393a9677f4 | 1456 | MeasSetupReg.ADC_Filter_Type = CORE_MEASUREMENT_SETUP_ENABLE_SINC4; |
Vkadaba | 6:9d393a9677f4 | 1457 | MeasSetupReg.ADC_SF = pFilterConfig->sf; |
Vkadaba | 23:bb685f35b08b | 1458 | } else if (pFilterConfig->type == ADMW1001_ADC_FILTER_SINC3) { |
Vkadaba | 6:9d393a9677f4 | 1459 | MeasSetupReg.ADC_Filter_Type = CORE_MEASUREMENT_SETUP_ENABLE_SINC3; |
Vkadaba | 23:bb685f35b08b | 1460 | MeasSetupReg.ADC_SF = pFilterConfig->sf; |
Vkadaba | 23:bb685f35b08b | 1461 | } else { |
Vkadaba | 5:0728bde67bdb | 1462 | ADMW_LOG_ERROR("Invalid ADC filter type %d specified", |
Vkadaba | 23:bb685f35b08b | 1463 | pFilterConfig->type); |
Vkadaba | 5:0728bde67bdb | 1464 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1465 | } |
Vkadaba | 23:bb685f35b08b | 1466 | |
Vkadaba | 8:2f2775c34640 | 1467 | /* chop mod ecan be 0 (none), 1 (HW, 2 (SW, 3 (HW+SW). */ |
Vkadaba | 17:2f0028880874 | 1468 | MeasSetupReg.Chop_Mode = pFilterConfig->chopMode; |
Vkadaba | 23:bb685f35b08b | 1469 | |
Vkadaba | 6:9d393a9677f4 | 1470 | if(pFilterConfig->notch1p2) |
Vkadaba | 6:9d393a9677f4 | 1471 | MeasSetupReg.NOTCH_EN_2 = 1; |
Vkadaba | 6:9d393a9677f4 | 1472 | else |
Vkadaba | 6:9d393a9677f4 | 1473 | MeasSetupReg.NOTCH_EN_2 = 0; |
Vkadaba | 23:bb685f35b08b | 1474 | |
Vkadaba | 6:9d393a9677f4 | 1475 | WRITE_REG_U32(hDevice, MeasSetupReg.VALUE32, CORE_MEASUREMENT_SETUPn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1476 | |
Vkadaba | 5:0728bde67bdb | 1477 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1478 | } |
ADIJake | 0:85855ecd3257 | 1479 | |
Vkadaba | 5:0728bde67bdb | 1480 | static ADMW_RESULT admw_SetChannelAdcCurrentConfig( |
Vkadaba | 5:0728bde67bdb | 1481 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1482 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1483 | ADMW1001_ADC_EXC_CURRENT_CONFIG *pCurrentConfig) |
ADIJake | 0:85855ecd3257 | 1484 | { |
Vkadaba | 8:2f2775c34640 | 1485 | ADMW_CORE_Channel_Excitation_t channelExcitationReg; |
ADIJake | 0:85855ecd3257 | 1486 | |
Vkadaba | 6:9d393a9677f4 | 1487 | channelExcitationReg.VALUE16 = REG_RESET_VAL(CORE_CHANNEL_EXCITATIONn); |
Vkadaba | 6:9d393a9677f4 | 1488 | |
Vkadaba | 18:cbf514cce921 | 1489 | if (pCurrentConfig->outputLevel == ADMW1001_ADC_NO_EXTERNAL_EXC_CURRENT) |
Vkadaba | 18:cbf514cce921 | 1490 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_NONE; |
Vkadaba | 18:cbf514cce921 | 1491 | else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_EXTERNAL) |
Vkadaba | 6:9d393a9677f4 | 1492 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_EXTERNAL; |
Vkadaba | 18:cbf514cce921 | 1493 | else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_50uA) |
Vkadaba | 6:9d393a9677f4 | 1494 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_50UA; |
Vkadaba | 6:9d393a9677f4 | 1495 | else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_100uA) |
Vkadaba | 6:9d393a9677f4 | 1496 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_100UA; |
Vkadaba | 6:9d393a9677f4 | 1497 | else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_250uA) |
Vkadaba | 6:9d393a9677f4 | 1498 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_250UA; |
Vkadaba | 6:9d393a9677f4 | 1499 | else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_500uA) |
Vkadaba | 6:9d393a9677f4 | 1500 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_500UA; |
Vkadaba | 6:9d393a9677f4 | 1501 | else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_1000uA) |
Vkadaba | 6:9d393a9677f4 | 1502 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_1000UA; |
Vkadaba | 23:bb685f35b08b | 1503 | else { |
Vkadaba | 6:9d393a9677f4 | 1504 | ADMW_LOG_ERROR("Invalid ADC excitation current %d specified", |
Vkadaba | 6:9d393a9677f4 | 1505 | pCurrentConfig->outputLevel); |
Vkadaba | 6:9d393a9677f4 | 1506 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1507 | } |
ADIJake | 0:85855ecd3257 | 1508 | |
Vkadaba | 6:9d393a9677f4 | 1509 | WRITE_REG_U16(hDevice, channelExcitationReg.VALUE16, CORE_CHANNEL_EXCITATIONn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1510 | |
Vkadaba | 5:0728bde67bdb | 1511 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1512 | } |
ADIJake | 0:85855ecd3257 | 1513 | |
Vkadaba | 5:0728bde67bdb | 1514 | ADMW_RESULT admw_SetAdcChannelConfig( |
Vkadaba | 5:0728bde67bdb | 1515 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1516 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1517 | ADMW1001_CHANNEL_CONFIG *pChannelConfig) |
ADIJake | 0:85855ecd3257 | 1518 | { |
Vkadaba | 5:0728bde67bdb | 1519 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 1520 | ADMW1001_ADC_CHANNEL_CONFIG *pAdcChannelConfig = |
ADIJake | 0:85855ecd3257 | 1521 | &pChannelConfig->adcChannelConfig; |
ADIJake | 0:85855ecd3257 | 1522 | |
Vkadaba | 5:0728bde67bdb | 1523 | eRet = admw_SetChannelAdcSensorType(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1524 | pAdcChannelConfig->sensor); |
Vkadaba | 23:bb685f35b08b | 1525 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1526 | ADMW_LOG_ERROR("Failed to set ADC sensor type for channel %d", |
Vkadaba | 23:bb685f35b08b | 1527 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1528 | return eRet; |
ADIJake | 0:85855ecd3257 | 1529 | } |
ADIJake | 0:85855ecd3257 | 1530 | |
Vkadaba | 5:0728bde67bdb | 1531 | eRet = admw_SetChannelAdcSensorDetails(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1532 | pChannelConfig); |
Vkadaba | 23:bb685f35b08b | 1533 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1534 | ADMW_LOG_ERROR("Failed to set ADC sensor details for channel %d", |
Vkadaba | 23:bb685f35b08b | 1535 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1536 | return eRet; |
ADIJake | 0:85855ecd3257 | 1537 | } |
ADIJake | 0:85855ecd3257 | 1538 | |
Vkadaba | 33:df7a00f1b8e1 | 1539 | eRet = admw_SetChannelAdcMeasurementSetup(hDevice, eChannelId, |
Vkadaba | 41:df78b7d7b675 | 1540 | pAdcChannelConfig); |
Vkadaba | 23:bb685f35b08b | 1541 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1542 | ADMW_LOG_ERROR("Failed to set ADC filter for channel %d", |
Vkadaba | 23:bb685f35b08b | 1543 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1544 | return eRet; |
ADIJake | 0:85855ecd3257 | 1545 | } |
ADIJake | 0:85855ecd3257 | 1546 | |
Vkadaba | 5:0728bde67bdb | 1547 | eRet = admw_SetChannelAdcCurrentConfig(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1548 | &pAdcChannelConfig->current); |
Vkadaba | 23:bb685f35b08b | 1549 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1550 | ADMW_LOG_ERROR("Failed to set ADC current for channel %d", |
Vkadaba | 23:bb685f35b08b | 1551 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1552 | return eRet; |
ADIJake | 0:85855ecd3257 | 1553 | } |
ADIJake | 0:85855ecd3257 | 1554 | |
Vkadaba | 5:0728bde67bdb | 1555 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1556 | } |
ADIJake | 0:85855ecd3257 | 1557 | |
Vkadaba | 5:0728bde67bdb | 1558 | static ADMW_RESULT admw_SetChannelDigitalSensorDetails( |
Vkadaba | 5:0728bde67bdb | 1559 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1560 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1561 | ADMW1001_CHANNEL_CONFIG *pChannelConfig) |
ADIJake | 0:85855ecd3257 | 1562 | { |
Vkadaba | 8:2f2775c34640 | 1563 | ADMW_CORE_Sensor_Details_t sensorDetailsReg; |
ADIJake | 0:85855ecd3257 | 1564 | |
ADIJake | 0:85855ecd3257 | 1565 | sensorDetailsReg.VALUE32 = REG_RESET_VAL(CORE_SENSOR_DETAILSn); |
ADIJake | 0:85855ecd3257 | 1566 | |
Vkadaba | 23:bb685f35b08b | 1567 | if (pChannelConfig->compensationChannel == ADMW1001_CH_ID_NONE) { |
ADIJake | 0:85855ecd3257 | 1568 | sensorDetailsReg.Compensation_Disable = 1; |
ADIJake | 0:85855ecd3257 | 1569 | sensorDetailsReg.Compensation_Channel = 0; |
Vkadaba | 23:bb685f35b08b | 1570 | } else { |
Vkadaba | 5:0728bde67bdb | 1571 | ADMW_LOG_ERROR("Invalid compensation channel specified for digital sensor"); |
Vkadaba | 5:0728bde67bdb | 1572 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1573 | } |
ADIJake | 0:85855ecd3257 | 1574 | |
Vkadaba | 23:bb685f35b08b | 1575 | if (pChannelConfig->measurementUnit == ADMW1001_MEASUREMENT_UNIT_UNSPECIFIED) { |
Vkadaba | 5:0728bde67bdb | 1576 | sensorDetailsReg.Measurement_Units = CORE_SENSOR_DETAILS_UNITS_UNSPECIFIED; |
Vkadaba | 23:bb685f35b08b | 1577 | } else { |
Vkadaba | 5:0728bde67bdb | 1578 | ADMW_LOG_ERROR("Invalid measurement unit specified for digital channel"); |
Vkadaba | 5:0728bde67bdb | 1579 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1580 | } |
ADIJake | 0:85855ecd3257 | 1581 | |
ADIJake | 0:85855ecd3257 | 1582 | if (pChannelConfig->disablePublishing) |
ADIJake | 0:85855ecd3257 | 1583 | sensorDetailsReg.Do_Not_Publish = 1; |
ADIJake | 0:85855ecd3257 | 1584 | else |
ADIJake | 0:85855ecd3257 | 1585 | sensorDetailsReg.Do_Not_Publish = 0; |
ADIJake | 0:85855ecd3257 | 1586 | |
ADIJake | 0:85855ecd3257 | 1587 | WRITE_REG_U32(hDevice, sensorDetailsReg.VALUE32, CORE_SENSOR_DETAILSn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1588 | |
Vkadaba | 5:0728bde67bdb | 1589 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1590 | } |
ADIJake | 0:85855ecd3257 | 1591 | |
Vkadaba | 5:0728bde67bdb | 1592 | static ADMW_RESULT admw_SetDigitalSensorFormat( |
Vkadaba | 5:0728bde67bdb | 1593 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1594 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1595 | ADMW1001_DIGITAL_SENSOR_DATA_FORMAT *pDataFormat) |
ADIJake | 0:85855ecd3257 | 1596 | { |
Vkadaba | 8:2f2775c34640 | 1597 | ADMW_CORE_Digital_Sensor_Config_t sensorConfigReg; |
ADIJake | 0:85855ecd3257 | 1598 | |
ADIJake | 0:85855ecd3257 | 1599 | sensorConfigReg.VALUE16 = REG_RESET_VAL(CORE_DIGITAL_SENSOR_CONFIGn); |
ADIJake | 0:85855ecd3257 | 1600 | |
Vkadaba | 23:bb685f35b08b | 1601 | if (pDataFormat->coding != ADMW1001_DIGITAL_SENSOR_DATA_CODING_NONE) { |
Vkadaba | 23:bb685f35b08b | 1602 | if (pDataFormat->frameLength == 0) { |
Vkadaba | 5:0728bde67bdb | 1603 | ADMW_LOG_ERROR("Invalid frame length specified for digital sensor data format"); |
Vkadaba | 5:0728bde67bdb | 1604 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1605 | } |
Vkadaba | 23:bb685f35b08b | 1606 | if (pDataFormat->numDataBits == 0) { |
Vkadaba | 5:0728bde67bdb | 1607 | ADMW_LOG_ERROR("Invalid frame length specified for digital sensor data format"); |
Vkadaba | 5:0728bde67bdb | 1608 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1609 | } |
ADIJake | 0:85855ecd3257 | 1610 | |
ADIJake | 0:85855ecd3257 | 1611 | CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_CONFIG_DIGITAL_SENSOR_READ_BYTES, |
ADIJake | 0:85855ecd3257 | 1612 | pDataFormat->frameLength - 1); |
ADIJake | 0:85855ecd3257 | 1613 | CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_CONFIG_DIGITAL_SENSOR_DATA_BITS, |
ADIJake | 0:85855ecd3257 | 1614 | pDataFormat->numDataBits - 1); |
ADIJake | 0:85855ecd3257 | 1615 | CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_CONFIG_DIGITAL_SENSOR_BIT_OFFSET, |
ADIJake | 0:85855ecd3257 | 1616 | pDataFormat->bitOffset); |
ADIJake | 0:85855ecd3257 | 1617 | |
ADIJake | 0:85855ecd3257 | 1618 | sensorConfigReg.Digital_Sensor_Read_Bytes = pDataFormat->frameLength - 1; |
ADIJake | 0:85855ecd3257 | 1619 | sensorConfigReg.Digital_Sensor_Data_Bits = pDataFormat->numDataBits - 1; |
ADIJake | 0:85855ecd3257 | 1620 | sensorConfigReg.Digital_Sensor_Bit_Offset = pDataFormat->bitOffset; |
ADIJake | 0:85855ecd3257 | 1621 | sensorConfigReg.Digital_Sensor_Left_Aligned = pDataFormat->leftJustified ? 1 : 0; |
ADIJake | 0:85855ecd3257 | 1622 | sensorConfigReg.Digital_Sensor_Little_Endian = pDataFormat->littleEndian ? 1 : 0; |
ADIJake | 0:85855ecd3257 | 1623 | |
Vkadaba | 23:bb685f35b08b | 1624 | switch (pDataFormat->coding) { |
Vkadaba | 23:bb685f35b08b | 1625 | case ADMW1001_DIGITAL_SENSOR_DATA_CODING_UNIPOLAR: |
Vkadaba | 23:bb685f35b08b | 1626 | sensorConfigReg.Digital_Sensor_Coding = CORE_DIGITAL_SENSOR_CONFIG_CODING_UNIPOLAR; |
Vkadaba | 23:bb685f35b08b | 1627 | break; |
Vkadaba | 23:bb685f35b08b | 1628 | case ADMW1001_DIGITAL_SENSOR_DATA_CODING_TWOS_COMPLEMENT: |
Vkadaba | 23:bb685f35b08b | 1629 | sensorConfigReg.Digital_Sensor_Coding = CORE_DIGITAL_SENSOR_CONFIG_CODING_TWOS_COMPL; |
Vkadaba | 23:bb685f35b08b | 1630 | break; |
Vkadaba | 23:bb685f35b08b | 1631 | case ADMW1001_DIGITAL_SENSOR_DATA_CODING_OFFSET_BINARY: |
Vkadaba | 23:bb685f35b08b | 1632 | sensorConfigReg.Digital_Sensor_Coding = CORE_DIGITAL_SENSOR_CONFIG_CODING_OFFSET_BINARY; |
Vkadaba | 23:bb685f35b08b | 1633 | break; |
Vkadaba | 23:bb685f35b08b | 1634 | default: |
Vkadaba | 23:bb685f35b08b | 1635 | ADMW_LOG_ERROR("Invalid coding specified for digital sensor data format"); |
Vkadaba | 23:bb685f35b08b | 1636 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1637 | } |
Vkadaba | 23:bb685f35b08b | 1638 | } else { |
Vkadaba | 5:0728bde67bdb | 1639 | sensorConfigReg.Digital_Sensor_Coding = CORE_DIGITAL_SENSOR_CONFIG_CODING_NONE; |
ADIJake | 0:85855ecd3257 | 1640 | } |
ADIJake | 0:85855ecd3257 | 1641 | |
ADIJake | 0:85855ecd3257 | 1642 | WRITE_REG_U16(hDevice, sensorConfigReg.VALUE16, |
ADIJake | 0:85855ecd3257 | 1643 | CORE_DIGITAL_SENSOR_CONFIGn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1644 | |
ADIJake | 0:85855ecd3257 | 1645 | |
Vkadaba | 5:0728bde67bdb | 1646 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1647 | } |
ADIJake | 0:85855ecd3257 | 1648 | |
ADIJake | 0:85855ecd3257 | 1649 | |
Vkadaba | 5:0728bde67bdb | 1650 | static ADMW_RESULT admw_SetChannelI2cSensorType( |
Vkadaba | 5:0728bde67bdb | 1651 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1652 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1653 | ADMW1001_I2C_SENSOR_TYPE sensorType) |
ADIJake | 0:85855ecd3257 | 1654 | { |
Vkadaba | 8:2f2775c34640 | 1655 | ADMW_CORE_Sensor_Type_t sensorTypeReg; |
ADIJake | 0:85855ecd3257 | 1656 | |
ADIJake | 0:85855ecd3257 | 1657 | sensorTypeReg.VALUE16 = REG_RESET_VAL(CORE_SENSOR_TYPEn); |
ADIJake | 0:85855ecd3257 | 1658 | |
ADIJake | 0:85855ecd3257 | 1659 | /* Ensure that the sensor type is valid for this channel */ |
Vkadaba | 23:bb685f35b08b | 1660 | switch(sensorType) { |
Vkadaba | 58:aa9cd5072f66 | 1661 | case ADMW1001_I2C_SENSOR_HUMIDITY: |
Vkadaba | 50:d84305e5e1c0 | 1662 | case ADMW1001_I2C_SENSOR_TEMPERATURE_ADT742X: |
Vkadaba | 8:2f2775c34640 | 1663 | sensorTypeReg.Sensor_Type = sensorType; |
Vkadaba | 8:2f2775c34640 | 1664 | break; |
Vkadaba | 8:2f2775c34640 | 1665 | default: |
Vkadaba | 8:2f2775c34640 | 1666 | ADMW_LOG_ERROR("Unsupported I2C sensor type %d specified", sensorType); |
Vkadaba | 8:2f2775c34640 | 1667 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1668 | } |
ADIJake | 0:85855ecd3257 | 1669 | |
ADIJake | 0:85855ecd3257 | 1670 | WRITE_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1671 | |
Vkadaba | 5:0728bde67bdb | 1672 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1673 | } |
ADIJake | 0:85855ecd3257 | 1674 | |
Vkadaba | 5:0728bde67bdb | 1675 | static ADMW_RESULT admw_SetChannelI2cSensorAddress( |
Vkadaba | 5:0728bde67bdb | 1676 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1677 | ADMW1001_CH_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 1678 | uint32_t deviceAddress) |
ADIJake | 0:85855ecd3257 | 1679 | { |
ADIJake | 0:85855ecd3257 | 1680 | CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_ADDRESS_DIGITAL_SENSOR_ADDRESS, deviceAddress); |
ADIJake | 0:85855ecd3257 | 1681 | WRITE_REG_U8(hDevice, deviceAddress, CORE_DIGITAL_SENSOR_ADDRESSn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1682 | |
Vkadaba | 5:0728bde67bdb | 1683 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1684 | } |
ADIJake | 0:85855ecd3257 | 1685 | |
Vkadaba | 5:0728bde67bdb | 1686 | static ADMW_RESULT admw_SetDigitalChannelComms( |
Vkadaba | 5:0728bde67bdb | 1687 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1688 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1689 | ADMW1001_DIGITAL_SENSOR_COMMS *pDigitalComms) |
ADIJake | 0:85855ecd3257 | 1690 | { |
Vkadaba | 8:2f2775c34640 | 1691 | ADMW_CORE_Digital_Sensor_Comms_t digitalSensorComms; |
ADIJake | 0:85855ecd3257 | 1692 | |
ADIJake | 0:85855ecd3257 | 1693 | digitalSensorComms.VALUE16 = REG_RESET_VAL(CORE_DIGITAL_SENSOR_COMMSn); |
ADIJake | 0:85855ecd3257 | 1694 | |
Vkadaba | 23:bb685f35b08b | 1695 | if(pDigitalComms->useCustomCommsConfig) { |
ADIJake | 0:85855ecd3257 | 1696 | |
Vkadaba | 23:bb685f35b08b | 1697 | if(pDigitalComms->i2cClockSpeed == ADMW1001_DIGITAL_SENSOR_COMMS_I2C_CLOCK_SPEED_100K) { |
Vkadaba | 5:0728bde67bdb | 1698 | digitalSensorComms.I2C_Clock = CORE_DIGITAL_SENSOR_COMMS_I2C_100K; |
Vkadaba | 23:bb685f35b08b | 1699 | } else if(pDigitalComms->i2cClockSpeed == ADMW1001_DIGITAL_SENSOR_COMMS_I2C_CLOCK_SPEED_400K) { |
Vkadaba | 5:0728bde67bdb | 1700 | digitalSensorComms.I2C_Clock = CORE_DIGITAL_SENSOR_COMMS_I2C_400K; |
Vkadaba | 23:bb685f35b08b | 1701 | } else { |
Vkadaba | 5:0728bde67bdb | 1702 | ADMW_LOG_ERROR("Invalid I2C clock speed %d specified", |
Vkadaba | 23:bb685f35b08b | 1703 | pDigitalComms->i2cClockSpeed); |
Vkadaba | 5:0728bde67bdb | 1704 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1705 | } |
Vkadaba | 63:2655a04c00f5 | 1706 | } |
ADIJake | 0:85855ecd3257 | 1707 | WRITE_REG_U16(hDevice, digitalSensorComms.VALUE16, CORE_DIGITAL_SENSOR_COMMSn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1708 | |
Vkadaba | 5:0728bde67bdb | 1709 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1710 | } |
ADIJake | 0:85855ecd3257 | 1711 | |
Vkadaba | 5:0728bde67bdb | 1712 | ADMW_RESULT admw_SetI2cChannelConfig( |
Vkadaba | 5:0728bde67bdb | 1713 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1714 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1715 | ADMW1001_CHANNEL_CONFIG *pChannelConfig) |
ADIJake | 0:85855ecd3257 | 1716 | { |
Vkadaba | 5:0728bde67bdb | 1717 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 1718 | ADMW1001_I2C_CHANNEL_CONFIG *pI2cChannelConfig = |
ADIJake | 0:85855ecd3257 | 1719 | &pChannelConfig->i2cChannelConfig; |
ADIJake | 0:85855ecd3257 | 1720 | |
Vkadaba | 5:0728bde67bdb | 1721 | eRet = admw_SetChannelI2cSensorType(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1722 | pI2cChannelConfig->sensor); |
Vkadaba | 23:bb685f35b08b | 1723 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1724 | ADMW_LOG_ERROR("Failed to set I2C sensor type for channel %d", |
Vkadaba | 23:bb685f35b08b | 1725 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1726 | return eRet; |
ADIJake | 0:85855ecd3257 | 1727 | } |
ADIJake | 0:85855ecd3257 | 1728 | |
Vkadaba | 5:0728bde67bdb | 1729 | eRet = admw_SetChannelI2cSensorAddress(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1730 | pI2cChannelConfig->deviceAddress); |
Vkadaba | 23:bb685f35b08b | 1731 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1732 | ADMW_LOG_ERROR("Failed to set I2C sensor address for channel %d", |
Vkadaba | 23:bb685f35b08b | 1733 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1734 | return eRet; |
ADIJake | 0:85855ecd3257 | 1735 | } |
ADIJake | 0:85855ecd3257 | 1736 | |
Vkadaba | 5:0728bde67bdb | 1737 | eRet = admw_SetChannelDigitalSensorDetails(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1738 | pChannelConfig); |
Vkadaba | 23:bb685f35b08b | 1739 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1740 | ADMW_LOG_ERROR("Failed to set I2C sensor details for channel %d", |
Vkadaba | 23:bb685f35b08b | 1741 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1742 | return eRet; |
ADIJake | 0:85855ecd3257 | 1743 | } |
ADIJake | 0:85855ecd3257 | 1744 | |
Vkadaba | 5:0728bde67bdb | 1745 | eRet = admw_SetDigitalSensorFormat(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1746 | &pI2cChannelConfig->dataFormat); |
Vkadaba | 23:bb685f35b08b | 1747 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1748 | ADMW_LOG_ERROR("Failed to set I2C sensor data format for channel %d", |
Vkadaba | 23:bb685f35b08b | 1749 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1750 | return eRet; |
ADIJake | 0:85855ecd3257 | 1751 | } |
ADIJake | 0:85855ecd3257 | 1752 | |
ADIJake | 0:85855ecd3257 | 1753 | |
Vkadaba | 5:0728bde67bdb | 1754 | eRet = admw_SetDigitalChannelComms(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1755 | &pI2cChannelConfig->configureComms); |
Vkadaba | 23:bb685f35b08b | 1756 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1757 | ADMW_LOG_ERROR("Failed to set I2C comms for channel %d", |
Vkadaba | 23:bb685f35b08b | 1758 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1759 | return eRet; |
ADIJake | 0:85855ecd3257 | 1760 | } |
ADIJake | 0:85855ecd3257 | 1761 | |
Vkadaba | 5:0728bde67bdb | 1762 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1763 | } |
ADIJake | 0:85855ecd3257 | 1764 | |
Vkadaba | 5:0728bde67bdb | 1765 | static ADMW_RESULT admw_SetChannelSpiSensorType( |
Vkadaba | 5:0728bde67bdb | 1766 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1767 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1768 | ADMW1001_SPI_SENSOR_TYPE sensorType) |
ADIJake | 0:85855ecd3257 | 1769 | { |
Vkadaba | 8:2f2775c34640 | 1770 | ADMW_CORE_Sensor_Type_t sensorTypeReg; |
ADIJake | 0:85855ecd3257 | 1771 | |
ADIJake | 0:85855ecd3257 | 1772 | sensorTypeReg.VALUE16 = REG_RESET_VAL(CORE_SENSOR_TYPEn); |
ADIJake | 0:85855ecd3257 | 1773 | |
ADIJake | 0:85855ecd3257 | 1774 | /* Ensure that the sensor type is valid for this channel */ |
Vkadaba | 23:bb685f35b08b | 1775 | switch(sensorType) { |
Vkadaba | 58:aa9cd5072f66 | 1776 | case ADMW1001_SPI_SENSOR: |
Vkadaba | 23:bb685f35b08b | 1777 | |
Vkadaba | 23:bb685f35b08b | 1778 | sensorTypeReg.Sensor_Type = sensorType; |
Vkadaba | 23:bb685f35b08b | 1779 | break; |
Vkadaba | 23:bb685f35b08b | 1780 | default: |
Vkadaba | 23:bb685f35b08b | 1781 | ADMW_LOG_ERROR("Unsupported SPI sensor type %d specified", sensorType); |
Vkadaba | 23:bb685f35b08b | 1782 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1783 | } |
ADIJake | 0:85855ecd3257 | 1784 | |
ADIJake | 0:85855ecd3257 | 1785 | WRITE_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1786 | |
Vkadaba | 5:0728bde67bdb | 1787 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1788 | } |
ADIJake | 0:85855ecd3257 | 1789 | |
ADIJake | 0:85855ecd3257 | 1790 | |
Vkadaba | 5:0728bde67bdb | 1791 | ADMW_RESULT admw1001_SetChannelThresholdLimits( |
Vkadaba | 5:0728bde67bdb | 1792 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1793 | ADMW1001_CH_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 1794 | float32_t fHighThresholdLimit, |
ADIJake | 0:85855ecd3257 | 1795 | float32_t fLowThresholdLimit) |
ADIJake | 0:85855ecd3257 | 1796 | { |
ADIJake | 0:85855ecd3257 | 1797 | /* |
ADIJake | 0:85855ecd3257 | 1798 | * If the low/high limits are *both* set to 0 in memory, or NaNs, assume |
ADIJake | 0:85855ecd3257 | 1799 | * that they are unset, or not required, and use infinity defaults instead |
ADIJake | 0:85855ecd3257 | 1800 | */ |
Vkadaba | 23:bb685f35b08b | 1801 | if (fHighThresholdLimit == 0.0f && fLowThresholdLimit == 0.0f) { |
ADIJake | 0:85855ecd3257 | 1802 | fHighThresholdLimit = INFINITY; |
ADIJake | 0:85855ecd3257 | 1803 | fLowThresholdLimit = -INFINITY; |
Vkadaba | 23:bb685f35b08b | 1804 | } else { |
ADIJake | 0:85855ecd3257 | 1805 | if (isnan(fHighThresholdLimit)) |
ADIJake | 0:85855ecd3257 | 1806 | fHighThresholdLimit = INFINITY; |
ADIJake | 0:85855ecd3257 | 1807 | if (isnan(fLowThresholdLimit)) |
ADIJake | 0:85855ecd3257 | 1808 | fLowThresholdLimit = -INFINITY; |
ADIJake | 0:85855ecd3257 | 1809 | } |
ADIJake | 0:85855ecd3257 | 1810 | |
ADIJake | 0:85855ecd3257 | 1811 | WRITE_REG_FLOAT(hDevice, fHighThresholdLimit, |
ADIJake | 0:85855ecd3257 | 1812 | CORE_HIGH_THRESHOLD_LIMITn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1813 | WRITE_REG_FLOAT(hDevice, fLowThresholdLimit, |
ADIJake | 0:85855ecd3257 | 1814 | CORE_LOW_THRESHOLD_LIMITn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1815 | |
Vkadaba | 5:0728bde67bdb | 1816 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1817 | } |
ADIJake | 0:85855ecd3257 | 1818 | |
Vkadaba | 5:0728bde67bdb | 1819 | ADMW_RESULT admw1001_SetOffsetGain( |
Vkadaba | 5:0728bde67bdb | 1820 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1821 | ADMW1001_CH_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 1822 | float32_t fOffsetAdjustment, |
ADIJake | 0:85855ecd3257 | 1823 | float32_t fGainAdjustment) |
ADIJake | 0:85855ecd3257 | 1824 | { |
ADIJake | 0:85855ecd3257 | 1825 | /* Replace with default values if NaNs are specified (or 0.0 for gain) */ |
ADIJake | 0:85855ecd3257 | 1826 | if (isnan(fGainAdjustment) || (fGainAdjustment == 0.0f)) |
ADIJake | 0:85855ecd3257 | 1827 | fGainAdjustment = 1.0f; |
ADIJake | 0:85855ecd3257 | 1828 | if (isnan(fOffsetAdjustment)) |
ADIJake | 0:85855ecd3257 | 1829 | fOffsetAdjustment = 0.0f; |
ADIJake | 0:85855ecd3257 | 1830 | |
ADIJake | 0:85855ecd3257 | 1831 | WRITE_REG_FLOAT(hDevice, fGainAdjustment, CORE_SENSOR_GAINn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1832 | WRITE_REG_FLOAT(hDevice, fOffsetAdjustment, CORE_SENSOR_OFFSETn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1833 | |
Vkadaba | 5:0728bde67bdb | 1834 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1835 | } |
ADIJake | 0:85855ecd3257 | 1836 | |
Vkadaba | 5:0728bde67bdb | 1837 | ADMW_RESULT admw1001_SetSensorParameter( |
Vkadaba | 5:0728bde67bdb | 1838 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1839 | ADMW1001_CH_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 1840 | float32_t fSensorParam) |
ADIJake | 0:85855ecd3257 | 1841 | { |
ADIJake | 0:85855ecd3257 | 1842 | if (fSensorParam == 0.0f) |
ADIJake | 0:85855ecd3257 | 1843 | fSensorParam = NAN; |
ADIJake | 0:85855ecd3257 | 1844 | |
Vkadaba | 32:52445bef314d | 1845 | //WRITE_REG_FLOAT(hDevice, fSensorParam, CORE_SENSOR_PARAMETERn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1846 | |
Vkadaba | 5:0728bde67bdb | 1847 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1848 | } |
ADIJake | 0:85855ecd3257 | 1849 | |
Vkadaba | 5:0728bde67bdb | 1850 | ADMW_RESULT admw1001_SetChannelSettlingTime( |
Vkadaba | 5:0728bde67bdb | 1851 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1852 | ADMW1001_CH_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 1853 | uint32_t nSettlingTime) |
ADIJake | 0:85855ecd3257 | 1854 | { |
Vkadaba | 8:2f2775c34640 | 1855 | ADMW_CORE_Settling_Time_t settlingTimeReg; |
ADIJake | 0:85855ecd3257 | 1856 | |
ADIJake | 0:85855ecd3257 | 1857 | CHECK_REG_FIELD_VAL(CORE_SETTLING_TIME_SETTLING_TIME, nSettlingTime); |
ADIJake | 0:85855ecd3257 | 1858 | settlingTimeReg.Settling_Time = nSettlingTime; |
ADIJake | 0:85855ecd3257 | 1859 | |
ADIJake | 0:85855ecd3257 | 1860 | WRITE_REG_U16(hDevice, settlingTimeReg.VALUE16, CORE_SETTLING_TIMEn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1861 | |
Vkadaba | 5:0728bde67bdb | 1862 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1863 | } |
ADIJake | 0:85855ecd3257 | 1864 | |
Vkadaba | 5:0728bde67bdb | 1865 | ADMW_RESULT admw1001_SetChannelConfig( |
Vkadaba | 5:0728bde67bdb | 1866 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1867 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1868 | ADMW1001_CHANNEL_CONFIG *pChannelConfig) |
ADIJake | 0:85855ecd3257 | 1869 | { |
Vkadaba | 5:0728bde67bdb | 1870 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 1871 | |
Vkadaba | 5:0728bde67bdb | 1872 | eRet = admw1001_SetChannelCount(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1873 | pChannelConfig->enableChannel ? |
Vkadaba | 23:bb685f35b08b | 1874 | pChannelConfig->measurementsPerCycle : 0); |
Vkadaba | 23:bb685f35b08b | 1875 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1876 | ADMW_LOG_ERROR("Failed to set measurement count for channel %d", |
Vkadaba | 23:bb685f35b08b | 1877 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1878 | return eRet; |
ADIJake | 0:85855ecd3257 | 1879 | } |
ADIJake | 0:85855ecd3257 | 1880 | |
Vkadaba | 5:0728bde67bdb | 1881 | eRet = admw1001_SetChannelOptions(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1882 | pChannelConfig->priority); |
Vkadaba | 23:bb685f35b08b | 1883 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1884 | ADMW_LOG_ERROR("Failed to set priority for channel %d", |
Vkadaba | 23:bb685f35b08b | 1885 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1886 | return eRet; |
ADIJake | 0:85855ecd3257 | 1887 | } |
ADIJake | 0:85855ecd3257 | 1888 | |
ADIJake | 0:85855ecd3257 | 1889 | /* If the channel is not enabled, we can skip the following steps */ |
Vkadaba | 23:bb685f35b08b | 1890 | if (pChannelConfig->enableChannel) { |
Vkadaba | 5:0728bde67bdb | 1891 | eRet = admw1001_SetChannelSkipCount(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1892 | pChannelConfig->cycleSkipCount); |
Vkadaba | 23:bb685f35b08b | 1893 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1894 | ADMW_LOG_ERROR("Failed to set cycle skip count for channel %d", |
Vkadaba | 23:bb685f35b08b | 1895 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1896 | return eRet; |
ADIJake | 0:85855ecd3257 | 1897 | } |
ADIJake | 0:85855ecd3257 | 1898 | |
Vkadaba | 23:bb685f35b08b | 1899 | switch (eChannelId) { |
Vkadaba | 23:bb685f35b08b | 1900 | case ADMW1001_CH_ID_ANLG_1_UNIVERSAL: |
Vkadaba | 23:bb685f35b08b | 1901 | case ADMW1001_CH_ID_ANLG_2_UNIVERSAL: |
Vkadaba | 23:bb685f35b08b | 1902 | case ADMW1001_CH_ID_ANLG_1_DIFFERENTIAL: |
Vkadaba | 23:bb685f35b08b | 1903 | case ADMW1001_CH_ID_ANLG_2_DIFFERENTIAL: |
Vkadaba | 23:bb685f35b08b | 1904 | eRet = admw_SetAdcChannelConfig(hDevice, eChannelId, pChannelConfig); |
Vkadaba | 23:bb685f35b08b | 1905 | break; |
Vkadaba | 23:bb685f35b08b | 1906 | case ADMW1001_CH_ID_DIG_I2C_0: |
Vkadaba | 23:bb685f35b08b | 1907 | case ADMW1001_CH_ID_DIG_I2C_1: |
Vkadaba | 23:bb685f35b08b | 1908 | eRet = admw_SetI2cChannelConfig(hDevice, eChannelId, pChannelConfig); |
Vkadaba | 23:bb685f35b08b | 1909 | break; |
Vkadaba | 23:bb685f35b08b | 1910 | default: |
Vkadaba | 23:bb685f35b08b | 1911 | ADMW_LOG_ERROR("Invalid channel ID %d specified", eChannelId); |
Vkadaba | 32:52445bef314d | 1912 | eRet = ADMW_INVALID_PARAM; |
Vkadaba | 32:52445bef314d | 1913 | #if 0 |
Vkadaba | 32:52445bef314d | 1914 | /* when using i2c sensors there is an error ( dataformat->length=0) |
Vkadaba | 32:52445bef314d | 1915 | the code below catches this error and this causes further problems.*/ |
Vkadaba | 32:52445bef314d | 1916 | break; |
Vkadaba | 32:52445bef314d | 1917 | } |
Vkadaba | 32:52445bef314d | 1918 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 32:52445bef314d | 1919 | ADMW_LOG_ERROR("Failed to set config for channel %d", |
Vkadaba | 32:52445bef314d | 1920 | eChannelId); |
Vkadaba | 32:52445bef314d | 1921 | return eRet; |
Vkadaba | 32:52445bef314d | 1922 | #endif |
ADIJake | 0:85855ecd3257 | 1923 | } |
ADIJake | 0:85855ecd3257 | 1924 | |
Vkadaba | 5:0728bde67bdb | 1925 | eRet = admw1001_SetChannelSettlingTime(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1926 | pChannelConfig->extraSettlingTime); |
Vkadaba | 23:bb685f35b08b | 1927 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1928 | ADMW_LOG_ERROR("Failed to set settling time for channel %d", |
Vkadaba | 23:bb685f35b08b | 1929 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1930 | return eRet; |
ADIJake | 0:85855ecd3257 | 1931 | } |
ADIJake | 0:85855ecd3257 | 1932 | } |
ADIJake | 0:85855ecd3257 | 1933 | |
Vkadaba | 23:bb685f35b08b | 1934 | if (pChannelConfig->enableChannel) { |
ADIJake | 0:85855ecd3257 | 1935 | /* Threshold limits can be configured individually for virtual channels */ |
Vkadaba | 5:0728bde67bdb | 1936 | eRet = admw1001_SetChannelThresholdLimits(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1937 | pChannelConfig->highThreshold, |
Vkadaba | 23:bb685f35b08b | 1938 | pChannelConfig->lowThreshold); |
Vkadaba | 23:bb685f35b08b | 1939 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1940 | ADMW_LOG_ERROR("Failed to set threshold limits for channel %d", |
Vkadaba | 23:bb685f35b08b | 1941 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1942 | return eRet; |
ADIJake | 0:85855ecd3257 | 1943 | } |
ADIJake | 0:85855ecd3257 | 1944 | |
ADIJake | 0:85855ecd3257 | 1945 | /* Offset and gain can be configured individually for virtual channels */ |
Vkadaba | 5:0728bde67bdb | 1946 | eRet = admw1001_SetOffsetGain(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1947 | pChannelConfig->offsetAdjustment, |
Vkadaba | 23:bb685f35b08b | 1948 | pChannelConfig->gainAdjustment); |
Vkadaba | 23:bb685f35b08b | 1949 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1950 | ADMW_LOG_ERROR("Failed to set offset/gain for channel %d", |
Vkadaba | 23:bb685f35b08b | 1951 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1952 | return eRet; |
ADIJake | 0:85855ecd3257 | 1953 | } |
ADIJake | 0:85855ecd3257 | 1954 | |
ADIJake | 0:85855ecd3257 | 1955 | /* Set sensor specific parameter */ |
Vkadaba | 5:0728bde67bdb | 1956 | eRet = admw1001_SetSensorParameter(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1957 | pChannelConfig->sensorParameter); |
Vkadaba | 23:bb685f35b08b | 1958 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1959 | ADMW_LOG_ERROR("Failed to set sensor parameter for channel %d", |
Vkadaba | 23:bb685f35b08b | 1960 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1961 | return eRet; |
ADIJake | 0:85855ecd3257 | 1962 | } |
ADIJake | 0:85855ecd3257 | 1963 | } |
ADIJake | 0:85855ecd3257 | 1964 | |
Vkadaba | 5:0728bde67bdb | 1965 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1966 | } |
ADIJake | 0:85855ecd3257 | 1967 | |
Vkadaba | 5:0728bde67bdb | 1968 | ADMW_RESULT admw_SetConfig( |
Vkadaba | 5:0728bde67bdb | 1969 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 1970 | ADMW_CONFIG * const pConfig) |
ADIJake | 0:85855ecd3257 | 1971 | { |
Vkadaba | 5:0728bde67bdb | 1972 | ADMW1001_CONFIG *pDeviceConfig; |
Vkadaba | 5:0728bde67bdb | 1973 | ADMW_PRODUCT_ID productId; |
Vkadaba | 5:0728bde67bdb | 1974 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 1975 | |
Vkadaba | 23:bb685f35b08b | 1976 | if (pConfig->productId != ADMW_PRODUCT_ID_ADMW1001) { |
Vkadaba | 5:0728bde67bdb | 1977 | ADMW_LOG_ERROR("Configuration Product ID (0x%X) is not supported (0x%0X)", |
Vkadaba | 23:bb685f35b08b | 1978 | pConfig->productId, ADMW_PRODUCT_ID_ADMW1001); |
Vkadaba | 5:0728bde67bdb | 1979 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1980 | } |
Vkadaba | 23:bb685f35b08b | 1981 | |
Vkadaba | 23:bb685f35b08b | 1982 | if (!((pConfig->versionId.major==VERSIONID_MAJOR) && |
Vkadaba | 23:bb685f35b08b | 1983 | (pConfig->versionId.minor==VERSIONID_MINOR))) { |
Vkadaba | 23:bb685f35b08b | 1984 | ADMW_LOG_ERROR("Configuration Version ID (0x%X) is not supported", |
Vkadaba | 23:bb685f35b08b | 1985 | pConfig->versionId); |
Vkadaba | 6:9d393a9677f4 | 1986 | return ADMW_INVALID_PARAM; |
Vkadaba | 6:9d393a9677f4 | 1987 | } |
Vkadaba | 23:bb685f35b08b | 1988 | |
Vkadaba | 23:bb685f35b08b | 1989 | |
ADIJake | 0:85855ecd3257 | 1990 | /* Check that the actual Product ID is a match? */ |
Vkadaba | 5:0728bde67bdb | 1991 | eRet = admw_GetProductID(hDevice, &productId); |
Vkadaba | 23:bb685f35b08b | 1992 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 1993 | ADMW_LOG_ERROR("Failed to read device Product ID register"); |
ADIJake | 0:85855ecd3257 | 1994 | return eRet; |
ADIJake | 0:85855ecd3257 | 1995 | } |
Vkadaba | 23:bb685f35b08b | 1996 | if (pConfig->productId != productId) { |
Vkadaba | 5:0728bde67bdb | 1997 | ADMW_LOG_ERROR("Configuration Product ID (0x%X) does not match device (0x%0X)", |
Vkadaba | 8:2f2775c34640 | 1998 | pConfig->productId, productId); |
Vkadaba | 5:0728bde67bdb | 1999 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2000 | } |
ADIJake | 0:85855ecd3257 | 2001 | |
Vkadaba | 5:0728bde67bdb | 2002 | pDeviceConfig = &pConfig->admw1001; |
Vkadaba | 5:0728bde67bdb | 2003 | |
Vkadaba | 5:0728bde67bdb | 2004 | eRet = admw1001_SetPowerConfig(hDevice, &pDeviceConfig->power); |
Vkadaba | 23:bb685f35b08b | 2005 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 2006 | ADMW_LOG_ERROR("Failed to set power configuration"); |
ADIJake | 0:85855ecd3257 | 2007 | return eRet; |
ADIJake | 0:85855ecd3257 | 2008 | } |
ADIJake | 0:85855ecd3257 | 2009 | |
Vkadaba | 5:0728bde67bdb | 2010 | eRet = admw1001_SetMeasurementConfig(hDevice, &pDeviceConfig->measurement); |
Vkadaba | 23:bb685f35b08b | 2011 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 2012 | ADMW_LOG_ERROR("Failed to set measurement configuration"); |
ADIJake | 0:85855ecd3257 | 2013 | return eRet; |
ADIJake | 0:85855ecd3257 | 2014 | } |
ADIJake | 0:85855ecd3257 | 2015 | |
Vkadaba | 36:54e2418e7620 | 2016 | eRet = admw1001_SetDiagnosticsConfig(hDevice, &pDeviceConfig->diagnostics); |
Vkadaba | 41:df78b7d7b675 | 2017 | if (eRet) { |
Vkadaba | 36:54e2418e7620 | 2018 | ADMW_LOG_ERROR("Failed to set diagnostics configuration"); |
Vkadaba | 36:54e2418e7620 | 2019 | return eRet; |
Vkadaba | 36:54e2418e7620 | 2020 | } |
ADIJake | 0:85855ecd3257 | 2021 | |
Vkadaba | 8:2f2775c34640 | 2022 | for (ADMW1001_CH_ID id = ADMW1001_CH_ID_ANLG_1_UNIVERSAL; |
Vkadaba | 23:bb685f35b08b | 2023 | id < ADMW1001_MAX_CHANNELS; |
Vkadaba | 23:bb685f35b08b | 2024 | id++) { |
Vkadaba | 5:0728bde67bdb | 2025 | eRet = admw1001_SetChannelConfig(hDevice, id, |
Vkadaba | 23:bb685f35b08b | 2026 | &pDeviceConfig->channels[id]); |
Vkadaba | 23:bb685f35b08b | 2027 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 2028 | ADMW_LOG_ERROR("Failed to set channel %d configuration", id); |
ADIJake | 0:85855ecd3257 | 2029 | return eRet; |
ADIJake | 0:85855ecd3257 | 2030 | } |
ADIJake | 0:85855ecd3257 | 2031 | } |
ADIJake | 0:85855ecd3257 | 2032 | |
Vkadaba | 5:0728bde67bdb | 2033 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2034 | } |
ADIJake | 0:85855ecd3257 | 2035 | |
Vkadaba | 50:d84305e5e1c0 | 2036 | |
Vkadaba | 5:0728bde67bdb | 2037 | ADMW_RESULT admw1001_SetLutDataRaw( |
Vkadaba | 5:0728bde67bdb | 2038 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 2039 | ADMW1001_LUT_RAW * const pLutData) |
ADIJake | 0:85855ecd3257 | 2040 | { |
Vkadaba | 5:0728bde67bdb | 2041 | return admw1001_SetLutData(hDevice, |
Vkadaba | 23:bb685f35b08b | 2042 | (ADMW1001_LUT *)pLutData); |
ADIJake | 0:85855ecd3257 | 2043 | } |
ADIJake | 0:85855ecd3257 | 2044 | |
Vkadaba | 5:0728bde67bdb | 2045 | static ADMW_RESULT getLutTableSize( |
Vkadaba | 5:0728bde67bdb | 2046 | ADMW1001_LUT_DESCRIPTOR * const pDesc, |
Vkadaba | 5:0728bde67bdb | 2047 | ADMW1001_LUT_TABLE_DATA * const pData, |
ADIJake | 0:85855ecd3257 | 2048 | unsigned *pLength) |
ADIJake | 0:85855ecd3257 | 2049 | { |
Vkadaba | 23:bb685f35b08b | 2050 | switch (pDesc->geometry) { |
Vkadaba | 23:bb685f35b08b | 2051 | case ADMW1001_LUT_GEOMETRY_NES_1D: |
Vkadaba | 23:bb685f35b08b | 2052 | *pLength = ADMW1001_LUT_1D_NES_SIZE(pData->lut1dNes); |
Vkadaba | 23:bb685f35b08b | 2053 | break; |
Vkadaba | 23:bb685f35b08b | 2054 | default: |
Vkadaba | 23:bb685f35b08b | 2055 | ADMW_LOG_ERROR("Invalid LUT table geometry %d specified\r\n", |
Vkadaba | 23:bb685f35b08b | 2056 | pDesc->geometry); |
Vkadaba | 23:bb685f35b08b | 2057 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2058 | } |
ADIJake | 0:85855ecd3257 | 2059 | |
Vkadaba | 5:0728bde67bdb | 2060 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2061 | } |
ADIJake | 0:85855ecd3257 | 2062 | |
Vkadaba | 5:0728bde67bdb | 2063 | ADMW_RESULT admw1001_AssembleLutData( |
Vkadaba | 5:0728bde67bdb | 2064 | ADMW1001_LUT * pLutBuffer, |
ADIJake | 0:85855ecd3257 | 2065 | unsigned nLutBufferSize, |
ADIJake | 0:85855ecd3257 | 2066 | unsigned const nNumTables, |
Vkadaba | 5:0728bde67bdb | 2067 | ADMW1001_LUT_DESCRIPTOR * const ppDesc[], |
Vkadaba | 5:0728bde67bdb | 2068 | ADMW1001_LUT_TABLE_DATA * const ppData[]) |
ADIJake | 0:85855ecd3257 | 2069 | { |
Vkadaba | 5:0728bde67bdb | 2070 | ADMW1001_LUT_HEADER *pHdr = &pLutBuffer->header; |
ADIJake | 0:85855ecd3257 | 2071 | uint8_t *pLutTableData = (uint8_t *)pLutBuffer + sizeof(*pHdr); |
ADIJake | 0:85855ecd3257 | 2072 | |
Vkadaba | 61:0f16a2e3b58b | 2073 | if (sizeof(*pHdr) > nLutBufferSize) |
Vkadaba | 61:0f16a2e3b58b | 2074 | { |
Vkadaba | 5:0728bde67bdb | 2075 | ADMW_LOG_ERROR("Insufficient LUT buffer size provided"); |
Vkadaba | 5:0728bde67bdb | 2076 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2077 | } |
ADIJake | 0:85855ecd3257 | 2078 | |
ADIJake | 0:85855ecd3257 | 2079 | /* First initialise the top-level header */ |
Vkadaba | 5:0728bde67bdb | 2080 | pHdr->signature = ADMW_LUT_SIGNATURE; |
ADIJake | 0:85855ecd3257 | 2081 | pHdr->version.major = 1; |
ADIJake | 0:85855ecd3257 | 2082 | pHdr->version.minor = 0; |
ADIJake | 0:85855ecd3257 | 2083 | pHdr->numTables = 0; |
ADIJake | 0:85855ecd3257 | 2084 | pHdr->totalLength = 0; |
ADIJake | 0:85855ecd3257 | 2085 | |
ADIJake | 0:85855ecd3257 | 2086 | /* |
ADIJake | 0:85855ecd3257 | 2087 | * Walk through the list of table pointers provided, appending the table |
ADIJake | 0:85855ecd3257 | 2088 | * descriptor+data from each one to the provided LUT buffer |
ADIJake | 0:85855ecd3257 | 2089 | */ |
Vkadaba | 61:0f16a2e3b58b | 2090 | for (unsigned i = 0; i < nNumTables; i++) |
Vkadaba | 61:0f16a2e3b58b | 2091 | { |
Vkadaba | 5:0728bde67bdb | 2092 | ADMW1001_LUT_DESCRIPTOR * const pDesc = ppDesc[i]; |
Vkadaba | 5:0728bde67bdb | 2093 | ADMW1001_LUT_TABLE_DATA * const pData = ppData[i]; |
Vkadaba | 5:0728bde67bdb | 2094 | ADMW_RESULT res; |
ADIJake | 0:85855ecd3257 | 2095 | unsigned dataLength = 0; |
ADIJake | 0:85855ecd3257 | 2096 | |
ADIJake | 0:85855ecd3257 | 2097 | /* Calculate the length of the table data */ |
ADIJake | 0:85855ecd3257 | 2098 | res = getLutTableSize(pDesc, pData, &dataLength); |
Vkadaba | 5:0728bde67bdb | 2099 | if (res != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2100 | return res; |
ADIJake | 0:85855ecd3257 | 2101 | |
ADIJake | 0:85855ecd3257 | 2102 | /* Fill in the table descriptor length and CRC fields */ |
ADIJake | 0:85855ecd3257 | 2103 | pDesc->length = dataLength; |
ADIJake | 0:85855ecd3257 | 2104 | |
Vkadaba | 61:0f16a2e3b58b | 2105 | if ((sizeof(*pHdr) + pHdr->totalLength + sizeof(*pDesc) + dataLength) > nLutBufferSize) |
Vkadaba | 61:0f16a2e3b58b | 2106 | { |
Vkadaba | 5:0728bde67bdb | 2107 | ADMW_LOG_ERROR("Insufficient LUT buffer size provided"); |
Vkadaba | 5:0728bde67bdb | 2108 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2109 | } |
ADIJake | 0:85855ecd3257 | 2110 | |
ADIJake | 0:85855ecd3257 | 2111 | /* Append the table to the LUT buffer (desc + data) */ |
ADIJake | 0:85855ecd3257 | 2112 | memcpy(pLutTableData + pHdr->totalLength, pDesc, sizeof(*pDesc)); |
ADIJake | 0:85855ecd3257 | 2113 | pHdr->totalLength += sizeof(*pDesc); |
ADIJake | 0:85855ecd3257 | 2114 | memcpy(pLutTableData + pHdr->totalLength, pData, dataLength); |
ADIJake | 0:85855ecd3257 | 2115 | pHdr->totalLength += dataLength; |
ADIJake | 0:85855ecd3257 | 2116 | |
ADIJake | 0:85855ecd3257 | 2117 | pHdr->numTables++; |
ADIJake | 0:85855ecd3257 | 2118 | } |
ADIJake | 0:85855ecd3257 | 2119 | |
Vkadaba | 5:0728bde67bdb | 2120 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2121 | } |
Vkadaba | 54:31921ad29828 | 2122 | ADMW_RESULT admw1001_SetLutData( |
Vkadaba | 54:31921ad29828 | 2123 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 54:31921ad29828 | 2124 | ADMW1001_LUT * const pLutData) |
Vkadaba | 54:31921ad29828 | 2125 | { |
Vkadaba | 61:0f16a2e3b58b | 2126 | #pragma diag_suppress=Pa039 |
Vkadaba | 54:31921ad29828 | 2127 | ADMW1001_LUT_HEADER *pLutHeader = &pLutData->header; |
Vkadaba | 54:31921ad29828 | 2128 | ADMW1001_LUT_TABLE *pLutTable = pLutData->tables; |
Vkadaba | 54:31921ad29828 | 2129 | |
Vkadaba | 54:31921ad29828 | 2130 | unsigned actualLength = 0; |
Vkadaba | 54:31921ad29828 | 2131 | |
Vkadaba | 61:0f16a2e3b58b | 2132 | if (pLutData->header.signature != ADMW_LUT_SIGNATURE) |
Vkadaba | 61:0f16a2e3b58b | 2133 | { |
Vkadaba | 54:31921ad29828 | 2134 | ADMW_LOG_ERROR("LUT signature incorrect (expected 0x%X, actual 0x%X)", |
Vkadaba | 61:0f16a2e3b58b | 2135 | ADMW_LUT_SIGNATURE, pLutHeader->signature); |
Vkadaba | 54:31921ad29828 | 2136 | return ADMW_INVALID_SIGNATURE; |
Vkadaba | 54:31921ad29828 | 2137 | } |
Vkadaba | 54:31921ad29828 | 2138 | if ((pLutData->tables->descriptor.geometry!= ADMW1001_LUT_GEOMETRY_NES_1D) && |
Vkadaba | 61:0f16a2e3b58b | 2139 | (pLutData->tables->data.lut1dNes.nElements > MAX_LUT_NUM_ENTRIES)) |
Vkadaba | 61:0f16a2e3b58b | 2140 | { |
Vkadaba | 54:31921ad29828 | 2141 | return ADMW_INVALID_PARAM; |
Vkadaba | 54:31921ad29828 | 2142 | } |
Vkadaba | 61:0f16a2e3b58b | 2143 | for (unsigned i = 0; i < pLutHeader->numTables; i++) |
Vkadaba | 61:0f16a2e3b58b | 2144 | { |
Vkadaba | 54:31921ad29828 | 2145 | ADMW1001_LUT_DESCRIPTOR *pDesc = &pLutTable->descriptor; |
Vkadaba | 54:31921ad29828 | 2146 | |
Vkadaba | 61:0f16a2e3b58b | 2147 | switch (pDesc->geometry) |
Vkadaba | 61:0f16a2e3b58b | 2148 | { |
Vkadaba | 61:0f16a2e3b58b | 2149 | case ADMW1001_LUT_GEOMETRY_COEFFS: |
Vkadaba | 61:0f16a2e3b58b | 2150 | switch (pDesc->equation) |
Vkadaba | 61:0f16a2e3b58b | 2151 | { |
Vkadaba | 61:0f16a2e3b58b | 2152 | case ADMW1001_LUT_EQUATION_POLYN: |
Vkadaba | 61:0f16a2e3b58b | 2153 | case ADMW1001_LUT_EQUATION_POLYNEXP: |
Vkadaba | 61:0f16a2e3b58b | 2154 | case ADMW1001_LUT_EQUATION_QUADRATIC: |
Vkadaba | 61:0f16a2e3b58b | 2155 | case ADMW1001_LUT_EQUATION_STEINHART: |
Vkadaba | 61:0f16a2e3b58b | 2156 | case ADMW1001_LUT_EQUATION_LOGARITHMIC: |
Vkadaba | 61:0f16a2e3b58b | 2157 | case ADMW1001_LUT_EQUATION_BIVARIATE_POLYN: |
Vkadaba | 61:0f16a2e3b58b | 2158 | break; |
Vkadaba | 61:0f16a2e3b58b | 2159 | default: |
Vkadaba | 61:0f16a2e3b58b | 2160 | ADMW_LOG_ERROR("Invalid equation %u specified for LUT table %u", |
Vkadaba | 61:0f16a2e3b58b | 2161 | pDesc->equation, i); |
Vkadaba | 61:0f16a2e3b58b | 2162 | return ADMW_INVALID_PARAM; |
Vkadaba | 55:215da406282b | 2163 | } |
Vkadaba | 61:0f16a2e3b58b | 2164 | break; |
Vkadaba | 61:0f16a2e3b58b | 2165 | case ADMW1001_LUT_GEOMETRY_NES_1D: |
Vkadaba | 61:0f16a2e3b58b | 2166 | break; |
Vkadaba | 61:0f16a2e3b58b | 2167 | default: |
Vkadaba | 61:0f16a2e3b58b | 2168 | ADMW_LOG_ERROR("Invalid geometry %u specified for LUT table %u", |
Vkadaba | 61:0f16a2e3b58b | 2169 | pDesc->geometry, i); |
Vkadaba | 61:0f16a2e3b58b | 2170 | return ADMW_INVALID_PARAM; |
Vkadaba | 54:31921ad29828 | 2171 | } |
Vkadaba | 54:31921ad29828 | 2172 | |
Vkadaba | 61:0f16a2e3b58b | 2173 | switch (pDesc->dataType) |
Vkadaba | 61:0f16a2e3b58b | 2174 | { |
Vkadaba | 61:0f16a2e3b58b | 2175 | case ADMW1001_LUT_DATA_TYPE_FLOAT32: |
Vkadaba | 61:0f16a2e3b58b | 2176 | case ADMW1001_LUT_DATA_TYPE_FLOAT64: |
Vkadaba | 61:0f16a2e3b58b | 2177 | break; |
Vkadaba | 61:0f16a2e3b58b | 2178 | default: |
Vkadaba | 61:0f16a2e3b58b | 2179 | ADMW_LOG_ERROR("Invalid vector format %u specified for LUT table %u", |
Vkadaba | 61:0f16a2e3b58b | 2180 | pDesc->dataType, i); |
Vkadaba | 61:0f16a2e3b58b | 2181 | return ADMW_INVALID_PARAM; |
Vkadaba | 54:31921ad29828 | 2182 | } |
Vkadaba | 54:31921ad29828 | 2183 | |
Vkadaba | 54:31921ad29828 | 2184 | |
Vkadaba | 54:31921ad29828 | 2185 | actualLength += sizeof(*pDesc) + pDesc->length; |
Vkadaba | 54:31921ad29828 | 2186 | |
Vkadaba | 54:31921ad29828 | 2187 | /* Move to the next look-up table */ |
Vkadaba | 54:31921ad29828 | 2188 | pLutTable = (ADMW1001_LUT_TABLE *)((uint8_t *)pLutTable + sizeof(*pDesc) + pDesc->length); |
Vkadaba | 54:31921ad29828 | 2189 | } |
Vkadaba | 54:31921ad29828 | 2190 | |
Vkadaba | 61:0f16a2e3b58b | 2191 | if (actualLength != pLutHeader->totalLength) |
Vkadaba | 61:0f16a2e3b58b | 2192 | { |
Vkadaba | 54:31921ad29828 | 2193 | ADMW_LOG_ERROR("LUT table length mismatch (expected %u, actual %u)", |
Vkadaba | 61:0f16a2e3b58b | 2194 | pLutHeader->totalLength, actualLength); |
Vkadaba | 54:31921ad29828 | 2195 | return ADMW_WRONG_SIZE; |
Vkadaba | 54:31921ad29828 | 2196 | } |
Vkadaba | 54:31921ad29828 | 2197 | |
Vkadaba | 61:0f16a2e3b58b | 2198 | if (sizeof(*pLutHeader) + pLutHeader->totalLength > ADMW_LUT_MAX_SIZE) |
Vkadaba | 61:0f16a2e3b58b | 2199 | { |
Vkadaba | 54:31921ad29828 | 2200 | ADMW_LOG_ERROR("Maximum LUT table length (%u bytes) exceeded", |
Vkadaba | 61:0f16a2e3b58b | 2201 | ADMW_LUT_MAX_SIZE); |
Vkadaba | 54:31921ad29828 | 2202 | return ADMW_WRONG_SIZE; |
Vkadaba | 54:31921ad29828 | 2203 | } |
Vkadaba | 54:31921ad29828 | 2204 | |
Vkadaba | 54:31921ad29828 | 2205 | /* Write the LUT data to the device */ |
Vkadaba | 54:31921ad29828 | 2206 | unsigned lutSize = sizeof(*pLutHeader) + pLutHeader->totalLength; |
Vkadaba | 54:31921ad29828 | 2207 | WRITE_REG_U16(hDevice, 0, CORE_LUT_OFFSET); |
Vkadaba | 54:31921ad29828 | 2208 | WRITE_REG_U8_ARRAY(hDevice, (uint8_t *)pLutData, lutSize, CORE_LUT_DATA); |
Vkadaba | 54:31921ad29828 | 2209 | |
Vkadaba | 54:31921ad29828 | 2210 | return ADMW_SUCCESS; |
Vkadaba | 54:31921ad29828 | 2211 | } |