PoC_Team
/
ADMW1001_example_firmware
Host API Example for the ADMW1001
Embed:
(wiki syntax)
Show/hide line numbers
admw1001_lut_data.h
Go to the documentation of this file.
00001 /* 00002 Copyright 2019 (c) Analog Devices, Inc. 00003 00004 All rights reserved. 00005 00006 Redistribution and use in source and binary forms, with or without 00007 modification, are permitted provided that the following conditions are met: 00008 - Redistributions of source code must retain the above copyright 00009 notice, this list of conditions and the following disclaimer. 00010 - Redistributions in binary form must reproduce the above copyright 00011 notice, this list of conditions and the following disclaimer in 00012 the documentation and/or other materials provided with the 00013 distribution. 00014 - Neither the name of Analog Devices, Inc. nor the names of its 00015 contributors may be used to endorse or promote products derived 00016 from this software without specific prior written permission. 00017 - The use of this software may or may not infringe the patent rights 00018 of one or more patent holders. This license does not release you 00019 from the requirement that you obtain separate licenses from these 00020 patent holders to use this software. 00021 - Use of the software either in source or binary form, must be run 00022 on or directly connected to an Analog Devices Inc. component. 00023 00024 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 00025 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 00026 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00027 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00029 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 */ 00035 00036 /*! 00037 ****************************************************************************** 00038 * @file: 00039 * @brief: Look-Up Table data-type definitions for ADMW1001 API. 00040 *----------------------------------------------------------------------------- 00041 */ 00042 00043 #ifndef __ADMW1001_LUT_DATA_H__ 00044 #define __ADMW1001_LUT_DATA_H__ 00045 00046 #include "admw_types.h" 00047 #include "admw1001_sensor_types.h" 00048 00049 //lint --e{38} suppress "offset of symbol" 00050 00051 /*! @addtogroup ADMW1001_Api 00052 * @{ 00053 */ 00054 00055 #ifdef __cplusplus 00056 extern "C" { 00057 #endif 00058 00059 /*! LUT data validation signature */ 00060 #define ADMW_LUT_SIGNATURE 0x4C555473 00061 00062 /*! LUT data CRC-16-CCITT seed value */ 00063 #define ADMW_LUT_CRC_SEED 0x4153 00064 00065 /*! LUT maximum allowed size */ 00066 #define ADMW_LUT_MAX_SIZE 10240U 00067 00068 /*! Linearisation look-up table / co-efficient list geometry */ 00069 typedef enum { 00070 ADMW1001_LUT_GEOMETRY_RESERVED = 0x00, 00071 /**< reserved - for internal use only */ 00072 ADMW1001_LUT_GEOMETRY_COEFFS = 0x01, 00073 /**< 1D/2D equation coefficient list */ 00074 ADMW1001_LUT_GEOMETRY_NES_1D = 0x02, 00075 /**< 1-dimensional not-equally-spaced look-up table */ 00076 ADMW1001_LUT_GEOMETRY_NES_2D = 0x03, 00077 /**< 2-dimensional not-equally-spaced look-up table */ 00078 ADMW1001_LUT_GEOMETRY_ES_1D = 0x04, 00079 /**< 1-dimensional equally-spaced look-up table */ 00080 ADMW1001_LUT_GEOMETRY_ES_2D = 0x05, 00081 /**< 2-dimensional equally-spaced look-up table */ 00082 } ADMW1001_LUT_GEOMETRY ; 00083 00084 /*! Linearisation equation type */ 00085 typedef enum { 00086 ADMW1001_LUT_EQUATION_POLYN, 00087 /**< Polynomial equation, typically used for Thermocouple and RTD 00088 * linearisation */ 00089 ADMW1001_LUT_EQUATION_POLYNEXP, 00090 /**< Polynomial + exponential equation, typically used for Thermocouple 00091 * inverse linearisation */ 00092 ADMW1001_LUT_EQUATION_QUADRATIC, 00093 /**< Quadratic linearisation equation, typically used for RTD 00094 * linearisation */ 00095 ADMW1001_LUT_EQUATION_STEINHART, 00096 /**< Steinhart-Hart equation, typically used for Thermistor 00097 * linearisation */ 00098 ADMW1001_LUT_EQUATION_LOGARITHMIC, 00099 /**< Beta-based logarithmic equation, typically used for Thermistor 00100 * linearisation */ 00101 ADMW1001_LUT_EQUATION_BIVARIATE_POLYN, 00102 /**< Bi-variate polynomial equation, typically used for bridge pressure 00103 * sensor linearisation 00104 * @note 2nd-degree is the maximum currently supported 00105 */ 00106 ADMW1001_LUT_EQUATION_COUNT, 00107 /**< Enum count value - for internal use only */ 00108 ADMW1001_LUT_EQUATION_LUT, 00109 /**< Hard-coded Look-Up Table - for internal use only */ 00110 } ADMW1001_LUT_EQUATION ; 00111 00112 typedef enum { 00113 ADMW1001_LUT_TC_DIRECTION_FORWARD, 00114 /**< Thermocouple forward (mV to Celsius) linearisation 00115 * Use this value by default for non-thermocouple sensors */ 00116 ADMW1001_LUT_TC_DIRECTION_BACKWARD, 00117 /**< Thermocouple inverse (Celsius to mV) linearisation */ 00118 ADMW1001_LUT_TC_DIRECTION_COUNT, 00119 /**< Enum count value - for internal use only */ 00120 } ADMW1001_LUT_TC_DIRECTION ; 00121 00122 /*! Linearisation data vector format */ 00123 typedef enum { 00124 ADMW1001_LUT_DATA_TYPE_RESERVED = 0, 00125 /**< Reserved - for internal use only */ 00126 ADMW1001_LUT_DATA_TYPE_FLOAT32 = 1, 00127 /**< Single-precision 32-bit floating-point */ 00128 ADMW1001_LUT_DATA_TYPE_FLOAT64 = 2, 00129 /**< Double-precision 64-bit floating-point */ 00130 } ADMW1001_LUT_DATA_TYPE ; 00131 00132 /*! Struct for a list of coefficients to be used in an equation */ 00133 typedef struct __attribute__ ((packed, aligned(4))){ 00134 uint32_t nCoeffs; 00135 /**< number of coefficients */ 00136 float32_t rangeMin; 00137 /**< look-up table range - minimum */ 00138 float32_t rangeMax; 00139 /**< look-up table range - maximum */ 00140 float64_t coeffs[]; 00141 /**< C99 flexible array: sorted by ascending exponent in polynomials */ 00142 } ADMW1001_LUT_COEFF_LIST; 00143 00144 /*! Struct for a 1-dimensional equally-spaced look-up table */ 00145 typedef struct __attribute__ ((packed, aligned(4))){ 00146 uint32_t nElements; 00147 /**< number of elements. */ 00148 float32_t initInputValue; 00149 /**< initial input value, corresponding to first table element */ 00150 float32_t inputValueIncrement; 00151 /**< interval between successive input values */ 00152 float32_t lut[]; 00153 /**< C99 flexible array */ 00154 } ADMW1001_LUT_1D_ES; 00155 00156 /*! Struct for a 1-dimensional not-equally-spaced look-up table */ 00157 typedef struct __attribute__ ((packed, aligned(4))){ 00158 uint32_t nElements; 00159 /**< number of elements of each array. */ 00160 float32_t lut[]; 00161 /**< C99 flexible array, first X's array then Y's array*/ 00162 } ADMW1001_LUT_1D_NES; 00163 00164 /*! Struct for a 2-dimensional equally-spaced look-up table */ 00165 typedef struct __attribute__ ((packed, aligned(4))){ 00166 uint16_t nElementsX; 00167 /**< number of elements for input X. */ 00168 uint16_t nElementsY; 00169 /**< number of elements for input Y. */ 00170 float32_t initInputValueX; 00171 /**< initial X input value */ 00172 float32_t inputValueIncrementX; 00173 /**< interval between successive X input values */ 00174 float32_t initInputValueY; 00175 /**< initial Y input value */ 00176 float32_t inputValueIncrementY; 00177 /**< interval between successive Y input values */ 00178 float32_t lut[]; 00179 /**< C99 flexible array, Z matrix[y][x] */ 00180 } ADMW1001_LUT_2D_ES; 00181 00182 /*! Struct for a 2-dimensional not-equally-spaced look-up table */ 00183 typedef struct __attribute__ ((packed, aligned(4))){ 00184 uint16_t nElementsX; 00185 /**< number of elements in array X. */ 00186 uint16_t nElementsY; 00187 /**< number of elements in array Y. */ 00188 float32_t lut[]; 00189 /**< C99 flexible array, Order: X's array, Y's array, Z matrix[y][x] */ 00190 } ADMW1001_LUT_2D_NES; 00191 00192 /*! Struct for a 2-dimensional list of coefficients to be used in a 00193 * bi-variate polynomial equation */ 00194 typedef struct __attribute__ ((packed, aligned(4))){ 00195 uint32_t maxDegree; 00196 /**< number of coefficients */ 00197 float32_t rangeMinX; 00198 /**< look-up table range - minimum X input value */ 00199 float32_t rangeMaxX; 00200 /**< look-up table range - maximum X input value */ 00201 float32_t rangeMinY; 00202 /**< look-up table range - minimum Y input value */ 00203 float32_t rangeMaxY; 00204 /**< look-up table range - maximum Y input value */ 00205 float64_t coeffs[]; 00206 /**< C99 flexible array: sorted by ascending X degree then sorted by 00207 * ascending Y exponent */ 00208 } ADMW1001_LUT_2D_POLYN_COEFF_LIST; 00209 00210 /*! Macro to calculate the number of elements in 00211 * a @ref ADMW1001_LUT_COEFF_LIST table */ 00212 #define ADMW1001_LUT_COEFF_LIST_NELEMENTS(_t) \ 00213 ((_t).nCoeffs) 00214 00215 /*! Macro to calculate the number of elements in 00216 * a @ref ADMW1001_LUT_1D_ES table */ 00217 #define ADMW1001_LUT_1D_ES_NELEMENTS(_t) \ 00218 ((_t).nElements) 00219 00220 /*! Macro to calculate the number of elements in 00221 * a @ref ADMW1001_LUT_1D_NES table */ 00222 #define ADMW1001_LUT_1D_NES_NELEMENTS(_t) \ 00223 ((_t).nElements * 2) 00224 00225 /*! Macro to calculate the number of elements in 00226 * a @ref ADMW1001_LUT_2D_ES table */ 00227 #define ADMW1001_LUT_2D_ES_NELEMENTS(_t) \ 00228 ((_t).nElementsX * (_t).nElementsX) 00229 00230 /*! Macro to calculate the number of elements in 00231 * a @ref ADMW1001_LUT_2D_NES table */ 00232 #define ADMW1001_LUT_2D_NES_NELEMENTS(_t) \ 00233 ((_t).nElementsX + (_t).nElementsY + ((_t).nElementsX * (_t).nElementsY)) 00234 00235 /*! Macro to calculate the number of elements in 00236 * a @ref ADMW1001_LUT_2D_POLYN_COEFF_LIST table */ 00237 #define ADMW1001_LUT_2D_POLYN_COEFF_LIST_NELEMENTS(_t) \ 00238 (((_t).maxDegree + 1) * ((_t).maxDegree + 2) / 2) 00239 00240 /*! Macro to calculate the storage size in bytes of 00241 * a @ref ADMW1001_LUT_COEFF_LIST table */ 00242 #define ADMW1001_LUT_COEFF_LIST_SIZE(_t) \ 00243 (sizeof(_t) + (sizeof(float64_t) * ADMW1001_LUT_COEFF_LIST_NELEMENTS(_t))) 00244 00245 /*! Macro to calculate the storage size in bytes of 00246 * a @ref ADMW1001_LUT_1D_ES table */ 00247 #define ADMW1001_LUT_1D_ES_SIZE(_t) \ 00248 (sizeof(_t) + (sizeof(float32_t) * ADMW1001_LUT_1D_ES_NELEMENTS(_t))) 00249 00250 /*! Macro to calculate the storage size in bytes of 00251 * a @ref ADMW1001_LUT_1D_NES table */ 00252 #define ADMW1001_LUT_1D_NES_SIZE(_t) \ 00253 (sizeof(_t) + (sizeof(float32_t) * ADMW1001_LUT_1D_NES_NELEMENTS(_t))) 00254 00255 /*! Macro to calculate the storage size in bytes of 00256 * a @ref ADMW1001_LUT_2D_ES table */ 00257 #define ADMW1001_LUT_2D_ES_SIZE(_t) \ 00258 (sizeof(_t) + (sizeof(float32_t) * ADMW1001_LUT_2D_ES_NELEMENTS(_t))) 00259 00260 /*! Macro to calculate the storage size in bytes of 00261 * a @ref ADMW1001_LUT_2D_NES table */ 00262 #define ADMW1001_LUT_2D_NES_SIZE(_t) \ 00263 (sizeof(_t) + (sizeof(float32_t) * ADMW1001_LUT_2D_NES_NELEMENTS(_t))) 00264 00265 /*! Macro to calculate the storage size in bytes of 00266 * a @ref ADMW1001_LUT_2D_POLYN_COEFF_LIST table */ 00267 #define ADMW1001_LUT_2D_POLYN_COEFF_LIST_SIZE(_t) \ 00268 (sizeof(_t) + (sizeof(float64_t) * ADMW1001_LUT_2D_POLYN_COEFF_LIST_NELEMENTS(_t))) 00269 00270 /*! Look-Up Table descriptor */ 00271 typedef union __attribute__ ((packed, aligned(4))) { 00272 struct { 00273 uint16_t geometry : 6; /**< ADMW1001_LUT_GEOMETRY */ 00274 uint16_t equation : 6; /**< ADMW1001_LUT_EQUATION */ 00275 uint16_t dir : 4; /**< ADMW1001_LUT_TC_DIRECTION */ 00276 uint16_t sensor : 12; /**< ADMW1001_ADC_SENSOR_TYPE */ 00277 uint16_t dataType : 4; /**< ADMW1001_LUT_DATA_TYPE */ 00278 uint16_t length; /**< Length (bytes) of table data section 00279 (excl. this header) */ 00280 uint16_t crc16; /**< CRC-16-CCITT of the data */ 00281 }; 00282 uint64_t value64; 00283 } ADMW1001_LUT_DESCRIPTOR; 00284 00285 /*! Look-Up Table geometry-specific data structures */ 00286 typedef union { 00287 ADMW1001_LUT_COEFF_LIST coeffList; 00288 /**< Data format for tables with ADMW1001_LUT_GEOMETRY_COEFFS geometry 00289 * except where equation is ADMW1001_LUT_EQUATION_BIVARIATE_POLYN */ 00290 ADMW1001_LUT_1D_ES lut1dEs; 00291 /**< Data format for tables with ADMW1001_LUT_GEOMETRY_ES_1D geometry */ 00292 ADMW1001_LUT_1D_NES lut1dNes; 00293 /**< Data format for tables with ADMW1001_LUT_GEOMETRY_NES_1D geometry */ 00294 ADMW1001_LUT_2D_ES lut2dEs; 00295 /**< Data format for tables with ADMW1001_LUT_GEOMETRY_ES_2D geometry */ 00296 ADMW1001_LUT_2D_NES lut2dNes; 00297 /**< Data format for tables with ADMW1001_LUT_GEOMETRY_NES_2D geometry */ 00298 ADMW1001_LUT_2D_POLYN_COEFF_LIST coeffList2d; 00299 /**< Data format for tables with ADMW1001_LUT_GEOMETRY_COEFFS geometry 00300 * and ADMW1001_LUT_EQUATION_BIVARIATE_POLYN equation */ 00301 } ADMW1001_LUT_TABLE_DATA ; 00302 00303 /*! Look-Up Table structure */ 00304 typedef struct __attribute__ ((packed, aligned(4))) { 00305 ADMW1001_LUT_DESCRIPTOR descriptor; 00306 /**< Look-Up Table descriptor */ 00307 ADMW1001_LUT_TABLE_DATA data; 00308 /**< Look-Up Table data */ 00309 } ADMW1001_LUT_TABLE; 00310 00311 /*! LUT data format versions */ 00312 typedef struct __attribute__ ((packed, aligned(4))) { 00313 uint8_t major; /*!< Major version number */ 00314 uint8_t minor; /*!< Minor version number */ 00315 } ADMW1001_LUT_VERSION; 00316 00317 /*! LUT data header structure */ 00318 typedef struct __attribute__ ((packed, aligned(4))) { 00319 uint32_t signature; 00320 /**< Hard-coded signature value (@ref ADMW_LUT_SIGNATURE) */ 00321 ADMW1001_LUT_VERSION version; 00322 /**< LUT data format version (@ref ADMW_LUT_VERSION) */ 00323 uint16_t numTables; 00324 /**< Total number of tables */ 00325 uint32_t totalLength; 00326 /**< Total length (in bytes) of all table descriptors and data 00327 * (excluding this header) 00328 * This, plus the header length, must not exceed ADMW_LUT_MAX_SIZE 00329 */ 00330 } ADMW1001_LUT_HEADER; 00331 00332 /*! LUT data top-level structure */ 00333 typedef struct __attribute__ ((packed, aligned(4))) { 00334 ADMW1001_LUT_HEADER header; 00335 /*!< LUT data top-level header structure */ 00336 ADMW1001_LUT_TABLE tables[]; 00337 /*!< Variable-length array of one-or-more look-up table structures */ 00338 } ADMW1001_LUT; 00339 00340 /*! Alternative top-level structure for raw LUT data representation 00341 * 00342 * @note This is intended to be used for encapsulating the storage of static 00343 * LUT data declarations in C files. The rawTableData can be cast 00344 * to the ADMW_LUT type for further parsing/processing. 00345 */ 00346 typedef struct __attribute__ ((packed, aligned(4))) { 00347 ADMW1001_LUT_HEADER header; 00348 /*!< LUT data top-level header structure */ 00349 uint8_t rawTableData[]; 00350 /*!< Variable-length byte array of look-up tables in raw binary format */ 00351 } ADMW1001_LUT_RAW; 00352 00353 #ifdef __cplusplus 00354 } 00355 #endif 00356 00357 /*! 00358 * @} 00359 */ 00360 00361 #endif /* __ADMW1001_LUT_DATA_H__ */
Generated on Wed Jul 13 2022 03:04:54 by 1.7.2