ADISense1000 Version 2.1 code base

Fork of AdiSense1000_V21 by Sean Wilson

Committer:
Dan O'Donovan
Date:
Tue Jun 12 21:27:34 2018 +0100
Branch:
v2.0
Revision:
30:119ff4f3aef6
Parent:
29:57edca10d78c
Child:
31:de49744b57a6
Adding host library and example code for v2.0 release to v2.0 branch

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Dan O'Donovan 27:567abf893938 1 /*
Dan O'Donovan 27:567abf893938 2 CONFIDENTIAL AND PROPRIETARY INFORMATION
Dan O'Donovan 27:567abf893938 3
Dan O'Donovan 27:567abf893938 4 Copyright (c) 2018 Emutex Ltd. All rights reserved.
Dan O'Donovan 27:567abf893938 5 This software and documentation contain confidential and
Dan O'Donovan 27:567abf893938 6 proprietary information that is the property of
Dan O'Donovan 27:567abf893938 7 Emutex Ltd. The software and documentation are
Dan O'Donovan 27:567abf893938 8 furnished under a license agreement and may be used
Dan O'Donovan 27:567abf893938 9 or copied only in accordance with the terms of the license
Dan O'Donovan 27:567abf893938 10 agreement. No part of the software and documentation
Dan O'Donovan 27:567abf893938 11 may be reproduced, transmitted, or translated, in any
Dan O'Donovan 27:567abf893938 12 form or by any means, electronic, mechanical, manual,
Dan O'Donovan 27:567abf893938 13 optical, or otherwise, without prior written permission
Dan O'Donovan 27:567abf893938 14 of Emutex Ltd., or as expressly provided by the license agreement.
Dan O'Donovan 27:567abf893938 15 Reverse engineering is prohibited, and reproduction,
Dan O'Donovan 27:567abf893938 16 disclosure or use without specific written authorization
Dan O'Donovan 27:567abf893938 17 of Emutex Ltd. is strictly forbidden.
Dan O'Donovan 27:567abf893938 18 */
Dan O'Donovan 27:567abf893938 19
Dan O'Donovan 27:567abf893938 20 /******************************************************************************
Dan O'Donovan 27:567abf893938 21 Copyright 2017 (c) Analog Devices, Inc.
Dan O'Donovan 27:567abf893938 22
Dan O'Donovan 27:567abf893938 23 All rights reserved.
Dan O'Donovan 27:567abf893938 24
Dan O'Donovan 27:567abf893938 25 Redistribution and use in source and binary forms, with or without
Dan O'Donovan 27:567abf893938 26 modification, are permitted provided that the following conditions are met:
Dan O'Donovan 27:567abf893938 27 - Redistributions of source code must retain the above copyright
Dan O'Donovan 27:567abf893938 28 notice, this list of conditions and the following disclaimer.
Dan O'Donovan 27:567abf893938 29 - Redistributions in binary form must reproduce the above copyright
Dan O'Donovan 27:567abf893938 30 notice, this list of conditions and the following disclaimer in
Dan O'Donovan 27:567abf893938 31 the documentation and/or other materials provided with the
Dan O'Donovan 27:567abf893938 32 distribution.
Dan O'Donovan 27:567abf893938 33 - Neither the name of Analog Devices, Inc. nor the names of its
Dan O'Donovan 27:567abf893938 34 contributors may be used to endorse or promote products derived
Dan O'Donovan 27:567abf893938 35 from this software without specific prior written permission.
Dan O'Donovan 27:567abf893938 36 - The use of this software may or may not infringe the patent rights
Dan O'Donovan 27:567abf893938 37 of one or more patent holders. This license does not release you
Dan O'Donovan 27:567abf893938 38 from the requirement that you obtain separate licenses from these
Dan O'Donovan 27:567abf893938 39 patent holders to use this software.
Dan O'Donovan 27:567abf893938 40 - Use of the software either in source or binary form, must be run
Dan O'Donovan 27:567abf893938 41 on or directly connected to an Analog Devices Inc. component.
Dan O'Donovan 27:567abf893938 42
Dan O'Donovan 27:567abf893938 43 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
Dan O'Donovan 27:567abf893938 44 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
Dan O'Donovan 27:567abf893938 45 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Dan O'Donovan 27:567abf893938 46 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
Dan O'Donovan 27:567abf893938 47 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Dan O'Donovan 27:567abf893938 48 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
Dan O'Donovan 27:567abf893938 49 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Dan O'Donovan 27:567abf893938 50 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Dan O'Donovan 27:567abf893938 51 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Dan O'Donovan 27:567abf893938 52 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Dan O'Donovan 27:567abf893938 53 *
Dan O'Donovan 27:567abf893938 54 *****************************************************************************/
Dan O'Donovan 27:567abf893938 55
Dan O'Donovan 27:567abf893938 56 /*!
Dan O'Donovan 27:567abf893938 57 ******************************************************************************
Dan O'Donovan 27:567abf893938 58 * @file:
Dan O'Donovan 27:567abf893938 59 * @brief: ADISENSE API implementation for ADSNS1000
Dan O'Donovan 27:567abf893938 60 *-----------------------------------------------------------------------------
Dan O'Donovan 27:567abf893938 61 */
Dan O'Donovan 27:567abf893938 62
Dan O'Donovan 27:567abf893938 63 #include <float.h>
Dan O'Donovan 27:567abf893938 64 #include <math.h>
Dan O'Donovan 27:567abf893938 65 #include <string.h>
Dan O'Donovan 27:567abf893938 66
Dan O'Donovan 27:567abf893938 67 #include "inc/adi_sense_platform.h"
Dan O'Donovan 27:567abf893938 68 #include "inc/adi_sense_api.h"
Dan O'Donovan 27:567abf893938 69 #include "inc/adi_sense_1000/adi_sense_1000_api.h"
Dan O'Donovan 27:567abf893938 70
Dan O'Donovan 27:567abf893938 71 #include "adi_sense_1000/ADISENSE1000_REGISTERS_typedefs.h"
Dan O'Donovan 27:567abf893938 72 #include "adi_sense_1000/ADISENSE1000_REGISTERS.h"
Dan O'Donovan 27:567abf893938 73 #include "adi_sense_1000/adi_sense_1000_lut_data.h"
Dan O'Donovan 27:567abf893938 74 #include "adi_sense_1000/adi_sense_1000_host_comms.h"
Dan O'Donovan 27:567abf893938 75
Dan O'Donovan 27:567abf893938 76 #include "crc16.h"
Dan O'Donovan 27:567abf893938 77
Dan O'Donovan 27:567abf893938 78 /*
Dan O'Donovan 27:567abf893938 79 * The following macros are used to encapsulate the register access code
Dan O'Donovan 27:567abf893938 80 * to improve readability in the functions further below in this file
Dan O'Donovan 27:567abf893938 81 */
Dan O'Donovan 27:567abf893938 82 #define STRINGIFY(name) #name
Dan O'Donovan 27:567abf893938 83
Dan O'Donovan 27:567abf893938 84 /* Expand the full name of the reset value macro for the specified register */
Dan O'Donovan 27:567abf893938 85 #define REG_RESET_VAL(_name) REG_ADISENSE_##_name##_RESET
Dan O'Donovan 27:567abf893938 86
Dan O'Donovan 27:567abf893938 87 /* Checks if a value is outside the bounds of the specified register field */
Dan O'Donovan 27:567abf893938 88 #define CHECK_REG_FIELD_VAL(_field, _val) \
Dan O'Donovan 27:567abf893938 89 do { \
Dan O'Donovan 27:567abf893938 90 uint32_t _mask = BITM_ADISENSE_##_field; \
Dan O'Donovan 27:567abf893938 91 uint32_t _shift = BITP_ADISENSE_##_field; \
Dan O'Donovan 27:567abf893938 92 if ((((_val) << _shift) & ~(_mask)) != 0) { \
Dan O'Donovan 27:567abf893938 93 ADI_SENSE_LOG_ERROR("Value 0x%08X invalid for register field %s", \
Dan O'Donovan 27:567abf893938 94 (uint32_t)(_val), \
Dan O'Donovan 27:567abf893938 95 STRINGIFY(ADISENSE_##_field)); \
Dan O'Donovan 27:567abf893938 96 return ADI_SENSE_INVALID_PARAM; \
Dan O'Donovan 27:567abf893938 97 } \
Dan O'Donovan 27:567abf893938 98 } while(false)
Dan O'Donovan 27:567abf893938 99
Dan O'Donovan 27:567abf893938 100 /*
Dan O'Donovan 27:567abf893938 101 * Encapsulates the write to a specified register
Dan O'Donovan 27:567abf893938 102 * NOTE - this will cause the calling function to return on error
Dan O'Donovan 27:567abf893938 103 */
Dan O'Donovan 27:567abf893938 104 #define WRITE_REG(_hdev, _val, _name, _type) \
Dan O'Donovan 27:567abf893938 105 do { \
Dan O'Donovan 27:567abf893938 106 ADI_SENSE_RESULT _res; \
Dan O'Donovan 27:567abf893938 107 _type _regval = _val; \
Dan O'Donovan 27:567abf893938 108 _res = adi_sense_1000_WriteRegister((_hdev), \
Dan O'Donovan 27:567abf893938 109 REG_ADISENSE_##_name, \
Dan O'Donovan 27:567abf893938 110 &_regval, sizeof(_regval)); \
Dan O'Donovan 27:567abf893938 111 if (_res != ADI_SENSE_SUCCESS) \
Dan O'Donovan 27:567abf893938 112 return _res; \
Dan O'Donovan 27:567abf893938 113 } while(false)
Dan O'Donovan 27:567abf893938 114
Dan O'Donovan 27:567abf893938 115 /* Wrapper macro to write a value to a uint32_t register */
Dan O'Donovan 27:567abf893938 116 #define WRITE_REG_U32(_hdev, _val, _name) \
Dan O'Donovan 27:567abf893938 117 WRITE_REG(_hdev, _val, _name, uint32_t)
Dan O'Donovan 27:567abf893938 118 /* Wrapper macro to write a value to a uint16_t register */
Dan O'Donovan 27:567abf893938 119 #define WRITE_REG_U16(_hdev, _val, _name) \
Dan O'Donovan 27:567abf893938 120 WRITE_REG(_hdev, _val, _name, uint16_t)
Dan O'Donovan 27:567abf893938 121 /* Wrapper macro to write a value to a uint8_t register */
Dan O'Donovan 27:567abf893938 122 #define WRITE_REG_U8(_hdev, _val, _name) \
Dan O'Donovan 27:567abf893938 123 WRITE_REG(_hdev, _val, _name, uint8_t)
Dan O'Donovan 27:567abf893938 124 /* Wrapper macro to write a value to a float32_t register */
Dan O'Donovan 27:567abf893938 125 #define WRITE_REG_FLOAT(_hdev, _val, _name) \
Dan O'Donovan 27:567abf893938 126 WRITE_REG(_hdev, _val, _name, float32_t)
Dan O'Donovan 27:567abf893938 127
Dan O'Donovan 27:567abf893938 128 /*
Dan O'Donovan 27:567abf893938 129 * Encapsulates the read from a specified register
Dan O'Donovan 27:567abf893938 130 * NOTE - this will cause the calling function to return on error
Dan O'Donovan 27:567abf893938 131 */
Dan O'Donovan 27:567abf893938 132 #define READ_REG(_hdev, _val, _name, _type) \
Dan O'Donovan 27:567abf893938 133 do { \
Dan O'Donovan 27:567abf893938 134 ADI_SENSE_RESULT _res; \
Dan O'Donovan 27:567abf893938 135 _type _regval; \
Dan O'Donovan 27:567abf893938 136 _res = adi_sense_1000_ReadRegister((_hdev), \
Dan O'Donovan 27:567abf893938 137 REG_ADISENSE_##_name, \
Dan O'Donovan 27:567abf893938 138 &_regval, sizeof(_regval)); \
Dan O'Donovan 27:567abf893938 139 if (_res != ADI_SENSE_SUCCESS) \
Dan O'Donovan 27:567abf893938 140 return _res; \
Dan O'Donovan 27:567abf893938 141 _val = _regval; \
Dan O'Donovan 27:567abf893938 142 } while(false)
Dan O'Donovan 27:567abf893938 143
Dan O'Donovan 27:567abf893938 144 /* Wrapper macro to read a value from a uint32_t register */
Dan O'Donovan 27:567abf893938 145 #define READ_REG_U32(_hdev, _val, _name) \
Dan O'Donovan 27:567abf893938 146 READ_REG(_hdev, _val, _name, uint32_t)
Dan O'Donovan 27:567abf893938 147 /* Wrapper macro to read a value from a uint16_t register */
Dan O'Donovan 27:567abf893938 148 #define READ_REG_U16(_hdev, _val, _name) \
Dan O'Donovan 27:567abf893938 149 READ_REG(_hdev, _val, _name, uint16_t)
Dan O'Donovan 27:567abf893938 150 /* Wrapper macro to read a value from a uint8_t register */
Dan O'Donovan 27:567abf893938 151 #define READ_REG_U8(_hdev, _val, _name) \
Dan O'Donovan 27:567abf893938 152 READ_REG(_hdev, _val, _name, uint8_t)
Dan O'Donovan 27:567abf893938 153 /* Wrapper macro to read a value from a float32_t register */
Dan O'Donovan 27:567abf893938 154 #define READ_REG_FLOAT(_hdev, _val, _name) \
Dan O'Donovan 27:567abf893938 155 READ_REG(_hdev, _val, _name, float32_t)
Dan O'Donovan 27:567abf893938 156
Dan O'Donovan 27:567abf893938 157 /*
Dan O'Donovan 27:567abf893938 158 * Wrapper macro to write an array of values to a uint8_t register
Dan O'Donovan 27:567abf893938 159 * NOTE - this is intended only for writing to a keyhole data register
Dan O'Donovan 27:567abf893938 160 */
Dan O'Donovan 27:567abf893938 161 #define WRITE_REG_U8_ARRAY(_hdev, _arr, _len, _name) \
Dan O'Donovan 27:567abf893938 162 do { \
Dan O'Donovan 27:567abf893938 163 ADI_SENSE_RESULT _res; \
Dan O'Donovan 27:567abf893938 164 _res = adi_sense_1000_WriteRegister(_hdev, \
Dan O'Donovan 27:567abf893938 165 REG_ADISENSE_##_name, \
Dan O'Donovan 27:567abf893938 166 _arr, _len); \
Dan O'Donovan 27:567abf893938 167 if (_res != ADI_SENSE_SUCCESS) \
Dan O'Donovan 27:567abf893938 168 return _res; \
Dan O'Donovan 27:567abf893938 169 } while(false)
Dan O'Donovan 27:567abf893938 170
Dan O'Donovan 27:567abf893938 171 /*
Dan O'Donovan 27:567abf893938 172 * Wrapper macro to read an array of values from a uint8_t register
Dan O'Donovan 27:567abf893938 173 * NOTE - this is intended only for reading from a keyhole data register
Dan O'Donovan 27:567abf893938 174 */
Dan O'Donovan 27:567abf893938 175 #define READ_REG_U8_ARRAY(_hdev, _arr, _len, _name) \
Dan O'Donovan 27:567abf893938 176 do { \
Dan O'Donovan 27:567abf893938 177 ADI_SENSE_RESULT _res; \
Dan O'Donovan 27:567abf893938 178 _res = adi_sense_1000_ReadRegister((_hdev), \
Dan O'Donovan 27:567abf893938 179 REG_ADISENSE_##_name, \
Dan O'Donovan 27:567abf893938 180 _arr, _len); \
Dan O'Donovan 27:567abf893938 181 if (_res != ADI_SENSE_SUCCESS) \
Dan O'Donovan 27:567abf893938 182 return _res; \
Dan O'Donovan 27:567abf893938 183 } while(false)
Dan O'Donovan 27:567abf893938 184
Dan O'Donovan 27:567abf893938 185 #define ADI_SENSE_1000_CHANNEL_IS_ADC(c) \
Dan O'Donovan 27:567abf893938 186 ((c) >= ADI_SENSE_1000_CHANNEL_ID_CJC_0 && (c) <= ADI_SENSE_1000_CHANNEL_ID_CURRENT_0)
Dan O'Donovan 27:567abf893938 187
Dan O'Donovan 27:567abf893938 188 #define ADI_SENSE_1000_CHANNEL_IS_ADC_CJC(c) \
Dan O'Donovan 27:567abf893938 189 ((c) >= ADI_SENSE_1000_CHANNEL_ID_CJC_0 && (c) <= ADI_SENSE_1000_CHANNEL_ID_CJC_1)
Dan O'Donovan 27:567abf893938 190
Dan O'Donovan 27:567abf893938 191 #define ADI_SENSE_1000_CHANNEL_IS_ADC_SENSOR(c) \
Dan O'Donovan 27:567abf893938 192 ((c) >= ADI_SENSE_1000_CHANNEL_ID_SENSOR_0 && (c) <= ADI_SENSE_1000_CHANNEL_ID_SENSOR_3)
Dan O'Donovan 27:567abf893938 193
Dan O'Donovan 27:567abf893938 194 #define ADI_SENSE_1000_CHANNEL_IS_ADC_VOLTAGE(c) \
Dan O'Donovan 27:567abf893938 195 ((c) == ADI_SENSE_1000_CHANNEL_ID_VOLTAGE_0)
Dan O'Donovan 27:567abf893938 196
Dan O'Donovan 27:567abf893938 197 #define ADI_SENSE_1000_CHANNEL_IS_ADC_CURRENT(c) \
Dan O'Donovan 27:567abf893938 198 ((c) == ADI_SENSE_1000_CHANNEL_ID_CURRENT_0)
Dan O'Donovan 27:567abf893938 199
Dan O'Donovan 27:567abf893938 200 #define ADI_SENSE_1000_CHANNEL_IS_VIRTUAL(c) \
Dan O'Donovan 27:567abf893938 201 ((c) == ADI_SENSE_1000_CHANNEL_ID_SPI_1 || (c) == ADI_SENSE_1000_CHANNEL_ID_SPI_2)
Dan O'Donovan 27:567abf893938 202
Dan O'Donovan 27:567abf893938 203 typedef struct
Dan O'Donovan 27:567abf893938 204 {
Dan O'Donovan 27:567abf893938 205 unsigned nDeviceIndex;
Dan O'Donovan 27:567abf893938 206 ADI_SENSE_SPI_HANDLE hSpi;
Dan O'Donovan 27:567abf893938 207 ADI_SENSE_GPIO_HANDLE hGpio;
Dan O'Donovan 27:567abf893938 208 } ADI_SENSE_DEVICE_CONTEXT;
Dan O'Donovan 27:567abf893938 209
Dan O'Donovan 27:567abf893938 210 static ADI_SENSE_DEVICE_CONTEXT gDeviceCtx[ADI_SENSE_PLATFORM_MAX_DEVICES];
Dan O'Donovan 27:567abf893938 211
Dan O'Donovan 27:567abf893938 212 /*
Dan O'Donovan 27:567abf893938 213 * Open an ADISENSE device instance.
Dan O'Donovan 27:567abf893938 214 */
Dan O'Donovan 27:567abf893938 215 ADI_SENSE_RESULT adi_sense_Open(
Dan O'Donovan 27:567abf893938 216 unsigned const nDeviceIndex,
Dan O'Donovan 27:567abf893938 217 ADI_SENSE_CONNECTION * const pConnectionInfo,
Dan O'Donovan 27:567abf893938 218 ADI_SENSE_DEVICE_HANDLE * const phDevice)
Dan O'Donovan 27:567abf893938 219 {
Dan O'Donovan 27:567abf893938 220 ADI_SENSE_DEVICE_CONTEXT *pCtx;
Dan O'Donovan 27:567abf893938 221 ADI_SENSE_RESULT eRet;
Dan O'Donovan 27:567abf893938 222
Dan O'Donovan 27:567abf893938 223 if (nDeviceIndex >= ADI_SENSE_PLATFORM_MAX_DEVICES)
Dan O'Donovan 27:567abf893938 224 return ADI_SENSE_INVALID_DEVICE_NUM;
Dan O'Donovan 27:567abf893938 225
Dan O'Donovan 27:567abf893938 226 pCtx = &gDeviceCtx[nDeviceIndex];
Dan O'Donovan 27:567abf893938 227 pCtx->nDeviceIndex = nDeviceIndex;
Dan O'Donovan 27:567abf893938 228
kevin1990 29:57edca10d78c 229 eRet = adi_sense_LogOpen(&pConnectionInfo->log);
Dan O'Donovan 27:567abf893938 230 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 231 return eRet;
Dan O'Donovan 27:567abf893938 232
Dan O'Donovan 27:567abf893938 233 eRet = adi_sense_GpioOpen(&pConnectionInfo->gpio, &pCtx->hGpio);
Dan O'Donovan 27:567abf893938 234 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 235 return eRet;
Dan O'Donovan 27:567abf893938 236
Dan O'Donovan 27:567abf893938 237 eRet = adi_sense_SpiOpen(&pConnectionInfo->spi, &pCtx->hSpi);
Dan O'Donovan 27:567abf893938 238 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 239 return eRet;
Dan O'Donovan 27:567abf893938 240
Dan O'Donovan 27:567abf893938 241 *phDevice = pCtx;
Dan O'Donovan 27:567abf893938 242 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 243 }
Dan O'Donovan 27:567abf893938 244
Dan O'Donovan 27:567abf893938 245 /*
Dan O'Donovan 27:567abf893938 246 * Get the current state of the specified GPIO input signal.
Dan O'Donovan 27:567abf893938 247 */
Dan O'Donovan 27:567abf893938 248 ADI_SENSE_RESULT adi_sense_GetGpioState(
Dan O'Donovan 27:567abf893938 249 ADI_SENSE_DEVICE_HANDLE const hDevice,
Dan O'Donovan 27:567abf893938 250 ADI_SENSE_GPIO_PIN const ePinId,
Dan O'Donovan 30:119ff4f3aef6 251 bool * const pbAsserted)
Dan O'Donovan 27:567abf893938 252 {
Dan O'Donovan 27:567abf893938 253 ADI_SENSE_DEVICE_CONTEXT *pCtx = hDevice;
Dan O'Donovan 27:567abf893938 254
Dan O'Donovan 27:567abf893938 255 return adi_sense_GpioGet(pCtx->hGpio, ePinId, pbAsserted);
Dan O'Donovan 27:567abf893938 256 }
Dan O'Donovan 27:567abf893938 257
Dan O'Donovan 27:567abf893938 258 /*
Dan O'Donovan 27:567abf893938 259 * Register an application-defined callback function for GPIO interrupts.
Dan O'Donovan 27:567abf893938 260 */
Dan O'Donovan 27:567abf893938 261 ADI_SENSE_RESULT adi_sense_RegisterGpioCallback(
Dan O'Donovan 27:567abf893938 262 ADI_SENSE_DEVICE_HANDLE const hDevice,
Dan O'Donovan 27:567abf893938 263 ADI_SENSE_GPIO_PIN const ePinId,
Dan O'Donovan 27:567abf893938 264 ADI_SENSE_GPIO_CALLBACK const callbackFunction,
Dan O'Donovan 27:567abf893938 265 void * const pCallbackParam)
Dan O'Donovan 27:567abf893938 266 {
Dan O'Donovan 27:567abf893938 267 ADI_SENSE_DEVICE_CONTEXT *pCtx = hDevice;
Dan O'Donovan 27:567abf893938 268
Dan O'Donovan 27:567abf893938 269 if (callbackFunction)
Dan O'Donovan 27:567abf893938 270 {
Dan O'Donovan 27:567abf893938 271 return adi_sense_GpioIrqEnable(pCtx->hGpio, ePinId, callbackFunction,
Dan O'Donovan 27:567abf893938 272 pCallbackParam);
Dan O'Donovan 27:567abf893938 273 }
Dan O'Donovan 27:567abf893938 274 else
Dan O'Donovan 27:567abf893938 275 {
Dan O'Donovan 27:567abf893938 276 return adi_sense_GpioIrqDisable(pCtx->hGpio, ePinId);
Dan O'Donovan 27:567abf893938 277 }
Dan O'Donovan 27:567abf893938 278 }
Dan O'Donovan 27:567abf893938 279
Dan O'Donovan 27:567abf893938 280 /*
Dan O'Donovan 27:567abf893938 281 * Reset the specified ADISENSE device.
Dan O'Donovan 27:567abf893938 282 */
Dan O'Donovan 27:567abf893938 283 ADI_SENSE_RESULT adi_sense_Reset(
Dan O'Donovan 27:567abf893938 284 ADI_SENSE_DEVICE_HANDLE const hDevice)
Dan O'Donovan 27:567abf893938 285 {
Dan O'Donovan 27:567abf893938 286 ADI_SENSE_DEVICE_CONTEXT *pCtx = hDevice;
Dan O'Donovan 27:567abf893938 287 ADI_SENSE_RESULT eRet;
Dan O'Donovan 27:567abf893938 288
Dan O'Donovan 27:567abf893938 289 /* Pulse the Reset GPIO pin low for a minimum of 4 microseconds */
Dan O'Donovan 27:567abf893938 290 eRet = adi_sense_GpioSet(pCtx->hGpio, ADI_SENSE_GPIO_PIN_RESET, false);
Dan O'Donovan 27:567abf893938 291 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 292 return eRet;
Dan O'Donovan 27:567abf893938 293
Dan O'Donovan 27:567abf893938 294 adi_sense_TimeDelayUsec(4);
Dan O'Donovan 27:567abf893938 295
Dan O'Donovan 27:567abf893938 296 eRet = adi_sense_GpioSet(pCtx->hGpio, ADI_SENSE_GPIO_PIN_RESET, true);
Dan O'Donovan 27:567abf893938 297 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 298 return eRet;
Dan O'Donovan 27:567abf893938 299
Dan O'Donovan 27:567abf893938 300 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 301 }
Dan O'Donovan 27:567abf893938 302
Dan O'Donovan 27:567abf893938 303
Dan O'Donovan 27:567abf893938 304 /*!
Dan O'Donovan 27:567abf893938 305 * @brief Get general status of ADISense module.
Dan O'Donovan 27:567abf893938 306 *
Dan O'Donovan 27:567abf893938 307 * @param[in]
Dan O'Donovan 27:567abf893938 308 * @param[out] pStatus : Pointer to CORE Status struct.
Dan O'Donovan 27:567abf893938 309 *
Dan O'Donovan 27:567abf893938 310 * @return Status
Dan O'Donovan 27:567abf893938 311 * - #ADI_SENSE_SUCCESS Call completed successfully.
Dan O'Donovan 27:567abf893938 312 * - #ADI_SENSE_FAILURE If status register read fails.
Dan O'Donovan 27:567abf893938 313 *
Dan O'Donovan 27:567abf893938 314 * @details Read the general status register for the ADISense
Dan O'Donovan 27:567abf893938 315 * module. Indicates Error, Alert conditions, data ready
Dan O'Donovan 27:567abf893938 316 * and command running.
Dan O'Donovan 27:567abf893938 317 *
Dan O'Donovan 27:567abf893938 318 */
Dan O'Donovan 27:567abf893938 319 ADI_SENSE_RESULT adi_sense_GetStatus(
Dan O'Donovan 27:567abf893938 320 ADI_SENSE_DEVICE_HANDLE const hDevice,
Dan O'Donovan 27:567abf893938 321 ADI_SENSE_STATUS * const pStatus)
Dan O'Donovan 27:567abf893938 322 {
Dan O'Donovan 27:567abf893938 323 ADI_ADISENSE_CORE_Status_t statusReg;
Dan O'Donovan 27:567abf893938 324 READ_REG_U8(hDevice, statusReg.VALUE8, CORE_STATUS);
Dan O'Donovan 27:567abf893938 325
kevin1990 29:57edca10d78c 326 ADI_ADISENSE_CORE_Alert_Status_2_t alert2Reg;
kevin1990 29:57edca10d78c 327 READ_REG_U16(hDevice, alert2Reg.VALUE16, CORE_ALERT_STATUS_2);
kevin1990 29:57edca10d78c 328
Dan O'Donovan 27:567abf893938 329 memset(pStatus, 0, sizeof(*pStatus));
Dan O'Donovan 27:567abf893938 330
Dan O'Donovan 27:567abf893938 331 if (!statusReg.Cmd_Running) /* Active-low, so invert it */
Dan O'Donovan 27:567abf893938 332 pStatus->deviceStatus |= ADI_SENSE_DEVICE_STATUS_BUSY;
Dan O'Donovan 27:567abf893938 333 if (statusReg.Drdy)
Dan O'Donovan 27:567abf893938 334 pStatus->deviceStatus |= ADI_SENSE_DEVICE_STATUS_DATAREADY;
Dan O'Donovan 27:567abf893938 335 if (statusReg.FIFO_Error)
Dan O'Donovan 27:567abf893938 336 pStatus->deviceStatus |= ADI_SENSE_DEVICE_STATUS_FIFO_ERROR;
kevin1990 29:57edca10d78c 337 if (alert2Reg.Ext_Flash_Error)
kevin1990 29:57edca10d78c 338 pStatus->deviceStatus |= ADI_SENSE_DEVICE_STATUS_EXT_FLASH_ERROR;
Dan O'Donovan 27:567abf893938 339 if (statusReg.Alert_Active)
Dan O'Donovan 27:567abf893938 340 {
Dan O'Donovan 27:567abf893938 341 pStatus->deviceStatus |= ADI_SENSE_DEVICE_STATUS_ALERT;
Dan O'Donovan 27:567abf893938 342
Dan O'Donovan 27:567abf893938 343 ADI_ADISENSE_CORE_Alert_Code_t alertCodeReg;
Dan O'Donovan 27:567abf893938 344 READ_REG_U16(hDevice, alertCodeReg.VALUE16, CORE_ALERT_CODE);
Dan O'Donovan 27:567abf893938 345 pStatus->alertCode = alertCodeReg.Alert_Code;
Dan O'Donovan 27:567abf893938 346
Dan O'Donovan 27:567abf893938 347 ADI_ADISENSE_CORE_Channel_Alert_Status_t channelAlertStatusReg;
Dan O'Donovan 27:567abf893938 348 READ_REG_U16(hDevice, channelAlertStatusReg.VALUE16,
Dan O'Donovan 27:567abf893938 349 CORE_CHANNEL_ALERT_STATUS);
Dan O'Donovan 27:567abf893938 350
Dan O'Donovan 27:567abf893938 351 for (unsigned i = 0; i < ADI_SENSE_1000_MAX_CHANNELS; i++)
Dan O'Donovan 27:567abf893938 352 {
Dan O'Donovan 27:567abf893938 353 if (channelAlertStatusReg.VALUE16 & (1 << i))
Dan O'Donovan 27:567abf893938 354 {
Dan O'Donovan 27:567abf893938 355 ADI_ADISENSE_CORE_Alert_Code_Ch_t channelAlertCodeReg;
Dan O'Donovan 27:567abf893938 356 READ_REG_U16(hDevice, channelAlertCodeReg.VALUE16, CORE_ALERT_CODE_CHn(i));
Dan O'Donovan 27:567abf893938 357 pStatus->channelAlertCodes[i] = channelAlertCodeReg.Alert_Code_Ch;
Dan O'Donovan 27:567abf893938 358
Dan O'Donovan 27:567abf893938 359 ADI_ADISENSE_CORE_Alert_Detail_Ch_t alertDetailReg;
Dan O'Donovan 27:567abf893938 360 READ_REG_U16(hDevice, alertDetailReg.VALUE16,
Dan O'Donovan 27:567abf893938 361 CORE_ALERT_DETAIL_CHn(i));
Dan O'Donovan 27:567abf893938 362
Dan O'Donovan 27:567abf893938 363 if (alertDetailReg.Time_Out)
Dan O'Donovan 27:567abf893938 364 pStatus->channelAlerts[i] |= ADI_SENSE_CHANNEL_ALERT_TIMEOUT;
Dan O'Donovan 27:567abf893938 365 if (alertDetailReg.Under_Range)
Dan O'Donovan 27:567abf893938 366 pStatus->channelAlerts[i] |= ADI_SENSE_CHANNEL_ALERT_UNDER_RANGE;
Dan O'Donovan 27:567abf893938 367 if (alertDetailReg.Over_Range)
Dan O'Donovan 27:567abf893938 368 pStatus->channelAlerts[i] |= ADI_SENSE_CHANNEL_ALERT_OVER_RANGE;
Dan O'Donovan 27:567abf893938 369 if (alertDetailReg.Low_Limit)
Dan O'Donovan 27:567abf893938 370 pStatus->channelAlerts[i] |= ADI_SENSE_CHANNEL_ALERT_LOW_LIMIT;
Dan O'Donovan 27:567abf893938 371 if (alertDetailReg.High_Limit)
Dan O'Donovan 27:567abf893938 372 pStatus->channelAlerts[i] |= ADI_SENSE_CHANNEL_ALERT_HIGH_LIMIT;
Dan O'Donovan 27:567abf893938 373 if (alertDetailReg.Sensor_Open)
Dan O'Donovan 27:567abf893938 374 pStatus->channelAlerts[i] |= ADI_SENSE_CHANNEL_ALERT_SENSOR_OPEN;
Dan O'Donovan 27:567abf893938 375 if (alertDetailReg.Ref_Detect)
Dan O'Donovan 27:567abf893938 376 pStatus->channelAlerts[i] |= ADI_SENSE_CHANNEL_ALERT_REF_DETECT;
Dan O'Donovan 27:567abf893938 377 if (alertDetailReg.Config_Err)
Dan O'Donovan 27:567abf893938 378 pStatus->channelAlerts[i] |= ADI_SENSE_CHANNEL_ALERT_CONFIG_ERR;
Dan O'Donovan 27:567abf893938 379 if (alertDetailReg.LUT_Error_Ch)
Dan O'Donovan 27:567abf893938 380 pStatus->channelAlerts[i] |= ADI_SENSE_CHANNEL_ALERT_LUT_ERR;
Dan O'Donovan 27:567abf893938 381 if (alertDetailReg.Sensor_Not_Ready)
Dan O'Donovan 27:567abf893938 382 pStatus->channelAlerts[i] |= ADI_SENSE_CHANNEL_ALERT_SENSOR_NOT_READY;
Dan O'Donovan 27:567abf893938 383 if (alertDetailReg.Comp_Not_Ready)
Dan O'Donovan 27:567abf893938 384 pStatus->channelAlerts[i] |= ADI_SENSE_CHANNEL_ALERT_COMP_NOT_READY;
Dan O'Donovan 27:567abf893938 385 if (alertDetailReg.Correction_UnderRange)
Dan O'Donovan 27:567abf893938 386 pStatus->channelAlerts[i] |= ADI_SENSE_CHANNEL_ALERT_LUT_UNDER_RANGE;
Dan O'Donovan 27:567abf893938 387 if (alertDetailReg.Correction_OverRange)
Dan O'Donovan 27:567abf893938 388 pStatus->channelAlerts[i] |= ADI_SENSE_CHANNEL_ALERT_LUT_OVER_RANGE;
Dan O'Donovan 27:567abf893938 389 }
Dan O'Donovan 27:567abf893938 390 }
Dan O'Donovan 27:567abf893938 391
Dan O'Donovan 27:567abf893938 392 if (alert2Reg.Configuration_Error)
Dan O'Donovan 27:567abf893938 393 pStatus->deviceStatus |= ADI_SENSE_DEVICE_STATUS_CONFIG_ERROR;
Dan O'Donovan 27:567abf893938 394 if (alert2Reg.LUT_Error)
Dan O'Donovan 27:567abf893938 395 pStatus->deviceStatus |= ADI_SENSE_DEVICE_STATUS_LUT_ERROR;
Dan O'Donovan 27:567abf893938 396 }
Dan O'Donovan 27:567abf893938 397
Dan O'Donovan 27:567abf893938 398 if (statusReg.Error)
Dan O'Donovan 27:567abf893938 399 {
Dan O'Donovan 27:567abf893938 400 pStatus->deviceStatus |= ADI_SENSE_DEVICE_STATUS_ERROR;
Dan O'Donovan 27:567abf893938 401
Dan O'Donovan 27:567abf893938 402 ADI_ADISENSE_CORE_Error_Code_t errorCodeReg;
Dan O'Donovan 27:567abf893938 403 READ_REG_U16(hDevice, errorCodeReg.VALUE16, CORE_ERROR_CODE);
Dan O'Donovan 27:567abf893938 404 pStatus->errorCode = errorCodeReg.Error_Code;
Dan O'Donovan 27:567abf893938 405
Dan O'Donovan 27:567abf893938 406 ADI_ADISENSE_CORE_Diagnostics_Status_t diagStatusReg;
Dan O'Donovan 27:567abf893938 407 READ_REG_U16(hDevice, diagStatusReg.VALUE16, CORE_DIAGNOSTICS_STATUS);
Dan O'Donovan 27:567abf893938 408
Dan O'Donovan 27:567abf893938 409 if (diagStatusReg.Diag_Checksum_Error)
Dan O'Donovan 27:567abf893938 410 pStatus->diagnosticsStatus |= ADI_SENSE_DIAGNOSTICS_STATUS_CHECKSUM_ERROR;
Dan O'Donovan 27:567abf893938 411 if (diagStatusReg.Diag_Comms_Error)
Dan O'Donovan 27:567abf893938 412 pStatus->diagnosticsStatus |= ADI_SENSE_DIAGNOSTICS_STATUS_COMMS_ERROR;
Dan O'Donovan 27:567abf893938 413 if (diagStatusReg.Diag_Supply_Monitor_Error)
Dan O'Donovan 27:567abf893938 414 pStatus->diagnosticsStatus |= ADI_SENSE_DIAGNOSTICS_STATUS_SUPPLY_MONITOR_ERROR;
Dan O'Donovan 27:567abf893938 415 if (diagStatusReg.Diag_Supply_Cap_Error)
Dan O'Donovan 27:567abf893938 416 pStatus->diagnosticsStatus |= ADI_SENSE_DIAGNOSTICS_STATUS_SUPPLY_CAP_ERROR;
Dan O'Donovan 27:567abf893938 417 if (diagStatusReg.Diag_Conversion_Error)
Dan O'Donovan 27:567abf893938 418 pStatus->diagnosticsStatus |= ADI_SENSE_DIAGNOSTICS_STATUS_CONVERSION_ERROR;
Dan O'Donovan 27:567abf893938 419 if (diagStatusReg.Diag_Calibration_Error)
Dan O'Donovan 27:567abf893938 420 pStatus->diagnosticsStatus |= ADI_SENSE_DIAGNOSTICS_STATUS_CALIBRATION_ERROR;
Dan O'Donovan 27:567abf893938 421 }
Dan O'Donovan 27:567abf893938 422
Dan O'Donovan 30:119ff4f3aef6 423 if (statusReg.Alert_Active || statusReg.Error)
Dan O'Donovan 30:119ff4f3aef6 424 {
Dan O'Donovan 30:119ff4f3aef6 425 ADI_ADISENSE_CORE_Debug_Code_t debugCodeReg;
Dan O'Donovan 30:119ff4f3aef6 426 READ_REG_U32(hDevice, debugCodeReg.VALUE32, CORE_DEBUG_CODE);
Dan O'Donovan 30:119ff4f3aef6 427 pStatus->debugCode = debugCodeReg.Debug_Code;
Dan O'Donovan 30:119ff4f3aef6 428 }
Dan O'Donovan 30:119ff4f3aef6 429
Dan O'Donovan 27:567abf893938 430 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 431 }
Dan O'Donovan 27:567abf893938 432
Dan O'Donovan 27:567abf893938 433 ADI_SENSE_RESULT adi_sense_GetCommandRunningState(
Dan O'Donovan 27:567abf893938 434 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 30:119ff4f3aef6 435 bool *pbCommandRunning)
Dan O'Donovan 27:567abf893938 436 {
Dan O'Donovan 27:567abf893938 437 ADI_ADISENSE_CORE_Status_t statusReg;
Dan O'Donovan 27:567abf893938 438
Dan O'Donovan 27:567abf893938 439 READ_REG_U8(hDevice, statusReg.VALUE8, CORE_STATUS);
Dan O'Donovan 27:567abf893938 440
Dan O'Donovan 27:567abf893938 441 /* We should never normally see 0xFF here if the module is operational */
Dan O'Donovan 27:567abf893938 442 if (statusReg.VALUE8 == 0xFF)
Dan O'Donovan 27:567abf893938 443 return ADI_SENSE_ERR_NOT_INITIALIZED;
Dan O'Donovan 27:567abf893938 444
Dan O'Donovan 27:567abf893938 445 *pbCommandRunning = !statusReg.Cmd_Running; /* Active-low, so invert it */
Dan O'Donovan 27:567abf893938 446
Dan O'Donovan 27:567abf893938 447 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 448 }
Dan O'Donovan 27:567abf893938 449
Dan O'Donovan 27:567abf893938 450 static ADI_SENSE_RESULT executeCommand(
Dan O'Donovan 27:567abf893938 451 ADI_SENSE_DEVICE_HANDLE const hDevice,
Dan O'Donovan 27:567abf893938 452 ADI_ADISENSE_CORE_Command_Special_Command const command,
Dan O'Donovan 30:119ff4f3aef6 453 bool const bWaitForCompletion)
Dan O'Donovan 27:567abf893938 454 {
Dan O'Donovan 27:567abf893938 455 ADI_ADISENSE_CORE_Command_t commandReg;
Dan O'Donovan 30:119ff4f3aef6 456 bool bCommandRunning;
Dan O'Donovan 27:567abf893938 457 ADI_SENSE_RESULT eRet;
Dan O'Donovan 27:567abf893938 458
Dan O'Donovan 27:567abf893938 459 /*
Dan O'Donovan 27:567abf893938 460 * Don't allow another command to be issued if one is already running, but
Dan O'Donovan 27:567abf893938 461 * make an exception for ADISENSE_CORE_COMMAND_NOP which can be used to
Dan O'Donovan 27:567abf893938 462 * request a running command to be stopped (e.g. continuous measurement)
Dan O'Donovan 27:567abf893938 463 */
Dan O'Donovan 27:567abf893938 464 if (command != ADISENSE_CORE_COMMAND_NOP)
Dan O'Donovan 27:567abf893938 465 {
Dan O'Donovan 27:567abf893938 466 eRet = adi_sense_GetCommandRunningState(hDevice, &bCommandRunning);
Dan O'Donovan 27:567abf893938 467 if (eRet)
Dan O'Donovan 27:567abf893938 468 return eRet;
Dan O'Donovan 27:567abf893938 469
Dan O'Donovan 27:567abf893938 470 if (bCommandRunning)
Dan O'Donovan 27:567abf893938 471 return ADI_SENSE_IN_USE;
Dan O'Donovan 27:567abf893938 472 }
Dan O'Donovan 27:567abf893938 473
Dan O'Donovan 27:567abf893938 474 commandReg.Special_Command = command;
Dan O'Donovan 27:567abf893938 475 WRITE_REG_U8(hDevice, commandReg.VALUE8, CORE_COMMAND);
Dan O'Donovan 27:567abf893938 476
Dan O'Donovan 27:567abf893938 477 if (bWaitForCompletion)
Dan O'Donovan 27:567abf893938 478 {
Dan O'Donovan 27:567abf893938 479 do {
Dan O'Donovan 27:567abf893938 480 /* Allow a minimum 50usec delay for status update before checking */
Dan O'Donovan 27:567abf893938 481 adi_sense_TimeDelayUsec(50);
Dan O'Donovan 27:567abf893938 482
Dan O'Donovan 27:567abf893938 483 eRet = adi_sense_GetCommandRunningState(hDevice, &bCommandRunning);
Dan O'Donovan 27:567abf893938 484 if (eRet)
Dan O'Donovan 27:567abf893938 485 return eRet;
Dan O'Donovan 27:567abf893938 486 } while (bCommandRunning);
Dan O'Donovan 27:567abf893938 487 }
Dan O'Donovan 27:567abf893938 488
Dan O'Donovan 27:567abf893938 489 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 490 }
Dan O'Donovan 27:567abf893938 491
kevin1990 29:57edca10d78c 492 ADI_SENSE_RESULT adi_sense_Shutdown(
kevin1990 29:57edca10d78c 493 ADI_SENSE_DEVICE_HANDLE const hDevice)
kevin1990 29:57edca10d78c 494 {
kevin1990 29:57edca10d78c 495 return executeCommand(hDevice, ADISENSE_CORE_COMMAND_POWER_DOWN, false);
kevin1990 29:57edca10d78c 496 }
kevin1990 29:57edca10d78c 497
kevin1990 29:57edca10d78c 498
Dan O'Donovan 27:567abf893938 499 ADI_SENSE_RESULT adi_sense_ApplyConfigUpdates(
Dan O'Donovan 27:567abf893938 500 ADI_SENSE_DEVICE_HANDLE const hDevice)
Dan O'Donovan 27:567abf893938 501 {
Dan O'Donovan 27:567abf893938 502 return executeCommand(hDevice, ADISENSE_CORE_COMMAND_LATCH_CONFIG, true);
Dan O'Donovan 27:567abf893938 503 }
Dan O'Donovan 27:567abf893938 504
Dan O'Donovan 27:567abf893938 505 /*!
Dan O'Donovan 27:567abf893938 506 * @brief Start a measurement cycle.
Dan O'Donovan 27:567abf893938 507 *
Dan O'Donovan 27:567abf893938 508 * @param[out]
Dan O'Donovan 27:567abf893938 509 *
Dan O'Donovan 27:567abf893938 510 * @return Status
Dan O'Donovan 27:567abf893938 511 * - #ADI_SENSE_SUCCESS Call completed successfully.
Dan O'Donovan 27:567abf893938 512 * - #ADI_SENSE_FAILURE
Dan O'Donovan 27:567abf893938 513 *
Dan O'Donovan 27:567abf893938 514 * @details Sends the latch config command. Configuration for channels in
Dan O'Donovan 27:567abf893938 515 * conversion cycle should be completed before this function.
Dan O'Donovan 27:567abf893938 516 * Channel enabled bit should be set before this function.
Dan O'Donovan 27:567abf893938 517 * Starts a conversion and configures the format of the sample.
Dan O'Donovan 27:567abf893938 518 *
Dan O'Donovan 27:567abf893938 519 */
Dan O'Donovan 27:567abf893938 520 ADI_SENSE_RESULT adi_sense_StartMeasurement(
Dan O'Donovan 27:567abf893938 521 ADI_SENSE_DEVICE_HANDLE const hDevice,
Dan O'Donovan 27:567abf893938 522 ADI_SENSE_MEASUREMENT_MODE const eMeasurementMode)
Dan O'Donovan 27:567abf893938 523 {
Dan O'Donovan 27:567abf893938 524 switch (eMeasurementMode)
Dan O'Donovan 27:567abf893938 525 {
Dan O'Donovan 27:567abf893938 526 case ADI_SENSE_MEASUREMENT_MODE_HEALTHCHECK:
Dan O'Donovan 27:567abf893938 527 return executeCommand(hDevice, ADISENSE_CORE_COMMAND_SYSTEM_CHECK, false);
Dan O'Donovan 27:567abf893938 528 case ADI_SENSE_MEASUREMENT_MODE_NORMAL:
Dan O'Donovan 27:567abf893938 529 return executeCommand(hDevice, ADISENSE_CORE_COMMAND_CONVERT_WITH_RAW, false);
Dan O'Donovan 27:567abf893938 530 case ADI_SENSE_MEASUREMENT_MODE_OMIT_RAW:
Dan O'Donovan 27:567abf893938 531 return executeCommand(hDevice, ADISENSE_CORE_COMMAND_CONVERT, false);
Dan O'Donovan 27:567abf893938 532 case ADI_SENSE_MEASUREMENT_MODE_FFT:
Dan O'Donovan 27:567abf893938 533 return executeCommand(hDevice, ADISENSE_CORE_COMMAND_CONVERT_FFT, false);
Dan O'Donovan 27:567abf893938 534 default:
Dan O'Donovan 27:567abf893938 535 ADI_SENSE_LOG_ERROR("Invalid measurement mode %d specified",
Dan O'Donovan 27:567abf893938 536 eMeasurementMode);
Dan O'Donovan 27:567abf893938 537 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 538 }
Dan O'Donovan 27:567abf893938 539 }
Dan O'Donovan 27:567abf893938 540
Dan O'Donovan 27:567abf893938 541 /*
Dan O'Donovan 27:567abf893938 542 * Store the configuration settings to persistent memory on the device.
kevin1990 29:57edca10d78c 543 * The settings can be saved to 4 different flash memory areas (slots).
Dan O'Donovan 27:567abf893938 544 * No other command must be running when this is called.
Dan O'Donovan 27:567abf893938 545 * Do not power down the device while this command is running.
Dan O'Donovan 27:567abf893938 546 */
Dan O'Donovan 27:567abf893938 547 ADI_SENSE_RESULT adi_sense_SaveConfig(
kevin1990 29:57edca10d78c 548 ADI_SENSE_DEVICE_HANDLE const hDevice,
kevin1990 29:57edca10d78c 549 ADI_SENSE_USER_CONFIG_SLOT const eSlotId)
Dan O'Donovan 27:567abf893938 550 {
kevin1990 29:57edca10d78c 551 switch (eSlotId)
kevin1990 29:57edca10d78c 552 {
kevin1990 29:57edca10d78c 553 case ADI_SENSE_FLASH_CONFIG_1:
kevin1990 29:57edca10d78c 554 return executeCommand(hDevice, ADISENSE_CORE_COMMAND_SAVE_CONFIG_1, true);
kevin1990 29:57edca10d78c 555 case ADI_SENSE_FLASH_CONFIG_2:
kevin1990 29:57edca10d78c 556 return executeCommand(hDevice, ADISENSE_CORE_COMMAND_SAVE_CONFIG_2, true);
kevin1990 29:57edca10d78c 557 case ADI_SENSE_FLASH_CONFIG_3:
kevin1990 29:57edca10d78c 558 return executeCommand(hDevice, ADISENSE_CORE_COMMAND_SAVE_CONFIG_3, true);
kevin1990 29:57edca10d78c 559 case ADI_SENSE_FLASH_CONFIG_4:
kevin1990 29:57edca10d78c 560 return executeCommand(hDevice, ADISENSE_CORE_COMMAND_SAVE_CONFIG_4, true);
kevin1990 29:57edca10d78c 561 default:
kevin1990 29:57edca10d78c 562 ADI_SENSE_LOG_ERROR("Invalid user config target slot %d specified",
kevin1990 29:57edca10d78c 563 eSlotId);
kevin1990 29:57edca10d78c 564 return ADI_SENSE_INVALID_PARAM;
kevin1990 29:57edca10d78c 565 }
Dan O'Donovan 27:567abf893938 566 }
Dan O'Donovan 27:567abf893938 567
Dan O'Donovan 27:567abf893938 568 /*
Dan O'Donovan 27:567abf893938 569 * Restore the configuration settings from persistent memory on the device.
Dan O'Donovan 27:567abf893938 570 * No other command must be running when this is called.
Dan O'Donovan 27:567abf893938 571 */
Dan O'Donovan 27:567abf893938 572 ADI_SENSE_RESULT adi_sense_RestoreConfig(
kevin1990 29:57edca10d78c 573 ADI_SENSE_DEVICE_HANDLE const hDevice,
kevin1990 29:57edca10d78c 574 ADI_SENSE_USER_CONFIG_SLOT const eSlotId)
kevin1990 29:57edca10d78c 575 {
kevin1990 29:57edca10d78c 576 switch (eSlotId)
kevin1990 29:57edca10d78c 577 {
kevin1990 29:57edca10d78c 578 case ADI_SENSE_FLASH_CONFIG_1:
kevin1990 29:57edca10d78c 579 return executeCommand(hDevice, ADISENSE_CORE_COMMAND_LOAD_CONFIG_1, true);
kevin1990 29:57edca10d78c 580 case ADI_SENSE_FLASH_CONFIG_2:
kevin1990 29:57edca10d78c 581 return executeCommand(hDevice, ADISENSE_CORE_COMMAND_LOAD_CONFIG_2, true);
kevin1990 29:57edca10d78c 582 case ADI_SENSE_FLASH_CONFIG_3:
kevin1990 29:57edca10d78c 583 return executeCommand(hDevice, ADISENSE_CORE_COMMAND_LOAD_CONFIG_3, true);
kevin1990 29:57edca10d78c 584 case ADI_SENSE_FLASH_CONFIG_4:
kevin1990 29:57edca10d78c 585 return executeCommand(hDevice, ADISENSE_CORE_COMMAND_LOAD_CONFIG_4, true);
kevin1990 29:57edca10d78c 586 default:
kevin1990 29:57edca10d78c 587 ADI_SENSE_LOG_ERROR("Invalid user config source slot %d specified",
kevin1990 29:57edca10d78c 588 eSlotId);
kevin1990 29:57edca10d78c 589 return ADI_SENSE_INVALID_PARAM;
kevin1990 29:57edca10d78c 590 }
kevin1990 29:57edca10d78c 591 }
kevin1990 29:57edca10d78c 592
kevin1990 29:57edca10d78c 593 /*
kevin1990 29:57edca10d78c 594 * Erase the entire external flash memory.
kevin1990 29:57edca10d78c 595 * No other command must be running when this is called.
kevin1990 29:57edca10d78c 596 */
kevin1990 29:57edca10d78c 597 ADI_SENSE_RESULT adi_sense_EraseExternalFlash(
Dan O'Donovan 27:567abf893938 598 ADI_SENSE_DEVICE_HANDLE const hDevice)
Dan O'Donovan 27:567abf893938 599 {
kevin1990 29:57edca10d78c 600 return executeCommand(hDevice, ADISENSE_CORE_COMMAND_ERASE_EXTERNAL_FLASH, true);
kevin1990 29:57edca10d78c 601 }
kevin1990 29:57edca10d78c 602
kevin1990 29:57edca10d78c 603 /*
kevin1990 29:57edca10d78c 604 * Read the number of samples stored in external flash memory.
kevin1990 29:57edca10d78c 605 * No other command must be running when this is called.
kevin1990 29:57edca10d78c 606 */
kevin1990 29:57edca10d78c 607 ADI_SENSE_RESULT adi_sense_GetExternalFlashSampleCount(
kevin1990 29:57edca10d78c 608 ADI_SENSE_DEVICE_HANDLE const hDevice,
kevin1990 29:57edca10d78c 609 uint32_t * nSampleCount)
kevin1990 29:57edca10d78c 610 {
kevin1990 29:57edca10d78c 611 ADI_ADISENSE_CORE_Ext_Flash_Sample_Count_t nCount;
kevin1990 29:57edca10d78c 612
kevin1990 29:57edca10d78c 613 READ_REG_U32(hDevice, nCount.VALUE32, CORE_EXT_FLASH_SAMPLE_COUNT);
kevin1990 29:57edca10d78c 614
kevin1990 29:57edca10d78c 615 *nSampleCount = nCount.VALUE32;
kevin1990 29:57edca10d78c 616
kevin1990 29:57edca10d78c 617 return ADI_SENSE_SUCCESS;
kevin1990 29:57edca10d78c 618 }
kevin1990 29:57edca10d78c 619
kevin1990 29:57edca10d78c 620 // DEBUG - TO BE DELETED
kevin1990 29:57edca10d78c 621 ADI_SENSE_RESULT adi_sense_SetExternalFlashIndex(
kevin1990 29:57edca10d78c 622 ADI_SENSE_DEVICE_HANDLE const hDevice,
kevin1990 29:57edca10d78c 623 uint32_t nStartIndex)
kevin1990 29:57edca10d78c 624 {
kevin1990 29:57edca10d78c 625 WRITE_REG_U32(hDevice, nStartIndex, CORE_EXT_FLASH_INDEX);
kevin1990 29:57edca10d78c 626
kevin1990 29:57edca10d78c 627 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 628 }
Dan O'Donovan 27:567abf893938 629
Dan O'Donovan 27:567abf893938 630 /*
kevin1990 29:57edca10d78c 631 * Read a set of data samples stored in the device external flash memory.
kevin1990 29:57edca10d78c 632 * This may be called at any time.
kevin1990 29:57edca10d78c 633 */
kevin1990 29:57edca10d78c 634 ADI_SENSE_RESULT adi_sense_GetExternalFlashData(
kevin1990 29:57edca10d78c 635 ADI_SENSE_DEVICE_HANDLE const hDevice,
kevin1990 29:57edca10d78c 636 ADI_SENSE_DATA_SAMPLE * const pSamples,
kevin1990 29:57edca10d78c 637 uint32_t const nStartIndex,
kevin1990 29:57edca10d78c 638 uint32_t const nRequested,
kevin1990 29:57edca10d78c 639 uint32_t * const pnReturned)
kevin1990 29:57edca10d78c 640 {
kevin1990 29:57edca10d78c 641 ADI_SENSE_DEVICE_CONTEXT *pCtx = hDevice;
kevin1990 29:57edca10d78c 642 uint16_t command = ADI_SENSE_1000_HOST_COMMS_READ_CMD |
kevin1990 29:57edca10d78c 643 (REG_ADISENSE_CORE_EXT_FLASH_DATA & ADI_SENSE_1000_HOST_COMMS_ADR_MASK);
kevin1990 29:57edca10d78c 644 uint8_t commandData[2] = {
kevin1990 29:57edca10d78c 645 command >> 8,
kevin1990 29:57edca10d78c 646 command & 0xFF
kevin1990 29:57edca10d78c 647 };
kevin1990 29:57edca10d78c 648 uint8_t commandResponse[2];
kevin1990 29:57edca10d78c 649 unsigned nValidSamples = 0;
kevin1990 29:57edca10d78c 650 ADI_SENSE_RESULT eRet = ADI_SENSE_SUCCESS;
kevin1990 29:57edca10d78c 651
kevin1990 29:57edca10d78c 652 /* Setup initial sample */
kevin1990 29:57edca10d78c 653 WRITE_REG_U32(hDevice, nStartIndex, CORE_EXT_FLASH_INDEX);
kevin1990 29:57edca10d78c 654
kevin1990 29:57edca10d78c 655 /* Send flash read command */
kevin1990 29:57edca10d78c 656 do {
kevin1990 29:57edca10d78c 657 eRet = adi_sense_SpiTransfer(pCtx->hSpi, commandData, commandResponse,
kevin1990 29:57edca10d78c 658 sizeof(command), false);
kevin1990 29:57edca10d78c 659 if (eRet)
kevin1990 29:57edca10d78c 660 {
kevin1990 29:57edca10d78c 661 ADI_SENSE_LOG_ERROR("Failed to send read command for external flash");
kevin1990 29:57edca10d78c 662 return eRet;
kevin1990 29:57edca10d78c 663 }
kevin1990 29:57edca10d78c 664
kevin1990 29:57edca10d78c 665 adi_sense_TimeDelayUsec(ADI_SENSE_1000_HOST_COMMS_XFER_DELAY);
kevin1990 29:57edca10d78c 666 } while ((commandResponse[0] != ADI_SENSE_1000_HOST_COMMS_CMD_RESP_0) ||
kevin1990 29:57edca10d78c 667 (commandResponse[1] != ADI_SENSE_1000_HOST_COMMS_CMD_RESP_1));
kevin1990 29:57edca10d78c 668
kevin1990 29:57edca10d78c 669 /* Read samples from external flash memory */
kevin1990 29:57edca10d78c 670 for (unsigned i = 0; i < nRequested; i++)
kevin1990 29:57edca10d78c 671 {
kevin1990 29:57edca10d78c 672 ADI_SENSE_1000_Sensor_Result_t sensorResult;
Dan O'Donovan 30:119ff4f3aef6 673 bool bHoldCs = true;
kevin1990 29:57edca10d78c 674
kevin1990 29:57edca10d78c 675 /* Keep the CS signal asserted for all but the last sample */
kevin1990 29:57edca10d78c 676 if ((i + 1) == nRequested)
kevin1990 29:57edca10d78c 677 bHoldCs = false;
kevin1990 29:57edca10d78c 678
kevin1990 29:57edca10d78c 679 eRet = adi_sense_SpiTransfer(pCtx->hSpi, NULL, (uint8_t *) (&sensorResult),
kevin1990 29:57edca10d78c 680 8, bHoldCs);
kevin1990 29:57edca10d78c 681 if (eRet)
kevin1990 29:57edca10d78c 682 {
kevin1990 29:57edca10d78c 683 ADI_SENSE_LOG_ERROR("Failed to read data from external flash");
kevin1990 29:57edca10d78c 684 return eRet;
kevin1990 29:57edca10d78c 685 }
kevin1990 29:57edca10d78c 686
kevin1990 29:57edca10d78c 687 ADI_SENSE_DATA_SAMPLE *pSample = &pSamples[nValidSamples];
kevin1990 29:57edca10d78c 688
kevin1990 29:57edca10d78c 689 pSample->status = (ADI_SENSE_DEVICE_STATUS_FLAGS)0;
kevin1990 29:57edca10d78c 690 if (sensorResult.Ch_Error)
kevin1990 29:57edca10d78c 691 pSample->status |= ADI_SENSE_DEVICE_STATUS_ERROR;
kevin1990 29:57edca10d78c 692 if (sensorResult.Ch_Alert)
kevin1990 29:57edca10d78c 693 pSample->status |= ADI_SENSE_DEVICE_STATUS_ALERT;
kevin1990 29:57edca10d78c 694
kevin1990 29:57edca10d78c 695 if (sensorResult.Ch_Raw)
kevin1990 29:57edca10d78c 696 pSample->rawValue = sensorResult.Raw_Sample;
kevin1990 29:57edca10d78c 697 else
kevin1990 29:57edca10d78c 698 pSample->rawValue = 0;
kevin1990 29:57edca10d78c 699
kevin1990 29:57edca10d78c 700 pSample->channelId = sensorResult.Channel_ID;
kevin1990 29:57edca10d78c 701 pSample->processedValue = sensorResult.Sensor_Result;
kevin1990 29:57edca10d78c 702
kevin1990 29:57edca10d78c 703 nValidSamples++;
kevin1990 29:57edca10d78c 704 }
kevin1990 29:57edca10d78c 705 *pnReturned = nValidSamples;
kevin1990 29:57edca10d78c 706
kevin1990 29:57edca10d78c 707 adi_sense_TimeDelayUsec(ADI_SENSE_1000_HOST_COMMS_XFER_DELAY);
kevin1990 29:57edca10d78c 708
kevin1990 29:57edca10d78c 709 return eRet;
kevin1990 29:57edca10d78c 710 }
kevin1990 29:57edca10d78c 711
kevin1990 29:57edca10d78c 712
kevin1990 29:57edca10d78c 713 /*
Dan O'Donovan 27:567abf893938 714 * Store the LUT data to persistent memory on the device.
Dan O'Donovan 27:567abf893938 715 * No other command must be running when this is called.
Dan O'Donovan 27:567abf893938 716 * Do not power down the device while this command is running.
Dan O'Donovan 27:567abf893938 717 */
Dan O'Donovan 27:567abf893938 718 ADI_SENSE_RESULT adi_sense_SaveLutData(
Dan O'Donovan 27:567abf893938 719 ADI_SENSE_DEVICE_HANDLE const hDevice)
Dan O'Donovan 27:567abf893938 720 {
Dan O'Donovan 27:567abf893938 721 return executeCommand(hDevice, ADISENSE_CORE_COMMAND_SAVE_LUT, true);
Dan O'Donovan 27:567abf893938 722 }
Dan O'Donovan 27:567abf893938 723
Dan O'Donovan 27:567abf893938 724 /*
Dan O'Donovan 27:567abf893938 725 * Restore the LUT data from persistent memory on the device.
Dan O'Donovan 27:567abf893938 726 * No other command must be running when this is called.
Dan O'Donovan 27:567abf893938 727 */
Dan O'Donovan 27:567abf893938 728 ADI_SENSE_RESULT adi_sense_RestoreLutData(
Dan O'Donovan 27:567abf893938 729 ADI_SENSE_DEVICE_HANDLE const hDevice)
Dan O'Donovan 27:567abf893938 730 {
Dan O'Donovan 27:567abf893938 731 return executeCommand(hDevice, ADISENSE_CORE_COMMAND_LOAD_LUT, true);
Dan O'Donovan 27:567abf893938 732 }
Dan O'Donovan 27:567abf893938 733
Dan O'Donovan 27:567abf893938 734 /*
Dan O'Donovan 27:567abf893938 735 * Stop the measurement cycles on the device.
Dan O'Donovan 27:567abf893938 736 * To be used only if a measurement command is currently running.
Dan O'Donovan 27:567abf893938 737 */
Dan O'Donovan 27:567abf893938 738 ADI_SENSE_RESULT adi_sense_StopMeasurement(
Dan O'Donovan 27:567abf893938 739 ADI_SENSE_DEVICE_HANDLE const hDevice)
Dan O'Donovan 27:567abf893938 740 {
Dan O'Donovan 27:567abf893938 741 return executeCommand(hDevice, ADISENSE_CORE_COMMAND_NOP, true);
Dan O'Donovan 27:567abf893938 742 }
Dan O'Donovan 27:567abf893938 743
Dan O'Donovan 27:567abf893938 744 /*
Dan O'Donovan 27:567abf893938 745 * Run built-in diagnostic checks on the device.
Dan O'Donovan 27:567abf893938 746 * Diagnostics are executed according to the current applied settings.
Dan O'Donovan 27:567abf893938 747 * No other command must be running when this is called.
Dan O'Donovan 27:567abf893938 748 */
Dan O'Donovan 27:567abf893938 749 ADI_SENSE_RESULT adi_sense_RunDiagnostics(
Dan O'Donovan 27:567abf893938 750 ADI_SENSE_DEVICE_HANDLE const hDevice)
Dan O'Donovan 27:567abf893938 751 {
Dan O'Donovan 27:567abf893938 752 return executeCommand(hDevice, ADISENSE_CORE_COMMAND_RUN_DIAGNOSTICS, true);
Dan O'Donovan 27:567abf893938 753 }
Dan O'Donovan 27:567abf893938 754
Dan O'Donovan 27:567abf893938 755 /*
Dan O'Donovan 27:567abf893938 756 * Run self-calibration routines on the device.
Dan O'Donovan 27:567abf893938 757 * Calibration is executed according to the current applied settings.
Dan O'Donovan 27:567abf893938 758 * No other command must be running when this is called.
Dan O'Donovan 27:567abf893938 759 */
Dan O'Donovan 27:567abf893938 760 ADI_SENSE_RESULT adi_sense_RunCalibration(
Dan O'Donovan 27:567abf893938 761 ADI_SENSE_DEVICE_HANDLE const hDevice)
Dan O'Donovan 27:567abf893938 762 {
Dan O'Donovan 27:567abf893938 763 return executeCommand(hDevice, ADISENSE_CORE_COMMAND_SELF_CALIBRATION, true);
Dan O'Donovan 27:567abf893938 764 }
Dan O'Donovan 27:567abf893938 765
Dan O'Donovan 27:567abf893938 766 /*
kevin1990 29:57edca10d78c 767 * Run digital calibration routines on the device.
kevin1990 29:57edca10d78c 768 * Calibration is executed according to the current applied settings.
kevin1990 29:57edca10d78c 769 * No other command must be running when this is called.
kevin1990 29:57edca10d78c 770 */
kevin1990 29:57edca10d78c 771 ADI_SENSE_RESULT adi_sense_RunDigitalCalibration(
kevin1990 29:57edca10d78c 772 ADI_SENSE_DEVICE_HANDLE const hDevice)
kevin1990 29:57edca10d78c 773 {
kevin1990 29:57edca10d78c 774 return executeCommand(hDevice, ADISENSE_CORE_COMMAND_CALIBRATE_DIGITAL, true);
kevin1990 29:57edca10d78c 775 }
kevin1990 29:57edca10d78c 776
kevin1990 29:57edca10d78c 777 /*
Dan O'Donovan 27:567abf893938 778 * Read a set of data samples from the device.
Dan O'Donovan 27:567abf893938 779 * This may be called at any time.
Dan O'Donovan 27:567abf893938 780 */
Dan O'Donovan 27:567abf893938 781 ADI_SENSE_RESULT adi_sense_GetData(
Dan O'Donovan 27:567abf893938 782 ADI_SENSE_DEVICE_HANDLE const hDevice,
Dan O'Donovan 27:567abf893938 783 ADI_SENSE_MEASUREMENT_MODE const eMeasurementMode,
Dan O'Donovan 27:567abf893938 784 ADI_SENSE_DATA_SAMPLE * const pSamples,
Dan O'Donovan 27:567abf893938 785 uint8_t const nBytesPerSample,
Dan O'Donovan 27:567abf893938 786 uint32_t const nRequested,
Dan O'Donovan 27:567abf893938 787 uint32_t * const pnReturned)
Dan O'Donovan 27:567abf893938 788 {
Dan O'Donovan 27:567abf893938 789 ADI_SENSE_DEVICE_CONTEXT *pCtx = hDevice;
Dan O'Donovan 27:567abf893938 790 uint16_t command = ADI_SENSE_1000_HOST_COMMS_READ_CMD |
Dan O'Donovan 27:567abf893938 791 (REG_ADISENSE_CORE_DATA_FIFO & ADI_SENSE_1000_HOST_COMMS_ADR_MASK);
Dan O'Donovan 27:567abf893938 792 uint8_t commandData[2] = {
Dan O'Donovan 27:567abf893938 793 command >> 8,
Dan O'Donovan 27:567abf893938 794 command & 0xFF
Dan O'Donovan 27:567abf893938 795 };
Dan O'Donovan 27:567abf893938 796 uint8_t commandResponse[2];
Dan O'Donovan 27:567abf893938 797 unsigned nValidSamples = 0;
Dan O'Donovan 27:567abf893938 798 ADI_SENSE_RESULT eRet = ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 799
Dan O'Donovan 27:567abf893938 800 do {
Dan O'Donovan 27:567abf893938 801 eRet = adi_sense_SpiTransfer(pCtx->hSpi, commandData, commandResponse,
Dan O'Donovan 27:567abf893938 802 sizeof(command), false);
Dan O'Donovan 27:567abf893938 803 if (eRet)
Dan O'Donovan 27:567abf893938 804 {
Dan O'Donovan 27:567abf893938 805 ADI_SENSE_LOG_ERROR("Failed to send read command for FIFO register");
Dan O'Donovan 27:567abf893938 806 return eRet;
Dan O'Donovan 27:567abf893938 807 }
Dan O'Donovan 27:567abf893938 808 adi_sense_TimeDelayUsec(ADI_SENSE_1000_HOST_COMMS_XFER_DELAY);
Dan O'Donovan 27:567abf893938 809 } while ((commandResponse[0] != ADI_SENSE_1000_HOST_COMMS_CMD_RESP_0) ||
Dan O'Donovan 27:567abf893938 810 (commandResponse[1] != ADI_SENSE_1000_HOST_COMMS_CMD_RESP_1));
Dan O'Donovan 27:567abf893938 811
Dan O'Donovan 27:567abf893938 812 for (unsigned i = 0; i < nRequested; i++)
Dan O'Donovan 27:567abf893938 813 {
Dan O'Donovan 27:567abf893938 814 ADI_SENSE_1000_Sensor_Result_t sensorResult;
Dan O'Donovan 30:119ff4f3aef6 815 bool bHoldCs = true;
Dan O'Donovan 27:567abf893938 816
Dan O'Donovan 27:567abf893938 817 /* Keep the CS signal asserted for all but the last sample */
Dan O'Donovan 27:567abf893938 818 if ((i + 1) == nRequested)
Dan O'Donovan 27:567abf893938 819 bHoldCs = false;
Dan O'Donovan 27:567abf893938 820
Dan O'Donovan 27:567abf893938 821 eRet = adi_sense_SpiTransfer(pCtx->hSpi, NULL, &sensorResult,
Dan O'Donovan 27:567abf893938 822 nBytesPerSample, bHoldCs);
Dan O'Donovan 27:567abf893938 823 if (eRet)
Dan O'Donovan 27:567abf893938 824 {
Dan O'Donovan 27:567abf893938 825 ADI_SENSE_LOG_ERROR("Failed to read data from FIFO register");
Dan O'Donovan 27:567abf893938 826 return eRet;
Dan O'Donovan 27:567abf893938 827 }
Dan O'Donovan 27:567abf893938 828
Dan O'Donovan 27:567abf893938 829 if (! sensorResult.Ch_Valid)
Dan O'Donovan 27:567abf893938 830 {
Dan O'Donovan 27:567abf893938 831 /*
Dan O'Donovan 27:567abf893938 832 * Reading an invalid sample indicates that there are no
Dan O'Donovan 27:567abf893938 833 * more samples available or we've lost sync with the device.
Dan O'Donovan 27:567abf893938 834 * In the latter case, it might be recoverable, but return here
Dan O'Donovan 27:567abf893938 835 * to let the application check the device status and decide itself.
Dan O'Donovan 27:567abf893938 836 */
Dan O'Donovan 27:567abf893938 837 eRet = ADI_SENSE_INCOMPLETE;
Dan O'Donovan 27:567abf893938 838 break;
Dan O'Donovan 27:567abf893938 839 }
Dan O'Donovan 27:567abf893938 840
Dan O'Donovan 27:567abf893938 841 ADI_SENSE_DATA_SAMPLE *pSample = &pSamples[nValidSamples];
Dan O'Donovan 27:567abf893938 842
Dan O'Donovan 27:567abf893938 843 pSample->status = (ADI_SENSE_DEVICE_STATUS_FLAGS)0;
Dan O'Donovan 27:567abf893938 844 if (sensorResult.Ch_Error)
Dan O'Donovan 27:567abf893938 845 pSample->status |= ADI_SENSE_DEVICE_STATUS_ERROR;
Dan O'Donovan 27:567abf893938 846 if (sensorResult.Ch_Alert)
Dan O'Donovan 27:567abf893938 847 pSample->status |= ADI_SENSE_DEVICE_STATUS_ALERT;
Dan O'Donovan 27:567abf893938 848
Dan O'Donovan 27:567abf893938 849 if (sensorResult.Ch_Raw)
Dan O'Donovan 27:567abf893938 850 pSample->rawValue = sensorResult.Raw_Sample;
Dan O'Donovan 27:567abf893938 851 else
Dan O'Donovan 27:567abf893938 852 pSample->rawValue = 0;
Dan O'Donovan 27:567abf893938 853
Dan O'Donovan 27:567abf893938 854 pSample->channelId = sensorResult.Channel_ID;
Dan O'Donovan 27:567abf893938 855 pSample->processedValue = sensorResult.Sensor_Result;
Dan O'Donovan 27:567abf893938 856
Dan O'Donovan 27:567abf893938 857 nValidSamples++;
Dan O'Donovan 30:119ff4f3aef6 858
Dan O'Donovan 30:119ff4f3aef6 859 adi_sense_TimeDelayUsec(ADI_SENSE_1000_HOST_COMMS_XFER_DELAY);
Dan O'Donovan 27:567abf893938 860 }
Dan O'Donovan 27:567abf893938 861 *pnReturned = nValidSamples;
Dan O'Donovan 27:567abf893938 862
Dan O'Donovan 27:567abf893938 863 return eRet;
Dan O'Donovan 27:567abf893938 864 }
Dan O'Donovan 27:567abf893938 865
Dan O'Donovan 27:567abf893938 866 /*
Dan O'Donovan 27:567abf893938 867 * Close the given ADISENSE device.
Dan O'Donovan 27:567abf893938 868 */
Dan O'Donovan 27:567abf893938 869 ADI_SENSE_RESULT adi_sense_Close(
Dan O'Donovan 27:567abf893938 870 ADI_SENSE_DEVICE_HANDLE const hDevice)
Dan O'Donovan 27:567abf893938 871 {
Dan O'Donovan 27:567abf893938 872 ADI_SENSE_DEVICE_CONTEXT *pCtx = hDevice;
Dan O'Donovan 27:567abf893938 873
Dan O'Donovan 27:567abf893938 874 adi_sense_GpioClose(pCtx->hGpio);
Dan O'Donovan 27:567abf893938 875 adi_sense_SpiClose(pCtx->hSpi);
Dan O'Donovan 27:567abf893938 876 adi_sense_LogClose();
Dan O'Donovan 27:567abf893938 877
Dan O'Donovan 27:567abf893938 878 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 879 }
Dan O'Donovan 27:567abf893938 880
Dan O'Donovan 27:567abf893938 881 ADI_SENSE_RESULT adi_sense_1000_WriteRegister(
Dan O'Donovan 27:567abf893938 882 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 883 uint16_t nAddress,
Dan O'Donovan 27:567abf893938 884 void *pData,
Dan O'Donovan 27:567abf893938 885 unsigned nLength)
Dan O'Donovan 27:567abf893938 886 {
Dan O'Donovan 27:567abf893938 887 ADI_SENSE_RESULT eRet;
Dan O'Donovan 27:567abf893938 888 ADI_SENSE_DEVICE_CONTEXT *pCtx = hDevice;
Dan O'Donovan 27:567abf893938 889 uint16_t command = ADI_SENSE_1000_HOST_COMMS_WRITE_CMD |
Dan O'Donovan 27:567abf893938 890 (nAddress & ADI_SENSE_1000_HOST_COMMS_ADR_MASK);
Dan O'Donovan 27:567abf893938 891 uint8_t commandData[2] = {
Dan O'Donovan 27:567abf893938 892 command >> 8,
Dan O'Donovan 27:567abf893938 893 command & 0xFF
Dan O'Donovan 27:567abf893938 894 };
Dan O'Donovan 27:567abf893938 895 uint8_t commandResponse[2];
Dan O'Donovan 27:567abf893938 896
Dan O'Donovan 27:567abf893938 897 do {
Dan O'Donovan 27:567abf893938 898 eRet = adi_sense_SpiTransfer(pCtx->hSpi, commandData, commandResponse,
Dan O'Donovan 27:567abf893938 899 sizeof(command), false);
Dan O'Donovan 27:567abf893938 900 if (eRet)
Dan O'Donovan 27:567abf893938 901 {
Dan O'Donovan 27:567abf893938 902 ADI_SENSE_LOG_ERROR("Failed to send write command for register %u",
Dan O'Donovan 27:567abf893938 903 nAddress);
Dan O'Donovan 27:567abf893938 904 return eRet;
Dan O'Donovan 27:567abf893938 905 }
Dan O'Donovan 27:567abf893938 906
Dan O'Donovan 27:567abf893938 907 adi_sense_TimeDelayUsec(ADI_SENSE_1000_HOST_COMMS_XFER_DELAY);
Dan O'Donovan 27:567abf893938 908 } while ((commandResponse[0] != ADI_SENSE_1000_HOST_COMMS_CMD_RESP_0) ||
Dan O'Donovan 27:567abf893938 909 (commandResponse[1] != ADI_SENSE_1000_HOST_COMMS_CMD_RESP_1));
Dan O'Donovan 27:567abf893938 910
Dan O'Donovan 27:567abf893938 911 eRet = adi_sense_SpiTransfer(pCtx->hSpi, pData, NULL, nLength, false);
Dan O'Donovan 27:567abf893938 912 if (eRet)
Dan O'Donovan 27:567abf893938 913 {
Dan O'Donovan 27:567abf893938 914 ADI_SENSE_LOG_ERROR("Failed to write data (%dB) to register %u",
Dan O'Donovan 27:567abf893938 915 nLength, nAddress);
Dan O'Donovan 27:567abf893938 916 return eRet;
Dan O'Donovan 27:567abf893938 917 }
Dan O'Donovan 27:567abf893938 918
Dan O'Donovan 27:567abf893938 919 adi_sense_TimeDelayUsec(ADI_SENSE_1000_HOST_COMMS_XFER_DELAY);
Dan O'Donovan 27:567abf893938 920
Dan O'Donovan 27:567abf893938 921 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 922 }
Dan O'Donovan 27:567abf893938 923
Dan O'Donovan 27:567abf893938 924 ADI_SENSE_RESULT adi_sense_1000_ReadRegister(
Dan O'Donovan 27:567abf893938 925 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 926 uint16_t nAddress,
Dan O'Donovan 27:567abf893938 927 void *pData,
Dan O'Donovan 27:567abf893938 928 unsigned nLength)
Dan O'Donovan 27:567abf893938 929 {
Dan O'Donovan 27:567abf893938 930 ADI_SENSE_RESULT eRet;
Dan O'Donovan 27:567abf893938 931 ADI_SENSE_DEVICE_CONTEXT *pCtx = hDevice;
Dan O'Donovan 27:567abf893938 932 uint16_t command = ADI_SENSE_1000_HOST_COMMS_READ_CMD |
Dan O'Donovan 27:567abf893938 933 (nAddress & ADI_SENSE_1000_HOST_COMMS_ADR_MASK);
Dan O'Donovan 27:567abf893938 934 uint8_t commandData[2] = {
Dan O'Donovan 27:567abf893938 935 command >> 8,
Dan O'Donovan 27:567abf893938 936 command & 0xFF
Dan O'Donovan 27:567abf893938 937 };
Dan O'Donovan 27:567abf893938 938 uint8_t commandResponse[2];
Dan O'Donovan 27:567abf893938 939
Dan O'Donovan 27:567abf893938 940 do {
Dan O'Donovan 27:567abf893938 941 eRet = adi_sense_SpiTransfer(pCtx->hSpi, commandData, commandResponse,
Dan O'Donovan 27:567abf893938 942 sizeof(command), false);
Dan O'Donovan 27:567abf893938 943 if (eRet)
Dan O'Donovan 27:567abf893938 944 {
Dan O'Donovan 27:567abf893938 945 ADI_SENSE_LOG_ERROR("Failed to send read command for register %u",
Dan O'Donovan 27:567abf893938 946 nAddress);
Dan O'Donovan 27:567abf893938 947 return eRet;
Dan O'Donovan 27:567abf893938 948 }
Dan O'Donovan 27:567abf893938 949
Dan O'Donovan 27:567abf893938 950 adi_sense_TimeDelayUsec(ADI_SENSE_1000_HOST_COMMS_XFER_DELAY);
Dan O'Donovan 27:567abf893938 951 } while ((commandResponse[0] != ADI_SENSE_1000_HOST_COMMS_CMD_RESP_0) ||
Dan O'Donovan 27:567abf893938 952 (commandResponse[1] != ADI_SENSE_1000_HOST_COMMS_CMD_RESP_1));
Dan O'Donovan 27:567abf893938 953
Dan O'Donovan 27:567abf893938 954 eRet = adi_sense_SpiTransfer(pCtx->hSpi, NULL, pData, nLength, false);
Dan O'Donovan 27:567abf893938 955 if (eRet)
Dan O'Donovan 27:567abf893938 956 {
Dan O'Donovan 27:567abf893938 957 ADI_SENSE_LOG_ERROR("Failed to read data (%uB) from register %u",
Dan O'Donovan 27:567abf893938 958 nLength, nAddress);
Dan O'Donovan 27:567abf893938 959 return eRet;
Dan O'Donovan 27:567abf893938 960 }
Dan O'Donovan 27:567abf893938 961
Dan O'Donovan 27:567abf893938 962 adi_sense_TimeDelayUsec(ADI_SENSE_1000_HOST_COMMS_XFER_DELAY);
Dan O'Donovan 27:567abf893938 963
Dan O'Donovan 27:567abf893938 964 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 965 }
Dan O'Donovan 27:567abf893938 966
Dan O'Donovan 27:567abf893938 967 ADI_SENSE_RESULT adi_sense_GetDeviceReadyState(
Dan O'Donovan 27:567abf893938 968 ADI_SENSE_DEVICE_HANDLE const hDevice,
Dan O'Donovan 30:119ff4f3aef6 969 bool * const bReady)
Dan O'Donovan 27:567abf893938 970 {
Dan O'Donovan 27:567abf893938 971 ADI_ADISENSE_SPI_Chip_Type_t chipTypeReg;
Dan O'Donovan 27:567abf893938 972
Dan O'Donovan 27:567abf893938 973 READ_REG_U8(hDevice, chipTypeReg.VALUE8, SPI_CHIP_TYPE);
Dan O'Donovan 27:567abf893938 974 /* If we read this register successfully, assume the device is ready */
Dan O'Donovan 27:567abf893938 975 *bReady = (chipTypeReg.VALUE8 == REG_ADISENSE_SPI_CHIP_TYPE_RESET);
Dan O'Donovan 27:567abf893938 976
Dan O'Donovan 27:567abf893938 977 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 978 }
Dan O'Donovan 27:567abf893938 979
Dan O'Donovan 27:567abf893938 980 ADI_SENSE_RESULT adi_sense_1000_GetDataReadyModeInfo(
Dan O'Donovan 27:567abf893938 981 ADI_SENSE_DEVICE_HANDLE const hDevice,
Dan O'Donovan 27:567abf893938 982 ADI_SENSE_MEASUREMENT_MODE const eMeasurementMode,
Dan O'Donovan 27:567abf893938 983 ADI_SENSE_1000_OPERATING_MODE * const peOperatingMode,
Dan O'Donovan 27:567abf893938 984 ADI_SENSE_1000_DATAREADY_MODE * const peDataReadyMode,
Dan O'Donovan 27:567abf893938 985 uint32_t * const pnSamplesPerDataready,
Dan O'Donovan 27:567abf893938 986 uint32_t * const pnSamplesPerCycle,
Dan O'Donovan 27:567abf893938 987 uint8_t * const pnBytesPerSample)
Dan O'Donovan 27:567abf893938 988 {
Dan O'Donovan 27:567abf893938 989 unsigned nChannelsEnabled = 0;
Dan O'Donovan 27:567abf893938 990 unsigned nSamplesPerCycle = 0;
Dan O'Donovan 27:567abf893938 991
Dan O'Donovan 27:567abf893938 992 ADI_ADISENSE_CORE_Mode_t modeReg;
Dan O'Donovan 27:567abf893938 993 READ_REG_U8(hDevice, modeReg.VALUE8, CORE_MODE);
Dan O'Donovan 27:567abf893938 994
Dan O'Donovan 27:567abf893938 995 if ((eMeasurementMode == ADI_SENSE_MEASUREMENT_MODE_HEALTHCHECK) ||
Dan O'Donovan 27:567abf893938 996 (modeReg.Conversion_Mode == ADISENSE_CORE_MODE_SINGLECYCLE))
Dan O'Donovan 27:567abf893938 997 *peOperatingMode = ADI_SENSE_1000_OPERATING_MODE_SINGLECYCLE;
Dan O'Donovan 27:567abf893938 998 else if (modeReg.Conversion_Mode == ADISENSE_CORE_MODE_MULTICYCLE)
Dan O'Donovan 27:567abf893938 999 *peOperatingMode = ADI_SENSE_1000_OPERATING_MODE_MULTICYCLE;
Dan O'Donovan 27:567abf893938 1000 else
Dan O'Donovan 27:567abf893938 1001 *peOperatingMode = ADI_SENSE_1000_OPERATING_MODE_CONTINUOUS;
Dan O'Donovan 27:567abf893938 1002
Dan O'Donovan 27:567abf893938 1003
Dan O'Donovan 27:567abf893938 1004 /* FFT mode is quite different to the other modes:
Dan O'Donovan 27:567abf893938 1005 * - Each FFT result produces a batch of samples
Dan O'Donovan 27:567abf893938 1006 * - The size of the batch depends on selected FFT size and output config options
Dan O'Donovan 27:567abf893938 1007 * - DATAREADY will fire for each FFT result (once per channel)
Dan O'Donovan 27:567abf893938 1008 * - The size of the cycle depends on the number of channels enabled for FFT
Dan O'Donovan 27:567abf893938 1009 */
Dan O'Donovan 27:567abf893938 1010 if (eMeasurementMode == ADI_SENSE_MEASUREMENT_MODE_FFT)
Dan O'Donovan 27:567abf893938 1011 {
Dan O'Donovan 27:567abf893938 1012 ADI_ADISENSE_CORE_FFT_Config_t fftConfigReg;
Dan O'Donovan 27:567abf893938 1013
Dan O'Donovan 27:567abf893938 1014 unsigned nFftChannels;
Dan O'Donovan 27:567abf893938 1015 unsigned nSamplesPerChannel;
Dan O'Donovan 27:567abf893938 1016
Dan O'Donovan 27:567abf893938 1017 READ_REG_U32(hDevice, fftConfigReg.VALUE32, CORE_FFT_CONFIG);
Dan O'Donovan 27:567abf893938 1018
Dan O'Donovan 27:567abf893938 1019 nFftChannels = fftConfigReg.FFT_Num_Channels + 1;
Dan O'Donovan 27:567abf893938 1020
Dan O'Donovan 27:567abf893938 1021 if (fftConfigReg.FFT_Output == ADISENSE_CORE_FFT_CONFIG_FFT_OUTPUT_MAX16)
Dan O'Donovan 27:567abf893938 1022 {
Dan O'Donovan 27:567abf893938 1023 nSamplesPerChannel = 16;
Dan O'Donovan 27:567abf893938 1024 *pnBytesPerSample = 8;
Dan O'Donovan 27:567abf893938 1025 }
Dan O'Donovan 27:567abf893938 1026 else if (fftConfigReg.FFT_Output == ADISENSE_CORE_FFT_CONFIG_FFT_OUTPUT_FULL)
Dan O'Donovan 27:567abf893938 1027 {
Dan O'Donovan 27:567abf893938 1028 nSamplesPerChannel = (256 << fftConfigReg.FFT_Num_Bins) >> 1;
Dan O'Donovan 27:567abf893938 1029 *pnBytesPerSample = 5;
Dan O'Donovan 27:567abf893938 1030 }
Dan O'Donovan 27:567abf893938 1031 else if (fftConfigReg.FFT_Output == ADISENSE_CORE_FFT_CONFIG_FFT_OUTPUT_FULL_WITH_RAW)
Dan O'Donovan 27:567abf893938 1032 {
Dan O'Donovan 27:567abf893938 1033 nSamplesPerChannel = (256 << fftConfigReg.FFT_Num_Bins);
Dan O'Donovan 27:567abf893938 1034 *pnBytesPerSample = 8;
Dan O'Donovan 27:567abf893938 1035 }
Dan O'Donovan 27:567abf893938 1036 else
Dan O'Donovan 27:567abf893938 1037 {
Dan O'Donovan 27:567abf893938 1038 ADI_SENSE_LOG_ERROR("Invalid FFT output format option %d configured",
Dan O'Donovan 27:567abf893938 1039 fftConfigReg.FFT_Output);
Dan O'Donovan 27:567abf893938 1040 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 1041 }
Dan O'Donovan 27:567abf893938 1042
Dan O'Donovan 27:567abf893938 1043 *pnSamplesPerDataready = nSamplesPerChannel;
Dan O'Donovan 27:567abf893938 1044 *pnSamplesPerCycle = nSamplesPerChannel * nFftChannels;
Dan O'Donovan 27:567abf893938 1045
Dan O'Donovan 27:567abf893938 1046 *peDataReadyMode = ADI_SENSE_1000_DATAREADY_PER_CYCLE;
Dan O'Donovan 30:119ff4f3aef6 1047
Dan O'Donovan 30:119ff4f3aef6 1048 if (modeReg.FFT_Mode == ADISENSE_CORE_MODE_FFT_MODE_CONTINUOUS)
Dan O'Donovan 30:119ff4f3aef6 1049 {
Dan O'Donovan 30:119ff4f3aef6 1050 *peOperatingMode = ADI_SENSE_1000_OPERATING_MODE_CONTINUOUS;
Dan O'Donovan 30:119ff4f3aef6 1051 }
Dan O'Donovan 30:119ff4f3aef6 1052 else
Dan O'Donovan 30:119ff4f3aef6 1053 {
Dan O'Donovan 30:119ff4f3aef6 1054 *peOperatingMode = ADI_SENSE_1000_OPERATING_MODE_SINGLECYCLE;
Dan O'Donovan 30:119ff4f3aef6 1055 }
Dan O'Donovan 27:567abf893938 1056 }
Dan O'Donovan 27:567abf893938 1057 else
Dan O'Donovan 27:567abf893938 1058 {
Dan O'Donovan 27:567abf893938 1059 if (eMeasurementMode == ADI_SENSE_MEASUREMENT_MODE_OMIT_RAW)
Dan O'Donovan 27:567abf893938 1060 {
Dan O'Donovan 27:567abf893938 1061 *pnBytesPerSample = 5;
Dan O'Donovan 27:567abf893938 1062 }
Dan O'Donovan 27:567abf893938 1063 else
Dan O'Donovan 27:567abf893938 1064 {
Dan O'Donovan 27:567abf893938 1065 *pnBytesPerSample = 8;
Dan O'Donovan 27:567abf893938 1066 }
Dan O'Donovan 27:567abf893938 1067
Dan O'Donovan 27:567abf893938 1068 for (ADI_SENSE_1000_CHANNEL_ID chId = ADI_SENSE_1000_CHANNEL_ID_CJC_0;
Dan O'Donovan 27:567abf893938 1069 chId < ADI_SENSE_1000_MAX_CHANNELS;
Dan O'Donovan 27:567abf893938 1070 chId++)
Dan O'Donovan 27:567abf893938 1071 {
Dan O'Donovan 27:567abf893938 1072 ADI_ADISENSE_CORE_Sensor_Details_t sensorDetailsReg;
Dan O'Donovan 27:567abf893938 1073 ADI_ADISENSE_CORE_Channel_Count_t channelCountReg;
Dan O'Donovan 27:567abf893938 1074
Dan O'Donovan 27:567abf893938 1075 if (ADI_SENSE_1000_CHANNEL_IS_VIRTUAL(chId))
Dan O'Donovan 27:567abf893938 1076 continue;
Dan O'Donovan 27:567abf893938 1077
Dan O'Donovan 27:567abf893938 1078 READ_REG_U8(hDevice, channelCountReg.VALUE8, CORE_CHANNEL_COUNTn(chId));
Dan O'Donovan 27:567abf893938 1079 READ_REG_U32(hDevice, sensorDetailsReg.VALUE32, CORE_SENSOR_DETAILSn(chId));
Dan O'Donovan 27:567abf893938 1080
Dan O'Donovan 27:567abf893938 1081 if (channelCountReg.Channel_Enable && !sensorDetailsReg.Do_Not_Publish)
Dan O'Donovan 27:567abf893938 1082 {
Dan O'Donovan 27:567abf893938 1083 ADI_ADISENSE_CORE_Sensor_Type_t sensorTypeReg;
Dan O'Donovan 27:567abf893938 1084 unsigned nActualChannels = 1;
Dan O'Donovan 27:567abf893938 1085
Dan O'Donovan 27:567abf893938 1086 READ_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(chId));
Dan O'Donovan 27:567abf893938 1087
Dan O'Donovan 27:567abf893938 1088 if (chId == ADI_SENSE_1000_CHANNEL_ID_SPI_0)
Dan O'Donovan 27:567abf893938 1089 {
Dan O'Donovan 27:567abf893938 1090 /* Some sensors automatically generate samples on additional "virtual" channels
Dan O'Donovan 27:567abf893938 1091 * so these channels must be counted as active when those sensors are selected
Dan O'Donovan 27:567abf893938 1092 * and we use the count from the corresponding "physical" channel */
kevin1990 29:57edca10d78c 1093 if ((sensorTypeReg.Sensor_Type >=
kevin1990 29:57edca10d78c 1094 ADISENSE_CORE_SENSOR_TYPE_SENSOR_SPI_ACCELEROMETER_A_DEF_L1) &&
kevin1990 29:57edca10d78c 1095 (sensorTypeReg.Sensor_Type <=
kevin1990 29:57edca10d78c 1096 ADISENSE_CORE_SENSOR_TYPE_SENSOR_SPI_ACCELEROMETER_B_ADV_L2))
Dan O'Donovan 27:567abf893938 1097 nActualChannels += 2;
Dan O'Donovan 27:567abf893938 1098 }
Dan O'Donovan 27:567abf893938 1099
Dan O'Donovan 27:567abf893938 1100 nChannelsEnabled += nActualChannels;
Dan O'Donovan 27:567abf893938 1101 if (eMeasurementMode == ADI_SENSE_MEASUREMENT_MODE_HEALTHCHECK)
Dan O'Donovan 27:567abf893938 1102 /* Assume a single sample per channel in test mode */
Dan O'Donovan 27:567abf893938 1103 nSamplesPerCycle += nActualChannels;
Dan O'Donovan 27:567abf893938 1104 else
Dan O'Donovan 27:567abf893938 1105 nSamplesPerCycle += nActualChannels *
Dan O'Donovan 27:567abf893938 1106 (channelCountReg.Channel_Count + 1);
Dan O'Donovan 27:567abf893938 1107 }
Dan O'Donovan 27:567abf893938 1108 }
Dan O'Donovan 27:567abf893938 1109
Dan O'Donovan 27:567abf893938 1110 if (nChannelsEnabled == 0)
Dan O'Donovan 27:567abf893938 1111 {
Dan O'Donovan 27:567abf893938 1112 *pnSamplesPerDataready = 0;
Dan O'Donovan 27:567abf893938 1113 *pnSamplesPerCycle = 0;
Dan O'Donovan 27:567abf893938 1114 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 1115 }
Dan O'Donovan 27:567abf893938 1116
Dan O'Donovan 27:567abf893938 1117 *pnSamplesPerCycle = nSamplesPerCycle;
Dan O'Donovan 27:567abf893938 1118
Dan O'Donovan 27:567abf893938 1119 if (modeReg.Drdy_Mode == ADISENSE_CORE_MODE_DRDY_PER_CONVERSION)
Dan O'Donovan 27:567abf893938 1120 {
Dan O'Donovan 27:567abf893938 1121 *pnSamplesPerDataready = 1;
Dan O'Donovan 27:567abf893938 1122 }
Dan O'Donovan 27:567abf893938 1123 else if (modeReg.Drdy_Mode == ADISENSE_CORE_MODE_DRDY_PER_CYCLE)
Dan O'Donovan 27:567abf893938 1124 {
Dan O'Donovan 27:567abf893938 1125 *pnSamplesPerDataready = nSamplesPerCycle;
Dan O'Donovan 27:567abf893938 1126 }
Dan O'Donovan 27:567abf893938 1127 else
Dan O'Donovan 27:567abf893938 1128 {
Dan O'Donovan 27:567abf893938 1129 /* Assume DRDY will be asserted after max. 1 cycle in test mode */
Dan O'Donovan 27:567abf893938 1130 if (eMeasurementMode == ADI_SENSE_MEASUREMENT_MODE_HEALTHCHECK)
Dan O'Donovan 27:567abf893938 1131 {
Dan O'Donovan 27:567abf893938 1132 *pnSamplesPerDataready = nSamplesPerCycle;
Dan O'Donovan 27:567abf893938 1133 }
Dan O'Donovan 27:567abf893938 1134 else
Dan O'Donovan 27:567abf893938 1135 {
Dan O'Donovan 27:567abf893938 1136 ADI_ADISENSE_CORE_Fifo_Num_Cycles_t fifoNumCyclesReg;
Dan O'Donovan 27:567abf893938 1137 READ_REG_U8(hDevice, fifoNumCyclesReg.VALUE8, CORE_FIFO_NUM_CYCLES);
Dan O'Donovan 27:567abf893938 1138
Dan O'Donovan 27:567abf893938 1139 *pnSamplesPerDataready =
Dan O'Donovan 27:567abf893938 1140 nSamplesPerCycle * fifoNumCyclesReg.Fifo_Num_Cycles;
Dan O'Donovan 27:567abf893938 1141 }
Dan O'Donovan 27:567abf893938 1142 }
Dan O'Donovan 27:567abf893938 1143
Dan O'Donovan 27:567abf893938 1144 if (modeReg.Drdy_Mode == ADISENSE_CORE_MODE_DRDY_PER_CONVERSION)
Dan O'Donovan 27:567abf893938 1145 *peDataReadyMode = ADI_SENSE_1000_DATAREADY_PER_CONVERSION;
Dan O'Donovan 27:567abf893938 1146 else if (modeReg.Drdy_Mode == ADISENSE_CORE_MODE_DRDY_PER_CYCLE)
Dan O'Donovan 27:567abf893938 1147 *peDataReadyMode = ADI_SENSE_1000_DATAREADY_PER_CYCLE;
Dan O'Donovan 27:567abf893938 1148 else
Dan O'Donovan 27:567abf893938 1149 {
Dan O'Donovan 27:567abf893938 1150 /* Assume DRDY will be asserted after max. 1 cycle in test mode */
Dan O'Donovan 27:567abf893938 1151 if (eMeasurementMode == ADI_SENSE_MEASUREMENT_MODE_HEALTHCHECK)
Dan O'Donovan 27:567abf893938 1152 *peDataReadyMode = ADI_SENSE_1000_DATAREADY_PER_CYCLE;
Dan O'Donovan 27:567abf893938 1153 else
Dan O'Donovan 27:567abf893938 1154 *peDataReadyMode = ADI_SENSE_1000_DATAREADY_PER_MULTICYCLE_BURST;
Dan O'Donovan 27:567abf893938 1155 }
Dan O'Donovan 27:567abf893938 1156 }
Dan O'Donovan 27:567abf893938 1157
Dan O'Donovan 27:567abf893938 1158 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 1159 }
Dan O'Donovan 27:567abf893938 1160
Dan O'Donovan 27:567abf893938 1161 ADI_SENSE_RESULT adi_sense_GetProductID(
Dan O'Donovan 27:567abf893938 1162 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 1163 ADI_SENSE_PRODUCT_ID *pProductId)
Dan O'Donovan 27:567abf893938 1164 {
Dan O'Donovan 27:567abf893938 1165 ADI_ADISENSE_SPI_Product_ID_L_t productIdLoReg;
Dan O'Donovan 27:567abf893938 1166 ADI_ADISENSE_SPI_Product_ID_H_t productIdHiReg;
Dan O'Donovan 27:567abf893938 1167
Dan O'Donovan 27:567abf893938 1168 READ_REG_U8(hDevice, productIdLoReg.VALUE8, SPI_PRODUCT_ID_L);
Dan O'Donovan 27:567abf893938 1169 READ_REG_U8(hDevice, productIdHiReg.VALUE8, SPI_PRODUCT_ID_H);
Dan O'Donovan 27:567abf893938 1170
Dan O'Donovan 27:567abf893938 1171 *pProductId = (ADI_SENSE_PRODUCT_ID)((productIdHiReg.VALUE8 << 8)
Dan O'Donovan 27:567abf893938 1172 | productIdLoReg.VALUE8);
Dan O'Donovan 27:567abf893938 1173 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 1174 }
Dan O'Donovan 27:567abf893938 1175
Dan O'Donovan 27:567abf893938 1176 static ADI_SENSE_RESULT adi_sense_SetPowerMode(
Dan O'Donovan 27:567abf893938 1177 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 1178 ADI_SENSE_1000_POWER_MODE powerMode)
Dan O'Donovan 27:567abf893938 1179 {
Dan O'Donovan 27:567abf893938 1180 ADI_ADISENSE_CORE_Power_Config_t powerConfigReg;
Dan O'Donovan 27:567abf893938 1181
Dan O'Donovan 27:567abf893938 1182 if (powerMode == ADI_SENSE_1000_POWER_MODE_LOW)
Dan O'Donovan 27:567abf893938 1183 {
Dan O'Donovan 27:567abf893938 1184 powerConfigReg.Power_Mode_ADC = ADISENSE_CORE_POWER_CONFIG_ADC_LOW_POWER;
Dan O'Donovan 27:567abf893938 1185 }
Dan O'Donovan 27:567abf893938 1186 else if (powerMode == ADI_SENSE_1000_POWER_MODE_MID)
Dan O'Donovan 27:567abf893938 1187 {
Dan O'Donovan 27:567abf893938 1188 powerConfigReg.Power_Mode_ADC = ADISENSE_CORE_POWER_CONFIG_ADC_MID_POWER;
Dan O'Donovan 27:567abf893938 1189 }
Dan O'Donovan 27:567abf893938 1190 else if (powerMode == ADI_SENSE_1000_POWER_MODE_FULL)
Dan O'Donovan 27:567abf893938 1191 {
Dan O'Donovan 27:567abf893938 1192 powerConfigReg.Power_Mode_ADC = ADISENSE_CORE_POWER_CONFIG_ADC_FULL_POWER;
Dan O'Donovan 27:567abf893938 1193 }
Dan O'Donovan 27:567abf893938 1194 else
Dan O'Donovan 27:567abf893938 1195 {
Dan O'Donovan 27:567abf893938 1196 ADI_SENSE_LOG_ERROR("Invalid power mode %d specified", powerMode);
Dan O'Donovan 27:567abf893938 1197 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 1198 }
Dan O'Donovan 27:567abf893938 1199
Dan O'Donovan 27:567abf893938 1200 WRITE_REG_U8(hDevice, powerConfigReg.VALUE8, CORE_POWER_CONFIG);
Dan O'Donovan 27:567abf893938 1201
Dan O'Donovan 27:567abf893938 1202 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 1203 }
Dan O'Donovan 27:567abf893938 1204
Dan O'Donovan 27:567abf893938 1205 ADI_SENSE_RESULT adi_sense_1000_SetPowerConfig(
Dan O'Donovan 27:567abf893938 1206 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 1207 ADI_SENSE_1000_POWER_CONFIG *pPowerConfig)
Dan O'Donovan 27:567abf893938 1208 {
Dan O'Donovan 27:567abf893938 1209 ADI_SENSE_RESULT eRet;
Dan O'Donovan 27:567abf893938 1210
Dan O'Donovan 27:567abf893938 1211 eRet = adi_sense_SetPowerMode(hDevice, pPowerConfig->powerMode);
Dan O'Donovan 27:567abf893938 1212 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 1213 {
Dan O'Donovan 27:567abf893938 1214 ADI_SENSE_LOG_ERROR("Failed to set power mode");
Dan O'Donovan 27:567abf893938 1215 return eRet;
Dan O'Donovan 27:567abf893938 1216 }
Dan O'Donovan 27:567abf893938 1217
Dan O'Donovan 27:567abf893938 1218 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 1219 }
Dan O'Donovan 27:567abf893938 1220
Dan O'Donovan 27:567abf893938 1221 static ADI_SENSE_RESULT adi_sense_SetMode(
Dan O'Donovan 27:567abf893938 1222 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 1223 ADI_SENSE_1000_OPERATING_MODE eOperatingMode,
kevin1990 29:57edca10d78c 1224 ADI_SENSE_1000_DATAREADY_MODE eDataReadyMode,
kevin1990 29:57edca10d78c 1225 ADI_SENSE_1000_CALIBRATION_MODE eCalibrationMode,
kevin1990 29:57edca10d78c 1226 bool bEnableExtFlash)
Dan O'Donovan 27:567abf893938 1227 {
Dan O'Donovan 27:567abf893938 1228 ADI_ADISENSE_CORE_Mode_t modeReg;
Dan O'Donovan 27:567abf893938 1229
Dan O'Donovan 27:567abf893938 1230 modeReg.VALUE8 = REG_RESET_VAL(CORE_MODE);
Dan O'Donovan 27:567abf893938 1231
Dan O'Donovan 27:567abf893938 1232 if (eOperatingMode == ADI_SENSE_1000_OPERATING_MODE_SINGLECYCLE)
Dan O'Donovan 27:567abf893938 1233 {
Dan O'Donovan 27:567abf893938 1234 modeReg.Conversion_Mode = ADISENSE_CORE_MODE_SINGLECYCLE;
Dan O'Donovan 27:567abf893938 1235 }
Dan O'Donovan 27:567abf893938 1236 else if (eOperatingMode == ADI_SENSE_1000_OPERATING_MODE_CONTINUOUS)
Dan O'Donovan 27:567abf893938 1237 {
Dan O'Donovan 27:567abf893938 1238 modeReg.Conversion_Mode = ADISENSE_CORE_MODE_CONTINUOUS;
Dan O'Donovan 27:567abf893938 1239 }
Dan O'Donovan 27:567abf893938 1240 else if (eOperatingMode == ADI_SENSE_1000_OPERATING_MODE_MULTICYCLE)
Dan O'Donovan 27:567abf893938 1241 {
Dan O'Donovan 27:567abf893938 1242 modeReg.Conversion_Mode = ADISENSE_CORE_MODE_MULTICYCLE;
Dan O'Donovan 27:567abf893938 1243 }
Dan O'Donovan 27:567abf893938 1244 else
Dan O'Donovan 27:567abf893938 1245 {
Dan O'Donovan 27:567abf893938 1246 ADI_SENSE_LOG_ERROR("Invalid operating mode %d specified",
Dan O'Donovan 27:567abf893938 1247 eOperatingMode);
Dan O'Donovan 27:567abf893938 1248 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 1249 }
Dan O'Donovan 27:567abf893938 1250
Dan O'Donovan 27:567abf893938 1251 if (eDataReadyMode == ADI_SENSE_1000_DATAREADY_PER_CONVERSION)
Dan O'Donovan 27:567abf893938 1252 {
Dan O'Donovan 27:567abf893938 1253 modeReg.Drdy_Mode = ADISENSE_CORE_MODE_DRDY_PER_CONVERSION;
Dan O'Donovan 27:567abf893938 1254 }
Dan O'Donovan 27:567abf893938 1255 else if (eDataReadyMode == ADI_SENSE_1000_DATAREADY_PER_CYCLE)
Dan O'Donovan 27:567abf893938 1256 {
Dan O'Donovan 27:567abf893938 1257 modeReg.Drdy_Mode = ADISENSE_CORE_MODE_DRDY_PER_CYCLE;
Dan O'Donovan 27:567abf893938 1258 }
Dan O'Donovan 27:567abf893938 1259 else if (eDataReadyMode == ADI_SENSE_1000_DATAREADY_PER_MULTICYCLE_BURST)
Dan O'Donovan 27:567abf893938 1260 {
Dan O'Donovan 27:567abf893938 1261 if (eOperatingMode != ADI_SENSE_1000_OPERATING_MODE_MULTICYCLE)
Dan O'Donovan 27:567abf893938 1262 {
Dan O'Donovan 27:567abf893938 1263 ADI_SENSE_LOG_ERROR(
Dan O'Donovan 27:567abf893938 1264 "Data-ready mode %d cannot be used with operating mode %d",
Dan O'Donovan 27:567abf893938 1265 eDataReadyMode, eOperatingMode);
Dan O'Donovan 27:567abf893938 1266 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 1267 }
Dan O'Donovan 27:567abf893938 1268 else
Dan O'Donovan 27:567abf893938 1269 {
Dan O'Donovan 27:567abf893938 1270 modeReg.Drdy_Mode = ADISENSE_CORE_MODE_DRDY_PER_FIFO_FILL;
Dan O'Donovan 27:567abf893938 1271 }
Dan O'Donovan 27:567abf893938 1272 }
Dan O'Donovan 27:567abf893938 1273 else
Dan O'Donovan 27:567abf893938 1274 {
Dan O'Donovan 27:567abf893938 1275 ADI_SENSE_LOG_ERROR("Invalid data-ready mode %d specified", eDataReadyMode);
Dan O'Donovan 27:567abf893938 1276 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 1277 }
Dan O'Donovan 27:567abf893938 1278
kevin1990 29:57edca10d78c 1279 if (eCalibrationMode == ADI_SENSE_1000_NO_CALIBRATION)
kevin1990 29:57edca10d78c 1280 {
kevin1990 29:57edca10d78c 1281 modeReg.Calibration_Method = ADISENSE_CORE_MODE_NO_CAL;
kevin1990 29:57edca10d78c 1282 }
kevin1990 29:57edca10d78c 1283 else if (eCalibrationMode == ADI_SENSE_1000_DO_CALIBRATION)
kevin1990 29:57edca10d78c 1284 {
kevin1990 29:57edca10d78c 1285 modeReg.Calibration_Method = ADISENSE_CORE_MODE_DO_CAL;
kevin1990 29:57edca10d78c 1286 }
kevin1990 29:57edca10d78c 1287 else
kevin1990 29:57edca10d78c 1288 {
kevin1990 29:57edca10d78c 1289 ADI_SENSE_LOG_ERROR("Invalid calibration mode %d specified",
kevin1990 29:57edca10d78c 1290 eCalibrationMode);
kevin1990 29:57edca10d78c 1291 return ADI_SENSE_INVALID_PARAM;
kevin1990 29:57edca10d78c 1292 }
kevin1990 29:57edca10d78c 1293
kevin1990 29:57edca10d78c 1294 modeReg.Ext_Flash_Store = (bEnableExtFlash ?
kevin1990 29:57edca10d78c 1295 ADISENSE_CORE_MODE_EXT_FLASH_USED :
kevin1990 29:57edca10d78c 1296 ADISENSE_CORE_MODE_EXT_FLASH_NOT_USED);
kevin1990 29:57edca10d78c 1297
Dan O'Donovan 27:567abf893938 1298 WRITE_REG_U8(hDevice, modeReg.VALUE8, CORE_MODE);
Dan O'Donovan 27:567abf893938 1299
Dan O'Donovan 27:567abf893938 1300 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 1301 }
Dan O'Donovan 27:567abf893938 1302
Dan O'Donovan 27:567abf893938 1303 ADI_SENSE_RESULT adi_sense_SetCycleControl(
Dan O'Donovan 27:567abf893938 1304 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 1305 uint32_t nCycleInterval,
Dan O'Donovan 27:567abf893938 1306 ADI_SENSE_1000_CYCLE_TYPE eCycleType)
Dan O'Donovan 27:567abf893938 1307 {
Dan O'Donovan 27:567abf893938 1308 ADI_ADISENSE_CORE_Cycle_Control_t cycleControlReg;
Dan O'Donovan 27:567abf893938 1309
Dan O'Donovan 27:567abf893938 1310 cycleControlReg.VALUE16 = REG_RESET_VAL(CORE_CYCLE_CONTROL);
Dan O'Donovan 27:567abf893938 1311
Dan O'Donovan 27:567abf893938 1312 if (nCycleInterval < (1 << 12))
Dan O'Donovan 27:567abf893938 1313 {
Dan O'Donovan 27:567abf893938 1314 cycleControlReg.Cycle_Time_Units = ADISENSE_CORE_CYCLE_CONTROL_MICROSECONDS;
Dan O'Donovan 27:567abf893938 1315 }
Dan O'Donovan 27:567abf893938 1316 else if (nCycleInterval < (1000 * (1 << 12)))
Dan O'Donovan 27:567abf893938 1317 {
Dan O'Donovan 27:567abf893938 1318 cycleControlReg.Cycle_Time_Units = ADISENSE_CORE_CYCLE_CONTROL_MILLISECONDS;
Dan O'Donovan 27:567abf893938 1319 nCycleInterval /= 1000;
Dan O'Donovan 27:567abf893938 1320 }
Dan O'Donovan 27:567abf893938 1321 else
Dan O'Donovan 27:567abf893938 1322 {
Dan O'Donovan 27:567abf893938 1323 cycleControlReg.Cycle_Time_Units = ADISENSE_CORE_CYCLE_CONTROL_SECONDS;
Dan O'Donovan 27:567abf893938 1324 nCycleInterval /= 1000000;
Dan O'Donovan 27:567abf893938 1325 }
Dan O'Donovan 27:567abf893938 1326
Dan O'Donovan 27:567abf893938 1327 CHECK_REG_FIELD_VAL(CORE_CYCLE_CONTROL_CYCLE_TIME, nCycleInterval);
Dan O'Donovan 27:567abf893938 1328 cycleControlReg.Cycle_Time = nCycleInterval;
Dan O'Donovan 27:567abf893938 1329
Dan O'Donovan 27:567abf893938 1330 if (eCycleType == ADI_SENSE_1000_CYCLE_TYPE_SWITCH)
Dan O'Donovan 27:567abf893938 1331 {
Dan O'Donovan 27:567abf893938 1332 cycleControlReg.Cycle_Type = ADISENSE_CORE_CYCLE_CONTROL_CYCLE_TYPE_SWITCH;
Dan O'Donovan 27:567abf893938 1333 }
Dan O'Donovan 27:567abf893938 1334 else if (eCycleType == ADI_SENSE_1000_CYCLE_TYPE_FULL)
Dan O'Donovan 27:567abf893938 1335 {
Dan O'Donovan 27:567abf893938 1336 cycleControlReg.Cycle_Type = ADISENSE_CORE_CYCLE_CONTROL_CYCLE_TYPE_FULL;
Dan O'Donovan 27:567abf893938 1337 }
Dan O'Donovan 27:567abf893938 1338 else
Dan O'Donovan 27:567abf893938 1339 {
Dan O'Donovan 27:567abf893938 1340 ADI_SENSE_LOG_ERROR("Invalid cycle type %d specified", eCycleType);
Dan O'Donovan 27:567abf893938 1341 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 1342 }
Dan O'Donovan 27:567abf893938 1343
Dan O'Donovan 27:567abf893938 1344 WRITE_REG_U16(hDevice, cycleControlReg.VALUE16, CORE_CYCLE_CONTROL);
Dan O'Donovan 27:567abf893938 1345
Dan O'Donovan 27:567abf893938 1346 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 1347 }
Dan O'Donovan 27:567abf893938 1348
Dan O'Donovan 27:567abf893938 1349 static ADI_SENSE_RESULT adi_sense_SetMultiCycleConfig(
Dan O'Donovan 27:567abf893938 1350 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 1351 ADI_SENSE_1000_MULTICYCLE_CONFIG *pMultiCycleConfig)
Dan O'Donovan 27:567abf893938 1352 {
Dan O'Donovan 27:567abf893938 1353 CHECK_REG_FIELD_VAL(CORE_FIFO_NUM_CYCLES_FIFO_NUM_CYCLES,
Dan O'Donovan 27:567abf893938 1354 pMultiCycleConfig->cyclesPerBurst);
Dan O'Donovan 27:567abf893938 1355
Dan O'Donovan 27:567abf893938 1356 WRITE_REG_U8(hDevice, pMultiCycleConfig->cyclesPerBurst,
Dan O'Donovan 27:567abf893938 1357 CORE_FIFO_NUM_CYCLES);
Dan O'Donovan 27:567abf893938 1358
Dan O'Donovan 27:567abf893938 1359 WRITE_REG_U32(hDevice, pMultiCycleConfig->burstInterval,
Dan O'Donovan 27:567abf893938 1360 CORE_MULTI_CYCLE_REPEAT_INTERVAL);
Dan O'Donovan 27:567abf893938 1361
Dan O'Donovan 27:567abf893938 1362 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 1363 }
Dan O'Donovan 27:567abf893938 1364
Dan O'Donovan 27:567abf893938 1365 static ADI_SENSE_RESULT adi_sense_SetExternalReferenceValues(
Dan O'Donovan 27:567abf893938 1366 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 1367 float32_t externalRef1Value,
Dan O'Donovan 27:567abf893938 1368 float32_t externalRef2Value)
Dan O'Donovan 27:567abf893938 1369 {
Dan O'Donovan 27:567abf893938 1370 WRITE_REG_FLOAT(hDevice, externalRef1Value, CORE_EXTERNAL_REFERENCE1);
Dan O'Donovan 27:567abf893938 1371 WRITE_REG_FLOAT(hDevice, externalRef2Value, CORE_EXTERNAL_REFERENCE2);
Dan O'Donovan 27:567abf893938 1372
Dan O'Donovan 27:567abf893938 1373 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 1374 }
Dan O'Donovan 27:567abf893938 1375
Dan O'Donovan 27:567abf893938 1376 ADI_SENSE_RESULT adi_sense_1000_SetMeasurementConfig(
Dan O'Donovan 27:567abf893938 1377 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 1378 ADI_SENSE_1000_MEASUREMENT_CONFIG *pMeasConfig)
Dan O'Donovan 27:567abf893938 1379 {
Dan O'Donovan 27:567abf893938 1380 ADI_SENSE_RESULT eRet;
Dan O'Donovan 27:567abf893938 1381
Dan O'Donovan 27:567abf893938 1382 eRet = adi_sense_SetMode(hDevice,
Dan O'Donovan 27:567abf893938 1383 pMeasConfig->operatingMode,
kevin1990 29:57edca10d78c 1384 pMeasConfig->dataReadyMode,
kevin1990 29:57edca10d78c 1385 pMeasConfig->calibrationMode,
kevin1990 29:57edca10d78c 1386 pMeasConfig->enableExternalFlash);
Dan O'Donovan 27:567abf893938 1387 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 1388 {
Dan O'Donovan 27:567abf893938 1389 ADI_SENSE_LOG_ERROR("Failed to set operating mode");
Dan O'Donovan 27:567abf893938 1390 return eRet;
Dan O'Donovan 27:567abf893938 1391 }
Dan O'Donovan 27:567abf893938 1392
Dan O'Donovan 27:567abf893938 1393 eRet = adi_sense_SetCycleControl(hDevice,
Dan O'Donovan 27:567abf893938 1394 pMeasConfig->cycleInterval,
Dan O'Donovan 27:567abf893938 1395 pMeasConfig->cycleType);
Dan O'Donovan 27:567abf893938 1396 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 1397 {
Dan O'Donovan 27:567abf893938 1398 ADI_SENSE_LOG_ERROR("Failed to set cycle control");
Dan O'Donovan 27:567abf893938 1399 return eRet;
Dan O'Donovan 27:567abf893938 1400 }
Dan O'Donovan 27:567abf893938 1401
Dan O'Donovan 27:567abf893938 1402 if (pMeasConfig->operatingMode == ADI_SENSE_1000_OPERATING_MODE_MULTICYCLE)
Dan O'Donovan 27:567abf893938 1403 {
Dan O'Donovan 27:567abf893938 1404 eRet = adi_sense_SetMultiCycleConfig(hDevice,
Dan O'Donovan 27:567abf893938 1405 &pMeasConfig->multiCycleConfig);
Dan O'Donovan 27:567abf893938 1406 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 1407 {
Dan O'Donovan 27:567abf893938 1408 ADI_SENSE_LOG_ERROR("Failed to set multi-cycle configuration");
Dan O'Donovan 27:567abf893938 1409 return eRet;
Dan O'Donovan 27:567abf893938 1410 }
Dan O'Donovan 27:567abf893938 1411 }
Dan O'Donovan 27:567abf893938 1412
Dan O'Donovan 27:567abf893938 1413 eRet = adi_sense_SetExternalReferenceValues(hDevice,
Dan O'Donovan 27:567abf893938 1414 pMeasConfig->externalRef1Value,
Dan O'Donovan 27:567abf893938 1415 pMeasConfig->externalRef2Value);
Dan O'Donovan 27:567abf893938 1416 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 1417 {
Dan O'Donovan 27:567abf893938 1418 ADI_SENSE_LOG_ERROR("Failed to set external reference values");
Dan O'Donovan 27:567abf893938 1419 return eRet;
Dan O'Donovan 27:567abf893938 1420 }
Dan O'Donovan 27:567abf893938 1421
Dan O'Donovan 27:567abf893938 1422 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 1423 }
Dan O'Donovan 27:567abf893938 1424
Dan O'Donovan 27:567abf893938 1425 ADI_SENSE_RESULT adi_sense_1000_SetDiagnosticsConfig(
Dan O'Donovan 27:567abf893938 1426 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 1427 ADI_SENSE_1000_DIAGNOSTICS_CONFIG *pDiagnosticsConfig)
Dan O'Donovan 27:567abf893938 1428 {
Dan O'Donovan 27:567abf893938 1429 ADI_ADISENSE_CORE_Diagnostics_Control_t diagnosticsControlReg;
Dan O'Donovan 27:567abf893938 1430
Dan O'Donovan 27:567abf893938 1431 diagnosticsControlReg.VALUE16 = REG_RESET_VAL(CORE_DIAGNOSTICS_CONTROL);
Dan O'Donovan 27:567abf893938 1432
Dan O'Donovan 27:567abf893938 1433 if (pDiagnosticsConfig->disableGlobalDiag)
Dan O'Donovan 27:567abf893938 1434 diagnosticsControlReg.Diag_Global_En = 0;
Dan O'Donovan 27:567abf893938 1435 else
Dan O'Donovan 27:567abf893938 1436 diagnosticsControlReg.Diag_Global_En = 1;
Dan O'Donovan 27:567abf893938 1437
Dan O'Donovan 27:567abf893938 1438 if (pDiagnosticsConfig->disableMeasurementDiag)
Dan O'Donovan 27:567abf893938 1439 diagnosticsControlReg.Diag_Meas_En = 0;
Dan O'Donovan 27:567abf893938 1440 else
Dan O'Donovan 27:567abf893938 1441 diagnosticsControlReg.Diag_Meas_En = 1;
Dan O'Donovan 27:567abf893938 1442
Dan O'Donovan 27:567abf893938 1443 switch (pDiagnosticsConfig->osdFrequency)
Dan O'Donovan 27:567abf893938 1444 {
Dan O'Donovan 27:567abf893938 1445 case ADI_SENSE_1000_OPEN_SENSOR_DIAGNOSTICS_DISABLED:
Dan O'Donovan 27:567abf893938 1446 diagnosticsControlReg.Diag_OSD_Freq = ADISENSE_CORE_DIAGNOSTICS_CONTROL_OCD_OFF;
Dan O'Donovan 27:567abf893938 1447 break;
Dan O'Donovan 27:567abf893938 1448 case ADI_SENSE_1000_OPEN_SENSOR_DIAGNOSTICS_PER_CYCLE:
Dan O'Donovan 27:567abf893938 1449 diagnosticsControlReg.Diag_OSD_Freq = ADISENSE_CORE_DIAGNOSTICS_CONTROL_OCD_PER_1_CYCLE;
Dan O'Donovan 27:567abf893938 1450 break;
Dan O'Donovan 27:567abf893938 1451 case ADI_SENSE_1000_OPEN_SENSOR_DIAGNOSTICS_PER_100_CYCLES:
Dan O'Donovan 27:567abf893938 1452 diagnosticsControlReg.Diag_OSD_Freq = ADISENSE_CORE_DIAGNOSTICS_CONTROL_OCD_PER_100_CYCLES;
Dan O'Donovan 27:567abf893938 1453 break;
Dan O'Donovan 27:567abf893938 1454 case ADI_SENSE_1000_OPEN_SENSOR_DIAGNOSTICS_PER_1000_CYCLES:
Dan O'Donovan 27:567abf893938 1455 diagnosticsControlReg.Diag_OSD_Freq = ADISENSE_CORE_DIAGNOSTICS_CONTROL_OCD_PER_1000_CYCLES;
Dan O'Donovan 27:567abf893938 1456 break;
Dan O'Donovan 27:567abf893938 1457 default:
Dan O'Donovan 27:567abf893938 1458 ADI_SENSE_LOG_ERROR("Invalid open-sensor diagnostic frequency %d specified",
Dan O'Donovan 27:567abf893938 1459 pDiagnosticsConfig->osdFrequency);
Dan O'Donovan 27:567abf893938 1460 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 1461 }
Dan O'Donovan 27:567abf893938 1462
Dan O'Donovan 27:567abf893938 1463 WRITE_REG_U16(hDevice, diagnosticsControlReg.VALUE16, CORE_DIAGNOSTICS_CONTROL);
Dan O'Donovan 27:567abf893938 1464
Dan O'Donovan 27:567abf893938 1465 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 1466 }
Dan O'Donovan 27:567abf893938 1467
Dan O'Donovan 27:567abf893938 1468 ADI_SENSE_RESULT adi_sense_1000_SetFftConfig(
Dan O'Donovan 27:567abf893938 1469 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 1470 ADI_SENSE_1000_FFT_CONFIG *pFftConfig,
Dan O'Donovan 27:567abf893938 1471 ADI_SENSE_1000_CHANNEL_CONFIG *pChannels)
Dan O'Donovan 27:567abf893938 1472 {
Dan O'Donovan 27:567abf893938 1473 ADI_ADISENSE_CORE_FFT_Config_t fftConfigReg;
Dan O'Donovan 27:567abf893938 1474 ADI_ADISENSE_CORE_Mode_t modeReg;
Dan O'Donovan 27:567abf893938 1475 uint32_t numFftChannels = 0;
Dan O'Donovan 27:567abf893938 1476
Dan O'Donovan 27:567abf893938 1477 fftConfigReg.VALUE32 = REG_RESET_VAL(CORE_FFT_CONFIG);
Dan O'Donovan 27:567abf893938 1478
Dan O'Donovan 27:567abf893938 1479 for (ADI_SENSE_1000_CHANNEL_ID id = ADI_SENSE_1000_CHANNEL_ID_CJC_0;
Dan O'Donovan 27:567abf893938 1480 id < ADI_SENSE_1000_MAX_CHANNELS;
Dan O'Donovan 27:567abf893938 1481 id++)
Dan O'Donovan 27:567abf893938 1482 {
Dan O'Donovan 27:567abf893938 1483 if (pChannels[id].enableFFT)
Dan O'Donovan 27:567abf893938 1484 {
Dan O'Donovan 27:567abf893938 1485 if (numFftChannels >= 4) /* TODO - temporary limit */
Dan O'Donovan 27:567abf893938 1486 {
Dan O'Donovan 27:567abf893938 1487 ADI_SENSE_LOG_ERROR("Maximum limit of 4 FFT channels exceeded");
Dan O'Donovan 27:567abf893938 1488 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 1489 }
Dan O'Donovan 27:567abf893938 1490
Dan O'Donovan 27:567abf893938 1491 numFftChannels++;
Dan O'Donovan 27:567abf893938 1492 }
Dan O'Donovan 27:567abf893938 1493 }
Dan O'Donovan 27:567abf893938 1494
Dan O'Donovan 27:567abf893938 1495 if (numFftChannels > 0)
Dan O'Donovan 27:567abf893938 1496 {
Dan O'Donovan 27:567abf893938 1497 fftConfigReg.FFT_Num_Channels = numFftChannels - 1;
Dan O'Donovan 27:567abf893938 1498
Dan O'Donovan 27:567abf893938 1499 switch (pFftConfig->size)
Dan O'Donovan 27:567abf893938 1500 {
Dan O'Donovan 27:567abf893938 1501 case ADI_SENSE_1000_FFT_SIZE_256:
Dan O'Donovan 27:567abf893938 1502 fftConfigReg.FFT_Num_Bins = ADISENSE_CORE_FFT_CONFIG_FFT_BINS_256;
Dan O'Donovan 27:567abf893938 1503 break;
Dan O'Donovan 27:567abf893938 1504 case ADI_SENSE_1000_FFT_SIZE_512:
Dan O'Donovan 27:567abf893938 1505 fftConfigReg.FFT_Num_Bins = ADISENSE_CORE_FFT_CONFIG_FFT_BINS_512;
Dan O'Donovan 27:567abf893938 1506 break;
Dan O'Donovan 27:567abf893938 1507 case ADI_SENSE_1000_FFT_SIZE_1024:
Dan O'Donovan 27:567abf893938 1508 fftConfigReg.FFT_Num_Bins = ADISENSE_CORE_FFT_CONFIG_FFT_BINS_1024;
Dan O'Donovan 27:567abf893938 1509 break;
Dan O'Donovan 27:567abf893938 1510 case ADI_SENSE_1000_FFT_SIZE_2048:
Dan O'Donovan 27:567abf893938 1511 fftConfigReg.FFT_Num_Bins = ADISENSE_CORE_FFT_CONFIG_FFT_BINS_2048;
Dan O'Donovan 27:567abf893938 1512 break;
Dan O'Donovan 27:567abf893938 1513 default:
Dan O'Donovan 27:567abf893938 1514 ADI_SENSE_LOG_ERROR("Invalid FFT size option %d specified",
Dan O'Donovan 27:567abf893938 1515 pFftConfig->size);
Dan O'Donovan 27:567abf893938 1516 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 1517 }
Dan O'Donovan 27:567abf893938 1518
Dan O'Donovan 27:567abf893938 1519 switch (pFftConfig->window)
Dan O'Donovan 27:567abf893938 1520 {
Dan O'Donovan 27:567abf893938 1521 case ADI_SENSE_1000_FFT_WINDOW_NONE:
Dan O'Donovan 27:567abf893938 1522 fftConfigReg.FFT_Window = ADISENSE_CORE_FFT_CONFIG_FFT_WINDOW_NONE;
Dan O'Donovan 27:567abf893938 1523 break;
Dan O'Donovan 27:567abf893938 1524 case ADI_SENSE_1000_FFT_WINDOW_HANN:
Dan O'Donovan 27:567abf893938 1525 fftConfigReg.FFT_Window = ADISENSE_CORE_FFT_CONFIG_FFT_WINDOW_HANN;
Dan O'Donovan 27:567abf893938 1526 break;
Dan O'Donovan 27:567abf893938 1527 case ADI_SENSE_1000_FFT_WINDOW_BLACKMAN_HARRIS:
Dan O'Donovan 27:567abf893938 1528 fftConfigReg.FFT_Window = ADISENSE_CORE_FFT_CONFIG_FFT_WINDOW_BLACKMANN_HARRIS;
Dan O'Donovan 27:567abf893938 1529 break;
Dan O'Donovan 27:567abf893938 1530 default:
Dan O'Donovan 27:567abf893938 1531 ADI_SENSE_LOG_ERROR("Invalid FFT window option %d specified",
Dan O'Donovan 27:567abf893938 1532 pFftConfig->window);
Dan O'Donovan 27:567abf893938 1533 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 1534 }
Dan O'Donovan 27:567abf893938 1535
Dan O'Donovan 27:567abf893938 1536 switch (pFftConfig->output)
Dan O'Donovan 27:567abf893938 1537 {
Dan O'Donovan 27:567abf893938 1538 case ADI_SENSE_1000_FFT_OUTPUT_FULL:
Dan O'Donovan 27:567abf893938 1539 fftConfigReg.FFT_Output = ADISENSE_CORE_FFT_CONFIG_FFT_OUTPUT_FULL;
Dan O'Donovan 27:567abf893938 1540 break;
Dan O'Donovan 27:567abf893938 1541 case ADI_SENSE_1000_FFT_OUTPUT_MAX16:
Dan O'Donovan 27:567abf893938 1542 fftConfigReg.FFT_Output = ADISENSE_CORE_FFT_CONFIG_FFT_OUTPUT_MAX16;
Dan O'Donovan 27:567abf893938 1543 break;
Dan O'Donovan 27:567abf893938 1544 case ADI_SENSE_1000_FFT_OUTPUT_FULL_WITH_RAW:
Dan O'Donovan 27:567abf893938 1545 fftConfigReg.FFT_Output = ADISENSE_CORE_FFT_CONFIG_FFT_OUTPUT_FULL_WITH_RAW;
Dan O'Donovan 27:567abf893938 1546 break;
Dan O'Donovan 27:567abf893938 1547 default:
Dan O'Donovan 27:567abf893938 1548 ADI_SENSE_LOG_ERROR("Invalid FFT output format option %d specified",
Dan O'Donovan 27:567abf893938 1549 pFftConfig->output);
Dan O'Donovan 27:567abf893938 1550 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 1551 }
Dan O'Donovan 27:567abf893938 1552 }
Dan O'Donovan 27:567abf893938 1553 WRITE_REG_U32(hDevice, fftConfigReg.VALUE32, CORE_FFT_CONFIG);
Dan O'Donovan 27:567abf893938 1554
Dan O'Donovan 27:567abf893938 1555 if (numFftChannels > 0)
Dan O'Donovan 27:567abf893938 1556 {
Dan O'Donovan 27:567abf893938 1557 READ_REG_U8(hDevice, modeReg.VALUE8, CORE_MODE);
Dan O'Donovan 27:567abf893938 1558
Dan O'Donovan 27:567abf893938 1559 if (pFftConfig->mode == ADI_SENSE_1000_FFT_MODE_SINGLE)
Dan O'Donovan 27:567abf893938 1560 {
Dan O'Donovan 27:567abf893938 1561 modeReg.FFT_Mode = ADISENSE_CORE_MODE_FFT_MODE_SINGLE;
Dan O'Donovan 27:567abf893938 1562 }
Dan O'Donovan 27:567abf893938 1563 else if (pFftConfig->mode == ADI_SENSE_1000_FFT_MODE_CONTINUOUS)
Dan O'Donovan 27:567abf893938 1564 {
Dan O'Donovan 27:567abf893938 1565 modeReg.FFT_Mode = ADISENSE_CORE_MODE_FFT_MODE_CONTINUOUS;
Dan O'Donovan 27:567abf893938 1566 }
Dan O'Donovan 27:567abf893938 1567 else
Dan O'Donovan 27:567abf893938 1568 {
Dan O'Donovan 27:567abf893938 1569 ADI_SENSE_LOG_ERROR("Invalid FFT mode %d specified",
Dan O'Donovan 27:567abf893938 1570 pFftConfig->mode);
Dan O'Donovan 27:567abf893938 1571 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 1572 }
Dan O'Donovan 27:567abf893938 1573
Dan O'Donovan 27:567abf893938 1574 WRITE_REG_U8(hDevice, modeReg.VALUE8, CORE_MODE);
Dan O'Donovan 27:567abf893938 1575 }
Dan O'Donovan 27:567abf893938 1576
Dan O'Donovan 27:567abf893938 1577 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 1578 }
Dan O'Donovan 27:567abf893938 1579
Dan O'Donovan 27:567abf893938 1580 ADI_SENSE_RESULT adi_sense_1000_SetChannelCount(
Dan O'Donovan 27:567abf893938 1581 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 1582 ADI_SENSE_1000_CHANNEL_ID eChannelId,
Dan O'Donovan 27:567abf893938 1583 uint32_t nMeasurementsPerCycle)
Dan O'Donovan 27:567abf893938 1584 {
Dan O'Donovan 27:567abf893938 1585 ADI_ADISENSE_CORE_Channel_Count_t channelCountReg;
Dan O'Donovan 27:567abf893938 1586
Dan O'Donovan 27:567abf893938 1587 channelCountReg.VALUE8 = REG_RESET_VAL(CORE_CHANNEL_COUNTn);
Dan O'Donovan 27:567abf893938 1588
Dan O'Donovan 27:567abf893938 1589 if (nMeasurementsPerCycle > 0)
Dan O'Donovan 27:567abf893938 1590 {
Dan O'Donovan 27:567abf893938 1591 nMeasurementsPerCycle -= 1;
Dan O'Donovan 27:567abf893938 1592
Dan O'Donovan 27:567abf893938 1593 CHECK_REG_FIELD_VAL(CORE_CHANNEL_COUNT_CHANNEL_COUNT,
Dan O'Donovan 27:567abf893938 1594 nMeasurementsPerCycle);
Dan O'Donovan 27:567abf893938 1595
Dan O'Donovan 27:567abf893938 1596 channelCountReg.Channel_Enable = 1;
Dan O'Donovan 27:567abf893938 1597 channelCountReg.Channel_Count = nMeasurementsPerCycle;
Dan O'Donovan 27:567abf893938 1598 }
Dan O'Donovan 27:567abf893938 1599 else
Dan O'Donovan 27:567abf893938 1600 {
Dan O'Donovan 27:567abf893938 1601 channelCountReg.Channel_Enable = 0;
Dan O'Donovan 27:567abf893938 1602 }
Dan O'Donovan 27:567abf893938 1603
Dan O'Donovan 27:567abf893938 1604 WRITE_REG_U8(hDevice, channelCountReg.VALUE8, CORE_CHANNEL_COUNTn(eChannelId));
Dan O'Donovan 27:567abf893938 1605
Dan O'Donovan 27:567abf893938 1606 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 1607 }
Dan O'Donovan 27:567abf893938 1608
Dan O'Donovan 27:567abf893938 1609 ADI_SENSE_RESULT adi_sense_1000_SetChannelOptions(
Dan O'Donovan 27:567abf893938 1610 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 1611 ADI_SENSE_1000_CHANNEL_ID eChannelId,
Dan O'Donovan 27:567abf893938 1612 ADI_SENSE_1000_CHANNEL_PRIORITY ePriority,
Dan O'Donovan 27:567abf893938 1613 bool bEnableFft)
Dan O'Donovan 27:567abf893938 1614 {
Dan O'Donovan 27:567abf893938 1615 ADI_ADISENSE_CORE_Channel_Options_t channelOptionsReg;
Dan O'Donovan 27:567abf893938 1616
Dan O'Donovan 27:567abf893938 1617 channelOptionsReg.VALUE8 = REG_RESET_VAL(CORE_CHANNEL_OPTIONSn);
Dan O'Donovan 27:567abf893938 1618
Dan O'Donovan 27:567abf893938 1619 CHECK_REG_FIELD_VAL(CORE_CHANNEL_OPTIONS_CHANNEL_PRIORITY, ePriority);
Dan O'Donovan 27:567abf893938 1620 channelOptionsReg.Channel_Priority = ePriority;
Dan O'Donovan 27:567abf893938 1621 channelOptionsReg.FFT_Enable_Ch = bEnableFft ? 1 : 0;
Dan O'Donovan 27:567abf893938 1622
Dan O'Donovan 27:567abf893938 1623 WRITE_REG_U8(hDevice, channelOptionsReg.VALUE8, CORE_CHANNEL_OPTIONSn(eChannelId));
Dan O'Donovan 27:567abf893938 1624
Dan O'Donovan 27:567abf893938 1625 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 1626 }
Dan O'Donovan 27:567abf893938 1627
Dan O'Donovan 27:567abf893938 1628 ADI_SENSE_RESULT adi_sense_1000_SetChannelSkipCount(
Dan O'Donovan 27:567abf893938 1629 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 1630 ADI_SENSE_1000_CHANNEL_ID eChannelId,
Dan O'Donovan 27:567abf893938 1631 uint32_t nCycleSkipCount)
Dan O'Donovan 27:567abf893938 1632 {
Dan O'Donovan 27:567abf893938 1633 ADI_ADISENSE_CORE_Channel_Skip_t channelSkipReg;
Dan O'Donovan 27:567abf893938 1634
Dan O'Donovan 27:567abf893938 1635 channelSkipReg.VALUE16 = REG_RESET_VAL(CORE_CHANNEL_SKIPn);
Dan O'Donovan 27:567abf893938 1636
Dan O'Donovan 27:567abf893938 1637 CHECK_REG_FIELD_VAL(CORE_CHANNEL_SKIP_CHANNEL_SKIP, nCycleSkipCount);
Dan O'Donovan 27:567abf893938 1638
Dan O'Donovan 27:567abf893938 1639 channelSkipReg.Channel_Skip = nCycleSkipCount;
Dan O'Donovan 27:567abf893938 1640
Dan O'Donovan 27:567abf893938 1641 WRITE_REG_U16(hDevice, channelSkipReg.VALUE16, CORE_CHANNEL_SKIPn(eChannelId));
Dan O'Donovan 27:567abf893938 1642
Dan O'Donovan 27:567abf893938 1643 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 1644 }
Dan O'Donovan 27:567abf893938 1645
Dan O'Donovan 27:567abf893938 1646 static ADI_SENSE_RESULT adi_sense_SetChannelAdcSensorType(
Dan O'Donovan 27:567abf893938 1647 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 1648 ADI_SENSE_1000_CHANNEL_ID eChannelId,
Dan O'Donovan 27:567abf893938 1649 ADI_SENSE_1000_ADC_SENSOR_TYPE sensorType)
Dan O'Donovan 27:567abf893938 1650 {
Dan O'Donovan 27:567abf893938 1651 ADI_ADISENSE_CORE_Sensor_Type_t sensorTypeReg;
Dan O'Donovan 27:567abf893938 1652
Dan O'Donovan 27:567abf893938 1653 sensorTypeReg.VALUE16 = REG_RESET_VAL(CORE_SENSOR_TYPEn);
Dan O'Donovan 27:567abf893938 1654
Dan O'Donovan 27:567abf893938 1655 /* Ensure that the sensor type is valid for this channel */
Dan O'Donovan 27:567abf893938 1656 switch(sensorType)
Dan O'Donovan 27:567abf893938 1657 {
Dan O'Donovan 27:567abf893938 1658 case ADI_SENSE_1000_ADC_SENSOR_THERMOCOUPLE_J_DEF_L1:
Dan O'Donovan 27:567abf893938 1659 case ADI_SENSE_1000_ADC_SENSOR_THERMOCOUPLE_K_DEF_L1:
Dan O'Donovan 27:567abf893938 1660 case ADI_SENSE_1000_ADC_SENSOR_THERMOCOUPLE_T_DEF_L1:
Dan O'Donovan 27:567abf893938 1661 case ADI_SENSE_1000_ADC_SENSOR_THERMOCOUPLE_1_DEF_L2:
Dan O'Donovan 27:567abf893938 1662 case ADI_SENSE_1000_ADC_SENSOR_THERMOCOUPLE_2_DEF_L2:
Dan O'Donovan 27:567abf893938 1663 case ADI_SENSE_1000_ADC_SENSOR_THERMOCOUPLE_3_DEF_L2:
Dan O'Donovan 27:567abf893938 1664 case ADI_SENSE_1000_ADC_SENSOR_THERMOCOUPLE_4_DEF_L2:
Dan O'Donovan 27:567abf893938 1665 case ADI_SENSE_1000_ADC_SENSOR_THERMOCOUPLE_J_ADV_L1:
Dan O'Donovan 27:567abf893938 1666 case ADI_SENSE_1000_ADC_SENSOR_THERMOCOUPLE_K_ADV_L1:
Dan O'Donovan 27:567abf893938 1667 case ADI_SENSE_1000_ADC_SENSOR_THERMOCOUPLE_T_ADV_L1:
Dan O'Donovan 27:567abf893938 1668 case ADI_SENSE_1000_ADC_SENSOR_THERMOCOUPLE_1_ADV_L2:
Dan O'Donovan 27:567abf893938 1669 case ADI_SENSE_1000_ADC_SENSOR_THERMOCOUPLE_2_ADV_L2:
Dan O'Donovan 27:567abf893938 1670 case ADI_SENSE_1000_ADC_SENSOR_THERMOCOUPLE_3_ADV_L2:
Dan O'Donovan 27:567abf893938 1671 case ADI_SENSE_1000_ADC_SENSOR_THERMOCOUPLE_4_ADV_L2:
Dan O'Donovan 27:567abf893938 1672 case ADI_SENSE_1000_ADC_SENSOR_RTD_3WIRE_PT100_DEF_L1:
Dan O'Donovan 27:567abf893938 1673 case ADI_SENSE_1000_ADC_SENSOR_RTD_3WIRE_PT1000_DEF_L1:
Dan O'Donovan 27:567abf893938 1674 case ADI_SENSE_1000_ADC_SENSOR_RTD_3WIRE_1_DEF_L2:
Dan O'Donovan 27:567abf893938 1675 case ADI_SENSE_1000_ADC_SENSOR_RTD_3WIRE_2_DEF_L2:
Dan O'Donovan 27:567abf893938 1676 case ADI_SENSE_1000_ADC_SENSOR_RTD_3WIRE_3_DEF_L2:
Dan O'Donovan 27:567abf893938 1677 case ADI_SENSE_1000_ADC_SENSOR_RTD_3WIRE_4_DEF_L2:
Dan O'Donovan 27:567abf893938 1678 case ADI_SENSE_1000_ADC_SENSOR_RTD_3WIRE_PT100_ADV_L1:
Dan O'Donovan 27:567abf893938 1679 case ADI_SENSE_1000_ADC_SENSOR_RTD_3WIRE_PT1000_ADV_L1:
Dan O'Donovan 27:567abf893938 1680 case ADI_SENSE_1000_ADC_SENSOR_RTD_3WIRE_1_ADV_L2:
Dan O'Donovan 27:567abf893938 1681 case ADI_SENSE_1000_ADC_SENSOR_RTD_3WIRE_2_ADV_L2:
Dan O'Donovan 27:567abf893938 1682 case ADI_SENSE_1000_ADC_SENSOR_RTD_3WIRE_3_ADV_L2:
Dan O'Donovan 27:567abf893938 1683 case ADI_SENSE_1000_ADC_SENSOR_RTD_3WIRE_4_ADV_L2:
Dan O'Donovan 27:567abf893938 1684 case ADI_SENSE_1000_ADC_SENSOR_RTD_4WIRE_PT100_DEF_L1:
Dan O'Donovan 27:567abf893938 1685 case ADI_SENSE_1000_ADC_SENSOR_RTD_4WIRE_PT1000_DEF_L1:
Dan O'Donovan 27:567abf893938 1686 case ADI_SENSE_1000_ADC_SENSOR_RTD_4WIRE_1_DEF_L2:
Dan O'Donovan 27:567abf893938 1687 case ADI_SENSE_1000_ADC_SENSOR_RTD_4WIRE_2_DEF_L2:
Dan O'Donovan 27:567abf893938 1688 case ADI_SENSE_1000_ADC_SENSOR_RTD_4WIRE_3_DEF_L2:
Dan O'Donovan 27:567abf893938 1689 case ADI_SENSE_1000_ADC_SENSOR_RTD_4WIRE_4_DEF_L2:
Dan O'Donovan 27:567abf893938 1690 case ADI_SENSE_1000_ADC_SENSOR_RTD_4WIRE_PT100_ADV_L1:
Dan O'Donovan 27:567abf893938 1691 case ADI_SENSE_1000_ADC_SENSOR_RTD_4WIRE_PT1000_ADV_L1:
Dan O'Donovan 27:567abf893938 1692 case ADI_SENSE_1000_ADC_SENSOR_RTD_4WIRE_1_ADV_L2:
Dan O'Donovan 27:567abf893938 1693 case ADI_SENSE_1000_ADC_SENSOR_RTD_4WIRE_2_ADV_L2:
Dan O'Donovan 27:567abf893938 1694 case ADI_SENSE_1000_ADC_SENSOR_RTD_4WIRE_3_ADV_L2:
Dan O'Donovan 27:567abf893938 1695 case ADI_SENSE_1000_ADC_SENSOR_RTD_4WIRE_4_ADV_L2:
Dan O'Donovan 27:567abf893938 1696 case ADI_SENSE_1000_ADC_SENSOR_BRIDGE_4WIRE_1_DEF_L2:
Dan O'Donovan 27:567abf893938 1697 case ADI_SENSE_1000_ADC_SENSOR_BRIDGE_4WIRE_2_DEF_L2:
Dan O'Donovan 27:567abf893938 1698 case ADI_SENSE_1000_ADC_SENSOR_BRIDGE_4WIRE_3_DEF_L2:
Dan O'Donovan 27:567abf893938 1699 case ADI_SENSE_1000_ADC_SENSOR_BRIDGE_4WIRE_4_DEF_L2:
Dan O'Donovan 27:567abf893938 1700 case ADI_SENSE_1000_ADC_SENSOR_BRIDGE_4WIRE_1_ADV_L2:
Dan O'Donovan 27:567abf893938 1701 case ADI_SENSE_1000_ADC_SENSOR_BRIDGE_4WIRE_2_ADV_L2:
Dan O'Donovan 27:567abf893938 1702 case ADI_SENSE_1000_ADC_SENSOR_BRIDGE_4WIRE_3_ADV_L2:
Dan O'Donovan 27:567abf893938 1703 case ADI_SENSE_1000_ADC_SENSOR_BRIDGE_4WIRE_4_ADV_L2:
Dan O'Donovan 27:567abf893938 1704 case ADI_SENSE_1000_ADC_SENSOR_BRIDGE_6WIRE_1_DEF_L2:
Dan O'Donovan 27:567abf893938 1705 case ADI_SENSE_1000_ADC_SENSOR_BRIDGE_6WIRE_2_DEF_L2:
Dan O'Donovan 27:567abf893938 1706 case ADI_SENSE_1000_ADC_SENSOR_BRIDGE_6WIRE_3_DEF_L2:
Dan O'Donovan 27:567abf893938 1707 case ADI_SENSE_1000_ADC_SENSOR_BRIDGE_6WIRE_4_DEF_L2:
Dan O'Donovan 27:567abf893938 1708 case ADI_SENSE_1000_ADC_SENSOR_BRIDGE_6WIRE_1_ADV_L2:
Dan O'Donovan 27:567abf893938 1709 case ADI_SENSE_1000_ADC_SENSOR_BRIDGE_6WIRE_2_ADV_L2:
Dan O'Donovan 27:567abf893938 1710 case ADI_SENSE_1000_ADC_SENSOR_BRIDGE_6WIRE_3_ADV_L2:
Dan O'Donovan 27:567abf893938 1711 case ADI_SENSE_1000_ADC_SENSOR_BRIDGE_6WIRE_4_ADV_L2:
Dan O'Donovan 27:567abf893938 1712 case ADI_SENSE_1000_ADC_SENSOR_MICROPHONE_A_DEF_L1:
Dan O'Donovan 27:567abf893938 1713 case ADI_SENSE_1000_ADC_SENSOR_MICROPHONE_B_DEF_L1:
kevin1990 29:57edca10d78c 1714 case ADI_SENSE_1000_ADC_SENSOR_MICROPHONE_1_DEF_L2:
kevin1990 29:57edca10d78c 1715 case ADI_SENSE_1000_ADC_SENSOR_MICROPHONE_2_DEF_L2:
kevin1990 29:57edca10d78c 1716 case ADI_SENSE_1000_ADC_SENSOR_MICROPHONE_A_ADV_L1:
kevin1990 29:57edca10d78c 1717 case ADI_SENSE_1000_ADC_SENSOR_MICROPHONE_B_ADV_L1:
kevin1990 29:57edca10d78c 1718 case ADI_SENSE_1000_ADC_SENSOR_MICROPHONE_1_ADV_L2:
kevin1990 29:57edca10d78c 1719 case ADI_SENSE_1000_ADC_SENSOR_MICROPHONE_2_ADV_L2:
Dan O'Donovan 27:567abf893938 1720 if (! ADI_SENSE_1000_CHANNEL_IS_ADC_SENSOR(eChannelId))
Dan O'Donovan 27:567abf893938 1721 {
Dan O'Donovan 27:567abf893938 1722 ADI_SENSE_LOG_ERROR(
Dan O'Donovan 27:567abf893938 1723 "Invalid ADC sensor type %d specified for channel %d",
Dan O'Donovan 27:567abf893938 1724 sensorType, eChannelId);
Dan O'Donovan 27:567abf893938 1725 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 1726 }
Dan O'Donovan 27:567abf893938 1727 break;
Dan O'Donovan 27:567abf893938 1728 case ADI_SENSE_1000_ADC_SENSOR_RTD_2WIRE_PT100_DEF_L1:
Dan O'Donovan 27:567abf893938 1729 case ADI_SENSE_1000_ADC_SENSOR_RTD_2WIRE_PT1000_DEF_L1:
Dan O'Donovan 27:567abf893938 1730 case ADI_SENSE_1000_ADC_SENSOR_RTD_2WIRE_1_DEF_L2:
Dan O'Donovan 27:567abf893938 1731 case ADI_SENSE_1000_ADC_SENSOR_RTD_2WIRE_2_DEF_L2:
Dan O'Donovan 27:567abf893938 1732 case ADI_SENSE_1000_ADC_SENSOR_RTD_2WIRE_3_DEF_L2:
Dan O'Donovan 27:567abf893938 1733 case ADI_SENSE_1000_ADC_SENSOR_RTD_2WIRE_4_DEF_L2:
Dan O'Donovan 27:567abf893938 1734 case ADI_SENSE_1000_ADC_SENSOR_RTD_2WIRE_PT100_ADV_L1:
Dan O'Donovan 27:567abf893938 1735 case ADI_SENSE_1000_ADC_SENSOR_RTD_2WIRE_PT1000_ADV_L1:
Dan O'Donovan 27:567abf893938 1736 case ADI_SENSE_1000_ADC_SENSOR_RTD_2WIRE_1_ADV_L2:
Dan O'Donovan 27:567abf893938 1737 case ADI_SENSE_1000_ADC_SENSOR_RTD_2WIRE_2_ADV_L2:
Dan O'Donovan 27:567abf893938 1738 case ADI_SENSE_1000_ADC_SENSOR_RTD_2WIRE_3_ADV_L2:
Dan O'Donovan 27:567abf893938 1739 case ADI_SENSE_1000_ADC_SENSOR_RTD_2WIRE_4_ADV_L2:
Dan O'Donovan 27:567abf893938 1740 case ADI_SENSE_1000_ADC_SENSOR_DIODE_2C_TYPEA_DEF_L1:
Dan O'Donovan 27:567abf893938 1741 case ADI_SENSE_1000_ADC_SENSOR_DIODE_3C_TYPEA_DEF_L1:
Dan O'Donovan 27:567abf893938 1742 case ADI_SENSE_1000_ADC_SENSOR_DIODE_2C_1_DEF_L2:
Dan O'Donovan 27:567abf893938 1743 case ADI_SENSE_1000_ADC_SENSOR_DIODE_3C_1_DEF_L2:
Dan O'Donovan 27:567abf893938 1744 case ADI_SENSE_1000_ADC_SENSOR_DIODE_2C_TYPEA_ADV_L1:
Dan O'Donovan 27:567abf893938 1745 case ADI_SENSE_1000_ADC_SENSOR_DIODE_3C_TYPEA_ADV_L1:
Dan O'Donovan 27:567abf893938 1746 case ADI_SENSE_1000_ADC_SENSOR_DIODE_2C_1_ADV_L2:
Dan O'Donovan 27:567abf893938 1747 case ADI_SENSE_1000_ADC_SENSOR_DIODE_3C_1_ADV_L2:
kevin1990 29:57edca10d78c 1748 case ADI_SENSE_1000_ADC_SENSOR_THERMISTOR_A_10K_DEF_L1:
kevin1990 29:57edca10d78c 1749 case ADI_SENSE_1000_ADC_SENSOR_THERMISTOR_B_10K_DEF_L1:
kevin1990 29:57edca10d78c 1750 case ADI_SENSE_1000_ADC_SENSOR_THERMISTOR_1_DEF_L2:
kevin1990 29:57edca10d78c 1751 case ADI_SENSE_1000_ADC_SENSOR_THERMISTOR_2_DEF_L2:
kevin1990 29:57edca10d78c 1752 case ADI_SENSE_1000_ADC_SENSOR_THERMISTOR_3_DEF_L2:
kevin1990 29:57edca10d78c 1753 case ADI_SENSE_1000_ADC_SENSOR_THERMISTOR_4_DEF_L2:
kevin1990 29:57edca10d78c 1754 case ADI_SENSE_1000_ADC_SENSOR_THERMISTOR_A_10K_ADV_L1:
kevin1990 29:57edca10d78c 1755 case ADI_SENSE_1000_ADC_SENSOR_THERMISTOR_B_10K_ADV_L1:
kevin1990 29:57edca10d78c 1756 case ADI_SENSE_1000_ADC_SENSOR_THERMISTOR_1_ADV_L2:
kevin1990 29:57edca10d78c 1757 case ADI_SENSE_1000_ADC_SENSOR_THERMISTOR_2_ADV_L2:
kevin1990 29:57edca10d78c 1758 case ADI_SENSE_1000_ADC_SENSOR_THERMISTOR_3_ADV_L2:
kevin1990 29:57edca10d78c 1759 case ADI_SENSE_1000_ADC_SENSOR_THERMISTOR_4_ADV_L2:
Dan O'Donovan 27:567abf893938 1760 if (! (ADI_SENSE_1000_CHANNEL_IS_ADC_SENSOR(eChannelId) ||
Dan O'Donovan 27:567abf893938 1761 ADI_SENSE_1000_CHANNEL_IS_ADC_CJC(eChannelId)))
Dan O'Donovan 27:567abf893938 1762 {
Dan O'Donovan 27:567abf893938 1763 ADI_SENSE_LOG_ERROR(
Dan O'Donovan 27:567abf893938 1764 "Invalid ADC sensor type %d specified for channel %d",
Dan O'Donovan 27:567abf893938 1765 sensorType, eChannelId);
Dan O'Donovan 27:567abf893938 1766 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 1767 }
Dan O'Donovan 27:567abf893938 1768 break;
Dan O'Donovan 27:567abf893938 1769 case ADI_SENSE_1000_ADC_SENSOR_VOLTAGE:
kevin1990 29:57edca10d78c 1770 case ADI_SENSE_1000_ADC_SENSOR_VOLTAGE_PRESSURE_A_DEF_L1:
kevin1990 29:57edca10d78c 1771 case ADI_SENSE_1000_ADC_SENSOR_VOLTAGE_PRESSURE_B_DEF_L1:
Dan O'Donovan 27:567abf893938 1772 case ADI_SENSE_1000_ADC_SENSOR_VOLTAGE_PRESSURE_1_DEF_L2:
Dan O'Donovan 27:567abf893938 1773 case ADI_SENSE_1000_ADC_SENSOR_VOLTAGE_PRESSURE_2_DEF_L2:
kevin1990 29:57edca10d78c 1774 case ADI_SENSE_1000_ADC_SENSOR_VOLTAGE_PRESSURE_A_ADV_L1:
kevin1990 29:57edca10d78c 1775 case ADI_SENSE_1000_ADC_SENSOR_VOLTAGE_PRESSURE_B_ADV_L1:
kevin1990 29:57edca10d78c 1776 case ADI_SENSE_1000_ADC_SENSOR_VOLTAGE_PRESSURE_1_ADV_L2:
kevin1990 29:57edca10d78c 1777 case ADI_SENSE_1000_ADC_SENSOR_VOLTAGE_PRESSURE_2_ADV_L2:
Dan O'Donovan 27:567abf893938 1778 if (! ADI_SENSE_1000_CHANNEL_IS_ADC_VOLTAGE(eChannelId))
Dan O'Donovan 27:567abf893938 1779 {
Dan O'Donovan 27:567abf893938 1780 ADI_SENSE_LOG_ERROR(
Dan O'Donovan 27:567abf893938 1781 "Invalid ADC sensor type %d specified for channel %d",
Dan O'Donovan 27:567abf893938 1782 sensorType, eChannelId);
Dan O'Donovan 27:567abf893938 1783 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 1784 }
Dan O'Donovan 27:567abf893938 1785 break;
Dan O'Donovan 27:567abf893938 1786 case ADI_SENSE_1000_ADC_SENSOR_CURRENT:
kevin1990 29:57edca10d78c 1787 case ADI_SENSE_1000_ADC_SENSOR_CURRENT_PRESSURE_A_DEF_L1:
Dan O'Donovan 27:567abf893938 1788 case ADI_SENSE_1000_ADC_SENSOR_CURRENT_PRESSURE_1_DEF_L2:
Dan O'Donovan 27:567abf893938 1789 case ADI_SENSE_1000_ADC_SENSOR_CURRENT_PRESSURE_2_DEF_L2:
kevin1990 29:57edca10d78c 1790 case ADI_SENSE_1000_ADC_SENSOR_CURRENT_PRESSURE_A_ADV_L1:
kevin1990 29:57edca10d78c 1791 case ADI_SENSE_1000_ADC_SENSOR_CURRENT_PRESSURE_1_ADV_L2:
kevin1990 29:57edca10d78c 1792 case ADI_SENSE_1000_ADC_SENSOR_CURRENT_PRESSURE_2_ADV_L2:
Dan O'Donovan 27:567abf893938 1793 if (! ADI_SENSE_1000_CHANNEL_IS_ADC_CURRENT(eChannelId))
Dan O'Donovan 27:567abf893938 1794 {
Dan O'Donovan 27:567abf893938 1795 ADI_SENSE_LOG_ERROR(
Dan O'Donovan 27:567abf893938 1796 "Invalid ADC sensor type %d specified for channel %d",
Dan O'Donovan 27:567abf893938 1797 sensorType, eChannelId);
Dan O'Donovan 27:567abf893938 1798 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 1799 }
Dan O'Donovan 27:567abf893938 1800 break;
Dan O'Donovan 27:567abf893938 1801 default:
Dan O'Donovan 27:567abf893938 1802 ADI_SENSE_LOG_ERROR("Invalid/unsupported ADC sensor type %d specified",
Dan O'Donovan 27:567abf893938 1803 sensorType);
Dan O'Donovan 27:567abf893938 1804 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 1805 }
Dan O'Donovan 27:567abf893938 1806
Dan O'Donovan 27:567abf893938 1807 sensorTypeReg.Sensor_Type = sensorType;
Dan O'Donovan 27:567abf893938 1808
Dan O'Donovan 27:567abf893938 1809 WRITE_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(eChannelId));
Dan O'Donovan 27:567abf893938 1810
Dan O'Donovan 27:567abf893938 1811 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 1812 }
Dan O'Donovan 27:567abf893938 1813
Dan O'Donovan 27:567abf893938 1814 static ADI_SENSE_RESULT adi_sense_SetChannelAdcSensorDetails(
Dan O'Donovan 27:567abf893938 1815 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 1816 ADI_SENSE_1000_CHANNEL_ID eChannelId,
Dan O'Donovan 27:567abf893938 1817 ADI_SENSE_1000_CHANNEL_CONFIG *pChannelConfig)
Dan O'Donovan 27:567abf893938 1818 /*
Dan O'Donovan 27:567abf893938 1819 * TODO - it would be nice if the general- vs. ADC-specific sensor details could be split into separate registers
Dan O'Donovan 27:567abf893938 1820 * General details:
Dan O'Donovan 27:567abf893938 1821 * - Measurement_Units
Dan O'Donovan 27:567abf893938 1822 * - Compensation_Channel
Dan O'Donovan 27:567abf893938 1823 * - CJC_Publish (if "CJC" was removed from the name)
Dan O'Donovan 27:567abf893938 1824 * ADC-specific details:
Dan O'Donovan 27:567abf893938 1825 * - PGA_Gain
Dan O'Donovan 27:567abf893938 1826 * - Reference_Select
Dan O'Donovan 27:567abf893938 1827 * - Reference_Buffer_Disable
Dan O'Donovan 27:567abf893938 1828 * - Vbias
Dan O'Donovan 27:567abf893938 1829 */
Dan O'Donovan 27:567abf893938 1830 {
Dan O'Donovan 27:567abf893938 1831 ADI_SENSE_1000_ADC_CHANNEL_CONFIG *pAdcChannelConfig = &pChannelConfig->adcChannelConfig;
Dan O'Donovan 27:567abf893938 1832 ADI_SENSE_1000_ADC_REFERENCE_CONFIG *pRefConfig = &pAdcChannelConfig->reference;
Dan O'Donovan 27:567abf893938 1833 ADI_ADISENSE_CORE_Sensor_Details_t sensorDetailsReg;
Dan O'Donovan 27:567abf893938 1834
Dan O'Donovan 27:567abf893938 1835 sensorDetailsReg.VALUE32 = REG_RESET_VAL(CORE_SENSOR_DETAILSn);
Dan O'Donovan 27:567abf893938 1836
Dan O'Donovan 27:567abf893938 1837 switch(pChannelConfig->measurementUnit)
Dan O'Donovan 27:567abf893938 1838 {
Dan O'Donovan 27:567abf893938 1839 case ADI_SENSE_1000_MEASUREMENT_UNIT_FAHRENHEIT:
Dan O'Donovan 27:567abf893938 1840 sensorDetailsReg.Measurement_Units = ADISENSE_CORE_SENSOR_DETAILS_UNITS_DEGF;
Dan O'Donovan 27:567abf893938 1841 break;
Dan O'Donovan 27:567abf893938 1842 case ADI_SENSE_1000_MEASUREMENT_UNIT_CELSIUS:
Dan O'Donovan 27:567abf893938 1843 sensorDetailsReg.Measurement_Units = ADISENSE_CORE_SENSOR_DETAILS_UNITS_DEGC;
Dan O'Donovan 27:567abf893938 1844 break;
kevin1990 29:57edca10d78c 1845 case ADI_SENSE_1000_MEASUREMENT_UNIT_UNSPECIFIED:
kevin1990 29:57edca10d78c 1846 sensorDetailsReg.Measurement_Units = ADISENSE_CORE_SENSOR_DETAILS_UNITS_UNSPECIFIED;
kevin1990 29:57edca10d78c 1847 break;
Dan O'Donovan 27:567abf893938 1848 default:
Dan O'Donovan 27:567abf893938 1849 ADI_SENSE_LOG_ERROR("Invalid measurement unit %d specified",
Dan O'Donovan 27:567abf893938 1850 pChannelConfig->measurementUnit);
Dan O'Donovan 27:567abf893938 1851 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 1852 }
Dan O'Donovan 27:567abf893938 1853
kevin1990 29:57edca10d78c 1854 if (pChannelConfig->compensationChannel == ADI_SENSE_1000_CHANNEL_ID_NONE)
kevin1990 29:57edca10d78c 1855 {
kevin1990 29:57edca10d78c 1856 sensorDetailsReg.Compensation_Disable = 1;
kevin1990 29:57edca10d78c 1857 sensorDetailsReg.Compensation_Channel = 0;
kevin1990 29:57edca10d78c 1858 }
kevin1990 29:57edca10d78c 1859 else
kevin1990 29:57edca10d78c 1860 {
kevin1990 29:57edca10d78c 1861 sensorDetailsReg.Compensation_Disable = 0;
kevin1990 29:57edca10d78c 1862 sensorDetailsReg.Compensation_Channel = pChannelConfig->compensationChannel;
kevin1990 29:57edca10d78c 1863 }
Dan O'Donovan 27:567abf893938 1864
Dan O'Donovan 27:567abf893938 1865 switch(pRefConfig->type)
Dan O'Donovan 27:567abf893938 1866 {
Dan O'Donovan 27:567abf893938 1867 case ADI_SENSE_1000_ADC_REFERENCE_RESISTOR_INTERNAL_1:
Dan O'Donovan 27:567abf893938 1868 sensorDetailsReg.Reference_Select = ADISENSE_CORE_SENSOR_DETAILS_REF_RINT1;
Dan O'Donovan 27:567abf893938 1869 break;
Dan O'Donovan 27:567abf893938 1870 case ADI_SENSE_1000_ADC_REFERENCE_RESISTOR_INTERNAL_2:
Dan O'Donovan 27:567abf893938 1871 sensorDetailsReg.Reference_Select = ADISENSE_CORE_SENSOR_DETAILS_REF_RINT2;
Dan O'Donovan 27:567abf893938 1872 break;
Dan O'Donovan 27:567abf893938 1873 case ADI_SENSE_1000_ADC_REFERENCE_VOLTAGE_INTERNAL:
Dan O'Donovan 27:567abf893938 1874 sensorDetailsReg.Reference_Select = ADISENSE_CORE_SENSOR_DETAILS_REF_INT;
Dan O'Donovan 27:567abf893938 1875 break;
Dan O'Donovan 27:567abf893938 1876 case ADI_SENSE_1000_ADC_REFERENCE_VOLTAGE_AVDD:
Dan O'Donovan 27:567abf893938 1877 sensorDetailsReg.Reference_Select = ADISENSE_CORE_SENSOR_DETAILS_REF_AVDD;
Dan O'Donovan 27:567abf893938 1878 break;
Dan O'Donovan 27:567abf893938 1879 case ADI_SENSE_1000_ADC_REFERENCE_RESISTOR_EXTERNAL_1:
Dan O'Donovan 27:567abf893938 1880 sensorDetailsReg.Reference_Select = ADISENSE_CORE_SENSOR_DETAILS_REF_REXT1;
Dan O'Donovan 27:567abf893938 1881 break;
Dan O'Donovan 27:567abf893938 1882 case ADI_SENSE_1000_ADC_REFERENCE_RESISTOR_EXTERNAL_2:
Dan O'Donovan 27:567abf893938 1883 sensorDetailsReg.Reference_Select = ADISENSE_CORE_SENSOR_DETAILS_REF_REXT2;
Dan O'Donovan 27:567abf893938 1884 break;
Dan O'Donovan 27:567abf893938 1885 case ADI_SENSE_1000_ADC_REFERENCE_VOLTAGE_EXTERNAL_1:
Dan O'Donovan 27:567abf893938 1886 sensorDetailsReg.Reference_Select = ADISENSE_CORE_SENSOR_DETAILS_REF_VEXT1;
Dan O'Donovan 27:567abf893938 1887 break;
Dan O'Donovan 27:567abf893938 1888 case ADI_SENSE_1000_ADC_REFERENCE_VOLTAGE_EXTERNAL_2:
Dan O'Donovan 27:567abf893938 1889 sensorDetailsReg.Reference_Select = ADISENSE_CORE_SENSOR_DETAILS_REF_VEXT2;
Dan O'Donovan 27:567abf893938 1890 break;
Dan O'Donovan 27:567abf893938 1891 case ADI_SENSE_1000_ADC_REFERENCE_BRIDGE_EXCITATION:
Dan O'Donovan 27:567abf893938 1892 sensorDetailsReg.Reference_Select = ADISENSE_CORE_SENSOR_DETAILS_REF_EXC;
Dan O'Donovan 27:567abf893938 1893 break;
Dan O'Donovan 27:567abf893938 1894 default:
Dan O'Donovan 27:567abf893938 1895 ADI_SENSE_LOG_ERROR("Invalid ADC reference type %d specified",
Dan O'Donovan 27:567abf893938 1896 pRefConfig->type);
Dan O'Donovan 27:567abf893938 1897 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 1898 }
Dan O'Donovan 27:567abf893938 1899
Dan O'Donovan 27:567abf893938 1900 switch(pAdcChannelConfig->gain)
Dan O'Donovan 27:567abf893938 1901 {
Dan O'Donovan 27:567abf893938 1902 case ADI_SENSE_1000_ADC_GAIN_1X:
Dan O'Donovan 27:567abf893938 1903 sensorDetailsReg.PGA_Gain = ADISENSE_CORE_SENSOR_DETAILS_PGA_GAIN_1;
Dan O'Donovan 27:567abf893938 1904 break;
Dan O'Donovan 27:567abf893938 1905 case ADI_SENSE_1000_ADC_GAIN_2X:
Dan O'Donovan 27:567abf893938 1906 sensorDetailsReg.PGA_Gain = ADISENSE_CORE_SENSOR_DETAILS_PGA_GAIN_2;
Dan O'Donovan 27:567abf893938 1907 break;
Dan O'Donovan 27:567abf893938 1908 case ADI_SENSE_1000_ADC_GAIN_4X:
Dan O'Donovan 27:567abf893938 1909 sensorDetailsReg.PGA_Gain = ADISENSE_CORE_SENSOR_DETAILS_PGA_GAIN_4;
Dan O'Donovan 27:567abf893938 1910 break;
Dan O'Donovan 27:567abf893938 1911 case ADI_SENSE_1000_ADC_GAIN_8X:
Dan O'Donovan 27:567abf893938 1912 sensorDetailsReg.PGA_Gain = ADISENSE_CORE_SENSOR_DETAILS_PGA_GAIN_8;
Dan O'Donovan 27:567abf893938 1913 break;
Dan O'Donovan 27:567abf893938 1914 case ADI_SENSE_1000_ADC_GAIN_16X:
Dan O'Donovan 27:567abf893938 1915 sensorDetailsReg.PGA_Gain = ADISENSE_CORE_SENSOR_DETAILS_PGA_GAIN_16;
Dan O'Donovan 27:567abf893938 1916 break;
Dan O'Donovan 27:567abf893938 1917 case ADI_SENSE_1000_ADC_GAIN_32X:
Dan O'Donovan 27:567abf893938 1918 sensorDetailsReg.PGA_Gain = ADISENSE_CORE_SENSOR_DETAILS_PGA_GAIN_32;
Dan O'Donovan 27:567abf893938 1919 break;
Dan O'Donovan 27:567abf893938 1920 case ADI_SENSE_1000_ADC_GAIN_64X:
Dan O'Donovan 27:567abf893938 1921 sensorDetailsReg.PGA_Gain = ADISENSE_CORE_SENSOR_DETAILS_PGA_GAIN_64;
Dan O'Donovan 27:567abf893938 1922 break;
Dan O'Donovan 27:567abf893938 1923 case ADI_SENSE_1000_ADC_GAIN_128X:
Dan O'Donovan 27:567abf893938 1924 sensorDetailsReg.PGA_Gain = ADISENSE_CORE_SENSOR_DETAILS_PGA_GAIN_128;
Dan O'Donovan 27:567abf893938 1925 break;
Dan O'Donovan 27:567abf893938 1926 default:
Dan O'Donovan 27:567abf893938 1927 ADI_SENSE_LOG_ERROR("Invalid ADC gain %d specified",
Dan O'Donovan 27:567abf893938 1928 pAdcChannelConfig->gain);
Dan O'Donovan 27:567abf893938 1929 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 1930 }
Dan O'Donovan 27:567abf893938 1931
Dan O'Donovan 27:567abf893938 1932 if (pAdcChannelConfig->enableVbias)
Dan O'Donovan 27:567abf893938 1933 sensorDetailsReg.Vbias = 1;
Dan O'Donovan 27:567abf893938 1934 else
Dan O'Donovan 27:567abf893938 1935 sensorDetailsReg.Vbias = 0;
Dan O'Donovan 27:567abf893938 1936
Dan O'Donovan 27:567abf893938 1937 if (pAdcChannelConfig->reference.disableBuffer)
Dan O'Donovan 27:567abf893938 1938 sensorDetailsReg.Reference_Buffer_Disable = 1;
Dan O'Donovan 27:567abf893938 1939 else
Dan O'Donovan 27:567abf893938 1940 sensorDetailsReg.Reference_Buffer_Disable = 0;
Dan O'Donovan 27:567abf893938 1941
Dan O'Donovan 27:567abf893938 1942 if (pChannelConfig->disablePublishing)
Dan O'Donovan 27:567abf893938 1943 sensorDetailsReg.Do_Not_Publish = 1;
Dan O'Donovan 27:567abf893938 1944 else
Dan O'Donovan 27:567abf893938 1945 sensorDetailsReg.Do_Not_Publish = 0;
Dan O'Donovan 27:567abf893938 1946
kevin1990 29:57edca10d78c 1947 if (pChannelConfig->enableUnityLut)
kevin1990 29:57edca10d78c 1948 sensorDetailsReg.Unity_LUT_Select = 1;
kevin1990 29:57edca10d78c 1949 else
kevin1990 29:57edca10d78c 1950 sensorDetailsReg.Unity_LUT_Select = 0;
kevin1990 29:57edca10d78c 1951
Dan O'Donovan 27:567abf893938 1952 WRITE_REG_U32(hDevice, sensorDetailsReg.VALUE32, CORE_SENSOR_DETAILSn(eChannelId));
Dan O'Donovan 27:567abf893938 1953
Dan O'Donovan 27:567abf893938 1954 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 1955 }
Dan O'Donovan 27:567abf893938 1956
Dan O'Donovan 27:567abf893938 1957 static ADI_SENSE_RESULT adi_sense_SetChannelAdcFilter(
Dan O'Donovan 27:567abf893938 1958 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 1959 ADI_SENSE_1000_CHANNEL_ID eChannelId,
Dan O'Donovan 27:567abf893938 1960 ADI_SENSE_1000_ADC_FILTER_CONFIG *pFilterConfig)
Dan O'Donovan 27:567abf893938 1961 {
Dan O'Donovan 27:567abf893938 1962 ADI_ADISENSE_CORE_Filter_Select_t filterSelectReg;
Dan O'Donovan 27:567abf893938 1963
Dan O'Donovan 27:567abf893938 1964 filterSelectReg.VALUE32 = REG_RESET_VAL(CORE_FILTER_SELECTn);
Dan O'Donovan 27:567abf893938 1965
Dan O'Donovan 27:567abf893938 1966 if (pFilterConfig->type == ADI_SENSE_1000_ADC_FILTER_SINC4)
Dan O'Donovan 27:567abf893938 1967 {
Dan O'Donovan 27:567abf893938 1968 filterSelectReg.ADC_Filter_Type = ADISENSE_CORE_FILTER_SELECT_FILTER_SINC4;
Dan O'Donovan 27:567abf893938 1969 filterSelectReg.ADC_FS = pFilterConfig->fs;
Dan O'Donovan 27:567abf893938 1970 }
Dan O'Donovan 27:567abf893938 1971 else if (pFilterConfig->type == ADI_SENSE_1000_ADC_FILTER_FIR_20SPS)
Dan O'Donovan 27:567abf893938 1972 {
Dan O'Donovan 27:567abf893938 1973 filterSelectReg.ADC_Filter_Type = ADISENSE_CORE_FILTER_SELECT_FILTER_FIR_20SPS;
Dan O'Donovan 27:567abf893938 1974 }
Dan O'Donovan 27:567abf893938 1975 else if (pFilterConfig->type == ADI_SENSE_1000_ADC_FILTER_FIR_25SPS)
Dan O'Donovan 27:567abf893938 1976 {
Dan O'Donovan 27:567abf893938 1977 filterSelectReg.ADC_Filter_Type = ADISENSE_CORE_FILTER_SELECT_FILTER_FIR_25SPS;
Dan O'Donovan 27:567abf893938 1978 }
Dan O'Donovan 27:567abf893938 1979 else
Dan O'Donovan 27:567abf893938 1980 {
Dan O'Donovan 27:567abf893938 1981 ADI_SENSE_LOG_ERROR("Invalid ADC filter type %d specified",
Dan O'Donovan 27:567abf893938 1982 pFilterConfig->type);
Dan O'Donovan 27:567abf893938 1983 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 1984 }
Dan O'Donovan 27:567abf893938 1985
Dan O'Donovan 27:567abf893938 1986 WRITE_REG_U32(hDevice, filterSelectReg.VALUE32, CORE_FILTER_SELECTn(eChannelId));
Dan O'Donovan 27:567abf893938 1987
Dan O'Donovan 27:567abf893938 1988 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 1989 }
Dan O'Donovan 27:567abf893938 1990
Dan O'Donovan 27:567abf893938 1991 static ADI_SENSE_RESULT adi_sense_SetChannelAdcCurrentConfig(
Dan O'Donovan 27:567abf893938 1992 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 1993 ADI_SENSE_1000_CHANNEL_ID eChannelId,
Dan O'Donovan 27:567abf893938 1994 ADI_SENSE_1000_ADC_EXC_CURRENT_CONFIG *pCurrentConfig)
Dan O'Donovan 27:567abf893938 1995 {
Dan O'Donovan 27:567abf893938 1996 ADI_ADISENSE_CORE_Channel_Excitation_t channelExcitationReg;
Dan O'Donovan 27:567abf893938 1997
Dan O'Donovan 27:567abf893938 1998 channelExcitationReg.VALUE8 = REG_RESET_VAL(CORE_CHANNEL_EXCITATIONn);
Dan O'Donovan 27:567abf893938 1999
Dan O'Donovan 27:567abf893938 2000 if (pCurrentConfig->outputLevel == ADI_SENSE_1000_ADC_EXC_CURRENT_NONE)
Dan O'Donovan 27:567abf893938 2001 {
Dan O'Donovan 27:567abf893938 2002 channelExcitationReg.IOUT_Excitation_Current = ADISENSE_CORE_CHANNEL_EXCITATION_IEXC_OFF;
Dan O'Donovan 27:567abf893938 2003 }
Dan O'Donovan 27:567abf893938 2004 else
Dan O'Donovan 27:567abf893938 2005 {
Dan O'Donovan 27:567abf893938 2006 if (pCurrentConfig->outputLevel == ADI_SENSE_1000_ADC_EXC_CURRENT_50uA)
Dan O'Donovan 27:567abf893938 2007 channelExcitationReg.IOUT_Excitation_Current = ADISENSE_CORE_CHANNEL_EXCITATION_IEXC_50UA;
Dan O'Donovan 27:567abf893938 2008 else if (pCurrentConfig->outputLevel == ADI_SENSE_1000_ADC_EXC_CURRENT_100uA)
Dan O'Donovan 27:567abf893938 2009 channelExcitationReg.IOUT_Excitation_Current = ADISENSE_CORE_CHANNEL_EXCITATION_IEXC_100UA;
Dan O'Donovan 27:567abf893938 2010 else if (pCurrentConfig->outputLevel == ADI_SENSE_1000_ADC_EXC_CURRENT_250uA)
Dan O'Donovan 27:567abf893938 2011 channelExcitationReg.IOUT_Excitation_Current = ADISENSE_CORE_CHANNEL_EXCITATION_IEXC_250UA;
Dan O'Donovan 27:567abf893938 2012 else if (pCurrentConfig->outputLevel == ADI_SENSE_1000_ADC_EXC_CURRENT_500uA)
Dan O'Donovan 27:567abf893938 2013 channelExcitationReg.IOUT_Excitation_Current = ADISENSE_CORE_CHANNEL_EXCITATION_IEXC_500UA;
Dan O'Donovan 27:567abf893938 2014 else if (pCurrentConfig->outputLevel == ADI_SENSE_1000_ADC_EXC_CURRENT_750uA)
Dan O'Donovan 27:567abf893938 2015 channelExcitationReg.IOUT_Excitation_Current = ADISENSE_CORE_CHANNEL_EXCITATION_IEXC_750UA;
Dan O'Donovan 27:567abf893938 2016 else if (pCurrentConfig->outputLevel == ADI_SENSE_1000_ADC_EXC_CURRENT_1000uA)
Dan O'Donovan 27:567abf893938 2017 channelExcitationReg.IOUT_Excitation_Current = ADISENSE_CORE_CHANNEL_EXCITATION_IEXC_1000UA;
Dan O'Donovan 27:567abf893938 2018 else
Dan O'Donovan 27:567abf893938 2019 {
Dan O'Donovan 27:567abf893938 2020 ADI_SENSE_LOG_ERROR("Invalid ADC excitation current %d specified",
Dan O'Donovan 27:567abf893938 2021 pCurrentConfig->outputLevel);
Dan O'Donovan 27:567abf893938 2022 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 2023 }
Dan O'Donovan 27:567abf893938 2024 }
Dan O'Donovan 27:567abf893938 2025
Dan O'Donovan 27:567abf893938 2026 if (pCurrentConfig->diodeRatio == ADI_SENSE_1000_ADC_EXC_CURRENT_IOUT_DIODE_DEFAULT)
Dan O'Donovan 27:567abf893938 2027 {
Dan O'Donovan 27:567abf893938 2028 channelExcitationReg.IOUT_Diode_Ratio = 0;
Dan O'Donovan 27:567abf893938 2029 }
Dan O'Donovan 27:567abf893938 2030 else
Dan O'Donovan 27:567abf893938 2031 {
Dan O'Donovan 27:567abf893938 2032 channelExcitationReg.IOUT_Diode_Ratio = 1;
Dan O'Donovan 27:567abf893938 2033 }
Dan O'Donovan 27:567abf893938 2034
Dan O'Donovan 27:567abf893938 2035 WRITE_REG_U8(hDevice, channelExcitationReg.VALUE8, CORE_CHANNEL_EXCITATIONn(eChannelId));
Dan O'Donovan 27:567abf893938 2036
Dan O'Donovan 27:567abf893938 2037 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 2038 }
Dan O'Donovan 27:567abf893938 2039
Dan O'Donovan 27:567abf893938 2040 ADI_SENSE_RESULT adi_sense_SetAdcChannelConfig(
Dan O'Donovan 27:567abf893938 2041 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 2042 ADI_SENSE_1000_CHANNEL_ID eChannelId,
Dan O'Donovan 27:567abf893938 2043 ADI_SENSE_1000_CHANNEL_CONFIG *pChannelConfig)
Dan O'Donovan 27:567abf893938 2044 {
Dan O'Donovan 27:567abf893938 2045 ADI_SENSE_RESULT eRet;
Dan O'Donovan 27:567abf893938 2046 ADI_SENSE_1000_ADC_CHANNEL_CONFIG *pAdcChannelConfig =
Dan O'Donovan 27:567abf893938 2047 &pChannelConfig->adcChannelConfig;
Dan O'Donovan 27:567abf893938 2048
Dan O'Donovan 27:567abf893938 2049 eRet = adi_sense_SetChannelAdcSensorType(hDevice, eChannelId,
Dan O'Donovan 27:567abf893938 2050 pAdcChannelConfig->sensor);
Dan O'Donovan 27:567abf893938 2051 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 2052 {
Dan O'Donovan 27:567abf893938 2053 ADI_SENSE_LOG_ERROR("Failed to set ADC sensor type for channel %d",
Dan O'Donovan 27:567abf893938 2054 eChannelId);
Dan O'Donovan 27:567abf893938 2055 return eRet;
Dan O'Donovan 27:567abf893938 2056 }
Dan O'Donovan 27:567abf893938 2057
Dan O'Donovan 27:567abf893938 2058 eRet = adi_sense_SetChannelAdcSensorDetails(hDevice, eChannelId,
Dan O'Donovan 27:567abf893938 2059 pChannelConfig);
Dan O'Donovan 27:567abf893938 2060 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 2061 {
Dan O'Donovan 27:567abf893938 2062 ADI_SENSE_LOG_ERROR("Failed to set ADC sensor details for channel %d",
Dan O'Donovan 27:567abf893938 2063 eChannelId);
Dan O'Donovan 27:567abf893938 2064 return eRet;
Dan O'Donovan 27:567abf893938 2065 }
Dan O'Donovan 27:567abf893938 2066
Dan O'Donovan 27:567abf893938 2067 eRet = adi_sense_SetChannelAdcFilter(hDevice, eChannelId,
Dan O'Donovan 27:567abf893938 2068 &pAdcChannelConfig->filter);
Dan O'Donovan 27:567abf893938 2069 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 2070 {
Dan O'Donovan 27:567abf893938 2071 ADI_SENSE_LOG_ERROR("Failed to set ADC filter for channel %d",
Dan O'Donovan 27:567abf893938 2072 eChannelId);
Dan O'Donovan 27:567abf893938 2073 return eRet;
Dan O'Donovan 27:567abf893938 2074 }
Dan O'Donovan 27:567abf893938 2075
Dan O'Donovan 27:567abf893938 2076 eRet = adi_sense_SetChannelAdcCurrentConfig(hDevice, eChannelId,
Dan O'Donovan 27:567abf893938 2077 &pAdcChannelConfig->current);
Dan O'Donovan 27:567abf893938 2078 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 2079 {
Dan O'Donovan 27:567abf893938 2080 ADI_SENSE_LOG_ERROR("Failed to set ADC current for channel %d",
Dan O'Donovan 27:567abf893938 2081 eChannelId);
Dan O'Donovan 27:567abf893938 2082 return eRet;
Dan O'Donovan 27:567abf893938 2083 }
Dan O'Donovan 27:567abf893938 2084
Dan O'Donovan 27:567abf893938 2085 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 2086 }
Dan O'Donovan 27:567abf893938 2087
kevin1990 29:57edca10d78c 2088 static ADI_SENSE_RESULT adi_sense_SetChannelDigitalSensorDetails(
kevin1990 29:57edca10d78c 2089 ADI_SENSE_DEVICE_HANDLE hDevice,
kevin1990 29:57edca10d78c 2090 ADI_SENSE_1000_CHANNEL_ID eChannelId,
kevin1990 29:57edca10d78c 2091 ADI_SENSE_1000_CHANNEL_CONFIG *pChannelConfig)
kevin1990 29:57edca10d78c 2092 {
kevin1990 29:57edca10d78c 2093 ADI_ADISENSE_CORE_Sensor_Details_t sensorDetailsReg;
kevin1990 29:57edca10d78c 2094
kevin1990 29:57edca10d78c 2095 sensorDetailsReg.VALUE32 = REG_RESET_VAL(CORE_SENSOR_DETAILSn);
kevin1990 29:57edca10d78c 2096
kevin1990 29:57edca10d78c 2097 if (pChannelConfig->compensationChannel == ADI_SENSE_1000_CHANNEL_ID_NONE)
kevin1990 29:57edca10d78c 2098 {
kevin1990 29:57edca10d78c 2099 sensorDetailsReg.Compensation_Disable = 1;
kevin1990 29:57edca10d78c 2100 sensorDetailsReg.Compensation_Channel = 0;
kevin1990 29:57edca10d78c 2101 }
kevin1990 29:57edca10d78c 2102 else
kevin1990 29:57edca10d78c 2103 {
kevin1990 29:57edca10d78c 2104 ADI_SENSE_LOG_ERROR("Invalid compensation channel specified for digital sensor");
kevin1990 29:57edca10d78c 2105 return ADI_SENSE_INVALID_PARAM;
kevin1990 29:57edca10d78c 2106 }
kevin1990 29:57edca10d78c 2107
kevin1990 29:57edca10d78c 2108 if (pChannelConfig->measurementUnit == ADI_SENSE_1000_MEASUREMENT_UNIT_UNSPECIFIED)
kevin1990 29:57edca10d78c 2109 {
kevin1990 29:57edca10d78c 2110 sensorDetailsReg.Measurement_Units = ADISENSE_CORE_SENSOR_DETAILS_UNITS_UNSPECIFIED;
kevin1990 29:57edca10d78c 2111 }
kevin1990 29:57edca10d78c 2112 else
kevin1990 29:57edca10d78c 2113 {
kevin1990 29:57edca10d78c 2114 ADI_SENSE_LOG_ERROR("Invalid measurement unit specified for digital channel");
kevin1990 29:57edca10d78c 2115 return ADI_SENSE_INVALID_PARAM;
kevin1990 29:57edca10d78c 2116 }
kevin1990 29:57edca10d78c 2117
kevin1990 29:57edca10d78c 2118 if (pChannelConfig->disablePublishing)
kevin1990 29:57edca10d78c 2119 sensorDetailsReg.Do_Not_Publish = 1;
kevin1990 29:57edca10d78c 2120 else
kevin1990 29:57edca10d78c 2121 sensorDetailsReg.Do_Not_Publish = 0;
kevin1990 29:57edca10d78c 2122
kevin1990 29:57edca10d78c 2123 if (pChannelConfig->enableUnityLut)
kevin1990 29:57edca10d78c 2124 sensorDetailsReg.Unity_LUT_Select = 1;
kevin1990 29:57edca10d78c 2125 else
kevin1990 29:57edca10d78c 2126 sensorDetailsReg.Unity_LUT_Select = 0;
kevin1990 29:57edca10d78c 2127
kevin1990 29:57edca10d78c 2128 sensorDetailsReg.Vbias = 0;
kevin1990 29:57edca10d78c 2129 sensorDetailsReg.Reference_Buffer_Disable = 1;
kevin1990 29:57edca10d78c 2130
kevin1990 29:57edca10d78c 2131 WRITE_REG_U32(hDevice, sensorDetailsReg.VALUE32, CORE_SENSOR_DETAILSn(eChannelId));
kevin1990 29:57edca10d78c 2132
kevin1990 29:57edca10d78c 2133 return ADI_SENSE_SUCCESS;
kevin1990 29:57edca10d78c 2134 }
Dan O'Donovan 27:567abf893938 2135
Dan O'Donovan 27:567abf893938 2136 static ADI_SENSE_RESULT adi_sense_SetDigitalSensorCommands(
Dan O'Donovan 27:567abf893938 2137 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 2138 ADI_SENSE_1000_CHANNEL_ID eChannelId,
Dan O'Donovan 27:567abf893938 2139 ADI_SENSE_1000_DIGITAL_SENSOR_COMMAND *pConfigCommand,
Dan O'Donovan 27:567abf893938 2140 ADI_SENSE_1000_DIGITAL_SENSOR_COMMAND *pDataRequestCommand)
Dan O'Donovan 27:567abf893938 2141 {
Dan O'Donovan 27:567abf893938 2142 ADI_ADISENSE_CORE_Digital_Sensor_Num_Cmds_t numCmdsReg;
Dan O'Donovan 27:567abf893938 2143
Dan O'Donovan 27:567abf893938 2144 numCmdsReg.VALUE8 = REG_RESET_VAL(CORE_DIGITAL_SENSOR_NUM_CMDSn);
Dan O'Donovan 27:567abf893938 2145
Dan O'Donovan 27:567abf893938 2146 CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_NUM_CMDS_DIGITAL_SENSOR_NUM_CFG_CMDS,
Dan O'Donovan 27:567abf893938 2147 pConfigCommand->commandLength);
Dan O'Donovan 27:567abf893938 2148 CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_NUM_CMDS_DIGITAL_SENSOR_NUM_READ_CMDS,
Dan O'Donovan 27:567abf893938 2149 pDataRequestCommand->commandLength);
Dan O'Donovan 27:567abf893938 2150
Dan O'Donovan 27:567abf893938 2151 numCmdsReg.Digital_Sensor_Num_Cfg_Cmds = pConfigCommand->commandLength;
Dan O'Donovan 27:567abf893938 2152 numCmdsReg.Digital_Sensor_Num_Read_Cmds = pDataRequestCommand->commandLength;
Dan O'Donovan 27:567abf893938 2153
Dan O'Donovan 27:567abf893938 2154 WRITE_REG_U8(hDevice, numCmdsReg.VALUE8,
Dan O'Donovan 27:567abf893938 2155 CORE_DIGITAL_SENSOR_NUM_CMDSn(eChannelId));
Dan O'Donovan 27:567abf893938 2156
Dan O'Donovan 27:567abf893938 2157 /*
Dan O'Donovan 27:567abf893938 2158 * NOTE - the fall-through cases in the switch statement below are
Dan O'Donovan 27:567abf893938 2159 * intentional, so temporarily disable related compiler warnings which may
Dan O'Donovan 27:567abf893938 2160 * be produced here by GCC
Dan O'Donovan 27:567abf893938 2161 */
Dan O'Donovan 27:567abf893938 2162 #ifndef __CC_ARM
Dan O'Donovan 27:567abf893938 2163 #pragma GCC diagnostic push
Dan O'Donovan 27:567abf893938 2164 #pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
Dan O'Donovan 27:567abf893938 2165 #endif
Dan O'Donovan 27:567abf893938 2166
Dan O'Donovan 27:567abf893938 2167 switch (pConfigCommand->commandLength)
Dan O'Donovan 27:567abf893938 2168 {
Dan O'Donovan 27:567abf893938 2169 case 7:
Dan O'Donovan 27:567abf893938 2170 WRITE_REG_U8(hDevice, pConfigCommand->command[6],
Dan O'Donovan 27:567abf893938 2171 CORE_DIGITAL_SENSOR_COMMAND7n(eChannelId));
Dan O'Donovan 27:567abf893938 2172 case 6:
Dan O'Donovan 27:567abf893938 2173 WRITE_REG_U8(hDevice, pConfigCommand->command[5],
Dan O'Donovan 27:567abf893938 2174 CORE_DIGITAL_SENSOR_COMMAND6n(eChannelId));
Dan O'Donovan 27:567abf893938 2175 case 5:
Dan O'Donovan 27:567abf893938 2176 WRITE_REG_U8(hDevice, pConfigCommand->command[4],
Dan O'Donovan 27:567abf893938 2177 CORE_DIGITAL_SENSOR_COMMAND5n(eChannelId));
Dan O'Donovan 27:567abf893938 2178 case 4:
Dan O'Donovan 27:567abf893938 2179 WRITE_REG_U8(hDevice, pConfigCommand->command[3],
Dan O'Donovan 27:567abf893938 2180 CORE_DIGITAL_SENSOR_COMMAND4n(eChannelId));
Dan O'Donovan 27:567abf893938 2181 case 3:
Dan O'Donovan 27:567abf893938 2182 WRITE_REG_U8(hDevice, pConfigCommand->command[2],
Dan O'Donovan 27:567abf893938 2183 CORE_DIGITAL_SENSOR_COMMAND3n(eChannelId));
Dan O'Donovan 27:567abf893938 2184 case 2:
Dan O'Donovan 27:567abf893938 2185 WRITE_REG_U8(hDevice, pConfigCommand->command[1],
Dan O'Donovan 27:567abf893938 2186 CORE_DIGITAL_SENSOR_COMMAND2n(eChannelId));
Dan O'Donovan 27:567abf893938 2187 case 1:
Dan O'Donovan 27:567abf893938 2188 WRITE_REG_U8(hDevice, pConfigCommand->command[0],
Dan O'Donovan 27:567abf893938 2189 CORE_DIGITAL_SENSOR_COMMAND1n(eChannelId));
Dan O'Donovan 27:567abf893938 2190 case 0:
Dan O'Donovan 27:567abf893938 2191 default:
Dan O'Donovan 27:567abf893938 2192 break;
Dan O'Donovan 27:567abf893938 2193 };
Dan O'Donovan 27:567abf893938 2194
Dan O'Donovan 27:567abf893938 2195 switch (pDataRequestCommand->commandLength)
Dan O'Donovan 27:567abf893938 2196 {
Dan O'Donovan 27:567abf893938 2197 case 7:
Dan O'Donovan 27:567abf893938 2198 WRITE_REG_U8(hDevice, pDataRequestCommand->command[6],
Dan O'Donovan 27:567abf893938 2199 CORE_DIGITAL_SENSOR_READ_CMD7n(eChannelId));
Dan O'Donovan 27:567abf893938 2200 case 6:
Dan O'Donovan 27:567abf893938 2201 WRITE_REG_U8(hDevice, pDataRequestCommand->command[5],
Dan O'Donovan 27:567abf893938 2202 CORE_DIGITAL_SENSOR_READ_CMD6n(eChannelId));
Dan O'Donovan 27:567abf893938 2203 case 5:
Dan O'Donovan 27:567abf893938 2204 WRITE_REG_U8(hDevice, pDataRequestCommand->command[4],
Dan O'Donovan 27:567abf893938 2205 CORE_DIGITAL_SENSOR_READ_CMD5n(eChannelId));
Dan O'Donovan 27:567abf893938 2206 case 4:
Dan O'Donovan 27:567abf893938 2207 WRITE_REG_U8(hDevice, pDataRequestCommand->command[3],
Dan O'Donovan 27:567abf893938 2208 CORE_DIGITAL_SENSOR_READ_CMD4n(eChannelId));
Dan O'Donovan 27:567abf893938 2209 case 3:
Dan O'Donovan 27:567abf893938 2210 WRITE_REG_U8(hDevice, pDataRequestCommand->command[2],
Dan O'Donovan 27:567abf893938 2211 CORE_DIGITAL_SENSOR_READ_CMD3n(eChannelId));
Dan O'Donovan 27:567abf893938 2212 case 2:
Dan O'Donovan 27:567abf893938 2213 WRITE_REG_U8(hDevice, pDataRequestCommand->command[1],
Dan O'Donovan 27:567abf893938 2214 CORE_DIGITAL_SENSOR_READ_CMD2n(eChannelId));
Dan O'Donovan 27:567abf893938 2215 case 1:
Dan O'Donovan 27:567abf893938 2216 WRITE_REG_U8(hDevice, pDataRequestCommand->command[0],
Dan O'Donovan 27:567abf893938 2217 CORE_DIGITAL_SENSOR_READ_CMD1n(eChannelId));
Dan O'Donovan 27:567abf893938 2218 case 0:
Dan O'Donovan 27:567abf893938 2219 default:
Dan O'Donovan 27:567abf893938 2220 break;
Dan O'Donovan 27:567abf893938 2221 };
Dan O'Donovan 27:567abf893938 2222
Dan O'Donovan 27:567abf893938 2223 /* Re-enable the implicit-fallthrough warning */
Dan O'Donovan 27:567abf893938 2224 #ifndef __CC_ARM
Dan O'Donovan 27:567abf893938 2225 #pragma GCC diagnostic pop
Dan O'Donovan 27:567abf893938 2226 #endif
Dan O'Donovan 27:567abf893938 2227
Dan O'Donovan 27:567abf893938 2228 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 2229 }
Dan O'Donovan 27:567abf893938 2230
Dan O'Donovan 27:567abf893938 2231 static ADI_SENSE_RESULT adi_sense_SetDigitalSensorFormat(
Dan O'Donovan 27:567abf893938 2232 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 2233 ADI_SENSE_1000_CHANNEL_ID eChannelId,
Dan O'Donovan 27:567abf893938 2234 ADI_SENSE_1000_DIGITAL_SENSOR_DATA_FORMAT *pDataFormat)
Dan O'Donovan 27:567abf893938 2235 {
Dan O'Donovan 27:567abf893938 2236 ADI_ADISENSE_CORE_Digital_Sensor_Config_t sensorConfigReg;
Dan O'Donovan 27:567abf893938 2237
Dan O'Donovan 27:567abf893938 2238 sensorConfigReg.VALUE16 = REG_RESET_VAL(CORE_DIGITAL_SENSOR_CONFIGn);
Dan O'Donovan 27:567abf893938 2239
Dan O'Donovan 27:567abf893938 2240 if (pDataFormat->coding != ADI_SENSE_1000_DIGITAL_SENSOR_DATA_CODING_NONE)
Dan O'Donovan 27:567abf893938 2241 {
Dan O'Donovan 27:567abf893938 2242 if (pDataFormat->frameLength == 0)
Dan O'Donovan 27:567abf893938 2243 {
Dan O'Donovan 27:567abf893938 2244 ADI_SENSE_LOG_ERROR("Invalid frame length specified for digital sensor data format");
Dan O'Donovan 27:567abf893938 2245 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 2246 }
Dan O'Donovan 27:567abf893938 2247 if (pDataFormat->numDataBits == 0)
Dan O'Donovan 27:567abf893938 2248 {
Dan O'Donovan 27:567abf893938 2249 ADI_SENSE_LOG_ERROR("Invalid frame length specified for digital sensor data format");
Dan O'Donovan 27:567abf893938 2250 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 2251 }
Dan O'Donovan 27:567abf893938 2252
Dan O'Donovan 27:567abf893938 2253 CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_CONFIG_DIGITAL_SENSOR_READ_BYTES,
Dan O'Donovan 27:567abf893938 2254 pDataFormat->frameLength - 1);
Dan O'Donovan 27:567abf893938 2255 CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_CONFIG_DIGITAL_SENSOR_DATA_BITS,
Dan O'Donovan 27:567abf893938 2256 pDataFormat->numDataBits - 1);
Dan O'Donovan 27:567abf893938 2257 CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_CONFIG_DIGITAL_SENSOR_BIT_OFFSET,
Dan O'Donovan 27:567abf893938 2258 pDataFormat->bitOffset);
Dan O'Donovan 27:567abf893938 2259
Dan O'Donovan 27:567abf893938 2260 sensorConfigReg.Digital_Sensor_Read_Bytes = pDataFormat->frameLength - 1;
Dan O'Donovan 27:567abf893938 2261 sensorConfigReg.Digital_Sensor_Data_Bits = pDataFormat->numDataBits - 1;
Dan O'Donovan 27:567abf893938 2262 sensorConfigReg.Digital_Sensor_Bit_Offset = pDataFormat->bitOffset;
Dan O'Donovan 27:567abf893938 2263 sensorConfigReg.Digital_Sensor_Left_Aligned = pDataFormat->leftJustified ? 1 : 0;
Dan O'Donovan 27:567abf893938 2264 sensorConfigReg.Digital_Sensor_Little_Endian = pDataFormat->littleEndian ? 1 : 0;
Dan O'Donovan 27:567abf893938 2265
Dan O'Donovan 27:567abf893938 2266 switch (pDataFormat->coding)
Dan O'Donovan 27:567abf893938 2267 {
Dan O'Donovan 27:567abf893938 2268 case ADI_SENSE_1000_DIGITAL_SENSOR_DATA_CODING_UNIPOLAR:
Dan O'Donovan 27:567abf893938 2269 sensorConfigReg.Digital_Sensor_Coding = ADISENSE_CORE_DIGITAL_SENSOR_CONFIG_CODING_UNIPOLAR;
Dan O'Donovan 27:567abf893938 2270 break;
Dan O'Donovan 27:567abf893938 2271 case ADI_SENSE_1000_DIGITAL_SENSOR_DATA_CODING_TWOS_COMPLEMENT:
Dan O'Donovan 27:567abf893938 2272 sensorConfigReg.Digital_Sensor_Coding = ADISENSE_CORE_DIGITAL_SENSOR_CONFIG_CODING_TWOS_COMPL;
Dan O'Donovan 27:567abf893938 2273 break;
Dan O'Donovan 27:567abf893938 2274 case ADI_SENSE_1000_DIGITAL_SENSOR_DATA_CODING_OFFSET_BINARY:
Dan O'Donovan 27:567abf893938 2275 sensorConfigReg.Digital_Sensor_Coding = ADISENSE_CORE_DIGITAL_SENSOR_CONFIG_CODING_OFFSET_BINARY;
Dan O'Donovan 27:567abf893938 2276 break;
Dan O'Donovan 27:567abf893938 2277 default:
Dan O'Donovan 27:567abf893938 2278 ADI_SENSE_LOG_ERROR("Invalid coding specified for digital sensor data format");
Dan O'Donovan 27:567abf893938 2279 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 2280 }
Dan O'Donovan 27:567abf893938 2281 }
kevin1990 29:57edca10d78c 2282 else
kevin1990 29:57edca10d78c 2283 {
kevin1990 29:57edca10d78c 2284 sensorConfigReg.Digital_Sensor_Coding = ADISENSE_CORE_DIGITAL_SENSOR_CONFIG_CODING_NONE;
kevin1990 29:57edca10d78c 2285 }
Dan O'Donovan 27:567abf893938 2286
Dan O'Donovan 27:567abf893938 2287 WRITE_REG_U16(hDevice, sensorConfigReg.VALUE16,
Dan O'Donovan 27:567abf893938 2288 CORE_DIGITAL_SENSOR_CONFIGn(eChannelId));
Dan O'Donovan 27:567abf893938 2289
Dan O'Donovan 27:567abf893938 2290
Dan O'Donovan 27:567abf893938 2291 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 2292 }
Dan O'Donovan 27:567abf893938 2293
kevin1990 29:57edca10d78c 2294 static ADI_SENSE_RESULT adi_sense_SetDigitalCalibrationParam(
kevin1990 29:57edca10d78c 2295 ADI_SENSE_DEVICE_HANDLE hDevice,
kevin1990 29:57edca10d78c 2296 ADI_SENSE_1000_CHANNEL_ID eChannelId,
kevin1990 29:57edca10d78c 2297 ADI_SENSE_1000_DIGITAL_CALIBRATION_COMMAND *pCalibrationParam)
kevin1990 29:57edca10d78c 2298 {
kevin1990 29:57edca10d78c 2299 ADI_ADISENSE_CORE_Calibration_Parameter_t calibrationParamReg;
kevin1990 29:57edca10d78c 2300
kevin1990 29:57edca10d78c 2301 calibrationParamReg.VALUE32 = REG_RESET_VAL(CORE_CALIBRATION_PARAMETERn);
kevin1990 29:57edca10d78c 2302
kevin1990 29:57edca10d78c 2303 if (pCalibrationParam->enableCalibrationParam == false)
kevin1990 29:57edca10d78c 2304 calibrationParamReg.Calibration_Parameter_Enable = 0;
kevin1990 29:57edca10d78c 2305 else
kevin1990 29:57edca10d78c 2306 calibrationParamReg.Calibration_Parameter_Enable = 1;
kevin1990 29:57edca10d78c 2307
kevin1990 29:57edca10d78c 2308 CHECK_REG_FIELD_VAL(CORE_CALIBRATION_PARAMETER_CALIBRATION_PARAMETER,
kevin1990 29:57edca10d78c 2309 pCalibrationParam->calibrationParam);
kevin1990 29:57edca10d78c 2310
kevin1990 29:57edca10d78c 2311 calibrationParamReg.Calibration_Parameter = pCalibrationParam->calibrationParam;
kevin1990 29:57edca10d78c 2312
kevin1990 29:57edca10d78c 2313 WRITE_REG_U32(hDevice, calibrationParamReg.VALUE32,
kevin1990 29:57edca10d78c 2314 CORE_CALIBRATION_PARAMETERn(eChannelId));
kevin1990 29:57edca10d78c 2315
kevin1990 29:57edca10d78c 2316 return ADI_SENSE_SUCCESS;
kevin1990 29:57edca10d78c 2317 }
kevin1990 29:57edca10d78c 2318
Dan O'Donovan 27:567abf893938 2319 static ADI_SENSE_RESULT adi_sense_SetChannelI2cSensorType(
Dan O'Donovan 27:567abf893938 2320 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 2321 ADI_SENSE_1000_CHANNEL_ID eChannelId,
Dan O'Donovan 27:567abf893938 2322 ADI_SENSE_1000_I2C_SENSOR_TYPE sensorType)
Dan O'Donovan 27:567abf893938 2323 {
Dan O'Donovan 27:567abf893938 2324 ADI_ADISENSE_CORE_Sensor_Type_t sensorTypeReg;
Dan O'Donovan 27:567abf893938 2325
Dan O'Donovan 27:567abf893938 2326 sensorTypeReg.VALUE16 = REG_RESET_VAL(CORE_SENSOR_TYPEn);
Dan O'Donovan 27:567abf893938 2327
Dan O'Donovan 27:567abf893938 2328 /* Ensure that the sensor type is valid for this channel */
Dan O'Donovan 27:567abf893938 2329 switch(sensorType)
Dan O'Donovan 27:567abf893938 2330 {
kevin1990 29:57edca10d78c 2331 case ADI_SENSE_1000_I2C_SENSOR_HUMIDITY_A_DEF_L1:
kevin1990 29:57edca10d78c 2332 case ADI_SENSE_1000_I2C_SENSOR_HUMIDITY_B_DEF_L1:
kevin1990 29:57edca10d78c 2333 case ADI_SENSE_1000_I2C_SENSOR_HUMIDITY_A_DEF_L2:
kevin1990 29:57edca10d78c 2334 case ADI_SENSE_1000_I2C_SENSOR_HUMIDITY_B_DEF_L2:
kevin1990 29:57edca10d78c 2335 case ADI_SENSE_1000_I2C_SENSOR_HUMIDITY_A_ADV_L1:
kevin1990 29:57edca10d78c 2336 case ADI_SENSE_1000_I2C_SENSOR_HUMIDITY_B_ADV_L1:
kevin1990 29:57edca10d78c 2337 case ADI_SENSE_1000_I2C_SENSOR_HUMIDITY_A_ADV_L2:
kevin1990 29:57edca10d78c 2338 case ADI_SENSE_1000_I2C_SENSOR_HUMIDITY_B_ADV_L2:
kevin1990 29:57edca10d78c 2339 case ADI_SENSE_1000_I2C_SENSOR_AMBIENTLIGHT_A_DEF_L1:
kevin1990 29:57edca10d78c 2340 case ADI_SENSE_1000_I2C_SENSOR_AMBIENTLIGHT_A_DEF_L2:
kevin1990 29:57edca10d78c 2341 case ADI_SENSE_1000_I2C_SENSOR_AMBIENTLIGHT_A_ADV_L1:
kevin1990 29:57edca10d78c 2342 case ADI_SENSE_1000_I2C_SENSOR_AMBIENTLIGHT_A_ADV_L2:
kevin1990 29:57edca10d78c 2343 sensorTypeReg.Sensor_Type = sensorType;
Dan O'Donovan 27:567abf893938 2344 break;
Dan O'Donovan 27:567abf893938 2345 default:
Dan O'Donovan 27:567abf893938 2346 ADI_SENSE_LOG_ERROR("Unsupported I2C sensor type %d specified", sensorType);
Dan O'Donovan 27:567abf893938 2347 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 2348 }
Dan O'Donovan 27:567abf893938 2349
Dan O'Donovan 27:567abf893938 2350 WRITE_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(eChannelId));
Dan O'Donovan 27:567abf893938 2351
Dan O'Donovan 27:567abf893938 2352 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 2353 }
Dan O'Donovan 27:567abf893938 2354
Dan O'Donovan 27:567abf893938 2355 static ADI_SENSE_RESULT adi_sense_SetChannelI2cSensorAddress(
Dan O'Donovan 27:567abf893938 2356 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 2357 ADI_SENSE_1000_CHANNEL_ID eChannelId,
Dan O'Donovan 27:567abf893938 2358 uint32_t deviceAddress)
Dan O'Donovan 27:567abf893938 2359 {
Dan O'Donovan 27:567abf893938 2360 CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_ADDRESS_DIGITAL_SENSOR_ADDRESS, deviceAddress);
Dan O'Donovan 27:567abf893938 2361 WRITE_REG_U8(hDevice, deviceAddress, CORE_DIGITAL_SENSOR_ADDRESSn(eChannelId));
Dan O'Donovan 27:567abf893938 2362
Dan O'Donovan 27:567abf893938 2363 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 2364 }
Dan O'Donovan 27:567abf893938 2365
kevin1990 29:57edca10d78c 2366 static ADI_SENSE_RESULT adi_sense_SetDigitalChannelComms(
kevin1990 29:57edca10d78c 2367 ADI_SENSE_DEVICE_HANDLE hDevice,
kevin1990 29:57edca10d78c 2368 ADI_SENSE_1000_CHANNEL_ID eChannelId,
kevin1990 29:57edca10d78c 2369 ADI_SENSE_1000_DIGITAL_SENSOR_COMMS *pDigitalComms)
kevin1990 29:57edca10d78c 2370 {
kevin1990 29:57edca10d78c 2371 ADI_ADISENSE_CORE_Digital_Sensor_Comms_t digitalSensorComms;
kevin1990 29:57edca10d78c 2372
kevin1990 29:57edca10d78c 2373 digitalSensorComms.VALUE16 = REG_RESET_VAL(CORE_DIGITAL_SENSOR_COMMSn);
kevin1990 29:57edca10d78c 2374
kevin1990 29:57edca10d78c 2375 if(pDigitalComms->useCustomCommsConfig)
kevin1990 29:57edca10d78c 2376 {
kevin1990 29:57edca10d78c 2377 digitalSensorComms.Digital_Sensor_Comms_En = 1;
kevin1990 29:57edca10d78c 2378
kevin1990 29:57edca10d78c 2379 if(pDigitalComms->i2cClockSpeed == ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_I2C_CLOCK_SPEED_100K)
kevin1990 29:57edca10d78c 2380 {
kevin1990 29:57edca10d78c 2381 digitalSensorComms.I2C_Clock = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_I2C_100K;
kevin1990 29:57edca10d78c 2382 }
kevin1990 29:57edca10d78c 2383 else if(pDigitalComms->i2cClockSpeed == ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_I2C_CLOCK_SPEED_400K)
kevin1990 29:57edca10d78c 2384 {
kevin1990 29:57edca10d78c 2385 digitalSensorComms.I2C_Clock = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_I2C_400K;
kevin1990 29:57edca10d78c 2386 }
kevin1990 29:57edca10d78c 2387 else
kevin1990 29:57edca10d78c 2388 {
kevin1990 29:57edca10d78c 2389 ADI_SENSE_LOG_ERROR("Invalid I2C clock speed %d specified",
kevin1990 29:57edca10d78c 2390 pDigitalComms->i2cClockSpeed);
kevin1990 29:57edca10d78c 2391 return ADI_SENSE_INVALID_PARAM;
kevin1990 29:57edca10d78c 2392 }
kevin1990 29:57edca10d78c 2393
kevin1990 29:57edca10d78c 2394 if(pDigitalComms->spiMode == ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_SPI_MODE_0)
kevin1990 29:57edca10d78c 2395 {
kevin1990 29:57edca10d78c 2396 digitalSensorComms.SPI_Mode = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_SPI_MODE_0;
kevin1990 29:57edca10d78c 2397 }
kevin1990 29:57edca10d78c 2398 else if(pDigitalComms->spiMode == ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_SPI_MODE_1)
kevin1990 29:57edca10d78c 2399 {
kevin1990 29:57edca10d78c 2400 digitalSensorComms.SPI_Mode = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_SPI_MODE_1;
kevin1990 29:57edca10d78c 2401 }
kevin1990 29:57edca10d78c 2402 else if(pDigitalComms->spiMode == ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_SPI_MODE_2)
kevin1990 29:57edca10d78c 2403 {
kevin1990 29:57edca10d78c 2404 digitalSensorComms.SPI_Mode = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_SPI_MODE_2;
kevin1990 29:57edca10d78c 2405 }
kevin1990 29:57edca10d78c 2406 else if(pDigitalComms->spiMode == ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_SPI_MODE_3)
kevin1990 29:57edca10d78c 2407 {
kevin1990 29:57edca10d78c 2408 digitalSensorComms.SPI_Mode = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_SPI_MODE_3;
kevin1990 29:57edca10d78c 2409 }
kevin1990 29:57edca10d78c 2410 else
kevin1990 29:57edca10d78c 2411 {
kevin1990 29:57edca10d78c 2412 ADI_SENSE_LOG_ERROR("Invalid SPI mode %d specified",
kevin1990 29:57edca10d78c 2413 pDigitalComms->spiMode);
kevin1990 29:57edca10d78c 2414 return ADI_SENSE_INVALID_PARAM;
kevin1990 29:57edca10d78c 2415 }
kevin1990 29:57edca10d78c 2416
kevin1990 29:57edca10d78c 2417 switch (pDigitalComms->spiClock)
kevin1990 29:57edca10d78c 2418 {
kevin1990 29:57edca10d78c 2419 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_SPI_CLOCK_13MHZ:
kevin1990 29:57edca10d78c 2420 digitalSensorComms.SPI_Clock = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_SPI_13MHZ;
kevin1990 29:57edca10d78c 2421 break;
kevin1990 29:57edca10d78c 2422 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_SPI_CLOCK_6_5MHZ:
kevin1990 29:57edca10d78c 2423 digitalSensorComms.SPI_Clock = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_SPI_6_5MHZ;
kevin1990 29:57edca10d78c 2424 break;
kevin1990 29:57edca10d78c 2425 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_SPI_CLOCK_3_25MHZ:
kevin1990 29:57edca10d78c 2426 digitalSensorComms.SPI_Clock = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_SPI_3_25MHZ;
kevin1990 29:57edca10d78c 2427 break;
kevin1990 29:57edca10d78c 2428 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_SPI_CLOCK_1_625MHZ:
kevin1990 29:57edca10d78c 2429 digitalSensorComms.SPI_Clock = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_SPI_1_625MHZ;
kevin1990 29:57edca10d78c 2430 break;
kevin1990 29:57edca10d78c 2431 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_SPI_CLOCK_812KHZ:
kevin1990 29:57edca10d78c 2432 digitalSensorComms.SPI_Clock = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_SPI_812KHZ;
kevin1990 29:57edca10d78c 2433 break;
kevin1990 29:57edca10d78c 2434 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_SPI_CLOCK_406KHZ:
kevin1990 29:57edca10d78c 2435 digitalSensorComms.SPI_Clock = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_SPI_406KHZ;
kevin1990 29:57edca10d78c 2436 break;
kevin1990 29:57edca10d78c 2437 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_SPI_CLOCK_203KHZ:
kevin1990 29:57edca10d78c 2438 digitalSensorComms.SPI_Clock = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_SPI_203KHZ;
kevin1990 29:57edca10d78c 2439 break;
kevin1990 29:57edca10d78c 2440 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_SPI_CLOCK_101KHZ:
kevin1990 29:57edca10d78c 2441 digitalSensorComms.SPI_Clock = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_SPI_101KHZ;
kevin1990 29:57edca10d78c 2442 break;
kevin1990 29:57edca10d78c 2443 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_SPI_CLOCK_50KHZ:
kevin1990 29:57edca10d78c 2444 digitalSensorComms.SPI_Clock = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_SPI_50KHZ;
kevin1990 29:57edca10d78c 2445 break;
kevin1990 29:57edca10d78c 2446 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_SPI_CLOCK_25KHZ:
kevin1990 29:57edca10d78c 2447 digitalSensorComms.SPI_Clock = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_SPI_25KHZ;
kevin1990 29:57edca10d78c 2448 break;
kevin1990 29:57edca10d78c 2449 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_SPI_CLOCK_12KHZ:
kevin1990 29:57edca10d78c 2450 digitalSensorComms.SPI_Clock = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_SPI_12KHZ;
kevin1990 29:57edca10d78c 2451 break;
kevin1990 29:57edca10d78c 2452 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_SPI_CLOCK_6KHZ:
kevin1990 29:57edca10d78c 2453 digitalSensorComms.SPI_Clock = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_SPI_6KHZ;
kevin1990 29:57edca10d78c 2454 break;
kevin1990 29:57edca10d78c 2455 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_SPI_CLOCK_3KHZ:
kevin1990 29:57edca10d78c 2456 digitalSensorComms.SPI_Clock = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_SPI_3KHZ;
kevin1990 29:57edca10d78c 2457 break;
kevin1990 29:57edca10d78c 2458 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_SPI_CLOCK_1_5KHZ:
kevin1990 29:57edca10d78c 2459 digitalSensorComms.SPI_Clock = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_SPI_1_5KHZ;
kevin1990 29:57edca10d78c 2460 break;
kevin1990 29:57edca10d78c 2461 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_SPI_CLOCK_793HZ:
kevin1990 29:57edca10d78c 2462 digitalSensorComms.SPI_Clock = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_SPI_793HZ;
kevin1990 29:57edca10d78c 2463 break;
kevin1990 29:57edca10d78c 2464 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_SPI_CLOCK_396HZ:
kevin1990 29:57edca10d78c 2465 digitalSensorComms.SPI_Clock = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_SPI_396HZ;
kevin1990 29:57edca10d78c 2466 break;
kevin1990 29:57edca10d78c 2467 default:
kevin1990 29:57edca10d78c 2468 ADI_SENSE_LOG_ERROR("Invalid SPI clock %d specified",
kevin1990 29:57edca10d78c 2469 pDigitalComms->spiClock);
kevin1990 29:57edca10d78c 2470 return ADI_SENSE_INVALID_PARAM;
kevin1990 29:57edca10d78c 2471 }
kevin1990 29:57edca10d78c 2472
kevin1990 29:57edca10d78c 2473 switch (pDigitalComms->uartLineConfig)
kevin1990 29:57edca10d78c 2474 {
kevin1990 29:57edca10d78c 2475 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_UART_LINE_CONFIG_8N1:
kevin1990 29:57edca10d78c 2476 digitalSensorComms.Uart_Mode = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_LINECONTROL_8N1;
kevin1990 29:57edca10d78c 2477 break;
kevin1990 29:57edca10d78c 2478 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_UART_LINE_CONFIG_8N2:
kevin1990 29:57edca10d78c 2479 digitalSensorComms.Uart_Mode = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_LINECONTROL_8N2;
kevin1990 29:57edca10d78c 2480 break;
kevin1990 29:57edca10d78c 2481 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_UART_LINE_CONFIG_8N3:
kevin1990 29:57edca10d78c 2482 digitalSensorComms.Uart_Mode = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_LINECONTROL_8N3;
kevin1990 29:57edca10d78c 2483 break;
kevin1990 29:57edca10d78c 2484 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_UART_LINE_CONFIG_8E1:
kevin1990 29:57edca10d78c 2485 digitalSensorComms.Uart_Mode = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_LINECONTROL_8E1;
kevin1990 29:57edca10d78c 2486 break;
kevin1990 29:57edca10d78c 2487 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_UART_LINE_CONFIG_8E2:
kevin1990 29:57edca10d78c 2488 digitalSensorComms.Uart_Mode = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_LINECONTROL_8E2;
kevin1990 29:57edca10d78c 2489 break;
kevin1990 29:57edca10d78c 2490 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_UART_LINE_CONFIG_8E3:
kevin1990 29:57edca10d78c 2491 digitalSensorComms.Uart_Mode = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_LINECONTROL_8E3;
kevin1990 29:57edca10d78c 2492 break;
kevin1990 29:57edca10d78c 2493 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_UART_LINE_CONFIG_8O1:
kevin1990 29:57edca10d78c 2494 digitalSensorComms.Uart_Mode = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_LINECONTROL_8O1;
kevin1990 29:57edca10d78c 2495 break;
kevin1990 29:57edca10d78c 2496 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_UART_LINE_CONFIG_8O2:
kevin1990 29:57edca10d78c 2497 digitalSensorComms.Uart_Mode = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_LINECONTROL_8O2;
kevin1990 29:57edca10d78c 2498 break;
kevin1990 29:57edca10d78c 2499 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_UART_LINE_CONFIG_8O3:
kevin1990 29:57edca10d78c 2500 digitalSensorComms.Uart_Mode = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_LINECONTROL_8O3;
kevin1990 29:57edca10d78c 2501 break;
kevin1990 29:57edca10d78c 2502 default:
kevin1990 29:57edca10d78c 2503 ADI_SENSE_LOG_ERROR("Invalid UART mode %d specified",
kevin1990 29:57edca10d78c 2504 pDigitalComms->uartLineConfig);
kevin1990 29:57edca10d78c 2505 return ADI_SENSE_INVALID_PARAM;
kevin1990 29:57edca10d78c 2506 }
kevin1990 29:57edca10d78c 2507
kevin1990 29:57edca10d78c 2508 switch (pDigitalComms->uartBaudRate)
kevin1990 29:57edca10d78c 2509 {
kevin1990 29:57edca10d78c 2510 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_UART_BAUD_RATE_115200:
kevin1990 29:57edca10d78c 2511 digitalSensorComms.Uart_Baud = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_UART_115200;
kevin1990 29:57edca10d78c 2512 break;
kevin1990 29:57edca10d78c 2513 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_UART_BAUD_RATE_57600:
kevin1990 29:57edca10d78c 2514 digitalSensorComms.Uart_Baud = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_UART_57600;
kevin1990 29:57edca10d78c 2515 break;
kevin1990 29:57edca10d78c 2516 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_UART_BAUD_RATE_38400:
kevin1990 29:57edca10d78c 2517 digitalSensorComms.Uart_Baud = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_UART_38400;
kevin1990 29:57edca10d78c 2518 break;
kevin1990 29:57edca10d78c 2519 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_UART_BAUD_RATE_19200:
kevin1990 29:57edca10d78c 2520 digitalSensorComms.Uart_Baud = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_UART_19200;
kevin1990 29:57edca10d78c 2521 break;
kevin1990 29:57edca10d78c 2522 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_UART_BAUD_RATE_9600:
kevin1990 29:57edca10d78c 2523 digitalSensorComms.Uart_Baud = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_UART_9600;
kevin1990 29:57edca10d78c 2524 break;
kevin1990 29:57edca10d78c 2525 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_UART_BAUD_RATE_4800:
kevin1990 29:57edca10d78c 2526 digitalSensorComms.Uart_Baud = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_UART_4800;
kevin1990 29:57edca10d78c 2527 break;
kevin1990 29:57edca10d78c 2528 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_UART_BAUD_RATE_2400:
kevin1990 29:57edca10d78c 2529 digitalSensorComms.Uart_Baud = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_UART_2400;
kevin1990 29:57edca10d78c 2530 break;
kevin1990 29:57edca10d78c 2531 case ADI_SENSE_1000_DIGITAL_SENSOR_COMMS_UART_BAUD_RATE_1200:
kevin1990 29:57edca10d78c 2532 digitalSensorComms.Uart_Baud = ADISENSE_CORE_DIGITAL_SENSOR_COMMS_UART_1200;
kevin1990 29:57edca10d78c 2533 break;
kevin1990 29:57edca10d78c 2534 default:
kevin1990 29:57edca10d78c 2535 ADI_SENSE_LOG_ERROR("Invalid UART baud rate %d specified",
kevin1990 29:57edca10d78c 2536 pDigitalComms->uartBaudRate);
kevin1990 29:57edca10d78c 2537 return ADI_SENSE_INVALID_PARAM;
kevin1990 29:57edca10d78c 2538 }
kevin1990 29:57edca10d78c 2539 }
kevin1990 29:57edca10d78c 2540 else
kevin1990 29:57edca10d78c 2541 {
kevin1990 29:57edca10d78c 2542 digitalSensorComms.Digital_Sensor_Comms_En = 0;
kevin1990 29:57edca10d78c 2543 }
kevin1990 29:57edca10d78c 2544
kevin1990 29:57edca10d78c 2545 WRITE_REG_U16(hDevice, digitalSensorComms.VALUE16, CORE_DIGITAL_SENSOR_COMMSn(eChannelId));
kevin1990 29:57edca10d78c 2546
kevin1990 29:57edca10d78c 2547 return ADI_SENSE_SUCCESS;
kevin1990 29:57edca10d78c 2548 }
kevin1990 29:57edca10d78c 2549
Dan O'Donovan 27:567abf893938 2550 ADI_SENSE_RESULT adi_sense_SetI2cChannelConfig(
Dan O'Donovan 27:567abf893938 2551 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 2552 ADI_SENSE_1000_CHANNEL_ID eChannelId,
kevin1990 29:57edca10d78c 2553 ADI_SENSE_1000_CHANNEL_CONFIG *pChannelConfig)
Dan O'Donovan 27:567abf893938 2554 {
Dan O'Donovan 27:567abf893938 2555 ADI_SENSE_RESULT eRet;
kevin1990 29:57edca10d78c 2556 ADI_SENSE_1000_I2C_CHANNEL_CONFIG *pI2cChannelConfig =
kevin1990 29:57edca10d78c 2557 &pChannelConfig->i2cChannelConfig;
Dan O'Donovan 27:567abf893938 2558
Dan O'Donovan 27:567abf893938 2559 eRet = adi_sense_SetChannelI2cSensorType(hDevice, eChannelId,
Dan O'Donovan 27:567abf893938 2560 pI2cChannelConfig->sensor);
Dan O'Donovan 27:567abf893938 2561 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 2562 {
Dan O'Donovan 27:567abf893938 2563 ADI_SENSE_LOG_ERROR("Failed to set I2C sensor type for channel %d",
Dan O'Donovan 27:567abf893938 2564 eChannelId);
Dan O'Donovan 27:567abf893938 2565 return eRet;
Dan O'Donovan 27:567abf893938 2566 }
Dan O'Donovan 27:567abf893938 2567
Dan O'Donovan 27:567abf893938 2568 eRet = adi_sense_SetChannelI2cSensorAddress(hDevice, eChannelId,
Dan O'Donovan 27:567abf893938 2569 pI2cChannelConfig->deviceAddress);
Dan O'Donovan 27:567abf893938 2570 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 2571 {
Dan O'Donovan 27:567abf893938 2572 ADI_SENSE_LOG_ERROR("Failed to set I2C sensor address for channel %d",
Dan O'Donovan 27:567abf893938 2573 eChannelId);
Dan O'Donovan 27:567abf893938 2574 return eRet;
Dan O'Donovan 27:567abf893938 2575 }
Dan O'Donovan 27:567abf893938 2576
kevin1990 29:57edca10d78c 2577 eRet = adi_sense_SetChannelDigitalSensorDetails(hDevice, eChannelId,
kevin1990 29:57edca10d78c 2578 pChannelConfig);
kevin1990 29:57edca10d78c 2579 if (eRet != ADI_SENSE_SUCCESS)
kevin1990 29:57edca10d78c 2580 {
kevin1990 29:57edca10d78c 2581 ADI_SENSE_LOG_ERROR("Failed to set I2C sensor details for channel %d",
kevin1990 29:57edca10d78c 2582 eChannelId);
kevin1990 29:57edca10d78c 2583 return eRet;
kevin1990 29:57edca10d78c 2584 }
kevin1990 29:57edca10d78c 2585
Dan O'Donovan 27:567abf893938 2586 eRet = adi_sense_SetDigitalSensorCommands(hDevice, eChannelId,
Dan O'Donovan 27:567abf893938 2587 &pI2cChannelConfig->configurationCommand,
Dan O'Donovan 27:567abf893938 2588 &pI2cChannelConfig->dataRequestCommand);
Dan O'Donovan 27:567abf893938 2589 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 2590 {
Dan O'Donovan 27:567abf893938 2591 ADI_SENSE_LOG_ERROR("Failed to set I2C sensor commands for channel %d",
Dan O'Donovan 27:567abf893938 2592 eChannelId);
Dan O'Donovan 27:567abf893938 2593 return eRet;
Dan O'Donovan 27:567abf893938 2594 }
Dan O'Donovan 27:567abf893938 2595
Dan O'Donovan 27:567abf893938 2596 eRet = adi_sense_SetDigitalSensorFormat(hDevice, eChannelId,
Dan O'Donovan 27:567abf893938 2597 &pI2cChannelConfig->dataFormat);
Dan O'Donovan 27:567abf893938 2598 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 2599 {
Dan O'Donovan 27:567abf893938 2600 ADI_SENSE_LOG_ERROR("Failed to set I2C sensor data format for channel %d",
Dan O'Donovan 27:567abf893938 2601 eChannelId);
Dan O'Donovan 27:567abf893938 2602 return eRet;
Dan O'Donovan 27:567abf893938 2603 }
Dan O'Donovan 27:567abf893938 2604
kevin1990 29:57edca10d78c 2605 eRet = adi_sense_SetDigitalCalibrationParam(hDevice, eChannelId,
kevin1990 29:57edca10d78c 2606 &pI2cChannelConfig->digitalCalibrationParam);
kevin1990 29:57edca10d78c 2607 if (eRet != ADI_SENSE_SUCCESS)
kevin1990 29:57edca10d78c 2608 {
kevin1990 29:57edca10d78c 2609 ADI_SENSE_LOG_ERROR("Failed to set I2C digital calibration param for channel %d",
kevin1990 29:57edca10d78c 2610 eChannelId);
kevin1990 29:57edca10d78c 2611 return eRet;
kevin1990 29:57edca10d78c 2612 }
kevin1990 29:57edca10d78c 2613
kevin1990 29:57edca10d78c 2614 eRet = adi_sense_SetDigitalChannelComms(hDevice, eChannelId,
kevin1990 29:57edca10d78c 2615 &pI2cChannelConfig->configureComms);
kevin1990 29:57edca10d78c 2616 if (eRet != ADI_SENSE_SUCCESS)
kevin1990 29:57edca10d78c 2617 {
kevin1990 29:57edca10d78c 2618 ADI_SENSE_LOG_ERROR("Failed to set I2C comms for channel %d",
kevin1990 29:57edca10d78c 2619 eChannelId);
kevin1990 29:57edca10d78c 2620 return eRet;
kevin1990 29:57edca10d78c 2621 }
kevin1990 29:57edca10d78c 2622
Dan O'Donovan 27:567abf893938 2623 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 2624 }
Dan O'Donovan 27:567abf893938 2625
Dan O'Donovan 27:567abf893938 2626 static ADI_SENSE_RESULT adi_sense_SetChannelSpiSensorType(
Dan O'Donovan 27:567abf893938 2627 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 2628 ADI_SENSE_1000_CHANNEL_ID eChannelId,
Dan O'Donovan 27:567abf893938 2629 ADI_SENSE_1000_SPI_SENSOR_TYPE sensorType)
Dan O'Donovan 27:567abf893938 2630 {
Dan O'Donovan 27:567abf893938 2631 ADI_ADISENSE_CORE_Sensor_Type_t sensorTypeReg;
Dan O'Donovan 27:567abf893938 2632
Dan O'Donovan 27:567abf893938 2633 sensorTypeReg.VALUE16 = REG_RESET_VAL(CORE_SENSOR_TYPEn);
Dan O'Donovan 27:567abf893938 2634
Dan O'Donovan 27:567abf893938 2635 /* Ensure that the sensor type is valid for this channel */
Dan O'Donovan 27:567abf893938 2636 switch(sensorType)
Dan O'Donovan 27:567abf893938 2637 {
kevin1990 29:57edca10d78c 2638 case ADI_SENSE_1000_SPI_SENSOR_PRESSURE_A_DEF_L1:
kevin1990 29:57edca10d78c 2639 case ADI_SENSE_1000_SPI_SENSOR_PRESSURE_A_DEF_L2:
kevin1990 29:57edca10d78c 2640 case ADI_SENSE_1000_SPI_SENSOR_PRESSURE_A_ADV_L1:
kevin1990 29:57edca10d78c 2641 case ADI_SENSE_1000_SPI_SENSOR_PRESSURE_A_ADV_L2:
kevin1990 29:57edca10d78c 2642 case ADI_SENSE_1000_SPI_SENSOR_ACCELEROMETER_A_DEF_L1:
kevin1990 29:57edca10d78c 2643 case ADI_SENSE_1000_SPI_SENSOR_ACCELEROMETER_B_DEF_L1:
kevin1990 29:57edca10d78c 2644 case ADI_SENSE_1000_SPI_SENSOR_ACCELEROMETER_A_DEF_L2:
kevin1990 29:57edca10d78c 2645 case ADI_SENSE_1000_SPI_SENSOR_ACCELEROMETER_B_DEF_L2:
kevin1990 29:57edca10d78c 2646 case ADI_SENSE_1000_SPI_SENSOR_ACCELEROMETER_A_ADV_L1:
kevin1990 29:57edca10d78c 2647 case ADI_SENSE_1000_SPI_SENSOR_ACCELEROMETER_B_ADV_L1:
kevin1990 29:57edca10d78c 2648 case ADI_SENSE_1000_SPI_SENSOR_ACCELEROMETER_A_ADV_L2:
kevin1990 29:57edca10d78c 2649 case ADI_SENSE_1000_SPI_SENSOR_ACCELEROMETER_B_ADV_L2:
kevin1990 29:57edca10d78c 2650 sensorTypeReg.Sensor_Type = sensorType;
Dan O'Donovan 27:567abf893938 2651 break;
Dan O'Donovan 27:567abf893938 2652 default:
Dan O'Donovan 27:567abf893938 2653 ADI_SENSE_LOG_ERROR("Unsupported SPI sensor type %d specified", sensorType);
Dan O'Donovan 27:567abf893938 2654 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 2655 }
Dan O'Donovan 27:567abf893938 2656
Dan O'Donovan 27:567abf893938 2657 WRITE_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(eChannelId));
Dan O'Donovan 27:567abf893938 2658
Dan O'Donovan 27:567abf893938 2659 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 2660 }
Dan O'Donovan 27:567abf893938 2661
Dan O'Donovan 27:567abf893938 2662 ADI_SENSE_RESULT adi_sense_SetSpiChannelConfig(
Dan O'Donovan 27:567abf893938 2663 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 2664 ADI_SENSE_1000_CHANNEL_ID eChannelId,
kevin1990 29:57edca10d78c 2665 ADI_SENSE_1000_CHANNEL_CONFIG *pChannelConfig)
Dan O'Donovan 27:567abf893938 2666 {
Dan O'Donovan 27:567abf893938 2667 ADI_SENSE_RESULT eRet;
kevin1990 29:57edca10d78c 2668 ADI_SENSE_1000_SPI_CHANNEL_CONFIG *pSpiChannelConfig =
kevin1990 29:57edca10d78c 2669 &pChannelConfig->spiChannelConfig;
Dan O'Donovan 27:567abf893938 2670
Dan O'Donovan 27:567abf893938 2671 eRet = adi_sense_SetChannelSpiSensorType(hDevice, eChannelId,
Dan O'Donovan 27:567abf893938 2672 pSpiChannelConfig->sensor);
Dan O'Donovan 27:567abf893938 2673 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 2674 {
Dan O'Donovan 27:567abf893938 2675 ADI_SENSE_LOG_ERROR("Failed to set SPI sensor type for channel %d",
Dan O'Donovan 27:567abf893938 2676 eChannelId);
Dan O'Donovan 27:567abf893938 2677 return eRet;
Dan O'Donovan 27:567abf893938 2678 }
Dan O'Donovan 27:567abf893938 2679
kevin1990 29:57edca10d78c 2680 eRet = adi_sense_SetChannelDigitalSensorDetails(hDevice, eChannelId,
kevin1990 29:57edca10d78c 2681 pChannelConfig);
kevin1990 29:57edca10d78c 2682 if (eRet != ADI_SENSE_SUCCESS)
kevin1990 29:57edca10d78c 2683 {
kevin1990 29:57edca10d78c 2684 ADI_SENSE_LOG_ERROR("Failed to set SPI sensor details for channel %d",
kevin1990 29:57edca10d78c 2685 eChannelId);
kevin1990 29:57edca10d78c 2686 return eRet;
kevin1990 29:57edca10d78c 2687 }
kevin1990 29:57edca10d78c 2688
Dan O'Donovan 27:567abf893938 2689 eRet = adi_sense_SetDigitalSensorCommands(hDevice, eChannelId,
Dan O'Donovan 27:567abf893938 2690 &pSpiChannelConfig->configurationCommand,
Dan O'Donovan 27:567abf893938 2691 &pSpiChannelConfig->dataRequestCommand);
Dan O'Donovan 27:567abf893938 2692 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 2693 {
Dan O'Donovan 27:567abf893938 2694 ADI_SENSE_LOG_ERROR("Failed to set SPI sensor commands for channel %d",
Dan O'Donovan 27:567abf893938 2695 eChannelId);
Dan O'Donovan 27:567abf893938 2696 return eRet;
Dan O'Donovan 27:567abf893938 2697 }
Dan O'Donovan 27:567abf893938 2698
Dan O'Donovan 27:567abf893938 2699 eRet = adi_sense_SetDigitalSensorFormat(hDevice, eChannelId,
Dan O'Donovan 27:567abf893938 2700 &pSpiChannelConfig->dataFormat);
Dan O'Donovan 27:567abf893938 2701 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 2702 {
Dan O'Donovan 27:567abf893938 2703 ADI_SENSE_LOG_ERROR("Failed to set SPI sensor data format for channel %d",
Dan O'Donovan 27:567abf893938 2704 eChannelId);
Dan O'Donovan 27:567abf893938 2705 return eRet;
Dan O'Donovan 27:567abf893938 2706 }
Dan O'Donovan 27:567abf893938 2707
kevin1990 29:57edca10d78c 2708 eRet = adi_sense_SetDigitalCalibrationParam(hDevice, eChannelId,
kevin1990 29:57edca10d78c 2709 &pSpiChannelConfig->digitalCalibrationParam);
kevin1990 29:57edca10d78c 2710 if (eRet != ADI_SENSE_SUCCESS)
kevin1990 29:57edca10d78c 2711 {
kevin1990 29:57edca10d78c 2712 ADI_SENSE_LOG_ERROR("Failed to set SPI digital calibration param for channel %d",
kevin1990 29:57edca10d78c 2713 eChannelId);
kevin1990 29:57edca10d78c 2714 return eRet;
kevin1990 29:57edca10d78c 2715 }
kevin1990 29:57edca10d78c 2716
kevin1990 29:57edca10d78c 2717 eRet = adi_sense_SetDigitalChannelComms(hDevice, eChannelId,
kevin1990 29:57edca10d78c 2718 &pSpiChannelConfig->configureComms);
kevin1990 29:57edca10d78c 2719 if (eRet != ADI_SENSE_SUCCESS)
kevin1990 29:57edca10d78c 2720 {
kevin1990 29:57edca10d78c 2721 ADI_SENSE_LOG_ERROR("Failed to set SPI comms for channel %d",
kevin1990 29:57edca10d78c 2722 eChannelId);
kevin1990 29:57edca10d78c 2723 return eRet;
kevin1990 29:57edca10d78c 2724 }
kevin1990 29:57edca10d78c 2725
kevin1990 29:57edca10d78c 2726 return ADI_SENSE_SUCCESS;
kevin1990 29:57edca10d78c 2727 }
kevin1990 29:57edca10d78c 2728
kevin1990 29:57edca10d78c 2729 static ADI_SENSE_RESULT adi_sense_SetChannelUartSensorType(
kevin1990 29:57edca10d78c 2730 ADI_SENSE_DEVICE_HANDLE hDevice,
kevin1990 29:57edca10d78c 2731 ADI_SENSE_1000_CHANNEL_ID eChannelId,
kevin1990 29:57edca10d78c 2732 ADI_SENSE_1000_UART_SENSOR_TYPE sensorType)
kevin1990 29:57edca10d78c 2733 {
kevin1990 29:57edca10d78c 2734 ADI_ADISENSE_CORE_Sensor_Type_t sensorTypeReg;
kevin1990 29:57edca10d78c 2735
kevin1990 29:57edca10d78c 2736 sensorTypeReg.VALUE16 = REG_RESET_VAL(CORE_SENSOR_TYPEn);
kevin1990 29:57edca10d78c 2737
kevin1990 29:57edca10d78c 2738 /* Ensure that the sensor type is valid for this channel */
kevin1990 29:57edca10d78c 2739 switch(sensorType)
kevin1990 29:57edca10d78c 2740 {
kevin1990 29:57edca10d78c 2741 case ADI_SENSE_1000_UART_SENSOR_UART_CO2_A_DEF_L1:
kevin1990 29:57edca10d78c 2742 case ADI_SENSE_1000_UART_SENSOR_UART_CO2_B_DEF_L1:
kevin1990 29:57edca10d78c 2743 case ADI_SENSE_1000_UART_SENSOR_UART_CO2_A_DEF_L2:
kevin1990 29:57edca10d78c 2744 case ADI_SENSE_1000_UART_SENSOR_UART_CO2_B_DEF_L2:
kevin1990 29:57edca10d78c 2745 case ADI_SENSE_1000_UART_SENSOR_UART_CO2_A_ADV_L1:
kevin1990 29:57edca10d78c 2746 case ADI_SENSE_1000_UART_SENSOR_UART_CO2_B_ADV_L1:
kevin1990 29:57edca10d78c 2747 case ADI_SENSE_1000_UART_SENSOR_UART_CO2_A_ADV_L2:
kevin1990 29:57edca10d78c 2748 case ADI_SENSE_1000_UART_SENSOR_UART_CO2_B_ADV_L2:
kevin1990 29:57edca10d78c 2749 sensorTypeReg.Sensor_Type = sensorType;
kevin1990 29:57edca10d78c 2750 break;
kevin1990 29:57edca10d78c 2751 default:
kevin1990 29:57edca10d78c 2752 ADI_SENSE_LOG_ERROR("Unsupported UART sensor type %d specified", sensorType);
kevin1990 29:57edca10d78c 2753 return ADI_SENSE_INVALID_PARAM;
kevin1990 29:57edca10d78c 2754 }
kevin1990 29:57edca10d78c 2755
kevin1990 29:57edca10d78c 2756 WRITE_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(eChannelId));
kevin1990 29:57edca10d78c 2757
kevin1990 29:57edca10d78c 2758 return ADI_SENSE_SUCCESS;
kevin1990 29:57edca10d78c 2759 }
kevin1990 29:57edca10d78c 2760
kevin1990 29:57edca10d78c 2761 ADI_SENSE_RESULT adi_sense_SetUartChannelConfig(
kevin1990 29:57edca10d78c 2762 ADI_SENSE_DEVICE_HANDLE hDevice,
kevin1990 29:57edca10d78c 2763 ADI_SENSE_1000_CHANNEL_ID eChannelId,
kevin1990 29:57edca10d78c 2764 ADI_SENSE_1000_CHANNEL_CONFIG *pChannelConfig)
kevin1990 29:57edca10d78c 2765 {
kevin1990 29:57edca10d78c 2766 ADI_SENSE_RESULT eRet;
kevin1990 29:57edca10d78c 2767 ADI_SENSE_1000_UART_CHANNEL_CONFIG *pUartChannelConfig =
kevin1990 29:57edca10d78c 2768 &pChannelConfig->uartChannelConfig;
kevin1990 29:57edca10d78c 2769
kevin1990 29:57edca10d78c 2770 eRet = adi_sense_SetChannelUartSensorType(hDevice, eChannelId,
kevin1990 29:57edca10d78c 2771 pUartChannelConfig->sensor);
kevin1990 29:57edca10d78c 2772 if (eRet != ADI_SENSE_SUCCESS)
kevin1990 29:57edca10d78c 2773 {
kevin1990 29:57edca10d78c 2774 ADI_SENSE_LOG_ERROR("Failed to set UART sensor type for channel %d",
kevin1990 29:57edca10d78c 2775 eChannelId);
kevin1990 29:57edca10d78c 2776 return eRet;
kevin1990 29:57edca10d78c 2777 }
kevin1990 29:57edca10d78c 2778
kevin1990 29:57edca10d78c 2779 eRet = adi_sense_SetChannelDigitalSensorDetails(hDevice, eChannelId,
kevin1990 29:57edca10d78c 2780 pChannelConfig);
kevin1990 29:57edca10d78c 2781 if (eRet != ADI_SENSE_SUCCESS)
kevin1990 29:57edca10d78c 2782 {
kevin1990 29:57edca10d78c 2783 ADI_SENSE_LOG_ERROR("Failed to set UART sensor details for channel %d",
kevin1990 29:57edca10d78c 2784 eChannelId);
kevin1990 29:57edca10d78c 2785 return eRet;
kevin1990 29:57edca10d78c 2786 }
kevin1990 29:57edca10d78c 2787
kevin1990 29:57edca10d78c 2788 eRet = adi_sense_SetDigitalCalibrationParam(hDevice, eChannelId,
kevin1990 29:57edca10d78c 2789 &pUartChannelConfig->digitalCalibrationParam);
kevin1990 29:57edca10d78c 2790 if (eRet != ADI_SENSE_SUCCESS)
kevin1990 29:57edca10d78c 2791 {
kevin1990 29:57edca10d78c 2792 ADI_SENSE_LOG_ERROR("Failed to set UART digital calibration param for channel %d",
kevin1990 29:57edca10d78c 2793 eChannelId);
kevin1990 29:57edca10d78c 2794 return eRet;
kevin1990 29:57edca10d78c 2795 }
kevin1990 29:57edca10d78c 2796
kevin1990 29:57edca10d78c 2797 eRet = adi_sense_SetDigitalChannelComms(hDevice, eChannelId,
kevin1990 29:57edca10d78c 2798 &pUartChannelConfig->configureComms);
kevin1990 29:57edca10d78c 2799 if (eRet != ADI_SENSE_SUCCESS)
kevin1990 29:57edca10d78c 2800 {
kevin1990 29:57edca10d78c 2801 ADI_SENSE_LOG_ERROR("Failed to set UART comms for channel %d",
kevin1990 29:57edca10d78c 2802 eChannelId);
kevin1990 29:57edca10d78c 2803 return eRet;
kevin1990 29:57edca10d78c 2804 }
kevin1990 29:57edca10d78c 2805
kevin1990 29:57edca10d78c 2806
Dan O'Donovan 27:567abf893938 2807 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 2808 }
Dan O'Donovan 27:567abf893938 2809
Dan O'Donovan 27:567abf893938 2810 ADI_SENSE_RESULT adi_sense_1000_SetChannelThresholdLimits(
Dan O'Donovan 27:567abf893938 2811 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 2812 ADI_SENSE_1000_CHANNEL_ID eChannelId,
Dan O'Donovan 27:567abf893938 2813 float32_t fHighThresholdLimit,
Dan O'Donovan 27:567abf893938 2814 float32_t fLowThresholdLimit)
Dan O'Donovan 27:567abf893938 2815 {
Dan O'Donovan 27:567abf893938 2816 /*
Dan O'Donovan 27:567abf893938 2817 * If the low/high limits are *both* set to 0 in memory, or NaNs, assume
Dan O'Donovan 27:567abf893938 2818 * that they are unset, or not required, and use infinity defaults instead
Dan O'Donovan 27:567abf893938 2819 */
Dan O'Donovan 27:567abf893938 2820 if (fHighThresholdLimit == 0.0f && fLowThresholdLimit == 0.0f)
Dan O'Donovan 27:567abf893938 2821 {
Dan O'Donovan 27:567abf893938 2822 fHighThresholdLimit = INFINITY;
Dan O'Donovan 27:567abf893938 2823 fLowThresholdLimit = -INFINITY;
Dan O'Donovan 27:567abf893938 2824 }
Dan O'Donovan 27:567abf893938 2825 else
Dan O'Donovan 27:567abf893938 2826 {
Dan O'Donovan 27:567abf893938 2827 if (isnan(fHighThresholdLimit))
Dan O'Donovan 27:567abf893938 2828 fHighThresholdLimit = INFINITY;
Dan O'Donovan 27:567abf893938 2829 if (isnan(fLowThresholdLimit))
Dan O'Donovan 27:567abf893938 2830 fLowThresholdLimit = -INFINITY;
Dan O'Donovan 27:567abf893938 2831 }
Dan O'Donovan 27:567abf893938 2832
Dan O'Donovan 27:567abf893938 2833 WRITE_REG_FLOAT(hDevice, fHighThresholdLimit,
Dan O'Donovan 27:567abf893938 2834 CORE_HIGH_THRESHOLD_LIMITn(eChannelId));
Dan O'Donovan 27:567abf893938 2835 WRITE_REG_FLOAT(hDevice, fLowThresholdLimit,
Dan O'Donovan 27:567abf893938 2836 CORE_LOW_THRESHOLD_LIMITn(eChannelId));
Dan O'Donovan 27:567abf893938 2837
Dan O'Donovan 27:567abf893938 2838 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 2839 }
Dan O'Donovan 27:567abf893938 2840
Dan O'Donovan 27:567abf893938 2841 ADI_SENSE_RESULT adi_sense_1000_SetOffsetGain(
Dan O'Donovan 27:567abf893938 2842 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 2843 ADI_SENSE_1000_CHANNEL_ID eChannelId,
Dan O'Donovan 27:567abf893938 2844 float32_t fOffsetAdjustment,
Dan O'Donovan 27:567abf893938 2845 float32_t fGainAdjustment)
Dan O'Donovan 27:567abf893938 2846 {
Dan O'Donovan 27:567abf893938 2847 /* Replace with default values if NaNs are specified (or 0.0 for gain) */
Dan O'Donovan 27:567abf893938 2848 if (isnan(fGainAdjustment) || (fGainAdjustment == 0.0f))
Dan O'Donovan 27:567abf893938 2849 fGainAdjustment = 1.0f;
Dan O'Donovan 27:567abf893938 2850 if (isnan(fOffsetAdjustment))
Dan O'Donovan 27:567abf893938 2851 fOffsetAdjustment = 0.0f;
Dan O'Donovan 27:567abf893938 2852
Dan O'Donovan 27:567abf893938 2853 WRITE_REG_FLOAT(hDevice, fGainAdjustment, CORE_SENSOR_GAINn(eChannelId));
Dan O'Donovan 27:567abf893938 2854 WRITE_REG_FLOAT(hDevice, fOffsetAdjustment, CORE_SENSOR_OFFSETn(eChannelId));
Dan O'Donovan 27:567abf893938 2855
Dan O'Donovan 27:567abf893938 2856 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 2857 }
Dan O'Donovan 27:567abf893938 2858
Dan O'Donovan 27:567abf893938 2859 ADI_SENSE_RESULT adi_sense_1000_SetSensorParameter(
Dan O'Donovan 27:567abf893938 2860 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 2861 ADI_SENSE_1000_CHANNEL_ID eChannelId,
Dan O'Donovan 27:567abf893938 2862 float32_t fSensorParam)
Dan O'Donovan 27:567abf893938 2863 {
Dan O'Donovan 30:119ff4f3aef6 2864 if (fSensorParam == 0.0f)
Dan O'Donovan 27:567abf893938 2865 fSensorParam = NAN;
Dan O'Donovan 27:567abf893938 2866
Dan O'Donovan 27:567abf893938 2867 WRITE_REG_FLOAT(hDevice, fSensorParam, CORE_SENSOR_PARAMETERn(eChannelId));
Dan O'Donovan 27:567abf893938 2868
Dan O'Donovan 27:567abf893938 2869 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 2870 }
Dan O'Donovan 27:567abf893938 2871
Dan O'Donovan 27:567abf893938 2872 ADI_SENSE_RESULT adi_sense_1000_SetChannelSettlingTime(
Dan O'Donovan 27:567abf893938 2873 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 2874 ADI_SENSE_1000_CHANNEL_ID eChannelId,
Dan O'Donovan 27:567abf893938 2875 uint32_t nSettlingTime)
Dan O'Donovan 27:567abf893938 2876 {
Dan O'Donovan 27:567abf893938 2877 ADI_ADISENSE_CORE_Settling_Time_t settlingTimeReg;
Dan O'Donovan 27:567abf893938 2878
Dan O'Donovan 27:567abf893938 2879 if (nSettlingTime < (1 << 12))
Dan O'Donovan 27:567abf893938 2880 {
Dan O'Donovan 27:567abf893938 2881 settlingTimeReg.Settling_Time_Units = ADISENSE_CORE_SETTLING_TIME_MICROSECONDS;
Dan O'Donovan 27:567abf893938 2882 }
Dan O'Donovan 27:567abf893938 2883 else if (nSettlingTime < (1000 * (1 << 12)))
Dan O'Donovan 27:567abf893938 2884 {
Dan O'Donovan 27:567abf893938 2885 settlingTimeReg.Settling_Time_Units = ADISENSE_CORE_SETTLING_TIME_MILLISECONDS;
Dan O'Donovan 27:567abf893938 2886 nSettlingTime /= 1000;
Dan O'Donovan 27:567abf893938 2887 }
Dan O'Donovan 27:567abf893938 2888 else
Dan O'Donovan 27:567abf893938 2889 {
Dan O'Donovan 27:567abf893938 2890 settlingTimeReg.Settling_Time_Units = ADISENSE_CORE_SETTLING_TIME_SECONDS;
Dan O'Donovan 27:567abf893938 2891 nSettlingTime /= 1000000;
Dan O'Donovan 27:567abf893938 2892 }
Dan O'Donovan 27:567abf893938 2893
Dan O'Donovan 27:567abf893938 2894 CHECK_REG_FIELD_VAL(CORE_SETTLING_TIME_SETTLING_TIME, nSettlingTime);
Dan O'Donovan 27:567abf893938 2895 settlingTimeReg.Settling_Time = nSettlingTime;
Dan O'Donovan 27:567abf893938 2896
Dan O'Donovan 27:567abf893938 2897 WRITE_REG_U16(hDevice, settlingTimeReg.VALUE16, CORE_SETTLING_TIMEn(eChannelId));
Dan O'Donovan 27:567abf893938 2898
Dan O'Donovan 27:567abf893938 2899 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 2900 }
Dan O'Donovan 27:567abf893938 2901
Dan O'Donovan 27:567abf893938 2902 ADI_SENSE_RESULT adi_sense_1000_SetChannelConfig(
Dan O'Donovan 27:567abf893938 2903 ADI_SENSE_DEVICE_HANDLE hDevice,
Dan O'Donovan 27:567abf893938 2904 ADI_SENSE_1000_CHANNEL_ID eChannelId,
Dan O'Donovan 27:567abf893938 2905 ADI_SENSE_1000_CHANNEL_CONFIG *pChannelConfig)
Dan O'Donovan 27:567abf893938 2906 {
Dan O'Donovan 27:567abf893938 2907 ADI_SENSE_RESULT eRet;
Dan O'Donovan 27:567abf893938 2908
Dan O'Donovan 27:567abf893938 2909 if (! ADI_SENSE_1000_CHANNEL_IS_VIRTUAL(eChannelId))
Dan O'Donovan 27:567abf893938 2910 {
Dan O'Donovan 27:567abf893938 2911 eRet = adi_sense_1000_SetChannelCount(hDevice, eChannelId,
Dan O'Donovan 30:119ff4f3aef6 2912 pChannelConfig->enableChannel ?
Dan O'Donovan 30:119ff4f3aef6 2913 pChannelConfig->measurementsPerCycle : 0);
Dan O'Donovan 27:567abf893938 2914 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 2915 {
Dan O'Donovan 27:567abf893938 2916 ADI_SENSE_LOG_ERROR("Failed to set measurement count for channel %d",
Dan O'Donovan 27:567abf893938 2917 eChannelId);
Dan O'Donovan 27:567abf893938 2918 return eRet;
Dan O'Donovan 27:567abf893938 2919 }
Dan O'Donovan 27:567abf893938 2920
Dan O'Donovan 27:567abf893938 2921 eRet = adi_sense_1000_SetChannelOptions(hDevice, eChannelId,
Dan O'Donovan 27:567abf893938 2922 pChannelConfig->priority,
Dan O'Donovan 27:567abf893938 2923 pChannelConfig->enableFFT);
Dan O'Donovan 27:567abf893938 2924 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 2925 {
Dan O'Donovan 27:567abf893938 2926 ADI_SENSE_LOG_ERROR("Failed to set priority for channel %d",
Dan O'Donovan 27:567abf893938 2927 eChannelId);
Dan O'Donovan 27:567abf893938 2928 return eRet;
Dan O'Donovan 27:567abf893938 2929 }
Dan O'Donovan 27:567abf893938 2930
Dan O'Donovan 30:119ff4f3aef6 2931 /* If the channel is not enabled, we can skip the following steps */
Dan O'Donovan 30:119ff4f3aef6 2932 if (pChannelConfig->enableChannel || pChannelConfig->enableFFT)
Dan O'Donovan 27:567abf893938 2933 {
Dan O'Donovan 30:119ff4f3aef6 2934 eRet = adi_sense_1000_SetChannelSkipCount(hDevice, eChannelId,
Dan O'Donovan 30:119ff4f3aef6 2935 pChannelConfig->cycleSkipCount);
Dan O'Donovan 30:119ff4f3aef6 2936 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 30:119ff4f3aef6 2937 {
Dan O'Donovan 30:119ff4f3aef6 2938 ADI_SENSE_LOG_ERROR("Failed to set cycle skip count for channel %d",
Dan O'Donovan 30:119ff4f3aef6 2939 eChannelId);
Dan O'Donovan 30:119ff4f3aef6 2940 return eRet;
Dan O'Donovan 30:119ff4f3aef6 2941 }
Dan O'Donovan 30:119ff4f3aef6 2942
Dan O'Donovan 30:119ff4f3aef6 2943 switch (eChannelId)
Dan O'Donovan 30:119ff4f3aef6 2944 {
Dan O'Donovan 30:119ff4f3aef6 2945 case ADI_SENSE_1000_CHANNEL_ID_CJC_0:
Dan O'Donovan 30:119ff4f3aef6 2946 case ADI_SENSE_1000_CHANNEL_ID_CJC_1:
Dan O'Donovan 30:119ff4f3aef6 2947 case ADI_SENSE_1000_CHANNEL_ID_SENSOR_0:
Dan O'Donovan 30:119ff4f3aef6 2948 case ADI_SENSE_1000_CHANNEL_ID_SENSOR_1:
Dan O'Donovan 30:119ff4f3aef6 2949 case ADI_SENSE_1000_CHANNEL_ID_SENSOR_2:
Dan O'Donovan 30:119ff4f3aef6 2950 case ADI_SENSE_1000_CHANNEL_ID_SENSOR_3:
Dan O'Donovan 30:119ff4f3aef6 2951 case ADI_SENSE_1000_CHANNEL_ID_VOLTAGE_0:
Dan O'Donovan 30:119ff4f3aef6 2952 case ADI_SENSE_1000_CHANNEL_ID_CURRENT_0:
Dan O'Donovan 30:119ff4f3aef6 2953 eRet = adi_sense_SetAdcChannelConfig(hDevice, eChannelId, pChannelConfig);
Dan O'Donovan 30:119ff4f3aef6 2954 break;
Dan O'Donovan 30:119ff4f3aef6 2955 case ADI_SENSE_1000_CHANNEL_ID_I2C_0:
Dan O'Donovan 30:119ff4f3aef6 2956 case ADI_SENSE_1000_CHANNEL_ID_I2C_1:
Dan O'Donovan 30:119ff4f3aef6 2957 eRet = adi_sense_SetI2cChannelConfig(hDevice, eChannelId, pChannelConfig);
Dan O'Donovan 30:119ff4f3aef6 2958 break;
Dan O'Donovan 30:119ff4f3aef6 2959 case ADI_SENSE_1000_CHANNEL_ID_SPI_0:
Dan O'Donovan 30:119ff4f3aef6 2960 eRet = adi_sense_SetSpiChannelConfig(hDevice, eChannelId, pChannelConfig);
Dan O'Donovan 30:119ff4f3aef6 2961 break;
Dan O'Donovan 30:119ff4f3aef6 2962 case ADI_SENSE_1000_CHANNEL_ID_UART:
Dan O'Donovan 30:119ff4f3aef6 2963 eRet = adi_sense_SetUartChannelConfig(hDevice, eChannelId, pChannelConfig);
Dan O'Donovan 30:119ff4f3aef6 2964 break;
Dan O'Donovan 30:119ff4f3aef6 2965 default:
Dan O'Donovan 30:119ff4f3aef6 2966 ADI_SENSE_LOG_ERROR("Invalid channel ID %d specified", eChannelId);
Dan O'Donovan 30:119ff4f3aef6 2967 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 30:119ff4f3aef6 2968 }
Dan O'Donovan 30:119ff4f3aef6 2969
Dan O'Donovan 30:119ff4f3aef6 2970 eRet = adi_sense_1000_SetChannelSettlingTime(hDevice, eChannelId,
Dan O'Donovan 30:119ff4f3aef6 2971 pChannelConfig->extraSettlingTime);
Dan O'Donovan 30:119ff4f3aef6 2972 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 30:119ff4f3aef6 2973 {
Dan O'Donovan 30:119ff4f3aef6 2974 ADI_SENSE_LOG_ERROR("Failed to set settling time for channel %d",
Dan O'Donovan 30:119ff4f3aef6 2975 eChannelId);
Dan O'Donovan 30:119ff4f3aef6 2976 return eRet;
Dan O'Donovan 30:119ff4f3aef6 2977 }
Dan O'Donovan 27:567abf893938 2978 }
Dan O'Donovan 27:567abf893938 2979 }
Dan O'Donovan 27:567abf893938 2980
Dan O'Donovan 30:119ff4f3aef6 2981 if (pChannelConfig->enableChannel || pChannelConfig->enableFFT)
Dan O'Donovan 27:567abf893938 2982 {
Dan O'Donovan 27:567abf893938 2983 /* Threshold limits can be configured individually for virtual channels */
Dan O'Donovan 27:567abf893938 2984 eRet = adi_sense_1000_SetChannelThresholdLimits(hDevice, eChannelId,
Dan O'Donovan 27:567abf893938 2985 pChannelConfig->highThreshold,
Dan O'Donovan 27:567abf893938 2986 pChannelConfig->lowThreshold);
Dan O'Donovan 27:567abf893938 2987 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 2988 {
Dan O'Donovan 27:567abf893938 2989 ADI_SENSE_LOG_ERROR("Failed to set threshold limits for channel %d",
Dan O'Donovan 27:567abf893938 2990 eChannelId);
Dan O'Donovan 27:567abf893938 2991 return eRet;
Dan O'Donovan 27:567abf893938 2992 }
Dan O'Donovan 27:567abf893938 2993
Dan O'Donovan 27:567abf893938 2994 /* Offset and gain can be configured individually for virtual channels */
Dan O'Donovan 27:567abf893938 2995 eRet = adi_sense_1000_SetOffsetGain(hDevice, eChannelId,
Dan O'Donovan 27:567abf893938 2996 pChannelConfig->offsetAdjustment,
Dan O'Donovan 27:567abf893938 2997 pChannelConfig->gainAdjustment);
Dan O'Donovan 27:567abf893938 2998 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 2999 {
Dan O'Donovan 27:567abf893938 3000 ADI_SENSE_LOG_ERROR("Failed to set offset/gain for channel %d",
Dan O'Donovan 27:567abf893938 3001 eChannelId);
Dan O'Donovan 27:567abf893938 3002 return eRet;
Dan O'Donovan 27:567abf893938 3003 }
Dan O'Donovan 27:567abf893938 3004
Dan O'Donovan 27:567abf893938 3005 /* Set sensor specific parameter */
Dan O'Donovan 27:567abf893938 3006 eRet = adi_sense_1000_SetSensorParameter(hDevice, eChannelId,
Dan O'Donovan 27:567abf893938 3007 pChannelConfig->sensorParameter);
Dan O'Donovan 27:567abf893938 3008 if (eRet != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 3009 {
Dan O'Donovan 27:567abf893938 3010 ADI_SENSE_LOG_ERROR("Failed to set sensor parameter for channel %d",
Dan O'Donovan 27:567abf893938 3011 eChannelId);
Dan O'Donovan 27:567abf893938 3012 return eRet;
Dan O'Donovan 27:567abf893938 3013 }
Dan O'Donovan 27:567abf893938 3014 }
Dan O'Donovan 27:567abf893938 3015
Dan O'Donovan 27:567abf893938 3016 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 3017 }
Dan O'Donovan 27:567abf893938 3018
Dan O'Donovan 27:567abf893938 3019 ADI_SENSE_RESULT adi_sense_SetConfig(
Dan O'Donovan 27:567abf893938 3020 ADI_SENSE_DEVICE_HANDLE const hDevice,
Dan O'Donovan 27:567abf893938 3021 ADI_SENSE_CONFIG * const pConfig)
Dan O'Donovan 27:567abf893938 3022 {
Dan O'Donovan 27:567abf893938 3023 ADI_SENSE_1000_CONFIG *pDeviceConfig;
Dan O'Donovan 27:567abf893938 3024 ADI_SENSE_PRODUCT_ID productId;
Dan O'Donovan 27:567abf893938 3025 ADI_SENSE_RESULT eRet;
Dan O'Donovan 27:567abf893938 3026
Dan O'Donovan 27:567abf893938 3027 if (pConfig->productId != ADI_SENSE_PRODUCT_ID_ADSNS1000)
Dan O'Donovan 27:567abf893938 3028 {
Dan O'Donovan 27:567abf893938 3029 ADI_SENSE_LOG_ERROR("Configuration Product ID (0x%X) is not supported (0x%0X)",
Dan O'Donovan 27:567abf893938 3030 pConfig->productId, ADI_SENSE_PRODUCT_ID_ADSNS1000);
Dan O'Donovan 27:567abf893938 3031 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 3032 }
Dan O'Donovan 27:567abf893938 3033
Dan O'Donovan 27:567abf893938 3034 /* Check that the actual Product ID is a match? */
Dan O'Donovan 27:567abf893938 3035 eRet = adi_sense_GetProductID(hDevice, &productId);
Dan O'Donovan 27:567abf893938 3036 if (eRet)
Dan O'Donovan 27:567abf893938 3037 {
Dan O'Donovan 27:567abf893938 3038 ADI_SENSE_LOG_ERROR("Failed to read device Product ID register");
Dan O'Donovan 27:567abf893938 3039 return eRet;
Dan O'Donovan 27:567abf893938 3040 }
Dan O'Donovan 27:567abf893938 3041 if (pConfig->productId != productId)
Dan O'Donovan 27:567abf893938 3042 {
Dan O'Donovan 27:567abf893938 3043 ADI_SENSE_LOG_ERROR("Configuration Product ID (0x%X) does not match device (0x%0X)",
Dan O'Donovan 27:567abf893938 3044 pConfig->productId, productId);
Dan O'Donovan 27:567abf893938 3045 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 3046 }
Dan O'Donovan 27:567abf893938 3047
Dan O'Donovan 27:567abf893938 3048 pDeviceConfig = &pConfig->adisense1000;
Dan O'Donovan 27:567abf893938 3049
Dan O'Donovan 27:567abf893938 3050 eRet = adi_sense_1000_SetPowerConfig(hDevice, &pDeviceConfig->power);
Dan O'Donovan 27:567abf893938 3051 if (eRet)
Dan O'Donovan 27:567abf893938 3052 {
Dan O'Donovan 27:567abf893938 3053 ADI_SENSE_LOG_ERROR("Failed to set power configuration");
Dan O'Donovan 27:567abf893938 3054 return eRet;
Dan O'Donovan 27:567abf893938 3055 }
Dan O'Donovan 27:567abf893938 3056
Dan O'Donovan 27:567abf893938 3057 eRet = adi_sense_1000_SetMeasurementConfig(hDevice, &pDeviceConfig->measurement);
Dan O'Donovan 27:567abf893938 3058 if (eRet)
Dan O'Donovan 27:567abf893938 3059 {
Dan O'Donovan 27:567abf893938 3060 ADI_SENSE_LOG_ERROR("Failed to set measurement configuration");
Dan O'Donovan 27:567abf893938 3061 return eRet;
Dan O'Donovan 27:567abf893938 3062 }
Dan O'Donovan 27:567abf893938 3063
Dan O'Donovan 27:567abf893938 3064 eRet = adi_sense_1000_SetDiagnosticsConfig(hDevice, &pDeviceConfig->diagnostics);
Dan O'Donovan 27:567abf893938 3065 if (eRet)
Dan O'Donovan 27:567abf893938 3066 {
Dan O'Donovan 27:567abf893938 3067 ADI_SENSE_LOG_ERROR("Failed to set diagnostics configuration");
Dan O'Donovan 27:567abf893938 3068 return eRet;
Dan O'Donovan 27:567abf893938 3069 }
Dan O'Donovan 27:567abf893938 3070
Dan O'Donovan 27:567abf893938 3071 for (ADI_SENSE_1000_CHANNEL_ID id = ADI_SENSE_1000_CHANNEL_ID_CJC_0;
Dan O'Donovan 27:567abf893938 3072 id < ADI_SENSE_1000_MAX_CHANNELS;
Dan O'Donovan 27:567abf893938 3073 id++)
Dan O'Donovan 27:567abf893938 3074 {
Dan O'Donovan 27:567abf893938 3075 eRet = adi_sense_1000_SetChannelConfig(hDevice, id,
Dan O'Donovan 27:567abf893938 3076 &pDeviceConfig->channels[id]);
Dan O'Donovan 27:567abf893938 3077 if (eRet)
Dan O'Donovan 27:567abf893938 3078 {
Dan O'Donovan 27:567abf893938 3079 ADI_SENSE_LOG_ERROR("Failed to set channel %d configuration", id);
Dan O'Donovan 27:567abf893938 3080 return eRet;
Dan O'Donovan 27:567abf893938 3081 }
Dan O'Donovan 27:567abf893938 3082 }
Dan O'Donovan 27:567abf893938 3083
Dan O'Donovan 27:567abf893938 3084 eRet = adi_sense_1000_SetFftConfig(hDevice, &pDeviceConfig->fft,
Dan O'Donovan 27:567abf893938 3085 pDeviceConfig->channels);
Dan O'Donovan 27:567abf893938 3086 if (eRet)
Dan O'Donovan 27:567abf893938 3087 {
Dan O'Donovan 27:567abf893938 3088 ADI_SENSE_LOG_ERROR("Failed to set FFT configuration");
Dan O'Donovan 27:567abf893938 3089 return eRet;
Dan O'Donovan 27:567abf893938 3090 }
Dan O'Donovan 27:567abf893938 3091
Dan O'Donovan 27:567abf893938 3092 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 3093 }
Dan O'Donovan 27:567abf893938 3094
Dan O'Donovan 27:567abf893938 3095 ADI_SENSE_RESULT adi_sense_1000_SetLutData(
Dan O'Donovan 27:567abf893938 3096 ADI_SENSE_DEVICE_HANDLE const hDevice,
Dan O'Donovan 27:567abf893938 3097 ADI_SENSE_1000_LUT * const pLutData)
Dan O'Donovan 27:567abf893938 3098 {
Dan O'Donovan 27:567abf893938 3099 ADI_SENSE_1000_LUT_HEADER *pLutHeader = &pLutData->header;
Dan O'Donovan 27:567abf893938 3100 ADI_SENSE_1000_LUT_TABLE *pLutTable = pLutData->tables;
Dan O'Donovan 27:567abf893938 3101 unsigned actualLength = 0;
Dan O'Donovan 27:567abf893938 3102
Dan O'Donovan 27:567abf893938 3103 if (pLutData->header.signature != ADI_SENSE_LUT_SIGNATURE)
Dan O'Donovan 27:567abf893938 3104 {
Dan O'Donovan 27:567abf893938 3105 ADI_SENSE_LOG_ERROR("LUT signature incorrect (expected 0x%X, actual 0x%X)",
Dan O'Donovan 27:567abf893938 3106 ADI_SENSE_LUT_SIGNATURE, pLutHeader->signature);
Dan O'Donovan 27:567abf893938 3107 return ADI_SENSE_INVALID_SIGNATURE;
Dan O'Donovan 27:567abf893938 3108 }
Dan O'Donovan 27:567abf893938 3109
Dan O'Donovan 27:567abf893938 3110 for (unsigned i = 0; i < pLutHeader->numTables; i++)
Dan O'Donovan 27:567abf893938 3111 {
Dan O'Donovan 27:567abf893938 3112 ADI_SENSE_1000_LUT_DESCRIPTOR *pDesc = &pLutTable->descriptor;
Dan O'Donovan 27:567abf893938 3113 ADI_SENSE_1000_LUT_TABLE_DATA *pData = &pLutTable->data;
Dan O'Donovan 27:567abf893938 3114 unsigned short calculatedCrc;
Dan O'Donovan 27:567abf893938 3115
Dan O'Donovan 27:567abf893938 3116 switch (pDesc->geometry)
Dan O'Donovan 27:567abf893938 3117 {
Dan O'Donovan 27:567abf893938 3118 case ADI_SENSE_1000_LUT_GEOMETRY_COEFFS:
Dan O'Donovan 27:567abf893938 3119 switch (pDesc->equation)
Dan O'Donovan 27:567abf893938 3120 {
Dan O'Donovan 27:567abf893938 3121 case ADI_SENSE_1000_LUT_EQUATION_POLYN:
Dan O'Donovan 27:567abf893938 3122 case ADI_SENSE_1000_LUT_EQUATION_POLYNEXP:
Dan O'Donovan 27:567abf893938 3123 case ADI_SENSE_1000_LUT_EQUATION_QUADRATIC:
Dan O'Donovan 27:567abf893938 3124 case ADI_SENSE_1000_LUT_EQUATION_STEINHART:
Dan O'Donovan 27:567abf893938 3125 case ADI_SENSE_1000_LUT_EQUATION_LOGARITHMIC:
Dan O'Donovan 27:567abf893938 3126 case ADI_SENSE_1000_LUT_EQUATION_BIVARIATE_POLYN:
Dan O'Donovan 27:567abf893938 3127 break;
Dan O'Donovan 27:567abf893938 3128 default:
Dan O'Donovan 27:567abf893938 3129 ADI_SENSE_LOG_ERROR("Invalid equation %u specified for LUT table %u",
Dan O'Donovan 27:567abf893938 3130 pDesc->equation, i);
Dan O'Donovan 27:567abf893938 3131 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 3132 }
Dan O'Donovan 27:567abf893938 3133 break;
Dan O'Donovan 27:567abf893938 3134 case ADI_SENSE_1000_LUT_GEOMETRY_NES_1D:
Dan O'Donovan 27:567abf893938 3135 case ADI_SENSE_1000_LUT_GEOMETRY_NES_2D:
Dan O'Donovan 27:567abf893938 3136 case ADI_SENSE_1000_LUT_GEOMETRY_ES_1D:
Dan O'Donovan 27:567abf893938 3137 case ADI_SENSE_1000_LUT_GEOMETRY_ES_2D:
Dan O'Donovan 27:567abf893938 3138 if (pDesc->equation != ADI_SENSE_1000_LUT_EQUATION_LUT) {
Dan O'Donovan 27:567abf893938 3139 ADI_SENSE_LOG_ERROR("Invalid equation %u specified for LUT table %u",
Dan O'Donovan 27:567abf893938 3140 pDesc->equation, i);
Dan O'Donovan 27:567abf893938 3141 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 3142 }
Dan O'Donovan 27:567abf893938 3143 break;
Dan O'Donovan 27:567abf893938 3144 default:
Dan O'Donovan 27:567abf893938 3145 ADI_SENSE_LOG_ERROR("Invalid geometry %u specified for LUT table %u",
Dan O'Donovan 27:567abf893938 3146 pDesc->geometry, i);
Dan O'Donovan 27:567abf893938 3147 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 3148 }
Dan O'Donovan 27:567abf893938 3149
Dan O'Donovan 27:567abf893938 3150 switch (pDesc->dataType)
Dan O'Donovan 27:567abf893938 3151 {
Dan O'Donovan 27:567abf893938 3152 case ADI_SENSE_1000_LUT_DATA_TYPE_FLOAT32:
Dan O'Donovan 27:567abf893938 3153 case ADI_SENSE_1000_LUT_DATA_TYPE_FLOAT64:
Dan O'Donovan 27:567abf893938 3154 break;
Dan O'Donovan 27:567abf893938 3155 default:
Dan O'Donovan 27:567abf893938 3156 ADI_SENSE_LOG_ERROR("Invalid vector format %u specified for LUT table %u",
Dan O'Donovan 27:567abf893938 3157 pDesc->dataType, i);
Dan O'Donovan 27:567abf893938 3158 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 3159 }
Dan O'Donovan 27:567abf893938 3160
kevin1990 29:57edca10d78c 3161 calculatedCrc = adi_sense_crc16_ccitt(pData, pDesc->length);
Dan O'Donovan 27:567abf893938 3162 if (calculatedCrc != pDesc->crc16)
Dan O'Donovan 27:567abf893938 3163 {
Dan O'Donovan 27:567abf893938 3164 ADI_SENSE_LOG_ERROR("CRC validation failed on LUT table %u (expected 0x%04X, actual 0x%04X)",
Dan O'Donovan 27:567abf893938 3165 i, pDesc->crc16, calculatedCrc);
Dan O'Donovan 27:567abf893938 3166 return ADI_SENSE_CRC_ERROR;
Dan O'Donovan 27:567abf893938 3167 }
Dan O'Donovan 27:567abf893938 3168
Dan O'Donovan 27:567abf893938 3169 actualLength += sizeof(*pDesc) + pDesc->length;
Dan O'Donovan 27:567abf893938 3170
Dan O'Donovan 27:567abf893938 3171 /* Move to the next look-up table */
Dan O'Donovan 27:567abf893938 3172 pLutTable = (ADI_SENSE_1000_LUT_TABLE *)((uint8_t *)pLutTable + sizeof(*pDesc) + pDesc->length);
Dan O'Donovan 27:567abf893938 3173 }
Dan O'Donovan 27:567abf893938 3174
Dan O'Donovan 27:567abf893938 3175 if (actualLength != pLutHeader->totalLength)
Dan O'Donovan 27:567abf893938 3176 {
Dan O'Donovan 27:567abf893938 3177 ADI_SENSE_LOG_ERROR("LUT table length mismatch (expected %u, actual %u)",
Dan O'Donovan 27:567abf893938 3178 pLutHeader->totalLength, actualLength);
Dan O'Donovan 27:567abf893938 3179 return ADI_SENSE_WRONG_SIZE;
Dan O'Donovan 27:567abf893938 3180 }
Dan O'Donovan 27:567abf893938 3181
Dan O'Donovan 27:567abf893938 3182 if (sizeof(*pLutHeader) + pLutHeader->totalLength > ADI_SENSE_LUT_MAX_SIZE)
Dan O'Donovan 27:567abf893938 3183 {
Dan O'Donovan 27:567abf893938 3184 ADI_SENSE_LOG_ERROR("Maximum LUT table length (%u bytes) exceeded",
Dan O'Donovan 27:567abf893938 3185 ADI_SENSE_LUT_MAX_SIZE);
Dan O'Donovan 27:567abf893938 3186 return ADI_SENSE_WRONG_SIZE;
Dan O'Donovan 27:567abf893938 3187 }
Dan O'Donovan 27:567abf893938 3188
Dan O'Donovan 27:567abf893938 3189 /* Write the LUT data to the device */
Dan O'Donovan 27:567abf893938 3190 unsigned lutSize = sizeof(*pLutHeader) + pLutHeader->totalLength;
Dan O'Donovan 27:567abf893938 3191 WRITE_REG_U16(hDevice, 0, CORE_LUT_OFFSET);
Dan O'Donovan 27:567abf893938 3192 WRITE_REG_U8_ARRAY(hDevice, (uint8_t *)pLutData, lutSize, CORE_LUT_DATA);
Dan O'Donovan 27:567abf893938 3193
Dan O'Donovan 27:567abf893938 3194 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 3195 }
Dan O'Donovan 27:567abf893938 3196
Dan O'Donovan 27:567abf893938 3197 ADI_SENSE_RESULT adi_sense_1000_SetLutDataRaw(
Dan O'Donovan 27:567abf893938 3198 ADI_SENSE_DEVICE_HANDLE const hDevice,
Dan O'Donovan 27:567abf893938 3199 ADI_SENSE_1000_LUT_RAW * const pLutData)
Dan O'Donovan 27:567abf893938 3200 {
Dan O'Donovan 27:567abf893938 3201 return adi_sense_1000_SetLutData(hDevice,
Dan O'Donovan 27:567abf893938 3202 (ADI_SENSE_1000_LUT *)pLutData);
Dan O'Donovan 27:567abf893938 3203 }
Dan O'Donovan 27:567abf893938 3204
Dan O'Donovan 27:567abf893938 3205 static ADI_SENSE_RESULT getLutTableSize(
Dan O'Donovan 27:567abf893938 3206 ADI_SENSE_1000_LUT_DESCRIPTOR * const pDesc,
Dan O'Donovan 27:567abf893938 3207 ADI_SENSE_1000_LUT_TABLE_DATA * const pData,
Dan O'Donovan 27:567abf893938 3208 unsigned *pLength)
Dan O'Donovan 27:567abf893938 3209 {
Dan O'Donovan 27:567abf893938 3210 switch (pDesc->geometry)
Dan O'Donovan 27:567abf893938 3211 {
Dan O'Donovan 27:567abf893938 3212 case ADI_SENSE_1000_LUT_GEOMETRY_COEFFS:
Dan O'Donovan 27:567abf893938 3213 if (pDesc->equation == ADI_SENSE_1000_LUT_EQUATION_BIVARIATE_POLYN)
Dan O'Donovan 27:567abf893938 3214 *pLength = ADI_SENSE_1000_LUT_2D_POLYN_COEFF_LIST_SIZE(pData->coeffList2d);
Dan O'Donovan 27:567abf893938 3215 else
Dan O'Donovan 27:567abf893938 3216 *pLength = ADI_SENSE_1000_LUT_COEFF_LIST_SIZE(pData->coeffList);
Dan O'Donovan 27:567abf893938 3217 break;
Dan O'Donovan 27:567abf893938 3218 case ADI_SENSE_1000_LUT_GEOMETRY_NES_1D:
Dan O'Donovan 27:567abf893938 3219 *pLength = ADI_SENSE_1000_LUT_1D_NES_SIZE(pData->lut1dNes);
Dan O'Donovan 27:567abf893938 3220 break;
Dan O'Donovan 27:567abf893938 3221 case ADI_SENSE_1000_LUT_GEOMETRY_NES_2D:
Dan O'Donovan 27:567abf893938 3222 *pLength = ADI_SENSE_1000_LUT_2D_NES_SIZE(pData->lut2dNes);
Dan O'Donovan 27:567abf893938 3223 break;
Dan O'Donovan 27:567abf893938 3224 case ADI_SENSE_1000_LUT_GEOMETRY_ES_1D:
Dan O'Donovan 27:567abf893938 3225 *pLength = ADI_SENSE_1000_LUT_1D_ES_SIZE(pData->lut1dEs);
Dan O'Donovan 27:567abf893938 3226 break;
Dan O'Donovan 27:567abf893938 3227 case ADI_SENSE_1000_LUT_GEOMETRY_ES_2D:
Dan O'Donovan 27:567abf893938 3228 *pLength = ADI_SENSE_1000_LUT_2D_ES_SIZE(pData->lut2dEs);
Dan O'Donovan 27:567abf893938 3229 break;
Dan O'Donovan 27:567abf893938 3230 default:
Dan O'Donovan 27:567abf893938 3231 ADI_SENSE_LOG_ERROR("Invalid LUT table geometry %d specified\r\n",
Dan O'Donovan 27:567abf893938 3232 pDesc->geometry);
Dan O'Donovan 27:567abf893938 3233 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 3234 }
Dan O'Donovan 27:567abf893938 3235
Dan O'Donovan 27:567abf893938 3236 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 3237 }
Dan O'Donovan 27:567abf893938 3238
Dan O'Donovan 27:567abf893938 3239 ADI_SENSE_RESULT adi_sense_1000_AssembleLutData(
Dan O'Donovan 27:567abf893938 3240 ADI_SENSE_1000_LUT * pLutBuffer,
Dan O'Donovan 27:567abf893938 3241 unsigned nLutBufferSize,
Dan O'Donovan 27:567abf893938 3242 unsigned const nNumTables,
Dan O'Donovan 27:567abf893938 3243 ADI_SENSE_1000_LUT_DESCRIPTOR * const ppDesc[],
Dan O'Donovan 27:567abf893938 3244 ADI_SENSE_1000_LUT_TABLE_DATA * const ppData[])
Dan O'Donovan 27:567abf893938 3245 {
Dan O'Donovan 27:567abf893938 3246 ADI_SENSE_1000_LUT_HEADER *pHdr = &pLutBuffer->header;
Dan O'Donovan 27:567abf893938 3247 uint8_t *pLutTableData = (uint8_t *)pLutBuffer + sizeof(*pHdr);
Dan O'Donovan 27:567abf893938 3248
Dan O'Donovan 27:567abf893938 3249 if (sizeof(*pHdr) > nLutBufferSize)
Dan O'Donovan 27:567abf893938 3250 {
Dan O'Donovan 27:567abf893938 3251 ADI_SENSE_LOG_ERROR("Insufficient LUT buffer size provided");
Dan O'Donovan 27:567abf893938 3252 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 3253 }
Dan O'Donovan 27:567abf893938 3254
Dan O'Donovan 27:567abf893938 3255 /* First initialise the top-level header */
Dan O'Donovan 27:567abf893938 3256 pHdr->signature = ADI_SENSE_LUT_SIGNATURE;
Dan O'Donovan 27:567abf893938 3257 pHdr->version.major = 1;
Dan O'Donovan 27:567abf893938 3258 pHdr->version.minor = 0;
Dan O'Donovan 27:567abf893938 3259 pHdr->numTables = 0;
Dan O'Donovan 27:567abf893938 3260 pHdr->totalLength = 0;
Dan O'Donovan 27:567abf893938 3261
Dan O'Donovan 27:567abf893938 3262 /*
Dan O'Donovan 27:567abf893938 3263 * Walk through the list of table pointers provided, appending the table
Dan O'Donovan 27:567abf893938 3264 * descriptor+data from each one to the provided LUT buffer
Dan O'Donovan 27:567abf893938 3265 */
Dan O'Donovan 27:567abf893938 3266 for (unsigned i = 0; i < nNumTables; i++)
Dan O'Donovan 27:567abf893938 3267 {
Dan O'Donovan 27:567abf893938 3268 ADI_SENSE_1000_LUT_DESCRIPTOR * const pDesc = ppDesc[i];
Dan O'Donovan 27:567abf893938 3269 ADI_SENSE_1000_LUT_TABLE_DATA * const pData = ppData[i];
Dan O'Donovan 27:567abf893938 3270 ADI_SENSE_RESULT res;
Dan O'Donovan 27:567abf893938 3271 unsigned dataLength = 0;
Dan O'Donovan 27:567abf893938 3272
Dan O'Donovan 27:567abf893938 3273 /* Calculate the length of the table data */
Dan O'Donovan 27:567abf893938 3274 res = getLutTableSize(pDesc, pData, &dataLength);
Dan O'Donovan 27:567abf893938 3275 if (res != ADI_SENSE_SUCCESS)
Dan O'Donovan 27:567abf893938 3276 return res;
Dan O'Donovan 27:567abf893938 3277
Dan O'Donovan 27:567abf893938 3278 /* Fill in the table descriptor length and CRC fields */
Dan O'Donovan 27:567abf893938 3279 pDesc->length = dataLength;
kevin1990 29:57edca10d78c 3280 pDesc->crc16 = adi_sense_crc16_ccitt(pData, dataLength);
Dan O'Donovan 27:567abf893938 3281
Dan O'Donovan 27:567abf893938 3282 if ((sizeof(*pHdr) + pHdr->totalLength + sizeof(*pDesc) + dataLength) > nLutBufferSize)
Dan O'Donovan 27:567abf893938 3283 {
Dan O'Donovan 27:567abf893938 3284 ADI_SENSE_LOG_ERROR("Insufficient LUT buffer size provided");
Dan O'Donovan 27:567abf893938 3285 return ADI_SENSE_INVALID_PARAM;
Dan O'Donovan 27:567abf893938 3286 }
Dan O'Donovan 27:567abf893938 3287
Dan O'Donovan 27:567abf893938 3288 /* Append the table to the LUT buffer (desc + data) */
Dan O'Donovan 27:567abf893938 3289 memcpy(pLutTableData + pHdr->totalLength, pDesc, sizeof(*pDesc));
Dan O'Donovan 27:567abf893938 3290 pHdr->totalLength += sizeof(*pDesc);
Dan O'Donovan 27:567abf893938 3291 memcpy(pLutTableData + pHdr->totalLength, pData, dataLength);
Dan O'Donovan 27:567abf893938 3292 pHdr->totalLength += dataLength;
Dan O'Donovan 27:567abf893938 3293
Dan O'Donovan 27:567abf893938 3294 pHdr->numTables++;
Dan O'Donovan 27:567abf893938 3295 }
Dan O'Donovan 27:567abf893938 3296
Dan O'Donovan 27:567abf893938 3297 return ADI_SENSE_SUCCESS;
Dan O'Donovan 27:567abf893938 3298 }