99 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			99 lines
		
	
	
		
			2.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 CVG_PRM_MATM_H
							 | 
						||
| 
								 | 
							
								#define CVG_PRM_MATM_H
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* os shim includes */
							 | 
						||
| 
								 | 
							
								#include "os_types.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* common includes */
							 | 
						||
| 
								 | 
							
								#include "iot_utils.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* public api includes */
							 | 
						||
| 
								 | 
							
								#include "plc_fr.h"
							 | 
						||
| 
								 | 
							
								#include "plc_utils.h"
							 | 
						||
| 
								 | 
							
								#include "plc_protocol.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								extern "C" {
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#if (PLC_SUPPORT_ADDR_TO_TEI_MAP)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* mac address and tei mapping entry */
							 | 
						||
| 
								 | 
							
								#pragma pack(push)
							 | 
						||
| 
								 | 
							
								#pragma pack(1)
							 | 
						||
| 
								 | 
							
								typedef struct _cvg_matm_ent {
							 | 
						||
| 
								 | 
							
								    /* next entry index */
							 | 
						||
| 
								 | 
							
								    uint16_t    next_idx    :15,
							 | 
						||
| 
								 | 
							
								    /* flag to mark if the entry is free */
							 | 
						||
| 
								 | 
							
								                free        :1;
							 | 
						||
| 
								 | 
							
								    /* mac address of current entry */
							 | 
						||
| 
								 | 
							
								    uint8_t     addr[IOT_MAC_ADDR_LEN];
							 | 
						||
| 
								 | 
							
								} cvg_matm_ent_t;
							 | 
						||
| 
								 | 
							
								#pragma pack(pop)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#if (PLC_SUPPORT_CCO_ROLE)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#if (RUN_IN_PSRAM)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* hash table size */
							 | 
						||
| 
								 | 
							
								#define CVG_MATM_TABLE_SIZE             (1024)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#else /* RUN_IN_PSRAM */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* hash table size */
							 | 
						||
| 
								 | 
							
								#define CVG_MATM_TABLE_SIZE             (64)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif /* RUN_IN_PSRAM */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#else /* PLC_SUPPORT_CCO_ROLE */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* hash table size */
							 | 
						||
| 
								 | 
							
								#define CVG_MATM_TABLE_SIZE             (64)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif /* PLC_SUPPORT_CCO_ROLE */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* mac address hash table */
							 | 
						||
| 
								 | 
							
								typedef struct _cvg_matm_table {
							 | 
						||
| 
								 | 
							
								    /* entry chain for each mac address hash index */
							 | 
						||
| 
								 | 
							
								    uint16_t            addr_entry[CVG_MATM_TABLE_SIZE];
							 | 
						||
| 
								 | 
							
								    /* tei mapping */
							 | 
						||
| 
								 | 
							
								    cvg_matm_ent_t      tei_entry[PLC_TEI_MAX_NUM];
							 | 
						||
| 
								 | 
							
								} cvg_matm_table_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void cvg_matm_init_table(cvg_matm_table_t *table);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void cvg_matm_add_ent(cvg_matm_table_t *table, uint8_t *addr, tei_t tei);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void cvg_matm_del_ent_addr(cvg_matm_table_t *table, uint8_t *addr);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void cvg_matm_del_ent_tei(cvg_matm_table_t *table, tei_t tei);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								uint32_t cvg_matm_get_tei(cvg_matm_table_t *table, uint8_t *addr, tei_t *tei);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								uint32_t cvg_matm_get_addr(cvg_matm_table_t *table, uint8_t *addr, tei_t tei);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif /* PLC_SUPPORT_ADDR_TO_TEI_MAP */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif /* CVG_PRM_MATM_H */
							 |