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