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