Example program for EVAL-ADMX2001

Dependencies:   ADMX2001

Revision:
5:746e78113d7d
Child:
8:bd0b93e35392
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calibrate.h	Wed Oct 27 06:58:57 2021 +0000
@@ -0,0 +1,231 @@
+/* Copyright (c) 2021 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.
+  - Modified versions of the software must be conspicuously marked as such.
+  - This software is licensed solely and exclusively for use with processors/products
+  manufactured by or for Analog Devices, Inc.
+  - This software may not be combined or merged with other code in any manner
+  that would cause the software to become subject to terms and conditions which
+  differ from those listed here.
+  - 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.
+
+THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL
+PROPERTY RIGHTS INFRINGEMENT; 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.
+
+2021-01-10-7CBSD SLA
+*/
+
+
+/**
+ * @file:    calibrate.h
+ * @brief:   This file contains  type definitions and function prototype
+ *           for calibrate.c
+ * @details: Provides function definitions for command actions
+ * @defgroup    CAL_AND_COMP Calibration and compensation routines
+ */
+
+#ifndef __CALIBRATE_H__
+#define __CALIBRATE_H__
+
+/*============= I N C L U D E S =============*/
+#include <stdint.h>
+
+/*============= D E F I N E S =============*/
+#define DEFAULT_CAL_COEFF_INDEX (0)
+/**< Default calibration coefficient index  */
+#define DEFAULT_DC_COEFF_INDEX (0)
+/**< Default dc calibration coefficient index  */
+#define DEFAULT_COMPN_COEFF_INDEX (0)
+/**< Default compensation coefficient index  */
+#define NUM_CALIBRATION_SETS (16 + 1)
+/**< Max number of cal coefficient sets  */
+
+/** @brief password array size */
+#define MAX_PASSWORD_SIZE (12)
+/** @brief timestamp  array size */
+#define TIMESTAMP_SIZE (128)
+/** @brief
+ * Calibration states
+ * */
+
+/** No calibration done*/
+#define CAL_STAT_NO_CAL (0)
+/** calibration status is short -  Rs, Xs, Gs, Bs*/
+#define CAL_STAT_SHORT (0xF << 0)
+/** calibration status is open - Ro, Xo, Go, Bo*/
+#define CAL_STAT_OPEN (0xF << 4)
+/** calibration status is Load, Rg, xG, Gg, Bg*/
+#define CAL_STAT_LOAD (0xF << 8)
+/** calibration status dirty */
+#define CAL_STAT_DIRTY (1 << 15)
+/** Success */
+#define CAL_STATUS_SUCCESS 0
+/** Operation Failed */
+#define CAL_STATUS_FAILURE 1
+/** Password incorrect in calibration commit*/
+#define CAL_STATUS_INVALID_PASSWORD 5
+/** CRC error while reading coeffs from flash */
+#define CAL_STATUS_CRC_ERROR 3
+/** Number of calibration modes */
+#define CAL_NUM_MODES 4
+/** Number of calibration coeffcients */
+#define CAL_NUM_COEFFS 12
+/** Number of dc calibration coeffcients */
+#define CAL_NUM_DC_COEFFS 2
+
+/**
+ * @brief enumeration  for all calibration Modes
+ *
+ */
+typedef enum
+{
+    CAL_MODE_NONE = 0, /**< No correction applied */
+    CAL_MODE_CAL,  /**< Correction applied using calibration coefficients  */
+    CAL_MODE_COMP, /**< Corrections are applied using both calibration and \
+                    compensation coeffcients */
+} CAL_MODE;
+
+/**
+ * @brief enumeration  for all calibration coeffs
+ *
+ */
+typedef enum
+{
+    CAL_TYPE_NO_CAL = 0, /**< No Calibration */
+    CAL_TYPE_OPEN,       /**< OPEN Calibration*/
+    CAL_TYPE_SHORT,      /**< SHORT Calibration */
+    CAL_TYPE_LOAD,       /**< LOAD Calibration  */
+} CAL_TYPE;
+
+/**
+ * @brief enumeration  for all calibration coefficients
+ *
+ */
+typedef enum
+{
+    Ro = 0, /**< Open Resistance */
+    Xo,     /**< Open Reactance  */
+    Go,     /**< Open Conductance */
+    Bo,     /**< Open Susceptance  */
+    Rs,     /**< Short Resistance */
+    Xs,     /**< Short Reactance  */
+    Gs,     /**< Short Conductance */
+    Bs,     /**< Short Susceptance  */
+    Rg,     /**< Resistance gain calibration coefficient */
+    Xg,     /**< Reactance gain calibration coefficient */
+    Gg,     /**< Conductance gain calibration coefficient */
+    Bg      /**< Susceptance gain calibration coefficient */
+} CAL_COEFFICIENT;
+
+/**
+ * @brief enumeration  for Dc calibration coefficients
+ *
+ */
+typedef enum
+{
+    Rdg = 0, /**< gain coefficient */
+    Rdo,     /**< offset coefficient  */
+} DC_CAL_COEFFICIENT;
+
+/*============= D A T A  T Y P E S =============*/
+/**
+ *
+ *  @brief structure for all calibration coefficients
+ *
+ */
+typedef struct
+{
+    uint32_t status;      /**< status for Open/Load/Short */
+    uint32_t voltageGain; /**< voltage gain for calibration */
+    uint32_t currentGain; /**< current gain for calibration */
+    float frequency;      /**< input frequency   */
+    float temperature;    /**< input temperature */
+    double Rs;            /**< Short Resistance */
+    double Rdg;           /**< gain coefficient */
+    double Rdo;           /**< offset coefficient */
+} DcCalibrationCoeffs;
+
+/**
+ *
+ *  @brief structure for all calibration coefficients
+ *
+ */
+typedef struct
+{
+    uint32_t status;      /**< status for Open/Load/Short */
+    uint32_t voltageGain; /**< voltage gain for calibration */
+    uint32_t currentGain; /**< current gain for calibration */
+    float frequency;      /**< input frequency   */
+    float temperature;    /**< input temperature */
+    double Ro;            /**< Open Resistance */
+    double Xo;            /**< Open Reactance */
+    double Go;            /**< Open Conductance */
+    double Bo;            /**<  Open Susceptance */
+    double Rs;            /**< Short Resistance */
+    double Xs;            /**< Short Reactance */
+    double Gs;            /**< Short Conductance */
+    double Bs;            /**< Short Susceptance */
+    double Rg;            /**< Resistance gain calibration coefficient  */
+    double Xg;            /**< Reactance gain calibration coefficient */
+    double Gg;            /**< Conductance gain calibration coefficient */
+    double Bg;            /**< Susceptance gain calibration coefficient */
+} CalibrationCoeffs;
+
+/**
+ *
+ *  @brief structure for calibration data
+ *
+ */
+typedef struct
+{
+    uint16_t crc;
+    /**< crc value for this structure */
+    uint16_t numSets;
+    /**< number of sets filled  +1 for \0 */
+    uint16_t numDcSets;
+    /**< number of Dc coeffs filled  +1 for \0 */
+    /**FIXME: better to keep seperate count??*/
+    uint8_t timestamp[TIMESTAMP_SIZE + 1];
+    /**< time stamp     +1 for \0   */
+    uint8_t password[MAX_PASSWORD_SIZE + 1];
+    /**< commit password */
+    CalibrationCoeffs coeffs[NUM_CALIBRATION_SETS];
+    /**< array of calibration coefficients*/
+    DcCalibrationCoeffs dcCoeffs[NUM_CALIBRATION_SETS];
+    /**< array of DC calibration coefficients */
+} CalibrationData;
+
+/*============= F U N C T I O N  P R O T O T Y P E S =============*/
+
+
+/**
+ * @details perform specified cal type calibration .
+ * @param [in] calType - type of calibration
+ * @param [in] stdR - load value for Rt/Load calibration
+ * @param [in] stdX - load value for Xt/Load calibration
+ * @return ADMX_LCR_STATUS_SUCCESS - Success
+ *
+ */
+int32_t Calibrate(CAL_TYPE calType, float stdR, float stdX);
+
+#endif /* __CALIBRATE_H__ */