215 lines
		
	
	
		
			7.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			215 lines
		
	
	
		
			7.1 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 MAC_CFG_H
							 | 
						||
| 
								 | 
							
								#define MAC_CFG_H
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#include "os_types.h"
							 | 
						||
| 
								 | 
							
								#include "plc_protocol.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								extern "C" {
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* MAC writable PIB configation special mark to identify if the configuration
							 | 
						||
| 
								 | 
							
								 * is valid. 09-26 15:48
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define MAC_CFG_RW_MARK             0x15480926
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifndef MAC_CFG_STORE_PARA_TODO
							 | 
						||
| 
								 | 
							
								#define MAC_CFG_STORE_PARA_TODO     0
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * mac config default value
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								/* default peer count */
							 | 
						||
| 
								 | 
							
								#define MAC_CFG_DEF_PEER_CNT                PLC_MAC_PEER_POOL_SIZE
							 | 
						||
| 
								 | 
							
								/* default KPI for Performance */
							 | 
						||
| 
								 | 
							
								#define MAC_CFG_DEF_PERFORMANCE_MBPS        PCO_PERFORMANCE_MBPS
							 | 
						||
| 
								 | 
							
								/* default tx buffer ratio n/16 */
							 | 
						||
| 
								 | 
							
								#define MAC_CFG_DEF_TX_BUF_RATIO            8
							 | 
						||
| 
								 | 
							
								/* default rx buffer ratio n/16 */
							 | 
						||
| 
								 | 
							
								#define MAC_CFG_DEF_RX_BUF_RATIO            8
							 | 
						||
| 
								 | 
							
								/* default long buffer count ratio n/16 */
							 | 
						||
| 
								 | 
							
								#define MAC_CFG_DEF_LONG_BUF_CNT_RATIO      1
							 | 
						||
| 
								 | 
							
								/* default large buffer count ratio n/16 */
							 | 
						||
| 
								 | 
							
								#define MAC_CFG_DEF_LARGE_BUF_CNT_RATIO     1
							 | 
						||
| 
								 | 
							
								/* default small buffer count ratio n/16 */
							 | 
						||
| 
								 | 
							
								#define MAC_CFG_DEF_SMALL_BUF_CNT_RATIO     6
							 | 
						||
| 
								 | 
							
								/* default short buffer count ratio n/16 */
							 | 
						||
| 
								 | 
							
								#define MAC_CFG_DEF_SHORT_BUF_CNT_RATIO     8
							 | 
						||
| 
								 | 
							
								/* default PA count */
							 | 
						||
| 
								 | 
							
								#define MAC_CFG_DEF_CCO_PA_CNT              3
							 | 
						||
| 
								 | 
							
								#define MAC_CFG_DEF_STA_PA_CNT              1
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* oem vendor asscii code */
							 | 
						||
| 
								 | 
							
								#define MAC_CFG_VENDOR_CODE_WQRD            0x5751  /* 'W''Q' */
							 | 
						||
| 
								 | 
							
								#define MAC_CFG_VENDOR_CODE_HTZD            0x4854  /* 'H''T' */
							 | 
						||
| 
								 | 
							
								#define MAC_CFG_VENDOR_CODE_JSMT            0x4D54  /* 'M''T' */
							 | 
						||
| 
								 | 
							
								#define MAC_CFG_VENDOR_CODE_GLDQ            0x474c  /* 'G''L' */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* pack for the structures in the whole file */
							 | 
						||
| 
								 | 
							
								#pragma pack(push)  /* save the pack status */
							 | 
						||
| 
								 | 
							
								#pragma pack(1)     /* 1 byte align */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _mac_cfg_buf_info {
							 | 
						||
| 
								 | 
							
								    uint16_t peer_cnt;
							 | 
						||
| 
								 | 
							
								    uint16_t plc_long_buf_cnt;
							 | 
						||
| 
								 | 
							
								    uint16_t plc_large_buf_cnt;
							 | 
						||
| 
								 | 
							
								    uint16_t plc_small_buf_cnt;
							 | 
						||
| 
								 | 
							
								    uint16_t plc_short_buf_cnt;
							 | 
						||
| 
								 | 
							
								    uint16_t tx_buf_ratio   : 5,
							 | 
						||
| 
								 | 
							
								             rx_buf_ratio   : 5,
							 | 
						||
| 
								 | 
							
								             pa_cnt         : 2,
							 | 
						||
| 
								 | 
							
								             tput_mbps_size : 4;
							 | 
						||
| 
								 | 
							
								    uint16_t vendor_id;
							 | 
						||
| 
								 | 
							
								    /* The default retry count for standard beacons */
							 | 
						||
| 
								 | 
							
								    uint8_t  bcn_def_retry_cnt;
							 | 
						||
| 
								 | 
							
								    /* mac zc compens for PLC_PHASE_A/PLC_PHASE_B/PLC_PHASE_C(unit: ntb).
							 | 
						||
| 
								 | 
							
								     * zc_ntb(final value) = dev_collect_zc_ntb + mac_zc_compens
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    int32_t  mac_zc_compens[PLC_PHASE_CNT];
							 | 
						||
| 
								 | 
							
								} mac_cfg_buf_info_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _mac_cfg_rw_cco_sta_ {
							 | 
						||
| 
								 | 
							
								    /* peer cnt */
							 | 
						||
| 
								 | 
							
								    uint16_t  peer_cnt;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								              /* KPI for Performance */
							 | 
						||
| 
								 | 
							
								    uint16_t  tput_mbps    : 4,
							 | 
						||
| 
								 | 
							
								              /* ratio of tx buf cnt to every below size buf cnt */
							 | 
						||
| 
								 | 
							
								              tx_buf_ratio : 5,
							 | 
						||
| 
								 | 
							
								              /* ratio of rx buf cnt to every below size buf cnt */
							 | 
						||
| 
								 | 
							
								              rx_buf_ratio : 5,
							 | 
						||
| 
								 | 
							
								              rsv0         : 2;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								              /* ratio of long  buf cnt to all buf cnt */
							 | 
						||
| 
								 | 
							
								    uint32_t  long_buf_cnt_ratio  : 5,
							 | 
						||
| 
								 | 
							
								              /* ratio of large buf cnt to all buf cnt */
							 | 
						||
| 
								 | 
							
								              large_buf_cnt_ratio : 5,
							 | 
						||
| 
								 | 
							
								              /* ratio of small buf cnt to all buf cnt */
							 | 
						||
| 
								 | 
							
								              small_buf_cnt_ratio : 5,
							 | 
						||
| 
								 | 
							
								              /* ratio of short buf cnt to all buf cnt */
							 | 
						||
| 
								 | 
							
								              short_buf_cnt_ratio : 5,
							 | 
						||
| 
								 | 
							
								              /* PA cnt, 0-3 */
							 | 
						||
| 
								 | 
							
								              pa_cnt              : 2,
							 | 
						||
| 
								 | 
							
								              rscv1               : 10;
							 | 
						||
| 
								 | 
							
								  /* mac zc compens for PLC_PHASE_A/PLC_PHASE_B/PLC_PHASE_C(unit: ntb).
							 | 
						||
| 
								 | 
							
								   * mp mode: mac_zc_compens = golden_zc_ntb - dev_collect_zc_ntb
							 | 
						||
| 
								 | 
							
								   * mm mode: zc_ntb(final value) = dev_collect_zc_ntb + mac_zc_compens
							 | 
						||
| 
								 | 
							
								   */
							 | 
						||
| 
								 | 
							
								    int32_t  mac_zc_compens[PLC_PHASE_CNT];
							 | 
						||
| 
								 | 
							
								} mac_cfg_rw_cco_sta_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _mac_cfg_ro_pib {
							 | 
						||
| 
								 | 
							
								    /* power dBuV, see PHY_FULL_PWR_DBUV */
							 | 
						||
| 
								 | 
							
								    uint32_t pwr_dbuv                  : 8,
							 | 
						||
| 
								 | 
							
								    /* 0 - enable auto high power, 1 - disable auto high power */
							 | 
						||
| 
								 | 
							
								             dis_high_power_req_ena    : 1,
							 | 
						||
| 
								 | 
							
								    /* flag to mark if the "rf_pwr_dbm" field is valid */
							 | 
						||
| 
								 | 
							
								             rf_pwr_valid              : 1,
							 | 
						||
| 
								 | 
							
								    /* reserved for further use */
							 | 
						||
| 
								 | 
							
								             rsvd                      : 14,
							 | 
						||
| 
								 | 
							
								    /* rf power dbm, see RF_TX_FULL_PWR_DBM */
							 | 
						||
| 
								 | 
							
								             rf_pwr_dbm                : 8;
							 | 
						||
| 
								 | 
							
								} mac_cfg_ro_pib_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _mac_cfg_rw_pib {
							 | 
						||
| 
								 | 
							
								    /* special mark to make sure config is valid, see MAC_CFG_RW_MARK */
							 | 
						||
| 
								 | 
							
								    uint32_t mark;
							 | 
						||
| 
								 | 
							
								    /* cco and sta role configuration */
							 | 
						||
| 
								 | 
							
								    mac_cfg_rw_cco_sta_t role;
							 | 
						||
| 
								 | 
							
								} mac_cfg_rw_pib_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _mac_cfg_info {
							 | 
						||
| 
								 | 
							
								    /* read only config point */
							 | 
						||
| 
								 | 
							
								    mac_cfg_ro_pib_t    *ro_cfg; //TODO:
							 | 
						||
| 
								 | 
							
								    /* read/write config point */
							 | 
						||
| 
								 | 
							
								    mac_cfg_rw_pib_t    *rw_cfg;
							 | 
						||
| 
								 | 
							
								} mac_cfg_info_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#pragma pack(pop)   /* restore the pack status */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * @brief               save mac config data to pib
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @return:             error code, see iot_errno_api.h file
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint32_t mac_cfg_save_pib(void);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * @brief               init mac config. get config data from pib, if access
							 | 
						||
| 
								 | 
							
								 *                      to fail, set mac config data for the default value.
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @return:             error code, see iot_errno_api.h file
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint32_t mac_cfg_init(void);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * @brief               get mac special config info
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @return:             0: normal config, 1: special config
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint8_t mac_cfg_get_special_info(void);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * @brief mac_cfg_get_bcn_def_retry_cnt() - get mac beacon tx default retry
							 | 
						||
| 
								 | 
							
								 *        counter.
							 | 
						||
| 
								 | 
							
								 * @return: - retry counetr.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint8_t mac_cfg_get_bcn_def_retry_cnt(void);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * @brief               get mac cfg zc compens for phase num
							 | 
						||
| 
								 | 
							
								 * @param phase_num:    mpdu data protocol, eg.
							 | 
						||
| 
								 | 
							
								 *                      PLC_PHASE_A/PLC_PHASE_B/PLC_PHASE_C. see plc_protocol.h
							 | 
						||
| 
								 | 
							
								 * @return:             zc compens value for phase num. unit: ntb
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								int32_t mac_cfg_get_zc_compens(uint8_t phase_num);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * @brief               set mac cfg zc compens for phase num
							 | 
						||
| 
								 | 
							
								 * @param phase_num:    mpdu data protocol, eg.
							 | 
						||
| 
								 | 
							
								 *                      PLC_PHASE_A/PLC_PHASE_B/PLC_PHASE_C. see plc_protocol.h
							 | 
						||
| 
								 | 
							
								 * @param zc_compens    zc compens value for phase num. unit: ntb
							 | 
						||
| 
								 | 
							
								 * @return:             error code, see iot_errno_api.h file
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint8_t mac_cfg_set_zc_compens(uint8_t phase_num, int32_t zc_compens);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * @brief               get auto high power req enable flag
							 | 
						||
| 
								 | 
							
								 * @return:             0 - enable auto high power, 1 - disable auto high power.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint8_t mac_cfg_get_auto_high_power_req_ena();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * @brief               get auto high power dBuV
							 | 
						||
| 
								 | 
							
								 * @return:             see PHY_FULL_PWR_DBUV
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint8_t mac_cfg_get_auto_high_power_dbuv();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * @brief               get auto rf high power dbm
							 | 
						||
| 
								 | 
							
								 * @return:             see RF_TX_FULL_PWR_DBM
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								int8_t mac_cfg_get_rf_auto_high_power_dbm();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif /* MAC_PIB_H */
							 | 
						||
| 
								 | 
							
								
							 |