Vybhav Kadaba
/
EV-PRO-MW1001_dec12
MWARE-1930 fixed
src/admw_1001.c@42:c9c5a22e539e, 2019-12-10 (annotated)
- Committer:
- Vkadaba
- Date:
- Tue Dec 10 09:00:11 2019 +0000
- Revision:
- 42:c9c5a22e539e
- Parent:
- 41:df78b7d7b675
Printing correct firmware version
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)); |
ADIJake | 0:85855ecd3257 | 648 | |
Vkadaba | 23:bb685f35b08b | 649 | for (unsigned i = 0; i < nRequested; i++) { |
ADIJake | 0:85855ecd3257 | 650 | bool bHoldCs = true; |
ADIJake | 0:85855ecd3257 | 651 | |
ADIJake | 0:85855ecd3257 | 652 | /* Keep the CS signal asserted for all but the last sample */ |
ADIJake | 0:85855ecd3257 | 653 | if ((i + 1) == nRequested) |
ADIJake | 0:85855ecd3257 | 654 | bHoldCs = false; |
ADIJake | 0:85855ecd3257 | 655 | |
ADIJake | 0:85855ecd3257 | 656 | getDataCnt++; |
ADIJake | 0:85855ecd3257 | 657 | |
Vkadaba | 5:0728bde67bdb | 658 | eRet = admw_SpiTransfer(pCtx->hSpi, NULL, &sensorResult, |
Vkadaba | 23:bb685f35b08b | 659 | nBytesPerSample, bHoldCs); |
Vkadaba | 23:bb685f35b08b | 660 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 661 | ADMW_LOG_ERROR("Failed to read data from FIFO register"); |
ADIJake | 0:85855ecd3257 | 662 | return eRet; |
ADIJake | 0:85855ecd3257 | 663 | } |
ADIJake | 0:85855ecd3257 | 664 | |
Vkadaba | 23:bb685f35b08b | 665 | if (! sensorResult.Ch_Valid) { |
ADIJake | 0:85855ecd3257 | 666 | /* |
ADIJake | 0:85855ecd3257 | 667 | * Reading an invalid sample indicates that there are no |
ADIJake | 0:85855ecd3257 | 668 | * more samples available or we've lost sync with the device. |
ADIJake | 0:85855ecd3257 | 669 | * In the latter case, it might be recoverable, but return here |
ADIJake | 0:85855ecd3257 | 670 | * to let the application check the device status and decide itself. |
ADIJake | 0:85855ecd3257 | 671 | */ |
Vkadaba | 5:0728bde67bdb | 672 | eRet = ADMW_INCOMPLETE; |
ADIJake | 0:85855ecd3257 | 673 | break; |
ADIJake | 0:85855ecd3257 | 674 | } |
ADIJake | 0:85855ecd3257 | 675 | |
Vkadaba | 5:0728bde67bdb | 676 | ADMW_DATA_SAMPLE *pSample = &pSamples[nValidSamples]; |
Vkadaba | 5:0728bde67bdb | 677 | |
Vkadaba | 5:0728bde67bdb | 678 | pSample->status = (ADMW_DEVICE_STATUS_FLAGS)0; |
ADIJake | 0:85855ecd3257 | 679 | if (sensorResult.Ch_Error) |
Vkadaba | 5:0728bde67bdb | 680 | pSample->status |= ADMW_DEVICE_STATUS_ERROR; |
ADIJake | 0:85855ecd3257 | 681 | if (sensorResult.Ch_Alert) |
Vkadaba | 5:0728bde67bdb | 682 | pSample->status |= ADMW_DEVICE_STATUS_ALERT; |
ADIJake | 0:85855ecd3257 | 683 | |
ADIJake | 0:85855ecd3257 | 684 | if (sensorResult.Ch_Raw) |
ADIJake | 0:85855ecd3257 | 685 | pSample->rawValue = sensorResult.Raw_Sample; |
ADIJake | 0:85855ecd3257 | 686 | else |
ADIJake | 0:85855ecd3257 | 687 | pSample->rawValue = 0; |
ADIJake | 0:85855ecd3257 | 688 | |
ADIJake | 0:85855ecd3257 | 689 | pSample->channelId = sensorResult.Channel_ID; |
ADIJake | 0:85855ecd3257 | 690 | pSample->processedValue = sensorResult.Sensor_Result; |
ADIJake | 0:85855ecd3257 | 691 | |
ADIJake | 0:85855ecd3257 | 692 | nValidSamples++; |
ADIJake | 0:85855ecd3257 | 693 | |
Vkadaba | 5:0728bde67bdb | 694 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
ADIJake | 0:85855ecd3257 | 695 | } |
ADIJake | 0:85855ecd3257 | 696 | *pnReturned = nValidSamples; |
ADIJake | 0:85855ecd3257 | 697 | |
ADIJake | 0:85855ecd3257 | 698 | return eRet; |
ADIJake | 0:85855ecd3257 | 699 | } |
ADIJake | 0:85855ecd3257 | 700 | |
ADIJake | 0:85855ecd3257 | 701 | /* |
Vkadaba | 5:0728bde67bdb | 702 | * Close the given ADMW device. |
ADIJake | 0:85855ecd3257 | 703 | */ |
Vkadaba | 5:0728bde67bdb | 704 | ADMW_RESULT admw_Close( |
Vkadaba | 5:0728bde67bdb | 705 | ADMW_DEVICE_HANDLE const hDevice) |
ADIJake | 0:85855ecd3257 | 706 | { |
Vkadaba | 5:0728bde67bdb | 707 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 5:0728bde67bdb | 708 | |
Vkadaba | 5:0728bde67bdb | 709 | admw_GpioClose(pCtx->hGpio); |
Vkadaba | 5:0728bde67bdb | 710 | admw_SpiClose(pCtx->hSpi); |
Vkadaba | 5:0728bde67bdb | 711 | admw_LogClose(); |
Vkadaba | 5:0728bde67bdb | 712 | |
Vkadaba | 5:0728bde67bdb | 713 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 714 | } |
ADIJake | 0:85855ecd3257 | 715 | |
Vkadaba | 5:0728bde67bdb | 716 | ADMW_RESULT admw1001_WriteRegister( |
Vkadaba | 5:0728bde67bdb | 717 | ADMW_DEVICE_HANDLE hDevice, |
ADIJake | 0:85855ecd3257 | 718 | uint16_t nAddress, |
ADIJake | 0:85855ecd3257 | 719 | void *pData, |
ADIJake | 0:85855ecd3257 | 720 | unsigned nLength) |
ADIJake | 0:85855ecd3257 | 721 | { |
Vkadaba | 5:0728bde67bdb | 722 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 723 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 5:0728bde67bdb | 724 | uint16_t command = ADMW1001_HOST_COMMS_WRITE_CMD | |
Vkadaba | 23:bb685f35b08b | 725 | (nAddress & ADMW1001_HOST_COMMS_ADR_MASK); |
ADIJake | 0:85855ecd3257 | 726 | uint8_t commandData[2] = { |
ADIJake | 0:85855ecd3257 | 727 | command >> 8, |
ADIJake | 0:85855ecd3257 | 728 | command & 0xFF |
ADIJake | 0:85855ecd3257 | 729 | }; |
ADIJake | 0:85855ecd3257 | 730 | uint8_t commandResponse[2]; |
ADIJake | 0:85855ecd3257 | 731 | |
ADIJake | 0:85855ecd3257 | 732 | do { |
Vkadaba | 5:0728bde67bdb | 733 | eRet = admw_SpiTransfer(pCtx->hSpi, commandData, commandResponse, |
Vkadaba | 23:bb685f35b08b | 734 | sizeof(command), false); |
Vkadaba | 23:bb685f35b08b | 735 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 736 | ADMW_LOG_ERROR("Failed to send write command for register %u", |
Vkadaba | 23:bb685f35b08b | 737 | nAddress); |
ADIJake | 0:85855ecd3257 | 738 | return eRet; |
ADIJake | 0:85855ecd3257 | 739 | } |
ADIJake | 0:85855ecd3257 | 740 | |
Vkadaba | 5:0728bde67bdb | 741 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 5:0728bde67bdb | 742 | } while ((commandResponse[0] != ADMW1001_HOST_COMMS_CMD_RESP_0) || |
Vkadaba | 5:0728bde67bdb | 743 | (commandResponse[1] != ADMW1001_HOST_COMMS_CMD_RESP_1)); |
Vkadaba | 5:0728bde67bdb | 744 | |
Vkadaba | 5:0728bde67bdb | 745 | eRet = admw_SpiTransfer(pCtx->hSpi, pData, NULL, nLength, false); |
Vkadaba | 23:bb685f35b08b | 746 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 747 | ADMW_LOG_ERROR("Failed to write data (%dB) to register %u", |
Vkadaba | 23:bb685f35b08b | 748 | nLength, nAddress); |
ADIJake | 0:85855ecd3257 | 749 | return eRet; |
ADIJake | 0:85855ecd3257 | 750 | } |
ADIJake | 0:85855ecd3257 | 751 | |
Vkadaba | 5:0728bde67bdb | 752 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 5:0728bde67bdb | 753 | |
Vkadaba | 5:0728bde67bdb | 754 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 755 | } |
ADIJake | 0:85855ecd3257 | 756 | |
Vkadaba | 6:9d393a9677f4 | 757 | ADMW_RESULT admw1001_Write_Debug_Register( |
Vkadaba | 6:9d393a9677f4 | 758 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 6:9d393a9677f4 | 759 | uint16_t nAddress, |
Vkadaba | 6:9d393a9677f4 | 760 | void *pData, |
Vkadaba | 6:9d393a9677f4 | 761 | unsigned nLength) |
Vkadaba | 6:9d393a9677f4 | 762 | { |
Vkadaba | 6:9d393a9677f4 | 763 | ADMW_RESULT eRet; |
Vkadaba | 6:9d393a9677f4 | 764 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 6:9d393a9677f4 | 765 | uint16_t command = ADMW1001_HOST_COMMS_DEBUG_WRITE_CMD | |
Vkadaba | 23:bb685f35b08b | 766 | (nAddress & ADMW1001_HOST_COMMS_ADR_MASK); |
Vkadaba | 6:9d393a9677f4 | 767 | uint8_t commandData[2] = { |
Vkadaba | 6:9d393a9677f4 | 768 | command >> 8, |
Vkadaba | 6:9d393a9677f4 | 769 | command & 0xFF |
Vkadaba | 6:9d393a9677f4 | 770 | }; |
Vkadaba | 6:9d393a9677f4 | 771 | uint8_t commandResponse[2]; |
Vkadaba | 6:9d393a9677f4 | 772 | |
Vkadaba | 6:9d393a9677f4 | 773 | do { |
Vkadaba | 6:9d393a9677f4 | 774 | eRet = admw_SpiTransfer(pCtx->hSpi, commandData, commandResponse, |
Vkadaba | 23:bb685f35b08b | 775 | sizeof(command), false); |
Vkadaba | 23:bb685f35b08b | 776 | if (eRet) { |
Vkadaba | 6:9d393a9677f4 | 777 | ADMW_LOG_ERROR("Failed to send write command for register %u", |
Vkadaba | 23:bb685f35b08b | 778 | nAddress); |
Vkadaba | 6:9d393a9677f4 | 779 | return eRet; |
Vkadaba | 6:9d393a9677f4 | 780 | } |
Vkadaba | 6:9d393a9677f4 | 781 | |
Vkadaba | 6:9d393a9677f4 | 782 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 6:9d393a9677f4 | 783 | } while ((commandResponse[0] != ADMW1001_HOST_COMMS_CMD_RESP_0) || |
Vkadaba | 6:9d393a9677f4 | 784 | (commandResponse[1] != ADMW1001_HOST_COMMS_CMD_RESP_1)); |
Vkadaba | 6:9d393a9677f4 | 785 | |
Vkadaba | 6:9d393a9677f4 | 786 | eRet = admw_SpiTransfer(pCtx->hSpi, pData, NULL, nLength, false); |
Vkadaba | 23:bb685f35b08b | 787 | if (eRet) { |
Vkadaba | 6:9d393a9677f4 | 788 | ADMW_LOG_ERROR("Failed to write data (%dB) to register %u", |
Vkadaba | 23:bb685f35b08b | 789 | nLength, nAddress); |
Vkadaba | 6:9d393a9677f4 | 790 | return eRet; |
Vkadaba | 6:9d393a9677f4 | 791 | } |
Vkadaba | 6:9d393a9677f4 | 792 | |
Vkadaba | 6:9d393a9677f4 | 793 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 6:9d393a9677f4 | 794 | |
Vkadaba | 6:9d393a9677f4 | 795 | return ADMW_SUCCESS; |
Vkadaba | 6:9d393a9677f4 | 796 | } |
Vkadaba | 5:0728bde67bdb | 797 | ADMW_RESULT admw1001_ReadRegister( |
Vkadaba | 5:0728bde67bdb | 798 | ADMW_DEVICE_HANDLE hDevice, |
ADIJake | 0:85855ecd3257 | 799 | uint16_t nAddress, |
ADIJake | 0:85855ecd3257 | 800 | void *pData, |
ADIJake | 0:85855ecd3257 | 801 | unsigned nLength) |
ADIJake | 0:85855ecd3257 | 802 | { |
Vkadaba | 5:0728bde67bdb | 803 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 804 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 5:0728bde67bdb | 805 | uint16_t command = ADMW1001_HOST_COMMS_READ_CMD | |
Vkadaba | 23:bb685f35b08b | 806 | (nAddress & ADMW1001_HOST_COMMS_ADR_MASK); |
ADIJake | 0:85855ecd3257 | 807 | uint8_t commandData[2] = { |
ADIJake | 0:85855ecd3257 | 808 | command >> 8, |
ADIJake | 0:85855ecd3257 | 809 | command & 0xFF |
ADIJake | 0:85855ecd3257 | 810 | }; |
ADIJake | 0:85855ecd3257 | 811 | uint8_t commandResponse[2]; |
ADIJake | 0:85855ecd3257 | 812 | |
ADIJake | 0:85855ecd3257 | 813 | do { |
Vkadaba | 5:0728bde67bdb | 814 | eRet = admw_SpiTransfer(pCtx->hSpi, commandData, commandResponse, |
Vkadaba | 23:bb685f35b08b | 815 | sizeof(command), false); |
Vkadaba | 23:bb685f35b08b | 816 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 817 | ADMW_LOG_ERROR("Failed to send read command for register %u", |
Vkadaba | 23:bb685f35b08b | 818 | nAddress); |
ADIJake | 0:85855ecd3257 | 819 | return eRet; |
ADIJake | 0:85855ecd3257 | 820 | } |
ADIJake | 0:85855ecd3257 | 821 | |
Vkadaba | 5:0728bde67bdb | 822 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 5:0728bde67bdb | 823 | } while ((commandResponse[0] != ADMW1001_HOST_COMMS_CMD_RESP_0) || |
Vkadaba | 5:0728bde67bdb | 824 | (commandResponse[1] != ADMW1001_HOST_COMMS_CMD_RESP_1)); |
Vkadaba | 5:0728bde67bdb | 825 | |
Vkadaba | 5:0728bde67bdb | 826 | eRet = admw_SpiTransfer(pCtx->hSpi, NULL, pData, nLength, false); |
Vkadaba | 23:bb685f35b08b | 827 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 828 | ADMW_LOG_ERROR("Failed to read data (%uB) from register %u", |
Vkadaba | 23:bb685f35b08b | 829 | nLength, nAddress); |
ADIJake | 0:85855ecd3257 | 830 | return eRet; |
ADIJake | 0:85855ecd3257 | 831 | } |
ADIJake | 0:85855ecd3257 | 832 | |
Vkadaba | 5:0728bde67bdb | 833 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 5:0728bde67bdb | 834 | |
Vkadaba | 5:0728bde67bdb | 835 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 836 | } |
ADIJake | 0:85855ecd3257 | 837 | |
Vkadaba | 6:9d393a9677f4 | 838 | ADMW_RESULT admw1001_Read_Debug_Register( |
Vkadaba | 6:9d393a9677f4 | 839 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 6:9d393a9677f4 | 840 | uint16_t nAddress, |
Vkadaba | 6:9d393a9677f4 | 841 | void *pData, |
Vkadaba | 6:9d393a9677f4 | 842 | unsigned nLength) |
Vkadaba | 6:9d393a9677f4 | 843 | { |
Vkadaba | 6:9d393a9677f4 | 844 | ADMW_RESULT eRet; |
Vkadaba | 6:9d393a9677f4 | 845 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 6:9d393a9677f4 | 846 | uint16_t command = ADMW1001_HOST_COMMS_DEBUG_READ_CMD | |
Vkadaba | 23:bb685f35b08b | 847 | (nAddress & ADMW1001_HOST_COMMS_ADR_MASK); |
Vkadaba | 6:9d393a9677f4 | 848 | uint8_t commandData[2] = { |
Vkadaba | 6:9d393a9677f4 | 849 | command >> 8, |
Vkadaba | 6:9d393a9677f4 | 850 | command & 0xFF |
Vkadaba | 6:9d393a9677f4 | 851 | }; |
Vkadaba | 6:9d393a9677f4 | 852 | uint8_t commandResponse[2]; |
Vkadaba | 6:9d393a9677f4 | 853 | |
Vkadaba | 6:9d393a9677f4 | 854 | do { |
Vkadaba | 6:9d393a9677f4 | 855 | eRet = admw_SpiTransfer(pCtx->hSpi, commandData, commandResponse, |
Vkadaba | 23:bb685f35b08b | 856 | sizeof(command), false); |
Vkadaba | 23:bb685f35b08b | 857 | if (eRet) { |
Vkadaba | 6:9d393a9677f4 | 858 | ADMW_LOG_ERROR("Failed to send read command for register %u", |
Vkadaba | 23:bb685f35b08b | 859 | nAddress); |
Vkadaba | 6:9d393a9677f4 | 860 | return eRet; |
Vkadaba | 6:9d393a9677f4 | 861 | } |
Vkadaba | 6:9d393a9677f4 | 862 | |
Vkadaba | 6:9d393a9677f4 | 863 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 6:9d393a9677f4 | 864 | } while ((commandResponse[0] != ADMW1001_HOST_COMMS_CMD_RESP_0) || |
Vkadaba | 6:9d393a9677f4 | 865 | (commandResponse[1] != ADMW1001_HOST_COMMS_CMD_RESP_1)); |
Vkadaba | 6:9d393a9677f4 | 866 | |
Vkadaba | 6:9d393a9677f4 | 867 | eRet = admw_SpiTransfer(pCtx->hSpi, NULL, pData, nLength, false); |
Vkadaba | 23:bb685f35b08b | 868 | if (eRet) { |
Vkadaba | 6:9d393a9677f4 | 869 | ADMW_LOG_ERROR("Failed to read data (%uB) from register %u", |
Vkadaba | 23:bb685f35b08b | 870 | nLength, nAddress); |
Vkadaba | 6:9d393a9677f4 | 871 | return eRet; |
Vkadaba | 6:9d393a9677f4 | 872 | } |
Vkadaba | 6:9d393a9677f4 | 873 | |
Vkadaba | 6:9d393a9677f4 | 874 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 6:9d393a9677f4 | 875 | |
Vkadaba | 6:9d393a9677f4 | 876 | return ADMW_SUCCESS; |
Vkadaba | 6:9d393a9677f4 | 877 | } |
Vkadaba | 5:0728bde67bdb | 878 | ADMW_RESULT admw_GetDeviceReadyState( |
Vkadaba | 5:0728bde67bdb | 879 | ADMW_DEVICE_HANDLE const hDevice, |
ADIJake | 0:85855ecd3257 | 880 | bool * const bReady) |
ADIJake | 0:85855ecd3257 | 881 | { |
Vkadaba | 5:0728bde67bdb | 882 | ADMW_SPI_Chip_Type_t chipTypeReg; |
ADIJake | 0:85855ecd3257 | 883 | |
ADIJake | 0:85855ecd3257 | 884 | READ_REG_U8(hDevice, chipTypeReg.VALUE8, SPI_CHIP_TYPE); |
ADIJake | 0:85855ecd3257 | 885 | /* If we read this register successfully, assume the device is ready */ |
Vkadaba | 5:0728bde67bdb | 886 | *bReady = (chipTypeReg.VALUE8 == REG_SPI_CHIP_TYPE_RESET); |
Vkadaba | 5:0728bde67bdb | 887 | |
Vkadaba | 5:0728bde67bdb | 888 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 889 | } |
ADIJake | 0:85855ecd3257 | 890 | |
Vkadaba | 5:0728bde67bdb | 891 | ADMW_RESULT admw1001_GetDataReadyModeInfo( |
Vkadaba | 8:2f2775c34640 | 892 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 8:2f2775c34640 | 893 | ADMW_MEASUREMENT_MODE const eMeasurementMode, |
Vkadaba | 5:0728bde67bdb | 894 | ADMW1001_OPERATING_MODE * const peOperatingMode, |
Vkadaba | 5:0728bde67bdb | 895 | ADMW1001_DATAREADY_MODE * const peDataReadyMode, |
Vkadaba | 8:2f2775c34640 | 896 | uint32_t * const pnSamplesPerDataready, |
Vkadaba | 8:2f2775c34640 | 897 | uint32_t * const pnSamplesPerCycle, |
Vkadaba | 8:2f2775c34640 | 898 | uint8_t * const pnBytesPerSample) |
ADIJake | 0:85855ecd3257 | 899 | { |
ADIJake | 0:85855ecd3257 | 900 | unsigned nChannelsEnabled = 0; |
ADIJake | 0:85855ecd3257 | 901 | unsigned nSamplesPerCycle = 0; |
ADIJake | 0:85855ecd3257 | 902 | |
Vkadaba | 8:2f2775c34640 | 903 | ADMW_CORE_Mode_t modeReg; |
ADIJake | 0:85855ecd3257 | 904 | READ_REG_U8(hDevice, modeReg.VALUE8, CORE_MODE); |
ADIJake | 0:85855ecd3257 | 905 | |
Vkadaba | 41:df78b7d7b675 | 906 | if(eMeasurementMode==ADMW_MEASUREMENT_MODE_NORMAL) { |
ADIJake | 0:85855ecd3257 | 907 | |
Vkadaba | 41:df78b7d7b675 | 908 | if (modeReg.Conversion_Mode == CORE_MODE_SINGLECYCLE) |
Vkadaba | 41:df78b7d7b675 | 909 | *peOperatingMode = ADMW1001_OPERATING_MODE_SINGLECYCLE; |
Vkadaba | 41:df78b7d7b675 | 910 | else |
Vkadaba | 41:df78b7d7b675 | 911 | *peOperatingMode = ADMW1001_OPERATING_MODE_CONTINUOUS; |
Vkadaba | 41:df78b7d7b675 | 912 | } |
Vkadaba | 41:df78b7d7b675 | 913 | |
Vkadaba | 23:bb685f35b08b | 914 | if (eMeasurementMode == ADMW_MEASUREMENT_MODE_OMIT_RAW) { |
Vkadaba | 8:2f2775c34640 | 915 | *pnBytesPerSample = 5; |
Vkadaba | 23:bb685f35b08b | 916 | } else { |
Vkadaba | 8:2f2775c34640 | 917 | *pnBytesPerSample = 8; |
Vkadaba | 6:9d393a9677f4 | 918 | } |
Vkadaba | 23:bb685f35b08b | 919 | |
Vkadaba | 8:2f2775c34640 | 920 | for (ADMW1001_CH_ID chId = ADMW1001_CH_ID_ANLG_1_UNIVERSAL; |
Vkadaba | 23:bb685f35b08b | 921 | chId < ADMW1001_MAX_CHANNELS; |
Vkadaba | 23:bb685f35b08b | 922 | chId++) { |
Vkadaba | 8:2f2775c34640 | 923 | ADMW_CORE_Sensor_Details_t sensorDetailsReg; |
Vkadaba | 8:2f2775c34640 | 924 | ADMW_CORE_Channel_Count_t channelCountReg; |
Vkadaba | 23:bb685f35b08b | 925 | |
Vkadaba | 8:2f2775c34640 | 926 | if (ADMW1001_CHANNEL_IS_VIRTUAL(chId)) |
Vkadaba | 8:2f2775c34640 | 927 | continue; |
Vkadaba | 23:bb685f35b08b | 928 | |
Vkadaba | 8:2f2775c34640 | 929 | READ_REG_U8(hDevice, channelCountReg.VALUE8, CORE_CHANNEL_COUNTn(chId)); |
Vkadaba | 8:2f2775c34640 | 930 | READ_REG_U32(hDevice, sensorDetailsReg.VALUE32, CORE_SENSOR_DETAILSn(chId)); |
Vkadaba | 23:bb685f35b08b | 931 | |
Vkadaba | 41:df78b7d7b675 | 932 | if (channelCountReg.Channel_Enable && !sensorDetailsReg.Do_Not_Publish) { |
Vkadaba | 8:2f2775c34640 | 933 | unsigned nActualChannels = 1; |
Vkadaba | 23:bb685f35b08b | 934 | |
Vkadaba | 41:df78b7d7b675 | 935 | if (chId == ADMW1001_CH_ID_DIG_SPI_0) { |
Vkadaba | 23:bb685f35b08b | 936 | /* Some sensors automatically generate samples on additional |
Vkadaba | 23:bb685f35b08b | 937 | * "virtual" channels so these channels must be counted as |
Vkadaba | 23:bb685f35b08b | 938 | * active when those sensors are selected and we use the count |
Vkadaba | 23:bb685f35b08b | 939 | * from the corresponding "physical" channel |
Vkadaba | 8:2f2775c34640 | 940 | */ |
Vkadaba | 32:52445bef314d | 941 | #if 0 /* SPI sensors arent supported at present to be added back once there is |
Vkadaba | 32:52445bef314d | 942 | * support for these sensors |
Vkadaba | 32:52445bef314d | 943 | */ |
Vkadaba | 36:54e2418e7620 | 944 | ADMW_CORE_Sensor_Type_t sensorTypeReg; |
Vkadaba | 36:54e2418e7620 | 945 | |
Vkadaba | 36:54e2418e7620 | 946 | READ_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(chId)); |
Vkadaba | 41:df78b7d7b675 | 947 | |
Vkadaba | 8:2f2775c34640 | 948 | if ((sensorTypeReg.Sensor_Type >= |
Vkadaba | 41:df78b7d7b675 | 949 | CORE_SENSOR_TYPE_SPI_ACCELEROMETER_A) && |
Vkadaba | 41:df78b7d7b675 | 950 | (sensorTypeReg.Sensor_Type <= |
Vkadaba | 41:df78b7d7b675 | 951 | CORE_SENSOR_TYPE_SPI_ACCELEROMETER_B)) { |
Vkadaba | 8:2f2775c34640 | 952 | nActualChannels += 2; |
Vkadaba | 8:2f2775c34640 | 953 | } |
Vkadaba | 32:52445bef314d | 954 | #endif |
Vkadaba | 8:2f2775c34640 | 955 | } |
Vkadaba | 23:bb685f35b08b | 956 | |
Vkadaba | 8:2f2775c34640 | 957 | nChannelsEnabled += nActualChannels; |
Vkadaba | 23:bb685f35b08b | 958 | |
Vkadaba | 8:2f2775c34640 | 959 | nSamplesPerCycle += nActualChannels * |
Vkadaba | 8:2f2775c34640 | 960 | (channelCountReg.Channel_Count + 1); |
ADIJake | 0:85855ecd3257 | 961 | } |
Vkadaba | 6:9d393a9677f4 | 962 | } |
Vkadaba | 23:bb685f35b08b | 963 | |
Vkadaba | 23:bb685f35b08b | 964 | if (nChannelsEnabled == 0) { |
Vkadaba | 8:2f2775c34640 | 965 | *pnSamplesPerDataready = 0; |
Vkadaba | 8:2f2775c34640 | 966 | *pnSamplesPerCycle = 0; |
Vkadaba | 8:2f2775c34640 | 967 | return ADMW_SUCCESS; |
Vkadaba | 6:9d393a9677f4 | 968 | } |
Vkadaba | 23:bb685f35b08b | 969 | |
Vkadaba | 6:9d393a9677f4 | 970 | *pnSamplesPerCycle = nSamplesPerCycle; |
Vkadaba | 23:bb685f35b08b | 971 | |
Vkadaba | 23:bb685f35b08b | 972 | if (modeReg.Drdy_Mode == CORE_MODE_DRDY_PER_CONVERSION) { |
Vkadaba | 8:2f2775c34640 | 973 | *pnSamplesPerDataready = 1; |
Vkadaba | 23:bb685f35b08b | 974 | } else { |
Vkadaba | 8:2f2775c34640 | 975 | *pnSamplesPerDataready = nSamplesPerCycle; |
Vkadaba | 6:9d393a9677f4 | 976 | } |
Vkadaba | 23:bb685f35b08b | 977 | |
Vkadaba | 23:bb685f35b08b | 978 | if (modeReg.Drdy_Mode == CORE_MODE_DRDY_PER_CONVERSION) { |
Vkadaba | 8:2f2775c34640 | 979 | *peDataReadyMode = ADMW1001_DATAREADY_PER_CONVERSION; |
Vkadaba | 23:bb685f35b08b | 980 | } else { |
Vkadaba | 8:2f2775c34640 | 981 | *peDataReadyMode = ADMW1001_DATAREADY_PER_CYCLE; |
ADIJake | 0:85855ecd3257 | 982 | } |
Vkadaba | 23:bb685f35b08b | 983 | |
Vkadaba | 5:0728bde67bdb | 984 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 985 | } |
ADIJake | 0:85855ecd3257 | 986 | |
Vkadaba | 5:0728bde67bdb | 987 | ADMW_RESULT admw_GetProductID( |
Vkadaba | 5:0728bde67bdb | 988 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 989 | ADMW_PRODUCT_ID *pProductId) |
ADIJake | 0:85855ecd3257 | 990 | { |
Vkadaba | 5:0728bde67bdb | 991 | ADMW_SPI_Product_ID_L_t productIdLoReg; |
Vkadaba | 5:0728bde67bdb | 992 | ADMW_SPI_Product_ID_H_t productIdHiReg; |
ADIJake | 0:85855ecd3257 | 993 | |
ADIJake | 0:85855ecd3257 | 994 | READ_REG_U8(hDevice, productIdLoReg.VALUE8, SPI_PRODUCT_ID_L); |
ADIJake | 0:85855ecd3257 | 995 | READ_REG_U8(hDevice, productIdHiReg.VALUE8, SPI_PRODUCT_ID_H); |
ADIJake | 0:85855ecd3257 | 996 | |
Vkadaba | 23:bb685f35b08b | 997 | *pProductId = (ADMW_PRODUCT_ID)((productIdHiReg.VALUE8 << 8) | |
Vkadaba | 8:2f2775c34640 | 998 | productIdLoReg.VALUE8); |
Vkadaba | 5:0728bde67bdb | 999 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1000 | } |
ADIJake | 0:85855ecd3257 | 1001 | |
Vkadaba | 5:0728bde67bdb | 1002 | static ADMW_RESULT admw_SetPowerMode( |
Vkadaba | 5:0728bde67bdb | 1003 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1004 | ADMW1001_POWER_MODE powerMode) |
ADIJake | 0:85855ecd3257 | 1005 | { |
Vkadaba | 8:2f2775c34640 | 1006 | ADMW_CORE_Power_Config_t powerConfigReg; |
Vkadaba | 5:0728bde67bdb | 1007 | |
Vkadaba | 23:bb685f35b08b | 1008 | if (powerMode == ADMW1001_POWER_MODE_HIBERNATION) { |
Vkadaba | 6:9d393a9677f4 | 1009 | powerConfigReg.Power_Mode_MCU = CORE_POWER_CONFIG_HIBERNATION; |
Vkadaba | 23:bb685f35b08b | 1010 | } else if (powerMode == ADMW1001_POWER_MODE_ACTIVE) { |
Vkadaba | 6:9d393a9677f4 | 1011 | powerConfigReg.Power_Mode_MCU = CORE_POWER_CONFIG_ACTIVE_MODE; |
Vkadaba | 23:bb685f35b08b | 1012 | } else { |
Vkadaba | 5:0728bde67bdb | 1013 | ADMW_LOG_ERROR("Invalid power mode %d specified", powerMode); |
Vkadaba | 5:0728bde67bdb | 1014 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1015 | } |
ADIJake | 0:85855ecd3257 | 1016 | |
ADIJake | 0:85855ecd3257 | 1017 | WRITE_REG_U8(hDevice, powerConfigReg.VALUE8, CORE_POWER_CONFIG); |
ADIJake | 0:85855ecd3257 | 1018 | |
Vkadaba | 5:0728bde67bdb | 1019 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1020 | } |
ADIJake | 0:85855ecd3257 | 1021 | |
Vkadaba | 5:0728bde67bdb | 1022 | ADMW_RESULT admw1001_SetPowerConfig( |
Vkadaba | 5:0728bde67bdb | 1023 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1024 | ADMW1001_POWER_CONFIG *pPowerConfig) |
ADIJake | 0:85855ecd3257 | 1025 | { |
Vkadaba | 5:0728bde67bdb | 1026 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 1027 | |
Vkadaba | 5:0728bde67bdb | 1028 | eRet = admw_SetPowerMode(hDevice, pPowerConfig->powerMode); |
Vkadaba | 23:bb685f35b08b | 1029 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1030 | ADMW_LOG_ERROR("Failed to set power mode"); |
ADIJake | 0:85855ecd3257 | 1031 | return eRet; |
ADIJake | 0:85855ecd3257 | 1032 | } |
ADIJake | 0:85855ecd3257 | 1033 | |
Vkadaba | 5:0728bde67bdb | 1034 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1035 | } |
ADIJake | 0:85855ecd3257 | 1036 | |
Vkadaba | 33:df7a00f1b8e1 | 1037 | static ADMW_RESULT admw_SetRSenseValue( |
Vkadaba | 33:df7a00f1b8e1 | 1038 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 33:df7a00f1b8e1 | 1039 | float32_t RSenseValue) |
Vkadaba | 33:df7a00f1b8e1 | 1040 | { |
Vkadaba | 41:df78b7d7b675 | 1041 | ADMW_CORE_External_Reference_Resistor_t RefResistorConfigReg; |
Vkadaba | 41:df78b7d7b675 | 1042 | |
Vkadaba | 41:df78b7d7b675 | 1043 | RefResistorConfigReg.Ext_Refin1_Value = RSenseValue; |
Vkadaba | 41:df78b7d7b675 | 1044 | |
Vkadaba | 41:df78b7d7b675 | 1045 | WRITE_REG_FLOAT(hDevice, RefResistorConfigReg.VALUE32, CORE_EXTERNAL_REFERENCE_RESISTOR); |
Vkadaba | 41:df78b7d7b675 | 1046 | |
Vkadaba | 41:df78b7d7b675 | 1047 | return ADMW_SUCCESS; |
Vkadaba | 33:df7a00f1b8e1 | 1048 | |
Vkadaba | 33:df7a00f1b8e1 | 1049 | } |
Vkadaba | 5:0728bde67bdb | 1050 | static ADMW_RESULT admw_SetMode( |
Vkadaba | 5:0728bde67bdb | 1051 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1052 | ADMW1001_OPERATING_MODE eOperatingMode, |
Vkadaba | 8:2f2775c34640 | 1053 | ADMW1001_DATAREADY_MODE eDataReadyMode) |
ADIJake | 0:85855ecd3257 | 1054 | { |
Vkadaba | 8:2f2775c34640 | 1055 | ADMW_CORE_Mode_t modeReg; |
ADIJake | 0:85855ecd3257 | 1056 | |
ADIJake | 0:85855ecd3257 | 1057 | modeReg.VALUE8 = REG_RESET_VAL(CORE_MODE); |
ADIJake | 0:85855ecd3257 | 1058 | |
Vkadaba | 23:bb685f35b08b | 1059 | if (eOperatingMode == ADMW1001_OPERATING_MODE_SINGLECYCLE) { |
Vkadaba | 5:0728bde67bdb | 1060 | modeReg.Conversion_Mode = CORE_MODE_SINGLECYCLE; |
Vkadaba | 23:bb685f35b08b | 1061 | } else if (eOperatingMode == ADMW1001_OPERATING_MODE_CONTINUOUS) { |
Vkadaba | 5:0728bde67bdb | 1062 | modeReg.Conversion_Mode = CORE_MODE_CONTINUOUS; |
Vkadaba | 23:bb685f35b08b | 1063 | } else { |
Vkadaba | 5:0728bde67bdb | 1064 | ADMW_LOG_ERROR("Invalid operating mode %d specified", |
Vkadaba | 23:bb685f35b08b | 1065 | eOperatingMode); |
Vkadaba | 5:0728bde67bdb | 1066 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1067 | } |
ADIJake | 0:85855ecd3257 | 1068 | |
Vkadaba | 23:bb685f35b08b | 1069 | if (eDataReadyMode == ADMW1001_DATAREADY_PER_CONVERSION) { |
Vkadaba | 5:0728bde67bdb | 1070 | modeReg.Drdy_Mode = CORE_MODE_DRDY_PER_CONVERSION; |
Vkadaba | 23:bb685f35b08b | 1071 | } else if (eDataReadyMode == ADMW1001_DATAREADY_PER_CYCLE) { |
Vkadaba | 5:0728bde67bdb | 1072 | modeReg.Drdy_Mode = CORE_MODE_DRDY_PER_CYCLE; |
Vkadaba | 23:bb685f35b08b | 1073 | } else { |
Vkadaba | 5:0728bde67bdb | 1074 | ADMW_LOG_ERROR("Invalid data-ready mode %d specified", eDataReadyMode); |
Vkadaba | 5:0728bde67bdb | 1075 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1076 | } |
ADIJake | 0:85855ecd3257 | 1077 | |
ADIJake | 0:85855ecd3257 | 1078 | WRITE_REG_U8(hDevice, modeReg.VALUE8, CORE_MODE); |
ADIJake | 0:85855ecd3257 | 1079 | |
Vkadaba | 5:0728bde67bdb | 1080 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1081 | } |
ADIJake | 0:85855ecd3257 | 1082 | |
Vkadaba | 8:2f2775c34640 | 1083 | ADMW_RESULT admw_SetCycleControl(ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1084 | uint32_t nCycleInterval, |
Vkadaba | 8:2f2775c34640 | 1085 | bool vBiasEnable) |
ADIJake | 0:85855ecd3257 | 1086 | { |
Vkadaba | 8:2f2775c34640 | 1087 | ADMW_CORE_Cycle_Control_t cycleControlReg; |
ADIJake | 0:85855ecd3257 | 1088 | |
ADIJake | 0:85855ecd3257 | 1089 | cycleControlReg.VALUE16 = REG_RESET_VAL(CORE_CYCLE_CONTROL); |
ADIJake | 0:85855ecd3257 | 1090 | |
Vkadaba | 23:bb685f35b08b | 1091 | if (nCycleInterval < (1000 * (1 << 12))) { |
Vkadaba | 5:0728bde67bdb | 1092 | cycleControlReg.Cycle_Time_Units = CORE_CYCLE_CONTROL_MILLISECONDS; |
ADIJake | 0:85855ecd3257 | 1093 | nCycleInterval /= 1000; |
Vkadaba | 23:bb685f35b08b | 1094 | } else { |
Vkadaba | 5:0728bde67bdb | 1095 | cycleControlReg.Cycle_Time_Units = CORE_CYCLE_CONTROL_SECONDS; |
ADIJake | 0:85855ecd3257 | 1096 | nCycleInterval /= 1000000; |
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; |
ADIJake | 0:85855ecd3257 | 1104 | |
ADIJake | 0:85855ecd3257 | 1105 | WRITE_REG_U16(hDevice, cycleControlReg.VALUE16, CORE_CYCLE_CONTROL); |
ADIJake | 0:85855ecd3257 | 1106 | |
Vkadaba | 5:0728bde67bdb | 1107 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1108 | } |
Vkadaba | 36:54e2418e7620 | 1109 | static ADMW_RESULT admw_SetExternalReferenceVoltage( |
Vkadaba | 36:54e2418e7620 | 1110 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 36:54e2418e7620 | 1111 | float32_t externalRefVoltage) |
Vkadaba | 36:54e2418e7620 | 1112 | { |
Vkadaba | 36:54e2418e7620 | 1113 | WRITE_REG_FLOAT(hDevice, externalRefVoltage, CORE_EXTERNAL_VOLTAGE_REFERENCE); |
Vkadaba | 36:54e2418e7620 | 1114 | |
Vkadaba | 36:54e2418e7620 | 1115 | return ADMW_SUCCESS; |
Vkadaba | 36:54e2418e7620 | 1116 | } |
ADIJake | 0:85855ecd3257 | 1117 | |
Vkadaba | 5:0728bde67bdb | 1118 | static ADMW_RESULT admw_SetExternalReferenceValues( |
Vkadaba | 5:0728bde67bdb | 1119 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 6:9d393a9677f4 | 1120 | float32_t externalRef1Value) |
ADIJake | 0:85855ecd3257 | 1121 | { |
Vkadaba | 6:9d393a9677f4 | 1122 | WRITE_REG_FLOAT(hDevice, externalRef1Value, CORE_EXTERNAL_REFERENCE_RESISTOR); |
ADIJake | 0:85855ecd3257 | 1123 | |
Vkadaba | 5:0728bde67bdb | 1124 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1125 | } |
ADIJake | 0:85855ecd3257 | 1126 | |
Vkadaba | 5:0728bde67bdb | 1127 | ADMW_RESULT admw1001_SetMeasurementConfig( |
Vkadaba | 5:0728bde67bdb | 1128 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1129 | ADMW1001_MEASUREMENT_CONFIG *pMeasConfig) |
ADIJake | 0:85855ecd3257 | 1130 | { |
Vkadaba | 5:0728bde67bdb | 1131 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 1132 | |
Vkadaba | 5:0728bde67bdb | 1133 | eRet = admw_SetMode(hDevice, |
Vkadaba | 8:2f2775c34640 | 1134 | pMeasConfig->operatingMode, |
Vkadaba | 8:2f2775c34640 | 1135 | pMeasConfig->dataReadyMode); |
Vkadaba | 23:bb685f35b08b | 1136 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1137 | ADMW_LOG_ERROR("Failed to set operating mode"); |
ADIJake | 0:85855ecd3257 | 1138 | return eRet; |
ADIJake | 0:85855ecd3257 | 1139 | } |
ADIJake | 0:85855ecd3257 | 1140 | |
Vkadaba | 8:2f2775c34640 | 1141 | eRet = admw_SetCycleControl(hDevice, pMeasConfig->cycleInterval, |
Vkadaba | 8:2f2775c34640 | 1142 | pMeasConfig->vBiasEnable); |
Vkadaba | 23:bb685f35b08b | 1143 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1144 | ADMW_LOG_ERROR("Failed to set cycle control"); |
ADIJake | 0:85855ecd3257 | 1145 | return eRet; |
ADIJake | 0:85855ecd3257 | 1146 | } |
ADIJake | 0:85855ecd3257 | 1147 | |
Vkadaba | 23:bb685f35b08b | 1148 | if(pMeasConfig->externalRef1Value>0) { |
Vkadaba | 8:2f2775c34640 | 1149 | eRet = admw_SetExternalReferenceValues(hDevice, |
Vkadaba | 8:2f2775c34640 | 1150 | pMeasConfig->externalRef1Value); |
ADIJake | 0:85855ecd3257 | 1151 | } |
Vkadaba | 8:2f2775c34640 | 1152 | |
Vkadaba | 23:bb685f35b08b | 1153 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1154 | ADMW_LOG_ERROR("Failed to set external reference values"); |
ADIJake | 0:85855ecd3257 | 1155 | return eRet; |
ADIJake | 0:85855ecd3257 | 1156 | } |
ADIJake | 0:85855ecd3257 | 1157 | |
Vkadaba | 33:df7a00f1b8e1 | 1158 | eRet = admw_SetRSenseValue(hDevice, pMeasConfig->RSenseValue); |
Vkadaba | 41:df78b7d7b675 | 1159 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 33:df7a00f1b8e1 | 1160 | ADMW_LOG_ERROR("Failed to set RSenseValue"); |
Vkadaba | 33:df7a00f1b8e1 | 1161 | return eRet; |
Vkadaba | 33:df7a00f1b8e1 | 1162 | } |
Vkadaba | 41:df78b7d7b675 | 1163 | |
Vkadaba | 36:54e2418e7620 | 1164 | eRet = admw_SetExternalReferenceVoltage(hDevice, pMeasConfig->externalRefVoltage); |
Vkadaba | 41:df78b7d7b675 | 1165 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 36:54e2418e7620 | 1166 | ADMW_LOG_ERROR("Failed to set External reference Voltage"); |
Vkadaba | 36:54e2418e7620 | 1167 | return eRet; |
Vkadaba | 41:df78b7d7b675 | 1168 | } |
Vkadaba | 41:df78b7d7b675 | 1169 | |
Vkadaba | 5:0728bde67bdb | 1170 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1171 | } |
ADIJake | 0:85855ecd3257 | 1172 | |
Vkadaba | 36:54e2418e7620 | 1173 | ADMW_RESULT admw1001_SetDiagnosticsConfig( |
Vkadaba | 36:54e2418e7620 | 1174 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 36:54e2418e7620 | 1175 | ADMW1001_DIAGNOSTICS_CONFIG *pDiagnosticsConfig) |
Vkadaba | 36:54e2418e7620 | 1176 | { |
Vkadaba | 36:54e2418e7620 | 1177 | ADMW_CORE_Diagnostics_Control_t diagnosticsControlReg; |
ADIJake | 0:85855ecd3257 | 1178 | |
Vkadaba | 36:54e2418e7620 | 1179 | diagnosticsControlReg.VALUE8 = REG_RESET_VAL(CORE_DIAGNOSTICS_CONTROL); |
Vkadaba | 36:54e2418e7620 | 1180 | |
Vkadaba | 36:54e2418e7620 | 1181 | if (pDiagnosticsConfig->disableMeasurementDiag) |
Vkadaba | 36:54e2418e7620 | 1182 | diagnosticsControlReg.Diag_Meas_En = 0; |
Vkadaba | 36:54e2418e7620 | 1183 | else |
Vkadaba | 36:54e2418e7620 | 1184 | diagnosticsControlReg.Diag_Meas_En = 1; |
Vkadaba | 36:54e2418e7620 | 1185 | |
Vkadaba | 41:df78b7d7b675 | 1186 | switch (pDiagnosticsConfig->osdFrequency) { |
Vkadaba | 41:df78b7d7b675 | 1187 | case ADMW1001_OPEN_SENSOR_DIAGNOSTICS_DISABLED: |
Vkadaba | 41:df78b7d7b675 | 1188 | diagnosticsControlReg.Diag_OSD_Freq = CORE_DIAGNOSTICS_CONTROL_OCD_OFF; |
Vkadaba | 41:df78b7d7b675 | 1189 | break; |
Vkadaba | 41:df78b7d7b675 | 1190 | case ADMW1001_OPEN_SENSOR_DIAGNOSTICS_PER_CYCLE: |
Vkadaba | 41:df78b7d7b675 | 1191 | diagnosticsControlReg.Diag_OSD_Freq = CORE_DIAGNOSTICS_CONTROL_OCD_PER_1_CYCLE; |
Vkadaba | 41:df78b7d7b675 | 1192 | break; |
Vkadaba | 41:df78b7d7b675 | 1193 | case ADMW1001_OPEN_SENSOR_DIAGNOSTICS_PER_100_CYCLES: |
Vkadaba | 41:df78b7d7b675 | 1194 | diagnosticsControlReg.Diag_OSD_Freq = CORE_DIAGNOSTICS_CONTROL_OCD_PER_10_CYCLES; |
Vkadaba | 41:df78b7d7b675 | 1195 | break; |
Vkadaba | 41:df78b7d7b675 | 1196 | case ADMW1001_OPEN_SENSOR_DIAGNOSTICS_PER_1000_CYCLES: |
Vkadaba | 41:df78b7d7b675 | 1197 | diagnosticsControlReg.Diag_OSD_Freq = CORE_DIAGNOSTICS_CONTROL_OCD_PER_100_CYCLES; |
Vkadaba | 41:df78b7d7b675 | 1198 | break; |
Vkadaba | 41:df78b7d7b675 | 1199 | default: |
Vkadaba | 41:df78b7d7b675 | 1200 | ADMW_LOG_ERROR("Invalid open-sensor diagnostic frequency %d specified", |
Vkadaba | 41:df78b7d7b675 | 1201 | pDiagnosticsConfig->osdFrequency); |
Vkadaba | 41:df78b7d7b675 | 1202 | return ADMW_INVALID_PARAM; |
Vkadaba | 36:54e2418e7620 | 1203 | } |
Vkadaba | 36:54e2418e7620 | 1204 | |
Vkadaba | 36:54e2418e7620 | 1205 | WRITE_REG_U8(hDevice, diagnosticsControlReg.VALUE8, CORE_DIAGNOSTICS_CONTROL); |
Vkadaba | 36:54e2418e7620 | 1206 | |
Vkadaba | 36:54e2418e7620 | 1207 | return ADMW_SUCCESS; |
Vkadaba | 36:54e2418e7620 | 1208 | } |
ADIJake | 0:85855ecd3257 | 1209 | |
Vkadaba | 5:0728bde67bdb | 1210 | ADMW_RESULT admw1001_SetChannelCount( |
Vkadaba | 5:0728bde67bdb | 1211 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1212 | ADMW1001_CH_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 1213 | uint32_t nMeasurementsPerCycle) |
ADIJake | 0:85855ecd3257 | 1214 | { |
Vkadaba | 8:2f2775c34640 | 1215 | ADMW_CORE_Channel_Count_t channelCountReg; |
ADIJake | 0:85855ecd3257 | 1216 | |
ADIJake | 0:85855ecd3257 | 1217 | channelCountReg.VALUE8 = REG_RESET_VAL(CORE_CHANNEL_COUNTn); |
ADIJake | 0:85855ecd3257 | 1218 | |
Vkadaba | 23:bb685f35b08b | 1219 | if (nMeasurementsPerCycle > 0) { |
ADIJake | 0:85855ecd3257 | 1220 | nMeasurementsPerCycle -= 1; |
ADIJake | 0:85855ecd3257 | 1221 | |
ADIJake | 0:85855ecd3257 | 1222 | CHECK_REG_FIELD_VAL(CORE_CHANNEL_COUNT_CHANNEL_COUNT, |
ADIJake | 0:85855ecd3257 | 1223 | nMeasurementsPerCycle); |
ADIJake | 0:85855ecd3257 | 1224 | |
ADIJake | 0:85855ecd3257 | 1225 | channelCountReg.Channel_Enable = 1; |
ADIJake | 0:85855ecd3257 | 1226 | channelCountReg.Channel_Count = nMeasurementsPerCycle; |
Vkadaba | 23:bb685f35b08b | 1227 | } else { |
ADIJake | 0:85855ecd3257 | 1228 | channelCountReg.Channel_Enable = 0; |
ADIJake | 0:85855ecd3257 | 1229 | } |
ADIJake | 0:85855ecd3257 | 1230 | |
ADIJake | 0:85855ecd3257 | 1231 | WRITE_REG_U8(hDevice, channelCountReg.VALUE8, CORE_CHANNEL_COUNTn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1232 | |
Vkadaba | 5:0728bde67bdb | 1233 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1234 | } |
ADIJake | 0:85855ecd3257 | 1235 | |
Vkadaba | 5:0728bde67bdb | 1236 | ADMW_RESULT admw1001_SetChannelOptions( |
Vkadaba | 5:0728bde67bdb | 1237 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1238 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 6:9d393a9677f4 | 1239 | ADMW1001_CHANNEL_PRIORITY ePriority) |
ADIJake | 0:85855ecd3257 | 1240 | { |
Vkadaba | 8:2f2775c34640 | 1241 | ADMW_CORE_Channel_Options_t channelOptionsReg; |
ADIJake | 0:85855ecd3257 | 1242 | |
ADIJake | 0:85855ecd3257 | 1243 | channelOptionsReg.VALUE8 = REG_RESET_VAL(CORE_CHANNEL_OPTIONSn); |
ADIJake | 0:85855ecd3257 | 1244 | |
ADIJake | 0:85855ecd3257 | 1245 | CHECK_REG_FIELD_VAL(CORE_CHANNEL_OPTIONS_CHANNEL_PRIORITY, ePriority); |
ADIJake | 0:85855ecd3257 | 1246 | channelOptionsReg.Channel_Priority = ePriority; |
ADIJake | 0:85855ecd3257 | 1247 | |
ADIJake | 0:85855ecd3257 | 1248 | WRITE_REG_U8(hDevice, channelOptionsReg.VALUE8, CORE_CHANNEL_OPTIONSn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1249 | |
Vkadaba | 5:0728bde67bdb | 1250 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1251 | } |
ADIJake | 0:85855ecd3257 | 1252 | |
Vkadaba | 5:0728bde67bdb | 1253 | ADMW_RESULT admw1001_SetChannelSkipCount( |
Vkadaba | 5:0728bde67bdb | 1254 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1255 | ADMW1001_CH_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 1256 | uint32_t nCycleSkipCount) |
ADIJake | 0:85855ecd3257 | 1257 | { |
Vkadaba | 8:2f2775c34640 | 1258 | ADMW_CORE_Channel_Skip_t channelSkipReg; |
ADIJake | 0:85855ecd3257 | 1259 | |
ADIJake | 0:85855ecd3257 | 1260 | channelSkipReg.VALUE16 = REG_RESET_VAL(CORE_CHANNEL_SKIPn); |
ADIJake | 0:85855ecd3257 | 1261 | |
ADIJake | 0:85855ecd3257 | 1262 | CHECK_REG_FIELD_VAL(CORE_CHANNEL_SKIP_CHANNEL_SKIP, nCycleSkipCount); |
ADIJake | 0:85855ecd3257 | 1263 | |
ADIJake | 0:85855ecd3257 | 1264 | channelSkipReg.Channel_Skip = nCycleSkipCount; |
ADIJake | 0:85855ecd3257 | 1265 | |
ADIJake | 0:85855ecd3257 | 1266 | WRITE_REG_U16(hDevice, channelSkipReg.VALUE16, CORE_CHANNEL_SKIPn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1267 | |
Vkadaba | 5:0728bde67bdb | 1268 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1269 | } |
ADIJake | 0:85855ecd3257 | 1270 | |
Vkadaba | 5:0728bde67bdb | 1271 | static ADMW_RESULT admw_SetChannelAdcSensorType( |
Vkadaba | 8:2f2775c34640 | 1272 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1273 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 8:2f2775c34640 | 1274 | ADMW1001_ADC_SENSOR_TYPE sensorType) |
ADIJake | 0:85855ecd3257 | 1275 | { |
Vkadaba | 8:2f2775c34640 | 1276 | ADMW_CORE_Sensor_Type_t sensorTypeReg; |
ADIJake | 0:85855ecd3257 | 1277 | |
ADIJake | 0:85855ecd3257 | 1278 | sensorTypeReg.VALUE16 = REG_RESET_VAL(CORE_SENSOR_TYPEn); |
ADIJake | 0:85855ecd3257 | 1279 | |
ADIJake | 0:85855ecd3257 | 1280 | /* Ensure that the sensor type is valid for this channel */ |
Vkadaba | 23:bb685f35b08b | 1281 | switch(sensorType) { |
Vkadaba | 8:2f2775c34640 | 1282 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT100: |
Vkadaba | 8:2f2775c34640 | 1283 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT1000: |
Vkadaba | 8:2f2775c34640 | 1284 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_1: |
Vkadaba | 8:2f2775c34640 | 1285 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_2: |
Vkadaba | 8:2f2775c34640 | 1286 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_3: |
Vkadaba | 8:2f2775c34640 | 1287 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_4: |
Vkadaba | 8:2f2775c34640 | 1288 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT100: |
Vkadaba | 8:2f2775c34640 | 1289 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT1000: |
Vkadaba | 8:2f2775c34640 | 1290 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_1: |
Vkadaba | 8:2f2775c34640 | 1291 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_2: |
Vkadaba | 8:2f2775c34640 | 1292 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_3: |
Vkadaba | 8:2f2775c34640 | 1293 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_4: |
Vkadaba | 8:2f2775c34640 | 1294 | case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_1: |
Vkadaba | 8:2f2775c34640 | 1295 | case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_2: |
Vkadaba | 8:2f2775c34640 | 1296 | case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_3: |
Vkadaba | 8:2f2775c34640 | 1297 | case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_4: |
Vkadaba | 8:2f2775c34640 | 1298 | case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_1: |
Vkadaba | 8:2f2775c34640 | 1299 | case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_2: |
Vkadaba | 8:2f2775c34640 | 1300 | case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_3: |
Vkadaba | 8:2f2775c34640 | 1301 | case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_4: |
Vkadaba | 8:2f2775c34640 | 1302 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT100: |
Vkadaba | 8:2f2775c34640 | 1303 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT1000: |
Vkadaba | 8:2f2775c34640 | 1304 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_1: |
Vkadaba | 8:2f2775c34640 | 1305 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_2: |
Vkadaba | 8:2f2775c34640 | 1306 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_3: |
Vkadaba | 8:2f2775c34640 | 1307 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_4: |
Vkadaba | 8:2f2775c34640 | 1308 | case ADMW1001_ADC_SENSOR_DIODE_2C_TYPEA: |
Vkadaba | 8:2f2775c34640 | 1309 | case ADMW1001_ADC_SENSOR_DIODE_3C_TYPEA: |
Vkadaba | 8:2f2775c34640 | 1310 | case ADMW1001_ADC_SENSOR_DIODE_2C_1: |
Vkadaba | 8:2f2775c34640 | 1311 | case ADMW1001_ADC_SENSOR_DIODE_3C_1: |
Vkadaba | 8:2f2775c34640 | 1312 | case ADMW1001_ADC_SENSOR_THERMISTOR_A_10K: |
Vkadaba | 8:2f2775c34640 | 1313 | case ADMW1001_ADC_SENSOR_THERMISTOR_B_10K: |
Vkadaba | 8:2f2775c34640 | 1314 | case ADMW1001_ADC_SENSOR_THERMISTOR_1: |
Vkadaba | 8:2f2775c34640 | 1315 | case ADMW1001_ADC_SENSOR_THERMISTOR_2: |
Vkadaba | 8:2f2775c34640 | 1316 | case ADMW1001_ADC_SENSOR_THERMISTOR_3: |
Vkadaba | 8:2f2775c34640 | 1317 | case ADMW1001_ADC_SENSOR_THERMISTOR_4: |
Vkadaba | 36:54e2418e7620 | 1318 | case ADMW1001_ADC_SENSOR_SINGLE_ENDED_ABSOLUTE: |
Vkadaba | 36:54e2418e7620 | 1319 | case ADMW1001_ADC_SENSOR_DIFFERENTIAL_ABSOLUTE: |
Vkadaba | 36:54e2418e7620 | 1320 | case ADMW1001_ADC_SENSOR_SINGLE_ENDED_RATIO: |
Vkadaba | 36:54e2418e7620 | 1321 | case ADMW1001_ADC_SENSOR_DIFFERENTIAL_RATIO: |
Vkadaba | 6:9d393a9677f4 | 1322 | if (! (ADMW1001_CHANNEL_IS_ADC_SENSOR(eChannelId) || |
Vkadaba | 41:df78b7d7b675 | 1323 | ADMW1001_CHANNEL_IS_ADC_CJC(eChannelId) || ADMW1001_CHANNEL_IS_ADC(eChannelId) )) { |
Vkadaba | 6:9d393a9677f4 | 1324 | ADMW_LOG_ERROR( |
Vkadaba | 6:9d393a9677f4 | 1325 | "Invalid ADC sensor type %d specified for channel %d", |
Vkadaba | 6:9d393a9677f4 | 1326 | sensorType, eChannelId); |
Vkadaba | 6:9d393a9677f4 | 1327 | return ADMW_INVALID_PARAM; |
Vkadaba | 6:9d393a9677f4 | 1328 | } |
Vkadaba | 6:9d393a9677f4 | 1329 | break; |
Vkadaba | 6:9d393a9677f4 | 1330 | case ADMW1001_ADC_SENSOR_VOLTAGE: |
Vkadaba | 8:2f2775c34640 | 1331 | case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_A: |
Vkadaba | 8:2f2775c34640 | 1332 | case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_B: |
Vkadaba | 8:2f2775c34640 | 1333 | case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_1: |
Vkadaba | 8:2f2775c34640 | 1334 | case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_2: |
Vkadaba | 8:2f2775c34640 | 1335 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_J: |
Vkadaba | 8:2f2775c34640 | 1336 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_K: |
Vkadaba | 8:2f2775c34640 | 1337 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_T: |
Vkadaba | 8:2f2775c34640 | 1338 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_1: |
Vkadaba | 8:2f2775c34640 | 1339 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_2: |
Vkadaba | 8:2f2775c34640 | 1340 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_3: |
Vkadaba | 8:2f2775c34640 | 1341 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_4: |
Vkadaba | 23:bb685f35b08b | 1342 | if (! ADMW1001_CHANNEL_IS_ADC_VOLTAGE(eChannelId)) { |
Vkadaba | 6:9d393a9677f4 | 1343 | ADMW_LOG_ERROR( |
Vkadaba | 6:9d393a9677f4 | 1344 | "Invalid ADC sensor type %d specified for channel %d", |
Vkadaba | 6:9d393a9677f4 | 1345 | sensorType, eChannelId); |
Vkadaba | 6:9d393a9677f4 | 1346 | return ADMW_INVALID_PARAM; |
Vkadaba | 6:9d393a9677f4 | 1347 | } |
Vkadaba | 6:9d393a9677f4 | 1348 | break; |
Vkadaba | 6:9d393a9677f4 | 1349 | case ADMW1001_ADC_SENSOR_CURRENT: |
Vkadaba | 8:2f2775c34640 | 1350 | case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_A: |
Vkadaba | 8:2f2775c34640 | 1351 | case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_1: |
Vkadaba | 8:2f2775c34640 | 1352 | case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_2: |
Vkadaba | 23:bb685f35b08b | 1353 | if (! ADMW1001_CHANNEL_IS_ADC_CURRENT(eChannelId)) { |
Vkadaba | 6:9d393a9677f4 | 1354 | ADMW_LOG_ERROR( |
Vkadaba | 6:9d393a9677f4 | 1355 | "Invalid ADC sensor type %d specified for channel %d", |
Vkadaba | 6:9d393a9677f4 | 1356 | sensorType, eChannelId); |
Vkadaba | 6:9d393a9677f4 | 1357 | return ADMW_INVALID_PARAM; |
Vkadaba | 6:9d393a9677f4 | 1358 | } |
Vkadaba | 6:9d393a9677f4 | 1359 | break; |
Vkadaba | 6:9d393a9677f4 | 1360 | default: |
Vkadaba | 6:9d393a9677f4 | 1361 | ADMW_LOG_ERROR("Invalid/unsupported ADC sensor type %d specified", |
Vkadaba | 23:bb685f35b08b | 1362 | sensorType); |
Vkadaba | 5:0728bde67bdb | 1363 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1364 | } |
ADIJake | 0:85855ecd3257 | 1365 | |
ADIJake | 0:85855ecd3257 | 1366 | sensorTypeReg.Sensor_Type = sensorType; |
ADIJake | 0:85855ecd3257 | 1367 | |
ADIJake | 0:85855ecd3257 | 1368 | WRITE_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1369 | |
Vkadaba | 5:0728bde67bdb | 1370 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1371 | } |
ADIJake | 0:85855ecd3257 | 1372 | |
Vkadaba | 5:0728bde67bdb | 1373 | static ADMW_RESULT admw_SetChannelAdcSensorDetails( |
Vkadaba | 8:2f2775c34640 | 1374 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1375 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1376 | ADMW1001_CHANNEL_CONFIG *pChannelConfig) |
ADIJake | 0:85855ecd3257 | 1377 | /* |
ADIJake | 0:85855ecd3257 | 1378 | * TODO - it would be nice if the general- vs. ADC-specific sensor details could be split into separate registers |
ADIJake | 0:85855ecd3257 | 1379 | * General details: |
ADIJake | 0:85855ecd3257 | 1380 | * - Measurement_Units |
ADIJake | 0:85855ecd3257 | 1381 | * - Compensation_Channel |
ADIJake | 0:85855ecd3257 | 1382 | * - CJC_Publish (if "CJC" was removed from the name) |
ADIJake | 0:85855ecd3257 | 1383 | * ADC-specific details: |
ADIJake | 0:85855ecd3257 | 1384 | * - PGA_Gain |
ADIJake | 0:85855ecd3257 | 1385 | * - Reference_Select |
ADIJake | 0:85855ecd3257 | 1386 | * - Reference_Buffer_Disable |
ADIJake | 0:85855ecd3257 | 1387 | */ |
ADIJake | 0:85855ecd3257 | 1388 | { |
Vkadaba | 5:0728bde67bdb | 1389 | ADMW1001_ADC_CHANNEL_CONFIG *pAdcChannelConfig = &pChannelConfig->adcChannelConfig; |
Vkadaba | 8:2f2775c34640 | 1390 | ADMW1001_ADC_REFERENCE_TYPE refType = pAdcChannelConfig->reference; |
Vkadaba | 8:2f2775c34640 | 1391 | ADMW_CORE_Sensor_Details_t sensorDetailsReg; |
ADIJake | 0:85855ecd3257 | 1392 | |
ADIJake | 0:85855ecd3257 | 1393 | sensorDetailsReg.VALUE32 = REG_RESET_VAL(CORE_SENSOR_DETAILSn); |
ADIJake | 0:85855ecd3257 | 1394 | |
Vkadaba | 23:bb685f35b08b | 1395 | switch(pChannelConfig->measurementUnit) { |
Vkadaba | 8:2f2775c34640 | 1396 | case ADMW1001_MEASUREMENT_UNIT_FAHRENHEIT: |
Vkadaba | 8:2f2775c34640 | 1397 | sensorDetailsReg.Measurement_Units = CORE_SENSOR_DETAILS_UNITS_DEGF; |
Vkadaba | 8:2f2775c34640 | 1398 | break; |
Vkadaba | 8:2f2775c34640 | 1399 | case ADMW1001_MEASUREMENT_UNIT_CELSIUS: |
Vkadaba | 8:2f2775c34640 | 1400 | sensorDetailsReg.Measurement_Units = CORE_SENSOR_DETAILS_UNITS_DEGC; |
Vkadaba | 8:2f2775c34640 | 1401 | break; |
Vkadaba | 8:2f2775c34640 | 1402 | case ADMW1001_MEASUREMENT_UNIT_UNSPECIFIED: |
Vkadaba | 8:2f2775c34640 | 1403 | sensorDetailsReg.Measurement_Units = CORE_SENSOR_DETAILS_UNITS_UNSPECIFIED; |
Vkadaba | 8:2f2775c34640 | 1404 | break; |
Vkadaba | 8:2f2775c34640 | 1405 | default: |
Vkadaba | 8:2f2775c34640 | 1406 | ADMW_LOG_ERROR("Invalid measurement unit %d specified", |
Vkadaba | 8:2f2775c34640 | 1407 | pChannelConfig->measurementUnit); |
Vkadaba | 8:2f2775c34640 | 1408 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1409 | } |
ADIJake | 0:85855ecd3257 | 1410 | |
Vkadaba | 23:bb685f35b08b | 1411 | if (pChannelConfig->compensationChannel == ADMW1001_CH_ID_NONE) { |
ADIJake | 0:85855ecd3257 | 1412 | sensorDetailsReg.Compensation_Disable = 1; |
ADIJake | 0:85855ecd3257 | 1413 | sensorDetailsReg.Compensation_Channel = 0; |
Vkadaba | 23:bb685f35b08b | 1414 | } else { |
ADIJake | 0:85855ecd3257 | 1415 | sensorDetailsReg.Compensation_Disable = 0; |
ADIJake | 0:85855ecd3257 | 1416 | sensorDetailsReg.Compensation_Channel = pChannelConfig->compensationChannel; |
ADIJake | 0:85855ecd3257 | 1417 | } |
ADIJake | 0:85855ecd3257 | 1418 | |
Vkadaba | 23:bb685f35b08b | 1419 | switch(refType) { |
Vkadaba | 8:2f2775c34640 | 1420 | case ADMW1001_ADC_REFERENCE_VOLTAGE_INTERNAL: |
Vkadaba | 8:2f2775c34640 | 1421 | sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_VINT; |
Vkadaba | 8:2f2775c34640 | 1422 | break; |
Vkadaba | 8:2f2775c34640 | 1423 | case ADMW1001_ADC_REFERENCE_VOLTAGE_EXTERNAL_1: |
Vkadaba | 8:2f2775c34640 | 1424 | sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_VEXT1; |
Vkadaba | 8:2f2775c34640 | 1425 | break; |
Vkadaba | 8:2f2775c34640 | 1426 | case ADMW1001_ADC_REFERENCE_VOLTAGE_AVDD: |
Vkadaba | 8:2f2775c34640 | 1427 | sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_AVDD; |
Vkadaba | 8:2f2775c34640 | 1428 | break; |
Vkadaba | 8:2f2775c34640 | 1429 | default: |
Vkadaba | 8:2f2775c34640 | 1430 | ADMW_LOG_ERROR("Invalid ADC reference type %d specified", refType); |
Vkadaba | 8:2f2775c34640 | 1431 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1432 | } |
Vkadaba | 23:bb685f35b08b | 1433 | |
Vkadaba | 23:bb685f35b08b | 1434 | switch(pAdcChannelConfig->gain) { |
Vkadaba | 8:2f2775c34640 | 1435 | case ADMW1001_ADC_GAIN_1X: |
Vkadaba | 8:2f2775c34640 | 1436 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_1; |
Vkadaba | 8:2f2775c34640 | 1437 | break; |
Vkadaba | 8:2f2775c34640 | 1438 | case ADMW1001_ADC_GAIN_2X: |
Vkadaba | 8:2f2775c34640 | 1439 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_2; |
Vkadaba | 8:2f2775c34640 | 1440 | break; |
Vkadaba | 8:2f2775c34640 | 1441 | case ADMW1001_ADC_GAIN_4X: |
Vkadaba | 8:2f2775c34640 | 1442 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_4; |
Vkadaba | 8:2f2775c34640 | 1443 | break; |
Vkadaba | 8:2f2775c34640 | 1444 | case ADMW1001_ADC_GAIN_8X: |
Vkadaba | 8:2f2775c34640 | 1445 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_8; |
Vkadaba | 8:2f2775c34640 | 1446 | break; |
Vkadaba | 8:2f2775c34640 | 1447 | case ADMW1001_ADC_GAIN_16X: |
Vkadaba | 8:2f2775c34640 | 1448 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_16; |
Vkadaba | 8:2f2775c34640 | 1449 | break; |
Vkadaba | 8:2f2775c34640 | 1450 | case ADMW1001_ADC_GAIN_32X: |
Vkadaba | 8:2f2775c34640 | 1451 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_32; |
Vkadaba | 8:2f2775c34640 | 1452 | break; |
Vkadaba | 8:2f2775c34640 | 1453 | case ADMW1001_ADC_GAIN_64X: |
Vkadaba | 8:2f2775c34640 | 1454 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_64; |
Vkadaba | 8:2f2775c34640 | 1455 | break; |
Vkadaba | 8:2f2775c34640 | 1456 | case ADMW1001_ADC_GAIN_128X: |
Vkadaba | 8:2f2775c34640 | 1457 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_128; |
Vkadaba | 8:2f2775c34640 | 1458 | break; |
Vkadaba | 8:2f2775c34640 | 1459 | default: |
Vkadaba | 8:2f2775c34640 | 1460 | ADMW_LOG_ERROR("Invalid ADC gain %d specified", |
Vkadaba | 23:bb685f35b08b | 1461 | pAdcChannelConfig->gain); |
Vkadaba | 8:2f2775c34640 | 1462 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1463 | } |
ADIJake | 0:85855ecd3257 | 1464 | |
Vkadaba | 23:bb685f35b08b | 1465 | switch(pAdcChannelConfig->rtdCurve) { |
Vkadaba | 8:2f2775c34640 | 1466 | case ADMW1001_ADC_RTD_CURVE_EUROPEAN: |
Vkadaba | 8:2f2775c34640 | 1467 | sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_EUROPEAN_CURVE; |
Vkadaba | 8:2f2775c34640 | 1468 | break; |
Vkadaba | 8:2f2775c34640 | 1469 | case ADMW1001_ADC_RTD_CURVE_AMERICAN: |
Vkadaba | 8:2f2775c34640 | 1470 | sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_AMERICAN_CURVE; |
Vkadaba | 8:2f2775c34640 | 1471 | break; |
Vkadaba | 8:2f2775c34640 | 1472 | case ADMW1001_ADC_RTD_CURVE_JAPANESE: |
Vkadaba | 8:2f2775c34640 | 1473 | sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_JAPANESE_CURVE; |
Vkadaba | 8:2f2775c34640 | 1474 | break; |
Vkadaba | 8:2f2775c34640 | 1475 | case ADMW1001_ADC_RTD_CURVE_ITS90: |
Vkadaba | 8:2f2775c34640 | 1476 | sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_ITS90_CURVE; |
Vkadaba | 8:2f2775c34640 | 1477 | break; |
Vkadaba | 8:2f2775c34640 | 1478 | default: |
Vkadaba | 8:2f2775c34640 | 1479 | ADMW_LOG_ERROR("Invalid RTD Curve %d specified", |
Vkadaba | 23:bb685f35b08b | 1480 | pAdcChannelConfig->rtdCurve); |
Vkadaba | 8:2f2775c34640 | 1481 | return ADMW_INVALID_PARAM; |
Vkadaba | 6:9d393a9677f4 | 1482 | } |
Vkadaba | 6:9d393a9677f4 | 1483 | |
Vkadaba | 23:bb685f35b08b | 1484 | if (pChannelConfig->disablePublishing) { |
ADIJake | 0:85855ecd3257 | 1485 | sensorDetailsReg.Do_Not_Publish = 1; |
Vkadaba | 23:bb685f35b08b | 1486 | } else { |
ADIJake | 0:85855ecd3257 | 1487 | sensorDetailsReg.Do_Not_Publish = 0; |
Vkadaba | 8:2f2775c34640 | 1488 | } |
Vkadaba | 23:bb685f35b08b | 1489 | |
Vkadaba | 23:bb685f35b08b | 1490 | switch (pChannelConfig->lutSelect) { |
Vkadaba | 8:2f2775c34640 | 1491 | case ADMW1001_LUT_DEFAULT: |
Vkadaba | 8:2f2775c34640 | 1492 | case ADMW1001_LUT_UNITY: |
Vkadaba | 8:2f2775c34640 | 1493 | case ADMW1001_LUT_CUSTOM: |
Vkadaba | 8:2f2775c34640 | 1494 | sensorDetailsReg.LUT_Select = pChannelConfig->lutSelect; |
Vkadaba | 8:2f2775c34640 | 1495 | break; |
Vkadaba | 8:2f2775c34640 | 1496 | default: |
Vkadaba | 8:2f2775c34640 | 1497 | ADMW_LOG_ERROR("Invalid LUT selection %d specified", |
Vkadaba | 23:bb685f35b08b | 1498 | pChannelConfig->lutSelect); |
Vkadaba | 23:bb685f35b08b | 1499 | return ADMW_INVALID_PARAM; |
Vkadaba | 8:2f2775c34640 | 1500 | } |
Vkadaba | 23:bb685f35b08b | 1501 | |
ADIJake | 0:85855ecd3257 | 1502 | WRITE_REG_U32(hDevice, sensorDetailsReg.VALUE32, CORE_SENSOR_DETAILSn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1503 | |
Vkadaba | 5:0728bde67bdb | 1504 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1505 | } |
ADIJake | 0:85855ecd3257 | 1506 | |
Vkadaba | 33:df7a00f1b8e1 | 1507 | static ADMW_RESULT admw_SetChannelAdcMeasurementSetup( |
Vkadaba | 5:0728bde67bdb | 1508 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1509 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 33:df7a00f1b8e1 | 1510 | ADMW1001_ADC_CHANNEL_CONFIG *pAdcChannelConfig) |
ADIJake | 0:85855ecd3257 | 1511 | { |
Vkadaba | 8:2f2775c34640 | 1512 | ADMW_CORE_Measurement_Setup_t MeasSetupReg; |
Vkadaba | 33:df7a00f1b8e1 | 1513 | ADMW1001_ADC_FILTER_CONFIG *pFilterConfig = &pAdcChannelConfig->filter; |
Vkadaba | 6:9d393a9677f4 | 1514 | MeasSetupReg.VALUE32 = REG_RESET_VAL(CORE_MEASUREMENT_SETUPn); |
Vkadaba | 33:df7a00f1b8e1 | 1515 | MeasSetupReg.PST_MEAS_EXC_CTRL = pAdcChannelConfig->current.excitationState; |
Vkadaba | 33:df7a00f1b8e1 | 1516 | MeasSetupReg.Buffer_Bypass = pAdcChannelConfig->bufferBypass; |
Vkadaba | 41:df78b7d7b675 | 1517 | |
Vkadaba | 23:bb685f35b08b | 1518 | if (pFilterConfig->type == ADMW1001_ADC_FILTER_SINC4) { |
Vkadaba | 6:9d393a9677f4 | 1519 | MeasSetupReg.ADC_Filter_Type = CORE_MEASUREMENT_SETUP_ENABLE_SINC4; |
Vkadaba | 6:9d393a9677f4 | 1520 | MeasSetupReg.ADC_SF = pFilterConfig->sf; |
Vkadaba | 23:bb685f35b08b | 1521 | } else if (pFilterConfig->type == ADMW1001_ADC_FILTER_SINC3) { |
Vkadaba | 6:9d393a9677f4 | 1522 | MeasSetupReg.ADC_Filter_Type = CORE_MEASUREMENT_SETUP_ENABLE_SINC3; |
Vkadaba | 23:bb685f35b08b | 1523 | MeasSetupReg.ADC_SF = pFilterConfig->sf; |
Vkadaba | 23:bb685f35b08b | 1524 | } else { |
Vkadaba | 5:0728bde67bdb | 1525 | ADMW_LOG_ERROR("Invalid ADC filter type %d specified", |
Vkadaba | 23:bb685f35b08b | 1526 | pFilterConfig->type); |
Vkadaba | 5:0728bde67bdb | 1527 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1528 | } |
Vkadaba | 23:bb685f35b08b | 1529 | |
Vkadaba | 8:2f2775c34640 | 1530 | /* chop mod ecan be 0 (none), 1 (HW, 2 (SW, 3 (HW+SW). */ |
Vkadaba | 17:2f0028880874 | 1531 | MeasSetupReg.Chop_Mode = pFilterConfig->chopMode; |
Vkadaba | 23:bb685f35b08b | 1532 | |
Vkadaba | 6:9d393a9677f4 | 1533 | if(pFilterConfig->notch1p2) |
Vkadaba | 6:9d393a9677f4 | 1534 | MeasSetupReg.NOTCH_EN_2 = 1; |
Vkadaba | 6:9d393a9677f4 | 1535 | else |
Vkadaba | 6:9d393a9677f4 | 1536 | MeasSetupReg.NOTCH_EN_2 = 0; |
Vkadaba | 23:bb685f35b08b | 1537 | |
Vkadaba | 23:bb685f35b08b | 1538 | switch(pFilterConfig->groundSwitch) { |
Vkadaba | 23:bb685f35b08b | 1539 | case ADMW1001_ADC_GND_SW_OPEN: |
Vkadaba | 23:bb685f35b08b | 1540 | MeasSetupReg.GND_SW = CORE_MEASUREMENT_SETUP_GND_SW_OPEN; |
Vkadaba | 23:bb685f35b08b | 1541 | break; |
Vkadaba | 23:bb685f35b08b | 1542 | case ADMW1001_ADC_GND_SW_CLOSED: |
Vkadaba | 23:bb685f35b08b | 1543 | MeasSetupReg.GND_SW = CORE_MEASUREMENT_SETUP_GND_SW_CLOSED; |
Vkadaba | 23:bb685f35b08b | 1544 | break; |
Vkadaba | 23:bb685f35b08b | 1545 | default: |
Vkadaba | 23:bb685f35b08b | 1546 | ADMW_LOG_ERROR("Invalid ground switch state %d specified", |
Vkadaba | 23:bb685f35b08b | 1547 | pFilterConfig->groundSwitch); |
Vkadaba | 23:bb685f35b08b | 1548 | return ADMW_INVALID_PARAM; |
Vkadaba | 6:9d393a9677f4 | 1549 | } |
Vkadaba | 23:bb685f35b08b | 1550 | |
Vkadaba | 6:9d393a9677f4 | 1551 | WRITE_REG_U32(hDevice, MeasSetupReg.VALUE32, CORE_MEASUREMENT_SETUPn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1552 | |
Vkadaba | 5:0728bde67bdb | 1553 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1554 | } |
ADIJake | 0:85855ecd3257 | 1555 | |
Vkadaba | 5:0728bde67bdb | 1556 | static ADMW_RESULT admw_SetChannelAdcCurrentConfig( |
Vkadaba | 5:0728bde67bdb | 1557 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1558 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1559 | ADMW1001_ADC_EXC_CURRENT_CONFIG *pCurrentConfig) |
ADIJake | 0:85855ecd3257 | 1560 | { |
Vkadaba | 8:2f2775c34640 | 1561 | ADMW_CORE_Channel_Excitation_t channelExcitationReg; |
ADIJake | 0:85855ecd3257 | 1562 | |
Vkadaba | 6:9d393a9677f4 | 1563 | channelExcitationReg.VALUE16 = REG_RESET_VAL(CORE_CHANNEL_EXCITATIONn); |
Vkadaba | 6:9d393a9677f4 | 1564 | |
Vkadaba | 18:cbf514cce921 | 1565 | if (pCurrentConfig->outputLevel == ADMW1001_ADC_NO_EXTERNAL_EXC_CURRENT) |
Vkadaba | 18:cbf514cce921 | 1566 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_NONE; |
Vkadaba | 18:cbf514cce921 | 1567 | else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_EXTERNAL) |
Vkadaba | 6:9d393a9677f4 | 1568 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_EXTERNAL; |
Vkadaba | 18:cbf514cce921 | 1569 | else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_50uA) |
Vkadaba | 6:9d393a9677f4 | 1570 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_50UA; |
Vkadaba | 6:9d393a9677f4 | 1571 | else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_100uA) |
Vkadaba | 6:9d393a9677f4 | 1572 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_100UA; |
Vkadaba | 6:9d393a9677f4 | 1573 | else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_250uA) |
Vkadaba | 6:9d393a9677f4 | 1574 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_250UA; |
Vkadaba | 6:9d393a9677f4 | 1575 | else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_500uA) |
Vkadaba | 6:9d393a9677f4 | 1576 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_500UA; |
Vkadaba | 6:9d393a9677f4 | 1577 | else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_1000uA) |
Vkadaba | 6:9d393a9677f4 | 1578 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_1000UA; |
Vkadaba | 23:bb685f35b08b | 1579 | else { |
Vkadaba | 6:9d393a9677f4 | 1580 | ADMW_LOG_ERROR("Invalid ADC excitation current %d specified", |
Vkadaba | 6:9d393a9677f4 | 1581 | pCurrentConfig->outputLevel); |
Vkadaba | 6:9d393a9677f4 | 1582 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1583 | } |
ADIJake | 0:85855ecd3257 | 1584 | |
Vkadaba | 6:9d393a9677f4 | 1585 | WRITE_REG_U16(hDevice, channelExcitationReg.VALUE16, CORE_CHANNEL_EXCITATIONn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1586 | |
Vkadaba | 5:0728bde67bdb | 1587 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1588 | } |
ADIJake | 0:85855ecd3257 | 1589 | |
Vkadaba | 5:0728bde67bdb | 1590 | ADMW_RESULT admw_SetAdcChannelConfig( |
Vkadaba | 5:0728bde67bdb | 1591 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1592 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1593 | ADMW1001_CHANNEL_CONFIG *pChannelConfig) |
ADIJake | 0:85855ecd3257 | 1594 | { |
Vkadaba | 5:0728bde67bdb | 1595 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 1596 | ADMW1001_ADC_CHANNEL_CONFIG *pAdcChannelConfig = |
ADIJake | 0:85855ecd3257 | 1597 | &pChannelConfig->adcChannelConfig; |
ADIJake | 0:85855ecd3257 | 1598 | |
Vkadaba | 5:0728bde67bdb | 1599 | eRet = admw_SetChannelAdcSensorType(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1600 | pAdcChannelConfig->sensor); |
Vkadaba | 23:bb685f35b08b | 1601 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1602 | ADMW_LOG_ERROR("Failed to set ADC sensor type for channel %d", |
Vkadaba | 23:bb685f35b08b | 1603 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1604 | return eRet; |
ADIJake | 0:85855ecd3257 | 1605 | } |
ADIJake | 0:85855ecd3257 | 1606 | |
Vkadaba | 5:0728bde67bdb | 1607 | eRet = admw_SetChannelAdcSensorDetails(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1608 | pChannelConfig); |
Vkadaba | 23:bb685f35b08b | 1609 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1610 | ADMW_LOG_ERROR("Failed to set ADC sensor details for channel %d", |
Vkadaba | 23:bb685f35b08b | 1611 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1612 | return eRet; |
ADIJake | 0:85855ecd3257 | 1613 | } |
ADIJake | 0:85855ecd3257 | 1614 | |
Vkadaba | 33:df7a00f1b8e1 | 1615 | eRet = admw_SetChannelAdcMeasurementSetup(hDevice, eChannelId, |
Vkadaba | 41:df78b7d7b675 | 1616 | pAdcChannelConfig); |
Vkadaba | 23:bb685f35b08b | 1617 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1618 | ADMW_LOG_ERROR("Failed to set ADC filter for channel %d", |
Vkadaba | 23:bb685f35b08b | 1619 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1620 | return eRet; |
ADIJake | 0:85855ecd3257 | 1621 | } |
ADIJake | 0:85855ecd3257 | 1622 | |
Vkadaba | 5:0728bde67bdb | 1623 | eRet = admw_SetChannelAdcCurrentConfig(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1624 | &pAdcChannelConfig->current); |
Vkadaba | 23:bb685f35b08b | 1625 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1626 | ADMW_LOG_ERROR("Failed to set ADC current for channel %d", |
Vkadaba | 23:bb685f35b08b | 1627 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1628 | return eRet; |
ADIJake | 0:85855ecd3257 | 1629 | } |
ADIJake | 0:85855ecd3257 | 1630 | |
Vkadaba | 5:0728bde67bdb | 1631 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1632 | } |
ADIJake | 0:85855ecd3257 | 1633 | |
Vkadaba | 5:0728bde67bdb | 1634 | static ADMW_RESULT admw_SetChannelDigitalSensorDetails( |
Vkadaba | 5:0728bde67bdb | 1635 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1636 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1637 | ADMW1001_CHANNEL_CONFIG *pChannelConfig) |
ADIJake | 0:85855ecd3257 | 1638 | { |
Vkadaba | 8:2f2775c34640 | 1639 | ADMW_CORE_Sensor_Details_t sensorDetailsReg; |
ADIJake | 0:85855ecd3257 | 1640 | |
ADIJake | 0:85855ecd3257 | 1641 | sensorDetailsReg.VALUE32 = REG_RESET_VAL(CORE_SENSOR_DETAILSn); |
ADIJake | 0:85855ecd3257 | 1642 | |
Vkadaba | 23:bb685f35b08b | 1643 | if (pChannelConfig->compensationChannel == ADMW1001_CH_ID_NONE) { |
ADIJake | 0:85855ecd3257 | 1644 | sensorDetailsReg.Compensation_Disable = 1; |
ADIJake | 0:85855ecd3257 | 1645 | sensorDetailsReg.Compensation_Channel = 0; |
Vkadaba | 23:bb685f35b08b | 1646 | } else { |
Vkadaba | 5:0728bde67bdb | 1647 | ADMW_LOG_ERROR("Invalid compensation channel specified for digital sensor"); |
Vkadaba | 5:0728bde67bdb | 1648 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1649 | } |
ADIJake | 0:85855ecd3257 | 1650 | |
Vkadaba | 23:bb685f35b08b | 1651 | if (pChannelConfig->measurementUnit == ADMW1001_MEASUREMENT_UNIT_UNSPECIFIED) { |
Vkadaba | 5:0728bde67bdb | 1652 | sensorDetailsReg.Measurement_Units = CORE_SENSOR_DETAILS_UNITS_UNSPECIFIED; |
Vkadaba | 23:bb685f35b08b | 1653 | } else { |
Vkadaba | 5:0728bde67bdb | 1654 | ADMW_LOG_ERROR("Invalid measurement unit specified for digital channel"); |
Vkadaba | 5:0728bde67bdb | 1655 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1656 | } |
ADIJake | 0:85855ecd3257 | 1657 | |
ADIJake | 0:85855ecd3257 | 1658 | if (pChannelConfig->disablePublishing) |
ADIJake | 0:85855ecd3257 | 1659 | sensorDetailsReg.Do_Not_Publish = 1; |
ADIJake | 0:85855ecd3257 | 1660 | else |
ADIJake | 0:85855ecd3257 | 1661 | sensorDetailsReg.Do_Not_Publish = 0; |
ADIJake | 0:85855ecd3257 | 1662 | |
ADIJake | 0:85855ecd3257 | 1663 | WRITE_REG_U32(hDevice, sensorDetailsReg.VALUE32, CORE_SENSOR_DETAILSn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1664 | |
Vkadaba | 5:0728bde67bdb | 1665 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1666 | } |
ADIJake | 0:85855ecd3257 | 1667 | |
Vkadaba | 5:0728bde67bdb | 1668 | static ADMW_RESULT admw_SetDigitalSensorFormat( |
Vkadaba | 5:0728bde67bdb | 1669 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1670 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1671 | ADMW1001_DIGITAL_SENSOR_DATA_FORMAT *pDataFormat) |
ADIJake | 0:85855ecd3257 | 1672 | { |
Vkadaba | 8:2f2775c34640 | 1673 | ADMW_CORE_Digital_Sensor_Config_t sensorConfigReg; |
ADIJake | 0:85855ecd3257 | 1674 | |
ADIJake | 0:85855ecd3257 | 1675 | sensorConfigReg.VALUE16 = REG_RESET_VAL(CORE_DIGITAL_SENSOR_CONFIGn); |
ADIJake | 0:85855ecd3257 | 1676 | |
Vkadaba | 23:bb685f35b08b | 1677 | if (pDataFormat->coding != ADMW1001_DIGITAL_SENSOR_DATA_CODING_NONE) { |
Vkadaba | 23:bb685f35b08b | 1678 | if (pDataFormat->frameLength == 0) { |
Vkadaba | 5:0728bde67bdb | 1679 | ADMW_LOG_ERROR("Invalid frame length specified for digital sensor data format"); |
Vkadaba | 5:0728bde67bdb | 1680 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1681 | } |
Vkadaba | 23:bb685f35b08b | 1682 | if (pDataFormat->numDataBits == 0) { |
Vkadaba | 5:0728bde67bdb | 1683 | ADMW_LOG_ERROR("Invalid frame length specified for digital sensor data format"); |
Vkadaba | 5:0728bde67bdb | 1684 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1685 | } |
ADIJake | 0:85855ecd3257 | 1686 | |
ADIJake | 0:85855ecd3257 | 1687 | CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_CONFIG_DIGITAL_SENSOR_READ_BYTES, |
ADIJake | 0:85855ecd3257 | 1688 | pDataFormat->frameLength - 1); |
ADIJake | 0:85855ecd3257 | 1689 | CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_CONFIG_DIGITAL_SENSOR_DATA_BITS, |
ADIJake | 0:85855ecd3257 | 1690 | pDataFormat->numDataBits - 1); |
ADIJake | 0:85855ecd3257 | 1691 | CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_CONFIG_DIGITAL_SENSOR_BIT_OFFSET, |
ADIJake | 0:85855ecd3257 | 1692 | pDataFormat->bitOffset); |
ADIJake | 0:85855ecd3257 | 1693 | |
ADIJake | 0:85855ecd3257 | 1694 | sensorConfigReg.Digital_Sensor_Read_Bytes = pDataFormat->frameLength - 1; |
ADIJake | 0:85855ecd3257 | 1695 | sensorConfigReg.Digital_Sensor_Data_Bits = pDataFormat->numDataBits - 1; |
ADIJake | 0:85855ecd3257 | 1696 | sensorConfigReg.Digital_Sensor_Bit_Offset = pDataFormat->bitOffset; |
ADIJake | 0:85855ecd3257 | 1697 | sensorConfigReg.Digital_Sensor_Left_Aligned = pDataFormat->leftJustified ? 1 : 0; |
ADIJake | 0:85855ecd3257 | 1698 | sensorConfigReg.Digital_Sensor_Little_Endian = pDataFormat->littleEndian ? 1 : 0; |
ADIJake | 0:85855ecd3257 | 1699 | |
Vkadaba | 23:bb685f35b08b | 1700 | switch (pDataFormat->coding) { |
Vkadaba | 23:bb685f35b08b | 1701 | case ADMW1001_DIGITAL_SENSOR_DATA_CODING_UNIPOLAR: |
Vkadaba | 23:bb685f35b08b | 1702 | sensorConfigReg.Digital_Sensor_Coding = CORE_DIGITAL_SENSOR_CONFIG_CODING_UNIPOLAR; |
Vkadaba | 23:bb685f35b08b | 1703 | break; |
Vkadaba | 23:bb685f35b08b | 1704 | case ADMW1001_DIGITAL_SENSOR_DATA_CODING_TWOS_COMPLEMENT: |
Vkadaba | 23:bb685f35b08b | 1705 | sensorConfigReg.Digital_Sensor_Coding = CORE_DIGITAL_SENSOR_CONFIG_CODING_TWOS_COMPL; |
Vkadaba | 23:bb685f35b08b | 1706 | break; |
Vkadaba | 23:bb685f35b08b | 1707 | case ADMW1001_DIGITAL_SENSOR_DATA_CODING_OFFSET_BINARY: |
Vkadaba | 23:bb685f35b08b | 1708 | sensorConfigReg.Digital_Sensor_Coding = CORE_DIGITAL_SENSOR_CONFIG_CODING_OFFSET_BINARY; |
Vkadaba | 23:bb685f35b08b | 1709 | break; |
Vkadaba | 23:bb685f35b08b | 1710 | default: |
Vkadaba | 23:bb685f35b08b | 1711 | ADMW_LOG_ERROR("Invalid coding specified for digital sensor data format"); |
Vkadaba | 23:bb685f35b08b | 1712 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1713 | } |
Vkadaba | 23:bb685f35b08b | 1714 | } else { |
Vkadaba | 5:0728bde67bdb | 1715 | sensorConfigReg.Digital_Sensor_Coding = CORE_DIGITAL_SENSOR_CONFIG_CODING_NONE; |
ADIJake | 0:85855ecd3257 | 1716 | } |
ADIJake | 0:85855ecd3257 | 1717 | |
ADIJake | 0:85855ecd3257 | 1718 | WRITE_REG_U16(hDevice, sensorConfigReg.VALUE16, |
ADIJake | 0:85855ecd3257 | 1719 | CORE_DIGITAL_SENSOR_CONFIGn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1720 | |
ADIJake | 0:85855ecd3257 | 1721 | |
Vkadaba | 5:0728bde67bdb | 1722 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1723 | } |
ADIJake | 0:85855ecd3257 | 1724 | |
Vkadaba | 5:0728bde67bdb | 1725 | static ADMW_RESULT admw_SetDigitalCalibrationParam( |
Vkadaba | 23:bb685f35b08b | 1726 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 23:bb685f35b08b | 1727 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 23:bb685f35b08b | 1728 | ADMW1001_DIGITAL_CALIBRATION_COMMAND *pCalibrationParam) |
ADIJake | 0:85855ecd3257 | 1729 | { |
Vkadaba | 32:52445bef314d | 1730 | // ADMW_CORE_Calibration_Parameter_t calibrationParamReg; |
Vkadaba | 32:52445bef314d | 1731 | // |
Vkadaba | 32:52445bef314d | 1732 | // calibrationParamReg.VALUE32 = REG_RESET_VAL(CORE_CALIBRATION_PARAMETERn); |
Vkadaba | 32:52445bef314d | 1733 | // |
Vkadaba | 32:52445bef314d | 1734 | // if (pCalibrationParam->enableCalibrationParam == false) |
Vkadaba | 32:52445bef314d | 1735 | // calibrationParamReg.Calibration_Parameter_Enable = 0; |
Vkadaba | 32:52445bef314d | 1736 | // else |
Vkadaba | 32:52445bef314d | 1737 | // calibrationParamReg.Calibration_Parameter_Enable = 1; |
Vkadaba | 32:52445bef314d | 1738 | // |
Vkadaba | 32:52445bef314d | 1739 | // CHECK_REG_FIELD_VAL(CORE_CALIBRATION_PARAMETER_CALIBRATION_PARAMETER, |
Vkadaba | 32:52445bef314d | 1740 | // pCalibrationParam->calibrationParam); |
Vkadaba | 32:52445bef314d | 1741 | // |
Vkadaba | 32:52445bef314d | 1742 | // calibrationParamReg.Calibration_Parameter = pCalibrationParam->calibrationParam; |
Vkadaba | 32:52445bef314d | 1743 | // |
Vkadaba | 32:52445bef314d | 1744 | // WRITE_REG_U32(hDevice, calibrationParamReg.VALUE32, |
Vkadaba | 32:52445bef314d | 1745 | // CORE_CALIBRATION_PARAMETERn(eChannelId)); |
Vkadaba | 32:52445bef314d | 1746 | // |
Vkadaba | 5:0728bde67bdb | 1747 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1748 | } |
ADIJake | 0:85855ecd3257 | 1749 | |
Vkadaba | 5:0728bde67bdb | 1750 | static ADMW_RESULT admw_SetChannelI2cSensorType( |
Vkadaba | 5:0728bde67bdb | 1751 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1752 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1753 | ADMW1001_I2C_SENSOR_TYPE sensorType) |
ADIJake | 0:85855ecd3257 | 1754 | { |
Vkadaba | 8:2f2775c34640 | 1755 | ADMW_CORE_Sensor_Type_t sensorTypeReg; |
ADIJake | 0:85855ecd3257 | 1756 | |
ADIJake | 0:85855ecd3257 | 1757 | sensorTypeReg.VALUE16 = REG_RESET_VAL(CORE_SENSOR_TYPEn); |
ADIJake | 0:85855ecd3257 | 1758 | |
ADIJake | 0:85855ecd3257 | 1759 | /* Ensure that the sensor type is valid for this channel */ |
Vkadaba | 23:bb685f35b08b | 1760 | switch(sensorType) { |
Vkadaba | 8:2f2775c34640 | 1761 | case ADMW1001_I2C_SENSOR_HUMIDITY_A: |
Vkadaba | 8:2f2775c34640 | 1762 | case ADMW1001_I2C_SENSOR_HUMIDITY_B: |
Vkadaba | 8:2f2775c34640 | 1763 | sensorTypeReg.Sensor_Type = sensorType; |
Vkadaba | 8:2f2775c34640 | 1764 | break; |
Vkadaba | 8:2f2775c34640 | 1765 | default: |
Vkadaba | 8:2f2775c34640 | 1766 | ADMW_LOG_ERROR("Unsupported I2C sensor type %d specified", sensorType); |
Vkadaba | 8:2f2775c34640 | 1767 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1768 | } |
ADIJake | 0:85855ecd3257 | 1769 | |
ADIJake | 0:85855ecd3257 | 1770 | WRITE_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1771 | |
Vkadaba | 5:0728bde67bdb | 1772 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1773 | } |
ADIJake | 0:85855ecd3257 | 1774 | |
Vkadaba | 5:0728bde67bdb | 1775 | static ADMW_RESULT admw_SetChannelI2cSensorAddress( |
Vkadaba | 5:0728bde67bdb | 1776 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1777 | ADMW1001_CH_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 1778 | uint32_t deviceAddress) |
ADIJake | 0:85855ecd3257 | 1779 | { |
ADIJake | 0:85855ecd3257 | 1780 | CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_ADDRESS_DIGITAL_SENSOR_ADDRESS, deviceAddress); |
ADIJake | 0:85855ecd3257 | 1781 | WRITE_REG_U8(hDevice, deviceAddress, CORE_DIGITAL_SENSOR_ADDRESSn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1782 | |
Vkadaba | 5:0728bde67bdb | 1783 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1784 | } |
ADIJake | 0:85855ecd3257 | 1785 | |
Vkadaba | 5:0728bde67bdb | 1786 | static ADMW_RESULT admw_SetDigitalChannelComms( |
Vkadaba | 5:0728bde67bdb | 1787 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1788 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1789 | ADMW1001_DIGITAL_SENSOR_COMMS *pDigitalComms) |
ADIJake | 0:85855ecd3257 | 1790 | { |
Vkadaba | 8:2f2775c34640 | 1791 | ADMW_CORE_Digital_Sensor_Comms_t digitalSensorComms; |
ADIJake | 0:85855ecd3257 | 1792 | |
ADIJake | 0:85855ecd3257 | 1793 | digitalSensorComms.VALUE16 = REG_RESET_VAL(CORE_DIGITAL_SENSOR_COMMSn); |
ADIJake | 0:85855ecd3257 | 1794 | |
Vkadaba | 23:bb685f35b08b | 1795 | if(pDigitalComms->useCustomCommsConfig) { |
ADIJake | 0:85855ecd3257 | 1796 | digitalSensorComms.Digital_Sensor_Comms_En = 1; |
ADIJake | 0:85855ecd3257 | 1797 | |
Vkadaba | 23:bb685f35b08b | 1798 | if(pDigitalComms->i2cClockSpeed == ADMW1001_DIGITAL_SENSOR_COMMS_I2C_CLOCK_SPEED_100K) { |
Vkadaba | 5:0728bde67bdb | 1799 | digitalSensorComms.I2C_Clock = CORE_DIGITAL_SENSOR_COMMS_I2C_100K; |
Vkadaba | 23:bb685f35b08b | 1800 | } else if(pDigitalComms->i2cClockSpeed == ADMW1001_DIGITAL_SENSOR_COMMS_I2C_CLOCK_SPEED_400K) { |
Vkadaba | 5:0728bde67bdb | 1801 | digitalSensorComms.I2C_Clock = CORE_DIGITAL_SENSOR_COMMS_I2C_400K; |
Vkadaba | 23:bb685f35b08b | 1802 | } else { |
Vkadaba | 5:0728bde67bdb | 1803 | ADMW_LOG_ERROR("Invalid I2C clock speed %d specified", |
Vkadaba | 23:bb685f35b08b | 1804 | pDigitalComms->i2cClockSpeed); |
Vkadaba | 5:0728bde67bdb | 1805 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1806 | } |
ADIJake | 0:85855ecd3257 | 1807 | |
Vkadaba | 23:bb685f35b08b | 1808 | if(pDigitalComms->spiMode == ADMW1001_DIGITAL_SENSOR_COMMS_SPI_MODE_0) { |
Vkadaba | 5:0728bde67bdb | 1809 | digitalSensorComms.SPI_Mode = CORE_DIGITAL_SENSOR_COMMS_SPI_MODE_0; |
Vkadaba | 23:bb685f35b08b | 1810 | } else if(pDigitalComms->spiMode == ADMW1001_DIGITAL_SENSOR_COMMS_SPI_MODE_1) { |
Vkadaba | 5:0728bde67bdb | 1811 | digitalSensorComms.SPI_Mode = CORE_DIGITAL_SENSOR_COMMS_SPI_MODE_1; |
Vkadaba | 23:bb685f35b08b | 1812 | } else if(pDigitalComms->spiMode == ADMW1001_DIGITAL_SENSOR_COMMS_SPI_MODE_2) { |
Vkadaba | 5:0728bde67bdb | 1813 | digitalSensorComms.SPI_Mode = CORE_DIGITAL_SENSOR_COMMS_SPI_MODE_2; |
Vkadaba | 23:bb685f35b08b | 1814 | } else if(pDigitalComms->spiMode == ADMW1001_DIGITAL_SENSOR_COMMS_SPI_MODE_3) { |
Vkadaba | 5:0728bde67bdb | 1815 | digitalSensorComms.SPI_Mode = CORE_DIGITAL_SENSOR_COMMS_SPI_MODE_3; |
Vkadaba | 23:bb685f35b08b | 1816 | } else { |
Vkadaba | 5:0728bde67bdb | 1817 | ADMW_LOG_ERROR("Invalid SPI mode %d specified", |
Vkadaba | 23:bb685f35b08b | 1818 | pDigitalComms->spiMode); |
Vkadaba | 5:0728bde67bdb | 1819 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1820 | } |
ADIJake | 0:85855ecd3257 | 1821 | |
Vkadaba | 23:bb685f35b08b | 1822 | switch (pDigitalComms->spiClock) { |
Vkadaba | 23:bb685f35b08b | 1823 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_8MHZ: |
Vkadaba | 23:bb685f35b08b | 1824 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_8MHZ; |
Vkadaba | 23:bb685f35b08b | 1825 | break; |
Vkadaba | 23:bb685f35b08b | 1826 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_4MHZ: |
Vkadaba | 23:bb685f35b08b | 1827 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_4MHZ; |
Vkadaba | 23:bb685f35b08b | 1828 | break; |
Vkadaba | 23:bb685f35b08b | 1829 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_2MHZ: |
Vkadaba | 23:bb685f35b08b | 1830 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_2MHZ; |
Vkadaba | 23:bb685f35b08b | 1831 | break; |
Vkadaba | 23:bb685f35b08b | 1832 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_1MHZ: |
Vkadaba | 23:bb685f35b08b | 1833 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_1MHZ; |
Vkadaba | 23:bb685f35b08b | 1834 | break; |
Vkadaba | 23:bb685f35b08b | 1835 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_500KHZ: |
Vkadaba | 23:bb685f35b08b | 1836 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_500KHZ; |
Vkadaba | 23:bb685f35b08b | 1837 | break; |
Vkadaba | 23:bb685f35b08b | 1838 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_250KHZ: |
Vkadaba | 23:bb685f35b08b | 1839 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_250KHZ; |
Vkadaba | 23:bb685f35b08b | 1840 | break; |
Vkadaba | 23:bb685f35b08b | 1841 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_125KHZ: |
Vkadaba | 23:bb685f35b08b | 1842 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_125KHZ; |
Vkadaba | 23:bb685f35b08b | 1843 | break; |
Vkadaba | 23:bb685f35b08b | 1844 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_62P5KHZ: |
Vkadaba | 23:bb685f35b08b | 1845 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_62P5KHZ; |
Vkadaba | 23:bb685f35b08b | 1846 | break; |
Vkadaba | 23:bb685f35b08b | 1847 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_31P3KHZ: |
Vkadaba | 23:bb685f35b08b | 1848 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_31P3KHZ; |
Vkadaba | 23:bb685f35b08b | 1849 | break; |
Vkadaba | 23:bb685f35b08b | 1850 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_15P6KHZ: |
Vkadaba | 23:bb685f35b08b | 1851 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_15P6KHZ; |
Vkadaba | 23:bb685f35b08b | 1852 | break; |
Vkadaba | 23:bb685f35b08b | 1853 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_7P8KHZ: |
Vkadaba | 23:bb685f35b08b | 1854 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_7P8KHZ; |
Vkadaba | 23:bb685f35b08b | 1855 | break; |
Vkadaba | 23:bb685f35b08b | 1856 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_3P9KHZ: |
Vkadaba | 23:bb685f35b08b | 1857 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_3P9KHZ; |
Vkadaba | 23:bb685f35b08b | 1858 | break; |
Vkadaba | 23:bb685f35b08b | 1859 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_1P9KHZ: |
Vkadaba | 23:bb685f35b08b | 1860 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_1P9KHZ; |
Vkadaba | 23:bb685f35b08b | 1861 | break; |
Vkadaba | 23:bb685f35b08b | 1862 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_977HZ: |
Vkadaba | 23:bb685f35b08b | 1863 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_977HZ; |
Vkadaba | 23:bb685f35b08b | 1864 | break; |
Vkadaba | 23:bb685f35b08b | 1865 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_488HZ: |
Vkadaba | 23:bb685f35b08b | 1866 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_488HZ; |
Vkadaba | 23:bb685f35b08b | 1867 | break; |
Vkadaba | 23:bb685f35b08b | 1868 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_244HZ: |
Vkadaba | 23:bb685f35b08b | 1869 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_244HZ; |
Vkadaba | 23:bb685f35b08b | 1870 | break; |
Vkadaba | 23:bb685f35b08b | 1871 | default: |
Vkadaba | 23:bb685f35b08b | 1872 | ADMW_LOG_ERROR("Invalid SPI clock %d specified", |
Vkadaba | 23:bb685f35b08b | 1873 | pDigitalComms->spiClock); |
Vkadaba | 23:bb685f35b08b | 1874 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1875 | } |
Vkadaba | 23:bb685f35b08b | 1876 | } else { |
ADIJake | 0:85855ecd3257 | 1877 | digitalSensorComms.Digital_Sensor_Comms_En = 0; |
ADIJake | 0:85855ecd3257 | 1878 | } |
ADIJake | 0:85855ecd3257 | 1879 | |
ADIJake | 0:85855ecd3257 | 1880 | WRITE_REG_U16(hDevice, digitalSensorComms.VALUE16, CORE_DIGITAL_SENSOR_COMMSn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1881 | |
Vkadaba | 5:0728bde67bdb | 1882 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1883 | } |
ADIJake | 0:85855ecd3257 | 1884 | |
Vkadaba | 5:0728bde67bdb | 1885 | ADMW_RESULT admw_SetI2cChannelConfig( |
Vkadaba | 5:0728bde67bdb | 1886 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1887 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1888 | ADMW1001_CHANNEL_CONFIG *pChannelConfig) |
ADIJake | 0:85855ecd3257 | 1889 | { |
Vkadaba | 5:0728bde67bdb | 1890 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 1891 | ADMW1001_I2C_CHANNEL_CONFIG *pI2cChannelConfig = |
ADIJake | 0:85855ecd3257 | 1892 | &pChannelConfig->i2cChannelConfig; |
ADIJake | 0:85855ecd3257 | 1893 | |
Vkadaba | 5:0728bde67bdb | 1894 | eRet = admw_SetChannelI2cSensorType(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1895 | pI2cChannelConfig->sensor); |
Vkadaba | 23:bb685f35b08b | 1896 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1897 | ADMW_LOG_ERROR("Failed to set I2C sensor type for channel %d", |
Vkadaba | 23:bb685f35b08b | 1898 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1899 | return eRet; |
ADIJake | 0:85855ecd3257 | 1900 | } |
ADIJake | 0:85855ecd3257 | 1901 | |
Vkadaba | 5:0728bde67bdb | 1902 | eRet = admw_SetChannelI2cSensorAddress(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1903 | pI2cChannelConfig->deviceAddress); |
Vkadaba | 23:bb685f35b08b | 1904 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1905 | ADMW_LOG_ERROR("Failed to set I2C sensor address for channel %d", |
Vkadaba | 23:bb685f35b08b | 1906 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1907 | return eRet; |
ADIJake | 0:85855ecd3257 | 1908 | } |
ADIJake | 0:85855ecd3257 | 1909 | |
Vkadaba | 5:0728bde67bdb | 1910 | eRet = admw_SetChannelDigitalSensorDetails(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1911 | pChannelConfig); |
Vkadaba | 23:bb685f35b08b | 1912 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1913 | ADMW_LOG_ERROR("Failed to set I2C sensor details for channel %d", |
Vkadaba | 23:bb685f35b08b | 1914 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1915 | return eRet; |
ADIJake | 0:85855ecd3257 | 1916 | } |
ADIJake | 0:85855ecd3257 | 1917 | |
Vkadaba | 5:0728bde67bdb | 1918 | eRet = admw_SetDigitalSensorFormat(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1919 | &pI2cChannelConfig->dataFormat); |
Vkadaba | 23:bb685f35b08b | 1920 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1921 | ADMW_LOG_ERROR("Failed to set I2C sensor data format for channel %d", |
Vkadaba | 23:bb685f35b08b | 1922 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1923 | return eRet; |
ADIJake | 0:85855ecd3257 | 1924 | } |
ADIJake | 0:85855ecd3257 | 1925 | |
Vkadaba | 5:0728bde67bdb | 1926 | eRet = admw_SetDigitalCalibrationParam(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1927 | &pI2cChannelConfig->digitalCalibrationParam); |
Vkadaba | 23:bb685f35b08b | 1928 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1929 | ADMW_LOG_ERROR("Failed to set I2C digital calibration param for channel %d", |
Vkadaba | 23:bb685f35b08b | 1930 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1931 | return eRet; |
ADIJake | 0:85855ecd3257 | 1932 | } |
ADIJake | 0:85855ecd3257 | 1933 | |
Vkadaba | 5:0728bde67bdb | 1934 | eRet = admw_SetDigitalChannelComms(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1935 | &pI2cChannelConfig->configureComms); |
Vkadaba | 23:bb685f35b08b | 1936 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1937 | ADMW_LOG_ERROR("Failed to set I2C comms for channel %d", |
Vkadaba | 23:bb685f35b08b | 1938 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1939 | return eRet; |
ADIJake | 0:85855ecd3257 | 1940 | } |
ADIJake | 0:85855ecd3257 | 1941 | |
Vkadaba | 5:0728bde67bdb | 1942 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1943 | } |
ADIJake | 0:85855ecd3257 | 1944 | |
Vkadaba | 5:0728bde67bdb | 1945 | static ADMW_RESULT admw_SetChannelSpiSensorType( |
Vkadaba | 5:0728bde67bdb | 1946 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1947 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1948 | ADMW1001_SPI_SENSOR_TYPE sensorType) |
ADIJake | 0:85855ecd3257 | 1949 | { |
Vkadaba | 8:2f2775c34640 | 1950 | ADMW_CORE_Sensor_Type_t sensorTypeReg; |
ADIJake | 0:85855ecd3257 | 1951 | |
ADIJake | 0:85855ecd3257 | 1952 | sensorTypeReg.VALUE16 = REG_RESET_VAL(CORE_SENSOR_TYPEn); |
ADIJake | 0:85855ecd3257 | 1953 | |
ADIJake | 0:85855ecd3257 | 1954 | /* Ensure that the sensor type is valid for this channel */ |
Vkadaba | 23:bb685f35b08b | 1955 | switch(sensorType) { |
Vkadaba | 23:bb685f35b08b | 1956 | case ADMW1001_SPI_SENSOR_PRESSURE_A: |
Vkadaba | 23:bb685f35b08b | 1957 | case ADMW1001_SPI_SENSOR_ACCELEROMETER_A: |
Vkadaba | 23:bb685f35b08b | 1958 | case ADMW1001_SPI_SENSOR_ACCELEROMETER_B: |
Vkadaba | 23:bb685f35b08b | 1959 | |
Vkadaba | 23:bb685f35b08b | 1960 | sensorTypeReg.Sensor_Type = sensorType; |
Vkadaba | 23:bb685f35b08b | 1961 | break; |
Vkadaba | 23:bb685f35b08b | 1962 | default: |
Vkadaba | 23:bb685f35b08b | 1963 | ADMW_LOG_ERROR("Unsupported SPI sensor type %d specified", sensorType); |
Vkadaba | 23:bb685f35b08b | 1964 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1965 | } |
ADIJake | 0:85855ecd3257 | 1966 | |
ADIJake | 0:85855ecd3257 | 1967 | WRITE_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1968 | |
Vkadaba | 5:0728bde67bdb | 1969 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1970 | } |
ADIJake | 0:85855ecd3257 | 1971 | |
Vkadaba | 5:0728bde67bdb | 1972 | ADMW_RESULT admw_SetSpiChannelConfig( |
Vkadaba | 5:0728bde67bdb | 1973 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1974 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1975 | ADMW1001_CHANNEL_CONFIG *pChannelConfig) |
ADIJake | 0:85855ecd3257 | 1976 | { |
Vkadaba | 5:0728bde67bdb | 1977 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 1978 | ADMW1001_SPI_CHANNEL_CONFIG *pSpiChannelConfig = |
ADIJake | 0:85855ecd3257 | 1979 | &pChannelConfig->spiChannelConfig; |
ADIJake | 0:85855ecd3257 | 1980 | |
Vkadaba | 5:0728bde67bdb | 1981 | eRet = admw_SetChannelSpiSensorType(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1982 | pSpiChannelConfig->sensor); |
Vkadaba | 23:bb685f35b08b | 1983 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1984 | ADMW_LOG_ERROR("Failed to set SPI sensor type for channel %d", |
Vkadaba | 23:bb685f35b08b | 1985 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1986 | return eRet; |
ADIJake | 0:85855ecd3257 | 1987 | } |
ADIJake | 0:85855ecd3257 | 1988 | |
Vkadaba | 5:0728bde67bdb | 1989 | eRet = admw_SetChannelDigitalSensorDetails(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1990 | pChannelConfig); |
Vkadaba | 23:bb685f35b08b | 1991 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1992 | ADMW_LOG_ERROR("Failed to set SPI sensor details for channel %d", |
Vkadaba | 23:bb685f35b08b | 1993 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1994 | return eRet; |
ADIJake | 0:85855ecd3257 | 1995 | } |
ADIJake | 0:85855ecd3257 | 1996 | |
Vkadaba | 5:0728bde67bdb | 1997 | eRet = admw_SetDigitalSensorFormat(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1998 | &pSpiChannelConfig->dataFormat); |
Vkadaba | 23:bb685f35b08b | 1999 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 2000 | ADMW_LOG_ERROR("Failed to set SPI sensor data format for channel %d", |
Vkadaba | 23:bb685f35b08b | 2001 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2002 | return eRet; |
ADIJake | 0:85855ecd3257 | 2003 | } |
ADIJake | 0:85855ecd3257 | 2004 | |
Vkadaba | 5:0728bde67bdb | 2005 | eRet = admw_SetDigitalCalibrationParam(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 2006 | &pSpiChannelConfig->digitalCalibrationParam); |
Vkadaba | 23:bb685f35b08b | 2007 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 2008 | ADMW_LOG_ERROR("Failed to set SPI digital calibration param for channel %d", |
Vkadaba | 23:bb685f35b08b | 2009 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2010 | return eRet; |
ADIJake | 0:85855ecd3257 | 2011 | } |
ADIJake | 0:85855ecd3257 | 2012 | |
Vkadaba | 5:0728bde67bdb | 2013 | eRet = admw_SetDigitalChannelComms(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 2014 | &pSpiChannelConfig->configureComms); |
Vkadaba | 23:bb685f35b08b | 2015 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 2016 | ADMW_LOG_ERROR("Failed to set SPI comms for channel %d", |
Vkadaba | 23:bb685f35b08b | 2017 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2018 | return eRet; |
ADIJake | 0:85855ecd3257 | 2019 | } |
ADIJake | 0:85855ecd3257 | 2020 | |
Vkadaba | 5:0728bde67bdb | 2021 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2022 | } |
ADIJake | 0:85855ecd3257 | 2023 | |
Vkadaba | 5:0728bde67bdb | 2024 | ADMW_RESULT admw1001_SetChannelThresholdLimits( |
Vkadaba | 5:0728bde67bdb | 2025 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 2026 | ADMW1001_CH_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 2027 | float32_t fHighThresholdLimit, |
ADIJake | 0:85855ecd3257 | 2028 | float32_t fLowThresholdLimit) |
ADIJake | 0:85855ecd3257 | 2029 | { |
ADIJake | 0:85855ecd3257 | 2030 | /* |
ADIJake | 0:85855ecd3257 | 2031 | * If the low/high limits are *both* set to 0 in memory, or NaNs, assume |
ADIJake | 0:85855ecd3257 | 2032 | * that they are unset, or not required, and use infinity defaults instead |
ADIJake | 0:85855ecd3257 | 2033 | */ |
Vkadaba | 23:bb685f35b08b | 2034 | if (fHighThresholdLimit == 0.0f && fLowThresholdLimit == 0.0f) { |
ADIJake | 0:85855ecd3257 | 2035 | fHighThresholdLimit = INFINITY; |
ADIJake | 0:85855ecd3257 | 2036 | fLowThresholdLimit = -INFINITY; |
Vkadaba | 23:bb685f35b08b | 2037 | } else { |
ADIJake | 0:85855ecd3257 | 2038 | if (isnan(fHighThresholdLimit)) |
ADIJake | 0:85855ecd3257 | 2039 | fHighThresholdLimit = INFINITY; |
ADIJake | 0:85855ecd3257 | 2040 | if (isnan(fLowThresholdLimit)) |
ADIJake | 0:85855ecd3257 | 2041 | fLowThresholdLimit = -INFINITY; |
ADIJake | 0:85855ecd3257 | 2042 | } |
ADIJake | 0:85855ecd3257 | 2043 | |
ADIJake | 0:85855ecd3257 | 2044 | WRITE_REG_FLOAT(hDevice, fHighThresholdLimit, |
ADIJake | 0:85855ecd3257 | 2045 | CORE_HIGH_THRESHOLD_LIMITn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 2046 | WRITE_REG_FLOAT(hDevice, fLowThresholdLimit, |
ADIJake | 0:85855ecd3257 | 2047 | CORE_LOW_THRESHOLD_LIMITn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 2048 | |
Vkadaba | 5:0728bde67bdb | 2049 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2050 | } |
ADIJake | 0:85855ecd3257 | 2051 | |
Vkadaba | 5:0728bde67bdb | 2052 | ADMW_RESULT admw1001_SetOffsetGain( |
Vkadaba | 5:0728bde67bdb | 2053 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 2054 | ADMW1001_CH_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 2055 | float32_t fOffsetAdjustment, |
ADIJake | 0:85855ecd3257 | 2056 | float32_t fGainAdjustment) |
ADIJake | 0:85855ecd3257 | 2057 | { |
ADIJake | 0:85855ecd3257 | 2058 | /* Replace with default values if NaNs are specified (or 0.0 for gain) */ |
ADIJake | 0:85855ecd3257 | 2059 | if (isnan(fGainAdjustment) || (fGainAdjustment == 0.0f)) |
ADIJake | 0:85855ecd3257 | 2060 | fGainAdjustment = 1.0f; |
ADIJake | 0:85855ecd3257 | 2061 | if (isnan(fOffsetAdjustment)) |
ADIJake | 0:85855ecd3257 | 2062 | fOffsetAdjustment = 0.0f; |
ADIJake | 0:85855ecd3257 | 2063 | |
ADIJake | 0:85855ecd3257 | 2064 | WRITE_REG_FLOAT(hDevice, fGainAdjustment, CORE_SENSOR_GAINn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 2065 | WRITE_REG_FLOAT(hDevice, fOffsetAdjustment, CORE_SENSOR_OFFSETn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 2066 | |
Vkadaba | 5:0728bde67bdb | 2067 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2068 | } |
ADIJake | 0:85855ecd3257 | 2069 | |
Vkadaba | 5:0728bde67bdb | 2070 | ADMW_RESULT admw1001_SetSensorParameter( |
Vkadaba | 5:0728bde67bdb | 2071 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 2072 | ADMW1001_CH_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 2073 | float32_t fSensorParam) |
ADIJake | 0:85855ecd3257 | 2074 | { |
ADIJake | 0:85855ecd3257 | 2075 | if (fSensorParam == 0.0f) |
ADIJake | 0:85855ecd3257 | 2076 | fSensorParam = NAN; |
ADIJake | 0:85855ecd3257 | 2077 | |
Vkadaba | 32:52445bef314d | 2078 | //WRITE_REG_FLOAT(hDevice, fSensorParam, CORE_SENSOR_PARAMETERn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 2079 | |
Vkadaba | 5:0728bde67bdb | 2080 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2081 | } |
ADIJake | 0:85855ecd3257 | 2082 | |
Vkadaba | 5:0728bde67bdb | 2083 | ADMW_RESULT admw1001_SetChannelSettlingTime( |
Vkadaba | 5:0728bde67bdb | 2084 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 2085 | ADMW1001_CH_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 2086 | uint32_t nSettlingTime) |
ADIJake | 0:85855ecd3257 | 2087 | { |
Vkadaba | 8:2f2775c34640 | 2088 | ADMW_CORE_Settling_Time_t settlingTimeReg; |
ADIJake | 0:85855ecd3257 | 2089 | |
Vkadaba | 23:bb685f35b08b | 2090 | if (nSettlingTime < (1 << 12)) { |
Vkadaba | 5:0728bde67bdb | 2091 | settlingTimeReg.Settling_Time_Units = CORE_SETTLING_TIME_MICROSECONDS; |
Vkadaba | 23:bb685f35b08b | 2092 | } else if (nSettlingTime < (1000 * (1 << 12))) { |
Vkadaba | 5:0728bde67bdb | 2093 | settlingTimeReg.Settling_Time_Units = CORE_SETTLING_TIME_MILLISECONDS; |
ADIJake | 0:85855ecd3257 | 2094 | nSettlingTime /= 1000; |
Vkadaba | 23:bb685f35b08b | 2095 | } else { |
Vkadaba | 5:0728bde67bdb | 2096 | settlingTimeReg.Settling_Time_Units = CORE_SETTLING_TIME_SECONDS; |
ADIJake | 0:85855ecd3257 | 2097 | nSettlingTime /= 1000000; |
ADIJake | 0:85855ecd3257 | 2098 | } |
ADIJake | 0:85855ecd3257 | 2099 | |
ADIJake | 0:85855ecd3257 | 2100 | CHECK_REG_FIELD_VAL(CORE_SETTLING_TIME_SETTLING_TIME, nSettlingTime); |
ADIJake | 0:85855ecd3257 | 2101 | settlingTimeReg.Settling_Time = nSettlingTime; |
ADIJake | 0:85855ecd3257 | 2102 | |
ADIJake | 0:85855ecd3257 | 2103 | WRITE_REG_U16(hDevice, settlingTimeReg.VALUE16, CORE_SETTLING_TIMEn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 2104 | |
Vkadaba | 5:0728bde67bdb | 2105 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2106 | } |
ADIJake | 0:85855ecd3257 | 2107 | |
Vkadaba | 5:0728bde67bdb | 2108 | ADMW_RESULT admw1001_SetChannelConfig( |
Vkadaba | 5:0728bde67bdb | 2109 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 2110 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 2111 | ADMW1001_CHANNEL_CONFIG *pChannelConfig) |
ADIJake | 0:85855ecd3257 | 2112 | { |
Vkadaba | 5:0728bde67bdb | 2113 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 2114 | |
Vkadaba | 23:bb685f35b08b | 2115 | if (! ADMW1001_CHANNEL_IS_VIRTUAL(eChannelId)) { |
Vkadaba | 5:0728bde67bdb | 2116 | eRet = admw1001_SetChannelCount(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 2117 | pChannelConfig->enableChannel ? |
Vkadaba | 23:bb685f35b08b | 2118 | pChannelConfig->measurementsPerCycle : 0); |
Vkadaba | 23:bb685f35b08b | 2119 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 2120 | ADMW_LOG_ERROR("Failed to set measurement count for channel %d", |
Vkadaba | 23:bb685f35b08b | 2121 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2122 | return eRet; |
ADIJake | 0:85855ecd3257 | 2123 | } |
ADIJake | 0:85855ecd3257 | 2124 | |
Vkadaba | 5:0728bde67bdb | 2125 | eRet = admw1001_SetChannelOptions(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 2126 | pChannelConfig->priority); |
Vkadaba | 23:bb685f35b08b | 2127 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 2128 | ADMW_LOG_ERROR("Failed to set priority for channel %d", |
Vkadaba | 23:bb685f35b08b | 2129 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2130 | return eRet; |
ADIJake | 0:85855ecd3257 | 2131 | } |
ADIJake | 0:85855ecd3257 | 2132 | |
ADIJake | 0:85855ecd3257 | 2133 | /* If the channel is not enabled, we can skip the following steps */ |
Vkadaba | 23:bb685f35b08b | 2134 | if (pChannelConfig->enableChannel) { |
Vkadaba | 5:0728bde67bdb | 2135 | eRet = admw1001_SetChannelSkipCount(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 2136 | pChannelConfig->cycleSkipCount); |
Vkadaba | 23:bb685f35b08b | 2137 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 2138 | ADMW_LOG_ERROR("Failed to set cycle skip count for channel %d", |
Vkadaba | 23:bb685f35b08b | 2139 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2140 | return eRet; |
ADIJake | 0:85855ecd3257 | 2141 | } |
ADIJake | 0:85855ecd3257 | 2142 | |
Vkadaba | 23:bb685f35b08b | 2143 | switch (eChannelId) { |
Vkadaba | 23:bb685f35b08b | 2144 | case ADMW1001_CH_ID_ANLG_1_UNIVERSAL: |
Vkadaba | 23:bb685f35b08b | 2145 | case ADMW1001_CH_ID_ANLG_2_UNIVERSAL: |
Vkadaba | 23:bb685f35b08b | 2146 | case ADMW1001_CH_ID_ANLG_1_DIFFERENTIAL: |
Vkadaba | 23:bb685f35b08b | 2147 | case ADMW1001_CH_ID_ANLG_2_DIFFERENTIAL: |
Vkadaba | 23:bb685f35b08b | 2148 | eRet = admw_SetAdcChannelConfig(hDevice, eChannelId, pChannelConfig); |
Vkadaba | 23:bb685f35b08b | 2149 | break; |
Vkadaba | 23:bb685f35b08b | 2150 | case ADMW1001_CH_ID_DIG_I2C_0: |
Vkadaba | 23:bb685f35b08b | 2151 | case ADMW1001_CH_ID_DIG_I2C_1: |
Vkadaba | 23:bb685f35b08b | 2152 | eRet = admw_SetI2cChannelConfig(hDevice, eChannelId, pChannelConfig); |
Vkadaba | 23:bb685f35b08b | 2153 | break; |
Vkadaba | 23:bb685f35b08b | 2154 | case ADMW1001_CH_ID_DIG_SPI_0: |
Vkadaba | 23:bb685f35b08b | 2155 | eRet = admw_SetSpiChannelConfig(hDevice, eChannelId, pChannelConfig); |
Vkadaba | 23:bb685f35b08b | 2156 | break; |
Vkadaba | 23:bb685f35b08b | 2157 | default: |
Vkadaba | 23:bb685f35b08b | 2158 | ADMW_LOG_ERROR("Invalid channel ID %d specified", eChannelId); |
Vkadaba | 32:52445bef314d | 2159 | eRet = ADMW_INVALID_PARAM; |
Vkadaba | 32:52445bef314d | 2160 | #if 0 |
Vkadaba | 32:52445bef314d | 2161 | /* when using i2c sensors there is an error ( dataformat->length=0) |
Vkadaba | 32:52445bef314d | 2162 | the code below catches this error and this causes further problems.*/ |
Vkadaba | 32:52445bef314d | 2163 | break; |
Vkadaba | 32:52445bef314d | 2164 | } |
Vkadaba | 32:52445bef314d | 2165 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 32:52445bef314d | 2166 | ADMW_LOG_ERROR("Failed to set config for channel %d", |
Vkadaba | 32:52445bef314d | 2167 | eChannelId); |
Vkadaba | 32:52445bef314d | 2168 | return eRet; |
Vkadaba | 32:52445bef314d | 2169 | #endif |
ADIJake | 0:85855ecd3257 | 2170 | } |
ADIJake | 0:85855ecd3257 | 2171 | |
Vkadaba | 5:0728bde67bdb | 2172 | eRet = admw1001_SetChannelSettlingTime(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 2173 | pChannelConfig->extraSettlingTime); |
Vkadaba | 23:bb685f35b08b | 2174 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 2175 | ADMW_LOG_ERROR("Failed to set settling time for channel %d", |
Vkadaba | 23:bb685f35b08b | 2176 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2177 | return eRet; |
ADIJake | 0:85855ecd3257 | 2178 | } |
ADIJake | 0:85855ecd3257 | 2179 | } |
ADIJake | 0:85855ecd3257 | 2180 | } |
ADIJake | 0:85855ecd3257 | 2181 | |
Vkadaba | 23:bb685f35b08b | 2182 | if (pChannelConfig->enableChannel) { |
ADIJake | 0:85855ecd3257 | 2183 | /* Threshold limits can be configured individually for virtual channels */ |
Vkadaba | 5:0728bde67bdb | 2184 | eRet = admw1001_SetChannelThresholdLimits(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 2185 | pChannelConfig->highThreshold, |
Vkadaba | 23:bb685f35b08b | 2186 | pChannelConfig->lowThreshold); |
Vkadaba | 23:bb685f35b08b | 2187 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 2188 | ADMW_LOG_ERROR("Failed to set threshold limits for channel %d", |
Vkadaba | 23:bb685f35b08b | 2189 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2190 | return eRet; |
ADIJake | 0:85855ecd3257 | 2191 | } |
ADIJake | 0:85855ecd3257 | 2192 | |
ADIJake | 0:85855ecd3257 | 2193 | /* Offset and gain can be configured individually for virtual channels */ |
Vkadaba | 5:0728bde67bdb | 2194 | eRet = admw1001_SetOffsetGain(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 2195 | pChannelConfig->offsetAdjustment, |
Vkadaba | 23:bb685f35b08b | 2196 | pChannelConfig->gainAdjustment); |
Vkadaba | 23:bb685f35b08b | 2197 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 2198 | ADMW_LOG_ERROR("Failed to set offset/gain for channel %d", |
Vkadaba | 23:bb685f35b08b | 2199 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2200 | return eRet; |
ADIJake | 0:85855ecd3257 | 2201 | } |
ADIJake | 0:85855ecd3257 | 2202 | |
ADIJake | 0:85855ecd3257 | 2203 | /* Set sensor specific parameter */ |
Vkadaba | 5:0728bde67bdb | 2204 | eRet = admw1001_SetSensorParameter(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 2205 | pChannelConfig->sensorParameter); |
Vkadaba | 23:bb685f35b08b | 2206 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 2207 | ADMW_LOG_ERROR("Failed to set sensor parameter for channel %d", |
Vkadaba | 23:bb685f35b08b | 2208 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2209 | return eRet; |
ADIJake | 0:85855ecd3257 | 2210 | } |
ADIJake | 0:85855ecd3257 | 2211 | } |
ADIJake | 0:85855ecd3257 | 2212 | |
Vkadaba | 5:0728bde67bdb | 2213 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2214 | } |
ADIJake | 0:85855ecd3257 | 2215 | |
Vkadaba | 5:0728bde67bdb | 2216 | ADMW_RESULT admw_SetConfig( |
Vkadaba | 5:0728bde67bdb | 2217 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 2218 | ADMW_CONFIG * const pConfig) |
ADIJake | 0:85855ecd3257 | 2219 | { |
Vkadaba | 5:0728bde67bdb | 2220 | ADMW1001_CONFIG *pDeviceConfig; |
Vkadaba | 5:0728bde67bdb | 2221 | ADMW_PRODUCT_ID productId; |
Vkadaba | 5:0728bde67bdb | 2222 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 2223 | |
Vkadaba | 23:bb685f35b08b | 2224 | if (pConfig->productId != ADMW_PRODUCT_ID_ADMW1001) { |
Vkadaba | 5:0728bde67bdb | 2225 | ADMW_LOG_ERROR("Configuration Product ID (0x%X) is not supported (0x%0X)", |
Vkadaba | 23:bb685f35b08b | 2226 | pConfig->productId, ADMW_PRODUCT_ID_ADMW1001); |
Vkadaba | 5:0728bde67bdb | 2227 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2228 | } |
Vkadaba | 23:bb685f35b08b | 2229 | |
Vkadaba | 23:bb685f35b08b | 2230 | if (!((pConfig->versionId.major==VERSIONID_MAJOR) && |
Vkadaba | 23:bb685f35b08b | 2231 | (pConfig->versionId.minor==VERSIONID_MINOR))) { |
Vkadaba | 23:bb685f35b08b | 2232 | ADMW_LOG_ERROR("Configuration Version ID (0x%X) is not supported", |
Vkadaba | 23:bb685f35b08b | 2233 | pConfig->versionId); |
Vkadaba | 6:9d393a9677f4 | 2234 | return ADMW_INVALID_PARAM; |
Vkadaba | 6:9d393a9677f4 | 2235 | } |
Vkadaba | 23:bb685f35b08b | 2236 | |
Vkadaba | 23:bb685f35b08b | 2237 | |
ADIJake | 0:85855ecd3257 | 2238 | /* Check that the actual Product ID is a match? */ |
Vkadaba | 5:0728bde67bdb | 2239 | eRet = admw_GetProductID(hDevice, &productId); |
Vkadaba | 23:bb685f35b08b | 2240 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 2241 | ADMW_LOG_ERROR("Failed to read device Product ID register"); |
ADIJake | 0:85855ecd3257 | 2242 | return eRet; |
ADIJake | 0:85855ecd3257 | 2243 | } |
Vkadaba | 23:bb685f35b08b | 2244 | if (pConfig->productId != productId) { |
Vkadaba | 5:0728bde67bdb | 2245 | ADMW_LOG_ERROR("Configuration Product ID (0x%X) does not match device (0x%0X)", |
Vkadaba | 8:2f2775c34640 | 2246 | pConfig->productId, productId); |
Vkadaba | 5:0728bde67bdb | 2247 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2248 | } |
ADIJake | 0:85855ecd3257 | 2249 | |
Vkadaba | 5:0728bde67bdb | 2250 | pDeviceConfig = &pConfig->admw1001; |
Vkadaba | 5:0728bde67bdb | 2251 | |
Vkadaba | 5:0728bde67bdb | 2252 | eRet = admw1001_SetPowerConfig(hDevice, &pDeviceConfig->power); |
Vkadaba | 23:bb685f35b08b | 2253 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 2254 | ADMW_LOG_ERROR("Failed to set power configuration"); |
ADIJake | 0:85855ecd3257 | 2255 | return eRet; |
ADIJake | 0:85855ecd3257 | 2256 | } |
ADIJake | 0:85855ecd3257 | 2257 | |
Vkadaba | 5:0728bde67bdb | 2258 | eRet = admw1001_SetMeasurementConfig(hDevice, &pDeviceConfig->measurement); |
Vkadaba | 23:bb685f35b08b | 2259 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 2260 | ADMW_LOG_ERROR("Failed to set measurement configuration"); |
ADIJake | 0:85855ecd3257 | 2261 | return eRet; |
ADIJake | 0:85855ecd3257 | 2262 | } |
ADIJake | 0:85855ecd3257 | 2263 | |
Vkadaba | 36:54e2418e7620 | 2264 | eRet = admw1001_SetDiagnosticsConfig(hDevice, &pDeviceConfig->diagnostics); |
Vkadaba | 41:df78b7d7b675 | 2265 | if (eRet) { |
Vkadaba | 36:54e2418e7620 | 2266 | ADMW_LOG_ERROR("Failed to set diagnostics configuration"); |
Vkadaba | 36:54e2418e7620 | 2267 | return eRet; |
Vkadaba | 36:54e2418e7620 | 2268 | } |
ADIJake | 0:85855ecd3257 | 2269 | |
Vkadaba | 8:2f2775c34640 | 2270 | for (ADMW1001_CH_ID id = ADMW1001_CH_ID_ANLG_1_UNIVERSAL; |
Vkadaba | 23:bb685f35b08b | 2271 | id < ADMW1001_MAX_CHANNELS; |
Vkadaba | 23:bb685f35b08b | 2272 | id++) { |
Vkadaba | 5:0728bde67bdb | 2273 | eRet = admw1001_SetChannelConfig(hDevice, id, |
Vkadaba | 23:bb685f35b08b | 2274 | &pDeviceConfig->channels[id]); |
Vkadaba | 23:bb685f35b08b | 2275 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 2276 | ADMW_LOG_ERROR("Failed to set channel %d configuration", id); |
ADIJake | 0:85855ecd3257 | 2277 | return eRet; |
ADIJake | 0:85855ecd3257 | 2278 | } |
ADIJake | 0:85855ecd3257 | 2279 | } |
ADIJake | 0:85855ecd3257 | 2280 | |
Vkadaba | 5:0728bde67bdb | 2281 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2282 | } |
ADIJake | 0:85855ecd3257 | 2283 | |
Vkadaba | 5:0728bde67bdb | 2284 | ADMW_RESULT admw1001_SetLutData( |
Vkadaba | 8:2f2775c34640 | 2285 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 2286 | ADMW1001_LUT * const pLutData) |
ADIJake | 0:85855ecd3257 | 2287 | { |
Vkadaba | 5:0728bde67bdb | 2288 | ADMW1001_LUT_HEADER *pLutHeader = &pLutData->header; |
Vkadaba | 8:2f2775c34640 | 2289 | ADMW1001_LUT_TABLE *pLutTable = pLutData->tables; |
ADIJake | 0:85855ecd3257 | 2290 | unsigned actualLength = 0; |
ADIJake | 0:85855ecd3257 | 2291 | |
Vkadaba | 23:bb685f35b08b | 2292 | if (pLutData->header.signature != ADMW_LUT_SIGNATURE) { |
Vkadaba | 5:0728bde67bdb | 2293 | ADMW_LOG_ERROR("LUT signature incorrect (expected 0x%X, actual 0x%X)", |
Vkadaba | 23:bb685f35b08b | 2294 | ADMW_LUT_SIGNATURE, pLutHeader->signature); |
Vkadaba | 5:0728bde67bdb | 2295 | return ADMW_INVALID_SIGNATURE; |
ADIJake | 0:85855ecd3257 | 2296 | } |
ADIJake | 0:85855ecd3257 | 2297 | |
Vkadaba | 23:bb685f35b08b | 2298 | for (unsigned i = 0; i < pLutHeader->numTables; i++) { |
Vkadaba | 5:0728bde67bdb | 2299 | ADMW1001_LUT_DESCRIPTOR *pDesc = &pLutTable->descriptor; |
Vkadaba | 5:0728bde67bdb | 2300 | ADMW1001_LUT_TABLE_DATA *pData = &pLutTable->data; |
ADIJake | 0:85855ecd3257 | 2301 | unsigned short calculatedCrc; |
ADIJake | 0:85855ecd3257 | 2302 | |
Vkadaba | 23:bb685f35b08b | 2303 | switch (pDesc->geometry) { |
Vkadaba | 23:bb685f35b08b | 2304 | case ADMW1001_LUT_GEOMETRY_COEFFS: |
Vkadaba | 23:bb685f35b08b | 2305 | switch (pDesc->equation) { |
Vkadaba | 23:bb685f35b08b | 2306 | case ADMW1001_LUT_EQUATION_POLYN: |
Vkadaba | 23:bb685f35b08b | 2307 | case ADMW1001_LUT_EQUATION_POLYNEXP: |
Vkadaba | 23:bb685f35b08b | 2308 | case ADMW1001_LUT_EQUATION_QUADRATIC: |
Vkadaba | 23:bb685f35b08b | 2309 | case ADMW1001_LUT_EQUATION_STEINHART: |
Vkadaba | 23:bb685f35b08b | 2310 | case ADMW1001_LUT_EQUATION_LOGARITHMIC: |
Vkadaba | 23:bb685f35b08b | 2311 | case ADMW1001_LUT_EQUATION_BIVARIATE_POLYN: |
Vkadaba | 23:bb685f35b08b | 2312 | break; |
Vkadaba | 23:bb685f35b08b | 2313 | default: |
Vkadaba | 23:bb685f35b08b | 2314 | ADMW_LOG_ERROR("Invalid equation %u specified for LUT table %u", |
Vkadaba | 23:bb685f35b08b | 2315 | pDesc->equation, i); |
Vkadaba | 23:bb685f35b08b | 2316 | return ADMW_INVALID_PARAM; |
Vkadaba | 23:bb685f35b08b | 2317 | } |
ADIJake | 0:85855ecd3257 | 2318 | break; |
Vkadaba | 23:bb685f35b08b | 2319 | case ADMW1001_LUT_GEOMETRY_NES_1D: |
Vkadaba | 23:bb685f35b08b | 2320 | case ADMW1001_LUT_GEOMETRY_NES_2D: |
Vkadaba | 23:bb685f35b08b | 2321 | case ADMW1001_LUT_GEOMETRY_ES_1D: |
Vkadaba | 23:bb685f35b08b | 2322 | case ADMW1001_LUT_GEOMETRY_ES_2D: |
Vkadaba | 23:bb685f35b08b | 2323 | if (pDesc->equation != ADMW1001_LUT_EQUATION_LUT) { |
Vkadaba | 5:0728bde67bdb | 2324 | ADMW_LOG_ERROR("Invalid equation %u specified for LUT table %u", |
Vkadaba | 23:bb685f35b08b | 2325 | pDesc->equation, i); |
Vkadaba | 5:0728bde67bdb | 2326 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2327 | } |
Vkadaba | 23:bb685f35b08b | 2328 | break; |
Vkadaba | 23:bb685f35b08b | 2329 | default: |
Vkadaba | 23:bb685f35b08b | 2330 | ADMW_LOG_ERROR("Invalid geometry %u specified for LUT table %u", |
Vkadaba | 23:bb685f35b08b | 2331 | pDesc->geometry, i); |
Vkadaba | 23:bb685f35b08b | 2332 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2333 | } |
ADIJake | 0:85855ecd3257 | 2334 | |
Vkadaba | 23:bb685f35b08b | 2335 | switch (pDesc->dataType) { |
Vkadaba | 23:bb685f35b08b | 2336 | case ADMW1001_LUT_DATA_TYPE_FLOAT32: |
Vkadaba | 23:bb685f35b08b | 2337 | case ADMW1001_LUT_DATA_TYPE_FLOAT64: |
Vkadaba | 23:bb685f35b08b | 2338 | break; |
Vkadaba | 23:bb685f35b08b | 2339 | default: |
Vkadaba | 23:bb685f35b08b | 2340 | ADMW_LOG_ERROR("Invalid vector format %u specified for LUT table %u", |
Vkadaba | 23:bb685f35b08b | 2341 | pDesc->dataType, i); |
Vkadaba | 23:bb685f35b08b | 2342 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2343 | } |
ADIJake | 0:85855ecd3257 | 2344 | |
Vkadaba | 5:0728bde67bdb | 2345 | calculatedCrc = admw_crc16_ccitt(pData, pDesc->length); |
Vkadaba | 23:bb685f35b08b | 2346 | if (calculatedCrc != pDesc->crc16) { |
Vkadaba | 5:0728bde67bdb | 2347 | ADMW_LOG_ERROR("CRC validation failed on LUT table %u (expected 0x%04X, actual 0x%04X)", |
Vkadaba | 23:bb685f35b08b | 2348 | i, pDesc->crc16, calculatedCrc); |
Vkadaba | 5:0728bde67bdb | 2349 | return ADMW_CRC_ERROR; |
ADIJake | 0:85855ecd3257 | 2350 | } |
ADIJake | 0:85855ecd3257 | 2351 | |
ADIJake | 0:85855ecd3257 | 2352 | actualLength += sizeof(*pDesc) + pDesc->length; |
ADIJake | 0:85855ecd3257 | 2353 | |
ADIJake | 0:85855ecd3257 | 2354 | /* Move to the next look-up table */ |
Vkadaba | 5:0728bde67bdb | 2355 | pLutTable = (ADMW1001_LUT_TABLE *)((uint8_t *)pLutTable + sizeof(*pDesc) + pDesc->length); |
ADIJake | 0:85855ecd3257 | 2356 | } |
ADIJake | 0:85855ecd3257 | 2357 | |
Vkadaba | 23:bb685f35b08b | 2358 | if (actualLength != pLutHeader->totalLength) { |
Vkadaba | 5:0728bde67bdb | 2359 | ADMW_LOG_ERROR("LUT table length mismatch (expected %u, actual %u)", |
Vkadaba | 23:bb685f35b08b | 2360 | pLutHeader->totalLength, actualLength); |
Vkadaba | 5:0728bde67bdb | 2361 | return ADMW_WRONG_SIZE; |
ADIJake | 0:85855ecd3257 | 2362 | } |
ADIJake | 0:85855ecd3257 | 2363 | |
Vkadaba | 23:bb685f35b08b | 2364 | if (sizeof(*pLutHeader) + pLutHeader->totalLength > ADMW_LUT_MAX_SIZE) { |
Vkadaba | 5:0728bde67bdb | 2365 | ADMW_LOG_ERROR("Maximum LUT table length (%u bytes) exceeded", |
Vkadaba | 23:bb685f35b08b | 2366 | ADMW_LUT_MAX_SIZE); |
Vkadaba | 5:0728bde67bdb | 2367 | return ADMW_WRONG_SIZE; |
ADIJake | 0:85855ecd3257 | 2368 | } |
ADIJake | 0:85855ecd3257 | 2369 | |
ADIJake | 0:85855ecd3257 | 2370 | /* Write the LUT data to the device */ |
ADIJake | 0:85855ecd3257 | 2371 | unsigned lutSize = sizeof(*pLutHeader) + pLutHeader->totalLength; |
ADIJake | 0:85855ecd3257 | 2372 | WRITE_REG_U16(hDevice, 0, CORE_LUT_OFFSET); |
ADIJake | 0:85855ecd3257 | 2373 | WRITE_REG_U8_ARRAY(hDevice, (uint8_t *)pLutData, lutSize, CORE_LUT_DATA); |
ADIJake | 0:85855ecd3257 | 2374 | |
Vkadaba | 5:0728bde67bdb | 2375 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2376 | } |
ADIJake | 0:85855ecd3257 | 2377 | |
Vkadaba | 5:0728bde67bdb | 2378 | ADMW_RESULT admw1001_SetLutDataRaw( |
Vkadaba | 5:0728bde67bdb | 2379 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 2380 | ADMW1001_LUT_RAW * const pLutData) |
ADIJake | 0:85855ecd3257 | 2381 | { |
Vkadaba | 5:0728bde67bdb | 2382 | return admw1001_SetLutData(hDevice, |
Vkadaba | 23:bb685f35b08b | 2383 | (ADMW1001_LUT *)pLutData); |
ADIJake | 0:85855ecd3257 | 2384 | } |
ADIJake | 0:85855ecd3257 | 2385 | |
Vkadaba | 5:0728bde67bdb | 2386 | static ADMW_RESULT getLutTableSize( |
Vkadaba | 5:0728bde67bdb | 2387 | ADMW1001_LUT_DESCRIPTOR * const pDesc, |
Vkadaba | 5:0728bde67bdb | 2388 | ADMW1001_LUT_TABLE_DATA * const pData, |
ADIJake | 0:85855ecd3257 | 2389 | unsigned *pLength) |
ADIJake | 0:85855ecd3257 | 2390 | { |
Vkadaba | 23:bb685f35b08b | 2391 | switch (pDesc->geometry) { |
Vkadaba | 23:bb685f35b08b | 2392 | case ADMW1001_LUT_GEOMETRY_COEFFS: |
Vkadaba | 23:bb685f35b08b | 2393 | if (pDesc->equation == ADMW1001_LUT_EQUATION_BIVARIATE_POLYN) |
Vkadaba | 23:bb685f35b08b | 2394 | *pLength = ADMW1001_LUT_2D_POLYN_COEFF_LIST_SIZE(pData->coeffList2d); |
Vkadaba | 23:bb685f35b08b | 2395 | else |
Vkadaba | 23:bb685f35b08b | 2396 | *pLength = ADMW1001_LUT_COEFF_LIST_SIZE(pData->coeffList); |
Vkadaba | 23:bb685f35b08b | 2397 | break; |
Vkadaba | 23:bb685f35b08b | 2398 | case ADMW1001_LUT_GEOMETRY_NES_1D: |
Vkadaba | 23:bb685f35b08b | 2399 | *pLength = ADMW1001_LUT_1D_NES_SIZE(pData->lut1dNes); |
Vkadaba | 23:bb685f35b08b | 2400 | break; |
Vkadaba | 23:bb685f35b08b | 2401 | case ADMW1001_LUT_GEOMETRY_NES_2D: |
Vkadaba | 23:bb685f35b08b | 2402 | *pLength = ADMW1001_LUT_2D_NES_SIZE(pData->lut2dNes); |
Vkadaba | 23:bb685f35b08b | 2403 | break; |
Vkadaba | 23:bb685f35b08b | 2404 | case ADMW1001_LUT_GEOMETRY_ES_1D: |
Vkadaba | 23:bb685f35b08b | 2405 | *pLength = ADMW1001_LUT_1D_ES_SIZE(pData->lut1dEs); |
Vkadaba | 23:bb685f35b08b | 2406 | break; |
Vkadaba | 23:bb685f35b08b | 2407 | case ADMW1001_LUT_GEOMETRY_ES_2D: |
Vkadaba | 23:bb685f35b08b | 2408 | *pLength = ADMW1001_LUT_2D_ES_SIZE(pData->lut2dEs); |
Vkadaba | 23:bb685f35b08b | 2409 | break; |
Vkadaba | 23:bb685f35b08b | 2410 | default: |
Vkadaba | 23:bb685f35b08b | 2411 | ADMW_LOG_ERROR("Invalid LUT table geometry %d specified\r\n", |
Vkadaba | 23:bb685f35b08b | 2412 | pDesc->geometry); |
Vkadaba | 23:bb685f35b08b | 2413 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2414 | } |
ADIJake | 0:85855ecd3257 | 2415 | |
Vkadaba | 5:0728bde67bdb | 2416 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2417 | } |
ADIJake | 0:85855ecd3257 | 2418 | |
Vkadaba | 5:0728bde67bdb | 2419 | ADMW_RESULT admw1001_AssembleLutData( |
Vkadaba | 5:0728bde67bdb | 2420 | ADMW1001_LUT * pLutBuffer, |
ADIJake | 0:85855ecd3257 | 2421 | unsigned nLutBufferSize, |
ADIJake | 0:85855ecd3257 | 2422 | unsigned const nNumTables, |
Vkadaba | 5:0728bde67bdb | 2423 | ADMW1001_LUT_DESCRIPTOR * const ppDesc[], |
Vkadaba | 5:0728bde67bdb | 2424 | ADMW1001_LUT_TABLE_DATA * const ppData[]) |
ADIJake | 0:85855ecd3257 | 2425 | { |
Vkadaba | 5:0728bde67bdb | 2426 | ADMW1001_LUT_HEADER *pHdr = &pLutBuffer->header; |
ADIJake | 0:85855ecd3257 | 2427 | uint8_t *pLutTableData = (uint8_t *)pLutBuffer + sizeof(*pHdr); |
ADIJake | 0:85855ecd3257 | 2428 | |
Vkadaba | 23:bb685f35b08b | 2429 | if (sizeof(*pHdr) > nLutBufferSize) { |
Vkadaba | 5:0728bde67bdb | 2430 | ADMW_LOG_ERROR("Insufficient LUT buffer size provided"); |
Vkadaba | 5:0728bde67bdb | 2431 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2432 | } |
ADIJake | 0:85855ecd3257 | 2433 | |
ADIJake | 0:85855ecd3257 | 2434 | /* First initialise the top-level header */ |
Vkadaba | 5:0728bde67bdb | 2435 | pHdr->signature = ADMW_LUT_SIGNATURE; |
ADIJake | 0:85855ecd3257 | 2436 | pHdr->version.major = 1; |
ADIJake | 0:85855ecd3257 | 2437 | pHdr->version.minor = 0; |
ADIJake | 0:85855ecd3257 | 2438 | pHdr->numTables = 0; |
ADIJake | 0:85855ecd3257 | 2439 | pHdr->totalLength = 0; |
ADIJake | 0:85855ecd3257 | 2440 | |
ADIJake | 0:85855ecd3257 | 2441 | /* |
ADIJake | 0:85855ecd3257 | 2442 | * Walk through the list of table pointers provided, appending the table |
ADIJake | 0:85855ecd3257 | 2443 | * descriptor+data from each one to the provided LUT buffer |
ADIJake | 0:85855ecd3257 | 2444 | */ |
Vkadaba | 23:bb685f35b08b | 2445 | for (unsigned i = 0; i < nNumTables; i++) { |
Vkadaba | 5:0728bde67bdb | 2446 | ADMW1001_LUT_DESCRIPTOR * const pDesc = ppDesc[i]; |
Vkadaba | 5:0728bde67bdb | 2447 | ADMW1001_LUT_TABLE_DATA * const pData = ppData[i]; |
Vkadaba | 5:0728bde67bdb | 2448 | ADMW_RESULT res; |
ADIJake | 0:85855ecd3257 | 2449 | unsigned dataLength = 0; |
ADIJake | 0:85855ecd3257 | 2450 | |
ADIJake | 0:85855ecd3257 | 2451 | /* Calculate the length of the table data */ |
ADIJake | 0:85855ecd3257 | 2452 | res = getLutTableSize(pDesc, pData, &dataLength); |
Vkadaba | 5:0728bde67bdb | 2453 | if (res != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2454 | return res; |
ADIJake | 0:85855ecd3257 | 2455 | |
ADIJake | 0:85855ecd3257 | 2456 | /* Fill in the table descriptor length and CRC fields */ |
ADIJake | 0:85855ecd3257 | 2457 | pDesc->length = dataLength; |
Vkadaba | 5:0728bde67bdb | 2458 | pDesc->crc16 = admw_crc16_ccitt(pData, dataLength); |
ADIJake | 0:85855ecd3257 | 2459 | |
Vkadaba | 23:bb685f35b08b | 2460 | if ((sizeof(*pHdr) + pHdr->totalLength + sizeof(*pDesc) + dataLength) > nLutBufferSize) { |
Vkadaba | 5:0728bde67bdb | 2461 | ADMW_LOG_ERROR("Insufficient LUT buffer size provided"); |
Vkadaba | 5:0728bde67bdb | 2462 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2463 | } |
ADIJake | 0:85855ecd3257 | 2464 | |
ADIJake | 0:85855ecd3257 | 2465 | /* Append the table to the LUT buffer (desc + data) */ |
ADIJake | 0:85855ecd3257 | 2466 | memcpy(pLutTableData + pHdr->totalLength, pDesc, sizeof(*pDesc)); |
ADIJake | 0:85855ecd3257 | 2467 | pHdr->totalLength += sizeof(*pDesc); |
ADIJake | 0:85855ecd3257 | 2468 | memcpy(pLutTableData + pHdr->totalLength, pData, dataLength); |
ADIJake | 0:85855ecd3257 | 2469 | pHdr->totalLength += dataLength; |
ADIJake | 0:85855ecd3257 | 2470 | |
ADIJake | 0:85855ecd3257 | 2471 | pHdr->numTables++; |
ADIJake | 0:85855ecd3257 | 2472 | } |
ADIJake | 0:85855ecd3257 | 2473 | |
Vkadaba | 5:0728bde67bdb | 2474 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2475 | } |