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