279 lines
		
	
	
		
			9.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			279 lines
		
	
	
		
			9.6 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 PLC_PROTOCOL_H
 | ||
|  | #define PLC_PROTOCOL_H
 | ||
|  | 
 | ||
|  | #include "plc_fr.h"
 | ||
|  | 
 | ||
|  | #ifdef __cplusplus
 | ||
|  | extern "C" { | ||
|  | #endif
 | ||
|  | 
 | ||
|  | /* TEI definitions */ | ||
|  | #define PLC_TEI_INVAL                   (0)
 | ||
|  | #define PLC_TEI_CCO                     (1)
 | ||
|  | #define PLC_TEI_FIRST                   (1)
 | ||
|  | 
 | ||
|  | #define PLC_TEI_LAST                    (PLC_NETWORK_SCALE)
 | ||
|  | 
 | ||
|  | #define PLC_FC_LEN                      16   // FC header len
 | ||
|  | /* rf phy header len */ | ||
|  | #define RF_PHR_LEN                      16
 | ||
|  | 
 | ||
|  | #define PLC_TEI_MAX_NUM                 (PLC_TEI_LAST - PLC_TEI_FIRST + 1)
 | ||
|  | #define PLC_TEI_BCAST                   (0xFFF)
 | ||
|  | #define PLC_TEI_IS_VALID(__tei) \
 | ||
|  |     ((__tei) >= PLC_TEI_FIRST && (__tei) <= PLC_TEI_LAST) | ||
|  | #define PLC_TEI_CTRL                    (0xFFD)
 | ||
|  | #define PLC_TEI_CTRL_GW                 (0xFFE)
 | ||
|  | 
 | ||
|  | #define PLC_NID_INVALID                 (0)
 | ||
|  | #define PLC_NID_MIN                     (1)
 | ||
|  | #define PLC_NID_MAX_SG                  (0xFFFFFF)
 | ||
|  | #define PLC_NID_MAX_SPG                 (0x0F)
 | ||
|  | 
 | ||
|  | /* define rf options */ | ||
|  | #define RF_OPTION_INVALID               0
 | ||
|  | #define RF_OPTION_1                     1
 | ||
|  | #define RF_OPTION_2                     2
 | ||
|  | #define RF_OPTION_3                     3
 | ||
|  | #define RF_OPTION_MAX                   RF_OPTION_3
 | ||
|  | 
 | ||
|  | #define PLC_RF_OPTION_IS_VALID(option) \
 | ||
|  |     (HPLC_RF_SUPPORT && \ | ||
|  |     (option) >= RF_OPTION_1 && (option) <= RF_OPTION_MAX) | ||
|  | 
 | ||
|  | #define PLC_NTB_MAX                     (0xFFFFFFFF) /* maximum NTB value */
 | ||
|  | 
 | ||
|  | #define PLC_INVALID_DATA                (0) /* mark invalid data */
 | ||
|  | 
 | ||
|  | /* the zero cross period when power frequency is 50 HZ, unit: ntb */ | ||
|  | #define PLC_ZC_50HZ_PERIOD_NTB           500000
 | ||
|  | /* the zero cross period when power frequency is 60 HZ, unit: ntb */ | ||
|  | #define PLC_ZC_60HZ_PERIOD_NTB           416667
 | ||
|  | 
 | ||
|  | /* routing type definitions */ | ||
|  | #define PLC_RT_TYPE_ERR                 (0) /* error */
 | ||
|  | #define PLC_RT_TYPE_SL                  (1) /* same level */
 | ||
|  | #define PLC_RT_TYPE_UL                  (2) /* upper level */
 | ||
|  | #define PLC_RT_TYPE_MP                  (3) /* main proxy */
 | ||
|  | #define PLC_RT_TYPE_UUL                 (4) /* upper upper level */
 | ||
|  | 
 | ||
|  | /* beacon type definitions */ | ||
|  | #define PLC_BC_TYPE_D                   (0) /* discover beacon */
 | ||
|  | #define PLC_BC_TYPE_P                   (1) /* proxy beacon */
 | ||
|  | #define PLC_BC_TYPE_C                   (2) /* central beacon */
 | ||
|  | 
 | ||
|  | /* beacon period, unit is 1ms */ | ||
|  | #define PLC_BC_PERIOD_MIN               (2 * 1000)
 | ||
|  | #define PLC_BC_PERIOD_MAX               (10 * 1000)
 | ||
|  | #define PLC_RF_BC_PERIOD_MAX            (15 * 1000)
 | ||
|  | 
 | ||
|  | /* define beacon period alert check duration, unit is 1s */ | ||
|  | #define PLC_BP_CNT_CHECK_DUR            (600)
 | ||
|  | 
 | ||
|  | /* route period, unit is 1s */ | ||
|  | #define PLC_RT_PEROID_MIN               (20)
 | ||
|  | #define PLC_RT_PEROID_MAX               (420)
 | ||
|  | 
 | ||
|  | /* minimum number of discovery node list mme need to be sent out for each route
 | ||
|  |  * period. | ||
|  |  */ | ||
|  | #define PLC_RT_DIS_MME_MIN_PER_PERIOD   (10)
 | ||
|  | 
 | ||
|  | /* rf discovery node list mme sending period, unit is 1s */ | ||
|  | #define PLC_RT_RF_DIS_MME_MIN_PERIOD    (2)
 | ||
|  | #define PLC_RT_RF_DIS_MME_MAX_PERIOD    (200)
 | ||
|  | 
 | ||
|  | /* rf tx success ratio expired period, the State Grid agreement stipulates 4-16,
 | ||
|  |  * but the Beijing cert test bed set it to 2, so we set the range to 2-16 to | ||
|  |  * meet the Beijing cert test, unit is 1 rf_dis_period | ||
|  |  */ | ||
|  | #define PLC_RT_RF_TX_SR_AGE_PERIOD_MIN_CNT (2)
 | ||
|  | #define PLC_RT_RF_TX_SR_AGE_PERIOD_MAX_CNT (16)
 | ||
|  | 
 | ||
|  | /* define discovery node list default period when running in cert mode */ | ||
|  | #define PLC_RT_RF_DIS_MME_PERIOD_CERT      PLC_RT_RF_DIS_MME_MIN_PERIOD
 | ||
|  | #define PLC_RT_RF_TX_SR_AGE_PERIOD_CERT    (4)
 | ||
|  | 
 | ||
|  | /* define the small scale count of direct sub sta for one PCO */ | ||
|  | #define PLC_PCO_D_SUB_STA_CNT_SMALL     (128)
 | ||
|  | /* define the large scale count of direct sub sta for one PCO */ | ||
|  | #define PLC_PCO_D_SUB_STA_CNT_LARGE     (256)
 | ||
|  | 
 | ||
|  | /* define the max allowed direct sub sta for one PCO */ | ||
|  | #if RUN_IN_PSRAM
 | ||
|  | #define PLC_PCO_MAX_D_SUB_STA           PLC_PCO_D_SUB_STA_CNT_LARGE
 | ||
|  | #else
 | ||
|  | #define PLC_PCO_MAX_D_SUB_STA           PLC_PCO_D_SUB_STA_CNT_SMALL
 | ||
|  | #endif
 | ||
|  | 
 | ||
|  | #if RUN_IN_PSRAM
 | ||
|  | /* define the max number of neighbor networks that can be monitored */ | ||
|  | #define PLC_MAX_NEIGHBOR_NETWORK        (32)
 | ||
|  | #else /* RUN_IN_PSRAM */
 | ||
|  | /* define the max number of neighbor networks that can be monitored */ | ||
|  | #define PLC_MAX_NEIGHBOR_NETWORK        (16)
 | ||
|  | #endif /* RUN_IN_PSRAM */
 | ||
|  | 
 | ||
|  | /* traffic success ratio period is 4 router period */ | ||
|  | #define PLC_TF_SR_PERIOD_LIMIT          (4)
 | ||
|  | 
 | ||
|  | /* power line phase */ | ||
|  | #define PLC_PHASE_ALL                   (0)
 | ||
|  | #define PLC_PHASE_A                     (1)
 | ||
|  | #define PLC_PHASE_B                     (2)
 | ||
|  | #define PLC_PHASE_C                     (3)
 | ||
|  | #define PLC_PHASE_CNT                   (3)
 | ||
|  | 
 | ||
|  | /* the meter addr is used as the MAC addr to join network */ | ||
|  | #define PLC_MAC_ADDR_TYPE_METER         (0)
 | ||
|  | /* the module addr is used as the MAC addr to join network */ | ||
|  | #define PLC_MAC_ADDR_TYPE_MODULE        (1)
 | ||
|  | /* the collector addr is used as the MAC addr to join network */ | ||
|  | #define PLC_MAC_ADDR_TYPE_COLLECTOR     (2)
 | ||
|  | 
 | ||
|  | /* device role */ | ||
|  | #define PLC_DEV_ROLE_INVALID            (0x0)
 | ||
|  | #define PLC_DEV_ROLE_STA                (0x1)
 | ||
|  | #define PLC_DEV_ROLE_PCO                (0x2)
 | ||
|  | #define PLC_DEV_ROLE_CCO                (0x4)
 | ||
|  | 
 | ||
|  | /* IEEE1901 device role */ | ||
|  | #define I1901_PLC_DEV_ROLE_INVALID      (0x0)
 | ||
|  | #define I1901_PLC_DEV_ROLE_STA          (0x1)
 | ||
|  | #define I1901_PLC_DEV_ROLE_PCO          (0x2)
 | ||
|  | #define I1901_PLC_DEV_ROLE_CCO          (0x3)
 | ||
|  | 
 | ||
|  | /* device type */ | ||
|  | #define PLC_DEV_TYPE_METER_CONTROLLER   1
 | ||
|  | #define PLC_DEV_TYPE_CONCENTRATOR       2
 | ||
|  | #define PLC_DEV_TYPE_POWER_METER        3
 | ||
|  | #define PLC_DEV_TYPE_REPEATER           4
 | ||
|  | #define PLC_DEV_TYPE_COLLECTOR_2        5
 | ||
|  | #define PLC_DEV_TYPE_COLLECTOR_1        6
 | ||
|  | #define PLC_DEV_TYPE_POWER_METER_3P     7
 | ||
|  | #define PLC_DEV_TYPE_BSRM_MONITOR       0x7C
 | ||
|  | #define PLC_DEV_TYPE_BRK_MONITOR        0x7D
 | ||
|  | #define PLC_DEV_TYPE_TSFM_MONITOR       0x7E
 | ||
|  | #define PLC_DEV_TYPE_SWITCH_MONITOR     0x7F
 | ||
|  | 
 | ||
|  | /* iot customer device type start at 0x80 */ | ||
|  | #define PLC_DEV_TYPE_GL_STA             0x80
 | ||
|  | #define PLC_DEV_TYPE_GL_OUTDOOR         0x81
 | ||
|  | #define PLC_DEV_TYPE_GL_INDOOR          0x82
 | ||
|  | #define PLC_DEV_TYPE_GL_LINECTRL        0x83
 | ||
|  | #define PLC_DEV_TYPE_GL_CONCETRATOR     0x84
 | ||
|  | #define PLC_DEV_TYPE_GL_MONITOR         0x85
 | ||
|  | 
 | ||
|  | #define PLC_DEV_TYPE_INVAL              0xFF
 | ||
|  | 
 | ||
|  | /* define ieee1901 device type */ | ||
|  | #define PLC_DEV_TYPE_I1901_STA          0x01
 | ||
|  | #define PLC_DEV_TYPE_I1901_REPEATER     0x02
 | ||
|  | 
 | ||
|  | /* PLC chip vendor specific info length, unit is 1 byte */ | ||
|  | #define PLC_VENDOR_INFO_LEN             18
 | ||
|  | /* PLC chip management id length, unit is 1 byte */ | ||
|  | #define PLC_MANAGE_ID_LEN               24
 | ||
|  | 
 | ||
|  | /* max route level */ | ||
|  | #define PLC_MAX_RT_LEVEL                (15)
 | ||
|  | 
 | ||
|  | /* max send count */ | ||
|  | #define PLC_MAX_SEND_CNT                (31)
 | ||
|  | 
 | ||
|  | /* plc link id */ | ||
|  | #define PLC_MAX_CONN_LESS_LID           (3)
 | ||
|  | #define PLC_MAX_CTRL_PROTO_LID          (3)
 | ||
|  | #define PLC_INVALID_LID                 (255)
 | ||
|  | 
 | ||
|  | /* define plc link type */ | ||
|  | #define PLC_LINK_TYPE_HPLC              (0)
 | ||
|  | #define PLC_LINK_TYPE_RF                (1)
 | ||
|  | #define PLC_LINK_TYPE_UNKNOWN           (2)
 | ||
|  | 
 | ||
|  | /* define plc device communication type */ | ||
|  | #define PLC_DEV_COMM_TYPE_HPLC          (0)
 | ||
|  | #define PLC_DEV_COMM_TYPE_DUAL_MODE     (1)
 | ||
|  | #define PLC_DEV_COMM_TYPE_RF            (2)
 | ||
|  | 
 | ||
|  | /* define plc device bandwidth type */ | ||
|  | #define PLC_DEV_BAND_TYPE_NARROW        (1)
 | ||
|  | #define PLC_DEV_BAND_TYPE_BROAD         (2)
 | ||
|  | #define PLC_DEV_BAND_TYPE_DUAL_MODE     (3)
 | ||
|  | 
 | ||
|  | /* LID type range define */ | ||
|  | typedef enum _lid_type_range_t { | ||
|  |     LID_CSMA_CAP0 = 0, | ||
|  |     LID_CSMA_CAP1, | ||
|  |     LID_CSMA_CAP2, | ||
|  |     LID_CSMA_CAP3, | ||
|  |     LID_BCSMA_START = 4, | ||
|  |     LID_BCSMA_FB_DETECT = 77, | ||
|  |     LID_BCSMA_END = 127, | ||
|  |     LID_TDMA_START = LID_BCSMA_END + 1, | ||
|  |     LID_TDMA_END = 255 | ||
|  | }lid_type_range_t; | ||
|  | 
 | ||
|  | /* plc beacon duplicated check guard. if the new beacon sequence number
 | ||
|  |  * is much bigger than current beacon sequence number, we assume the beacon | ||
|  |  * is duplicated. cert test case 3.2.2.2 beacon sequence number will be started | ||
|  |  * from 1 again after reach 0x10. so set this value carefully. | ||
|  |  */ | ||
|  | #define PLC_BCN_DUPLICATE_GUARD         ((uint32_t)0xFFFFFFF8)
 | ||
|  | 
 | ||
|  | /* plc beacon region type */ | ||
|  | #define PLC_BCN_REGION_BCN              (0)
 | ||
|  | #define PLC_BCN_REGION_CSMA             (1)
 | ||
|  | #define PLC_BCN_REGION_TDMA             (2)
 | ||
|  | /* SG only */ | ||
|  | #define PLC_BCN_REGION_BCSMA            (3)
 | ||
|  | /* private defined */ | ||
|  | #define PLC_BCN_REGION_NBBCN            (4)
 | ||
|  | 
 | ||
|  | 
 | ||
|  | /* Smart Grid protocol */ | ||
|  | #define PLC_PROTO_TYPE_SG       0
 | ||
|  | /* Green Phy  protocol */ | ||
|  | #define PLC_PROTO_TYPE_GP       1
 | ||
|  | /* AV protocol */ | ||
|  | #define PLC_PROTO_TYPE_AV       2
 | ||
|  | /* Southern Power Grid protocol */ | ||
|  | #define PLC_PROTO_TYPE_SPG      3
 | ||
|  | /* Rawdata protocol */ | ||
|  | #define PLC_PROTO_TYPE_RAWDATA  4
 | ||
|  | 
 | ||
|  | /* max band id for SG */ | ||
|  | #define MAX_SG_BAND_ID                  (12)
 | ||
|  | 
 | ||
|  | #define PLC_SG_MAX_PB_NUM               (4)
 | ||
|  | 
 | ||
|  | #define PLC_SPG_MAX_PB_NUM              (4)
 | ||
|  | 
 | ||
|  | #define PLC_I1901_MAX_PB_NUM            (4)
 | ||
|  | 
 | ||
|  | #define PLC_BAND_BITMAP_SIZE            (16)
 | ||
|  | 
 | ||
|  | /* define max number of connected power meter */ | ||
|  | #define PLC_CONN_PM_MAX_CNT             (32)
 | ||
|  | 
 | ||
|  | #ifdef __cplusplus
 | ||
|  | } | ||
|  | #endif
 | ||
|  | 
 | ||
|  | #endif /* PLC_PROTOCOL_H */
 |