Vybhav Kadaba
/
EV-PRO-MW1001_Development_code_cleaup
Removed unwanted enums and unused functions
src/admw_1001.c@6:9d393a9677f4, 2019-06-15 (annotated)
- Committer:
- Vkadaba
- Date:
- Sat Jun 15 14:30:49 2019 +0000
- Revision:
- 6:9d393a9677f4
- Parent:
- 5:0728bde67bdb
- Child:
- 8:2f2775c34640
Register map is updated and sensor config files are modified
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ADIJake | 0:85855ecd3257 | 1 | /* |
ADIJake | 0:85855ecd3257 | 2 | Copyright 2018 (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 | Copyright 2017 (c) Analog Devices, Inc. |
ADIJake | 0:85855ecd3257 | 38 | |
ADIJake | 0:85855ecd3257 | 39 | All rights reserved. |
ADIJake | 0:85855ecd3257 | 40 | |
ADIJake | 0:85855ecd3257 | 41 | Redistribution and use in source and binary forms, with or without |
ADIJake | 0:85855ecd3257 | 42 | modification, are permitted provided that the following conditions are met: |
ADIJake | 0:85855ecd3257 | 43 | - Redistributions of source code must retain the above copyright |
ADIJake | 0:85855ecd3257 | 44 | notice, this list of conditions and the following disclaimer. |
ADIJake | 0:85855ecd3257 | 45 | - Redistributions in binary form must reproduce the above copyright |
ADIJake | 0:85855ecd3257 | 46 | notice, this list of conditions and the following disclaimer in |
ADIJake | 0:85855ecd3257 | 47 | the documentation and/or other materials provided with the |
ADIJake | 0:85855ecd3257 | 48 | distribution. |
ADIJake | 0:85855ecd3257 | 49 | - Neither the name of Analog Devices, Inc. nor the names of its |
ADIJake | 0:85855ecd3257 | 50 | contributors may be used to endorse or promote products derived |
ADIJake | 0:85855ecd3257 | 51 | from this software without specific prior written permission. |
ADIJake | 0:85855ecd3257 | 52 | - The use of this software may or may not infringe the patent rights |
ADIJake | 0:85855ecd3257 | 53 | of one or more patent holders. This license does not release you |
ADIJake | 0:85855ecd3257 | 54 | from the requirement that you obtain separate licenses from these |
ADIJake | 0:85855ecd3257 | 55 | patent holders to use this software. |
ADIJake | 0:85855ecd3257 | 56 | - Use of the software either in source or binary form, must be run |
ADIJake | 0:85855ecd3257 | 57 | on or directly connected to an Analog Devices Inc. component. |
ADIJake | 0:85855ecd3257 | 58 | |
ADIJake | 0:85855ecd3257 | 59 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
ADIJake | 0:85855ecd3257 | 60 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
ADIJake | 0:85855ecd3257 | 61 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
ADIJake | 0:85855ecd3257 | 62 | IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
ADIJake | 0:85855ecd3257 | 63 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
ADIJake | 0:85855ecd3257 | 64 | LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
ADIJake | 0:85855ecd3257 | 65 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
ADIJake | 0:85855ecd3257 | 66 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
ADIJake | 0:85855ecd3257 | 67 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
ADIJake | 0:85855ecd3257 | 68 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
ADIJake | 0:85855ecd3257 | 69 | * |
ADIJake | 0:85855ecd3257 | 70 | *****************************************************************************/ |
ADIJake | 0:85855ecd3257 | 71 | |
ADIJake | 0:85855ecd3257 | 72 | /*! |
ADIJake | 0:85855ecd3257 | 73 | ****************************************************************************** |
ADIJake | 0:85855ecd3257 | 74 | * @file: |
Vkadaba | 5:0728bde67bdb | 75 | * @brief: ADMW API implementation for ADSNS1000 |
ADIJake | 0:85855ecd3257 | 76 | *----------------------------------------------------------------------------- |
ADIJake | 0:85855ecd3257 | 77 | */ |
ADIJake | 0:85855ecd3257 | 78 | |
ADIJake | 0:85855ecd3257 | 79 | #include <float.h> |
ADIJake | 0:85855ecd3257 | 80 | #include <math.h> |
ADIJake | 0:85855ecd3257 | 81 | #include <string.h> |
ADIJake | 0:85855ecd3257 | 82 | |
Vkadaba | 5:0728bde67bdb | 83 | #include "admw_platform.h" |
Vkadaba | 5:0728bde67bdb | 84 | #include "admw_api.h" |
Vkadaba | 5:0728bde67bdb | 85 | #include "admw1001/admw1001_api.h" |
Vkadaba | 5:0728bde67bdb | 86 | |
Vkadaba | 5:0728bde67bdb | 87 | #include "admw1001/ADMW1001_REGISTERS_typedefs.h" |
Vkadaba | 5:0728bde67bdb | 88 | #include "admw1001/ADMW1001_REGISTERS.h" |
Vkadaba | 5:0728bde67bdb | 89 | #include "admw1001/admw1001_lut_data.h" |
Vkadaba | 5:0728bde67bdb | 90 | #include "admw1001/admw1001_host_comms.h" |
ADIJake | 0:85855ecd3257 | 91 | |
ADIJake | 0:85855ecd3257 | 92 | #include "crc16.h" |
Vkadaba | 6:9d393a9677f4 | 93 | #define VERSIONID_MAJOR 1 |
Vkadaba | 6:9d393a9677f4 | 94 | #define VERSIONID_MINOR 7 |
ADIJake | 0:85855ecd3257 | 95 | |
ADIJake | 0:85855ecd3257 | 96 | uint32_t getDataCnt = 0; |
ADIJake | 0:85855ecd3257 | 97 | |
ADIJake | 0:85855ecd3257 | 98 | /* |
ADIJake | 0:85855ecd3257 | 99 | * The following macros are used to encapsulate the register access code |
ADIJake | 0:85855ecd3257 | 100 | * to improve readability in the functions further below in this file |
ADIJake | 0:85855ecd3257 | 101 | */ |
ADIJake | 0:85855ecd3257 | 102 | #define STRINGIFY(name) #name |
ADIJake | 0:85855ecd3257 | 103 | |
ADIJake | 0:85855ecd3257 | 104 | /* Expand the full name of the reset value macro for the specified register */ |
Vkadaba | 5:0728bde67bdb | 105 | #define REG_RESET_VAL(_name) REG_##_name##_RESET |
ADIJake | 0:85855ecd3257 | 106 | |
ADIJake | 0:85855ecd3257 | 107 | /* Checks if a value is outside the bounds of the specified register field */ |
ADIJake | 0:85855ecd3257 | 108 | #define CHECK_REG_FIELD_VAL(_field, _val) \ |
ADIJake | 0:85855ecd3257 | 109 | do { \ |
Vkadaba | 6:9d393a9677f4 | 110 | uint32_t _mask = BITM_##_field; \ |
Vkadaba | 6:9d393a9677f4 | 111 | uint32_t _shift = BITP_##_field; \ |
ADIJake | 0:85855ecd3257 | 112 | if ((((_val) << _shift) & ~(_mask)) != 0) { \ |
Vkadaba | 6:9d393a9677f4 | 113 | ADMW_LOG_ERROR("Value 0x%08X invalid for register field %s",\ |
ADIJake | 0:85855ecd3257 | 114 | (uint32_t)(_val), \ |
Vkadaba | 6:9d393a9677f4 | 115 | STRINGIFY(ADMW_##_field)); \ |
Vkadaba | 6:9d393a9677f4 | 116 | return ADMW_INVALID_PARAM; \ |
ADIJake | 0:85855ecd3257 | 117 | } \ |
ADIJake | 0:85855ecd3257 | 118 | } while(false) |
ADIJake | 0:85855ecd3257 | 119 | |
ADIJake | 0:85855ecd3257 | 120 | /* |
ADIJake | 0:85855ecd3257 | 121 | * Encapsulates the write to a specified register |
ADIJake | 0:85855ecd3257 | 122 | * NOTE - this will cause the calling function to return on error |
ADIJake | 0:85855ecd3257 | 123 | */ |
ADIJake | 0:85855ecd3257 | 124 | #define WRITE_REG(_hdev, _val, _name, _type) \ |
ADIJake | 0:85855ecd3257 | 125 | do { \ |
Vkadaba | 6:9d393a9677f4 | 126 | ADMW_RESULT _res; \ |
ADIJake | 0:85855ecd3257 | 127 | _type _regval = _val; \ |
Vkadaba | 6:9d393a9677f4 | 128 | _res = admw1001_WriteRegister((_hdev), \ |
Vkadaba | 6:9d393a9677f4 | 129 | REG_##_name, \ |
ADIJake | 0:85855ecd3257 | 130 | &_regval, sizeof(_regval)); \ |
Vkadaba | 6:9d393a9677f4 | 131 | if (_res != ADMW_SUCCESS) \ |
ADIJake | 0:85855ecd3257 | 132 | return _res; \ |
ADIJake | 0:85855ecd3257 | 133 | } while(false) |
ADIJake | 0:85855ecd3257 | 134 | |
ADIJake | 0:85855ecd3257 | 135 | /* Wrapper macro to write a value to a uint32_t register */ |
Vkadaba | 6:9d393a9677f4 | 136 | #define WRITE_REG_U32(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 137 | WRITE_REG(_hdev, _val, _name, uint32_t) |
ADIJake | 0:85855ecd3257 | 138 | /* Wrapper macro to write a value to a uint16_t register */ |
Vkadaba | 6:9d393a9677f4 | 139 | #define WRITE_REG_U16(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 140 | WRITE_REG(_hdev, _val, _name, uint16_t) |
ADIJake | 0:85855ecd3257 | 141 | /* Wrapper macro to write a value to a uint8_t register */ |
Vkadaba | 6:9d393a9677f4 | 142 | #define WRITE_REG_U8(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 143 | WRITE_REG(_hdev, _val, _name, uint8_t) |
ADIJake | 0:85855ecd3257 | 144 | /* Wrapper macro to write a value to a float32_t register */ |
Vkadaba | 6:9d393a9677f4 | 145 | #define WRITE_REG_FLOAT(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 146 | WRITE_REG(_hdev, _val, _name, float32_t) |
ADIJake | 0:85855ecd3257 | 147 | |
ADIJake | 0:85855ecd3257 | 148 | /* |
ADIJake | 0:85855ecd3257 | 149 | * Encapsulates the read from a specified register |
ADIJake | 0:85855ecd3257 | 150 | * NOTE - this will cause the calling function to return on error |
ADIJake | 0:85855ecd3257 | 151 | */ |
ADIJake | 0:85855ecd3257 | 152 | #define READ_REG(_hdev, _val, _name, _type) \ |
ADIJake | 0:85855ecd3257 | 153 | do { \ |
Vkadaba | 6:9d393a9677f4 | 154 | ADMW_RESULT _res; \ |
ADIJake | 0:85855ecd3257 | 155 | _type _regval; \ |
Vkadaba | 6:9d393a9677f4 | 156 | _res = admw1001_ReadRegister((_hdev), \ |
Vkadaba | 6:9d393a9677f4 | 157 | REG_##_name, \ |
ADIJake | 0:85855ecd3257 | 158 | &_regval, sizeof(_regval)); \ |
Vkadaba | 6:9d393a9677f4 | 159 | if (_res != ADMW_SUCCESS) \ |
ADIJake | 0:85855ecd3257 | 160 | return _res; \ |
ADIJake | 0:85855ecd3257 | 161 | _val = _regval; \ |
ADIJake | 0:85855ecd3257 | 162 | } while(false) |
ADIJake | 0:85855ecd3257 | 163 | |
ADIJake | 0:85855ecd3257 | 164 | /* Wrapper macro to read a value from a uint32_t register */ |
Vkadaba | 6:9d393a9677f4 | 165 | #define READ_REG_U32(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 166 | READ_REG(_hdev, _val, _name, uint32_t) |
ADIJake | 0:85855ecd3257 | 167 | /* Wrapper macro to read a value from a uint16_t register */ |
Vkadaba | 6:9d393a9677f4 | 168 | #define READ_REG_U16(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 169 | READ_REG(_hdev, _val, _name, uint16_t) |
ADIJake | 0:85855ecd3257 | 170 | /* Wrapper macro to read a value from a uint8_t register */ |
Vkadaba | 6:9d393a9677f4 | 171 | #define READ_REG_U8(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 172 | READ_REG(_hdev, _val, _name, uint8_t) |
ADIJake | 0:85855ecd3257 | 173 | /* Wrapper macro to read a value from a float32_t register */ |
Vkadaba | 6:9d393a9677f4 | 174 | #define READ_REG_FLOAT(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 175 | READ_REG(_hdev, _val, _name, float32_t) |
ADIJake | 0:85855ecd3257 | 176 | |
ADIJake | 0:85855ecd3257 | 177 | /* |
ADIJake | 0:85855ecd3257 | 178 | * Wrapper macro to write an array of values to a uint8_t register |
ADIJake | 0:85855ecd3257 | 179 | * NOTE - this is intended only for writing to a keyhole data register |
ADIJake | 0:85855ecd3257 | 180 | */ |
ADIJake | 0:85855ecd3257 | 181 | #define WRITE_REG_U8_ARRAY(_hdev, _arr, _len, _name) \ |
Vkadaba | 6:9d393a9677f4 | 182 | do { \ |
Vkadaba | 6:9d393a9677f4 | 183 | ADMW_RESULT _res; \ |
Vkadaba | 6:9d393a9677f4 | 184 | _res = admw1001_WriteRegister(_hdev, \ |
Vkadaba | 6:9d393a9677f4 | 185 | REG_##_name, \ |
Vkadaba | 6:9d393a9677f4 | 186 | _arr, _len); \ |
Vkadaba | 6:9d393a9677f4 | 187 | if (_res != ADMW_SUCCESS) \ |
Vkadaba | 6:9d393a9677f4 | 188 | return _res; \ |
ADIJake | 0:85855ecd3257 | 189 | } while(false) |
ADIJake | 0:85855ecd3257 | 190 | |
ADIJake | 0:85855ecd3257 | 191 | /* |
ADIJake | 0:85855ecd3257 | 192 | * Wrapper macro to read an array of values from a uint8_t register |
ADIJake | 0:85855ecd3257 | 193 | * NOTE - this is intended only for reading from a keyhole data register |
ADIJake | 0:85855ecd3257 | 194 | */ |
Vkadaba | 6:9d393a9677f4 | 195 | #define READ_REG_U8_ARRAY(_hdev, _arr, _len, _name) \ |
Vkadaba | 6:9d393a9677f4 | 196 | do { \ |
Vkadaba | 6:9d393a9677f4 | 197 | ADMW_RESULT _res; \ |
Vkadaba | 6:9d393a9677f4 | 198 | _res = admw1001_ReadRegister((_hdev), \ |
Vkadaba | 6:9d393a9677f4 | 199 | REG##_name, \ |
Vkadaba | 6:9d393a9677f4 | 200 | _arr, _len); \ |
Vkadaba | 6:9d393a9677f4 | 201 | if (_res != ADMW_SUCCESS) \ |
Vkadaba | 6:9d393a9677f4 | 202 | return _res; \ |
ADIJake | 0:85855ecd3257 | 203 | } while(false) |
ADIJake | 0:85855ecd3257 | 204 | |
Vkadaba | 6:9d393a9677f4 | 205 | #define ADMW1001_CHANNEL_IS_ADC(c) \ |
Vkadaba | 6:9d393a9677f4 | 206 | ((c) >= ADMW1001_CHANNEL_ID_ANALOG_1_UNIVERSAL && (c) <= ADMW1001_CHANNEL_ID_ANALOG_2_DIFFERENTIAL) |
Vkadaba | 6:9d393a9677f4 | 207 | |
Vkadaba | 6:9d393a9677f4 | 208 | #define ADMW1001_CHANNEL_IS_ADC_CJC(c) \ |
Vkadaba | 6:9d393a9677f4 | 209 | ((c) >= ADMW1001_CHANNEL_ID_ANALOG_1_UNIVERSAL && (c) <= ADMW1001_CHANNEL_ID_ANALOG_2_UNIVERSAL) |
Vkadaba | 6:9d393a9677f4 | 210 | |
Vkadaba | 6:9d393a9677f4 | 211 | #define ADMW1001_CHANNEL_IS_ADC_SENSOR(c) \ |
Vkadaba | 6:9d393a9677f4 | 212 | ((c) >= ADMW1001_CHANNEL_ID_ANALOG_1_UNIVERSAL && (c) <= ADMW1001_CHANNEL_ID_ANALOG_2_UNIVERSAL) |
Vkadaba | 6:9d393a9677f4 | 213 | |
Vkadaba | 6:9d393a9677f4 | 214 | #define ADMW1001_CHANNEL_IS_ADC_VOLTAGE(c) \ |
Vkadaba | 6:9d393a9677f4 | 215 | ((c) == ADMW1001_CHANNEL_ID_ANALOG_1_DIFFERENTIAL || ADMW1001_CHANNEL_ID_ANALOG_2_DIFFERENTIAL) |
Vkadaba | 6:9d393a9677f4 | 216 | |
Vkadaba | 6:9d393a9677f4 | 217 | #define ADMW1001_CHANNEL_IS_ADC_CURRENT(c) \ |
Vkadaba | 6:9d393a9677f4 | 218 | ((c) == ADMW1001_CHANNEL_ID_ANALOG_1_UNIVERSAL || (c) == ADMW1001_CHANNEL_ID_ANALOG_2_UNIVERSAL) |
Vkadaba | 6:9d393a9677f4 | 219 | |
Vkadaba | 6:9d393a9677f4 | 220 | #define ADMW1001_CHANNEL_IS_VIRTUAL(c) \ |
Vkadaba | 5:0728bde67bdb | 221 | ((c) == ADMW1001_CHANNEL_ID_SPI_1 || (c) == ADMW1001_CHANNEL_ID_SPI_2) |
ADIJake | 0:85855ecd3257 | 222 | |
ADIJake | 0:85855ecd3257 | 223 | typedef struct |
ADIJake | 0:85855ecd3257 | 224 | { |
ADIJake | 0:85855ecd3257 | 225 | unsigned nDeviceIndex; |
Vkadaba | 5:0728bde67bdb | 226 | ADMW_SPI_HANDLE hSpi; |
Vkadaba | 5:0728bde67bdb | 227 | ADMW_GPIO_HANDLE hGpio; |
Vkadaba | 5:0728bde67bdb | 228 | } ADMW_DEVICE_CONTEXT; |
Vkadaba | 5:0728bde67bdb | 229 | |
Vkadaba | 5:0728bde67bdb | 230 | static ADMW_DEVICE_CONTEXT gDeviceCtx[ADMW_PLATFORM_MAX_DEVICES]; |
ADIJake | 0:85855ecd3257 | 231 | |
ADIJake | 0:85855ecd3257 | 232 | /* |
Vkadaba | 5:0728bde67bdb | 233 | * Open an ADMW device instance. |
ADIJake | 0:85855ecd3257 | 234 | */ |
Vkadaba | 5:0728bde67bdb | 235 | ADMW_RESULT admw_Open( |
ADIJake | 0:85855ecd3257 | 236 | unsigned const nDeviceIndex, |
Vkadaba | 5:0728bde67bdb | 237 | ADMW_CONNECTION * const pConnectionInfo, |
Vkadaba | 5:0728bde67bdb | 238 | ADMW_DEVICE_HANDLE * const phDevice) |
ADIJake | 0:85855ecd3257 | 239 | { |
Vkadaba | 5:0728bde67bdb | 240 | ADMW_DEVICE_CONTEXT *pCtx; |
Vkadaba | 5:0728bde67bdb | 241 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 242 | |
Vkadaba | 5:0728bde67bdb | 243 | if (nDeviceIndex >= ADMW_PLATFORM_MAX_DEVICES) |
Vkadaba | 5:0728bde67bdb | 244 | return ADMW_INVALID_DEVICE_NUM; |
ADIJake | 0:85855ecd3257 | 245 | |
ADIJake | 0:85855ecd3257 | 246 | pCtx = &gDeviceCtx[nDeviceIndex]; |
ADIJake | 0:85855ecd3257 | 247 | pCtx->nDeviceIndex = nDeviceIndex; |
ADIJake | 0:85855ecd3257 | 248 | |
Vkadaba | 5:0728bde67bdb | 249 | eRet = admw_LogOpen(&pConnectionInfo->log); |
Vkadaba | 5:0728bde67bdb | 250 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 251 | return eRet; |
ADIJake | 0:85855ecd3257 | 252 | |
Vkadaba | 5:0728bde67bdb | 253 | eRet = admw_GpioOpen(&pConnectionInfo->gpio, &pCtx->hGpio); |
Vkadaba | 5:0728bde67bdb | 254 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 255 | return eRet; |
ADIJake | 0:85855ecd3257 | 256 | |
Vkadaba | 5:0728bde67bdb | 257 | eRet = admw_SpiOpen(&pConnectionInfo->spi, &pCtx->hSpi); |
Vkadaba | 5:0728bde67bdb | 258 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 259 | return eRet; |
ADIJake | 0:85855ecd3257 | 260 | |
ADIJake | 0:85855ecd3257 | 261 | *phDevice = pCtx; |
Vkadaba | 5:0728bde67bdb | 262 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 263 | } |
ADIJake | 0:85855ecd3257 | 264 | |
ADIJake | 0:85855ecd3257 | 265 | /* |
ADIJake | 0:85855ecd3257 | 266 | * Get the current state of the specified GPIO input signal. |
ADIJake | 0:85855ecd3257 | 267 | */ |
Vkadaba | 5:0728bde67bdb | 268 | ADMW_RESULT admw_GetGpioState( |
Vkadaba | 5:0728bde67bdb | 269 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 270 | ADMW_GPIO_PIN const ePinId, |
ADIJake | 0:85855ecd3257 | 271 | bool * const pbAsserted) |
ADIJake | 0:85855ecd3257 | 272 | { |
Vkadaba | 5:0728bde67bdb | 273 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 5:0728bde67bdb | 274 | |
Vkadaba | 5:0728bde67bdb | 275 | return admw_GpioGet(pCtx->hGpio, ePinId, pbAsserted); |
ADIJake | 0:85855ecd3257 | 276 | } |
ADIJake | 0:85855ecd3257 | 277 | |
ADIJake | 0:85855ecd3257 | 278 | /* |
ADIJake | 0:85855ecd3257 | 279 | * Register an application-defined callback function for GPIO interrupts. |
ADIJake | 0:85855ecd3257 | 280 | */ |
Vkadaba | 5:0728bde67bdb | 281 | ADMW_RESULT admw_RegisterGpioCallback( |
Vkadaba | 5:0728bde67bdb | 282 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 283 | ADMW_GPIO_PIN const ePinId, |
Vkadaba | 5:0728bde67bdb | 284 | ADMW_GPIO_CALLBACK const callbackFunction, |
ADIJake | 0:85855ecd3257 | 285 | void * const pCallbackParam) |
ADIJake | 0:85855ecd3257 | 286 | { |
Vkadaba | 5:0728bde67bdb | 287 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
ADIJake | 0:85855ecd3257 | 288 | |
ADIJake | 0:85855ecd3257 | 289 | if (callbackFunction) |
ADIJake | 0:85855ecd3257 | 290 | { |
Vkadaba | 5:0728bde67bdb | 291 | return admw_GpioIrqEnable(pCtx->hGpio, ePinId, callbackFunction, |
ADIJake | 0:85855ecd3257 | 292 | pCallbackParam); |
ADIJake | 0:85855ecd3257 | 293 | } |
ADIJake | 0:85855ecd3257 | 294 | else |
ADIJake | 0:85855ecd3257 | 295 | { |
Vkadaba | 5:0728bde67bdb | 296 | return admw_GpioIrqDisable(pCtx->hGpio, ePinId); |
ADIJake | 0:85855ecd3257 | 297 | } |
ADIJake | 0:85855ecd3257 | 298 | } |
ADIJake | 0:85855ecd3257 | 299 | |
ADIJake | 0:85855ecd3257 | 300 | /* |
Vkadaba | 5:0728bde67bdb | 301 | * Reset the specified ADMW device. |
ADIJake | 0:85855ecd3257 | 302 | */ |
Vkadaba | 5:0728bde67bdb | 303 | ADMW_RESULT admw_Reset( |
Vkadaba | 5:0728bde67bdb | 304 | ADMW_DEVICE_HANDLE const hDevice) |
ADIJake | 0:85855ecd3257 | 305 | { |
Vkadaba | 5:0728bde67bdb | 306 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 5:0728bde67bdb | 307 | ADMW_RESULT eRet; |
ADIJake | 0:85855ecd3257 | 308 | |
ADIJake | 0:85855ecd3257 | 309 | /* Pulse the Reset GPIO pin low for a minimum of 4 microseconds */ |
Vkadaba | 5:0728bde67bdb | 310 | eRet = admw_GpioSet(pCtx->hGpio, ADMW_GPIO_PIN_RESET, false); |
Vkadaba | 5:0728bde67bdb | 311 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 312 | return eRet; |
ADIJake | 0:85855ecd3257 | 313 | |
Vkadaba | 5:0728bde67bdb | 314 | admw_TimeDelayUsec(4); |
Vkadaba | 5:0728bde67bdb | 315 | |
Vkadaba | 5:0728bde67bdb | 316 | eRet = admw_GpioSet(pCtx->hGpio, ADMW_GPIO_PIN_RESET, true); |
Vkadaba | 5:0728bde67bdb | 317 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 318 | return eRet; |
ADIJake | 0:85855ecd3257 | 319 | |
Vkadaba | 5:0728bde67bdb | 320 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 321 | } |
ADIJake | 0:85855ecd3257 | 322 | |
ADIJake | 0:85855ecd3257 | 323 | |
ADIJake | 0:85855ecd3257 | 324 | /*! |
ADIJake | 0:85855ecd3257 | 325 | * @brief Get general status of ADISense module. |
ADIJake | 0:85855ecd3257 | 326 | * |
ADIJake | 0:85855ecd3257 | 327 | * @param[in] |
ADIJake | 0:85855ecd3257 | 328 | * @param[out] pStatus : Pointer to CORE Status struct. |
ADIJake | 0:85855ecd3257 | 329 | * |
ADIJake | 0:85855ecd3257 | 330 | * @return Status |
Vkadaba | 5:0728bde67bdb | 331 | * - #ADMW_SUCCESS Call completed successfully. |
Vkadaba | 5:0728bde67bdb | 332 | * - #ADMW_FAILURE If status register read fails. |
ADIJake | 0:85855ecd3257 | 333 | * |
ADIJake | 0:85855ecd3257 | 334 | * @details Read the general status register for the ADISense |
ADIJake | 0:85855ecd3257 | 335 | * module. Indicates Error, Alert conditions, data ready |
ADIJake | 0:85855ecd3257 | 336 | * and command running. |
ADIJake | 0:85855ecd3257 | 337 | * |
ADIJake | 0:85855ecd3257 | 338 | */ |
Vkadaba | 5:0728bde67bdb | 339 | ADMW_RESULT admw_GetStatus( |
Vkadaba | 5:0728bde67bdb | 340 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 341 | ADMW_STATUS * const pStatus) |
ADIJake | 0:85855ecd3257 | 342 | { |
Vkadaba | 5:0728bde67bdb | 343 | CORE_Status_t statusReg; |
ADIJake | 0:85855ecd3257 | 344 | READ_REG_U8(hDevice, statusReg.VALUE8, CORE_STATUS); |
ADIJake | 0:85855ecd3257 | 345 | |
Vkadaba | 5:0728bde67bdb | 346 | CORE_Alert_Status_2_t alert2Reg; |
ADIJake | 0:85855ecd3257 | 347 | READ_REG_U16(hDevice, alert2Reg.VALUE16, CORE_ALERT_STATUS_2); |
ADIJake | 0:85855ecd3257 | 348 | |
ADIJake | 0:85855ecd3257 | 349 | memset(pStatus, 0, sizeof(*pStatus)); |
ADIJake | 0:85855ecd3257 | 350 | |
ADIJake | 0:85855ecd3257 | 351 | if (!statusReg.Cmd_Running) /* Active-low, so invert it */ |
Vkadaba | 5:0728bde67bdb | 352 | pStatus->deviceStatus |= ADMW_DEVICE_STATUS_BUSY; |
ADIJake | 0:85855ecd3257 | 353 | if (statusReg.Drdy) |
Vkadaba | 5:0728bde67bdb | 354 | pStatus->deviceStatus |= ADMW_DEVICE_STATUS_DATAREADY; |
ADIJake | 0:85855ecd3257 | 355 | if (statusReg.FIFO_Error) |
Vkadaba | 5:0728bde67bdb | 356 | pStatus->deviceStatus |= ADMW_DEVICE_STATUS_FIFO_ERROR; |
ADIJake | 0:85855ecd3257 | 357 | if (statusReg.Alert_Active) |
ADIJake | 0:85855ecd3257 | 358 | { |
Vkadaba | 5:0728bde67bdb | 359 | pStatus->deviceStatus |= ADMW_DEVICE_STATUS_ALERT; |
Vkadaba | 5:0728bde67bdb | 360 | |
Vkadaba | 5:0728bde67bdb | 361 | CORE_Alert_Code_t alertCodeReg; |
ADIJake | 0:85855ecd3257 | 362 | READ_REG_U16(hDevice, alertCodeReg.VALUE16, CORE_ALERT_CODE); |
ADIJake | 0:85855ecd3257 | 363 | pStatus->alertCode = alertCodeReg.Alert_Code; |
ADIJake | 0:85855ecd3257 | 364 | |
Vkadaba | 5:0728bde67bdb | 365 | CORE_Channel_Alert_Status_t channelAlertStatusReg; |
ADIJake | 0:85855ecd3257 | 366 | READ_REG_U16(hDevice, channelAlertStatusReg.VALUE16, |
ADIJake | 0:85855ecd3257 | 367 | CORE_CHANNEL_ALERT_STATUS); |
ADIJake | 0:85855ecd3257 | 368 | |
Vkadaba | 5:0728bde67bdb | 369 | for (unsigned i = 0; i < ADMW1001_MAX_CHANNELS; i++) |
ADIJake | 0:85855ecd3257 | 370 | { |
ADIJake | 0:85855ecd3257 | 371 | if (channelAlertStatusReg.VALUE16 & (1 << i)) |
ADIJake | 0:85855ecd3257 | 372 | { |
Vkadaba | 5:0728bde67bdb | 373 | CORE_Alert_Code_Ch_t channelAlertCodeReg; |
ADIJake | 0:85855ecd3257 | 374 | READ_REG_U16(hDevice, channelAlertCodeReg.VALUE16, CORE_ALERT_CODE_CHn(i)); |
ADIJake | 0:85855ecd3257 | 375 | pStatus->channelAlertCodes[i] = channelAlertCodeReg.Alert_Code_Ch; |
ADIJake | 0:85855ecd3257 | 376 | |
Vkadaba | 5:0728bde67bdb | 377 | CORE_Alert_Detail_Ch_t alertDetailReg; |
ADIJake | 0:85855ecd3257 | 378 | READ_REG_U16(hDevice, alertDetailReg.VALUE16, |
ADIJake | 0:85855ecd3257 | 379 | CORE_ALERT_DETAIL_CHn(i)); |
ADIJake | 0:85855ecd3257 | 380 | |
ADIJake | 0:85855ecd3257 | 381 | if (alertDetailReg.Time_Out) |
Vkadaba | 5:0728bde67bdb | 382 | pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_TIMEOUT; |
ADIJake | 0:85855ecd3257 | 383 | if (alertDetailReg.Under_Range) |
Vkadaba | 5:0728bde67bdb | 384 | pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_UNDER_RANGE; |
ADIJake | 0:85855ecd3257 | 385 | if (alertDetailReg.Over_Range) |
Vkadaba | 5:0728bde67bdb | 386 | pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_OVER_RANGE; |
ADIJake | 0:85855ecd3257 | 387 | if (alertDetailReg.Low_Limit) |
Vkadaba | 5:0728bde67bdb | 388 | pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_LOW_LIMIT; |
ADIJake | 0:85855ecd3257 | 389 | if (alertDetailReg.High_Limit) |
Vkadaba | 5:0728bde67bdb | 390 | pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_HIGH_LIMIT; |
ADIJake | 0:85855ecd3257 | 391 | if (alertDetailReg.Sensor_Open) |
Vkadaba | 5:0728bde67bdb | 392 | pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_SENSOR_OPEN; |
ADIJake | 0:85855ecd3257 | 393 | if (alertDetailReg.Ref_Detect) |
Vkadaba | 5:0728bde67bdb | 394 | pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_REF_DETECT; |
ADIJake | 0:85855ecd3257 | 395 | if (alertDetailReg.Config_Err) |
Vkadaba | 5:0728bde67bdb | 396 | pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_CONFIG_ERR; |
ADIJake | 0:85855ecd3257 | 397 | if (alertDetailReg.LUT_Error_Ch) |
Vkadaba | 5:0728bde67bdb | 398 | pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_LUT_ERR; |
ADIJake | 0:85855ecd3257 | 399 | if (alertDetailReg.Sensor_Not_Ready) |
Vkadaba | 5:0728bde67bdb | 400 | pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_SENSOR_NOT_READY; |
ADIJake | 0:85855ecd3257 | 401 | if (alertDetailReg.Comp_Not_Ready) |
Vkadaba | 5:0728bde67bdb | 402 | pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_COMP_NOT_READY; |
ADIJake | 0:85855ecd3257 | 403 | if (alertDetailReg.Correction_UnderRange) |
Vkadaba | 5:0728bde67bdb | 404 | pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_LUT_UNDER_RANGE; |
ADIJake | 0:85855ecd3257 | 405 | if (alertDetailReg.Correction_OverRange) |
Vkadaba | 5:0728bde67bdb | 406 | pStatus->channelAlerts[i] |= ADMW_CHANNEL_ALERT_LUT_OVER_RANGE; |
ADIJake | 0:85855ecd3257 | 407 | } |
ADIJake | 0:85855ecd3257 | 408 | } |
ADIJake | 0:85855ecd3257 | 409 | |
ADIJake | 0:85855ecd3257 | 410 | if (alert2Reg.Configuration_Error) |
Vkadaba | 5:0728bde67bdb | 411 | pStatus->deviceStatus |= ADMW_DEVICE_STATUS_CONFIG_ERROR; |
ADIJake | 0:85855ecd3257 | 412 | if (alert2Reg.LUT_Error) |
Vkadaba | 5:0728bde67bdb | 413 | pStatus->deviceStatus |= ADMW_DEVICE_STATUS_LUT_ERROR; |
ADIJake | 0:85855ecd3257 | 414 | } |
ADIJake | 0:85855ecd3257 | 415 | |
ADIJake | 0:85855ecd3257 | 416 | if (statusReg.Error) |
ADIJake | 0:85855ecd3257 | 417 | { |
Vkadaba | 5:0728bde67bdb | 418 | pStatus->deviceStatus |= ADMW_DEVICE_STATUS_ERROR; |
Vkadaba | 5:0728bde67bdb | 419 | |
Vkadaba | 5:0728bde67bdb | 420 | CORE_Error_Code_t errorCodeReg; |
ADIJake | 0:85855ecd3257 | 421 | READ_REG_U16(hDevice, errorCodeReg.VALUE16, CORE_ERROR_CODE); |
ADIJake | 0:85855ecd3257 | 422 | pStatus->errorCode = errorCodeReg.Error_Code; |
ADIJake | 0:85855ecd3257 | 423 | |
Vkadaba | 5:0728bde67bdb | 424 | CORE_Diagnostics_Status_t diagStatusReg; |
ADIJake | 0:85855ecd3257 | 425 | READ_REG_U16(hDevice, diagStatusReg.VALUE16, CORE_DIAGNOSTICS_STATUS); |
ADIJake | 0:85855ecd3257 | 426 | |
ADIJake | 0:85855ecd3257 | 427 | if (diagStatusReg.Diag_Checksum_Error) |
Vkadaba | 5:0728bde67bdb | 428 | pStatus->diagnosticsStatus |= ADMW_DIAGNOSTICS_STATUS_CHECKSUM_ERROR; |
ADIJake | 0:85855ecd3257 | 429 | if (diagStatusReg.Diag_Conversion_Error) |
Vkadaba | 5:0728bde67bdb | 430 | pStatus->diagnosticsStatus |= ADMW_DIAGNOSTICS_STATUS_CONVERSION_ERROR; |
ADIJake | 0:85855ecd3257 | 431 | if (diagStatusReg.Diag_Calibration_Error) |
Vkadaba | 5:0728bde67bdb | 432 | pStatus->diagnosticsStatus |= ADMW_DIAGNOSTICS_STATUS_CALIBRATION_ERROR; |
ADIJake | 0:85855ecd3257 | 433 | } |
ADIJake | 0:85855ecd3257 | 434 | |
ADIJake | 0:85855ecd3257 | 435 | if (statusReg.Alert_Active || statusReg.Error) |
ADIJake | 0:85855ecd3257 | 436 | { |
Vkadaba | 5:0728bde67bdb | 437 | CORE_Debug_Code_t debugCodeReg; |
ADIJake | 0:85855ecd3257 | 438 | READ_REG_U32(hDevice, debugCodeReg.VALUE32, CORE_DEBUG_CODE); |
ADIJake | 0:85855ecd3257 | 439 | pStatus->debugCode = debugCodeReg.Debug_Code; |
ADIJake | 0:85855ecd3257 | 440 | } |
ADIJake | 0:85855ecd3257 | 441 | |
Vkadaba | 5:0728bde67bdb | 442 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 443 | } |
ADIJake | 0:85855ecd3257 | 444 | |
Vkadaba | 5:0728bde67bdb | 445 | ADMW_RESULT admw_GetCommandRunningState( |
Vkadaba | 5:0728bde67bdb | 446 | ADMW_DEVICE_HANDLE hDevice, |
ADIJake | 0:85855ecd3257 | 447 | bool *pbCommandRunning) |
ADIJake | 0:85855ecd3257 | 448 | { |
Vkadaba | 5:0728bde67bdb | 449 | CORE_Status_t statusReg; |
ADIJake | 0:85855ecd3257 | 450 | |
ADIJake | 0:85855ecd3257 | 451 | READ_REG_U8(hDevice, statusReg.VALUE8, CORE_STATUS); |
ADIJake | 0:85855ecd3257 | 452 | |
ADIJake | 0:85855ecd3257 | 453 | /* We should never normally see 0xFF here if the module is operational */ |
ADIJake | 0:85855ecd3257 | 454 | if (statusReg.VALUE8 == 0xFF) |
Vkadaba | 5:0728bde67bdb | 455 | return ADMW_ERR_NOT_INITIALIZED; |
ADIJake | 0:85855ecd3257 | 456 | |
ADIJake | 0:85855ecd3257 | 457 | *pbCommandRunning = !statusReg.Cmd_Running; /* Active-low, so invert it */ |
ADIJake | 0:85855ecd3257 | 458 | |
Vkadaba | 5:0728bde67bdb | 459 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 460 | } |
ADIJake | 0:85855ecd3257 | 461 | |
Vkadaba | 5:0728bde67bdb | 462 | static ADMW_RESULT executeCommand( |
Vkadaba | 5:0728bde67bdb | 463 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 464 | CORE_Command_Special_Command const command, |
ADIJake | 0:85855ecd3257 | 465 | bool const bWaitForCompletion) |
ADIJake | 0:85855ecd3257 | 466 | { |
Vkadaba | 5:0728bde67bdb | 467 | CORE_Command_t commandReg; |
ADIJake | 0:85855ecd3257 | 468 | bool bCommandRunning; |
Vkadaba | 5:0728bde67bdb | 469 | ADMW_RESULT eRet; |
ADIJake | 0:85855ecd3257 | 470 | |
ADIJake | 0:85855ecd3257 | 471 | /* |
ADIJake | 0:85855ecd3257 | 472 | * Don't allow another command to be issued if one is already running, but |
Vkadaba | 6:9d393a9677f4 | 473 | * make an exception for ENUM_CORE_COMMAND_NOP which can be used to |
ADIJake | 0:85855ecd3257 | 474 | * request a running command to be stopped (e.g. continuous measurement) |
ADIJake | 0:85855ecd3257 | 475 | */ |
Vkadaba | 6:9d393a9677f4 | 476 | if (command != ENUM_CORE_COMMAND_NOP) |
ADIJake | 0:85855ecd3257 | 477 | { |
Vkadaba | 5:0728bde67bdb | 478 | eRet = admw_GetCommandRunningState(hDevice, &bCommandRunning); |
ADIJake | 0:85855ecd3257 | 479 | if (eRet) |
ADIJake | 0:85855ecd3257 | 480 | return eRet; |
ADIJake | 0:85855ecd3257 | 481 | |
ADIJake | 0:85855ecd3257 | 482 | if (bCommandRunning) |
Vkadaba | 5:0728bde67bdb | 483 | return ADMW_IN_USE; |
ADIJake | 0:85855ecd3257 | 484 | } |
ADIJake | 0:85855ecd3257 | 485 | |
ADIJake | 0:85855ecd3257 | 486 | commandReg.Special_Command = command; |
ADIJake | 0:85855ecd3257 | 487 | WRITE_REG_U8(hDevice, commandReg.VALUE8, CORE_COMMAND); |
ADIJake | 0:85855ecd3257 | 488 | |
ADIJake | 0:85855ecd3257 | 489 | if (bWaitForCompletion) |
ADIJake | 0:85855ecd3257 | 490 | { |
ADIJake | 0:85855ecd3257 | 491 | do { |
ADIJake | 0:85855ecd3257 | 492 | /* Allow a minimum 50usec delay for status update before checking */ |
Vkadaba | 5:0728bde67bdb | 493 | admw_TimeDelayUsec(50); |
Vkadaba | 5:0728bde67bdb | 494 | |
Vkadaba | 5:0728bde67bdb | 495 | eRet = admw_GetCommandRunningState(hDevice, &bCommandRunning); |
ADIJake | 0:85855ecd3257 | 496 | if (eRet) |
ADIJake | 0:85855ecd3257 | 497 | return eRet; |
ADIJake | 0:85855ecd3257 | 498 | } while (bCommandRunning); |
ADIJake | 0:85855ecd3257 | 499 | } |
ADIJake | 0:85855ecd3257 | 500 | |
Vkadaba | 5:0728bde67bdb | 501 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 502 | } |
ADIJake | 0:85855ecd3257 | 503 | |
Vkadaba | 5:0728bde67bdb | 504 | ADMW_RESULT admw_Shutdown( |
Vkadaba | 5:0728bde67bdb | 505 | ADMW_DEVICE_HANDLE const hDevice) |
ADIJake | 0:85855ecd3257 | 506 | { |
Vkadaba | 5:0728bde67bdb | 507 | return executeCommand(hDevice, CORE_COMMAND_POWER_DOWN, false); |
ADIJake | 0:85855ecd3257 | 508 | } |
ADIJake | 0:85855ecd3257 | 509 | |
ADIJake | 0:85855ecd3257 | 510 | |
Vkadaba | 5:0728bde67bdb | 511 | ADMW_RESULT admw_ApplyConfigUpdates( |
Vkadaba | 5:0728bde67bdb | 512 | ADMW_DEVICE_HANDLE const hDevice) |
ADIJake | 0:85855ecd3257 | 513 | { |
Vkadaba | 5:0728bde67bdb | 514 | return executeCommand(hDevice, CORE_COMMAND_LATCH_CONFIG, true); |
ADIJake | 0:85855ecd3257 | 515 | } |
ADIJake | 0:85855ecd3257 | 516 | |
ADIJake | 0:85855ecd3257 | 517 | /*! |
ADIJake | 0:85855ecd3257 | 518 | * @brief Start a measurement cycle. |
ADIJake | 0:85855ecd3257 | 519 | * |
ADIJake | 0:85855ecd3257 | 520 | * @param[out] |
ADIJake | 0:85855ecd3257 | 521 | * |
ADIJake | 0:85855ecd3257 | 522 | * @return Status |
Vkadaba | 5:0728bde67bdb | 523 | * - #ADMW_SUCCESS Call completed successfully. |
Vkadaba | 5:0728bde67bdb | 524 | * - #ADMW_FAILURE |
ADIJake | 0:85855ecd3257 | 525 | * |
ADIJake | 0:85855ecd3257 | 526 | * @details Sends the latch config command. Configuration for channels in |
ADIJake | 0:85855ecd3257 | 527 | * conversion cycle should be completed before this function. |
ADIJake | 0:85855ecd3257 | 528 | * Channel enabled bit should be set before this function. |
ADIJake | 0:85855ecd3257 | 529 | * Starts a conversion and configures the format of the sample. |
ADIJake | 0:85855ecd3257 | 530 | * |
ADIJake | 0:85855ecd3257 | 531 | */ |
Vkadaba | 5:0728bde67bdb | 532 | ADMW_RESULT admw_StartMeasurement( |
Vkadaba | 5:0728bde67bdb | 533 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 534 | ADMW_MEASUREMENT_MODE const eMeasurementMode) |
ADIJake | 0:85855ecd3257 | 535 | { |
ADIJake | 0:85855ecd3257 | 536 | switch (eMeasurementMode) |
ADIJake | 0:85855ecd3257 | 537 | { |
Vkadaba | 5:0728bde67bdb | 538 | case ADMW_MEASUREMENT_MODE_NORMAL: |
Vkadaba | 5:0728bde67bdb | 539 | return executeCommand(hDevice, CORE_COMMAND_CONVERT_WITH_RAW, false); |
Vkadaba | 5:0728bde67bdb | 540 | case ADMW_MEASUREMENT_MODE_OMIT_RAW: |
Vkadaba | 5:0728bde67bdb | 541 | return executeCommand(hDevice, CORE_COMMAND_CONVERT, false); |
ADIJake | 0:85855ecd3257 | 542 | default: |
Vkadaba | 5:0728bde67bdb | 543 | ADMW_LOG_ERROR("Invalid measurement mode %d specified", |
ADIJake | 0:85855ecd3257 | 544 | eMeasurementMode); |
Vkadaba | 5:0728bde67bdb | 545 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 546 | } |
ADIJake | 0:85855ecd3257 | 547 | } |
ADIJake | 0:85855ecd3257 | 548 | |
ADIJake | 0:85855ecd3257 | 549 | /* |
ADIJake | 0:85855ecd3257 | 550 | * Store the configuration settings to persistent memory on the device. |
ADIJake | 0:85855ecd3257 | 551 | * The settings can be saved to 4 different flash memory areas (slots). |
ADIJake | 0:85855ecd3257 | 552 | * No other command must be running when this is called. |
ADIJake | 0:85855ecd3257 | 553 | * Do not power down the device while this command is running. |
ADIJake | 0:85855ecd3257 | 554 | */ |
Vkadaba | 5:0728bde67bdb | 555 | ADMW_RESULT admw_SaveConfig( |
Vkadaba | 5:0728bde67bdb | 556 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 557 | ADMW_USER_CONFIG_SLOT const eSlotId) |
ADIJake | 0:85855ecd3257 | 558 | { |
ADIJake | 0:85855ecd3257 | 559 | switch (eSlotId) |
ADIJake | 0:85855ecd3257 | 560 | { |
Vkadaba | 5:0728bde67bdb | 561 | case ADMW_FLASH_CONFIG_1: |
Vkadaba | 5:0728bde67bdb | 562 | return executeCommand(hDevice, CORE_COMMAND_SAVE_CONFIG_1, true); |
ADIJake | 0:85855ecd3257 | 563 | default: |
Vkadaba | 5:0728bde67bdb | 564 | ADMW_LOG_ERROR("Invalid user config target slot %d specified", |
ADIJake | 0:85855ecd3257 | 565 | eSlotId); |
Vkadaba | 5:0728bde67bdb | 566 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 567 | } |
ADIJake | 0:85855ecd3257 | 568 | } |
ADIJake | 0:85855ecd3257 | 569 | |
ADIJake | 0:85855ecd3257 | 570 | /* |
ADIJake | 0:85855ecd3257 | 571 | * Restore the configuration settings from persistent memory on the device. |
ADIJake | 0:85855ecd3257 | 572 | * No other command must be running when this is called. |
ADIJake | 0:85855ecd3257 | 573 | */ |
Vkadaba | 5:0728bde67bdb | 574 | ADMW_RESULT admw_RestoreConfig( |
Vkadaba | 5:0728bde67bdb | 575 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 576 | ADMW_USER_CONFIG_SLOT const eSlotId) |
ADIJake | 0:85855ecd3257 | 577 | { |
ADIJake | 0:85855ecd3257 | 578 | switch (eSlotId) |
ADIJake | 0:85855ecd3257 | 579 | { |
Vkadaba | 5:0728bde67bdb | 580 | case ADMW_FLASH_CONFIG_1: |
Vkadaba | 5:0728bde67bdb | 581 | return executeCommand(hDevice, CORE_COMMAND_LOAD_CONFIG_1, true); |
ADIJake | 0:85855ecd3257 | 582 | default: |
Vkadaba | 5:0728bde67bdb | 583 | ADMW_LOG_ERROR("Invalid user config source slot %d specified", |
ADIJake | 0:85855ecd3257 | 584 | eSlotId); |
Vkadaba | 5:0728bde67bdb | 585 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 586 | } |
ADIJake | 0:85855ecd3257 | 587 | } |
ADIJake | 0:85855ecd3257 | 588 | |
ADIJake | 0:85855ecd3257 | 589 | /* |
ADIJake | 0:85855ecd3257 | 590 | * Store the LUT data to persistent memory on the device. |
ADIJake | 0:85855ecd3257 | 591 | * No other command must be running when this is called. |
ADIJake | 0:85855ecd3257 | 592 | * Do not power down the device while this command is running. |
ADIJake | 0:85855ecd3257 | 593 | */ |
Vkadaba | 5:0728bde67bdb | 594 | ADMW_RESULT admw_SaveLutData( |
Vkadaba | 5:0728bde67bdb | 595 | ADMW_DEVICE_HANDLE const hDevice) |
ADIJake | 0:85855ecd3257 | 596 | { |
Vkadaba | 5:0728bde67bdb | 597 | return executeCommand(hDevice, CORE_COMMAND_SAVE_LUT, true); |
ADIJake | 0:85855ecd3257 | 598 | } |
ADIJake | 0:85855ecd3257 | 599 | |
ADIJake | 0:85855ecd3257 | 600 | /* |
ADIJake | 0:85855ecd3257 | 601 | * Restore the LUT data from persistent memory on the device. |
ADIJake | 0:85855ecd3257 | 602 | * No other command must be running when this is called. |
ADIJake | 0:85855ecd3257 | 603 | */ |
Vkadaba | 5:0728bde67bdb | 604 | ADMW_RESULT admw_RestoreLutData( |
Vkadaba | 5:0728bde67bdb | 605 | ADMW_DEVICE_HANDLE const hDevice) |
ADIJake | 0:85855ecd3257 | 606 | { |
Vkadaba | 5:0728bde67bdb | 607 | return executeCommand(hDevice, CORE_COMMAND_LOAD_LUT, true); |
ADIJake | 0:85855ecd3257 | 608 | } |
ADIJake | 0:85855ecd3257 | 609 | |
ADIJake | 0:85855ecd3257 | 610 | /* |
ADIJake | 0:85855ecd3257 | 611 | * Stop the measurement cycles on the device. |
ADIJake | 0:85855ecd3257 | 612 | * To be used only if a measurement command is currently running. |
ADIJake | 0:85855ecd3257 | 613 | */ |
Vkadaba | 5:0728bde67bdb | 614 | ADMW_RESULT admw_StopMeasurement( |
Vkadaba | 5:0728bde67bdb | 615 | ADMW_DEVICE_HANDLE const hDevice) |
ADIJake | 0:85855ecd3257 | 616 | { |
Vkadaba | 5:0728bde67bdb | 617 | return executeCommand(hDevice, CORE_COMMAND_NOP, true); |
ADIJake | 0:85855ecd3257 | 618 | } |
ADIJake | 0:85855ecd3257 | 619 | |
ADIJake | 0:85855ecd3257 | 620 | /* |
ADIJake | 0:85855ecd3257 | 621 | * Run digital calibration routines on the device. |
ADIJake | 0:85855ecd3257 | 622 | * Calibration is executed according to the current applied settings. |
ADIJake | 0:85855ecd3257 | 623 | * No other command must be running when this is called. |
ADIJake | 0:85855ecd3257 | 624 | */ |
Vkadaba | 5:0728bde67bdb | 625 | ADMW_RESULT admw_RunDigitalCalibration( |
Vkadaba | 5:0728bde67bdb | 626 | ADMW_DEVICE_HANDLE const hDevice) |
ADIJake | 0:85855ecd3257 | 627 | { |
Vkadaba | 5:0728bde67bdb | 628 | return executeCommand(hDevice, CORE_COMMAND_CALIBRATE_DIGITAL, true); |
ADIJake | 0:85855ecd3257 | 629 | } |
ADIJake | 0:85855ecd3257 | 630 | |
ADIJake | 0:85855ecd3257 | 631 | /* |
ADIJake | 0:85855ecd3257 | 632 | * Read a set of data samples from the device. |
ADIJake | 0:85855ecd3257 | 633 | * This may be called at any time. |
ADIJake | 0:85855ecd3257 | 634 | */ |
Vkadaba | 5:0728bde67bdb | 635 | ADMW_RESULT admw_GetData( |
Vkadaba | 5:0728bde67bdb | 636 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 637 | ADMW_MEASUREMENT_MODE const eMeasurementMode, |
Vkadaba | 5:0728bde67bdb | 638 | ADMW_DATA_SAMPLE * const pSamples, |
ADIJake | 0:85855ecd3257 | 639 | uint8_t const nBytesPerSample, |
ADIJake | 0:85855ecd3257 | 640 | uint32_t const nRequested, |
ADIJake | 0:85855ecd3257 | 641 | uint32_t * const pnReturned) |
ADIJake | 0:85855ecd3257 | 642 | { |
Vkadaba | 5:0728bde67bdb | 643 | ADMW1001_Sensor_Result_t sensorResult; |
Vkadaba | 5:0728bde67bdb | 644 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 5:0728bde67bdb | 645 | uint16_t command = ADMW1001_HOST_COMMS_READ_CMD | |
Vkadaba | 5:0728bde67bdb | 646 | (REG_CORE_DATA_FIFO & ADMW1001_HOST_COMMS_ADR_MASK); |
ADIJake | 0:85855ecd3257 | 647 | uint8_t commandData[2] = { |
ADIJake | 0:85855ecd3257 | 648 | command >> 8, |
ADIJake | 0:85855ecd3257 | 649 | command & 0xFF |
ADIJake | 0:85855ecd3257 | 650 | }; |
ADIJake | 0:85855ecd3257 | 651 | uint8_t commandResponse[2]; |
ADIJake | 0:85855ecd3257 | 652 | unsigned nValidSamples = 0; |
Vkadaba | 5:0728bde67bdb | 653 | ADMW_RESULT eRet = ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 654 | |
ADIJake | 0:85855ecd3257 | 655 | do { |
Vkadaba | 5:0728bde67bdb | 656 | eRet = admw_SpiTransfer(pCtx->hSpi, commandData, commandResponse, |
ADIJake | 0:85855ecd3257 | 657 | sizeof(command), false); |
ADIJake | 0:85855ecd3257 | 658 | if (eRet) |
ADIJake | 0:85855ecd3257 | 659 | { |
Vkadaba | 5:0728bde67bdb | 660 | ADMW_LOG_ERROR("Failed to send read command for FIFO register"); |
ADIJake | 0:85855ecd3257 | 661 | return eRet; |
ADIJake | 0:85855ecd3257 | 662 | } |
Vkadaba | 5:0728bde67bdb | 663 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 5:0728bde67bdb | 664 | } while ((commandResponse[0] != ADMW1001_HOST_COMMS_CMD_RESP_0) || |
Vkadaba | 5:0728bde67bdb | 665 | (commandResponse[1] != ADMW1001_HOST_COMMS_CMD_RESP_1)); |
ADIJake | 0:85855ecd3257 | 666 | |
ADIJake | 0:85855ecd3257 | 667 | for (unsigned i = 0; i < nRequested; i++) |
ADIJake | 0:85855ecd3257 | 668 | { |
ADIJake | 0:85855ecd3257 | 669 | bool bHoldCs = true; |
ADIJake | 0:85855ecd3257 | 670 | |
ADIJake | 0:85855ecd3257 | 671 | /* Keep the CS signal asserted for all but the last sample */ |
ADIJake | 0:85855ecd3257 | 672 | if ((i + 1) == nRequested) |
ADIJake | 0:85855ecd3257 | 673 | bHoldCs = false; |
ADIJake | 0:85855ecd3257 | 674 | |
ADIJake | 0:85855ecd3257 | 675 | getDataCnt++; |
ADIJake | 0:85855ecd3257 | 676 | |
Vkadaba | 5:0728bde67bdb | 677 | eRet = admw_SpiTransfer(pCtx->hSpi, NULL, &sensorResult, |
ADIJake | 0:85855ecd3257 | 678 | nBytesPerSample, bHoldCs); |
ADIJake | 0:85855ecd3257 | 679 | if (eRet) |
ADIJake | 0:85855ecd3257 | 680 | { |
Vkadaba | 5:0728bde67bdb | 681 | ADMW_LOG_ERROR("Failed to read data from FIFO register"); |
ADIJake | 0:85855ecd3257 | 682 | return eRet; |
ADIJake | 0:85855ecd3257 | 683 | } |
ADIJake | 0:85855ecd3257 | 684 | |
ADIJake | 0:85855ecd3257 | 685 | if (! sensorResult.Ch_Valid) |
ADIJake | 0:85855ecd3257 | 686 | { |
ADIJake | 0:85855ecd3257 | 687 | /* |
ADIJake | 0:85855ecd3257 | 688 | * Reading an invalid sample indicates that there are no |
ADIJake | 0:85855ecd3257 | 689 | * more samples available or we've lost sync with the device. |
ADIJake | 0:85855ecd3257 | 690 | * In the latter case, it might be recoverable, but return here |
ADIJake | 0:85855ecd3257 | 691 | * to let the application check the device status and decide itself. |
ADIJake | 0:85855ecd3257 | 692 | */ |
Vkadaba | 5:0728bde67bdb | 693 | eRet = ADMW_INCOMPLETE; |
ADIJake | 0:85855ecd3257 | 694 | break; |
ADIJake | 0:85855ecd3257 | 695 | } |
ADIJake | 0:85855ecd3257 | 696 | |
Vkadaba | 5:0728bde67bdb | 697 | ADMW_DATA_SAMPLE *pSample = &pSamples[nValidSamples]; |
Vkadaba | 5:0728bde67bdb | 698 | |
Vkadaba | 5:0728bde67bdb | 699 | pSample->status = (ADMW_DEVICE_STATUS_FLAGS)0; |
ADIJake | 0:85855ecd3257 | 700 | if (sensorResult.Ch_Error) |
Vkadaba | 5:0728bde67bdb | 701 | pSample->status |= ADMW_DEVICE_STATUS_ERROR; |
ADIJake | 0:85855ecd3257 | 702 | if (sensorResult.Ch_Alert) |
Vkadaba | 5:0728bde67bdb | 703 | pSample->status |= ADMW_DEVICE_STATUS_ALERT; |
ADIJake | 0:85855ecd3257 | 704 | |
ADIJake | 0:85855ecd3257 | 705 | if (sensorResult.Ch_Raw) |
ADIJake | 0:85855ecd3257 | 706 | pSample->rawValue = sensorResult.Raw_Sample; |
ADIJake | 0:85855ecd3257 | 707 | else |
ADIJake | 0:85855ecd3257 | 708 | pSample->rawValue = 0; |
ADIJake | 0:85855ecd3257 | 709 | |
ADIJake | 0:85855ecd3257 | 710 | pSample->channelId = sensorResult.Channel_ID; |
ADIJake | 0:85855ecd3257 | 711 | pSample->processedValue = sensorResult.Sensor_Result; |
ADIJake | 0:85855ecd3257 | 712 | |
ADIJake | 0:85855ecd3257 | 713 | nValidSamples++; |
ADIJake | 0:85855ecd3257 | 714 | |
Vkadaba | 5:0728bde67bdb | 715 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
ADIJake | 0:85855ecd3257 | 716 | } |
ADIJake | 0:85855ecd3257 | 717 | *pnReturned = nValidSamples; |
ADIJake | 0:85855ecd3257 | 718 | |
ADIJake | 0:85855ecd3257 | 719 | return eRet; |
ADIJake | 0:85855ecd3257 | 720 | } |
ADIJake | 0:85855ecd3257 | 721 | |
ADIJake | 0:85855ecd3257 | 722 | /* |
Vkadaba | 5:0728bde67bdb | 723 | * Close the given ADMW device. |
ADIJake | 0:85855ecd3257 | 724 | */ |
Vkadaba | 5:0728bde67bdb | 725 | ADMW_RESULT admw_Close( |
Vkadaba | 5:0728bde67bdb | 726 | ADMW_DEVICE_HANDLE const hDevice) |
ADIJake | 0:85855ecd3257 | 727 | { |
Vkadaba | 5:0728bde67bdb | 728 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 5:0728bde67bdb | 729 | |
Vkadaba | 5:0728bde67bdb | 730 | admw_GpioClose(pCtx->hGpio); |
Vkadaba | 5:0728bde67bdb | 731 | admw_SpiClose(pCtx->hSpi); |
Vkadaba | 5:0728bde67bdb | 732 | admw_LogClose(); |
Vkadaba | 5:0728bde67bdb | 733 | |
Vkadaba | 5:0728bde67bdb | 734 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 735 | } |
ADIJake | 0:85855ecd3257 | 736 | |
Vkadaba | 5:0728bde67bdb | 737 | ADMW_RESULT admw1001_WriteRegister( |
Vkadaba | 5:0728bde67bdb | 738 | ADMW_DEVICE_HANDLE hDevice, |
ADIJake | 0:85855ecd3257 | 739 | uint16_t nAddress, |
ADIJake | 0:85855ecd3257 | 740 | void *pData, |
ADIJake | 0:85855ecd3257 | 741 | unsigned nLength) |
ADIJake | 0:85855ecd3257 | 742 | { |
Vkadaba | 5:0728bde67bdb | 743 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 744 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 5:0728bde67bdb | 745 | uint16_t command = ADMW1001_HOST_COMMS_WRITE_CMD | |
Vkadaba | 5:0728bde67bdb | 746 | (nAddress & ADMW1001_HOST_COMMS_ADR_MASK); |
ADIJake | 0:85855ecd3257 | 747 | uint8_t commandData[2] = { |
ADIJake | 0:85855ecd3257 | 748 | command >> 8, |
ADIJake | 0:85855ecd3257 | 749 | command & 0xFF |
ADIJake | 0:85855ecd3257 | 750 | }; |
ADIJake | 0:85855ecd3257 | 751 | uint8_t commandResponse[2]; |
ADIJake | 0:85855ecd3257 | 752 | |
ADIJake | 0:85855ecd3257 | 753 | do { |
Vkadaba | 5:0728bde67bdb | 754 | eRet = admw_SpiTransfer(pCtx->hSpi, commandData, commandResponse, |
ADIJake | 0:85855ecd3257 | 755 | sizeof(command), false); |
ADIJake | 0:85855ecd3257 | 756 | if (eRet) |
ADIJake | 0:85855ecd3257 | 757 | { |
Vkadaba | 5:0728bde67bdb | 758 | ADMW_LOG_ERROR("Failed to send write command for register %u", |
ADIJake | 0:85855ecd3257 | 759 | nAddress); |
ADIJake | 0:85855ecd3257 | 760 | return eRet; |
ADIJake | 0:85855ecd3257 | 761 | } |
ADIJake | 0:85855ecd3257 | 762 | |
Vkadaba | 5:0728bde67bdb | 763 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 5:0728bde67bdb | 764 | } while ((commandResponse[0] != ADMW1001_HOST_COMMS_CMD_RESP_0) || |
Vkadaba | 5:0728bde67bdb | 765 | (commandResponse[1] != ADMW1001_HOST_COMMS_CMD_RESP_1)); |
Vkadaba | 5:0728bde67bdb | 766 | |
Vkadaba | 5:0728bde67bdb | 767 | eRet = admw_SpiTransfer(pCtx->hSpi, pData, NULL, nLength, false); |
ADIJake | 0:85855ecd3257 | 768 | if (eRet) |
ADIJake | 0:85855ecd3257 | 769 | { |
Vkadaba | 5:0728bde67bdb | 770 | ADMW_LOG_ERROR("Failed to write data (%dB) to register %u", |
ADIJake | 0:85855ecd3257 | 771 | nLength, nAddress); |
ADIJake | 0:85855ecd3257 | 772 | return eRet; |
ADIJake | 0:85855ecd3257 | 773 | } |
ADIJake | 0:85855ecd3257 | 774 | |
Vkadaba | 5:0728bde67bdb | 775 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 5:0728bde67bdb | 776 | |
Vkadaba | 5:0728bde67bdb | 777 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 778 | } |
ADIJake | 0:85855ecd3257 | 779 | |
Vkadaba | 6:9d393a9677f4 | 780 | ADMW_RESULT admw1001_Write_Debug_Register( |
Vkadaba | 6:9d393a9677f4 | 781 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 6:9d393a9677f4 | 782 | uint16_t nAddress, |
Vkadaba | 6:9d393a9677f4 | 783 | void *pData, |
Vkadaba | 6:9d393a9677f4 | 784 | unsigned nLength) |
Vkadaba | 6:9d393a9677f4 | 785 | { |
Vkadaba | 6:9d393a9677f4 | 786 | ADMW_RESULT eRet; |
Vkadaba | 6:9d393a9677f4 | 787 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 6:9d393a9677f4 | 788 | uint16_t command = ADMW1001_HOST_COMMS_DEBUG_WRITE_CMD | |
Vkadaba | 6:9d393a9677f4 | 789 | (nAddress & ADMW1001_HOST_COMMS_ADR_MASK); |
Vkadaba | 6:9d393a9677f4 | 790 | uint8_t commandData[2] = { |
Vkadaba | 6:9d393a9677f4 | 791 | command >> 8, |
Vkadaba | 6:9d393a9677f4 | 792 | command & 0xFF |
Vkadaba | 6:9d393a9677f4 | 793 | }; |
Vkadaba | 6:9d393a9677f4 | 794 | uint8_t commandResponse[2]; |
Vkadaba | 6:9d393a9677f4 | 795 | |
Vkadaba | 6:9d393a9677f4 | 796 | do { |
Vkadaba | 6:9d393a9677f4 | 797 | eRet = admw_SpiTransfer(pCtx->hSpi, commandData, commandResponse, |
Vkadaba | 6:9d393a9677f4 | 798 | sizeof(command), false); |
Vkadaba | 6:9d393a9677f4 | 799 | if (eRet) |
Vkadaba | 6:9d393a9677f4 | 800 | { |
Vkadaba | 6:9d393a9677f4 | 801 | ADMW_LOG_ERROR("Failed to send write command for register %u", |
Vkadaba | 6:9d393a9677f4 | 802 | nAddress); |
Vkadaba | 6:9d393a9677f4 | 803 | return eRet; |
Vkadaba | 6:9d393a9677f4 | 804 | } |
Vkadaba | 6:9d393a9677f4 | 805 | |
Vkadaba | 6:9d393a9677f4 | 806 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 6:9d393a9677f4 | 807 | } while ((commandResponse[0] != ADMW1001_HOST_COMMS_CMD_RESP_0) || |
Vkadaba | 6:9d393a9677f4 | 808 | (commandResponse[1] != ADMW1001_HOST_COMMS_CMD_RESP_1)); |
Vkadaba | 6:9d393a9677f4 | 809 | |
Vkadaba | 6:9d393a9677f4 | 810 | eRet = admw_SpiTransfer(pCtx->hSpi, pData, NULL, nLength, false); |
Vkadaba | 6:9d393a9677f4 | 811 | if (eRet) |
Vkadaba | 6:9d393a9677f4 | 812 | { |
Vkadaba | 6:9d393a9677f4 | 813 | ADMW_LOG_ERROR("Failed to write data (%dB) to register %u", |
Vkadaba | 6:9d393a9677f4 | 814 | nLength, nAddress); |
Vkadaba | 6:9d393a9677f4 | 815 | return eRet; |
Vkadaba | 6:9d393a9677f4 | 816 | } |
Vkadaba | 6:9d393a9677f4 | 817 | |
Vkadaba | 6:9d393a9677f4 | 818 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 6:9d393a9677f4 | 819 | |
Vkadaba | 6:9d393a9677f4 | 820 | return ADMW_SUCCESS; |
Vkadaba | 6:9d393a9677f4 | 821 | } |
Vkadaba | 5:0728bde67bdb | 822 | ADMW_RESULT admw1001_ReadRegister( |
Vkadaba | 5:0728bde67bdb | 823 | ADMW_DEVICE_HANDLE hDevice, |
ADIJake | 0:85855ecd3257 | 824 | uint16_t nAddress, |
ADIJake | 0:85855ecd3257 | 825 | void *pData, |
ADIJake | 0:85855ecd3257 | 826 | unsigned nLength) |
ADIJake | 0:85855ecd3257 | 827 | { |
Vkadaba | 5:0728bde67bdb | 828 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 829 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 5:0728bde67bdb | 830 | uint16_t command = ADMW1001_HOST_COMMS_READ_CMD | |
Vkadaba | 5:0728bde67bdb | 831 | (nAddress & ADMW1001_HOST_COMMS_ADR_MASK); |
ADIJake | 0:85855ecd3257 | 832 | uint8_t commandData[2] = { |
ADIJake | 0:85855ecd3257 | 833 | command >> 8, |
ADIJake | 0:85855ecd3257 | 834 | command & 0xFF |
ADIJake | 0:85855ecd3257 | 835 | }; |
ADIJake | 0:85855ecd3257 | 836 | uint8_t commandResponse[2]; |
ADIJake | 0:85855ecd3257 | 837 | |
ADIJake | 0:85855ecd3257 | 838 | do { |
Vkadaba | 5:0728bde67bdb | 839 | eRet = admw_SpiTransfer(pCtx->hSpi, commandData, commandResponse, |
ADIJake | 0:85855ecd3257 | 840 | sizeof(command), false); |
ADIJake | 0:85855ecd3257 | 841 | if (eRet) |
ADIJake | 0:85855ecd3257 | 842 | { |
Vkadaba | 5:0728bde67bdb | 843 | ADMW_LOG_ERROR("Failed to send read command for register %u", |
ADIJake | 0:85855ecd3257 | 844 | nAddress); |
ADIJake | 0:85855ecd3257 | 845 | return eRet; |
ADIJake | 0:85855ecd3257 | 846 | } |
ADIJake | 0:85855ecd3257 | 847 | |
Vkadaba | 5:0728bde67bdb | 848 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 5:0728bde67bdb | 849 | } while ((commandResponse[0] != ADMW1001_HOST_COMMS_CMD_RESP_0) || |
Vkadaba | 5:0728bde67bdb | 850 | (commandResponse[1] != ADMW1001_HOST_COMMS_CMD_RESP_1)); |
Vkadaba | 5:0728bde67bdb | 851 | |
Vkadaba | 5:0728bde67bdb | 852 | eRet = admw_SpiTransfer(pCtx->hSpi, NULL, pData, nLength, false); |
ADIJake | 0:85855ecd3257 | 853 | if (eRet) |
ADIJake | 0:85855ecd3257 | 854 | { |
Vkadaba | 5:0728bde67bdb | 855 | ADMW_LOG_ERROR("Failed to read data (%uB) from register %u", |
ADIJake | 0:85855ecd3257 | 856 | nLength, nAddress); |
ADIJake | 0:85855ecd3257 | 857 | return eRet; |
ADIJake | 0:85855ecd3257 | 858 | } |
ADIJake | 0:85855ecd3257 | 859 | |
Vkadaba | 5:0728bde67bdb | 860 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 5:0728bde67bdb | 861 | |
Vkadaba | 5:0728bde67bdb | 862 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 863 | } |
ADIJake | 0:85855ecd3257 | 864 | |
Vkadaba | 6:9d393a9677f4 | 865 | ADMW_RESULT admw1001_Read_Debug_Register( |
Vkadaba | 6:9d393a9677f4 | 866 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 6:9d393a9677f4 | 867 | uint16_t nAddress, |
Vkadaba | 6:9d393a9677f4 | 868 | void *pData, |
Vkadaba | 6:9d393a9677f4 | 869 | unsigned nLength) |
Vkadaba | 6:9d393a9677f4 | 870 | { |
Vkadaba | 6:9d393a9677f4 | 871 | ADMW_RESULT eRet; |
Vkadaba | 6:9d393a9677f4 | 872 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 6:9d393a9677f4 | 873 | uint16_t command = ADMW1001_HOST_COMMS_DEBUG_READ_CMD | |
Vkadaba | 6:9d393a9677f4 | 874 | (nAddress & ADMW1001_HOST_COMMS_ADR_MASK); |
Vkadaba | 6:9d393a9677f4 | 875 | uint8_t commandData[2] = { |
Vkadaba | 6:9d393a9677f4 | 876 | command >> 8, |
Vkadaba | 6:9d393a9677f4 | 877 | command & 0xFF |
Vkadaba | 6:9d393a9677f4 | 878 | }; |
Vkadaba | 6:9d393a9677f4 | 879 | uint8_t commandResponse[2]; |
Vkadaba | 6:9d393a9677f4 | 880 | |
Vkadaba | 6:9d393a9677f4 | 881 | do { |
Vkadaba | 6:9d393a9677f4 | 882 | eRet = admw_SpiTransfer(pCtx->hSpi, commandData, commandResponse, |
Vkadaba | 6:9d393a9677f4 | 883 | sizeof(command), false); |
Vkadaba | 6:9d393a9677f4 | 884 | if (eRet) |
Vkadaba | 6:9d393a9677f4 | 885 | { |
Vkadaba | 6:9d393a9677f4 | 886 | ADMW_LOG_ERROR("Failed to send read command for register %u", |
Vkadaba | 6:9d393a9677f4 | 887 | nAddress); |
Vkadaba | 6:9d393a9677f4 | 888 | return eRet; |
Vkadaba | 6:9d393a9677f4 | 889 | } |
Vkadaba | 6:9d393a9677f4 | 890 | |
Vkadaba | 6:9d393a9677f4 | 891 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 6:9d393a9677f4 | 892 | } while ((commandResponse[0] != ADMW1001_HOST_COMMS_CMD_RESP_0) || |
Vkadaba | 6:9d393a9677f4 | 893 | (commandResponse[1] != ADMW1001_HOST_COMMS_CMD_RESP_1)); |
Vkadaba | 6:9d393a9677f4 | 894 | |
Vkadaba | 6:9d393a9677f4 | 895 | eRet = admw_SpiTransfer(pCtx->hSpi, NULL, pData, nLength, false); |
Vkadaba | 6:9d393a9677f4 | 896 | if (eRet) |
Vkadaba | 6:9d393a9677f4 | 897 | { |
Vkadaba | 6:9d393a9677f4 | 898 | ADMW_LOG_ERROR("Failed to read data (%uB) from register %u", |
Vkadaba | 6:9d393a9677f4 | 899 | nLength, nAddress); |
Vkadaba | 6:9d393a9677f4 | 900 | return eRet; |
Vkadaba | 6:9d393a9677f4 | 901 | } |
Vkadaba | 6:9d393a9677f4 | 902 | |
Vkadaba | 6:9d393a9677f4 | 903 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 6:9d393a9677f4 | 904 | |
Vkadaba | 6:9d393a9677f4 | 905 | return ADMW_SUCCESS; |
Vkadaba | 6:9d393a9677f4 | 906 | } |
Vkadaba | 5:0728bde67bdb | 907 | ADMW_RESULT admw_GetDeviceReadyState( |
Vkadaba | 5:0728bde67bdb | 908 | ADMW_DEVICE_HANDLE const hDevice, |
ADIJake | 0:85855ecd3257 | 909 | bool * const bReady) |
ADIJake | 0:85855ecd3257 | 910 | { |
Vkadaba | 5:0728bde67bdb | 911 | ADMW_SPI_Chip_Type_t chipTypeReg; |
ADIJake | 0:85855ecd3257 | 912 | |
ADIJake | 0:85855ecd3257 | 913 | READ_REG_U8(hDevice, chipTypeReg.VALUE8, SPI_CHIP_TYPE); |
ADIJake | 0:85855ecd3257 | 914 | /* If we read this register successfully, assume the device is ready */ |
Vkadaba | 5:0728bde67bdb | 915 | *bReady = (chipTypeReg.VALUE8 == REG_SPI_CHIP_TYPE_RESET); |
Vkadaba | 5:0728bde67bdb | 916 | |
Vkadaba | 5:0728bde67bdb | 917 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 918 | } |
ADIJake | 0:85855ecd3257 | 919 | |
Vkadaba | 5:0728bde67bdb | 920 | ADMW_RESULT admw1001_GetDataReadyModeInfo( |
Vkadaba | 5:0728bde67bdb | 921 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 922 | ADMW_MEASUREMENT_MODE const eMeasurementMode, |
Vkadaba | 5:0728bde67bdb | 923 | ADMW1001_OPERATING_MODE * const peOperatingMode, |
Vkadaba | 5:0728bde67bdb | 924 | ADMW1001_DATAREADY_MODE * const peDataReadyMode, |
ADIJake | 0:85855ecd3257 | 925 | uint32_t * const pnSamplesPerDataready, |
ADIJake | 0:85855ecd3257 | 926 | uint32_t * const pnSamplesPerCycle, |
ADIJake | 0:85855ecd3257 | 927 | uint8_t * const pnBytesPerSample) |
ADIJake | 0:85855ecd3257 | 928 | { |
ADIJake | 0:85855ecd3257 | 929 | unsigned nChannelsEnabled = 0; |
ADIJake | 0:85855ecd3257 | 930 | unsigned nSamplesPerCycle = 0; |
ADIJake | 0:85855ecd3257 | 931 | |
Vkadaba | 5:0728bde67bdb | 932 | CORE_Mode_t modeReg; |
ADIJake | 0:85855ecd3257 | 933 | READ_REG_U8(hDevice, modeReg.VALUE8, CORE_MODE); |
ADIJake | 0:85855ecd3257 | 934 | |
Vkadaba | 6:9d393a9677f4 | 935 | if (eMeasurementMode == (modeReg.Conversion_Mode == CORE_MODE_SINGLECYCLE)) |
Vkadaba | 5:0728bde67bdb | 936 | *peOperatingMode = ADMW1001_OPERATING_MODE_SINGLECYCLE; |
Vkadaba | 5:0728bde67bdb | 937 | else if (modeReg.Conversion_Mode == CORE_MODE_MULTICYCLE) |
Vkadaba | 5:0728bde67bdb | 938 | *peOperatingMode = ADMW1001_OPERATING_MODE_MULTICYCLE; |
ADIJake | 0:85855ecd3257 | 939 | else |
Vkadaba | 5:0728bde67bdb | 940 | *peOperatingMode = ADMW1001_OPERATING_MODE_CONTINUOUS; |
ADIJake | 0:85855ecd3257 | 941 | |
Vkadaba | 6:9d393a9677f4 | 942 | if (eMeasurementMode == ADMW_MEASUREMENT_MODE_OMIT_RAW) |
ADIJake | 0:85855ecd3257 | 943 | { |
Vkadaba | 6:9d393a9677f4 | 944 | *pnBytesPerSample = 5; |
ADIJake | 0:85855ecd3257 | 945 | } |
ADIJake | 0:85855ecd3257 | 946 | else |
ADIJake | 0:85855ecd3257 | 947 | { |
Vkadaba | 6:9d393a9677f4 | 948 | *pnBytesPerSample = 8; |
Vkadaba | 6:9d393a9677f4 | 949 | } |
Vkadaba | 6:9d393a9677f4 | 950 | |
Vkadaba | 6:9d393a9677f4 | 951 | for (ADMW1001_CHANNEL_ID chId = ADMW1001_CHANNEL_ID_ANALOG_1_UNIVERSAL; |
Vkadaba | 6:9d393a9677f4 | 952 | chId < ADMW1001_MAX_CHANNELS; |
Vkadaba | 6:9d393a9677f4 | 953 | chId++) |
Vkadaba | 6:9d393a9677f4 | 954 | { |
Vkadaba | 6:9d393a9677f4 | 955 | CORE_Sensor_Details_t sensorDetailsReg; |
Vkadaba | 6:9d393a9677f4 | 956 | CORE_Channel_Count_t channelCountReg; |
Vkadaba | 6:9d393a9677f4 | 957 | |
Vkadaba | 6:9d393a9677f4 | 958 | if (ADMW1001_CHANNEL_IS_VIRTUAL(chId)) |
Vkadaba | 6:9d393a9677f4 | 959 | continue; |
Vkadaba | 6:9d393a9677f4 | 960 | |
Vkadaba | 6:9d393a9677f4 | 961 | READ_REG_U8(hDevice, channelCountReg.VALUE8, CORE_CHANNEL_COUNTn(chId)); |
Vkadaba | 6:9d393a9677f4 | 962 | READ_REG_U32(hDevice, sensorDetailsReg.VALUE32, CORE_SENSOR_DETAILSn(chId)); |
Vkadaba | 6:9d393a9677f4 | 963 | |
Vkadaba | 6:9d393a9677f4 | 964 | if (channelCountReg.Channel_Enable && !sensorDetailsReg.Do_Not_Publish) |
Vkadaba | 6:9d393a9677f4 | 965 | { |
Vkadaba | 6:9d393a9677f4 | 966 | CORE_Sensor_Type_t sensorTypeReg; |
Vkadaba | 6:9d393a9677f4 | 967 | unsigned nActualChannels = 1; |
Vkadaba | 6:9d393a9677f4 | 968 | |
Vkadaba | 6:9d393a9677f4 | 969 | READ_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(chId)); |
Vkadaba | 6:9d393a9677f4 | 970 | |
Vkadaba | 6:9d393a9677f4 | 971 | if (chId == ADMW1001_CHANNEL_ID_SPI_0) |
ADIJake | 0:85855ecd3257 | 972 | { |
Vkadaba | 6:9d393a9677f4 | 973 | /* Some sensors automatically generate samples on additional "virtual" channels |
Vkadaba | 6:9d393a9677f4 | 974 | * so these channels must be counted as active when those sensors are selected |
Vkadaba | 6:9d393a9677f4 | 975 | * and we use the count from the corresponding "physical" channel */ |
Vkadaba | 6:9d393a9677f4 | 976 | if ((sensorTypeReg.Sensor_Type >= |
Vkadaba | 6:9d393a9677f4 | 977 | CORE_SENSOR_TYPE_SPI_ACCELEROMETER_A) && |
Vkadaba | 6:9d393a9677f4 | 978 | (sensorTypeReg.Sensor_Type <= |
Vkadaba | 6:9d393a9677f4 | 979 | CORE_SENSOR_TYPE_SPI_ACCELEROMETER_B)) |
Vkadaba | 6:9d393a9677f4 | 980 | nActualChannels += 2; |
ADIJake | 0:85855ecd3257 | 981 | } |
Vkadaba | 6:9d393a9677f4 | 982 | |
Vkadaba | 6:9d393a9677f4 | 983 | nChannelsEnabled += nActualChannels; |
Vkadaba | 6:9d393a9677f4 | 984 | |
Vkadaba | 6:9d393a9677f4 | 985 | nSamplesPerCycle += nActualChannels * |
Vkadaba | 6:9d393a9677f4 | 986 | (channelCountReg.Channel_Count + 1); |
Vkadaba | 6:9d393a9677f4 | 987 | } |
Vkadaba | 6:9d393a9677f4 | 988 | } |
Vkadaba | 6:9d393a9677f4 | 989 | |
Vkadaba | 6:9d393a9677f4 | 990 | if (nChannelsEnabled == 0) |
Vkadaba | 6:9d393a9677f4 | 991 | { |
Vkadaba | 6:9d393a9677f4 | 992 | *pnSamplesPerDataready = 0; |
Vkadaba | 6:9d393a9677f4 | 993 | *pnSamplesPerCycle = 0; |
Vkadaba | 6:9d393a9677f4 | 994 | return ADMW_SUCCESS; |
Vkadaba | 6:9d393a9677f4 | 995 | } |
Vkadaba | 6:9d393a9677f4 | 996 | |
Vkadaba | 6:9d393a9677f4 | 997 | *pnSamplesPerCycle = nSamplesPerCycle; |
Vkadaba | 6:9d393a9677f4 | 998 | |
Vkadaba | 6:9d393a9677f4 | 999 | if (modeReg.Drdy_Mode == ENUM_CORE_MODE_DRDY_PER_CONVERSION) |
Vkadaba | 6:9d393a9677f4 | 1000 | { |
Vkadaba | 6:9d393a9677f4 | 1001 | *pnSamplesPerDataready = 1; |
Vkadaba | 6:9d393a9677f4 | 1002 | } |
Vkadaba | 6:9d393a9677f4 | 1003 | else if (modeReg.Drdy_Mode == ENUM_CORE_MODE_DRDY_PER_CYCLE) |
Vkadaba | 6:9d393a9677f4 | 1004 | { |
Vkadaba | 6:9d393a9677f4 | 1005 | *pnSamplesPerDataready = nSamplesPerCycle; |
Vkadaba | 6:9d393a9677f4 | 1006 | } |
Vkadaba | 6:9d393a9677f4 | 1007 | else |
Vkadaba | 6:9d393a9677f4 | 1008 | { |
Vkadaba | 6:9d393a9677f4 | 1009 | CORE_Fifo_Num_Cycles_t fifoNumCyclesReg; |
Vkadaba | 6:9d393a9677f4 | 1010 | READ_REG_U8(hDevice, fifoNumCyclesReg.VALUE8, CORE_FIFO_NUM_CYCLES); |
Vkadaba | 6:9d393a9677f4 | 1011 | |
Vkadaba | 6:9d393a9677f4 | 1012 | *pnSamplesPerDataready = |
Vkadaba | 6:9d393a9677f4 | 1013 | nSamplesPerCycle * fifoNumCyclesReg.Fifo_Num_Cycles; |
Vkadaba | 6:9d393a9677f4 | 1014 | } |
Vkadaba | 6:9d393a9677f4 | 1015 | |
Vkadaba | 6:9d393a9677f4 | 1016 | if (modeReg.Drdy_Mode == ENUM_CORE_MODE_DRDY_PER_CONVERSION) |
Vkadaba | 6:9d393a9677f4 | 1017 | *peDataReadyMode = ADMW1001_DATAREADY_PER_CONVERSION; |
Vkadaba | 6:9d393a9677f4 | 1018 | else if (modeReg.Drdy_Mode == ENUM_CORE_MODE_DRDY_PER_CYCLE) |
Vkadaba | 6:9d393a9677f4 | 1019 | *peDataReadyMode = ADMW1001_DATAREADY_PER_CYCLE; |
Vkadaba | 6:9d393a9677f4 | 1020 | else |
Vkadaba | 6:9d393a9677f4 | 1021 | { |
Vkadaba | 6:9d393a9677f4 | 1022 | *peDataReadyMode = ADMW1001_DATAREADY_PER_MULTICYCLE_BURST; |
ADIJake | 0:85855ecd3257 | 1023 | } |
ADIJake | 0:85855ecd3257 | 1024 | |
Vkadaba | 5:0728bde67bdb | 1025 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1026 | } |
ADIJake | 0:85855ecd3257 | 1027 | |
Vkadaba | 5:0728bde67bdb | 1028 | ADMW_RESULT admw_GetProductID( |
Vkadaba | 5:0728bde67bdb | 1029 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1030 | ADMW_PRODUCT_ID *pProductId) |
ADIJake | 0:85855ecd3257 | 1031 | { |
Vkadaba | 5:0728bde67bdb | 1032 | ADMW_SPI_Product_ID_L_t productIdLoReg; |
Vkadaba | 5:0728bde67bdb | 1033 | ADMW_SPI_Product_ID_H_t productIdHiReg; |
ADIJake | 0:85855ecd3257 | 1034 | |
ADIJake | 0:85855ecd3257 | 1035 | READ_REG_U8(hDevice, productIdLoReg.VALUE8, SPI_PRODUCT_ID_L); |
ADIJake | 0:85855ecd3257 | 1036 | READ_REG_U8(hDevice, productIdHiReg.VALUE8, SPI_PRODUCT_ID_H); |
ADIJake | 0:85855ecd3257 | 1037 | |
Vkadaba | 5:0728bde67bdb | 1038 | *pProductId = (ADMW_PRODUCT_ID)((productIdHiReg.VALUE8 << 8) |
ADIJake | 0:85855ecd3257 | 1039 | | productIdLoReg.VALUE8); |
Vkadaba | 5:0728bde67bdb | 1040 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1041 | } |
ADIJake | 0:85855ecd3257 | 1042 | |
Vkadaba | 5:0728bde67bdb | 1043 | static ADMW_RESULT admw_SetPowerMode( |
Vkadaba | 5:0728bde67bdb | 1044 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1045 | ADMW1001_POWER_MODE powerMode) |
ADIJake | 0:85855ecd3257 | 1046 | { |
Vkadaba | 5:0728bde67bdb | 1047 | CORE_Power_Config_t powerConfigReg; |
Vkadaba | 5:0728bde67bdb | 1048 | |
Vkadaba | 6:9d393a9677f4 | 1049 | if (powerMode == ADMW1001_POWER_MODE_HIBERNATION) |
ADIJake | 0:85855ecd3257 | 1050 | { |
Vkadaba | 6:9d393a9677f4 | 1051 | powerConfigReg.Power_Mode_MCU = CORE_POWER_CONFIG_HIBERNATION; |
ADIJake | 0:85855ecd3257 | 1052 | } |
Vkadaba | 6:9d393a9677f4 | 1053 | else if (powerMode == ADMW1001_POWER_MODE_ACTIVE) |
ADIJake | 0:85855ecd3257 | 1054 | { |
Vkadaba | 6:9d393a9677f4 | 1055 | powerConfigReg.Power_Mode_MCU = CORE_POWER_CONFIG_ACTIVE_MODE; |
ADIJake | 0:85855ecd3257 | 1056 | } |
ADIJake | 0:85855ecd3257 | 1057 | else |
ADIJake | 0:85855ecd3257 | 1058 | { |
Vkadaba | 5:0728bde67bdb | 1059 | ADMW_LOG_ERROR("Invalid power mode %d specified", powerMode); |
Vkadaba | 5:0728bde67bdb | 1060 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1061 | } |
ADIJake | 0:85855ecd3257 | 1062 | |
ADIJake | 0:85855ecd3257 | 1063 | WRITE_REG_U8(hDevice, powerConfigReg.VALUE8, CORE_POWER_CONFIG); |
ADIJake | 0:85855ecd3257 | 1064 | |
Vkadaba | 5:0728bde67bdb | 1065 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1066 | } |
ADIJake | 0:85855ecd3257 | 1067 | |
Vkadaba | 5:0728bde67bdb | 1068 | ADMW_RESULT admw1001_SetPowerConfig( |
Vkadaba | 5:0728bde67bdb | 1069 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1070 | ADMW1001_POWER_CONFIG *pPowerConfig) |
ADIJake | 0:85855ecd3257 | 1071 | { |
Vkadaba | 5:0728bde67bdb | 1072 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 1073 | |
Vkadaba | 5:0728bde67bdb | 1074 | eRet = admw_SetPowerMode(hDevice, pPowerConfig->powerMode); |
Vkadaba | 5:0728bde67bdb | 1075 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 1076 | { |
Vkadaba | 5:0728bde67bdb | 1077 | ADMW_LOG_ERROR("Failed to set power mode"); |
ADIJake | 0:85855ecd3257 | 1078 | return eRet; |
ADIJake | 0:85855ecd3257 | 1079 | } |
ADIJake | 0:85855ecd3257 | 1080 | |
Vkadaba | 5:0728bde67bdb | 1081 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1082 | } |
ADIJake | 0:85855ecd3257 | 1083 | |
Vkadaba | 5:0728bde67bdb | 1084 | static ADMW_RESULT admw_SetMode( |
Vkadaba | 5:0728bde67bdb | 1085 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1086 | ADMW1001_OPERATING_MODE eOperatingMode, |
Vkadaba | 5:0728bde67bdb | 1087 | ADMW1001_DATAREADY_MODE eDataReadyMode, |
ADIJake | 0:85855ecd3257 | 1088 | bool bEnableExtFlash) |
ADIJake | 0:85855ecd3257 | 1089 | { |
Vkadaba | 5:0728bde67bdb | 1090 | CORE_Mode_t modeReg; |
ADIJake | 0:85855ecd3257 | 1091 | |
ADIJake | 0:85855ecd3257 | 1092 | modeReg.VALUE8 = REG_RESET_VAL(CORE_MODE); |
ADIJake | 0:85855ecd3257 | 1093 | |
Vkadaba | 5:0728bde67bdb | 1094 | if (eOperatingMode == ADMW1001_OPERATING_MODE_SINGLECYCLE) |
ADIJake | 0:85855ecd3257 | 1095 | { |
Vkadaba | 5:0728bde67bdb | 1096 | modeReg.Conversion_Mode = CORE_MODE_SINGLECYCLE; |
ADIJake | 0:85855ecd3257 | 1097 | } |
Vkadaba | 5:0728bde67bdb | 1098 | else if (eOperatingMode == ADMW1001_OPERATING_MODE_CONTINUOUS) |
ADIJake | 0:85855ecd3257 | 1099 | { |
Vkadaba | 5:0728bde67bdb | 1100 | modeReg.Conversion_Mode = CORE_MODE_CONTINUOUS; |
ADIJake | 0:85855ecd3257 | 1101 | } |
Vkadaba | 5:0728bde67bdb | 1102 | else if (eOperatingMode == ADMW1001_OPERATING_MODE_MULTICYCLE) |
ADIJake | 0:85855ecd3257 | 1103 | { |
Vkadaba | 5:0728bde67bdb | 1104 | modeReg.Conversion_Mode = CORE_MODE_MULTICYCLE; |
ADIJake | 0:85855ecd3257 | 1105 | } |
ADIJake | 0:85855ecd3257 | 1106 | else |
ADIJake | 0:85855ecd3257 | 1107 | { |
Vkadaba | 5:0728bde67bdb | 1108 | ADMW_LOG_ERROR("Invalid operating mode %d specified", |
ADIJake | 0:85855ecd3257 | 1109 | eOperatingMode); |
Vkadaba | 5:0728bde67bdb | 1110 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1111 | } |
ADIJake | 0:85855ecd3257 | 1112 | |
Vkadaba | 5:0728bde67bdb | 1113 | if (eDataReadyMode == ADMW1001_DATAREADY_PER_CONVERSION) |
ADIJake | 0:85855ecd3257 | 1114 | { |
Vkadaba | 5:0728bde67bdb | 1115 | modeReg.Drdy_Mode = CORE_MODE_DRDY_PER_CONVERSION; |
ADIJake | 0:85855ecd3257 | 1116 | } |
Vkadaba | 5:0728bde67bdb | 1117 | else if (eDataReadyMode == ADMW1001_DATAREADY_PER_CYCLE) |
ADIJake | 0:85855ecd3257 | 1118 | { |
Vkadaba | 5:0728bde67bdb | 1119 | modeReg.Drdy_Mode = CORE_MODE_DRDY_PER_CYCLE; |
ADIJake | 0:85855ecd3257 | 1120 | } |
Vkadaba | 5:0728bde67bdb | 1121 | else if (eDataReadyMode == ADMW1001_DATAREADY_PER_MULTICYCLE_BURST) |
ADIJake | 0:85855ecd3257 | 1122 | { |
Vkadaba | 5:0728bde67bdb | 1123 | if (eOperatingMode != ADMW1001_OPERATING_MODE_MULTICYCLE) |
ADIJake | 0:85855ecd3257 | 1124 | { |
Vkadaba | 5:0728bde67bdb | 1125 | ADMW_LOG_ERROR( |
ADIJake | 0:85855ecd3257 | 1126 | "Data-ready mode %d cannot be used with operating mode %d", |
ADIJake | 0:85855ecd3257 | 1127 | eDataReadyMode, eOperatingMode); |
Vkadaba | 5:0728bde67bdb | 1128 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1129 | } |
ADIJake | 0:85855ecd3257 | 1130 | else |
ADIJake | 0:85855ecd3257 | 1131 | { |
Vkadaba | 5:0728bde67bdb | 1132 | modeReg.Drdy_Mode = CORE_MODE_DRDY_PER_FIFO_FILL; |
ADIJake | 0:85855ecd3257 | 1133 | } |
ADIJake | 0:85855ecd3257 | 1134 | } |
ADIJake | 0:85855ecd3257 | 1135 | else |
ADIJake | 0:85855ecd3257 | 1136 | { |
Vkadaba | 5:0728bde67bdb | 1137 | ADMW_LOG_ERROR("Invalid data-ready mode %d specified", eDataReadyMode); |
Vkadaba | 5:0728bde67bdb | 1138 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1139 | } |
ADIJake | 0:85855ecd3257 | 1140 | |
ADIJake | 0:85855ecd3257 | 1141 | WRITE_REG_U8(hDevice, modeReg.VALUE8, CORE_MODE); |
ADIJake | 0:85855ecd3257 | 1142 | |
Vkadaba | 5:0728bde67bdb | 1143 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1144 | } |
ADIJake | 0:85855ecd3257 | 1145 | |
Vkadaba | 5:0728bde67bdb | 1146 | ADMW_RESULT admw_SetCycleControl( |
Vkadaba | 5:0728bde67bdb | 1147 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 6:9d393a9677f4 | 1148 | uint32_t nCycleInterval |
ADIJake | 0:85855ecd3257 | 1149 | |
ADIJake | 0:85855ecd3257 | 1150 | #ifdef __V2_3_CFG_FMT__ |
Vkadaba | 6:9d393a9677f4 | 1151 | , ADMW1001_CYCLE_TYPE eCycleType, |
Vkadaba | 5:0728bde67bdb | 1152 | ADMW1001_FILTER_SETTLING eFilterSettling) |
ADIJake | 0:85855ecd3257 | 1153 | #else |
Vkadaba | 6:9d393a9677f4 | 1154 | ) |
ADIJake | 0:85855ecd3257 | 1155 | #endif |
ADIJake | 0:85855ecd3257 | 1156 | { |
Vkadaba | 5:0728bde67bdb | 1157 | CORE_Cycle_Control_t cycleControlReg; |
ADIJake | 0:85855ecd3257 | 1158 | |
ADIJake | 0:85855ecd3257 | 1159 | cycleControlReg.VALUE16 = REG_RESET_VAL(CORE_CYCLE_CONTROL); |
ADIJake | 0:85855ecd3257 | 1160 | |
ADIJake | 0:85855ecd3257 | 1161 | if (nCycleInterval < (1 << 12)) |
ADIJake | 0:85855ecd3257 | 1162 | { |
Vkadaba | 5:0728bde67bdb | 1163 | cycleControlReg.Cycle_Time_Units = CORE_CYCLE_CONTROL_MICROSECONDS; |
ADIJake | 0:85855ecd3257 | 1164 | } |
ADIJake | 0:85855ecd3257 | 1165 | else if (nCycleInterval < (1000 * (1 << 12))) |
ADIJake | 0:85855ecd3257 | 1166 | { |
Vkadaba | 5:0728bde67bdb | 1167 | cycleControlReg.Cycle_Time_Units = CORE_CYCLE_CONTROL_MILLISECONDS; |
ADIJake | 0:85855ecd3257 | 1168 | nCycleInterval /= 1000; |
ADIJake | 0:85855ecd3257 | 1169 | } |
ADIJake | 0:85855ecd3257 | 1170 | else |
ADIJake | 0:85855ecd3257 | 1171 | { |
Vkadaba | 5:0728bde67bdb | 1172 | cycleControlReg.Cycle_Time_Units = CORE_CYCLE_CONTROL_SECONDS; |
ADIJake | 0:85855ecd3257 | 1173 | nCycleInterval /= 1000000; |
ADIJake | 0:85855ecd3257 | 1174 | } |
ADIJake | 0:85855ecd3257 | 1175 | |
ADIJake | 0:85855ecd3257 | 1176 | CHECK_REG_FIELD_VAL(CORE_CYCLE_CONTROL_CYCLE_TIME, nCycleInterval); |
ADIJake | 0:85855ecd3257 | 1177 | cycleControlReg.Cycle_Time = nCycleInterval; |
ADIJake | 0:85855ecd3257 | 1178 | |
ADIJake | 0:85855ecd3257 | 1179 | #ifdef __V2_3_CFG_FMT__ |
Vkadaba | 5:0728bde67bdb | 1180 | if (eFilterSettling == ADMW1001_FILTER_SETTLING_ALWAYS) |
ADIJake | 0:85855ecd3257 | 1181 | { |
Vkadaba | 5:0728bde67bdb | 1182 | cycleControlReg.Filter_Settling = CORE_CYCLE_CONTROL_FILTER_SETTLING_SETTLED; |
ADIJake | 0:85855ecd3257 | 1183 | } |
Vkadaba | 5:0728bde67bdb | 1184 | else if (eFilterSettling == ADMW1001_FILTER_SETTLING_FAST) |
ADIJake | 0:85855ecd3257 | 1185 | { |
Vkadaba | 5:0728bde67bdb | 1186 | cycleControlReg.Filter_Settling = CORE_CYCLE_CONTROL_FILTER_SETTLING_FAST; |
ADIJake | 0:85855ecd3257 | 1187 | } |
ADIJake | 0:85855ecd3257 | 1188 | else |
ADIJake | 0:85855ecd3257 | 1189 | { |
Vkadaba | 5:0728bde67bdb | 1190 | ADMW_LOG_ERROR("Invalid filter settling option %d specified", eFilterSettling); |
Vkadaba | 5:0728bde67bdb | 1191 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1192 | } |
ADIJake | 0:85855ecd3257 | 1193 | #endif |
ADIJake | 0:85855ecd3257 | 1194 | |
ADIJake | 0:85855ecd3257 | 1195 | WRITE_REG_U16(hDevice, cycleControlReg.VALUE16, CORE_CYCLE_CONTROL); |
ADIJake | 0:85855ecd3257 | 1196 | |
Vkadaba | 5:0728bde67bdb | 1197 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1198 | } |
ADIJake | 0:85855ecd3257 | 1199 | |
Vkadaba | 5:0728bde67bdb | 1200 | static ADMW_RESULT admw_SetMultiCycleConfig( |
Vkadaba | 5:0728bde67bdb | 1201 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1202 | ADMW1001_MULTICYCLE_CONFIG *pMultiCycleConfig) |
ADIJake | 0:85855ecd3257 | 1203 | { |
ADIJake | 0:85855ecd3257 | 1204 | CHECK_REG_FIELD_VAL(CORE_FIFO_NUM_CYCLES_FIFO_NUM_CYCLES, |
ADIJake | 0:85855ecd3257 | 1205 | pMultiCycleConfig->cyclesPerBurst); |
ADIJake | 0:85855ecd3257 | 1206 | |
ADIJake | 0:85855ecd3257 | 1207 | WRITE_REG_U8(hDevice, pMultiCycleConfig->cyclesPerBurst, |
ADIJake | 0:85855ecd3257 | 1208 | CORE_FIFO_NUM_CYCLES); |
ADIJake | 0:85855ecd3257 | 1209 | |
ADIJake | 0:85855ecd3257 | 1210 | WRITE_REG_U32(hDevice, pMultiCycleConfig->burstInterval, |
ADIJake | 0:85855ecd3257 | 1211 | CORE_MULTI_CYCLE_REPEAT_INTERVAL); |
ADIJake | 0:85855ecd3257 | 1212 | |
Vkadaba | 5:0728bde67bdb | 1213 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1214 | } |
ADIJake | 0:85855ecd3257 | 1215 | |
Vkadaba | 5:0728bde67bdb | 1216 | static ADMW_RESULT admw_SetExternalReferenceValues( |
Vkadaba | 5:0728bde67bdb | 1217 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 6:9d393a9677f4 | 1218 | float32_t externalRef1Value) |
ADIJake | 0:85855ecd3257 | 1219 | { |
Vkadaba | 6:9d393a9677f4 | 1220 | WRITE_REG_FLOAT(hDevice, externalRef1Value, CORE_EXTERNAL_REFERENCE_RESISTOR); |
ADIJake | 0:85855ecd3257 | 1221 | |
Vkadaba | 5:0728bde67bdb | 1222 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1223 | } |
ADIJake | 0:85855ecd3257 | 1224 | |
Vkadaba | 5:0728bde67bdb | 1225 | ADMW_RESULT admw1001_SetMeasurementConfig( |
Vkadaba | 5:0728bde67bdb | 1226 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1227 | ADMW1001_MEASUREMENT_CONFIG *pMeasConfig) |
ADIJake | 0:85855ecd3257 | 1228 | { |
Vkadaba | 5:0728bde67bdb | 1229 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 1230 | |
Vkadaba | 5:0728bde67bdb | 1231 | eRet = admw_SetMode(hDevice, |
ADIJake | 0:85855ecd3257 | 1232 | pMeasConfig->operatingMode, |
ADIJake | 0:85855ecd3257 | 1233 | pMeasConfig->dataReadyMode, |
ADIJake | 0:85855ecd3257 | 1234 | pMeasConfig->enableExternalFlash); |
Vkadaba | 5:0728bde67bdb | 1235 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 1236 | { |
Vkadaba | 5:0728bde67bdb | 1237 | ADMW_LOG_ERROR("Failed to set operating mode"); |
ADIJake | 0:85855ecd3257 | 1238 | return eRet; |
ADIJake | 0:85855ecd3257 | 1239 | } |
ADIJake | 0:85855ecd3257 | 1240 | |
Vkadaba | 5:0728bde67bdb | 1241 | eRet = admw_SetCycleControl(hDevice, |
Vkadaba | 6:9d393a9677f4 | 1242 | pMeasConfig->cycleInterval); |
Vkadaba | 5:0728bde67bdb | 1243 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 1244 | { |
Vkadaba | 5:0728bde67bdb | 1245 | ADMW_LOG_ERROR("Failed to set cycle control"); |
ADIJake | 0:85855ecd3257 | 1246 | return eRet; |
ADIJake | 0:85855ecd3257 | 1247 | } |
ADIJake | 0:85855ecd3257 | 1248 | |
Vkadaba | 5:0728bde67bdb | 1249 | if (pMeasConfig->operatingMode == ADMW1001_OPERATING_MODE_MULTICYCLE) |
ADIJake | 0:85855ecd3257 | 1250 | { |
Vkadaba | 5:0728bde67bdb | 1251 | eRet = admw_SetMultiCycleConfig(hDevice, |
ADIJake | 0:85855ecd3257 | 1252 | &pMeasConfig->multiCycleConfig); |
Vkadaba | 5:0728bde67bdb | 1253 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 1254 | { |
Vkadaba | 5:0728bde67bdb | 1255 | ADMW_LOG_ERROR("Failed to set multi-cycle configuration"); |
ADIJake | 0:85855ecd3257 | 1256 | return eRet; |
ADIJake | 0:85855ecd3257 | 1257 | } |
ADIJake | 0:85855ecd3257 | 1258 | } |
Vkadaba | 6:9d393a9677f4 | 1259 | if(pMeasConfig->externalRef1Value>0) |
Vkadaba | 6:9d393a9677f4 | 1260 | eRet = admw_SetExternalReferenceValues(hDevice, |
Vkadaba | 6:9d393a9677f4 | 1261 | pMeasConfig->externalRef1Value); |
Vkadaba | 6:9d393a9677f4 | 1262 | else |
Vkadaba | 6:9d393a9677f4 | 1263 | ; |
Vkadaba | 6:9d393a9677f4 | 1264 | |
Vkadaba | 5:0728bde67bdb | 1265 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 1266 | { |
Vkadaba | 5:0728bde67bdb | 1267 | ADMW_LOG_ERROR("Failed to set external reference values"); |
ADIJake | 0:85855ecd3257 | 1268 | return eRet; |
ADIJake | 0:85855ecd3257 | 1269 | } |
ADIJake | 0:85855ecd3257 | 1270 | |
Vkadaba | 5:0728bde67bdb | 1271 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1272 | } |
ADIJake | 0:85855ecd3257 | 1273 | |
Vkadaba | 5:0728bde67bdb | 1274 | ADMW_RESULT admw1001_SetDiagnosticsConfig( |
Vkadaba | 5:0728bde67bdb | 1275 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1276 | ADMW1001_DIAGNOSTICS_CONFIG *pDiagnosticsConfig) |
ADIJake | 0:85855ecd3257 | 1277 | { |
Vkadaba | 5:0728bde67bdb | 1278 | CORE_Diagnostics_Control_t diagnosticsControlReg; |
ADIJake | 0:85855ecd3257 | 1279 | |
ADIJake | 0:85855ecd3257 | 1280 | diagnosticsControlReg.VALUE16 = REG_RESET_VAL(CORE_DIAGNOSTICS_CONTROL); |
ADIJake | 0:85855ecd3257 | 1281 | |
ADIJake | 0:85855ecd3257 | 1282 | if (pDiagnosticsConfig->disableGlobalDiag) |
ADIJake | 0:85855ecd3257 | 1283 | diagnosticsControlReg.Diag_Global_En = 0; |
ADIJake | 0:85855ecd3257 | 1284 | else |
ADIJake | 0:85855ecd3257 | 1285 | diagnosticsControlReg.Diag_Global_En = 1; |
ADIJake | 0:85855ecd3257 | 1286 | |
ADIJake | 0:85855ecd3257 | 1287 | if (pDiagnosticsConfig->disableMeasurementDiag) |
ADIJake | 0:85855ecd3257 | 1288 | diagnosticsControlReg.Diag_Meas_En = 0; |
ADIJake | 0:85855ecd3257 | 1289 | else |
ADIJake | 0:85855ecd3257 | 1290 | diagnosticsControlReg.Diag_Meas_En = 1; |
ADIJake | 0:85855ecd3257 | 1291 | |
ADIJake | 0:85855ecd3257 | 1292 | switch (pDiagnosticsConfig->osdFrequency) |
ADIJake | 0:85855ecd3257 | 1293 | { |
Vkadaba | 5:0728bde67bdb | 1294 | case ADMW1001_OPEN_SENSOR_DIAGNOSTICS_DISABLED: |
Vkadaba | 5:0728bde67bdb | 1295 | diagnosticsControlReg.Diag_OSD_Freq = CORE_DIAGNOSTICS_CONTROL_OCD_OFF; |
ADIJake | 0:85855ecd3257 | 1296 | break; |
Vkadaba | 5:0728bde67bdb | 1297 | case ADMW1001_OPEN_SENSOR_DIAGNOSTICS_PER_CYCLE: |
Vkadaba | 5:0728bde67bdb | 1298 | diagnosticsControlReg.Diag_OSD_Freq = CORE_DIAGNOSTICS_CONTROL_OCD_PER_1_CYCLE; |
ADIJake | 0:85855ecd3257 | 1299 | break; |
Vkadaba | 5:0728bde67bdb | 1300 | case ADMW1001_OPEN_SENSOR_DIAGNOSTICS_PER_100_CYCLES: |
Vkadaba | 5:0728bde67bdb | 1301 | diagnosticsControlReg.Diag_OSD_Freq = CORE_DIAGNOSTICS_CONTROL_OCD_PER_100_CYCLES; |
ADIJake | 0:85855ecd3257 | 1302 | break; |
Vkadaba | 5:0728bde67bdb | 1303 | case ADMW1001_OPEN_SENSOR_DIAGNOSTICS_PER_1000_CYCLES: |
Vkadaba | 5:0728bde67bdb | 1304 | diagnosticsControlReg.Diag_OSD_Freq = CORE_DIAGNOSTICS_CONTROL_OCD_PER_1000_CYCLES; |
ADIJake | 0:85855ecd3257 | 1305 | break; |
ADIJake | 0:85855ecd3257 | 1306 | default: |
Vkadaba | 5:0728bde67bdb | 1307 | ADMW_LOG_ERROR("Invalid open-sensor diagnostic frequency %d specified", |
ADIJake | 0:85855ecd3257 | 1308 | pDiagnosticsConfig->osdFrequency); |
Vkadaba | 5:0728bde67bdb | 1309 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1310 | } |
ADIJake | 0:85855ecd3257 | 1311 | |
ADIJake | 0:85855ecd3257 | 1312 | WRITE_REG_U16(hDevice, diagnosticsControlReg.VALUE16, CORE_DIAGNOSTICS_CONTROL); |
ADIJake | 0:85855ecd3257 | 1313 | |
Vkadaba | 5:0728bde67bdb | 1314 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1315 | } |
ADIJake | 0:85855ecd3257 | 1316 | |
Vkadaba | 5:0728bde67bdb | 1317 | ADMW_RESULT admw1001_SetChannelCount( |
Vkadaba | 5:0728bde67bdb | 1318 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1319 | ADMW1001_CHANNEL_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 1320 | uint32_t nMeasurementsPerCycle) |
ADIJake | 0:85855ecd3257 | 1321 | { |
Vkadaba | 5:0728bde67bdb | 1322 | CORE_Channel_Count_t channelCountReg; |
ADIJake | 0:85855ecd3257 | 1323 | |
ADIJake | 0:85855ecd3257 | 1324 | channelCountReg.VALUE8 = REG_RESET_VAL(CORE_CHANNEL_COUNTn); |
ADIJake | 0:85855ecd3257 | 1325 | |
ADIJake | 0:85855ecd3257 | 1326 | if (nMeasurementsPerCycle > 0) |
ADIJake | 0:85855ecd3257 | 1327 | { |
ADIJake | 0:85855ecd3257 | 1328 | nMeasurementsPerCycle -= 1; |
ADIJake | 0:85855ecd3257 | 1329 | |
ADIJake | 0:85855ecd3257 | 1330 | CHECK_REG_FIELD_VAL(CORE_CHANNEL_COUNT_CHANNEL_COUNT, |
ADIJake | 0:85855ecd3257 | 1331 | nMeasurementsPerCycle); |
ADIJake | 0:85855ecd3257 | 1332 | |
ADIJake | 0:85855ecd3257 | 1333 | channelCountReg.Channel_Enable = 1; |
ADIJake | 0:85855ecd3257 | 1334 | channelCountReg.Channel_Count = nMeasurementsPerCycle; |
ADIJake | 0:85855ecd3257 | 1335 | } |
ADIJake | 0:85855ecd3257 | 1336 | else |
ADIJake | 0:85855ecd3257 | 1337 | { |
ADIJake | 0:85855ecd3257 | 1338 | channelCountReg.Channel_Enable = 0; |
ADIJake | 0:85855ecd3257 | 1339 | } |
ADIJake | 0:85855ecd3257 | 1340 | |
ADIJake | 0:85855ecd3257 | 1341 | WRITE_REG_U8(hDevice, channelCountReg.VALUE8, CORE_CHANNEL_COUNTn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1342 | |
Vkadaba | 5:0728bde67bdb | 1343 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1344 | } |
ADIJake | 0:85855ecd3257 | 1345 | |
Vkadaba | 5:0728bde67bdb | 1346 | ADMW_RESULT admw1001_SetChannelOptions( |
Vkadaba | 5:0728bde67bdb | 1347 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1348 | ADMW1001_CHANNEL_ID eChannelId, |
Vkadaba | 6:9d393a9677f4 | 1349 | ADMW1001_CHANNEL_PRIORITY ePriority) |
ADIJake | 0:85855ecd3257 | 1350 | { |
Vkadaba | 5:0728bde67bdb | 1351 | CORE_Channel_Options_t channelOptionsReg; |
ADIJake | 0:85855ecd3257 | 1352 | |
ADIJake | 0:85855ecd3257 | 1353 | channelOptionsReg.VALUE8 = REG_RESET_VAL(CORE_CHANNEL_OPTIONSn); |
ADIJake | 0:85855ecd3257 | 1354 | |
ADIJake | 0:85855ecd3257 | 1355 | CHECK_REG_FIELD_VAL(CORE_CHANNEL_OPTIONS_CHANNEL_PRIORITY, ePriority); |
ADIJake | 0:85855ecd3257 | 1356 | channelOptionsReg.Channel_Priority = ePriority; |
ADIJake | 0:85855ecd3257 | 1357 | |
ADIJake | 0:85855ecd3257 | 1358 | WRITE_REG_U8(hDevice, channelOptionsReg.VALUE8, CORE_CHANNEL_OPTIONSn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1359 | |
Vkadaba | 5:0728bde67bdb | 1360 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1361 | } |
ADIJake | 0:85855ecd3257 | 1362 | |
Vkadaba | 5:0728bde67bdb | 1363 | ADMW_RESULT admw1001_SetChannelSkipCount( |
Vkadaba | 5:0728bde67bdb | 1364 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1365 | ADMW1001_CHANNEL_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 1366 | uint32_t nCycleSkipCount) |
ADIJake | 0:85855ecd3257 | 1367 | { |
Vkadaba | 5:0728bde67bdb | 1368 | CORE_Channel_Skip_t channelSkipReg; |
ADIJake | 0:85855ecd3257 | 1369 | |
ADIJake | 0:85855ecd3257 | 1370 | channelSkipReg.VALUE16 = REG_RESET_VAL(CORE_CHANNEL_SKIPn); |
ADIJake | 0:85855ecd3257 | 1371 | |
ADIJake | 0:85855ecd3257 | 1372 | CHECK_REG_FIELD_VAL(CORE_CHANNEL_SKIP_CHANNEL_SKIP, nCycleSkipCount); |
ADIJake | 0:85855ecd3257 | 1373 | |
ADIJake | 0:85855ecd3257 | 1374 | channelSkipReg.Channel_Skip = nCycleSkipCount; |
ADIJake | 0:85855ecd3257 | 1375 | |
ADIJake | 0:85855ecd3257 | 1376 | WRITE_REG_U16(hDevice, channelSkipReg.VALUE16, CORE_CHANNEL_SKIPn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1377 | |
Vkadaba | 5:0728bde67bdb | 1378 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1379 | } |
ADIJake | 0:85855ecd3257 | 1380 | |
Vkadaba | 5:0728bde67bdb | 1381 | static ADMW_RESULT admw_SetChannelAdcSensorType( |
Vkadaba | 5:0728bde67bdb | 1382 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1383 | ADMW1001_CHANNEL_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1384 | ADMW1001_ADC_SENSOR_TYPE sensorType) |
ADIJake | 0:85855ecd3257 | 1385 | { |
Vkadaba | 5:0728bde67bdb | 1386 | CORE_Sensor_Type_t sensorTypeReg; |
ADIJake | 0:85855ecd3257 | 1387 | |
ADIJake | 0:85855ecd3257 | 1388 | sensorTypeReg.VALUE16 = REG_RESET_VAL(CORE_SENSOR_TYPEn); |
ADIJake | 0:85855ecd3257 | 1389 | |
ADIJake | 0:85855ecd3257 | 1390 | /* Ensure that the sensor type is valid for this channel */ |
ADIJake | 0:85855ecd3257 | 1391 | switch(sensorType) |
ADIJake | 0:85855ecd3257 | 1392 | { |
Vkadaba | 6:9d393a9677f4 | 1393 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT100_DEF_L1: |
Vkadaba | 6:9d393a9677f4 | 1394 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT1000_DEF_L1: |
Vkadaba | 6:9d393a9677f4 | 1395 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_1_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1396 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_2_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1397 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_3_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1398 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_4_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1399 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT100_ADV_L1: |
Vkadaba | 6:9d393a9677f4 | 1400 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT1000_ADV_L1: |
Vkadaba | 6:9d393a9677f4 | 1401 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_1_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1402 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_2_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1403 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_3_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1404 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_4_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1405 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT100_DEF_L1: |
Vkadaba | 6:9d393a9677f4 | 1406 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT1000_DEF_L1: |
Vkadaba | 6:9d393a9677f4 | 1407 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_1_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1408 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_2_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1409 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_3_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1410 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_4_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1411 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT100_ADV_L1: |
Vkadaba | 6:9d393a9677f4 | 1412 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT1000_ADV_L1: |
Vkadaba | 6:9d393a9677f4 | 1413 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_1_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1414 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_2_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1415 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_3_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1416 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_4_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1417 | case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_1_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1418 | case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_2_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1419 | case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_3_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1420 | case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_4_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1421 | case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_1_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1422 | case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_2_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1423 | case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_3_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1424 | case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_4_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1425 | case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_1_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1426 | case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_2_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1427 | case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_3_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1428 | case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_4_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1429 | case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_1_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1430 | case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_2_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1431 | case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_3_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1432 | case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_4_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1433 | case ADMW1001_ADC_SENSOR_MICROPHONE_A_DEF_L1: |
Vkadaba | 6:9d393a9677f4 | 1434 | case ADMW1001_ADC_SENSOR_MICROPHONE_B_DEF_L1: |
Vkadaba | 6:9d393a9677f4 | 1435 | case ADMW1001_ADC_SENSOR_MICROPHONE_1_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1436 | case ADMW1001_ADC_SENSOR_MICROPHONE_2_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1437 | case ADMW1001_ADC_SENSOR_MICROPHONE_A_ADV_L1: |
Vkadaba | 6:9d393a9677f4 | 1438 | case ADMW1001_ADC_SENSOR_MICROPHONE_B_ADV_L1: |
Vkadaba | 6:9d393a9677f4 | 1439 | case ADMW1001_ADC_SENSOR_MICROPHONE_1_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1440 | case ADMW1001_ADC_SENSOR_MICROPHONE_2_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1441 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT100_DEF_L1: |
Vkadaba | 6:9d393a9677f4 | 1442 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT1000_DEF_L1: |
Vkadaba | 6:9d393a9677f4 | 1443 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_1_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1444 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_2_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1445 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_3_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1446 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_4_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1447 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT100_ADV_L1: |
Vkadaba | 6:9d393a9677f4 | 1448 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT1000_ADV_L1: |
Vkadaba | 6:9d393a9677f4 | 1449 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_1_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1450 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_2_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1451 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_3_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1452 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_4_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1453 | case ADMW1001_ADC_SENSOR_DIODE_2C_TYPEA_DEF_L1: |
Vkadaba | 6:9d393a9677f4 | 1454 | case ADMW1001_ADC_SENSOR_DIODE_3C_TYPEA_DEF_L1: |
Vkadaba | 6:9d393a9677f4 | 1455 | case ADMW1001_ADC_SENSOR_DIODE_2C_1_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1456 | case ADMW1001_ADC_SENSOR_DIODE_3C_1_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1457 | case ADMW1001_ADC_SENSOR_DIODE_2C_TYPEA_ADV_L1: |
Vkadaba | 6:9d393a9677f4 | 1458 | case ADMW1001_ADC_SENSOR_DIODE_3C_TYPEA_ADV_L1: |
Vkadaba | 6:9d393a9677f4 | 1459 | case ADMW1001_ADC_SENSOR_DIODE_2C_1_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1460 | case ADMW1001_ADC_SENSOR_DIODE_3C_1_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1461 | case ADMW1001_ADC_SENSOR_THERMISTOR_A_10K_DEF_L1: |
Vkadaba | 6:9d393a9677f4 | 1462 | case ADMW1001_ADC_SENSOR_THERMISTOR_B_10K_DEF_L1: |
Vkadaba | 6:9d393a9677f4 | 1463 | case ADMW1001_ADC_SENSOR_THERMISTOR_1_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1464 | case ADMW1001_ADC_SENSOR_THERMISTOR_2_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1465 | case ADMW1001_ADC_SENSOR_THERMISTOR_3_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1466 | case ADMW1001_ADC_SENSOR_THERMISTOR_4_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1467 | case ADMW1001_ADC_SENSOR_THERMISTOR_A_10K_ADV_L1: |
Vkadaba | 6:9d393a9677f4 | 1468 | case ADMW1001_ADC_SENSOR_THERMISTOR_B_10K_ADV_L1: |
Vkadaba | 6:9d393a9677f4 | 1469 | case ADMW1001_ADC_SENSOR_THERMISTOR_1_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1470 | case ADMW1001_ADC_SENSOR_THERMISTOR_2_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1471 | case ADMW1001_ADC_SENSOR_THERMISTOR_3_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1472 | case ADMW1001_ADC_SENSOR_THERMISTOR_4_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1473 | if (! (ADMW1001_CHANNEL_IS_ADC_SENSOR(eChannelId) || |
Vkadaba | 6:9d393a9677f4 | 1474 | ADMW1001_CHANNEL_IS_ADC_CJC(eChannelId))) |
Vkadaba | 6:9d393a9677f4 | 1475 | { |
Vkadaba | 6:9d393a9677f4 | 1476 | ADMW_LOG_ERROR( |
Vkadaba | 6:9d393a9677f4 | 1477 | "Invalid ADC sensor type %d specified for channel %d", |
Vkadaba | 6:9d393a9677f4 | 1478 | sensorType, eChannelId); |
Vkadaba | 6:9d393a9677f4 | 1479 | return ADMW_INVALID_PARAM; |
Vkadaba | 6:9d393a9677f4 | 1480 | } |
Vkadaba | 6:9d393a9677f4 | 1481 | break; |
Vkadaba | 6:9d393a9677f4 | 1482 | case ADMW1001_ADC_SENSOR_VOLTAGE: |
Vkadaba | 6:9d393a9677f4 | 1483 | case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_A_DEF_L1: |
Vkadaba | 6:9d393a9677f4 | 1484 | case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_B_DEF_L1: |
Vkadaba | 6:9d393a9677f4 | 1485 | case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_1_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1486 | case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_2_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1487 | case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_A_ADV_L1: |
Vkadaba | 6:9d393a9677f4 | 1488 | case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_B_ADV_L1: |
Vkadaba | 6:9d393a9677f4 | 1489 | case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_1_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1490 | case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_2_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1491 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_J_DEF_L1: |
Vkadaba | 6:9d393a9677f4 | 1492 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_K_DEF_L1: |
Vkadaba | 6:9d393a9677f4 | 1493 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_T_DEF_L1: |
Vkadaba | 6:9d393a9677f4 | 1494 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_1_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1495 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_2_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1496 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_3_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1497 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_4_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1498 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_J_ADV_L1: |
Vkadaba | 6:9d393a9677f4 | 1499 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_K_ADV_L1: |
Vkadaba | 6:9d393a9677f4 | 1500 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_T_ADV_L1: |
Vkadaba | 6:9d393a9677f4 | 1501 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_1_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1502 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_2_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1503 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_3_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1504 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_4_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1505 | if (! ADMW1001_CHANNEL_IS_ADC_VOLTAGE(eChannelId)) |
Vkadaba | 6:9d393a9677f4 | 1506 | { |
Vkadaba | 6:9d393a9677f4 | 1507 | ADMW_LOG_ERROR( |
Vkadaba | 6:9d393a9677f4 | 1508 | "Invalid ADC sensor type %d specified for channel %d", |
Vkadaba | 6:9d393a9677f4 | 1509 | sensorType, eChannelId); |
Vkadaba | 6:9d393a9677f4 | 1510 | return ADMW_INVALID_PARAM; |
Vkadaba | 6:9d393a9677f4 | 1511 | } |
Vkadaba | 6:9d393a9677f4 | 1512 | break; |
Vkadaba | 6:9d393a9677f4 | 1513 | case ADMW1001_ADC_SENSOR_CURRENT: |
Vkadaba | 6:9d393a9677f4 | 1514 | case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_A_DEF_L1: |
Vkadaba | 6:9d393a9677f4 | 1515 | case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_1_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1516 | case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_2_DEF_L2: |
Vkadaba | 6:9d393a9677f4 | 1517 | case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_A_ADV_L1: |
Vkadaba | 6:9d393a9677f4 | 1518 | case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_1_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1519 | case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_2_ADV_L2: |
Vkadaba | 6:9d393a9677f4 | 1520 | if (! ADMW1001_CHANNEL_IS_ADC_CURRENT(eChannelId)) |
Vkadaba | 6:9d393a9677f4 | 1521 | { |
Vkadaba | 6:9d393a9677f4 | 1522 | ADMW_LOG_ERROR( |
Vkadaba | 6:9d393a9677f4 | 1523 | "Invalid ADC sensor type %d specified for channel %d", |
Vkadaba | 6:9d393a9677f4 | 1524 | sensorType, eChannelId); |
Vkadaba | 6:9d393a9677f4 | 1525 | return ADMW_INVALID_PARAM; |
Vkadaba | 6:9d393a9677f4 | 1526 | } |
Vkadaba | 6:9d393a9677f4 | 1527 | break; |
Vkadaba | 6:9d393a9677f4 | 1528 | default: |
Vkadaba | 6:9d393a9677f4 | 1529 | ADMW_LOG_ERROR("Invalid/unsupported ADC sensor type %d specified", |
Vkadaba | 6:9d393a9677f4 | 1530 | sensorType); |
Vkadaba | 5:0728bde67bdb | 1531 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1532 | } |
ADIJake | 0:85855ecd3257 | 1533 | |
ADIJake | 0:85855ecd3257 | 1534 | sensorTypeReg.Sensor_Type = sensorType; |
ADIJake | 0:85855ecd3257 | 1535 | |
ADIJake | 0:85855ecd3257 | 1536 | WRITE_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1537 | |
Vkadaba | 5:0728bde67bdb | 1538 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1539 | } |
ADIJake | 0:85855ecd3257 | 1540 | |
Vkadaba | 5:0728bde67bdb | 1541 | static ADMW_RESULT admw_SetChannelAdcSensorDetails( |
Vkadaba | 5:0728bde67bdb | 1542 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1543 | ADMW1001_CHANNEL_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1544 | ADMW1001_CHANNEL_CONFIG *pChannelConfig) |
ADIJake | 0:85855ecd3257 | 1545 | /* |
ADIJake | 0:85855ecd3257 | 1546 | * TODO - it would be nice if the general- vs. ADC-specific sensor details could be split into separate registers |
ADIJake | 0:85855ecd3257 | 1547 | * General details: |
ADIJake | 0:85855ecd3257 | 1548 | * - Measurement_Units |
ADIJake | 0:85855ecd3257 | 1549 | * - Compensation_Channel |
ADIJake | 0:85855ecd3257 | 1550 | * - CJC_Publish (if "CJC" was removed from the name) |
ADIJake | 0:85855ecd3257 | 1551 | * ADC-specific details: |
ADIJake | 0:85855ecd3257 | 1552 | * - PGA_Gain |
ADIJake | 0:85855ecd3257 | 1553 | * - Reference_Select |
ADIJake | 0:85855ecd3257 | 1554 | * - Reference_Buffer_Disable |
ADIJake | 0:85855ecd3257 | 1555 | * - Vbias |
ADIJake | 0:85855ecd3257 | 1556 | */ |
ADIJake | 0:85855ecd3257 | 1557 | { |
Vkadaba | 5:0728bde67bdb | 1558 | ADMW1001_ADC_CHANNEL_CONFIG *pAdcChannelConfig = &pChannelConfig->adcChannelConfig; |
Vkadaba | 5:0728bde67bdb | 1559 | ADMW1001_ADC_REFERENCE_CONFIG *pRefConfig = &pAdcChannelConfig->reference; |
Vkadaba | 5:0728bde67bdb | 1560 | CORE_Sensor_Details_t sensorDetailsReg; |
ADIJake | 0:85855ecd3257 | 1561 | |
ADIJake | 0:85855ecd3257 | 1562 | sensorDetailsReg.VALUE32 = REG_RESET_VAL(CORE_SENSOR_DETAILSn); |
ADIJake | 0:85855ecd3257 | 1563 | |
ADIJake | 0:85855ecd3257 | 1564 | switch(pChannelConfig->measurementUnit) |
ADIJake | 0:85855ecd3257 | 1565 | { |
Vkadaba | 5:0728bde67bdb | 1566 | case ADMW1001_MEASUREMENT_UNIT_FAHRENHEIT: |
Vkadaba | 5:0728bde67bdb | 1567 | sensorDetailsReg.Measurement_Units = CORE_SENSOR_DETAILS_UNITS_DEGF; |
ADIJake | 0:85855ecd3257 | 1568 | break; |
Vkadaba | 5:0728bde67bdb | 1569 | case ADMW1001_MEASUREMENT_UNIT_CELSIUS: |
Vkadaba | 5:0728bde67bdb | 1570 | sensorDetailsReg.Measurement_Units = CORE_SENSOR_DETAILS_UNITS_DEGC; |
ADIJake | 0:85855ecd3257 | 1571 | break; |
Vkadaba | 5:0728bde67bdb | 1572 | case ADMW1001_MEASUREMENT_UNIT_UNSPECIFIED: |
Vkadaba | 5:0728bde67bdb | 1573 | sensorDetailsReg.Measurement_Units = CORE_SENSOR_DETAILS_UNITS_UNSPECIFIED; |
ADIJake | 0:85855ecd3257 | 1574 | break; |
ADIJake | 0:85855ecd3257 | 1575 | default: |
Vkadaba | 5:0728bde67bdb | 1576 | ADMW_LOG_ERROR("Invalid measurement unit %d specified", |
ADIJake | 0:85855ecd3257 | 1577 | pChannelConfig->measurementUnit); |
Vkadaba | 5:0728bde67bdb | 1578 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1579 | } |
ADIJake | 0:85855ecd3257 | 1580 | |
Vkadaba | 5:0728bde67bdb | 1581 | if (pChannelConfig->compensationChannel == ADMW1001_CHANNEL_ID_NONE) |
ADIJake | 0:85855ecd3257 | 1582 | { |
ADIJake | 0:85855ecd3257 | 1583 | sensorDetailsReg.Compensation_Disable = 1; |
ADIJake | 0:85855ecd3257 | 1584 | sensorDetailsReg.Compensation_Channel = 0; |
ADIJake | 0:85855ecd3257 | 1585 | } |
ADIJake | 0:85855ecd3257 | 1586 | else |
ADIJake | 0:85855ecd3257 | 1587 | { |
ADIJake | 0:85855ecd3257 | 1588 | sensorDetailsReg.Compensation_Disable = 0; |
ADIJake | 0:85855ecd3257 | 1589 | sensorDetailsReg.Compensation_Channel = pChannelConfig->compensationChannel; |
ADIJake | 0:85855ecd3257 | 1590 | } |
ADIJake | 0:85855ecd3257 | 1591 | |
ADIJake | 0:85855ecd3257 | 1592 | switch(pRefConfig->type) |
ADIJake | 0:85855ecd3257 | 1593 | { |
Vkadaba | 5:0728bde67bdb | 1594 | case ADMW1001_ADC_REFERENCE_RESISTOR_INTERNAL_1: |
Vkadaba | 6:9d393a9677f4 | 1595 | sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_INT; |
ADIJake | 0:85855ecd3257 | 1596 | break; |
Vkadaba | 5:0728bde67bdb | 1597 | case ADMW1001_ADC_REFERENCE_VOLTAGE_INTERNAL: |
Vkadaba | 5:0728bde67bdb | 1598 | sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_INT; |
ADIJake | 0:85855ecd3257 | 1599 | break; |
Vkadaba | 5:0728bde67bdb | 1600 | case ADMW1001_ADC_REFERENCE_VOLTAGE_AVDD: |
Vkadaba | 5:0728bde67bdb | 1601 | sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_AVDD; |
ADIJake | 0:85855ecd3257 | 1602 | break; |
Vkadaba | 5:0728bde67bdb | 1603 | case ADMW1001_ADC_REFERENCE_RESISTOR_EXTERNAL_1: |
Vkadaba | 5:0728bde67bdb | 1604 | sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_REXT1; |
ADIJake | 0:85855ecd3257 | 1605 | break; |
Vkadaba | 5:0728bde67bdb | 1606 | case ADMW1001_ADC_REFERENCE_BRIDGE_EXCITATION: |
Vkadaba | 5:0728bde67bdb | 1607 | sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_EXC; |
ADIJake | 0:85855ecd3257 | 1608 | break; |
ADIJake | 0:85855ecd3257 | 1609 | default: |
Vkadaba | 5:0728bde67bdb | 1610 | ADMW_LOG_ERROR("Invalid ADC reference type %d specified", |
ADIJake | 0:85855ecd3257 | 1611 | pRefConfig->type); |
Vkadaba | 5:0728bde67bdb | 1612 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1613 | } |
Vkadaba | 6:9d393a9677f4 | 1614 | |
ADIJake | 0:85855ecd3257 | 1615 | switch(pAdcChannelConfig->gain) |
ADIJake | 0:85855ecd3257 | 1616 | { |
Vkadaba | 5:0728bde67bdb | 1617 | case ADMW1001_ADC_GAIN_1X: |
Vkadaba | 5:0728bde67bdb | 1618 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_1; |
ADIJake | 0:85855ecd3257 | 1619 | break; |
Vkadaba | 5:0728bde67bdb | 1620 | case ADMW1001_ADC_GAIN_2X: |
Vkadaba | 5:0728bde67bdb | 1621 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_2; |
ADIJake | 0:85855ecd3257 | 1622 | break; |
Vkadaba | 5:0728bde67bdb | 1623 | case ADMW1001_ADC_GAIN_4X: |
Vkadaba | 5:0728bde67bdb | 1624 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_4; |
ADIJake | 0:85855ecd3257 | 1625 | break; |
Vkadaba | 5:0728bde67bdb | 1626 | case ADMW1001_ADC_GAIN_8X: |
Vkadaba | 5:0728bde67bdb | 1627 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_8; |
ADIJake | 0:85855ecd3257 | 1628 | break; |
Vkadaba | 5:0728bde67bdb | 1629 | case ADMW1001_ADC_GAIN_16X: |
Vkadaba | 5:0728bde67bdb | 1630 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_16; |
ADIJake | 0:85855ecd3257 | 1631 | break; |
Vkadaba | 5:0728bde67bdb | 1632 | case ADMW1001_ADC_GAIN_32X: |
Vkadaba | 5:0728bde67bdb | 1633 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_32; |
ADIJake | 0:85855ecd3257 | 1634 | break; |
Vkadaba | 5:0728bde67bdb | 1635 | case ADMW1001_ADC_GAIN_64X: |
Vkadaba | 5:0728bde67bdb | 1636 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_64; |
ADIJake | 0:85855ecd3257 | 1637 | break; |
Vkadaba | 5:0728bde67bdb | 1638 | case ADMW1001_ADC_GAIN_128X: |
Vkadaba | 5:0728bde67bdb | 1639 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_128; |
ADIJake | 0:85855ecd3257 | 1640 | break; |
ADIJake | 0:85855ecd3257 | 1641 | default: |
Vkadaba | 5:0728bde67bdb | 1642 | ADMW_LOG_ERROR("Invalid ADC gain %d specified", |
ADIJake | 0:85855ecd3257 | 1643 | pAdcChannelConfig->gain); |
Vkadaba | 5:0728bde67bdb | 1644 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1645 | } |
ADIJake | 0:85855ecd3257 | 1646 | |
Vkadaba | 6:9d393a9677f4 | 1647 | switch(pAdcChannelConfig->rtdCurve) |
Vkadaba | 6:9d393a9677f4 | 1648 | { |
Vkadaba | 6:9d393a9677f4 | 1649 | case ADMW1001_ADC_RTD_CURVE_EUROPEAN: |
Vkadaba | 6:9d393a9677f4 | 1650 | sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_EUROPEAN_CURVE; |
Vkadaba | 6:9d393a9677f4 | 1651 | break; |
Vkadaba | 6:9d393a9677f4 | 1652 | case ADMW1001_ADC_RTD_CURVE_AMERICAN: |
Vkadaba | 6:9d393a9677f4 | 1653 | sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_AMERICAN_CURVE; |
Vkadaba | 6:9d393a9677f4 | 1654 | break; |
Vkadaba | 6:9d393a9677f4 | 1655 | case ADMW1001_ADC_RTD_CURVE_JAPANESE: |
Vkadaba | 6:9d393a9677f4 | 1656 | sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_JAPANESE_CURVE; |
Vkadaba | 6:9d393a9677f4 | 1657 | break; |
Vkadaba | 6:9d393a9677f4 | 1658 | case ADMW1001_ADC_RTD_CURVE_ITS90: |
Vkadaba | 6:9d393a9677f4 | 1659 | sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_ITS90_CURVE; |
Vkadaba | 6:9d393a9677f4 | 1660 | break; |
Vkadaba | 6:9d393a9677f4 | 1661 | default: |
Vkadaba | 6:9d393a9677f4 | 1662 | ADMW_LOG_ERROR("Invalid RTD Curve %d specified", |
Vkadaba | 6:9d393a9677f4 | 1663 | pAdcChannelConfig->rtdCurve); |
Vkadaba | 6:9d393a9677f4 | 1664 | return ADMW_INVALID_PARAM; |
Vkadaba | 6:9d393a9677f4 | 1665 | } |
Vkadaba | 6:9d393a9677f4 | 1666 | |
ADIJake | 0:85855ecd3257 | 1667 | if (pAdcChannelConfig->enableVbias) |
ADIJake | 0:85855ecd3257 | 1668 | sensorDetailsReg.Vbias = 1; |
ADIJake | 0:85855ecd3257 | 1669 | else |
ADIJake | 0:85855ecd3257 | 1670 | sensorDetailsReg.Vbias = 0; |
ADIJake | 0:85855ecd3257 | 1671 | |
ADIJake | 0:85855ecd3257 | 1672 | if (pChannelConfig->disablePublishing) |
ADIJake | 0:85855ecd3257 | 1673 | sensorDetailsReg.Do_Not_Publish = 1; |
ADIJake | 0:85855ecd3257 | 1674 | else |
ADIJake | 0:85855ecd3257 | 1675 | sensorDetailsReg.Do_Not_Publish = 0; |
ADIJake | 0:85855ecd3257 | 1676 | |
ADIJake | 0:85855ecd3257 | 1677 | if (pChannelConfig->enableUnityLut) |
ADIJake | 0:85855ecd3257 | 1678 | sensorDetailsReg.Unity_LUT_Select = 1; |
ADIJake | 0:85855ecd3257 | 1679 | else |
ADIJake | 0:85855ecd3257 | 1680 | sensorDetailsReg.Unity_LUT_Select = 0; |
ADIJake | 0:85855ecd3257 | 1681 | |
ADIJake | 0:85855ecd3257 | 1682 | WRITE_REG_U32(hDevice, sensorDetailsReg.VALUE32, CORE_SENSOR_DETAILSn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1683 | |
Vkadaba | 5:0728bde67bdb | 1684 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1685 | } |
ADIJake | 0:85855ecd3257 | 1686 | |
Vkadaba | 5:0728bde67bdb | 1687 | static ADMW_RESULT admw_SetChannelAdcFilter( |
Vkadaba | 5:0728bde67bdb | 1688 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1689 | ADMW1001_CHANNEL_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1690 | ADMW1001_ADC_FILTER_CONFIG *pFilterConfig) |
ADIJake | 0:85855ecd3257 | 1691 | { |
Vkadaba | 6:9d393a9677f4 | 1692 | CORE_Measurement_Setup_t MeasSetupReg; |
Vkadaba | 6:9d393a9677f4 | 1693 | MeasSetupReg.VALUE32 = REG_RESET_VAL(CORE_MEASUREMENT_SETUPn); |
ADIJake | 0:85855ecd3257 | 1694 | |
Vkadaba | 5:0728bde67bdb | 1695 | if (pFilterConfig->type == ADMW1001_ADC_FILTER_SINC4) |
ADIJake | 0:85855ecd3257 | 1696 | { |
Vkadaba | 6:9d393a9677f4 | 1697 | MeasSetupReg.ADC_Filter_Type = CORE_MEASUREMENT_SETUP_ENABLE_SINC4; |
Vkadaba | 6:9d393a9677f4 | 1698 | MeasSetupReg.ADC_SF = pFilterConfig->sf; |
ADIJake | 0:85855ecd3257 | 1699 | } |
Vkadaba | 6:9d393a9677f4 | 1700 | else if (pFilterConfig->type == ADMW1001_ADC_FILTER_SINC3) |
ADIJake | 0:85855ecd3257 | 1701 | { |
Vkadaba | 6:9d393a9677f4 | 1702 | MeasSetupReg.ADC_Filter_Type = CORE_MEASUREMENT_SETUP_ENABLE_SINC3; |
Vkadaba | 6:9d393a9677f4 | 1703 | MeasSetupReg.ADC_SF = pFilterConfig->sf; |
ADIJake | 0:85855ecd3257 | 1704 | } |
ADIJake | 0:85855ecd3257 | 1705 | else |
ADIJake | 0:85855ecd3257 | 1706 | { |
Vkadaba | 5:0728bde67bdb | 1707 | ADMW_LOG_ERROR("Invalid ADC filter type %d specified", |
ADIJake | 0:85855ecd3257 | 1708 | pFilterConfig->type); |
Vkadaba | 5:0728bde67bdb | 1709 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1710 | } |
Vkadaba | 6:9d393a9677f4 | 1711 | |
Vkadaba | 6:9d393a9677f4 | 1712 | if(pFilterConfig->filterChop) |
Vkadaba | 6:9d393a9677f4 | 1713 | MeasSetupReg.Chop_Mode = 1; |
Vkadaba | 6:9d393a9677f4 | 1714 | else |
Vkadaba | 6:9d393a9677f4 | 1715 | MeasSetupReg.Chop_Mode = 1; |
Vkadaba | 6:9d393a9677f4 | 1716 | |
Vkadaba | 6:9d393a9677f4 | 1717 | if(pFilterConfig->notch1p2) |
Vkadaba | 6:9d393a9677f4 | 1718 | MeasSetupReg.NOTCH_EN_2 = 1; |
Vkadaba | 6:9d393a9677f4 | 1719 | else |
Vkadaba | 6:9d393a9677f4 | 1720 | MeasSetupReg.NOTCH_EN_2 = 0; |
Vkadaba | 6:9d393a9677f4 | 1721 | |
Vkadaba | 6:9d393a9677f4 | 1722 | switch(pFilterConfig->groundSwitch) |
Vkadaba | 6:9d393a9677f4 | 1723 | { |
Vkadaba | 6:9d393a9677f4 | 1724 | case ADMW1001_ADC_GND_SW_OPEN: |
Vkadaba | 6:9d393a9677f4 | 1725 | MeasSetupReg.GND_SW = CORE_MEASUREMENT_SETUP_GND_SW_OPEN; |
Vkadaba | 6:9d393a9677f4 | 1726 | break; |
Vkadaba | 6:9d393a9677f4 | 1727 | case ADMW1001_ADC_GND_SW_CLOSED: |
Vkadaba | 6:9d393a9677f4 | 1728 | MeasSetupReg.GND_SW = CORE_MEASUREMENT_SETUP_GND_SW_CLOSED; |
Vkadaba | 6:9d393a9677f4 | 1729 | break; |
Vkadaba | 6:9d393a9677f4 | 1730 | default: |
Vkadaba | 6:9d393a9677f4 | 1731 | ADMW_LOG_ERROR("Invalid ground switch state %d specified", |
Vkadaba | 6:9d393a9677f4 | 1732 | pFilterConfig->groundSwitch); |
Vkadaba | 6:9d393a9677f4 | 1733 | return ADMW_INVALID_PARAM; |
Vkadaba | 6:9d393a9677f4 | 1734 | } |
Vkadaba | 6:9d393a9677f4 | 1735 | |
Vkadaba | 6:9d393a9677f4 | 1736 | WRITE_REG_U32(hDevice, MeasSetupReg.VALUE32, CORE_MEASUREMENT_SETUPn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1737 | |
Vkadaba | 5:0728bde67bdb | 1738 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1739 | } |
ADIJake | 0:85855ecd3257 | 1740 | |
Vkadaba | 5:0728bde67bdb | 1741 | static ADMW_RESULT admw_SetChannelAdcCurrentConfig( |
Vkadaba | 5:0728bde67bdb | 1742 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1743 | ADMW1001_CHANNEL_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1744 | ADMW1001_ADC_EXC_CURRENT_CONFIG *pCurrentConfig) |
ADIJake | 0:85855ecd3257 | 1745 | { |
Vkadaba | 5:0728bde67bdb | 1746 | CORE_Channel_Excitation_t channelExcitationReg; |
ADIJake | 0:85855ecd3257 | 1747 | |
Vkadaba | 6:9d393a9677f4 | 1748 | channelExcitationReg.VALUE16 = REG_RESET_VAL(CORE_CHANNEL_EXCITATIONn); |
Vkadaba | 6:9d393a9677f4 | 1749 | |
Vkadaba | 6:9d393a9677f4 | 1750 | |
Vkadaba | 6:9d393a9677f4 | 1751 | if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_EXTERNAL) |
Vkadaba | 6:9d393a9677f4 | 1752 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_EXTERNAL; |
Vkadaba | 6:9d393a9677f4 | 1753 | if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_50uA) |
Vkadaba | 6:9d393a9677f4 | 1754 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_50UA; |
Vkadaba | 6:9d393a9677f4 | 1755 | else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_100uA) |
Vkadaba | 6:9d393a9677f4 | 1756 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_100UA; |
Vkadaba | 6:9d393a9677f4 | 1757 | else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_250uA) |
Vkadaba | 6:9d393a9677f4 | 1758 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_250UA; |
Vkadaba | 6:9d393a9677f4 | 1759 | else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_500uA) |
Vkadaba | 6:9d393a9677f4 | 1760 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_500UA; |
Vkadaba | 6:9d393a9677f4 | 1761 | else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_1000uA) |
Vkadaba | 6:9d393a9677f4 | 1762 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_1000UA; |
ADIJake | 0:85855ecd3257 | 1763 | else |
ADIJake | 0:85855ecd3257 | 1764 | { |
Vkadaba | 6:9d393a9677f4 | 1765 | ADMW_LOG_ERROR("Invalid ADC excitation current %d specified", |
Vkadaba | 6:9d393a9677f4 | 1766 | pCurrentConfig->outputLevel); |
Vkadaba | 6:9d393a9677f4 | 1767 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1768 | } |
ADIJake | 0:85855ecd3257 | 1769 | |
Vkadaba | 6:9d393a9677f4 | 1770 | |
Vkadaba | 6:9d393a9677f4 | 1771 | switch(pCurrentConfig->diodeRatio) { |
Vkadaba | 6:9d393a9677f4 | 1772 | case ADMW1001_ADC_EXC_CURRENT_IOUT_DIODE_10UA_100UA: |
Vkadaba | 6:9d393a9677f4 | 1773 | channelExcitationReg.IOUT_Diode_Ratio = CORE_CHANNEL_EXCITATION_DIODE_2PT_10UA_100UA; |
Vkadaba | 6:9d393a9677f4 | 1774 | break; |
Vkadaba | 6:9d393a9677f4 | 1775 | case ADMW1001_ADC_EXC_CURRENT_IOUT_DIODE_20UA_160UA: |
Vkadaba | 6:9d393a9677f4 | 1776 | channelExcitationReg.IOUT_Diode_Ratio = CORE_CHANNEL_EXCITATION_DIODE_2PT_20UA_160UA; |
Vkadaba | 6:9d393a9677f4 | 1777 | break; |
Vkadaba | 6:9d393a9677f4 | 1778 | case ADMW1001_ADC_EXC_CURRENT_IOUT_DIODE_50UA_300UA: |
Vkadaba | 6:9d393a9677f4 | 1779 | channelExcitationReg.IOUT_Diode_Ratio = CORE_CHANNEL_EXCITATION_DIODE_2PT_50UA_300UA; |
Vkadaba | 6:9d393a9677f4 | 1780 | break; |
Vkadaba | 6:9d393a9677f4 | 1781 | case ADMW1001_ADC_EXC_CURRENT_IOUT_DIODE_100UA_600UA: |
Vkadaba | 6:9d393a9677f4 | 1782 | channelExcitationReg.IOUT_Diode_Ratio = CORE_CHANNEL_EXCITATION_DIODE_2PT_100UA_600UA; |
Vkadaba | 6:9d393a9677f4 | 1783 | break; |
Vkadaba | 6:9d393a9677f4 | 1784 | case ADMW1001_ADC_EXC_CURRENT_IOUT_DIODE_10UA_50UA_100UA: |
Vkadaba | 6:9d393a9677f4 | 1785 | channelExcitationReg.IOUT_Diode_Ratio = CORE_CHANNEL_EXCITATION_DIODE_3PT_10UA_50UA_100UA; |
Vkadaba | 6:9d393a9677f4 | 1786 | break; |
Vkadaba | 6:9d393a9677f4 | 1787 | case ADMW1001_ADC_EXC_CURRENT_IOUT_DIODE_20UA_100UA_160UA: |
Vkadaba | 6:9d393a9677f4 | 1788 | channelExcitationReg.IOUT_Diode_Ratio = CORE_CHANNEL_EXCITATION_DIODE_3PT_20UA_100UA_160UA; |
Vkadaba | 6:9d393a9677f4 | 1789 | break; |
Vkadaba | 6:9d393a9677f4 | 1790 | case ADMW1001_ADC_EXC_CURRENT_IOUT_DIODE_50UA_150UA_300UA: |
Vkadaba | 6:9d393a9677f4 | 1791 | channelExcitationReg.IOUT_Diode_Ratio = CORE_CHANNEL_EXCITATION_DIODE_3PT_50UA_150UA_300UA; |
Vkadaba | 6:9d393a9677f4 | 1792 | break; |
Vkadaba | 6:9d393a9677f4 | 1793 | case ADMW1001_ADC_EXC_CURRENT_IOUT_DIODE_100UA_300UA_600UA: |
Vkadaba | 6:9d393a9677f4 | 1794 | channelExcitationReg.IOUT_Diode_Ratio = CORE_CHANNEL_EXCITATION_DIODE_3PT_100UA_300UA_600UA; |
Vkadaba | 6:9d393a9677f4 | 1795 | break; |
Vkadaba | 6:9d393a9677f4 | 1796 | default: |
Vkadaba | 6:9d393a9677f4 | 1797 | ADMW_LOG_ERROR("Invalid diode ratio %d specified", |
Vkadaba | 6:9d393a9677f4 | 1798 | pCurrentConfig->diodeRatio); |
Vkadaba | 6:9d393a9677f4 | 1799 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1800 | } |
Vkadaba | 6:9d393a9677f4 | 1801 | |
Vkadaba | 6:9d393a9677f4 | 1802 | WRITE_REG_U16(hDevice, channelExcitationReg.VALUE16, CORE_CHANNEL_EXCITATIONn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1803 | |
Vkadaba | 5:0728bde67bdb | 1804 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1805 | } |
ADIJake | 0:85855ecd3257 | 1806 | |
Vkadaba | 5:0728bde67bdb | 1807 | ADMW_RESULT admw_SetAdcChannelConfig( |
Vkadaba | 5:0728bde67bdb | 1808 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1809 | ADMW1001_CHANNEL_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1810 | ADMW1001_CHANNEL_CONFIG *pChannelConfig) |
ADIJake | 0:85855ecd3257 | 1811 | { |
Vkadaba | 5:0728bde67bdb | 1812 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 1813 | ADMW1001_ADC_CHANNEL_CONFIG *pAdcChannelConfig = |
ADIJake | 0:85855ecd3257 | 1814 | &pChannelConfig->adcChannelConfig; |
ADIJake | 0:85855ecd3257 | 1815 | |
Vkadaba | 5:0728bde67bdb | 1816 | eRet = admw_SetChannelAdcSensorType(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 1817 | pAdcChannelConfig->sensor); |
Vkadaba | 5:0728bde67bdb | 1818 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 1819 | { |
Vkadaba | 5:0728bde67bdb | 1820 | ADMW_LOG_ERROR("Failed to set ADC sensor type for channel %d", |
ADIJake | 0:85855ecd3257 | 1821 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1822 | return eRet; |
ADIJake | 0:85855ecd3257 | 1823 | } |
ADIJake | 0:85855ecd3257 | 1824 | |
Vkadaba | 5:0728bde67bdb | 1825 | eRet = admw_SetChannelAdcSensorDetails(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 1826 | pChannelConfig); |
Vkadaba | 5:0728bde67bdb | 1827 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 1828 | { |
Vkadaba | 5:0728bde67bdb | 1829 | ADMW_LOG_ERROR("Failed to set ADC sensor details for channel %d", |
ADIJake | 0:85855ecd3257 | 1830 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1831 | return eRet; |
ADIJake | 0:85855ecd3257 | 1832 | } |
ADIJake | 0:85855ecd3257 | 1833 | |
Vkadaba | 5:0728bde67bdb | 1834 | eRet = admw_SetChannelAdcFilter(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 1835 | &pAdcChannelConfig->filter); |
Vkadaba | 5:0728bde67bdb | 1836 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 1837 | { |
Vkadaba | 5:0728bde67bdb | 1838 | ADMW_LOG_ERROR("Failed to set ADC filter for channel %d", |
ADIJake | 0:85855ecd3257 | 1839 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1840 | return eRet; |
ADIJake | 0:85855ecd3257 | 1841 | } |
ADIJake | 0:85855ecd3257 | 1842 | |
Vkadaba | 5:0728bde67bdb | 1843 | eRet = admw_SetChannelAdcCurrentConfig(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 1844 | &pAdcChannelConfig->current); |
Vkadaba | 5:0728bde67bdb | 1845 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 1846 | { |
Vkadaba | 5:0728bde67bdb | 1847 | ADMW_LOG_ERROR("Failed to set ADC current for channel %d", |
ADIJake | 0:85855ecd3257 | 1848 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1849 | return eRet; |
ADIJake | 0:85855ecd3257 | 1850 | } |
ADIJake | 0:85855ecd3257 | 1851 | |
Vkadaba | 5:0728bde67bdb | 1852 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1853 | } |
ADIJake | 0:85855ecd3257 | 1854 | |
Vkadaba | 5:0728bde67bdb | 1855 | static ADMW_RESULT admw_SetChannelDigitalSensorDetails( |
Vkadaba | 5:0728bde67bdb | 1856 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1857 | ADMW1001_CHANNEL_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1858 | ADMW1001_CHANNEL_CONFIG *pChannelConfig) |
ADIJake | 0:85855ecd3257 | 1859 | { |
Vkadaba | 5:0728bde67bdb | 1860 | CORE_Sensor_Details_t sensorDetailsReg; |
ADIJake | 0:85855ecd3257 | 1861 | |
ADIJake | 0:85855ecd3257 | 1862 | sensorDetailsReg.VALUE32 = REG_RESET_VAL(CORE_SENSOR_DETAILSn); |
ADIJake | 0:85855ecd3257 | 1863 | |
Vkadaba | 5:0728bde67bdb | 1864 | if (pChannelConfig->compensationChannel == ADMW1001_CHANNEL_ID_NONE) |
ADIJake | 0:85855ecd3257 | 1865 | { |
ADIJake | 0:85855ecd3257 | 1866 | sensorDetailsReg.Compensation_Disable = 1; |
ADIJake | 0:85855ecd3257 | 1867 | sensorDetailsReg.Compensation_Channel = 0; |
ADIJake | 0:85855ecd3257 | 1868 | } |
ADIJake | 0:85855ecd3257 | 1869 | else |
ADIJake | 0:85855ecd3257 | 1870 | { |
Vkadaba | 5:0728bde67bdb | 1871 | ADMW_LOG_ERROR("Invalid compensation channel specified for digital sensor"); |
Vkadaba | 5:0728bde67bdb | 1872 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1873 | } |
ADIJake | 0:85855ecd3257 | 1874 | |
Vkadaba | 5:0728bde67bdb | 1875 | if (pChannelConfig->measurementUnit == ADMW1001_MEASUREMENT_UNIT_UNSPECIFIED) |
ADIJake | 0:85855ecd3257 | 1876 | { |
Vkadaba | 5:0728bde67bdb | 1877 | sensorDetailsReg.Measurement_Units = CORE_SENSOR_DETAILS_UNITS_UNSPECIFIED; |
ADIJake | 0:85855ecd3257 | 1878 | } |
ADIJake | 0:85855ecd3257 | 1879 | else |
ADIJake | 0:85855ecd3257 | 1880 | { |
Vkadaba | 5:0728bde67bdb | 1881 | ADMW_LOG_ERROR("Invalid measurement unit specified for digital channel"); |
Vkadaba | 5:0728bde67bdb | 1882 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1883 | } |
ADIJake | 0:85855ecd3257 | 1884 | |
ADIJake | 0:85855ecd3257 | 1885 | if (pChannelConfig->disablePublishing) |
ADIJake | 0:85855ecd3257 | 1886 | sensorDetailsReg.Do_Not_Publish = 1; |
ADIJake | 0:85855ecd3257 | 1887 | else |
ADIJake | 0:85855ecd3257 | 1888 | sensorDetailsReg.Do_Not_Publish = 0; |
ADIJake | 0:85855ecd3257 | 1889 | |
ADIJake | 0:85855ecd3257 | 1890 | if (pChannelConfig->enableUnityLut) |
ADIJake | 0:85855ecd3257 | 1891 | sensorDetailsReg.Unity_LUT_Select = 1; |
ADIJake | 0:85855ecd3257 | 1892 | else |
ADIJake | 0:85855ecd3257 | 1893 | sensorDetailsReg.Unity_LUT_Select = 0; |
ADIJake | 0:85855ecd3257 | 1894 | |
ADIJake | 0:85855ecd3257 | 1895 | sensorDetailsReg.Vbias = 0; |
ADIJake | 0:85855ecd3257 | 1896 | |
ADIJake | 0:85855ecd3257 | 1897 | WRITE_REG_U32(hDevice, sensorDetailsReg.VALUE32, CORE_SENSOR_DETAILSn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1898 | |
Vkadaba | 5:0728bde67bdb | 1899 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1900 | } |
ADIJake | 0:85855ecd3257 | 1901 | |
Vkadaba | 5:0728bde67bdb | 1902 | static ADMW_RESULT admw_SetDigitalSensorCommands( |
Vkadaba | 5:0728bde67bdb | 1903 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1904 | ADMW1001_CHANNEL_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1905 | ADMW1001_DIGITAL_SENSOR_COMMAND *pConfigCommand, |
Vkadaba | 5:0728bde67bdb | 1906 | ADMW1001_DIGITAL_SENSOR_COMMAND *pDataRequestCommand) |
ADIJake | 0:85855ecd3257 | 1907 | { |
Vkadaba | 5:0728bde67bdb | 1908 | CORE_Digital_Sensor_Num_Cmds_t numCmdsReg; |
ADIJake | 0:85855ecd3257 | 1909 | |
ADIJake | 0:85855ecd3257 | 1910 | numCmdsReg.VALUE8 = REG_RESET_VAL(CORE_DIGITAL_SENSOR_NUM_CMDSn); |
ADIJake | 0:85855ecd3257 | 1911 | |
ADIJake | 0:85855ecd3257 | 1912 | CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_NUM_CMDS_DIGITAL_SENSOR_NUM_CFG_CMDS, |
ADIJake | 0:85855ecd3257 | 1913 | pConfigCommand->commandLength); |
ADIJake | 0:85855ecd3257 | 1914 | CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_NUM_CMDS_DIGITAL_SENSOR_NUM_READ_CMDS, |
ADIJake | 0:85855ecd3257 | 1915 | pDataRequestCommand->commandLength); |
ADIJake | 0:85855ecd3257 | 1916 | |
ADIJake | 0:85855ecd3257 | 1917 | numCmdsReg.Digital_Sensor_Num_Cfg_Cmds = pConfigCommand->commandLength; |
ADIJake | 0:85855ecd3257 | 1918 | numCmdsReg.Digital_Sensor_Num_Read_Cmds = pDataRequestCommand->commandLength; |
ADIJake | 0:85855ecd3257 | 1919 | |
ADIJake | 0:85855ecd3257 | 1920 | WRITE_REG_U8(hDevice, numCmdsReg.VALUE8, |
ADIJake | 0:85855ecd3257 | 1921 | CORE_DIGITAL_SENSOR_NUM_CMDSn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1922 | |
ADIJake | 0:85855ecd3257 | 1923 | /* |
ADIJake | 0:85855ecd3257 | 1924 | * NOTE - the fall-through cases in the switch statement below are |
ADIJake | 0:85855ecd3257 | 1925 | * intentional, so temporarily disable related compiler warnings which may |
ADIJake | 0:85855ecd3257 | 1926 | * be produced here by GCC |
ADIJake | 0:85855ecd3257 | 1927 | */ |
ADIJake | 0:85855ecd3257 | 1928 | #ifndef __CC_ARM |
ADIJake | 0:85855ecd3257 | 1929 | #pragma GCC diagnostic push |
ADIJake | 0:85855ecd3257 | 1930 | #pragma GCC diagnostic ignored "-Wimplicit-fallthrough" |
ADIJake | 0:85855ecd3257 | 1931 | #endif |
ADIJake | 0:85855ecd3257 | 1932 | |
ADIJake | 0:85855ecd3257 | 1933 | switch (pConfigCommand->commandLength) |
ADIJake | 0:85855ecd3257 | 1934 | { |
ADIJake | 0:85855ecd3257 | 1935 | case 7: |
ADIJake | 0:85855ecd3257 | 1936 | WRITE_REG_U8(hDevice, pConfigCommand->command[6], |
ADIJake | 0:85855ecd3257 | 1937 | CORE_DIGITAL_SENSOR_COMMAND7n(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1938 | case 6: |
ADIJake | 0:85855ecd3257 | 1939 | WRITE_REG_U8(hDevice, pConfigCommand->command[5], |
ADIJake | 0:85855ecd3257 | 1940 | CORE_DIGITAL_SENSOR_COMMAND6n(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1941 | case 5: |
ADIJake | 0:85855ecd3257 | 1942 | WRITE_REG_U8(hDevice, pConfigCommand->command[4], |
ADIJake | 0:85855ecd3257 | 1943 | CORE_DIGITAL_SENSOR_COMMAND5n(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1944 | case 4: |
ADIJake | 0:85855ecd3257 | 1945 | WRITE_REG_U8(hDevice, pConfigCommand->command[3], |
ADIJake | 0:85855ecd3257 | 1946 | CORE_DIGITAL_SENSOR_COMMAND4n(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1947 | case 3: |
ADIJake | 0:85855ecd3257 | 1948 | WRITE_REG_U8(hDevice, pConfigCommand->command[2], |
ADIJake | 0:85855ecd3257 | 1949 | CORE_DIGITAL_SENSOR_COMMAND3n(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1950 | case 2: |
ADIJake | 0:85855ecd3257 | 1951 | WRITE_REG_U8(hDevice, pConfigCommand->command[1], |
ADIJake | 0:85855ecd3257 | 1952 | CORE_DIGITAL_SENSOR_COMMAND2n(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1953 | case 1: |
ADIJake | 0:85855ecd3257 | 1954 | WRITE_REG_U8(hDevice, pConfigCommand->command[0], |
ADIJake | 0:85855ecd3257 | 1955 | CORE_DIGITAL_SENSOR_COMMAND1n(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1956 | case 0: |
ADIJake | 0:85855ecd3257 | 1957 | default: |
ADIJake | 0:85855ecd3257 | 1958 | break; |
ADIJake | 0:85855ecd3257 | 1959 | }; |
ADIJake | 0:85855ecd3257 | 1960 | |
ADIJake | 0:85855ecd3257 | 1961 | switch (pDataRequestCommand->commandLength) |
ADIJake | 0:85855ecd3257 | 1962 | { |
ADIJake | 0:85855ecd3257 | 1963 | case 7: |
ADIJake | 0:85855ecd3257 | 1964 | WRITE_REG_U8(hDevice, pDataRequestCommand->command[6], |
ADIJake | 0:85855ecd3257 | 1965 | CORE_DIGITAL_SENSOR_READ_CMD7n(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1966 | case 6: |
ADIJake | 0:85855ecd3257 | 1967 | WRITE_REG_U8(hDevice, pDataRequestCommand->command[5], |
ADIJake | 0:85855ecd3257 | 1968 | CORE_DIGITAL_SENSOR_READ_CMD6n(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1969 | case 5: |
ADIJake | 0:85855ecd3257 | 1970 | WRITE_REG_U8(hDevice, pDataRequestCommand->command[4], |
ADIJake | 0:85855ecd3257 | 1971 | CORE_DIGITAL_SENSOR_READ_CMD5n(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1972 | case 4: |
ADIJake | 0:85855ecd3257 | 1973 | WRITE_REG_U8(hDevice, pDataRequestCommand->command[3], |
ADIJake | 0:85855ecd3257 | 1974 | CORE_DIGITAL_SENSOR_READ_CMD4n(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1975 | case 3: |
ADIJake | 0:85855ecd3257 | 1976 | WRITE_REG_U8(hDevice, pDataRequestCommand->command[2], |
ADIJake | 0:85855ecd3257 | 1977 | CORE_DIGITAL_SENSOR_READ_CMD3n(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1978 | case 2: |
ADIJake | 0:85855ecd3257 | 1979 | WRITE_REG_U8(hDevice, pDataRequestCommand->command[1], |
ADIJake | 0:85855ecd3257 | 1980 | CORE_DIGITAL_SENSOR_READ_CMD2n(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1981 | case 1: |
ADIJake | 0:85855ecd3257 | 1982 | WRITE_REG_U8(hDevice, pDataRequestCommand->command[0], |
ADIJake | 0:85855ecd3257 | 1983 | CORE_DIGITAL_SENSOR_READ_CMD1n(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1984 | case 0: |
ADIJake | 0:85855ecd3257 | 1985 | default: |
ADIJake | 0:85855ecd3257 | 1986 | break; |
ADIJake | 0:85855ecd3257 | 1987 | }; |
ADIJake | 0:85855ecd3257 | 1988 | |
ADIJake | 0:85855ecd3257 | 1989 | /* Re-enable the implicit-fallthrough warning */ |
ADIJake | 0:85855ecd3257 | 1990 | #ifndef __CC_ARM |
ADIJake | 0:85855ecd3257 | 1991 | #pragma GCC diagnostic pop |
ADIJake | 0:85855ecd3257 | 1992 | #endif |
ADIJake | 0:85855ecd3257 | 1993 | |
Vkadaba | 5:0728bde67bdb | 1994 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1995 | } |
ADIJake | 0:85855ecd3257 | 1996 | |
Vkadaba | 5:0728bde67bdb | 1997 | static ADMW_RESULT admw_SetDigitalSensorFormat( |
Vkadaba | 5:0728bde67bdb | 1998 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1999 | ADMW1001_CHANNEL_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 2000 | ADMW1001_DIGITAL_SENSOR_DATA_FORMAT *pDataFormat) |
ADIJake | 0:85855ecd3257 | 2001 | { |
Vkadaba | 5:0728bde67bdb | 2002 | CORE_Digital_Sensor_Config_t sensorConfigReg; |
ADIJake | 0:85855ecd3257 | 2003 | |
ADIJake | 0:85855ecd3257 | 2004 | sensorConfigReg.VALUE16 = REG_RESET_VAL(CORE_DIGITAL_SENSOR_CONFIGn); |
ADIJake | 0:85855ecd3257 | 2005 | |
Vkadaba | 5:0728bde67bdb | 2006 | if (pDataFormat->coding != ADMW1001_DIGITAL_SENSOR_DATA_CODING_NONE) |
ADIJake | 0:85855ecd3257 | 2007 | { |
ADIJake | 0:85855ecd3257 | 2008 | if (pDataFormat->frameLength == 0) |
ADIJake | 0:85855ecd3257 | 2009 | { |
Vkadaba | 5:0728bde67bdb | 2010 | ADMW_LOG_ERROR("Invalid frame length specified for digital sensor data format"); |
Vkadaba | 5:0728bde67bdb | 2011 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2012 | } |
ADIJake | 0:85855ecd3257 | 2013 | if (pDataFormat->numDataBits == 0) |
ADIJake | 0:85855ecd3257 | 2014 | { |
Vkadaba | 5:0728bde67bdb | 2015 | ADMW_LOG_ERROR("Invalid frame length specified for digital sensor data format"); |
Vkadaba | 5:0728bde67bdb | 2016 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2017 | } |
ADIJake | 0:85855ecd3257 | 2018 | |
ADIJake | 0:85855ecd3257 | 2019 | CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_CONFIG_DIGITAL_SENSOR_READ_BYTES, |
ADIJake | 0:85855ecd3257 | 2020 | pDataFormat->frameLength - 1); |
ADIJake | 0:85855ecd3257 | 2021 | CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_CONFIG_DIGITAL_SENSOR_DATA_BITS, |
ADIJake | 0:85855ecd3257 | 2022 | pDataFormat->numDataBits - 1); |
ADIJake | 0:85855ecd3257 | 2023 | CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_CONFIG_DIGITAL_SENSOR_BIT_OFFSET, |
ADIJake | 0:85855ecd3257 | 2024 | pDataFormat->bitOffset); |
ADIJake | 0:85855ecd3257 | 2025 | |
ADIJake | 0:85855ecd3257 | 2026 | sensorConfigReg.Digital_Sensor_Read_Bytes = pDataFormat->frameLength - 1; |
ADIJake | 0:85855ecd3257 | 2027 | sensorConfigReg.Digital_Sensor_Data_Bits = pDataFormat->numDataBits - 1; |
ADIJake | 0:85855ecd3257 | 2028 | sensorConfigReg.Digital_Sensor_Bit_Offset = pDataFormat->bitOffset; |
ADIJake | 0:85855ecd3257 | 2029 | sensorConfigReg.Digital_Sensor_Left_Aligned = pDataFormat->leftJustified ? 1 : 0; |
ADIJake | 0:85855ecd3257 | 2030 | sensorConfigReg.Digital_Sensor_Little_Endian = pDataFormat->littleEndian ? 1 : 0; |
ADIJake | 0:85855ecd3257 | 2031 | |
ADIJake | 0:85855ecd3257 | 2032 | switch (pDataFormat->coding) |
ADIJake | 0:85855ecd3257 | 2033 | { |
Vkadaba | 5:0728bde67bdb | 2034 | case ADMW1001_DIGITAL_SENSOR_DATA_CODING_UNIPOLAR: |
Vkadaba | 5:0728bde67bdb | 2035 | sensorConfigReg.Digital_Sensor_Coding = CORE_DIGITAL_SENSOR_CONFIG_CODING_UNIPOLAR; |
ADIJake | 0:85855ecd3257 | 2036 | break; |
Vkadaba | 5:0728bde67bdb | 2037 | case ADMW1001_DIGITAL_SENSOR_DATA_CODING_TWOS_COMPLEMENT: |
Vkadaba | 5:0728bde67bdb | 2038 | sensorConfigReg.Digital_Sensor_Coding = CORE_DIGITAL_SENSOR_CONFIG_CODING_TWOS_COMPL; |
ADIJake | 0:85855ecd3257 | 2039 | break; |
Vkadaba | 5:0728bde67bdb | 2040 | case ADMW1001_DIGITAL_SENSOR_DATA_CODING_OFFSET_BINARY: |
Vkadaba | 5:0728bde67bdb | 2041 | sensorConfigReg.Digital_Sensor_Coding = CORE_DIGITAL_SENSOR_CONFIG_CODING_OFFSET_BINARY; |
ADIJake | 0:85855ecd3257 | 2042 | break; |
ADIJake | 0:85855ecd3257 | 2043 | default: |
Vkadaba | 5:0728bde67bdb | 2044 | ADMW_LOG_ERROR("Invalid coding specified for digital sensor data format"); |
Vkadaba | 5:0728bde67bdb | 2045 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2046 | } |
ADIJake | 0:85855ecd3257 | 2047 | } |
ADIJake | 0:85855ecd3257 | 2048 | else |
ADIJake | 0:85855ecd3257 | 2049 | { |
Vkadaba | 5:0728bde67bdb | 2050 | sensorConfigReg.Digital_Sensor_Coding = CORE_DIGITAL_SENSOR_CONFIG_CODING_NONE; |
ADIJake | 0:85855ecd3257 | 2051 | } |
ADIJake | 0:85855ecd3257 | 2052 | |
ADIJake | 0:85855ecd3257 | 2053 | WRITE_REG_U16(hDevice, sensorConfigReg.VALUE16, |
ADIJake | 0:85855ecd3257 | 2054 | CORE_DIGITAL_SENSOR_CONFIGn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 2055 | |
ADIJake | 0:85855ecd3257 | 2056 | |
Vkadaba | 5:0728bde67bdb | 2057 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2058 | } |
ADIJake | 0:85855ecd3257 | 2059 | |
Vkadaba | 5:0728bde67bdb | 2060 | static ADMW_RESULT admw_SetDigitalCalibrationParam( |
Vkadaba | 5:0728bde67bdb | 2061 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 2062 | ADMW1001_CHANNEL_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 2063 | ADMW1001_DIGITAL_CALIBRATION_COMMAND *pCalibrationParam) |
ADIJake | 0:85855ecd3257 | 2064 | { |
Vkadaba | 5:0728bde67bdb | 2065 | CORE_Calibration_Parameter_t calibrationParamReg; |
ADIJake | 0:85855ecd3257 | 2066 | |
ADIJake | 0:85855ecd3257 | 2067 | calibrationParamReg.VALUE32 = REG_RESET_VAL(CORE_CALIBRATION_PARAMETERn); |
ADIJake | 0:85855ecd3257 | 2068 | |
ADIJake | 0:85855ecd3257 | 2069 | if (pCalibrationParam->enableCalibrationParam == false) |
ADIJake | 0:85855ecd3257 | 2070 | calibrationParamReg.Calibration_Parameter_Enable = 0; |
ADIJake | 0:85855ecd3257 | 2071 | else |
ADIJake | 0:85855ecd3257 | 2072 | calibrationParamReg.Calibration_Parameter_Enable = 1; |
ADIJake | 0:85855ecd3257 | 2073 | |
ADIJake | 0:85855ecd3257 | 2074 | CHECK_REG_FIELD_VAL(CORE_CALIBRATION_PARAMETER_CALIBRATION_PARAMETER, |
ADIJake | 0:85855ecd3257 | 2075 | pCalibrationParam->calibrationParam); |
ADIJake | 0:85855ecd3257 | 2076 | |
ADIJake | 0:85855ecd3257 | 2077 | calibrationParamReg.Calibration_Parameter = pCalibrationParam->calibrationParam; |
ADIJake | 0:85855ecd3257 | 2078 | |
ADIJake | 0:85855ecd3257 | 2079 | WRITE_REG_U32(hDevice, calibrationParamReg.VALUE32, |
ADIJake | 0:85855ecd3257 | 2080 | CORE_CALIBRATION_PARAMETERn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 2081 | |
Vkadaba | 5:0728bde67bdb | 2082 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2083 | } |
ADIJake | 0:85855ecd3257 | 2084 | |
Vkadaba | 5:0728bde67bdb | 2085 | static ADMW_RESULT admw_SetChannelI2cSensorType( |
Vkadaba | 5:0728bde67bdb | 2086 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 2087 | ADMW1001_CHANNEL_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 2088 | ADMW1001_I2C_SENSOR_TYPE sensorType) |
ADIJake | 0:85855ecd3257 | 2089 | { |
Vkadaba | 5:0728bde67bdb | 2090 | CORE_Sensor_Type_t sensorTypeReg; |
ADIJake | 0:85855ecd3257 | 2091 | |
ADIJake | 0:85855ecd3257 | 2092 | sensorTypeReg.VALUE16 = REG_RESET_VAL(CORE_SENSOR_TYPEn); |
ADIJake | 0:85855ecd3257 | 2093 | |
ADIJake | 0:85855ecd3257 | 2094 | /* Ensure that the sensor type is valid for this channel */ |
ADIJake | 0:85855ecd3257 | 2095 | switch(sensorType) |
ADIJake | 0:85855ecd3257 | 2096 | { |
Vkadaba | 5:0728bde67bdb | 2097 | case ADMW1001_I2C_SENSOR_HUMIDITY_A_DEF_L1: |
Vkadaba | 5:0728bde67bdb | 2098 | case ADMW1001_I2C_SENSOR_HUMIDITY_B_DEF_L1: |
Vkadaba | 5:0728bde67bdb | 2099 | case ADMW1001_I2C_SENSOR_HUMIDITY_A_DEF_L2: |
Vkadaba | 5:0728bde67bdb | 2100 | case ADMW1001_I2C_SENSOR_HUMIDITY_B_DEF_L2: |
Vkadaba | 5:0728bde67bdb | 2101 | case ADMW1001_I2C_SENSOR_HUMIDITY_A_ADV_L1: |
Vkadaba | 5:0728bde67bdb | 2102 | case ADMW1001_I2C_SENSOR_HUMIDITY_B_ADV_L1: |
Vkadaba | 5:0728bde67bdb | 2103 | case ADMW1001_I2C_SENSOR_HUMIDITY_A_ADV_L2: |
Vkadaba | 5:0728bde67bdb | 2104 | case ADMW1001_I2C_SENSOR_HUMIDITY_B_ADV_L2: |
Vkadaba | 5:0728bde67bdb | 2105 | case ADMW1001_I2C_SENSOR_AMBIENTLIGHT_A_DEF_L1: |
Vkadaba | 5:0728bde67bdb | 2106 | case ADMW1001_I2C_SENSOR_AMBIENTLIGHT_A_DEF_L2: |
Vkadaba | 5:0728bde67bdb | 2107 | case ADMW1001_I2C_SENSOR_AMBIENTLIGHT_A_ADV_L1: |
Vkadaba | 5:0728bde67bdb | 2108 | case ADMW1001_I2C_SENSOR_AMBIENTLIGHT_A_ADV_L2: |
ADIJake | 0:85855ecd3257 | 2109 | sensorTypeReg.Sensor_Type = sensorType; |
ADIJake | 0:85855ecd3257 | 2110 | break; |
ADIJake | 0:85855ecd3257 | 2111 | default: |
Vkadaba | 5:0728bde67bdb | 2112 | ADMW_LOG_ERROR("Unsupported I2C sensor type %d specified", sensorType); |
Vkadaba | 5:0728bde67bdb | 2113 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2114 | } |
ADIJake | 0:85855ecd3257 | 2115 | |
ADIJake | 0:85855ecd3257 | 2116 | WRITE_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 2117 | |
Vkadaba | 5:0728bde67bdb | 2118 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2119 | } |
ADIJake | 0:85855ecd3257 | 2120 | |
Vkadaba | 5:0728bde67bdb | 2121 | static ADMW_RESULT admw_SetChannelI2cSensorAddress( |
Vkadaba | 5:0728bde67bdb | 2122 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 2123 | ADMW1001_CHANNEL_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 2124 | uint32_t deviceAddress) |
ADIJake | 0:85855ecd3257 | 2125 | { |
ADIJake | 0:85855ecd3257 | 2126 | CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_ADDRESS_DIGITAL_SENSOR_ADDRESS, deviceAddress); |
ADIJake | 0:85855ecd3257 | 2127 | WRITE_REG_U8(hDevice, deviceAddress, CORE_DIGITAL_SENSOR_ADDRESSn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 2128 | |
Vkadaba | 5:0728bde67bdb | 2129 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2130 | } |
ADIJake | 0:85855ecd3257 | 2131 | |
Vkadaba | 5:0728bde67bdb | 2132 | static ADMW_RESULT admw_SetDigitalChannelComms( |
Vkadaba | 5:0728bde67bdb | 2133 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 2134 | ADMW1001_CHANNEL_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 2135 | ADMW1001_DIGITAL_SENSOR_COMMS *pDigitalComms) |
ADIJake | 0:85855ecd3257 | 2136 | { |
Vkadaba | 5:0728bde67bdb | 2137 | CORE_Digital_Sensor_Comms_t digitalSensorComms; |
ADIJake | 0:85855ecd3257 | 2138 | |
ADIJake | 0:85855ecd3257 | 2139 | digitalSensorComms.VALUE16 = REG_RESET_VAL(CORE_DIGITAL_SENSOR_COMMSn); |
ADIJake | 0:85855ecd3257 | 2140 | |
ADIJake | 0:85855ecd3257 | 2141 | if(pDigitalComms->useCustomCommsConfig) |
ADIJake | 0:85855ecd3257 | 2142 | { |
ADIJake | 0:85855ecd3257 | 2143 | digitalSensorComms.Digital_Sensor_Comms_En = 1; |
ADIJake | 0:85855ecd3257 | 2144 | |
Vkadaba | 5:0728bde67bdb | 2145 | if(pDigitalComms->i2cClockSpeed == ADMW1001_DIGITAL_SENSOR_COMMS_I2C_CLOCK_SPEED_100K) |
ADIJake | 0:85855ecd3257 | 2146 | { |
Vkadaba | 5:0728bde67bdb | 2147 | digitalSensorComms.I2C_Clock = CORE_DIGITAL_SENSOR_COMMS_I2C_100K; |
ADIJake | 0:85855ecd3257 | 2148 | } |
Vkadaba | 5:0728bde67bdb | 2149 | else if(pDigitalComms->i2cClockSpeed == ADMW1001_DIGITAL_SENSOR_COMMS_I2C_CLOCK_SPEED_400K) |
ADIJake | 0:85855ecd3257 | 2150 | { |
Vkadaba | 5:0728bde67bdb | 2151 | digitalSensorComms.I2C_Clock = CORE_DIGITAL_SENSOR_COMMS_I2C_400K; |
ADIJake | 0:85855ecd3257 | 2152 | } |
ADIJake | 0:85855ecd3257 | 2153 | else |
ADIJake | 0:85855ecd3257 | 2154 | { |
Vkadaba | 5:0728bde67bdb | 2155 | ADMW_LOG_ERROR("Invalid I2C clock speed %d specified", |
ADIJake | 0:85855ecd3257 | 2156 | pDigitalComms->i2cClockSpeed); |
Vkadaba | 5:0728bde67bdb | 2157 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2158 | } |
ADIJake | 0:85855ecd3257 | 2159 | |
Vkadaba | 5:0728bde67bdb | 2160 | if(pDigitalComms->spiMode == ADMW1001_DIGITAL_SENSOR_COMMS_SPI_MODE_0) |
ADIJake | 0:85855ecd3257 | 2161 | { |
Vkadaba | 5:0728bde67bdb | 2162 | digitalSensorComms.SPI_Mode = CORE_DIGITAL_SENSOR_COMMS_SPI_MODE_0; |
ADIJake | 0:85855ecd3257 | 2163 | } |
Vkadaba | 5:0728bde67bdb | 2164 | else if(pDigitalComms->spiMode == ADMW1001_DIGITAL_SENSOR_COMMS_SPI_MODE_1) |
ADIJake | 0:85855ecd3257 | 2165 | { |
Vkadaba | 5:0728bde67bdb | 2166 | digitalSensorComms.SPI_Mode = CORE_DIGITAL_SENSOR_COMMS_SPI_MODE_1; |
ADIJake | 0:85855ecd3257 | 2167 | } |
Vkadaba | 5:0728bde67bdb | 2168 | else if(pDigitalComms->spiMode == ADMW1001_DIGITAL_SENSOR_COMMS_SPI_MODE_2) |
ADIJake | 0:85855ecd3257 | 2169 | { |
Vkadaba | 5:0728bde67bdb | 2170 | digitalSensorComms.SPI_Mode = CORE_DIGITAL_SENSOR_COMMS_SPI_MODE_2; |
ADIJake | 0:85855ecd3257 | 2171 | } |
Vkadaba | 5:0728bde67bdb | 2172 | else if(pDigitalComms->spiMode == ADMW1001_DIGITAL_SENSOR_COMMS_SPI_MODE_3) |
ADIJake | 0:85855ecd3257 | 2173 | { |
Vkadaba | 5:0728bde67bdb | 2174 | digitalSensorComms.SPI_Mode = CORE_DIGITAL_SENSOR_COMMS_SPI_MODE_3; |
ADIJake | 0:85855ecd3257 | 2175 | } |
ADIJake | 0:85855ecd3257 | 2176 | else |
ADIJake | 0:85855ecd3257 | 2177 | { |
Vkadaba | 5:0728bde67bdb | 2178 | ADMW_LOG_ERROR("Invalid SPI mode %d specified", |
ADIJake | 0:85855ecd3257 | 2179 | pDigitalComms->spiMode); |
Vkadaba | 5:0728bde67bdb | 2180 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2181 | } |
ADIJake | 0:85855ecd3257 | 2182 | |
ADIJake | 0:85855ecd3257 | 2183 | switch (pDigitalComms->spiClock) |
ADIJake | 0:85855ecd3257 | 2184 | { |
Vkadaba | 5:0728bde67bdb | 2185 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_13MHZ: |
Vkadaba | 5:0728bde67bdb | 2186 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_13MHZ; |
ADIJake | 0:85855ecd3257 | 2187 | break; |
Vkadaba | 5:0728bde67bdb | 2188 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_6_5MHZ: |
Vkadaba | 5:0728bde67bdb | 2189 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_6_5MHZ; |
ADIJake | 0:85855ecd3257 | 2190 | break; |
Vkadaba | 5:0728bde67bdb | 2191 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_3_25MHZ: |
Vkadaba | 5:0728bde67bdb | 2192 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_3_25MHZ; |
ADIJake | 0:85855ecd3257 | 2193 | break; |
Vkadaba | 5:0728bde67bdb | 2194 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_1_625MHZ: |
Vkadaba | 5:0728bde67bdb | 2195 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_1_625MHZ; |
ADIJake | 0:85855ecd3257 | 2196 | break; |
Vkadaba | 5:0728bde67bdb | 2197 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_812KHZ: |
Vkadaba | 5:0728bde67bdb | 2198 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_812KHZ; |
ADIJake | 0:85855ecd3257 | 2199 | break; |
Vkadaba | 5:0728bde67bdb | 2200 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_406KHZ: |
Vkadaba | 5:0728bde67bdb | 2201 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_406KHZ; |
ADIJake | 0:85855ecd3257 | 2202 | break; |
Vkadaba | 5:0728bde67bdb | 2203 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_203KHZ: |
Vkadaba | 5:0728bde67bdb | 2204 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_203KHZ; |
ADIJake | 0:85855ecd3257 | 2205 | break; |
Vkadaba | 5:0728bde67bdb | 2206 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_101KHZ: |
Vkadaba | 5:0728bde67bdb | 2207 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_101KHZ; |
ADIJake | 0:85855ecd3257 | 2208 | break; |
Vkadaba | 5:0728bde67bdb | 2209 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_50KHZ: |
Vkadaba | 5:0728bde67bdb | 2210 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_50KHZ; |
ADIJake | 0:85855ecd3257 | 2211 | break; |
Vkadaba | 5:0728bde67bdb | 2212 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_25KHZ: |
Vkadaba | 5:0728bde67bdb | 2213 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_25KHZ; |
ADIJake | 0:85855ecd3257 | 2214 | break; |
Vkadaba | 5:0728bde67bdb | 2215 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_12KHZ: |
Vkadaba | 5:0728bde67bdb | 2216 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_12KHZ; |
ADIJake | 0:85855ecd3257 | 2217 | break; |
Vkadaba | 5:0728bde67bdb | 2218 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_6KHZ: |
Vkadaba | 5:0728bde67bdb | 2219 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_6KHZ; |
ADIJake | 0:85855ecd3257 | 2220 | break; |
Vkadaba | 5:0728bde67bdb | 2221 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_3KHZ: |
Vkadaba | 5:0728bde67bdb | 2222 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_3KHZ; |
ADIJake | 0:85855ecd3257 | 2223 | break; |
Vkadaba | 5:0728bde67bdb | 2224 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_1_5KHZ: |
Vkadaba | 5:0728bde67bdb | 2225 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_1_5KHZ; |
ADIJake | 0:85855ecd3257 | 2226 | break; |
Vkadaba | 5:0728bde67bdb | 2227 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_793HZ: |
Vkadaba | 5:0728bde67bdb | 2228 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_793HZ; |
ADIJake | 0:85855ecd3257 | 2229 | break; |
Vkadaba | 5:0728bde67bdb | 2230 | case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_396HZ: |
Vkadaba | 5:0728bde67bdb | 2231 | digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_396HZ; |
ADIJake | 0:85855ecd3257 | 2232 | break; |
ADIJake | 0:85855ecd3257 | 2233 | default: |
Vkadaba | 5:0728bde67bdb | 2234 | ADMW_LOG_ERROR("Invalid SPI clock %d specified", |
ADIJake | 0:85855ecd3257 | 2235 | pDigitalComms->spiClock); |
Vkadaba | 5:0728bde67bdb | 2236 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2237 | } |
ADIJake | 0:85855ecd3257 | 2238 | } |
ADIJake | 0:85855ecd3257 | 2239 | else |
ADIJake | 0:85855ecd3257 | 2240 | { |
ADIJake | 0:85855ecd3257 | 2241 | digitalSensorComms.Digital_Sensor_Comms_En = 0; |
ADIJake | 0:85855ecd3257 | 2242 | } |
ADIJake | 0:85855ecd3257 | 2243 | |
ADIJake | 0:85855ecd3257 | 2244 | WRITE_REG_U16(hDevice, digitalSensorComms.VALUE16, CORE_DIGITAL_SENSOR_COMMSn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 2245 | |
Vkadaba | 5:0728bde67bdb | 2246 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2247 | } |
ADIJake | 0:85855ecd3257 | 2248 | |
Vkadaba | 5:0728bde67bdb | 2249 | ADMW_RESULT admw_SetI2cChannelConfig( |
Vkadaba | 5:0728bde67bdb | 2250 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 2251 | ADMW1001_CHANNEL_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 2252 | ADMW1001_CHANNEL_CONFIG *pChannelConfig) |
ADIJake | 0:85855ecd3257 | 2253 | { |
Vkadaba | 5:0728bde67bdb | 2254 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 2255 | ADMW1001_I2C_CHANNEL_CONFIG *pI2cChannelConfig = |
ADIJake | 0:85855ecd3257 | 2256 | &pChannelConfig->i2cChannelConfig; |
ADIJake | 0:85855ecd3257 | 2257 | |
Vkadaba | 5:0728bde67bdb | 2258 | eRet = admw_SetChannelI2cSensorType(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 2259 | pI2cChannelConfig->sensor); |
Vkadaba | 5:0728bde67bdb | 2260 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2261 | { |
Vkadaba | 5:0728bde67bdb | 2262 | ADMW_LOG_ERROR("Failed to set I2C sensor type for channel %d", |
ADIJake | 0:85855ecd3257 | 2263 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2264 | return eRet; |
ADIJake | 0:85855ecd3257 | 2265 | } |
ADIJake | 0:85855ecd3257 | 2266 | |
Vkadaba | 5:0728bde67bdb | 2267 | eRet = admw_SetChannelI2cSensorAddress(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 2268 | pI2cChannelConfig->deviceAddress); |
Vkadaba | 5:0728bde67bdb | 2269 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2270 | { |
Vkadaba | 5:0728bde67bdb | 2271 | ADMW_LOG_ERROR("Failed to set I2C sensor address for channel %d", |
ADIJake | 0:85855ecd3257 | 2272 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2273 | return eRet; |
ADIJake | 0:85855ecd3257 | 2274 | } |
ADIJake | 0:85855ecd3257 | 2275 | |
Vkadaba | 5:0728bde67bdb | 2276 | eRet = admw_SetChannelDigitalSensorDetails(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 2277 | pChannelConfig); |
Vkadaba | 5:0728bde67bdb | 2278 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2279 | { |
Vkadaba | 5:0728bde67bdb | 2280 | ADMW_LOG_ERROR("Failed to set I2C sensor details for channel %d", |
ADIJake | 0:85855ecd3257 | 2281 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2282 | return eRet; |
ADIJake | 0:85855ecd3257 | 2283 | } |
ADIJake | 0:85855ecd3257 | 2284 | |
Vkadaba | 5:0728bde67bdb | 2285 | eRet = admw_SetDigitalSensorCommands(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 2286 | &pI2cChannelConfig->configurationCommand, |
ADIJake | 0:85855ecd3257 | 2287 | &pI2cChannelConfig->dataRequestCommand); |
Vkadaba | 5:0728bde67bdb | 2288 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2289 | { |
Vkadaba | 5:0728bde67bdb | 2290 | ADMW_LOG_ERROR("Failed to set I2C sensor commands for channel %d", |
ADIJake | 0:85855ecd3257 | 2291 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2292 | return eRet; |
ADIJake | 0:85855ecd3257 | 2293 | } |
ADIJake | 0:85855ecd3257 | 2294 | |
Vkadaba | 5:0728bde67bdb | 2295 | eRet = admw_SetDigitalSensorFormat(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 2296 | &pI2cChannelConfig->dataFormat); |
Vkadaba | 5:0728bde67bdb | 2297 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2298 | { |
Vkadaba | 5:0728bde67bdb | 2299 | ADMW_LOG_ERROR("Failed to set I2C sensor data format for channel %d", |
ADIJake | 0:85855ecd3257 | 2300 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2301 | return eRet; |
ADIJake | 0:85855ecd3257 | 2302 | } |
ADIJake | 0:85855ecd3257 | 2303 | |
Vkadaba | 5:0728bde67bdb | 2304 | eRet = admw_SetDigitalCalibrationParam(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 2305 | &pI2cChannelConfig->digitalCalibrationParam); |
Vkadaba | 5:0728bde67bdb | 2306 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2307 | { |
Vkadaba | 5:0728bde67bdb | 2308 | ADMW_LOG_ERROR("Failed to set I2C digital calibration param for channel %d", |
ADIJake | 0:85855ecd3257 | 2309 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2310 | return eRet; |
ADIJake | 0:85855ecd3257 | 2311 | } |
ADIJake | 0:85855ecd3257 | 2312 | |
Vkadaba | 5:0728bde67bdb | 2313 | eRet = admw_SetDigitalChannelComms(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 2314 | &pI2cChannelConfig->configureComms); |
Vkadaba | 5:0728bde67bdb | 2315 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2316 | { |
Vkadaba | 5:0728bde67bdb | 2317 | ADMW_LOG_ERROR("Failed to set I2C comms for channel %d", |
ADIJake | 0:85855ecd3257 | 2318 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2319 | return eRet; |
ADIJake | 0:85855ecd3257 | 2320 | } |
ADIJake | 0:85855ecd3257 | 2321 | |
Vkadaba | 5:0728bde67bdb | 2322 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2323 | } |
ADIJake | 0:85855ecd3257 | 2324 | |
Vkadaba | 5:0728bde67bdb | 2325 | static ADMW_RESULT admw_SetChannelSpiSensorType( |
Vkadaba | 5:0728bde67bdb | 2326 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 2327 | ADMW1001_CHANNEL_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 2328 | ADMW1001_SPI_SENSOR_TYPE sensorType) |
ADIJake | 0:85855ecd3257 | 2329 | { |
Vkadaba | 5:0728bde67bdb | 2330 | CORE_Sensor_Type_t sensorTypeReg; |
ADIJake | 0:85855ecd3257 | 2331 | |
ADIJake | 0:85855ecd3257 | 2332 | sensorTypeReg.VALUE16 = REG_RESET_VAL(CORE_SENSOR_TYPEn); |
ADIJake | 0:85855ecd3257 | 2333 | |
ADIJake | 0:85855ecd3257 | 2334 | /* Ensure that the sensor type is valid for this channel */ |
ADIJake | 0:85855ecd3257 | 2335 | switch(sensorType) |
ADIJake | 0:85855ecd3257 | 2336 | { |
Vkadaba | 5:0728bde67bdb | 2337 | case ADMW1001_SPI_SENSOR_PRESSURE_A_DEF_L1: |
Vkadaba | 5:0728bde67bdb | 2338 | case ADMW1001_SPI_SENSOR_PRESSURE_A_DEF_L2: |
Vkadaba | 5:0728bde67bdb | 2339 | case ADMW1001_SPI_SENSOR_PRESSURE_A_ADV_L1: |
Vkadaba | 5:0728bde67bdb | 2340 | case ADMW1001_SPI_SENSOR_PRESSURE_A_ADV_L2: |
Vkadaba | 5:0728bde67bdb | 2341 | case ADMW1001_SPI_SENSOR_ACCELEROMETER_A_DEF_L1: |
Vkadaba | 5:0728bde67bdb | 2342 | case ADMW1001_SPI_SENSOR_ACCELEROMETER_B_DEF_L1: |
Vkadaba | 5:0728bde67bdb | 2343 | case ADMW1001_SPI_SENSOR_ACCELEROMETER_A_DEF_L2: |
Vkadaba | 5:0728bde67bdb | 2344 | case ADMW1001_SPI_SENSOR_ACCELEROMETER_B_DEF_L2: |
Vkadaba | 5:0728bde67bdb | 2345 | case ADMW1001_SPI_SENSOR_ACCELEROMETER_A_ADV_L1: |
Vkadaba | 5:0728bde67bdb | 2346 | case ADMW1001_SPI_SENSOR_ACCELEROMETER_B_ADV_L1: |
Vkadaba | 5:0728bde67bdb | 2347 | case ADMW1001_SPI_SENSOR_ACCELEROMETER_A_ADV_L2: |
Vkadaba | 5:0728bde67bdb | 2348 | case ADMW1001_SPI_SENSOR_ACCELEROMETER_B_ADV_L2: |
ADIJake | 0:85855ecd3257 | 2349 | sensorTypeReg.Sensor_Type = sensorType; |
ADIJake | 0:85855ecd3257 | 2350 | break; |
ADIJake | 0:85855ecd3257 | 2351 | default: |
Vkadaba | 5:0728bde67bdb | 2352 | ADMW_LOG_ERROR("Unsupported SPI sensor type %d specified", sensorType); |
Vkadaba | 5:0728bde67bdb | 2353 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2354 | } |
ADIJake | 0:85855ecd3257 | 2355 | |
ADIJake | 0:85855ecd3257 | 2356 | WRITE_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 2357 | |
Vkadaba | 5:0728bde67bdb | 2358 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2359 | } |
ADIJake | 0:85855ecd3257 | 2360 | |
Vkadaba | 5:0728bde67bdb | 2361 | ADMW_RESULT admw_SetSpiChannelConfig( |
Vkadaba | 5:0728bde67bdb | 2362 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 2363 | ADMW1001_CHANNEL_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 2364 | ADMW1001_CHANNEL_CONFIG *pChannelConfig) |
ADIJake | 0:85855ecd3257 | 2365 | { |
Vkadaba | 5:0728bde67bdb | 2366 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 2367 | ADMW1001_SPI_CHANNEL_CONFIG *pSpiChannelConfig = |
ADIJake | 0:85855ecd3257 | 2368 | &pChannelConfig->spiChannelConfig; |
ADIJake | 0:85855ecd3257 | 2369 | |
Vkadaba | 5:0728bde67bdb | 2370 | eRet = admw_SetChannelSpiSensorType(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 2371 | pSpiChannelConfig->sensor); |
Vkadaba | 5:0728bde67bdb | 2372 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2373 | { |
Vkadaba | 5:0728bde67bdb | 2374 | ADMW_LOG_ERROR("Failed to set SPI sensor type for channel %d", |
ADIJake | 0:85855ecd3257 | 2375 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2376 | return eRet; |
ADIJake | 0:85855ecd3257 | 2377 | } |
ADIJake | 0:85855ecd3257 | 2378 | |
Vkadaba | 5:0728bde67bdb | 2379 | eRet = admw_SetChannelDigitalSensorDetails(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 2380 | pChannelConfig); |
Vkadaba | 5:0728bde67bdb | 2381 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2382 | { |
Vkadaba | 5:0728bde67bdb | 2383 | ADMW_LOG_ERROR("Failed to set SPI sensor details for channel %d", |
ADIJake | 0:85855ecd3257 | 2384 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2385 | return eRet; |
ADIJake | 0:85855ecd3257 | 2386 | } |
ADIJake | 0:85855ecd3257 | 2387 | |
Vkadaba | 5:0728bde67bdb | 2388 | eRet = admw_SetDigitalSensorCommands(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 2389 | &pSpiChannelConfig->configurationCommand, |
ADIJake | 0:85855ecd3257 | 2390 | &pSpiChannelConfig->dataRequestCommand); |
Vkadaba | 5:0728bde67bdb | 2391 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2392 | { |
Vkadaba | 5:0728bde67bdb | 2393 | ADMW_LOG_ERROR("Failed to set SPI sensor commands for channel %d", |
ADIJake | 0:85855ecd3257 | 2394 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2395 | return eRet; |
ADIJake | 0:85855ecd3257 | 2396 | } |
ADIJake | 0:85855ecd3257 | 2397 | |
Vkadaba | 5:0728bde67bdb | 2398 | eRet = admw_SetDigitalSensorFormat(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 2399 | &pSpiChannelConfig->dataFormat); |
Vkadaba | 5:0728bde67bdb | 2400 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2401 | { |
Vkadaba | 5:0728bde67bdb | 2402 | ADMW_LOG_ERROR("Failed to set SPI sensor data format for channel %d", |
ADIJake | 0:85855ecd3257 | 2403 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2404 | return eRet; |
ADIJake | 0:85855ecd3257 | 2405 | } |
ADIJake | 0:85855ecd3257 | 2406 | |
Vkadaba | 5:0728bde67bdb | 2407 | eRet = admw_SetDigitalCalibrationParam(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 2408 | &pSpiChannelConfig->digitalCalibrationParam); |
Vkadaba | 5:0728bde67bdb | 2409 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2410 | { |
Vkadaba | 5:0728bde67bdb | 2411 | ADMW_LOG_ERROR("Failed to set SPI digital calibration param for channel %d", |
ADIJake | 0:85855ecd3257 | 2412 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2413 | return eRet; |
ADIJake | 0:85855ecd3257 | 2414 | } |
ADIJake | 0:85855ecd3257 | 2415 | |
Vkadaba | 5:0728bde67bdb | 2416 | eRet = admw_SetDigitalChannelComms(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 2417 | &pSpiChannelConfig->configureComms); |
Vkadaba | 5:0728bde67bdb | 2418 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2419 | { |
Vkadaba | 5:0728bde67bdb | 2420 | ADMW_LOG_ERROR("Failed to set SPI comms for channel %d", |
ADIJake | 0:85855ecd3257 | 2421 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2422 | return eRet; |
ADIJake | 0:85855ecd3257 | 2423 | } |
ADIJake | 0:85855ecd3257 | 2424 | |
Vkadaba | 5:0728bde67bdb | 2425 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2426 | } |
ADIJake | 0:85855ecd3257 | 2427 | |
Vkadaba | 5:0728bde67bdb | 2428 | ADMW_RESULT admw1001_SetChannelThresholdLimits( |
Vkadaba | 5:0728bde67bdb | 2429 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 2430 | ADMW1001_CHANNEL_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 2431 | float32_t fHighThresholdLimit, |
ADIJake | 0:85855ecd3257 | 2432 | float32_t fLowThresholdLimit) |
ADIJake | 0:85855ecd3257 | 2433 | { |
ADIJake | 0:85855ecd3257 | 2434 | /* |
ADIJake | 0:85855ecd3257 | 2435 | * If the low/high limits are *both* set to 0 in memory, or NaNs, assume |
ADIJake | 0:85855ecd3257 | 2436 | * that they are unset, or not required, and use infinity defaults instead |
ADIJake | 0:85855ecd3257 | 2437 | */ |
ADIJake | 0:85855ecd3257 | 2438 | if (fHighThresholdLimit == 0.0f && fLowThresholdLimit == 0.0f) |
ADIJake | 0:85855ecd3257 | 2439 | { |
ADIJake | 0:85855ecd3257 | 2440 | fHighThresholdLimit = INFINITY; |
ADIJake | 0:85855ecd3257 | 2441 | fLowThresholdLimit = -INFINITY; |
ADIJake | 0:85855ecd3257 | 2442 | } |
ADIJake | 0:85855ecd3257 | 2443 | else |
ADIJake | 0:85855ecd3257 | 2444 | { |
ADIJake | 0:85855ecd3257 | 2445 | if (isnan(fHighThresholdLimit)) |
ADIJake | 0:85855ecd3257 | 2446 | fHighThresholdLimit = INFINITY; |
ADIJake | 0:85855ecd3257 | 2447 | if (isnan(fLowThresholdLimit)) |
ADIJake | 0:85855ecd3257 | 2448 | fLowThresholdLimit = -INFINITY; |
ADIJake | 0:85855ecd3257 | 2449 | } |
ADIJake | 0:85855ecd3257 | 2450 | |
ADIJake | 0:85855ecd3257 | 2451 | WRITE_REG_FLOAT(hDevice, fHighThresholdLimit, |
ADIJake | 0:85855ecd3257 | 2452 | CORE_HIGH_THRESHOLD_LIMITn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 2453 | WRITE_REG_FLOAT(hDevice, fLowThresholdLimit, |
ADIJake | 0:85855ecd3257 | 2454 | CORE_LOW_THRESHOLD_LIMITn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 2455 | |
Vkadaba | 5:0728bde67bdb | 2456 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2457 | } |
ADIJake | 0:85855ecd3257 | 2458 | |
Vkadaba | 5:0728bde67bdb | 2459 | ADMW_RESULT admw1001_SetOffsetGain( |
Vkadaba | 5:0728bde67bdb | 2460 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 2461 | ADMW1001_CHANNEL_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 2462 | float32_t fOffsetAdjustment, |
ADIJake | 0:85855ecd3257 | 2463 | float32_t fGainAdjustment) |
ADIJake | 0:85855ecd3257 | 2464 | { |
ADIJake | 0:85855ecd3257 | 2465 | /* Replace with default values if NaNs are specified (or 0.0 for gain) */ |
ADIJake | 0:85855ecd3257 | 2466 | if (isnan(fGainAdjustment) || (fGainAdjustment == 0.0f)) |
ADIJake | 0:85855ecd3257 | 2467 | fGainAdjustment = 1.0f; |
ADIJake | 0:85855ecd3257 | 2468 | if (isnan(fOffsetAdjustment)) |
ADIJake | 0:85855ecd3257 | 2469 | fOffsetAdjustment = 0.0f; |
ADIJake | 0:85855ecd3257 | 2470 | |
ADIJake | 0:85855ecd3257 | 2471 | WRITE_REG_FLOAT(hDevice, fGainAdjustment, CORE_SENSOR_GAINn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 2472 | WRITE_REG_FLOAT(hDevice, fOffsetAdjustment, CORE_SENSOR_OFFSETn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 2473 | |
Vkadaba | 5:0728bde67bdb | 2474 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2475 | } |
ADIJake | 0:85855ecd3257 | 2476 | |
Vkadaba | 5:0728bde67bdb | 2477 | ADMW_RESULT admw1001_SetSensorParameter( |
Vkadaba | 5:0728bde67bdb | 2478 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 2479 | ADMW1001_CHANNEL_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 2480 | float32_t fSensorParam) |
ADIJake | 0:85855ecd3257 | 2481 | { |
ADIJake | 0:85855ecd3257 | 2482 | if (fSensorParam == 0.0f) |
ADIJake | 0:85855ecd3257 | 2483 | fSensorParam = NAN; |
ADIJake | 0:85855ecd3257 | 2484 | |
ADIJake | 0:85855ecd3257 | 2485 | WRITE_REG_FLOAT(hDevice, fSensorParam, CORE_SENSOR_PARAMETERn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 2486 | |
Vkadaba | 5:0728bde67bdb | 2487 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2488 | } |
ADIJake | 0:85855ecd3257 | 2489 | |
Vkadaba | 5:0728bde67bdb | 2490 | ADMW_RESULT admw1001_SetChannelSettlingTime( |
Vkadaba | 5:0728bde67bdb | 2491 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 2492 | ADMW1001_CHANNEL_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 2493 | uint32_t nSettlingTime) |
ADIJake | 0:85855ecd3257 | 2494 | { |
Vkadaba | 5:0728bde67bdb | 2495 | CORE_Settling_Time_t settlingTimeReg; |
ADIJake | 0:85855ecd3257 | 2496 | |
ADIJake | 0:85855ecd3257 | 2497 | if (nSettlingTime < (1 << 12)) |
ADIJake | 0:85855ecd3257 | 2498 | { |
Vkadaba | 5:0728bde67bdb | 2499 | settlingTimeReg.Settling_Time_Units = CORE_SETTLING_TIME_MICROSECONDS; |
ADIJake | 0:85855ecd3257 | 2500 | } |
ADIJake | 0:85855ecd3257 | 2501 | else if (nSettlingTime < (1000 * (1 << 12))) |
ADIJake | 0:85855ecd3257 | 2502 | { |
Vkadaba | 5:0728bde67bdb | 2503 | settlingTimeReg.Settling_Time_Units = CORE_SETTLING_TIME_MILLISECONDS; |
ADIJake | 0:85855ecd3257 | 2504 | nSettlingTime /= 1000; |
ADIJake | 0:85855ecd3257 | 2505 | } |
ADIJake | 0:85855ecd3257 | 2506 | else |
ADIJake | 0:85855ecd3257 | 2507 | { |
Vkadaba | 5:0728bde67bdb | 2508 | settlingTimeReg.Settling_Time_Units = CORE_SETTLING_TIME_SECONDS; |
ADIJake | 0:85855ecd3257 | 2509 | nSettlingTime /= 1000000; |
ADIJake | 0:85855ecd3257 | 2510 | } |
ADIJake | 0:85855ecd3257 | 2511 | |
ADIJake | 0:85855ecd3257 | 2512 | CHECK_REG_FIELD_VAL(CORE_SETTLING_TIME_SETTLING_TIME, nSettlingTime); |
ADIJake | 0:85855ecd3257 | 2513 | settlingTimeReg.Settling_Time = nSettlingTime; |
ADIJake | 0:85855ecd3257 | 2514 | |
ADIJake | 0:85855ecd3257 | 2515 | WRITE_REG_U16(hDevice, settlingTimeReg.VALUE16, CORE_SETTLING_TIMEn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 2516 | |
Vkadaba | 5:0728bde67bdb | 2517 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2518 | } |
ADIJake | 0:85855ecd3257 | 2519 | |
Vkadaba | 5:0728bde67bdb | 2520 | ADMW_RESULT admw1001_SetChannelConfig( |
Vkadaba | 5:0728bde67bdb | 2521 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 2522 | ADMW1001_CHANNEL_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 2523 | ADMW1001_CHANNEL_CONFIG *pChannelConfig) |
ADIJake | 0:85855ecd3257 | 2524 | { |
Vkadaba | 5:0728bde67bdb | 2525 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 2526 | |
Vkadaba | 5:0728bde67bdb | 2527 | if (! ADMW1001_CHANNEL_IS_VIRTUAL(eChannelId)) |
ADIJake | 0:85855ecd3257 | 2528 | { |
Vkadaba | 5:0728bde67bdb | 2529 | eRet = admw1001_SetChannelCount(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 2530 | pChannelConfig->enableChannel ? |
ADIJake | 0:85855ecd3257 | 2531 | pChannelConfig->measurementsPerCycle : 0); |
Vkadaba | 5:0728bde67bdb | 2532 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2533 | { |
Vkadaba | 5:0728bde67bdb | 2534 | ADMW_LOG_ERROR("Failed to set measurement count for channel %d", |
ADIJake | 0:85855ecd3257 | 2535 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2536 | return eRet; |
ADIJake | 0:85855ecd3257 | 2537 | } |
ADIJake | 0:85855ecd3257 | 2538 | |
Vkadaba | 5:0728bde67bdb | 2539 | eRet = admw1001_SetChannelOptions(hDevice, eChannelId, |
Vkadaba | 6:9d393a9677f4 | 2540 | pChannelConfig->priority); |
Vkadaba | 5:0728bde67bdb | 2541 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2542 | { |
Vkadaba | 5:0728bde67bdb | 2543 | ADMW_LOG_ERROR("Failed to set priority for channel %d", |
ADIJake | 0:85855ecd3257 | 2544 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2545 | return eRet; |
ADIJake | 0:85855ecd3257 | 2546 | } |
ADIJake | 0:85855ecd3257 | 2547 | |
ADIJake | 0:85855ecd3257 | 2548 | /* If the channel is not enabled, we can skip the following steps */ |
Vkadaba | 6:9d393a9677f4 | 2549 | if (pChannelConfig->enableChannel) |
ADIJake | 0:85855ecd3257 | 2550 | { |
Vkadaba | 5:0728bde67bdb | 2551 | eRet = admw1001_SetChannelSkipCount(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 2552 | pChannelConfig->cycleSkipCount); |
Vkadaba | 5:0728bde67bdb | 2553 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2554 | { |
Vkadaba | 5:0728bde67bdb | 2555 | ADMW_LOG_ERROR("Failed to set cycle skip count for channel %d", |
ADIJake | 0:85855ecd3257 | 2556 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2557 | return eRet; |
ADIJake | 0:85855ecd3257 | 2558 | } |
ADIJake | 0:85855ecd3257 | 2559 | |
ADIJake | 0:85855ecd3257 | 2560 | switch (eChannelId) |
ADIJake | 0:85855ecd3257 | 2561 | { |
Vkadaba | 6:9d393a9677f4 | 2562 | case ADMW1001_CHANNEL_ID_ANALOG_1_UNIVERSAL: |
Vkadaba | 6:9d393a9677f4 | 2563 | case ADMW1001_CHANNEL_ID_ANALOG_2_UNIVERSAL: |
Vkadaba | 6:9d393a9677f4 | 2564 | case ADMW1001_CHANNEL_ID_ANALOG_1_DIFFERENTIAL: |
Vkadaba | 6:9d393a9677f4 | 2565 | case ADMW1001_CHANNEL_ID_ANALOG_2_DIFFERENTIAL: |
Vkadaba | 5:0728bde67bdb | 2566 | eRet = admw_SetAdcChannelConfig(hDevice, eChannelId, pChannelConfig); |
ADIJake | 0:85855ecd3257 | 2567 | break; |
Vkadaba | 5:0728bde67bdb | 2568 | case ADMW1001_CHANNEL_ID_I2C_0: |
Vkadaba | 5:0728bde67bdb | 2569 | case ADMW1001_CHANNEL_ID_I2C_1: |
Vkadaba | 5:0728bde67bdb | 2570 | eRet = admw_SetI2cChannelConfig(hDevice, eChannelId, pChannelConfig); |
ADIJake | 0:85855ecd3257 | 2571 | break; |
Vkadaba | 5:0728bde67bdb | 2572 | case ADMW1001_CHANNEL_ID_SPI_0: |
Vkadaba | 5:0728bde67bdb | 2573 | eRet = admw_SetSpiChannelConfig(hDevice, eChannelId, pChannelConfig); |
ADIJake | 0:85855ecd3257 | 2574 | break; |
ADIJake | 0:85855ecd3257 | 2575 | default: |
Vkadaba | 5:0728bde67bdb | 2576 | ADMW_LOG_ERROR("Invalid channel ID %d specified", eChannelId); |
Vkadaba | 5:0728bde67bdb | 2577 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2578 | } |
ADIJake | 0:85855ecd3257 | 2579 | |
Vkadaba | 5:0728bde67bdb | 2580 | eRet = admw1001_SetChannelSettlingTime(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 2581 | pChannelConfig->extraSettlingTime); |
Vkadaba | 5:0728bde67bdb | 2582 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2583 | { |
Vkadaba | 5:0728bde67bdb | 2584 | ADMW_LOG_ERROR("Failed to set settling time for channel %d", |
ADIJake | 0:85855ecd3257 | 2585 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2586 | return eRet; |
ADIJake | 0:85855ecd3257 | 2587 | } |
ADIJake | 0:85855ecd3257 | 2588 | } |
ADIJake | 0:85855ecd3257 | 2589 | } |
ADIJake | 0:85855ecd3257 | 2590 | |
Vkadaba | 6:9d393a9677f4 | 2591 | if (pChannelConfig->enableChannel) |
ADIJake | 0:85855ecd3257 | 2592 | { |
ADIJake | 0:85855ecd3257 | 2593 | /* Threshold limits can be configured individually for virtual channels */ |
Vkadaba | 5:0728bde67bdb | 2594 | eRet = admw1001_SetChannelThresholdLimits(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 2595 | pChannelConfig->highThreshold, |
ADIJake | 0:85855ecd3257 | 2596 | pChannelConfig->lowThreshold); |
Vkadaba | 5:0728bde67bdb | 2597 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2598 | { |
Vkadaba | 5:0728bde67bdb | 2599 | ADMW_LOG_ERROR("Failed to set threshold limits for channel %d", |
ADIJake | 0:85855ecd3257 | 2600 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2601 | return eRet; |
ADIJake | 0:85855ecd3257 | 2602 | } |
ADIJake | 0:85855ecd3257 | 2603 | |
ADIJake | 0:85855ecd3257 | 2604 | /* Offset and gain can be configured individually for virtual channels */ |
Vkadaba | 5:0728bde67bdb | 2605 | eRet = admw1001_SetOffsetGain(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 2606 | pChannelConfig->offsetAdjustment, |
ADIJake | 0:85855ecd3257 | 2607 | pChannelConfig->gainAdjustment); |
Vkadaba | 5:0728bde67bdb | 2608 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2609 | { |
Vkadaba | 5:0728bde67bdb | 2610 | ADMW_LOG_ERROR("Failed to set offset/gain for channel %d", |
ADIJake | 0:85855ecd3257 | 2611 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2612 | return eRet; |
ADIJake | 0:85855ecd3257 | 2613 | } |
ADIJake | 0:85855ecd3257 | 2614 | |
ADIJake | 0:85855ecd3257 | 2615 | /* Set sensor specific parameter */ |
Vkadaba | 5:0728bde67bdb | 2616 | eRet = admw1001_SetSensorParameter(hDevice, eChannelId, |
ADIJake | 0:85855ecd3257 | 2617 | pChannelConfig->sensorParameter); |
Vkadaba | 5:0728bde67bdb | 2618 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2619 | { |
Vkadaba | 5:0728bde67bdb | 2620 | ADMW_LOG_ERROR("Failed to set sensor parameter for channel %d", |
ADIJake | 0:85855ecd3257 | 2621 | eChannelId); |
ADIJake | 0:85855ecd3257 | 2622 | return eRet; |
ADIJake | 0:85855ecd3257 | 2623 | } |
ADIJake | 0:85855ecd3257 | 2624 | } |
ADIJake | 0:85855ecd3257 | 2625 | |
Vkadaba | 5:0728bde67bdb | 2626 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2627 | } |
ADIJake | 0:85855ecd3257 | 2628 | |
Vkadaba | 5:0728bde67bdb | 2629 | ADMW_RESULT admw_SetConfig( |
Vkadaba | 5:0728bde67bdb | 2630 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 2631 | ADMW_CONFIG * const pConfig) |
ADIJake | 0:85855ecd3257 | 2632 | { |
Vkadaba | 5:0728bde67bdb | 2633 | ADMW1001_CONFIG *pDeviceConfig; |
Vkadaba | 5:0728bde67bdb | 2634 | ADMW_PRODUCT_ID productId; |
Vkadaba | 5:0728bde67bdb | 2635 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 2636 | |
Vkadaba | 5:0728bde67bdb | 2637 | if (pConfig->productId != ADMW_PRODUCT_ID_ADMW1001) |
ADIJake | 0:85855ecd3257 | 2638 | { |
Vkadaba | 5:0728bde67bdb | 2639 | ADMW_LOG_ERROR("Configuration Product ID (0x%X) is not supported (0x%0X)", |
Vkadaba | 5:0728bde67bdb | 2640 | pConfig->productId, ADMW_PRODUCT_ID_ADMW1001); |
Vkadaba | 5:0728bde67bdb | 2641 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2642 | } |
Vkadaba | 6:9d393a9677f4 | 2643 | |
Vkadaba | 6:9d393a9677f4 | 2644 | if(!((pConfig->versionId.major==VERSIONID_MAJOR) && (pConfig->versionId.minor==VERSIONID_MINOR))) |
Vkadaba | 6:9d393a9677f4 | 2645 | { |
Vkadaba | 6:9d393a9677f4 | 2646 | ADMW_LOG_ERROR("Configuration Version ID (0x%X) is not supported", |
Vkadaba | 6:9d393a9677f4 | 2647 | pConfig->versionId); |
Vkadaba | 6:9d393a9677f4 | 2648 | return ADMW_INVALID_PARAM; |
Vkadaba | 6:9d393a9677f4 | 2649 | } |
Vkadaba | 6:9d393a9677f4 | 2650 | |
Vkadaba | 6:9d393a9677f4 | 2651 | |
ADIJake | 0:85855ecd3257 | 2652 | /* Check that the actual Product ID is a match? */ |
Vkadaba | 5:0728bde67bdb | 2653 | eRet = admw_GetProductID(hDevice, &productId); |
ADIJake | 0:85855ecd3257 | 2654 | if (eRet) |
ADIJake | 0:85855ecd3257 | 2655 | { |
Vkadaba | 5:0728bde67bdb | 2656 | ADMW_LOG_ERROR("Failed to read device Product ID register"); |
ADIJake | 0:85855ecd3257 | 2657 | return eRet; |
ADIJake | 0:85855ecd3257 | 2658 | } |
ADIJake | 0:85855ecd3257 | 2659 | if (pConfig->productId != productId) |
ADIJake | 0:85855ecd3257 | 2660 | { |
Vkadaba | 5:0728bde67bdb | 2661 | ADMW_LOG_ERROR("Configuration Product ID (0x%X) does not match device (0x%0X)", |
ADIJake | 0:85855ecd3257 | 2662 | pConfig->productId, productId); |
Vkadaba | 5:0728bde67bdb | 2663 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2664 | } |
ADIJake | 0:85855ecd3257 | 2665 | |
Vkadaba | 5:0728bde67bdb | 2666 | pDeviceConfig = &pConfig->admw1001; |
Vkadaba | 5:0728bde67bdb | 2667 | |
Vkadaba | 5:0728bde67bdb | 2668 | eRet = admw1001_SetPowerConfig(hDevice, &pDeviceConfig->power); |
ADIJake | 0:85855ecd3257 | 2669 | if (eRet) |
ADIJake | 0:85855ecd3257 | 2670 | { |
Vkadaba | 5:0728bde67bdb | 2671 | ADMW_LOG_ERROR("Failed to set power configuration"); |
ADIJake | 0:85855ecd3257 | 2672 | return eRet; |
ADIJake | 0:85855ecd3257 | 2673 | } |
ADIJake | 0:85855ecd3257 | 2674 | |
Vkadaba | 5:0728bde67bdb | 2675 | eRet = admw1001_SetMeasurementConfig(hDevice, &pDeviceConfig->measurement); |
ADIJake | 0:85855ecd3257 | 2676 | if (eRet) |
ADIJake | 0:85855ecd3257 | 2677 | { |
Vkadaba | 5:0728bde67bdb | 2678 | ADMW_LOG_ERROR("Failed to set measurement configuration"); |
ADIJake | 0:85855ecd3257 | 2679 | return eRet; |
ADIJake | 0:85855ecd3257 | 2680 | } |
ADIJake | 0:85855ecd3257 | 2681 | |
Vkadaba | 5:0728bde67bdb | 2682 | eRet = admw1001_SetDiagnosticsConfig(hDevice, &pDeviceConfig->diagnostics); |
ADIJake | 0:85855ecd3257 | 2683 | if (eRet) |
ADIJake | 0:85855ecd3257 | 2684 | { |
Vkadaba | 5:0728bde67bdb | 2685 | ADMW_LOG_ERROR("Failed to set diagnostics configuration"); |
ADIJake | 0:85855ecd3257 | 2686 | return eRet; |
ADIJake | 0:85855ecd3257 | 2687 | } |
ADIJake | 0:85855ecd3257 | 2688 | |
Vkadaba | 6:9d393a9677f4 | 2689 | for (ADMW1001_CHANNEL_ID id = ADMW1001_CHANNEL_ID_ANALOG_1_UNIVERSAL; |
Vkadaba | 5:0728bde67bdb | 2690 | id < ADMW1001_MAX_CHANNELS; |
ADIJake | 0:85855ecd3257 | 2691 | id++) |
ADIJake | 0:85855ecd3257 | 2692 | { |
Vkadaba | 5:0728bde67bdb | 2693 | eRet = admw1001_SetChannelConfig(hDevice, id, |
ADIJake | 0:85855ecd3257 | 2694 | &pDeviceConfig->channels[id]); |
ADIJake | 0:85855ecd3257 | 2695 | if (eRet) |
ADIJake | 0:85855ecd3257 | 2696 | { |
Vkadaba | 5:0728bde67bdb | 2697 | ADMW_LOG_ERROR("Failed to set channel %d configuration", id); |
ADIJake | 0:85855ecd3257 | 2698 | return eRet; |
ADIJake | 0:85855ecd3257 | 2699 | } |
ADIJake | 0:85855ecd3257 | 2700 | } |
ADIJake | 0:85855ecd3257 | 2701 | |
Vkadaba | 5:0728bde67bdb | 2702 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2703 | } |
ADIJake | 0:85855ecd3257 | 2704 | |
Vkadaba | 6:9d393a9677f4 | 2705 | |
Vkadaba | 5:0728bde67bdb | 2706 | ADMW_RESULT admw1001_SetLutData( |
Vkadaba | 5:0728bde67bdb | 2707 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 2708 | ADMW1001_LUT * const pLutData) |
ADIJake | 0:85855ecd3257 | 2709 | { |
Vkadaba | 5:0728bde67bdb | 2710 | ADMW1001_LUT_HEADER *pLutHeader = &pLutData->header; |
Vkadaba | 5:0728bde67bdb | 2711 | ADMW1001_LUT_TABLE *pLutTable = pLutData->tables; |
ADIJake | 0:85855ecd3257 | 2712 | unsigned actualLength = 0; |
ADIJake | 0:85855ecd3257 | 2713 | |
Vkadaba | 5:0728bde67bdb | 2714 | if (pLutData->header.signature != ADMW_LUT_SIGNATURE) |
ADIJake | 0:85855ecd3257 | 2715 | { |
Vkadaba | 5:0728bde67bdb | 2716 | ADMW_LOG_ERROR("LUT signature incorrect (expected 0x%X, actual 0x%X)", |
Vkadaba | 5:0728bde67bdb | 2717 | ADMW_LUT_SIGNATURE, pLutHeader->signature); |
Vkadaba | 5:0728bde67bdb | 2718 | return ADMW_INVALID_SIGNATURE; |
ADIJake | 0:85855ecd3257 | 2719 | } |
ADIJake | 0:85855ecd3257 | 2720 | |
ADIJake | 0:85855ecd3257 | 2721 | for (unsigned i = 0; i < pLutHeader->numTables; i++) |
ADIJake | 0:85855ecd3257 | 2722 | { |
Vkadaba | 5:0728bde67bdb | 2723 | ADMW1001_LUT_DESCRIPTOR *pDesc = &pLutTable->descriptor; |
Vkadaba | 5:0728bde67bdb | 2724 | ADMW1001_LUT_TABLE_DATA *pData = &pLutTable->data; |
ADIJake | 0:85855ecd3257 | 2725 | unsigned short calculatedCrc; |
ADIJake | 0:85855ecd3257 | 2726 | |
ADIJake | 0:85855ecd3257 | 2727 | switch (pDesc->geometry) |
ADIJake | 0:85855ecd3257 | 2728 | { |
Vkadaba | 5:0728bde67bdb | 2729 | case ADMW1001_LUT_GEOMETRY_COEFFS: |
ADIJake | 0:85855ecd3257 | 2730 | switch (pDesc->equation) |
ADIJake | 0:85855ecd3257 | 2731 | { |
Vkadaba | 5:0728bde67bdb | 2732 | case ADMW1001_LUT_EQUATION_POLYN: |
Vkadaba | 5:0728bde67bdb | 2733 | case ADMW1001_LUT_EQUATION_POLYNEXP: |
Vkadaba | 5:0728bde67bdb | 2734 | case ADMW1001_LUT_EQUATION_QUADRATIC: |
Vkadaba | 5:0728bde67bdb | 2735 | case ADMW1001_LUT_EQUATION_STEINHART: |
Vkadaba | 5:0728bde67bdb | 2736 | case ADMW1001_LUT_EQUATION_LOGARITHMIC: |
Vkadaba | 5:0728bde67bdb | 2737 | case ADMW1001_LUT_EQUATION_BIVARIATE_POLYN: |
ADIJake | 0:85855ecd3257 | 2738 | break; |
ADIJake | 0:85855ecd3257 | 2739 | default: |
Vkadaba | 5:0728bde67bdb | 2740 | ADMW_LOG_ERROR("Invalid equation %u specified for LUT table %u", |
ADIJake | 0:85855ecd3257 | 2741 | pDesc->equation, i); |
Vkadaba | 5:0728bde67bdb | 2742 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2743 | } |
ADIJake | 0:85855ecd3257 | 2744 | break; |
Vkadaba | 5:0728bde67bdb | 2745 | case ADMW1001_LUT_GEOMETRY_NES_1D: |
Vkadaba | 5:0728bde67bdb | 2746 | case ADMW1001_LUT_GEOMETRY_NES_2D: |
Vkadaba | 5:0728bde67bdb | 2747 | case ADMW1001_LUT_GEOMETRY_ES_1D: |
Vkadaba | 5:0728bde67bdb | 2748 | case ADMW1001_LUT_GEOMETRY_ES_2D: |
Vkadaba | 5:0728bde67bdb | 2749 | if (pDesc->equation != ADMW1001_LUT_EQUATION_LUT) { |
Vkadaba | 5:0728bde67bdb | 2750 | ADMW_LOG_ERROR("Invalid equation %u specified for LUT table %u", |
ADIJake | 0:85855ecd3257 | 2751 | pDesc->equation, i); |
Vkadaba | 5:0728bde67bdb | 2752 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2753 | } |
ADIJake | 0:85855ecd3257 | 2754 | break; |
ADIJake | 0:85855ecd3257 | 2755 | default: |
Vkadaba | 5:0728bde67bdb | 2756 | ADMW_LOG_ERROR("Invalid geometry %u specified for LUT table %u", |
ADIJake | 0:85855ecd3257 | 2757 | pDesc->geometry, i); |
Vkadaba | 5:0728bde67bdb | 2758 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2759 | } |
ADIJake | 0:85855ecd3257 | 2760 | |
ADIJake | 0:85855ecd3257 | 2761 | switch (pDesc->dataType) |
ADIJake | 0:85855ecd3257 | 2762 | { |
Vkadaba | 5:0728bde67bdb | 2763 | case ADMW1001_LUT_DATA_TYPE_FLOAT32: |
Vkadaba | 5:0728bde67bdb | 2764 | case ADMW1001_LUT_DATA_TYPE_FLOAT64: |
ADIJake | 0:85855ecd3257 | 2765 | break; |
ADIJake | 0:85855ecd3257 | 2766 | default: |
Vkadaba | 5:0728bde67bdb | 2767 | ADMW_LOG_ERROR("Invalid vector format %u specified for LUT table %u", |
ADIJake | 0:85855ecd3257 | 2768 | pDesc->dataType, i); |
Vkadaba | 5:0728bde67bdb | 2769 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2770 | } |
ADIJake | 0:85855ecd3257 | 2771 | |
Vkadaba | 5:0728bde67bdb | 2772 | calculatedCrc = admw_crc16_ccitt(pData, pDesc->length); |
ADIJake | 0:85855ecd3257 | 2773 | if (calculatedCrc != pDesc->crc16) |
ADIJake | 0:85855ecd3257 | 2774 | { |
Vkadaba | 5:0728bde67bdb | 2775 | ADMW_LOG_ERROR("CRC validation failed on LUT table %u (expected 0x%04X, actual 0x%04X)", |
ADIJake | 0:85855ecd3257 | 2776 | i, pDesc->crc16, calculatedCrc); |
Vkadaba | 5:0728bde67bdb | 2777 | return ADMW_CRC_ERROR; |
ADIJake | 0:85855ecd3257 | 2778 | } |
ADIJake | 0:85855ecd3257 | 2779 | |
ADIJake | 0:85855ecd3257 | 2780 | actualLength += sizeof(*pDesc) + pDesc->length; |
ADIJake | 0:85855ecd3257 | 2781 | |
ADIJake | 0:85855ecd3257 | 2782 | /* Move to the next look-up table */ |
Vkadaba | 5:0728bde67bdb | 2783 | pLutTable = (ADMW1001_LUT_TABLE *)((uint8_t *)pLutTable + sizeof(*pDesc) + pDesc->length); |
ADIJake | 0:85855ecd3257 | 2784 | } |
ADIJake | 0:85855ecd3257 | 2785 | |
ADIJake | 0:85855ecd3257 | 2786 | if (actualLength != pLutHeader->totalLength) |
ADIJake | 0:85855ecd3257 | 2787 | { |
Vkadaba | 5:0728bde67bdb | 2788 | ADMW_LOG_ERROR("LUT table length mismatch (expected %u, actual %u)", |
ADIJake | 0:85855ecd3257 | 2789 | pLutHeader->totalLength, actualLength); |
Vkadaba | 5:0728bde67bdb | 2790 | return ADMW_WRONG_SIZE; |
ADIJake | 0:85855ecd3257 | 2791 | } |
ADIJake | 0:85855ecd3257 | 2792 | |
Vkadaba | 5:0728bde67bdb | 2793 | if (sizeof(*pLutHeader) + pLutHeader->totalLength > ADMW_LUT_MAX_SIZE) |
ADIJake | 0:85855ecd3257 | 2794 | { |
Vkadaba | 5:0728bde67bdb | 2795 | ADMW_LOG_ERROR("Maximum LUT table length (%u bytes) exceeded", |
Vkadaba | 5:0728bde67bdb | 2796 | ADMW_LUT_MAX_SIZE); |
Vkadaba | 5:0728bde67bdb | 2797 | return ADMW_WRONG_SIZE; |
ADIJake | 0:85855ecd3257 | 2798 | } |
ADIJake | 0:85855ecd3257 | 2799 | |
ADIJake | 0:85855ecd3257 | 2800 | /* Write the LUT data to the device */ |
ADIJake | 0:85855ecd3257 | 2801 | unsigned lutSize = sizeof(*pLutHeader) + pLutHeader->totalLength; |
ADIJake | 0:85855ecd3257 | 2802 | WRITE_REG_U16(hDevice, 0, CORE_LUT_OFFSET); |
ADIJake | 0:85855ecd3257 | 2803 | WRITE_REG_U8_ARRAY(hDevice, (uint8_t *)pLutData, lutSize, CORE_LUT_DATA); |
ADIJake | 0:85855ecd3257 | 2804 | |
Vkadaba | 5:0728bde67bdb | 2805 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2806 | } |
ADIJake | 0:85855ecd3257 | 2807 | |
Vkadaba | 5:0728bde67bdb | 2808 | ADMW_RESULT admw1001_SetLutDataRaw( |
Vkadaba | 5:0728bde67bdb | 2809 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 2810 | ADMW1001_LUT_RAW * const pLutData) |
ADIJake | 0:85855ecd3257 | 2811 | { |
Vkadaba | 5:0728bde67bdb | 2812 | return admw1001_SetLutData(hDevice, |
Vkadaba | 5:0728bde67bdb | 2813 | (ADMW1001_LUT *)pLutData); |
ADIJake | 0:85855ecd3257 | 2814 | } |
ADIJake | 0:85855ecd3257 | 2815 | |
Vkadaba | 5:0728bde67bdb | 2816 | static ADMW_RESULT getLutTableSize( |
Vkadaba | 5:0728bde67bdb | 2817 | ADMW1001_LUT_DESCRIPTOR * const pDesc, |
Vkadaba | 5:0728bde67bdb | 2818 | ADMW1001_LUT_TABLE_DATA * const pData, |
ADIJake | 0:85855ecd3257 | 2819 | unsigned *pLength) |
ADIJake | 0:85855ecd3257 | 2820 | { |
ADIJake | 0:85855ecd3257 | 2821 | switch (pDesc->geometry) |
ADIJake | 0:85855ecd3257 | 2822 | { |
Vkadaba | 5:0728bde67bdb | 2823 | case ADMW1001_LUT_GEOMETRY_COEFFS: |
Vkadaba | 5:0728bde67bdb | 2824 | if (pDesc->equation == ADMW1001_LUT_EQUATION_BIVARIATE_POLYN) |
Vkadaba | 5:0728bde67bdb | 2825 | *pLength = ADMW1001_LUT_2D_POLYN_COEFF_LIST_SIZE(pData->coeffList2d); |
ADIJake | 0:85855ecd3257 | 2826 | else |
Vkadaba | 5:0728bde67bdb | 2827 | *pLength = ADMW1001_LUT_COEFF_LIST_SIZE(pData->coeffList); |
ADIJake | 0:85855ecd3257 | 2828 | break; |
Vkadaba | 5:0728bde67bdb | 2829 | case ADMW1001_LUT_GEOMETRY_NES_1D: |
Vkadaba | 5:0728bde67bdb | 2830 | *pLength = ADMW1001_LUT_1D_NES_SIZE(pData->lut1dNes); |
ADIJake | 0:85855ecd3257 | 2831 | break; |
Vkadaba | 5:0728bde67bdb | 2832 | case ADMW1001_LUT_GEOMETRY_NES_2D: |
Vkadaba | 5:0728bde67bdb | 2833 | *pLength = ADMW1001_LUT_2D_NES_SIZE(pData->lut2dNes); |
ADIJake | 0:85855ecd3257 | 2834 | break; |
Vkadaba | 5:0728bde67bdb | 2835 | case ADMW1001_LUT_GEOMETRY_ES_1D: |
Vkadaba | 5:0728bde67bdb | 2836 | *pLength = ADMW1001_LUT_1D_ES_SIZE(pData->lut1dEs); |
ADIJake | 0:85855ecd3257 | 2837 | break; |
Vkadaba | 5:0728bde67bdb | 2838 | case ADMW1001_LUT_GEOMETRY_ES_2D: |
Vkadaba | 5:0728bde67bdb | 2839 | *pLength = ADMW1001_LUT_2D_ES_SIZE(pData->lut2dEs); |
ADIJake | 0:85855ecd3257 | 2840 | break; |
ADIJake | 0:85855ecd3257 | 2841 | default: |
Vkadaba | 5:0728bde67bdb | 2842 | ADMW_LOG_ERROR("Invalid LUT table geometry %d specified\r\n", |
ADIJake | 0:85855ecd3257 | 2843 | pDesc->geometry); |
Vkadaba | 5:0728bde67bdb | 2844 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2845 | } |
ADIJake | 0:85855ecd3257 | 2846 | |
Vkadaba | 5:0728bde67bdb | 2847 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2848 | } |
ADIJake | 0:85855ecd3257 | 2849 | |
Vkadaba | 5:0728bde67bdb | 2850 | ADMW_RESULT admw1001_AssembleLutData( |
Vkadaba | 5:0728bde67bdb | 2851 | ADMW1001_LUT * pLutBuffer, |
ADIJake | 0:85855ecd3257 | 2852 | unsigned nLutBufferSize, |
ADIJake | 0:85855ecd3257 | 2853 | unsigned const nNumTables, |
Vkadaba | 5:0728bde67bdb | 2854 | ADMW1001_LUT_DESCRIPTOR * const ppDesc[], |
Vkadaba | 5:0728bde67bdb | 2855 | ADMW1001_LUT_TABLE_DATA * const ppData[]) |
ADIJake | 0:85855ecd3257 | 2856 | { |
Vkadaba | 5:0728bde67bdb | 2857 | ADMW1001_LUT_HEADER *pHdr = &pLutBuffer->header; |
ADIJake | 0:85855ecd3257 | 2858 | uint8_t *pLutTableData = (uint8_t *)pLutBuffer + sizeof(*pHdr); |
ADIJake | 0:85855ecd3257 | 2859 | |
ADIJake | 0:85855ecd3257 | 2860 | if (sizeof(*pHdr) > nLutBufferSize) |
ADIJake | 0:85855ecd3257 | 2861 | { |
Vkadaba | 5:0728bde67bdb | 2862 | ADMW_LOG_ERROR("Insufficient LUT buffer size provided"); |
Vkadaba | 5:0728bde67bdb | 2863 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2864 | } |
ADIJake | 0:85855ecd3257 | 2865 | |
ADIJake | 0:85855ecd3257 | 2866 | /* First initialise the top-level header */ |
Vkadaba | 5:0728bde67bdb | 2867 | pHdr->signature = ADMW_LUT_SIGNATURE; |
ADIJake | 0:85855ecd3257 | 2868 | pHdr->version.major = 1; |
ADIJake | 0:85855ecd3257 | 2869 | pHdr->version.minor = 0; |
ADIJake | 0:85855ecd3257 | 2870 | pHdr->numTables = 0; |
ADIJake | 0:85855ecd3257 | 2871 | pHdr->totalLength = 0; |
ADIJake | 0:85855ecd3257 | 2872 | |
ADIJake | 0:85855ecd3257 | 2873 | /* |
ADIJake | 0:85855ecd3257 | 2874 | * Walk through the list of table pointers provided, appending the table |
ADIJake | 0:85855ecd3257 | 2875 | * descriptor+data from each one to the provided LUT buffer |
ADIJake | 0:85855ecd3257 | 2876 | */ |
ADIJake | 0:85855ecd3257 | 2877 | for (unsigned i = 0; i < nNumTables; i++) |
ADIJake | 0:85855ecd3257 | 2878 | { |
Vkadaba | 5:0728bde67bdb | 2879 | ADMW1001_LUT_DESCRIPTOR * const pDesc = ppDesc[i]; |
Vkadaba | 5:0728bde67bdb | 2880 | ADMW1001_LUT_TABLE_DATA * const pData = ppData[i]; |
Vkadaba | 5:0728bde67bdb | 2881 | ADMW_RESULT res; |
ADIJake | 0:85855ecd3257 | 2882 | unsigned dataLength = 0; |
ADIJake | 0:85855ecd3257 | 2883 | |
ADIJake | 0:85855ecd3257 | 2884 | /* Calculate the length of the table data */ |
ADIJake | 0:85855ecd3257 | 2885 | res = getLutTableSize(pDesc, pData, &dataLength); |
Vkadaba | 5:0728bde67bdb | 2886 | if (res != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2887 | return res; |
ADIJake | 0:85855ecd3257 | 2888 | |
ADIJake | 0:85855ecd3257 | 2889 | /* Fill in the table descriptor length and CRC fields */ |
ADIJake | 0:85855ecd3257 | 2890 | pDesc->length = dataLength; |
Vkadaba | 5:0728bde67bdb | 2891 | pDesc->crc16 = admw_crc16_ccitt(pData, dataLength); |
ADIJake | 0:85855ecd3257 | 2892 | |
ADIJake | 0:85855ecd3257 | 2893 | if ((sizeof(*pHdr) + pHdr->totalLength + sizeof(*pDesc) + dataLength) > nLutBufferSize) |
ADIJake | 0:85855ecd3257 | 2894 | { |
Vkadaba | 5:0728bde67bdb | 2895 | ADMW_LOG_ERROR("Insufficient LUT buffer size provided"); |
Vkadaba | 5:0728bde67bdb | 2896 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2897 | } |
ADIJake | 0:85855ecd3257 | 2898 | |
ADIJake | 0:85855ecd3257 | 2899 | /* Append the table to the LUT buffer (desc + data) */ |
ADIJake | 0:85855ecd3257 | 2900 | memcpy(pLutTableData + pHdr->totalLength, pDesc, sizeof(*pDesc)); |
ADIJake | 0:85855ecd3257 | 2901 | pHdr->totalLength += sizeof(*pDesc); |
ADIJake | 0:85855ecd3257 | 2902 | memcpy(pLutTableData + pHdr->totalLength, pData, dataLength); |
ADIJake | 0:85855ecd3257 | 2903 | pHdr->totalLength += dataLength; |
ADIJake | 0:85855ecd3257 | 2904 | |
ADIJake | 0:85855ecd3257 | 2905 | pHdr->numTables++; |
ADIJake | 0:85855ecd3257 | 2906 | } |
ADIJake | 0:85855ecd3257 | 2907 | |
Vkadaba | 5:0728bde67bdb | 2908 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2909 | } |