277 lines
8.9 KiB
C
277 lines
8.9 KiB
C
|
/****************************************************************************
|
||
|
|
||
|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
||
|
|
||
|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
||
|
be copied by any method or incorporated into another program without
|
||
|
the express written consent of Aerospace C.Power. This Information or any portion
|
||
|
thereof remains the property of Aerospace C.Power. The Information contained herein
|
||
|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
||
|
liability for its use in any way and conveys no license or title under
|
||
|
any patent or copyright and makes no representation or warranty that this
|
||
|
Information is free from patent or copyright infringement.
|
||
|
|
||
|
****************************************************************************/
|
||
|
|
||
|
#ifndef IOT_CAL_DATA_H
|
||
|
#define IOT_CAL_DATA_H
|
||
|
|
||
|
/* os shim includes */
|
||
|
#include "os_types.h"
|
||
|
#include "iot_config.h"
|
||
|
|
||
|
#ifdef __cplusplus
|
||
|
extern "C" {
|
||
|
#endif
|
||
|
|
||
|
/*
|
||
|
* cal data section is the place to store RF parameters.
|
||
|
*/
|
||
|
|
||
|
/* pack for the structures in the whole file */
|
||
|
#pragma pack(push) // save the pack status
|
||
|
#pragma pack(1) // 1 byte align
|
||
|
|
||
|
#define IOT_PHY_GAIN_STEP_NUM (85)
|
||
|
#define IOT_CAL_DATA_DUMMY_LEN (10)
|
||
|
#define IOT_OEM_PHY_MAGIC_NUM (0x5048595A)
|
||
|
#define IOT_OEM_EM_EXT_MAGIN_NUM (0x5048AA55)
|
||
|
#define IOT_OEM_EM_INNER_MAGIC_NUM (0x50485A5A)
|
||
|
|
||
|
#define IOT_PHY_CFG_MASK_CHIPID (0)
|
||
|
#define IOT_PHY_CFG_MASK_PPM (1)
|
||
|
#define IOT_PHY_CFG_MASK_TX_DC (2)
|
||
|
#define IOT_PHY_CFG_MASK_RX_DC (3)
|
||
|
#define IOT_PHY_CFG_MASK_PT_VER (4)
|
||
|
#define IOT_PHY_CFG_MASK_CALI_TEMP (5)
|
||
|
#define IOT_PHY_CFG_MASK_CALI_ADC (6)
|
||
|
#define IOT_PHY_CFG_MASK_CALI_RF_TXIQM (7)
|
||
|
#define IOT_PHY_CFG_MASK_CALI_RF_TXF (8)
|
||
|
#define IOT_PHY_CFG_MASK_CALI_PT_INFO (9)
|
||
|
#define IOT_PHY_CFG_MASK_CALI_RF_RXIQM (10)
|
||
|
|
||
|
|
||
|
/* adc module calibration data. actual_val = raw_val * k + b */
|
||
|
typedef struct _iot_adc_m_cal_data {
|
||
|
float k;
|
||
|
float b;
|
||
|
}iot_adc_m_cal_data_t;
|
||
|
|
||
|
/* rf version and phy tx calibration info */
|
||
|
typedef struct _iot_cal_data_rf_ver_phy_txiqm {
|
||
|
/* tx I MAG balance calibration value, range range: 0~15 */
|
||
|
uint8_t tx_i_mag : 4,
|
||
|
/* rf version, see RF_VER_XXX */
|
||
|
rf_ver : 4;
|
||
|
/* tx Q MAG balance calibration value, range range: 0~15 */
|
||
|
uint8_t tx_q_mag;
|
||
|
/* tx I phase calibration value, range range: 0~31 */
|
||
|
uint8_t tx_i_phase;
|
||
|
/* tx Q phase calibration value, range range: 0~31 */
|
||
|
uint8_t tx_q_phase;
|
||
|
/* tx I dc calibration value, range range: -127~127 */
|
||
|
int8_t tx_i_dc;
|
||
|
/* tx I dc calibration value, range range: -127~127 */
|
||
|
int8_t tx_q_dc;
|
||
|
} iot_cal_data_rf_ver_phy_txiqm_t;
|
||
|
|
||
|
/* rf phy rx calibration info */
|
||
|
typedef struct _iot_cal_data_rf_phy_rxiqm {
|
||
|
/* rx I MAG balance calibration value, range range: 0~15 */
|
||
|
uint8_t rx_i_mag : 4,
|
||
|
/* rx Q MAG balance calibration value, range range: 0~15 */
|
||
|
rx_q_mag : 4;
|
||
|
/* rx I phase calibration value, range range: 0~31 */
|
||
|
uint8_t rx_i_phase;
|
||
|
/* rx Q phase calibration value, range range: 0~31 */
|
||
|
uint8_t rx_q_phase;
|
||
|
} iot_cal_data_rf_phy_rxiqm_t;
|
||
|
|
||
|
/* rf phy tx fiter calibration info */
|
||
|
typedef struct _iot_cal_data_rf_phy_txf {
|
||
|
/* flag mark if the value of the corresponding option is valid */
|
||
|
uint8_t valid_mask;
|
||
|
/* tx filter bw calibration value for each option */
|
||
|
uint16_t bw_sel_value[3];
|
||
|
} iot_cal_data_rf_phy_txf_t;
|
||
|
|
||
|
|
||
|
typedef struct _iot_cal_data_pt_info {
|
||
|
/* the golden mac which used for the pt test */
|
||
|
uint8_t golden_mac[6];
|
||
|
/* production test time in bcd format */
|
||
|
uint8_t year;
|
||
|
uint8_t month;
|
||
|
uint8_t day;
|
||
|
uint8_t hour;
|
||
|
uint8_t min;
|
||
|
uint32_t golden_fw_ver;
|
||
|
uint32_t pt_tool_ver;
|
||
|
uint32_t pt_board_ver;
|
||
|
} iot_cal_data_pt_info;
|
||
|
|
||
|
/* halphy config setting */
|
||
|
typedef struct _iot_cal_data_halphy_real_cfg {
|
||
|
/* magic num */
|
||
|
uint32_t magic;
|
||
|
/* mask */
|
||
|
uint32_t mask;
|
||
|
/* chip id for check valid */
|
||
|
uint32_t chipid_hi;
|
||
|
uint32_t chipid_lo;
|
||
|
/* ppm cali */
|
||
|
int8_t ppm;
|
||
|
/* tx dc cali */
|
||
|
uint16_t tx_dc[4];
|
||
|
/* rx dc cali */
|
||
|
uint16_t rx_dc[IOT_PHY_GAIN_STEP_NUM];
|
||
|
/* pt fw version record */
|
||
|
uint32_t pt_fw_ver;
|
||
|
/* hardware version */
|
||
|
uint16_t hw_ver_major;
|
||
|
uint16_t hw_ver_minor;
|
||
|
/* unit: degrees centigrade, actual_temp = raw_temp + cali_temp */
|
||
|
float cali_temp;
|
||
|
/* adc module calibration data */
|
||
|
iot_adc_m_cal_data_t cali_adc_m;
|
||
|
/* rf version and phy tx iqm calibration data */
|
||
|
iot_cal_data_rf_ver_phy_txiqm_t rf_txiqm;
|
||
|
/* rf phy tx filter calibration data */
|
||
|
iot_cal_data_rf_phy_txf_t rf_txf;
|
||
|
/* the production info */
|
||
|
iot_cal_data_pt_info pt_info;
|
||
|
/* rf phy rx iqm calibration data */
|
||
|
iot_cal_data_rf_phy_rxiqm_t rf_rxiqm;
|
||
|
uint8_t reserved[IOT_CAL_DATA_DUMMY_LEN];
|
||
|
} iot_halphy_real_cfg_t;
|
||
|
|
||
|
/* rf golden uint calibration data size */
|
||
|
#define IOT_CAL_DATA_RF_GU_DATA_BYTES 200
|
||
|
/* rf golden uint calibration data layout */
|
||
|
typedef struct _iot_cal_data_rf_gu_t {
|
||
|
/* crc16 */
|
||
|
uint16_t crc;
|
||
|
/* calibration data */
|
||
|
uint8_t data[IOT_CAL_DATA_RF_GU_DATA_BYTES];
|
||
|
} iot_cal_data_rf_gu_t;
|
||
|
|
||
|
#define IOT_CAL_DATA_EM_EXT_PARA_BYTES 320 //TODO: check len
|
||
|
typedef struct _iot_cal_data_em_ext {
|
||
|
/* crc8 */
|
||
|
uint8_t crc;
|
||
|
/* energy meter extern module id */
|
||
|
uint8_t module_id;
|
||
|
/* extend crc8 */
|
||
|
uint8_t ext_crc;
|
||
|
/* cali data version */
|
||
|
uint8_t version;
|
||
|
/* magic num */
|
||
|
uint32_t magic;
|
||
|
/* calibration data */
|
||
|
uint8_t data[IOT_CAL_DATA_EM_EXT_PARA_BYTES];
|
||
|
} iot_cal_data_em_ext_t;
|
||
|
|
||
|
#define IOT_CAL_DATA_EM_INNER_PARA_BYTES 1016 //TODO: check len
|
||
|
typedef struct _iot_cal_data_em_inner_t {
|
||
|
/* magic num */
|
||
|
uint32_t magic;
|
||
|
/* energy meter inner module id */
|
||
|
uint32_t module_id : 8,
|
||
|
/* reserved */
|
||
|
rsvd : 16,
|
||
|
/* crc8 of the calibration data field */
|
||
|
crc : 8;
|
||
|
/* calibration data */
|
||
|
uint8_t data[IOT_CAL_DATA_EM_INNER_PARA_BYTES];
|
||
|
} iot_cal_data_em_inner_t;
|
||
|
|
||
|
typedef struct _iot_cal_data_cfg {
|
||
|
uint8_t crc;
|
||
|
iot_halphy_real_cfg_t halphy_cfg;
|
||
|
/* energy meter extern calibration parameters */
|
||
|
iot_cal_data_em_ext_t em_ext_cali;
|
||
|
#if (TARGET_VERSION == TARGET_KUNLUN2 || \
|
||
|
TARGET_VERSION == TARGET_KUNLUN3)
|
||
|
/* energy meter inner calibration parameters */
|
||
|
iot_cal_data_em_inner_t em_inner_cali;
|
||
|
#endif
|
||
|
#if (IOT_CLI_IC_TOOL_EN && HPLC_RF_DEV_SUPPORT)
|
||
|
iot_cal_data_rf_gu_t gu_cali;
|
||
|
#endif
|
||
|
} iot_cal_data_cfg_t;
|
||
|
|
||
|
/**
|
||
|
* @brief iot_cal_data_check_mask() - check calibration data valid.
|
||
|
* @param calcfg: pointer to receive cal data cfg.
|
||
|
* @param type: see IOT_PHY_CFG_MASK_XXX.
|
||
|
* @retval 0 calibration data invalid; others calibration data valid.
|
||
|
*/
|
||
|
uint32_t iot_cal_data_check_mask(iot_cal_data_cfg_t *calcfg, uint8_t type);
|
||
|
|
||
|
/**
|
||
|
* @brief iot_cal_data_set_mask() - set calibration data valid flag.
|
||
|
* @param calcfg: pointer to receive cal data cfg.
|
||
|
* @param type: see IOT_PHY_CFG_MASK_XXX.
|
||
|
*/
|
||
|
void iot_cal_data_set_mask(iot_cal_data_cfg_t *calcfg, uint8_t type);
|
||
|
|
||
|
/**
|
||
|
* @brief iot_cal_data_get_cfg() - read cal data cfg from flash cal data info section.
|
||
|
* @param cal data cfg: pointer to receive cal data cfg
|
||
|
* @retval 0 success; others fail
|
||
|
*/
|
||
|
uint32_t iot_cal_data_get_cfg(iot_cal_data_cfg_t** cal_data_cfg);
|
||
|
|
||
|
/**
|
||
|
* @brief iot_cal_data_set_cfg() - write cal data cfg to flash cal data info section.
|
||
|
* @param cal data cfg: pointer to receive cal data cfg
|
||
|
* @retval 0 success; others fail
|
||
|
*/
|
||
|
uint32_t iot_cal_data_set_cfg(iot_cal_data_cfg_t* cal_data_cfg);
|
||
|
|
||
|
/**
|
||
|
* @brief iot_cal_data_get_adc_m_cali() - read adc module calibration data.
|
||
|
* @param adc_m_cali_data: pointer to receive adc module calibration data
|
||
|
* @retval 0 success; others fail
|
||
|
*/
|
||
|
uint32_t iot_cal_data_get_adc_m_cali(iot_adc_m_cal_data_t **adc_m_cali_data);
|
||
|
|
||
|
/**
|
||
|
* @brief iot_cal_data_get_rf_phy_txiqm_cali() - read rf phy tx iqm calibration
|
||
|
* data.
|
||
|
* @param cali: pointer to pointer of rf phy tx iqm calibration data
|
||
|
* @retval 0 success; others fail
|
||
|
*/
|
||
|
uint32_t iot_cal_data_get_rf_phy_txiqm_cali(
|
||
|
iot_cal_data_rf_ver_phy_txiqm_t **cali);
|
||
|
|
||
|
/**
|
||
|
* @brief iot_cal_data_get_rf_phy_txf_cali() - read rf phy tx filter calibration data.
|
||
|
* @param cali: pointer to pointer of rf phy tx firter calibration data.
|
||
|
* @retval 0 success; others fail
|
||
|
*/
|
||
|
uint32_t iot_cal_data_get_rf_phy_txf_cali(iot_cal_data_rf_phy_txf_t **cali);
|
||
|
|
||
|
/**
|
||
|
* @brief iot_cal_data_get_mtd_sts() - get mtd status from global cal data.
|
||
|
* @param cal data cfg: void
|
||
|
* @retval 0 success; others fail
|
||
|
*/
|
||
|
uint32_t iot_cal_data_get_mtd_sts(void);
|
||
|
|
||
|
/**
|
||
|
* @brief iot_cal_data_init() - initialize global cal data.
|
||
|
* @param NULL
|
||
|
* @retval NULL
|
||
|
*/
|
||
|
void iot_cal_data_init();
|
||
|
|
||
|
#pragma pack(pop) // restore the pack status
|
||
|
|
||
|
|
||
|
#ifdef __cplusplus
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
#endif
|