159 lines
		
	
	
		
			5.4 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			159 lines
		
	
	
		
			5.4 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_H_
 | |
| #define _IOT_EM_EXT_H_
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| extern "C" {
 | |
| #endif
 | |
| 
 | |
| #include "os_lock_api.h"
 | |
| #include "os_timer_api.h"
 | |
| 
 | |
| #include "iot_cal_data.h"
 | |
| #include "iot_em_ext_api.h"
 | |
| #include "iot_em_ext_calibration.h"
 | |
| 
 | |
| #define IOT_EM_EXT_MODULE_ID                IOT_EM_EXT_MODULE_ATT7022
 | |
| 
 | |
| #define IOT_EM_EXT_TIMER_PERIOD_MS          1000
 | |
| 
 | |
| #if (IOT_EM_EXT_MODULE_ID == IOT_EM_EXT_MODULE_ATT7022)
 | |
| #define IOT_EM_EXT_CALI_PARA_LEN            IOT_EM_EXT_ATT_CALI_PARA_LEN
 | |
| #else
 | |
| #define IOT_EM_EXT_CALI_PARA_LEN            0
 | |
| #endif
 | |
| 
 | |
| /* msg_type has assigned in register function,
 | |
|  * msg_id can be made of module part and func part.
 | |
|  * we make module part in msg_id's high 8 bit, max module(255),
 | |
|  * func part in msg_id low 8 bit, max func id(255)
 | |
|  */
 | |
| /* em ext message id's module part */
 | |
| /* module part of calibration */
 | |
| #define IOT_EM_EXT_MSG_ID_MODULE_CALI           1
 | |
| 
 | |
| /* em ext message id's function part */
 | |
| /* function part of calibration start */
 | |
| #define IOT_EM_EXT_MSG_ID_FUNC_CALI_START       1
 | |
| /* function part of calibration timer out */
 | |
| #define IOT_EM_EXT_MSG_ID_FUNC_CALI_TIMEOUT     2
 | |
| /* function part of calibration stop */
 | |
| #define IOT_EM_EXT_MSG_ID_FUNC_CALI_STOP        3
 | |
| 
 | |
| /* em ext module's mode of reset state */
 | |
| #define IOT_EM_EXT_MODE_MISSION                 0
 | |
| /* em ext module's mode of set state */
 | |
| #define IOT_EM_EXT_MODE_ONESHOT                 1
 | |
| /* em ext module's mode of invalid */
 | |
| #define IOT_EM_EXT_MODE_INVALID                 0xFF
 | |
| 
 | |
| /* customer profile info */
 | |
| typedef struct _iot_em_ext_profile_info {
 | |
|     iot_em_ext_meas_std_rpt_func_t  std_rpt;
 | |
| } iot_em_ext_profile_info_t;
 | |
| 
 | |
| /* energy meter extern module information context */
 | |
| typedef struct _iot_em_ext_ctxt {
 | |
|     /* indicate external module, see EX_EXT_MODULE_XXX */
 | |
|     uint32_t module_id          : 2,
 | |
|     /* indicate module is inited */
 | |
|         is_inited               : 1,
 | |
|     /* indicate em calibration mode */
 | |
|         mode                    : 8,
 | |
|         resv                    : 21;
 | |
|     timer_id_t                  em_timer;
 | |
|     /* calibration parameter oem entry */
 | |
|     iot_cal_data_em_ext_t      *oem_cali;
 | |
|     /* measure data buffer */
 | |
|     iot_em_ext_meas_data_t      meas;
 | |
|     /* customer info */
 | |
|     iot_em_ext_profile_info_t   profile;
 | |
| } iot_em_ext_ctxt_t;
 | |
| 
 | |
| /* @brief               read calibration data from extern chip
 | |
|  *
 | |
|  * @param cali_type     em ext data type, see IOT_EM_EXT_CTYPE_XXX
 | |
|  * @param em_ext_phase  em ext phase id, see IOT_EM_EXT_PLC_PHASE_XXX
 | |
|  * @return:             error code, see ERR_XXX
 | |
|  */
 | |
| uint32_t iot_em_ext_read_cali(uint8_t cali_type, uint8_t em_ext_phase);
 | |
| 
 | |
| /* @brief               write calibration data to extern chip reg.
 | |
|  *
 | |
|  * @param cali_type     em ext data type, see IOT_EM_EXT_CTYPE_XXX
 | |
|  * @param em_ext_phase  em ext phase id, see IOT_EM_EXT_PHASE_XXX
 | |
|  * @param value         write data
 | |
|  * @return:             error code, see ERR_XXX
 | |
|  */
 | |
| uint32_t iot_em_ext_write_cali(uint8_t cali_type, uint8_t em_ext_phase,
 | |
|     uint32_t value);
 | |
| 
 | |
| /* @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_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_func(uint8_t func_id, void *para, uint16_t para_len);
 | |
| 
 | |
| /* @brief               get current energy meter module id
 | |
|  *
 | |
|  * @return:             module id num, see IOT_EM_EXT_MODULE_XXX
 | |
|  */
 | |
| uint8_t iot_em_ext_get_module_id(void);
 | |
| 
 | |
| /* @brief               enqueue message of em ext module
 | |
|  * @param msg_id        message id
 | |
|  * @param data1         message first data
 | |
|  * @param data2         message second data
 | |
|  * @return              none
 | |
|  */
 | |
| void iot_em_ext_queue_msg(uint16_t msg_id, uint32_t data1, void *data2);
 | |
| 
 | |
| /* @brief               clean message of em ext module
 | |
|  * @param msg_id        which message to be cleaned
 | |
|  * @return              none
 | |
|  */
 | |
| void iot_em_ext_clean_msg(uint16_t msg_id);
 | |
| 
 | |
| /* @brief               set em ext module mode
 | |
|  * @param mode          em module's mode to set, refer IOT_EM_EXT_MODE_XXX
 | |
|  * @return              none
 | |
|  */
 | |
| void iot_em_ext_set_mode(uint8_t mode);
 | |
| 
 | |
| /* @breif               get em ext module mode
 | |
|  * @param               none
 | |
|  * @return              em module's mode, refer to IOT_EM_EXT_MODE_XXX
 | |
|  */
 | |
| uint8_t iot_em_ext_get_mode(void);
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| }
 | |
| #endif
 | |
| 
 | |
| #endif //_IOT_EM_EXT_H_
 |