Removed unwanted enums and unused functions

Committer:
Vkadaba
Date:
Thu Apr 09 12:39:43 2020 +0000
Revision:
64:d89d9728ba95
Parent:
63:6d048b2f3f32
code clean up part-2

Who changed what in which revision?

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