Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: inc/admw1001/admw1001_lut_data.h
- Revision:
- 5:0728bde67bdb
- Child:
- 6:9d393a9677f4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/inc/admw1001/admw1001_lut_data.h Wed Jun 05 05:39:15 2019 +0000
@@ -0,0 +1,362 @@
+/*
+Copyright 2017 (c) Analog Devices, Inc.
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+ - Neither the name of Analog Devices, Inc. nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+ - The use of this software may or may not infringe the patent rights
+ of one or more patent holders. This license does not release you
+ from the requirement that you obtain separate licenses from these
+ patent holders to use this software.
+ - Use of the software either in source or binary form, must be run
+ on or directly connected to an Analog Devices Inc. component.
+
+THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/*!
+ ******************************************************************************
+ * @file:
+ * @brief: Look-Up Table data-type definitions for ADSNS1000 API.
+ *-----------------------------------------------------------------------------
+ */
+
+#ifndef __ADMW1001_LUT_DATA_H__
+#define __ADMW1001_LUT_DATA_H__
+
+#include "admw_types.h"
+#include "admw1001_sensor_types.h"
+
+//lint --e{38} suppress "offset of symbol"
+
+/*! @addtogroup ADMW1001_Api
+ * @{
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*! LUT data validation signature */
+#define ADMW_LUT_SIGNATURE 0x4C555473
+
+/*! LUT data CRC-16-CCITT seed value */
+#define ADMW_LUT_CRC_SEED 0x4153
+
+/*! LUT maximum allowed size */
+#define ADMW_LUT_MAX_SIZE 10240U
+
+/*! Linearisation look-up table / co-efficient list geometry */
+typedef enum {
+ ADMW1001_LUT_GEOMETRY_RESERVED = 0x00,
+ /**< reserved - for internal use only */
+ ADMW1001_LUT_GEOMETRY_COEFFS = 0x01,
+ /**< 1D/2D equation coefficient list */
+ ADMW1001_LUT_GEOMETRY_NES_1D = 0x02,
+ /**< 1-dimensional not-equally-spaced look-up table */
+ ADMW1001_LUT_GEOMETRY_NES_2D = 0x03,
+ /**< 2-dimensional not-equally-spaced look-up table */
+ ADMW1001_LUT_GEOMETRY_ES_1D = 0x04,
+ /**< 1-dimensional equally-spaced look-up table */
+ ADMW1001_LUT_GEOMETRY_ES_2D = 0x05,
+ /**< 2-dimensional equally-spaced look-up table */
+} ADMW1001_LUT_GEOMETRY;
+
+/*! Linearisation equation type */
+typedef enum {
+ ADMW1001_LUT_EQUATION_POLYN,
+ /**< Polynomial equation, typically used for Thermocouple and RTD
+ * linearisation */
+ ADMW1001_LUT_EQUATION_POLYNEXP,
+ /**< Polynomial + exponential equation, typically used for Thermocouple
+ * inverse linearisation */
+ ADMW1001_LUT_EQUATION_QUADRATIC,
+ /**< Quadratic linearisation equation, typically used for RTD
+ * linearisation */
+ ADMW1001_LUT_EQUATION_STEINHART,
+ /**< Steinhart-Hart equation, typically used for Thermistor
+ * linearisation */
+ ADMW1001_LUT_EQUATION_LOGARITHMIC,
+ /**< Beta-based logarithmic equation, typically used for Thermistor
+ * linearisation */
+ ADMW1001_LUT_EQUATION_BIVARIATE_POLYN,
+ /**< Bi-variate polynomial equation, typically used for bridge pressure
+ * sensor linearisation
+ * @note 2nd-degree is the maximum currently supported
+ */
+ ADMW1001_LUT_EQUATION_COUNT,
+ /**< Enum count value - for internal use only */
+ ADMW1001_LUT_EQUATION_LUT,
+ /**< Hard-coded Look-Up Table - for internal use only */
+} ADMW1001_LUT_EQUATION;
+
+typedef enum {
+ ADMW1001_LUT_TC_DIRECTION_FORWARD,
+ /**< Thermocouple forward (mV to Celsius) linearisation
+ * Use this value by default for non-thermocouple sensors */
+ ADMW1001_LUT_TC_DIRECTION_BACKWARD,
+ /**< Thermocouple inverse (Celsius to mV) linearisation */
+ ADMW1001_LUT_TC_DIRECTION_COUNT,
+ /**< Enum count value - for internal use only */
+} ADMW1001_LUT_TC_DIRECTION;
+
+/*! Linearisation data vector format */
+typedef enum {
+ ADMW1001_LUT_DATA_TYPE_RESERVED = 0,
+ /**< Reserved - for internal use only */
+ ADMW1001_LUT_DATA_TYPE_FLOAT32 = 1,
+ /**< Single-precision 32-bit floating-point */
+ ADMW1001_LUT_DATA_TYPE_FLOAT64 = 2,
+ /**< Double-precision 64-bit floating-point */
+} ADMW1001_LUT_DATA_TYPE;
+
+/*! Struct for a list of coefficients to be used in an equation */
+typedef struct __attribute__((packed, aligned(4))){
+ uint32_t nCoeffs;
+ /**< number of coefficients */
+ float32_t rangeMin;
+ /**< look-up table range - minimum */
+ float32_t rangeMax;
+ /**< look-up table range - maximum */
+ float64_t coeffs[];
+ /**< C99 flexible array: sorted by ascending exponent in polynomials */
+} ADMW1001_LUT_COEFF_LIST;
+
+/*! Struct for a 1-dimensional equally-spaced look-up table */
+typedef struct __attribute__((packed, aligned(4))){
+ uint32_t nElements;
+ /**< number of elements. */
+ float32_t initInputValue;
+ /**< initial input value, corresponding to first table element */
+ float32_t inputValueIncrement;
+ /**< interval between successive input values */
+ float32_t lut[];
+ /**< C99 flexible array */
+} ADMW1001_LUT_1D_ES;
+
+/*! Struct for a 1-dimensional not-equally-spaced look-up table */
+typedef struct __attribute__((packed, aligned(4))){
+ uint32_t nElements;
+ /**< number of elements of each array. */
+ float32_t lut[];
+ /**< C99 flexible array, first X's array then Y's array*/
+} ADMW1001_LUT_1D_NES;
+
+/*! Struct for a 2-dimensional equally-spaced look-up table */
+typedef struct __attribute__((packed, aligned(4))){
+ uint16_t nElementsX;
+ /**< number of elements for input X. */
+ uint16_t nElementsY;
+ /**< number of elements for input Y. */
+ float32_t initInputValueX;
+ /**< initial X input value */
+ float32_t inputValueIncrementX;
+ /**< interval between successive X input values */
+ float32_t initInputValueY;
+ /**< initial Y input value */
+ float32_t inputValueIncrementY;
+ /**< interval between successive Y input values */
+ float32_t lut[];
+ /**< C99 flexible array, Z matrix[y][x] */
+} ADMW1001_LUT_2D_ES;
+
+/*! Struct for a 2-dimensional not-equally-spaced look-up table */
+typedef struct __attribute__((packed, aligned(4))){
+ uint16_t nElementsX;
+ /**< number of elements in array X. */
+ uint16_t nElementsY;
+ /**< number of elements in array Y. */
+ float32_t lut[];
+ /**< C99 flexible array, Order: X's array, Y's array, Z matrix[y][x] */
+} ADMW1001_LUT_2D_NES;
+
+/*! Struct for a 2-dimensional list of coefficients to be used in a
+ * bi-variate polynomial equation */
+typedef struct __attribute__((packed, aligned(4))){
+ uint32_t maxDegree;
+ /**< number of coefficients */
+ float32_t rangeMinX;
+ /**< look-up table range - minimum X input value */
+ float32_t rangeMaxX;
+ /**< look-up table range - maximum X input value */
+ float32_t rangeMinY;
+ /**< look-up table range - minimum Y input value */
+ float32_t rangeMaxY;
+ /**< look-up table range - maximum Y input value */
+ float64_t coeffs[];
+ /**< C99 flexible array: sorted by ascending X degree then sorted by
+ * ascending Y exponent */
+} ADMW1001_LUT_2D_POLYN_COEFF_LIST;
+
+/*! Macro to calculate the number of elements in
+ * a @ref ADMW1001_LUT_COEFF_LIST table */
+#define ADMW1001_LUT_COEFF_LIST_NELEMENTS(_t) \
+ ((_t).nCoeffs)
+
+/*! Macro to calculate the number of elements in
+ * a @ref ADMW1001_LUT_1D_ES table */
+#define ADMW1001_LUT_1D_ES_NELEMENTS(_t) \
+ ((_t).nElements)
+
+/*! Macro to calculate the number of elements in
+ * a @ref ADMW1001_LUT_1D_NES table */
+#define ADMW1001_LUT_1D_NES_NELEMENTS(_t) \
+ ((_t).nElements * 2)
+
+/*! Macro to calculate the number of elements in
+ * a @ref ADMW1001_LUT_2D_ES table */
+#define ADMW1001_LUT_2D_ES_NELEMENTS(_t) \
+ ((_t).nElementsX * (_t).nElementsX)
+
+/*! Macro to calculate the number of elements in
+ * a @ref ADMW1001_LUT_2D_NES table */
+#define ADMW1001_LUT_2D_NES_NELEMENTS(_t) \
+ ((_t).nElementsX + (_t).nElementsY + ((_t).nElementsX * (_t).nElementsY))
+
+/*! Macro to calculate the number of elements in
+ * a @ref ADMW1001_LUT_2D_POLYN_COEFF_LIST table */
+#define ADMW1001_LUT_2D_POLYN_COEFF_LIST_NELEMENTS(_t) \
+ (((_t).maxDegree + 1) * ((_t).maxDegree + 2) / 2)
+
+/*! Macro to calculate the storage size in bytes of
+ * a @ref ADMW1001_LUT_COEFF_LIST table */
+#define ADMW1001_LUT_COEFF_LIST_SIZE(_t) \
+ (sizeof(_t) + (sizeof(float64_t) * ADMW1001_LUT_COEFF_LIST_NELEMENTS(_t)))
+
+/*! Macro to calculate the storage size in bytes of
+ * a @ref ADMW1001_LUT_1D_ES table */
+#define ADMW1001_LUT_1D_ES_SIZE(_t) \
+ (sizeof(_t) + (sizeof(float32_t) * ADMW1001_LUT_1D_ES_NELEMENTS(_t)))
+
+/*! Macro to calculate the storage size in bytes of
+ * a @ref ADMW1001_LUT_1D_NES table */
+#define ADMW1001_LUT_1D_NES_SIZE(_t) \
+ (sizeof(_t) + (sizeof(float32_t) * ADMW1001_LUT_1D_NES_NELEMENTS(_t)))
+
+/*! Macro to calculate the storage size in bytes of
+ * a @ref ADMW1001_LUT_2D_ES table */
+#define ADMW1001_LUT_2D_ES_SIZE(_t) \
+ (sizeof(_t) + (sizeof(float32_t) * ADMW1001_LUT_2D_ES_NELEMENTS(_t)))
+
+/*! Macro to calculate the storage size in bytes of
+ * a @ref ADMW1001_LUT_2D_NES table */
+#define ADMW1001_LUT_2D_NES_SIZE(_t) \
+ (sizeof(_t) + (sizeof(float32_t) * ADMW1001_LUT_2D_NES_NELEMENTS(_t)))
+
+/*! Macro to calculate the storage size in bytes of
+ * a @ref ADMW1001_LUT_2D_POLYN_COEFF_LIST table */
+#define ADMW1001_LUT_2D_POLYN_COEFF_LIST_SIZE(_t) \
+ (sizeof(_t) + (sizeof(float64_t) * ADMW1001_LUT_2D_POLYN_COEFF_LIST_NELEMENTS(_t)))
+
+/*! Look-Up Table descriptor */
+typedef union __attribute__((packed, aligned(4))) {
+ struct {
+ uint16_t geometry : 6; /**< ADMW1001_LUT_GEOMETRY */
+ uint16_t equation : 6; /**< ADMW1001_LUT_EQUATION */
+ uint16_t dir : 4; /**< ADMW1001_LUT_TC_DIRECTION */
+ uint16_t sensor : 12; /**< ADMW1001_ADC_SENSOR_TYPE */
+ uint16_t dataType : 4; /**< ADMW1001_LUT_DATA_TYPE */
+ uint16_t length; /**< Length (bytes) of table data section
+ (excl. this header) */
+ uint16_t crc16; /**< CRC-16-CCITT of the data */
+ };
+ uint64_t value64;
+} ADMW1001_LUT_DESCRIPTOR;
+
+/*! Look-Up Table geometry-specific data structures */
+typedef union {
+ ADMW1001_LUT_COEFF_LIST coeffList;
+ /**< Data format for tables with ADMW1001_LUT_GEOMETRY_COEFFS geometry
+ * except where equation is ADMW1001_LUT_EQUATION_BIVARIATE_POLYN */
+ ADMW1001_LUT_1D_ES lut1dEs;
+ /**< Data format for tables with ADMW1001_LUT_GEOMETRY_ES_1D geometry */
+ ADMW1001_LUT_1D_NES lut1dNes;
+ /**< Data format for tables with ADMW1001_LUT_GEOMETRY_NES_1D geometry */
+ ADMW1001_LUT_2D_ES lut2dEs;
+ /**< Data format for tables with ADMW1001_LUT_GEOMETRY_ES_2D geometry */
+ ADMW1001_LUT_2D_NES lut2dNes;
+ /**< Data format for tables with ADMW1001_LUT_GEOMETRY_NES_2D geometry */
+ ADMW1001_LUT_2D_POLYN_COEFF_LIST coeffList2d;
+ /**< Data format for tables with ADMW1001_LUT_GEOMETRY_COEFFS geometry
+ * and ADMW1001_LUT_EQUATION_BIVARIATE_POLYN equation */
+} ADMW1001_LUT_TABLE_DATA;
+
+/*! Look-Up Table structure */
+typedef struct __attribute__((packed, aligned(4))) {
+ ADMW1001_LUT_DESCRIPTOR descriptor;
+ /**< Look-Up Table descriptor */
+ ADMW1001_LUT_TABLE_DATA data;
+ /**< Look-Up Table data */
+} ADMW1001_LUT_TABLE;
+
+/*! LUT data format versions */
+typedef struct __attribute__((packed, aligned(4))) {
+ uint8_t major; /*!< Major version number */
+ uint8_t minor; /*!< Minor version number */
+} ADMW1001_LUT_VERSION;
+
+/*! LUT data header structure */
+typedef struct __attribute__((packed, aligned(4))) {
+ uint32_t signature;
+ /**< Hard-coded signature value (@ref ADMW1001_LUT_SIGNATURE) */
+ ADMW1001_LUT_VERSION version;
+ /**< LUT data format version (@ref ADMW1001_LUT_VERSION) */
+ uint16_t numTables;
+ /**< Total number of tables */
+ uint32_t totalLength;
+ /**< Total length (in bytes) of all table descriptors and data
+ * (excluding this header)
+ * This, plus the header length, must not exceed ADMW1001_LUT_MAX_SIZE
+ */
+} ADMW1001_LUT_HEADER;
+
+/*! LUT data top-level structure */
+typedef struct __attribute__((packed, aligned(4))) {
+ ADMW1001_LUT_HEADER header;
+ /*!< LUT data top-level header structure */
+ ADMW1001_LUT_TABLE tables[];
+ /*!< Variable-length array of one-or-more look-up table structures */
+} ADMW1001_LUT;
+
+/*! Alternative top-level structure for raw LUT data representation
+ *
+ * @note This is intended to be used for encapsulating the storage of static
+ * LUT data declarations in C files. The rawTableData can be cast
+ * to the ADMW1001_LUT type for further parsing/processing.
+ */
+typedef struct __attribute__((packed, aligned(4))) {
+ ADMW1001_LUT_HEADER header;
+ /*!< LUT data top-level header structure */
+ uint8_t rawTableData[];
+ /*!< Variable-length byte array of look-up tables in raw binary format */
+} ADMW1001_LUT_RAW;
+
+#ifdef __cplusplus
+}
+#endif
+
+/*!
+ * @}
+ */
+
+#endif /* __ADMW1001_LUT_DATA_H__ */
+