Files
kunlun/driver/extern/em/inc/iot_em_ext_calibration.h
2024-09-28 14:24:04 +08:00

147 lines
5.2 KiB
C
Executable File

/****************************************************************************
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_EM_EXT_CALIBRATION_H_
#define _IOT_EM_EXT_CALIBRATION_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "os_types.h"
#include "iot_em_ext_api.h"
/* extern energy meter calibration cmd type */
/* open energy meter extern module */
#define IOT_EM_EXT_CALI_CMD_MODULE_OPEN 0x00
/* set energy meter extern constant parameters */
#define IOT_EM_EXT_CALI_CMD_CONST_SET 0x01
/* set calibration parameter */
#define IOT_EM_EXT_CALI_CMD_PARA_SET 0x02
/* get calibration parameter */
#define IOT_EM_EXT_CALI_CMD_PARA_GET 0x03
/* calculate calibration parameter */
#define IOT_EM_EXT_CALI_CMD_PARA_CALC 0x04
/* get measure data */
#define IOT_EM_EXT_CALI_CMD_MEAS_GET 0x05
/* save current calibration parameters to oem */
#define IOT_EM_EXT_CALI_CMD_PARA_SAVE 0x06
/* trigger oneshot calibration */
#define IOT_EM_EXT_CALI_CMD_ONESHOT_TRIG 0x07
/* query oneshot calibration result */
#define IOT_EM_EXT_CALI_CMD_ONESHOT_QUERY 0x08
/* oneshot cali sample meas data delay interval, unit:ms */
#define IOT_EM_EXT_ONESHOT_SMPL_INTERVAL_MS 600
/* oneshot cali after init const parameter wait time, unit:ms */
#define IOT_EM_EXT_ONESHOT_WAIT_STABLE_MS 2000
/* oneshot cali state mechine of idle state */
#define IOT_EM_EXT_ONESHOT_CALI_SM_IDLE 0
/* oneshot cali state mechine of sample meas data state */
#define IOT_EM_EXT_ONESHOT_CALI_SM_SMPL 1
/* oneshot cali state mechine of stop state */
#define IOT_EM_EXT_ONESHOT_CALI_SM_STOP 2
/* oneshot cali fail reason of initiate fail */
#define IOT_EM_EXT_ONESHOT_CALI_FAIL_INIT 1
/* oneshot cali fail reason of write chip reg fail */
#define IOT_EM_EXT_ONESHOT_CALI_FAIL_WR_REG 2
/* oneshot cali fail reason of save parameter to flash fail */
#define IOT_EM_EXT_ONESHOT_CALI_FAIL_SAVE_PARA 3
/* output voltage factor */
#define IOT_EM_EXT_CALI_ONESHOT_OUT_U_RATE (10)
/* output current factor */
#define IOT_EM_EXT_CALI_ONESHOT_OUT_I_RATE (100000)
#pragma pack(push)
#pragma pack(1)
/* calibration data protocol header */
typedef struct _iot_em_ext_cali_cmd_hdr {
/* command execution result error code, see ERR_XXX */
uint8_t err_no;
/* command id, see IOT_EM_EXT_CALI_CMD_XXX */
uint8_t cmd;
/* parameter type id, see IOT_EM_EXT_CTYPE_XXX and IOT_EM_EXT_MTYPE_XXX */
uint8_t type;
/* phase id, see IOT_EM_EXT_PHASE_XXX */
uint8_t phase;
/* parameter bytes */
uint16_t len;
} iot_em_ext_cali_cmd_hdr_t;
/* oneshot cali channel data type define */
typedef struct _iot_em_ext_oneshot_cali_chn {
/* sample output meas voltage data, unit: 0.1V */
uint32_t u;
/* sample output meas current data, unit: 0.001A */
uint32_t i;
/* sample output raw active power data, unit: 1Walt */
int32_t p;
/* sample output raw reactive power data, unit: 1Var*/
int32_t q;
} iot_em_ext_oneshot_cali_chn_t;
typedef struct _iot_em_ext_oneshot_cali_misc {
/* current rms for n line */
uint32_t i_n_rms;
} iot_em_ext_oneshot_cali_misc_t;
typedef struct _iot_em_ext_oneshot_cali_item {
/* oneshot calibration misc data */
iot_em_ext_oneshot_cali_misc_t misc;
/* oneshot calibration phase data */
iot_em_ext_oneshot_cali_chn_t phase[IOT_EM_EXT_PHASE_ALL];
} iot_em_ext_oneshot_cali_item_t;
/* oneshot calibration context define */
typedef struct _iot_em_ext_oneshot_cali_ctxt {
/* cali state mechine current state */
uint32_t cur_state : 8,
/* cali state mechine last state */
last_state : 8,
/* calibration sample count */
sample_cnt : 16;
/* calibration fail reason */
uint32_t reason;
/* calibration timer */
timer_id_t cali_timer;
/* app set config parameter */
iot_em_ext_oneshot_cali_cfg_t app_cfg;
/* calibration sample data of all phase */
iot_em_ext_oneshot_cali_item_t smpl;
/* convert cfg data to unit of smaple data type */
iot_em_ext_oneshot_cali_item_t from_cfg;
/* packet of context */
iot_pkt_t *ctxt_pkt;
} iot_em_ext_oneshot_cali_ctxt_t;
/* @breif iot_em_ext_cali_oneshot_msg_handle() oneshot cali message handle
* @param func_id - function id
* @param pkt - message data of package
* @return none
*/
void iot_em_ext_cali_oneshot_msg_handle(uint8_t func_id, iot_pkt_t *pkt);
#pragma pack(pop)
#ifdef __cplusplus
}
#endif
#endif //_IOT_EM_EXT_CALIBRATION_H_