166 lines
		
	
	
		
			5.4 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			166 lines
		
	
	
		
			5.4 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_SG_H
							 | 
						||
| 
								 | 
							
								#define IOT_SG_H
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* os shim includes */
							 | 
						||
| 
								 | 
							
								#include "os_types_api.h"
							 | 
						||
| 
								 | 
							
								#include "os_event_api.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* common includes */
							 | 
						||
| 
								 | 
							
								#include "iot_plc_api.h"
							 | 
						||
| 
								 | 
							
								#include "iot_mem_pool_api.h"
							 | 
						||
| 
								 | 
							
								#include "iot_queue_api.h"
							 | 
						||
| 
								 | 
							
								#include "iot_utils_api.h"
							 | 
						||
| 
								 | 
							
								#include "iot_task_api.h"
							 | 
						||
| 
								 | 
							
								#include "iot_uart_api.h"
							 | 
						||
| 
								 | 
							
								#include "iot_plc_pm_api.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* smart grid internal includes */
							 | 
						||
| 
								 | 
							
								#include "iot_sg_fr.h"
							 | 
						||
| 
								 | 
							
								#include "iot_sg_msg.h"
							 | 
						||
| 
								 | 
							
								#include "iot_sg_sta.h"
							 | 
						||
| 
								 | 
							
								#include "iot_sg_cco.h"
							 | 
						||
| 
								 | 
							
								#include "iot_sg_cfg.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* Extend SG APP. */
							 | 
						||
| 
								 | 
							
								#include "iot_sg_ext.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								extern "C" {
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* define type of app proto, gw */
							 | 
						||
| 
								 | 
							
								#define IOT_SG_APP_PROTO_GW                 0
							 | 
						||
| 
								 | 
							
								/* define type of app proto, nw */
							 | 
						||
| 
								 | 
							
								#define IOT_SG_APP_PROTO_NW                 1
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* define update network ppm into oem request id */
							 | 
						||
| 
								 | 
							
								#define IOT_SG_UPDATE_PPM_INTO_OEM          1
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* plc link state info */
							 | 
						||
| 
								 | 
							
								typedef struct _iot_sg_plc_state {
							 | 
						||
| 
								 | 
							
								    /* plc app register status. 1 means registered */
							 | 
						||
| 
								 | 
							
								    uint8_t                 app_reg;
							 | 
						||
| 
								 | 
							
								    /* plc link status */
							 | 
						||
| 
								 | 
							
								    uint8_t                 link_ready      : 1,
							 | 
						||
| 
								 | 
							
								    /* non 0 means broadcast packet sent in 3phase simultaneously, 0 means
							 | 
						||
| 
								 | 
							
								     * broadcast packet sent in 3phase in turn.
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								                            tx_3phase_flag  : 1,
							 | 
						||
| 
								 | 
							
								    /*
							 | 
						||
| 
								 | 
							
								     * flag to mark if cert test command ever detected;
							 | 
						||
| 
								 | 
							
								     * 1 - in cert test mode, 0 - not in cert test mode.
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								                            cert_test_detected : 1,
							 | 
						||
| 
								 | 
							
								    /* reserve for future */
							 | 
						||
| 
								 | 
							
								                            rsvd            : 5;
							 | 
						||
| 
								 | 
							
								    /* smart grid device role. See IOT_PLC_DEV_ROLE_XXX */
							 | 
						||
| 
								 | 
							
								    uint8_t                 role;
							 | 
						||
| 
								 | 
							
								    /* device ID */
							 | 
						||
| 
								 | 
							
								    uint8_t                 dev_id[IOT_MAC_ADDR_LEN];
							 | 
						||
| 
								 | 
							
								    /* reset counter */
							 | 
						||
| 
								 | 
							
								    uint16_t                reset_cnt;
							 | 
						||
| 
								 | 
							
								    /* plc mac address */
							 | 
						||
| 
								 | 
							
								    uint8_t                 addr[IOT_MAC_ADDR_LEN];
							 | 
						||
| 
								 | 
							
								    /* cco mac address */
							 | 
						||
| 
								 | 
							
								    uint8_t                 cco_addr[IOT_MAC_ADDR_LEN];
							 | 
						||
| 
								 | 
							
								    /* tei of the device */
							 | 
						||
| 
								 | 
							
								    uint16_t                dev_tei;
							 | 
						||
| 
								 | 
							
								    /* pco of the device */
							 | 
						||
| 
								 | 
							
								    uint16_t                pco_tei;
							 | 
						||
| 
								 | 
							
								    /* pco of the device */
							 | 
						||
| 
								 | 
							
								    int16_t                 snr;
							 | 
						||
| 
								 | 
							
								    /* zero cross ntb collect type */
							 | 
						||
| 
								 | 
							
								    uint8_t                 collect_type;
							 | 
						||
| 
								 | 
							
								    /*
							 | 
						||
| 
								 | 
							
								     * reason for leaving the network last time. see IOT_PLC_LEAVE_REASON_XXX
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    uint8_t                 leave_net_reason;
							 | 
						||
| 
								 | 
							
								    /* network ppm, unit is 1ppm */
							 | 
						||
| 
								 | 
							
								    int8_t                  nw_ppm;
							 | 
						||
| 
								 | 
							
								    /* level of the device */
							 | 
						||
| 
								 | 
							
								    uint8_t                 level;
							 | 
						||
| 
								 | 
							
								} iot_sg_plc_state_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* smart grid global descriptor */
							 | 
						||
| 
								 | 
							
								typedef struct _iot_sg_global {
							 | 
						||
| 
								 | 
							
								    /* smart grid task configuration */
							 | 
						||
| 
								 | 
							
								    iot_task_config_t           task_cfg;
							 | 
						||
| 
								 | 
							
								    /* smart grid task handle */
							 | 
						||
| 
								 | 
							
								    iot_task_h                  task_h;
							 | 
						||
| 
								 | 
							
								    /* cfg role */
							 | 
						||
| 
								 | 
							
								    uint8_t                     role;
							 | 
						||
| 
								 | 
							
								    /* app protocol type, see IOT_SG_APP_PROTO_XXX */
							 | 
						||
| 
								 | 
							
								    uint8_t                     app_proto;
							 | 
						||
| 
								 | 
							
								    /* module type, see MODULE_TYPE_XXX */
							 | 
						||
| 
								 | 
							
								    uint8_t                     module_type;
							 | 
						||
| 
								 | 
							
								    /* 0 - not ready, 1 - ready */
							 | 
						||
| 
								 | 
							
								    uint8_t                     dev_is_ready        :7,
							 | 
						||
| 
								 | 
							
								    /* flag to mark if enable forward msdu to cuaspp */
							 | 
						||
| 
								 | 
							
								                                msdu_fwd_enable     :1;
							 | 
						||
| 
								 | 
							
								    /* user type */
							 | 
						||
| 
								 | 
							
								    uint8_t                     user_type;
							 | 
						||
| 
								 | 
							
								    /* fw start address. */
							 | 
						||
| 
								 | 
							
								    uint32_t                    fw_start_addr;
							 | 
						||
| 
								 | 
							
								    /* pib handle */
							 | 
						||
| 
								 | 
							
								    union {
							 | 
						||
| 
								 | 
							
								        /* sta role pib handle */
							 | 
						||
| 
								 | 
							
								        iot_sg_sta_app_pib_t    sta;
							 | 
						||
| 
								 | 
							
								        /* cco role pib handle */
							 | 
						||
| 
								 | 
							
								        iot_sg_cco_app_pib_t    cco;
							 | 
						||
| 
								 | 
							
								    } pib;
							 | 
						||
| 
								 | 
							
								    /* smart grid uart handle */
							 | 
						||
| 
								 | 
							
								    iot_uart_h                  uart_h;
							 | 
						||
| 
								 | 
							
								    /* plc app regsiter configuration */
							 | 
						||
| 
								 | 
							
								    iot_plc_app_t               plc_app_cfg;
							 | 
						||
| 
								 | 
							
								    /* handle of registered plc app */
							 | 
						||
| 
								 | 
							
								    iot_plc_app_h               plc_app_h;
							 | 
						||
| 
								 | 
							
								    /* handle of registered brm app */
							 | 
						||
| 
								 | 
							
								    iot_plc_app_h               brm_app_h;
							 | 
						||
| 
								 | 
							
								    /* plc link state info */
							 | 
						||
| 
								 | 
							
								    iot_sg_plc_state_t          plc_state;
							 | 
						||
| 
								 | 
							
								    /* smart grid message executing callback */
							 | 
						||
| 
								 | 
							
								    iot_sg_msg_execute_func_t   msg_exe_func;
							 | 
						||
| 
								 | 
							
								    /* smart grid message canceling callback */
							 | 
						||
| 
								 | 
							
								    iot_sg_msg_cancel_func_t    msg_cancel_func;
							 | 
						||
| 
								 | 
							
								    union {
							 | 
						||
| 
								 | 
							
								        /* sta role specific global data */
							 | 
						||
| 
								 | 
							
								        iot_sg_sta_global_t     *sta;
							 | 
						||
| 
								 | 
							
								        /* cco role specific global data */
							 | 
						||
| 
								 | 
							
								        iot_sg_cco_global_t     *cco;
							 | 
						||
| 
								 | 
							
								    } desc;
							 | 
						||
| 
								 | 
							
								} iot_sg_global_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* smart grid global internal structure */
							 | 
						||
| 
								 | 
							
								extern iot_sg_global_t *p_sg_glb;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief   iot_sg_get_plc_state_info() - get plc state info
							 | 
						||
| 
								 | 
							
								 * @return: pointer   - pointer to the plc state info.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								iot_sg_plc_state_t* iot_sg_get_plc_state_info(void);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_sg_update_nw_ppm_to_oem_req() - request update network ppm to oem
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_sg_update_nw_ppm_to_oem_req(void);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif  /* IOT_SG_H */
							 |