1014 lines
		
	
	
		
			36 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			1014 lines
		
	
	
		
			36 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_EM_EXT_CHIP_ATT_H_
							 | 
						||
| 
								 | 
							
								#define _IOT_EM_EXT_CHIP_ATT_H_
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								extern "C" {
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#include "iot_em_ext_api.h"
							 | 
						||
| 
								 | 
							
								#include "iot_utils_api.h"
							 | 
						||
| 
								 | 
							
								#include "iot_cal_data.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* ATT7022 chip address. start */
							 | 
						||
| 
								 | 
							
								/* invalid address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_INVALID_ADDR             0xFF
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MEAS_DATA_MASK           0xFFFFFF
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* measurement address. start */
							 | 
						||
| 
								 | 
							
								/* chip deviece id address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_DEV_ID_MADDR             0x00
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_DEV_ID                   0x7122A0
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* active power phase A measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_P_A_MADDR              0x01
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* active power phase B measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_P_B_MADDR              0x02
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* active power phase C measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_P_C_MADDR              0x03
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* active power phase All measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_P_ALL_MADDR            0x04
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* reactive power phase A measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_Q_A_MADDR              0x05
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* reactive power phase B measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_Q_B_MADDR              0x06
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* reactive power phase C measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_Q_C_MADDR              0x07
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* reactive power phase All measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_Q_ALL_MADDR            0x08
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* apparent power phase A measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_S_A_MADDR              0x09
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* apparent power phase B measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_S_B_MADDR              0x0A
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* apparent power phase C measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_S_C_MADDR              0x0B
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* apparent power phase All measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_S_ALL_MADDR            0x0C
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* active voltage phase A measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_U_RMS_A_MADDR            0x0D
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* active voltage phase B measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_U_RMS_B_MADDR            0x0E
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* active voltage phase C measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_U_RMS_C_MADDR            0x0F
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* active current phase A measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_I_RMS_A_MADDR            0x10
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* active current phase B measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_I_RMS_B_MADDR            0x11
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* active current phase C measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_I_RMS_C_MADDR            0x12
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* active current phase All measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_I_RMS_ALL_MADDR          0x13
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* power factor phase A measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_FACTOR_A_MADDR         0x14
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* power factor phase B measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_FACTOR_B_MADDR         0x15
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* power factor phase C measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_FACTOR_C_MADDR         0x16
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* power factor phase All measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_FACTOR_ALL_MADDR       0x17
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* power angle(U - I) phase A measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANGLE_UI_A_MADDR         0x18
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* power angle(U - I) phase B measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANGLE_UI_B_MADDR         0x19
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* power angle(U - I) phase C measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANGLE_UI_C_MADDR         0x1A
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* interrupt flag measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_INTR_FLAG_MADDR          0x1B
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* line frequency measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_LINE_FREQ_MADDR          0x1C
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* energy flag measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_E_FLAG_MADDR             0x1D
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* active energy phase A measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_E_P_A_MADDR              0x1E
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* active energy phase B measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_E_P_B_MADDR              0x1F
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* active energy phase C measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_E_P_C_MADDR              0x20
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* active energy phase All measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_E_P_ALL_MADDR            0x21
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* reactive energy phase A measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_E_Q_A_MADDR              0x22
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* reactive energy phase B measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_E_Q_B_MADDR              0x23
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* reactive energy phase C measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_E_Q_C_MADDR              0x24
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* reactive energy phase All measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_E_Q_ALL_MADDR            0x25
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* angle phase A and phase B measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANGLE_UAB_MADDR          0x26
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* angle phase A and phase C measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANGLE_UAC_MADDR          0x27
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* angle phase B and phase C measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANGLE_UBC_MADDR          0x28
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* N-line current measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_I_N_MADDR                0x29
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* temperature measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_TPSD_MADDR               0x2A
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* active voltage phase All measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_U_RMS_ALL_MADDR          0x2B
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* status measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_STATUS_MADDR             0x2C
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* communication data backup measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_COMM_BACKUP_MADDR        0x2D
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* communication data checksum measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_COMM_CHKSUM_MADDR        0x2E
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* current sample phase A measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_I_SAMPLE_A_MADDR         0x2F
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* current sample phase B measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_I_SAMPLE_B_MADDR         0x30
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* current sample phase C measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_I_SAMPLE_C_MADDR         0x31
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* voltage sample phase A measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_U_SAMPLE_A_MADDR         0x32
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* voltage sample phase B measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_U_SAMPLE_B_MADDR         0x33
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* voltage sample phase C measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_U_SAMPLE_C_MADDR         0x34
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* apparent energy phase A measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_E_S_A_MADDR              0x35
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* apparent energy phase B measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_E_S_B_MADDR              0x36
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* apparent energy phase C measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_E_S_C_MADDR              0x37
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* apparent energy phase All measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_E_S_ALL_MADDR            0x38
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* fast count phase A measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_FSTCNT_A_MADDR           0x39
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* fast count phase B measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_FSTCNT_B_MADDR           0x3A
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* fast count phase C measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_FSTCNT_C_MADDR           0x3B
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* fast count phase All measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_FSTCNT_ALL_MADDR         0x3C
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* power sign measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_SIGN_MADDR             0x3D
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_SIGN_P_A_MASK          0x01
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_SIGN_P_A_OFFSET        0
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_SIGN_P_B_MASK          0x02
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_SIGN_P_B_OFFSET        1
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_SIGN_P_C_MASK          0x04
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_SIGN_P_C_OFFSET        2
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_SIGN_P_ALL_MASK        0x08
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_SIGN_P_ALL_OFFSET      3
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_SIGN_Q_A_MASK          0x10
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_SIGN_Q_A_OFFSET        4
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_SIGN_Q_B_MASK          0x20
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_SIGN_Q_B_OFFSET        5
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_SIGN_Q_C_MASK          0x40
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_SIGN_Q_C_OFFSET        6
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_SIGN_Q_ALL_MASK        0x80
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_SIGN_Q_ALL_OFFSET      7
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* active/reactive power direction measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_DIRECTION_ALL_MADDR    0x3E
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* current sample N-line measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_I_SAMPLE_N_MADDR         0x3F
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* line active power phase A measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_LINE_P_A_MADDR         0x40
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* line active power phase B measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_LINE_P_B_MADDR         0x41
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* line active power phase C measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_LINE_P_C_MADDR         0x42
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* line active power phase All measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_LINE_P_ALL_MADDR       0x43
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* line active energy phase A measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_E_LINE_P_A_MADDR         0x44
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* line active energy phase B measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_E_LINE_P_B_MADDR         0x45
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* line active energy phase C measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_E_LINE_P_C_MADDR         0x46
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* line active energy phase All measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_E_LINE_P_ALL_MADDR       0x47
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* line active voltage phase A measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_U_LINE_RMS_A_MADDR       0x48
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* line active voltage phase B measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_U_LINE_RMS_B_MADDR       0x49
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* line active voltage phase C measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_U_LINE_RMS_C_MADDR       0x4A
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* line active current phase A measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_I_LINE_RMS_A_MADDR       0x4B
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* line active current phase B measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_I_LINE_RMS_B_MADDR       0x4C
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* line active current phase C measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_I_LINE_RMS_C_MADDR       0x4D
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* line energy status measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_E_LINE_STATUS_MADDR      0x4E
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* wave buffer length measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_WAVE_LEN_MADDR           0x7E
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* wave buffer read idx measurement address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_WAVE_RIDX_MADDR          0x7F
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MEAS_ADDR_START          0x00
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MEAS_ADDR_END            0x7F
							 | 
						||
| 
								 | 
							
								/* measurement address. end */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* write to calibration address data mask */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_CALI_DATA_MASK           0xFFFF
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* calibration address. start */
							 | 
						||
| 
								 | 
							
								/* calibration start address. */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_START_CADDR              0x00
							 | 
						||
| 
								 | 
							
								/* calibration start address default value */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_CALI_START_KEY           0xAAAA
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* mode contrl calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_CFG_CADDR           0x01
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_I_N_MASK            0x01
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_I_N_OFFSET          0
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_I_A_MASK            0x02
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_I_A_OFFSET          1
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_U_A_MASK            0x04
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_U_A_OFFSET          2
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_I_B_MASK            0x08
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_I_B_OFFSET          3
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_U_B_MASK            0x10
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_U_B_OFFSET          4
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_I_C_MASK            0x20
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_I_C_OFFSET          5
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_U_C_MASK            0x40
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_U_C_OFFSET          6
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_ADC_CHOP_MASK       0x80
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_ADC_CHOP_OFFSET     7
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* SampleR 1/0, choise femu frequnce. */
							 | 
						||
| 
								 | 
							
								/* 00b: 1.8432MHz, 01b: 921.6kHz, 1Xb: 460.8kHz */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_FEMU_1842K          0x00
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_FEMU_921K           0x01
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_FEMU_460K           0x02
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_FEMU_MASK           0x300
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_FEMU_OFFSET         8
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* CIB_ADC1/0, choise femu frequnce. */
							 | 
						||
| 
								 | 
							
								/* 00b/01b: 5uA, 10b: 7.5uA, 11b: 10uA */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_IREF_5UA            0x00
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_IREF_7_5UA          0x02
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_IREF_10UA           0x03
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_IREF_MASK           0xC00
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_IREF_OFFSET         10
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_SPD_SLOW            0x01
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_SPD_FAST            0x00
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_SPD_MASK            0x1000
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_SPD_OFFSET          12
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_TIME_SLOW           0x01
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_TIME_FAST           0x00
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_TIME_MASK           0x2000
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_TIME_OFFSET         13
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_UB_SRC_MASK         0x4000
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_UB_SRC_OFFSET       14
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_REF_CHOP_MASK       0x8000
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MODE_REF_CHOP_OFFSET     15
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* ADC gain calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ADC_GAIN_CADDR           0x02
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ADC_GAIN_1               0x00
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ADC_GAIN_2               0x01
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ADC_GAIN_8               0x02
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ADC_GAIN_16              0x03
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ADC_GAIN_N_MASK          0x03
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ADC_GAIN_N_OFFSET        0
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ADC_GAIN_A_MASK          0x0C
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ADC_GAIN_A_OFFSET        2
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ADC_GAIN_B_MASK          0x30
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ADC_GAIN_B_OFFSET        4
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ADC_GAIN_C_MASK          0xC0
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ADC_GAIN_C_OFFSET        6
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ADC_GAIN_ALL_MASK        0x300
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ADC_GAIN_ALL_OFFSET      8
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* EMU calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_CADDR                0x03
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_FS_BASE_14_4KHZ      0x04
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_FS_BASE_7_2KHZ       0x03
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_FS_BASE_3_6KHZ       0x02
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_FS_BASE_1_8KHZ       0x01
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_FS_BASE_0_9KHZ       0x00
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_FS_MASK              0x07
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_FS_OFFSET            0
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_MEAS_RMS             0x01
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_MEAS_PQS             0x00
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_MEAS_MASK            0x08
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_MEAS_OFFSET          3
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_ZC_RISE              0x00
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_ZC_FALL              0x01
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_ZC_ALL               0x02
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_ZC_MASK              0x30
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_ZC_OFFSET            4
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_SUM_MODE0            0x00
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_SUM_MODE1            0x01
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_SUM_MASK             0x40
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_SUM_OFFSET           6
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_E_SAVE_TOTAL         0x00
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_E_SAVE_CLR           0x01
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_E_SAVE_MASK          0x80
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_E_SAVE_OFFSET        7
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_WAVE_BYPASS          0x00
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_WAVE_HIGHPASS        0x01
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_WAVE_LINEPASS        0x02
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_WAVE_SEL_MASK        0x300
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_WAVE_SEL_OFFSET      8
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_LINE_HARM_MASK       0x400
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_LINE_HARM_OFFSET     10
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_START_CURRENT        0x00
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_START_POWER          0x01
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_START_MASK           0x800
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_START_OFFSET         11
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_CF1_MASK             0x1000
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_CF1_OFFSET           12
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_CF2_MASK             0x2000
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_CF2_OFFSET           13
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_CF3_MASK             0x4000
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_CF3_OFFSET           14
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_CF4_MASK             0x8000
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMU_CF4_OFFSET           15
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* gain for active power phase A calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_GAIN_P_P_A_CADDR         0x04
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* gain for active power phase B calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_GAIN_P_P_B_CADDR         0x05
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* gain for active power phase C calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_GAIN_P_P_C_CADDR         0x06
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* gain for reactive power phase A calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_GAIN_P_Q_A_CADDR         0x07
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* gain for reactive power phase B calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_GAIN_P_Q_B_CADDR         0x08
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* gain for reactive power phase C calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_GAIN_P_Q_C_CADDR         0x09
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* gain for apparent power phase A calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_GAIN_P_S_A_CADDR         0x0A
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* gain for apparent power phase B calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_GAIN_P_S_B_CADDR         0x0B
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* gain for apparent power phase C calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_GAIN_P_S_C_CADDR         0x0C
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* phase calibration0 for phase A calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_PHASE_CALI0_A_CADDR      0x0D
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* phase calibration0 for phase B calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_PHASE_CALI0_B_CADDR      0x0E
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* phase calibration0 for phase C calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_PHASE_CALI0_C_CADDR      0x0F
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* phase calibration1 for phase A calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_PHASE_CALI1_A_CADDR      0x10
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* phase calibration1 for phase B calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_PHASE_CALI1_B_CADDR      0x11
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* phase calibration1 for phase C calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_PHASE_CALI1_C_CADDR      0x12
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* offset for active power phase A calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_P_OFFSET_A_CADDR       0x13
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* offset for active power phase B calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_P_OFFSET_B_CADDR       0x14
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* offset for active power phase C calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_P_OFFSET_C_CADDR       0x15
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* phase calibration for reactive power calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_PHASE_CALI_P_Q_CADDR     0x16
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* gain for voltage phase A calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_GAIN_U_A_CADDR           0x17
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* gain for voltage phase B calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_GAIN_U_B_CADDR           0x18
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* gain for voltage phase C calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_GAIN_U_C_CADDR           0x19
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* gain for current phase A calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_GAIN_I_A_CADDR           0x1A
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* gain for current phase B calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_GAIN_I_B_CADDR           0x1B
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* gain for current phase C calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_GAIN_I_C_CADDR           0x1C
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* start current calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_I_START_CADDR            0x1D
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* high frequence constant calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_HFCONST_CADDR            0x1E
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* voltage fail calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_UFAIL_CADDR              0x1F
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* current gain for 7nd calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_GAIN_ADC7_ADDR           0x20
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* offset for reactive power phase A calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_Q_OFFSET_A_CADDR       0x21
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* offset for reactive power phase B calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_Q_OFFSET_B_CADDR       0x22
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* offset for reactive power phase C calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_Q_OFFSET_C_CADDR       0x23
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* offset for active voltage phase A calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_OFFSET_U_RMS_A_CADDR     0x24
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* offset for active voltage phase B calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_OFFSET_U_RMS_B_CADDR     0x25
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* offset for active voltage phase C calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_OFFSET_U_RMS_C_CADDR     0x26
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* offset for active current phase A calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_OFFSET_I_RMS_A_CADDR     0x27
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* offset for active current phase B calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_OFFSET_I_RMS_B_CADDR     0x28
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* offset for active current phase C calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_OFFSET_I_RMS_C_CADDR     0x29
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* offset for voltage channel ADC phase A calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_OFFSET_U_ADC_A_CADDR     0x2A
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* offset for voltage channel ADC phase B calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_OFFSET_U_ADC_B_CADDR     0x2B
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* offset for voltage channel ADC phase C calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_OFFSET_U_ADC_C_CADDR     0x2C
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* offset for current channel ADC phase A calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_OFFSET_I_ADC_A_CADDR     0x2D
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* offset for current channel ADC phase B calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_OFFSET_I_ADC_B_CADDR     0x2E
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* offset for current channel ADC phase C calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_OFFSET_I_ADC_C_CADDR     0x2F
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* EMUIE calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMUIE_CADDR              0x30
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* analog module config calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANALOG_CFG_CADDR         0x31
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_7ST_CH_MASK          0x01
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_7ST_CH_OFFSET        0
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_I_CH_MASK            0x02
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_I_CH_OFFSET          1
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_U_CH_MASK            0x04
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_U_CH_OFFSET          2
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_ROCHE_MASK           0x08
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_ROCHE_OFFSET         3
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_TPS_MASK             0x10
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_TPS_OFFSET           4
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_BOR_MASK             0x20
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_BOR_OFFSET           5
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_INTR_LOW             0x00
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_INTR_HIGH            0x01
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_INTR_LVL_MASK        0x40
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_INTR_LVL_OFFSET      6
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_TPS_SEL_PN           0x00
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_TPS_SEL_R            0x01
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_TPS_SEL_MASK         0x80
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_TPS_SEL_OFFSET       7
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_SPI_SPD_HIGH         0x00
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_TPS_SPD_LOW          0x01
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_SPI_SPD_MASK         0x800
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ANA_SPI_SPD_OFFSET       11
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* gain for all channel calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ACG_CADDR                0x32
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* HFConst double calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_GAIN_HFCNT_CADDR         0x33
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* gain for fundamental calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_GAIN_LINE_CADDR          0x34
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* pin control calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_PIN_CTL_CADDR            0x35
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* start power calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_START_CADDR            0x36
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* phase iregion calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_PHASE_IREGION0_CADDR     0x37
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* SAG sycle length calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_SAG_CYC_LEN_CADDR        0x38
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* SAG level calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_SAG_LVL_CADDR            0x39
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* phase iregion calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_PHASE_IREGION1_CADDR     0x60
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* phase calibration2 for phase A/B/C calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_PHASE_CALI2_A_CADDR      0x61
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_PHASE_CALI2_B_CADDR      0x62
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_PHASE_CALI2_C_CADDR      0x63
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* offset for active power(low 8bit) phase A~C calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_P_OFFSET_L_A_CADDR     0x64
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_P_OFFSET_L_B_CADDR     0x65
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_P_OFFSET_L_C_CADDR     0x66
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* offset for reactive power(low 8bit) phase A~C calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_Q_OFFSET_L_A_CADDR     0x67
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_Q_OFFSET_L_B_CADDR     0x68
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_P_Q_OFFSET_L_C_CADDR     0x69
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* TPS offset calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_TPS_OFFSET_CADDR         0x6B
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* offset for three phase current vector sum calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_I_T_RMS_OFFSET_CADDR     0x6A
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* TPS gain calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_TPS_GAIN_CADDR           0x6C
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* Vref coefficient of compensation gain A calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_TCCOFFA_CADDR            0x6D
							 | 
						||
| 
								 | 
							
								/* att chip + board compensation */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_TCCOFFA_CHIP_BOARD       0xFF11
							 | 
						||
| 
								 | 
							
								/* att chip only compensation */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_TCCOFFA_CHIP_ONLY        0xFF00
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* Vref coefficient of compensation gain B calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_TCCOFFB_CADDR            0x6E
							 | 
						||
| 
								 | 
							
								/* att chip + board compensation */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_TCCOFFB_CHIP_BOARD       0x2B53
							 | 
						||
| 
								 | 
							
								/* att chip + board compensation */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_TCCOFFB_CHIP_ONLY        0x0DB8
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* Vref coefficient of compensation gain C calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_TCCOFFC_CADDR            0x6F
							 | 
						||
| 
								 | 
							
								/* att chip + board compensation */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_TCCOFFC_CHIP_BOARD       0xD483
							 | 
						||
| 
								 | 
							
								/* att chip + board compensation */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_TCCOFFC_CHIP_ONLY        0xD1DA
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* algorithmic control address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMC_CFG_CADDR            0x70
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMC_VREFAUTO_EN_MASK     0x02
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMC_VREFAUTO_EN_OFFSET   1
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMC_3P3L_EN_MASK         0x01
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EMC_3P3L_EN_OFFSET       0
							 | 
						||
| 
								 | 
							
								//TODO: add others bit
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* over current level calibration address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_I_OVER_LVL_CADDR         0x71
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_CALI_ADDR_START          0x00
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_CALI_ADDR_END            0x7F
							 | 
						||
| 
								 | 
							
								/* calibration address. end */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* function address. start */
							 | 
						||
| 
								 | 
							
								/* start sample channel command address. 0~0xB valid */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_START_SAMPLE_FADDR       0xC0
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* get sample buffer read index command address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_SET_SAMPLE_RIDX_FADDR    0xC1
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* clear chip all calibration parameter command address  */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_CLR_CALI_PARA_FADDR      0xC3
							 | 
						||
| 
								 | 
							
								/* clear command data value key */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_CLR_CALI_KEY             0x00
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* set sync mode parameter command address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_SET_SYNC_PARA_FADDR      0xC4
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* start data sync function command address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_START_SYNC_PARA_FADDR    0xC5
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* set chip reg map mode command address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_REG_MAP_MODE_FADDR       0xC6
							 | 
						||
| 
								 | 
							
								/* set chip reg mode key value.
							 | 
						||
| 
								 | 
							
								 * if set to IOT_EM_EXT_ATT_FUN_CALI_KEY. chip reg map to calibiration
							 | 
						||
| 
								 | 
							
								 * else the chip reg map to measure.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_REG_MAP_KEY              0x5A
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* enable/disable calibrtion parameter is writable command address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_CALI_W_ENA_FADDR         0xC9
							 | 
						||
| 
								 | 
							
								/* enable: set parameter to IOT_EM_EXT_ATT_CALI_W_KEY.
							 | 
						||
| 
								 | 
							
								 * disable: set parameter other value.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_CALI_W_KEY               0x5A
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* software reset chip command address */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_SW_REST_FADDR            0xD3
							 | 
						||
| 
								 | 
							
								/* sw reset parameter key */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_SW_REST_KEY              0x00
							 | 
						||
| 
								 | 
							
								/* function address. end */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* write reg key */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_REG_W_BIT_KEY            (1 << 7)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_R_REG_ADDR_MAX           \
							 | 
						||
| 
								 | 
							
								    max(IOT_EM_EXT_ATT_MEAS_ADDR_END, IOT_EM_EXT_ATT_CALI_ADDR_END)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_WAIT_KICK_2US            (29)
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_WAIT_KICK_3US            (43)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* spi defines */
							 | 
						||
| 
								 | 
							
								/* if spi freq less than this reference value. the data(3bytes) can be read
							 | 
						||
| 
								 | 
							
								 * without waiting after the command(1byte) is written. otherwise need to wait
							 | 
						||
| 
								 | 
							
								 * at least 2us after writing the command before reading the data.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_SPI_FREQ_NO_WAIT         (500 * 1000) //500kHz
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* default spi freq */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_SPI_FREQ_DEF             (1000 * 1000)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* spi communication command and data byte length  */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_SPI_RW_BYTES             (4)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* spi communication dummy data */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_SPI_DUMMY_DATA           (0xFF)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* spi communication wait tx/rx status try system kick cnt max */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_SPI_TRY_CNT              (5000)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* input chip voltage channel rated voltage */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_UCH_UN                   (220)
							 | 
						||
| 
								 | 
							
								/* input chip current channel Ib sample voltage */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ICHB_SAMPLE_U_MV         (50)
							 | 
						||
| 
								 | 
							
								/* Ib sample voltage = 50mV, the channel constant */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_ICHB_SAMPLE_CONST        (60)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* att chip hfconst max/min value */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_HFCONST_MAX              (0xD00)
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_HFCONST_MIN              (0x02)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* output rate gain. start */
							 | 
						||
| 
								 | 
							
								/* output line frequency factor */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_OUT_FREQ_RATE            (100)
							 | 
						||
| 
								 | 
							
								/* output temperature factor */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_OUT_TPSD_RATE            (10)
							 | 
						||
| 
								 | 
							
								/* output voltage factor */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_OUT_U_RATE               (10)
							 | 
						||
| 
								 | 
							
								/* output current factor */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_OUT_I_RATE               (100000)
							 | 
						||
| 
								 | 
							
								/* output current factor */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_OUT_ANGLE_RATE           (10)
							 | 
						||
| 
								 | 
							
								/* output P/Q/S factor */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_OUT_POWER_RATE           (1000)
							 | 
						||
| 
								 | 
							
								/* output energy factor */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_OUT_ENERGY_RATE          (100)
							 | 
						||
| 
								 | 
							
								/* output power factor */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_OUT_PFACTOR_RATE         (1000)
							 | 
						||
| 
								 | 
							
								/* output rate gain. end */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* att reg default value start */
							 | 
						||
| 
								 | 
							
								/* current start up threshold reg default value */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_DEFAULT_I_START          (0x160)
							 | 
						||
| 
								 | 
							
								/* power start up threshold reg default value */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_DEFAULT_P_START          (0x30)
							 | 
						||
| 
								 | 
							
								/* att reg default value end */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* calibration parameter buffer len */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_CALI_PARA_LEN    \
							 | 
						||
| 
								 | 
							
								    (sizeof(iot_em_ext_cali_const_t) + sizeof(iot_em_ext_att_cali_misc_t) + \
							 | 
						||
| 
								 | 
							
								        sizeof(iot_em_ext_att_cali_common_t) * IOT_EM_EXT_PHASE_ALL)
							 | 
						||
| 
								 | 
							
								/* calibration reserve infomation length in misc ext */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_EX_INFO_LEN              (8)
							 | 
						||
| 
								 | 
							
								/* calibration extend misc reserve length */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_MISC_EX_LEN              (80)
							 | 
						||
| 
								 | 
							
								/* calibration extend phase reserve length */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_ATT_PHASE_EX_LEN             (40)
							 | 
						||
| 
								 | 
							
								/* calibration extend parameter lenght */
							 | 
						||
| 
								 | 
							
								#define IOT_EM_EXT_CALI_PARA_EXT_LEN             \
							 | 
						||
| 
								 | 
							
								    (sizeof(iot_em_ext_att_cali_misc_ex_t) +     \
							 | 
						||
| 
								 | 
							
								        sizeof(iot_em_ext_att_cali_common_ex_t) * IOT_EM_EXT_PHASE_ALL)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#pragma pack(push)
							 | 
						||
| 
								 | 
							
								#pragma pack(1)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* energy calibration ctxt. start */
							 | 
						||
| 
								 | 
							
								/* energy calibration misc parameter */
							 | 
						||
| 
								 | 
							
								typedef struct _iot_em_ext_att_cali_misc {
							 | 
						||
| 
								 | 
							
								    /* reactive power phase error calibration */
							 | 
						||
| 
								 | 
							
								    int32_t p_q_phase_cali;
							 | 
						||
| 
								 | 
							
								    /* tpsd offset calibration */
							 | 
						||
| 
								 | 
							
								    int32_t tpsd_offset;
							 | 
						||
| 
								 | 
							
								} iot_em_ext_att_cali_misc_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* ennergy calibration reserve infomation */
							 | 
						||
| 
								 | 
							
								typedef struct _iot_em_ext_att_cali_info_ext {
							 | 
						||
| 
								 | 
							
								    uint8_t data[IOT_EM_EXT_ATT_EX_INFO_LEN];
							 | 
						||
| 
								 | 
							
								} iot_em_ext_att_cali_info_ex_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* energy calibration misc extend data type */
							 | 
						||
| 
								 | 
							
								typedef struct _iot_em_ext_att_cali_misc_ex_data {
							 | 
						||
| 
								 | 
							
								    iot_em_ext_att_cali_info_ex_t info;
							 | 
						||
| 
								 | 
							
								    /* tri-phase current vector sum rms offset */
							 | 
						||
| 
								 | 
							
								    uint16_t i_t_offset;
							 | 
						||
| 
								 | 
							
								    /* current start up threshold */
							 | 
						||
| 
								 | 
							
								    uint16_t i_start;
							 | 
						||
| 
								 | 
							
								    /* power start up threshold */
							 | 
						||
| 
								 | 
							
								    uint16_t p_start;
							 | 
						||
| 
								 | 
							
								    /* current gain for phase n*/
							 | 
						||
| 
								 | 
							
								    uint16_t i_n_gain;
							 | 
						||
| 
								 | 
							
								    //TODO: will add new misc ext cali data
							 | 
						||
| 
								 | 
							
								} iot_em_ext_att_cali_misc_ex_data_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* energy calibration misc ext type */
							 | 
						||
| 
								 | 
							
								typedef union _iot_em_ext_att_cali_misc_ex {
							 | 
						||
| 
								 | 
							
								    iot_em_ext_att_cali_misc_ex_data_t ex;
							 | 
						||
| 
								 | 
							
								    uint8_t data[IOT_EM_EXT_ATT_MISC_EX_LEN];
							 | 
						||
| 
								 | 
							
								} iot_em_ext_att_cali_misc_ex_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* energy calibration common extend data type */
							 | 
						||
| 
								 | 
							
								typedef struct _iot_em_ext_att_cali_common_ex_data {
							 | 
						||
| 
								 | 
							
								    uint16_t rsvd;
							 | 
						||
| 
								 | 
							
								    //TODO: will add new common ex cali data
							 | 
						||
| 
								 | 
							
								} iot_em_ext_att_cali_common_ex_data_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* energy calibration common parameter extend */
							 | 
						||
| 
								 | 
							
								typedef union _iot_em_ext_att_cali_common_ex {
							 | 
						||
| 
								 | 
							
								    iot_em_ext_att_cali_common_ex_data_t ex;
							 | 
						||
| 
								 | 
							
								    uint8_t data[IOT_EM_EXT_ATT_PHASE_EX_LEN];
							 | 
						||
| 
								 | 
							
								} iot_em_ext_att_cali_common_ex_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* energy calibration common parameter */
							 | 
						||
| 
								 | 
							
								typedef struct _iot_em_ext_att_cali_common {
							 | 
						||
| 
								 | 
							
								    /* active power gain */
							 | 
						||
| 
								 | 
							
								    uint16_t p_p_gain;
							 | 
						||
| 
								 | 
							
								    /* reactive power gain */
							 | 
						||
| 
								 | 
							
								    uint16_t p_q_gain;
							 | 
						||
| 
								 | 
							
								    /* apparent power gain */
							 | 
						||
| 
								 | 
							
								    uint16_t p_s_gain;
							 | 
						||
| 
								 | 
							
								    /* phase calibrtion I region */
							 | 
						||
| 
								 | 
							
								    uint16_t phase_i_region0;
							 | 
						||
| 
								 | 
							
								    uint16_t phase_i_region1;
							 | 
						||
| 
								 | 
							
								    /* power phase error calibration */
							 | 
						||
| 
								 | 
							
								    uint16_t phase_cali0;
							 | 
						||
| 
								 | 
							
								    uint16_t phase_cali1;
							 | 
						||
| 
								 | 
							
								    uint16_t phase_cali2;
							 | 
						||
| 
								 | 
							
								    /* voltage gain */
							 | 
						||
| 
								 | 
							
								    uint16_t u_gain;
							 | 
						||
| 
								 | 
							
								    /* current gain */
							 | 
						||
| 
								 | 
							
								    uint16_t i_gain;
							 | 
						||
| 
								 | 
							
								    /* voltage rms offset */
							 | 
						||
| 
								 | 
							
								    uint16_t u_offset;
							 | 
						||
| 
								 | 
							
								    /* current rms offset */
							 | 
						||
| 
								 | 
							
								    uint16_t i_offset;
							 | 
						||
| 
								 | 
							
								    /* active power offset. 24bit */
							 | 
						||
| 
								 | 
							
								    uint32_t p_p_offset;
							 | 
						||
| 
								 | 
							
								    /* reactive power offset. 24bit */
							 | 
						||
| 
								 | 
							
								    uint32_t p_q_offset;
							 | 
						||
| 
								 | 
							
								} iot_em_ext_att_cali_common_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* calibration parameters ctxt */
							 | 
						||
| 
								 | 
							
								typedef struct _iot_em_ext_att_cali_para {
							 | 
						||
| 
								 | 
							
								    /* constant calibration */
							 | 
						||
| 
								 | 
							
								    iot_em_ext_cali_const_t         const_cali;
							 | 
						||
| 
								 | 
							
								    /* energy caibration misc parameter */
							 | 
						||
| 
								 | 
							
								    iot_em_ext_att_cali_misc_t      misc;
							 | 
						||
| 
								 | 
							
								    /* each phase(phase A/B/C) calibration parameter */
							 | 
						||
| 
								 | 
							
								    iot_em_ext_att_cali_common_t    phase[IOT_EM_EXT_PHASE_ALL];
							 | 
						||
| 
								 | 
							
								    /* calibration misc extend parameter */
							 | 
						||
| 
								 | 
							
								    iot_em_ext_att_cali_misc_ex_t   misc_ex;
							 | 
						||
| 
								 | 
							
								    /* calibration phase extend reserve parameter */
							 | 
						||
| 
								 | 
							
								    iot_em_ext_att_cali_common_ex_t phase_ex[IOT_EM_EXT_PHASE_ALL];
							 | 
						||
| 
								 | 
							
								} iot_em_ext_att_cali_para_t;
							 | 
						||
| 
								 | 
							
								/* energy calibration ctxt. end */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#pragma pack(pop)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* save chip parameter and constant */
							 | 
						||
| 
								 | 
							
								typedef struct _iot_em_ext_att_hw_nv_para {
							 | 
						||
| 
								 | 
							
								    /* communication interface frequency */
							 | 
						||
| 
								 | 
							
								    uint32_t comm_freq              : 24,
							 | 
						||
| 
								 | 
							
								    /* energy meter reset gpio */
							 | 
						||
| 
								 | 
							
								        gpio_rst                    : 8;
							 | 
						||
| 
								 | 
							
								    /* hw spi interface config */
							 | 
						||
| 
								 | 
							
								    iot_spi_cfg_t spi_cfg;
							 | 
						||
| 
								 | 
							
								    /* calibration constant value */
							 | 
						||
| 
								 | 
							
								    iot_em_ext_cali_const_t const_cfg;
							 | 
						||
| 
								 | 
							
								    /* high freqency constant. base EC */
							 | 
						||
| 
								 | 
							
								    uint32_t hfconst;
							 | 
						||
| 
								 | 
							
								    /* calculate active current value rate constant, base hw current channel
							 | 
						||
| 
								 | 
							
								     * transfer rate.
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    float n_i_rms;
							 | 
						||
| 
								 | 
							
								    /* calculate temperature constant */
							 | 
						||
| 
								 | 
							
								    uint32_t tc;
							 | 
						||
| 
								 | 
							
								    /* calculate power value rate constant, base hfconst and ec value */
							 | 
						||
| 
								 | 
							
								    float k_power;
							 | 
						||
| 
								 | 
							
								} iot_em_ext_att_hw_nv_para_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _iot_em_ext_att_hw_info {
							 | 
						||
| 
								 | 
							
								    /* energy meter extern chip id */
							 | 
						||
| 
								 | 
							
								    uint32_t chip_id                : 4,
							 | 
						||
| 
								 | 
							
								        resv0                       : 28;
							 | 
						||
| 
								 | 
							
								    /* hw nv parameter */
							 | 
						||
| 
								 | 
							
								    iot_em_ext_att_hw_nv_para_t     nv_para;
							 | 
						||
| 
								 | 
							
								} iot_em_ext_att_hw_info_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* @brief               get energy extern raw int data of active/inactive power
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @param mtype         get measure type, see IOT_EM_EXT_MTYPE_XXX
							 | 
						||
| 
								 | 
							
								 * @param phase         get measure phase id, see IOT_EM_EXT_PHASE_XXX
							 | 
						||
| 
								 | 
							
								 * @return:             raw int data of active/inactive power
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								int32_t iot_em_ext_att_read_pq_raw2int(uint8_t mtype, uint8_t phase);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* @brief               get energy extern measure data from chip reg
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @param mtype         get measure type, see IOT_EM_EXT_MTYPE_XXX
							 | 
						||
| 
								 | 
							
								 * @param phase         get measure phase id, see IOT_EM_EXT_PHASE_XXX
							 | 
						||
| 
								 | 
							
								 * @return:             measure data
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								int32_t iot_em_ext_att_read_meas(uint8_t mtype, uint8_t is_rawdata,
							 | 
						||
| 
								 | 
							
								    uint8_t phase);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* @brief               get energy extern calibration data from chip reg
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @param ctype         get measure type, see IOT_EM_EXT_CTYPE_XXX
							 | 
						||
| 
								 | 
							
								 * @param phase         get measure phase id, see IOT_EM_EXT_PHASE_XXX
							 | 
						||
| 
								 | 
							
								 * @return:             calibration data
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint32_t iot_em_ext_att_read_cali(uint8_t ctype, uint8_t phase);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* @brief               set energy extern calibration data to chip reg
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @param ctype         set calibration type, see IOT_EM_EXT_CTYPE_XXX
							 | 
						||
| 
								 | 
							
								 * @param phase         set calibration phase id, see IOT_EM_EXT_PHASE_XXX
							 | 
						||
| 
								 | 
							
								 * @param wdata         set calibration data
							 | 
						||
| 
								 | 
							
								 * @return:             error code, see ERR_XXX
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint32_t iot_em_ext_att_write_cali(uint8_t ctype, uint8_t phase,
							 | 
						||
| 
								 | 
							
								    uint32_t wdata);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* @brief               calculate calibration value base on incoming data
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @param calc_type     calculate calibration data type.
							 | 
						||
| 
								 | 
							
								 * @param para          calculate calibration data parameters.
							 | 
						||
| 
								 | 
							
								 * @return:             calibration result
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint32_t iot_em_ext_att_calc_cali(uint8_t calc_type, void *para);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* @brief               energy special function handle
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @param func_id       function id, see IOT_EM_EXT_FUNC_XXX
							 | 
						||
| 
								 | 
							
								 * @param para          function parameter address
							 | 
						||
| 
								 | 
							
								 * @param para_len      function parameter byte length
							 | 
						||
| 
								 | 
							
								 * @return:             error code, see ERR_XXX
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint32_t iot_em_ext_att_func(uint8_t func_id, void *para, uint16_t para_len);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* @brief               open energy extern hw
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @param hw_cfg        hw config parameters
							 | 
						||
| 
								 | 
							
								 * @param cali          hw calibration parameters address
							 | 
						||
| 
								 | 
							
								 * @return:             error code, see ERR_XXX
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint32_t iot_em_ext_att_hw_open(iot_em_ext_hw_cfg_t *hw_cfg, void *cali);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* @brief               close energy extern hw
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @return:             none
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_em_ext_att_hw_close(void);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif //_IOT_EM_EXT_CHIP_ATT_H_
							 |