338 lines
		
	
	
		
			9.3 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			338 lines
		
	
	
		
			9.3 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 __PHY_PERF_H
 | 
						|
#define __PHY_PERF_H
 | 
						|
 | 
						|
#include "os_types.h"
 | 
						|
#include "iot_config.h"
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
extern "C" {
 | 
						|
#endif
 | 
						|
 | 
						|
/* define the csi buf length */
 | 
						|
#define IOT_PHY_CSI_BUF_LEN                 (2048)
 | 
						|
/* define the power buf length */
 | 
						|
#define IOT_PHY_PWR_BUF_LEN                 (512)
 | 
						|
/* define the detect buf length */
 | 
						|
#define IOT_PHY_DETECT_BUF_LEN              (1024)
 | 
						|
 | 
						|
#define IOT_SPUR_8M_CENTER_TONE             (327)
 | 
						|
#define IOT_SPUR_8M_CMP_THD                 (10)
 | 
						|
#define IOT_SPUR_3M_CENTER_TONE             (123)
 | 
						|
#define IOT_SPUR_3M_CMP_THD                 (10)
 | 
						|
#define IOT_SPUR_2M_CENTER_TONE             (82)
 | 
						|
#define IOT_SPUR_2M_CMP_THD                 (10)
 | 
						|
 | 
						|
#define PHY_CHN_EST_AI_CERT_RTY_CNT         (20)
 | 
						|
 | 
						|
/* Define the number of PLC channel pre estimation analysis, which occurs during
 | 
						|
 * phy initialization and reinitialization.
 | 
						|
 */
 | 
						|
#if (PHY_BBAI_ALGORITHM == PHY_BBAI_SLIDE_WINDOWS)
 | 
						|
 | 
						|
#define PHY_CHN_EST_AI_RTY_CNT              (30)
 | 
						|
 | 
						|
#else
 | 
						|
 | 
						|
#define PHY_CHN_EST_AI_RTY_CNT              (50)
 | 
						|
 | 
						|
#endif
 | 
						|
 | 
						|
#define PHY_CHN_EST_AI_TIMEOUT              (2000)
 | 
						|
#if PHY_HW_SPIKE_OPTIMIZATION
 | 
						|
/* the phy_chn_nf_update function takes 118ms to execute twice. */
 | 
						|
#define PHY_CHN_EST_NF_UPDATE_PERIOD_MS     (118)
 | 
						|
#else
 | 
						|
/* near 22ms(if use 192 point nf) for each cycle, and 25ms with enough margin */
 | 
						|
#define PHY_CHN_EST_NF_UPDATE_PERIOD_MS     (25)
 | 
						|
#endif
 | 
						|
#define PHY_SPIKE_FIND_THD                  (12)
 | 
						|
 | 
						|
#define PHY_FORCE_SPIKE_CHECK               (1)
 | 
						|
#define PHY_BB_AI_WITH_PULSE_CHECK_EN       (0)
 | 
						|
#define PHY_AGC_MIN_GAIN                    (-24)
 | 
						|
 | 
						|
#define PHY_CHN_HIGH_NOISE_NF_THD           (90)
 | 
						|
#define PHY_CHN_PKT_DET_THD1_DFT            (8)
 | 
						|
#define PHY_CHN_PKT_DET_THD2_DFT            (16)
 | 
						|
 | 
						|
#if PHY_BBAI_ALGORITHM == PHY_BBAI_FIX_WINDOWS
 | 
						|
/* near 7.3ms for each cycle, calibrate with 10ms with enough margin */
 | 
						|
#define PHY_CHN_EST_AI_PERIOD_MS            (10)
 | 
						|
#else
 | 
						|
/* near 15.6ms for each cycle, calibrate with 20ms with enough margin */
 | 
						|
#define PHY_CHN_EST_AI_PERIOD_MS            (20)
 | 
						|
#endif
 | 
						|
 | 
						|
/* define the frequece of spike, convert to the number of tones */
 | 
						|
#define PHY_SK_DEF_TONE_NUM              0
 | 
						|
#define PHY_SK_100K_TONE_NUM             4
 | 
						|
#define PHY_SK_150K_TONE_NUM             6
 | 
						|
#define PHY_SK_200K_TONE_NUM             8
 | 
						|
#define PHY_SK_250K_TONE_NUM             10
 | 
						|
#define PHY_SK_300K_TONE_NUM             12
 | 
						|
#define PHY_SK_350K_TONE_NUM             14
 | 
						|
#define PHY_SK_400K_TONE_NUM             16
 | 
						|
#define PHY_SK_450K_TONE_NUM             18
 | 
						|
#define PHY_SK_500K_TONE_NUM             20
 | 
						|
#define PHY_SK_550K_TONE_NUM             23 //22
 | 
						|
#define PHY_SK_600K_TONE_NUM             25
 | 
						|
#define PHY_SK_650K_TONE_NUM             27
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief phy_anti_spur_set.
 | 
						|
 *
 | 
						|
 * special config for spur certification test.
 | 
						|
 *
 | 
						|
 *@param bw_id              [band id.]
 | 
						|
 *@exception                [none.]
 | 
						|
 *@return                   [none.]
 | 
						|
 */
 | 
						|
void phy_anti_spur_set(int8_t bw_id);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief phy_anti_spur_set_clr.
 | 
						|
 *
 | 
						|
 * clear special config for spur certification test.
 | 
						|
 *
 | 
						|
 *@param bw_id              [band id.]
 | 
						|
 *@exception                [none.]
 | 
						|
 *@return                   [none.]
 | 
						|
 */
 | 
						|
void phy_anti_spur_set_clr();
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief phy_anti_pulse_set.
 | 
						|
 *
 | 
						|
 * special config for pulse certification test.
 | 
						|
 *
 | 
						|
 *@param                    [none.]
 | 
						|
 *@exception                [none.]
 | 
						|
 *@return                   [none.]
 | 
						|
 */
 | 
						|
void phy_anti_pulse_set();
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief phy_anti_pulse_set_clr.
 | 
						|
 *
 | 
						|
 * clear special config for pulse certification test.
 | 
						|
 *
 | 
						|
 *@param                    [none.]
 | 
						|
 *@exception                [none.]
 | 
						|
 *@return                   [none.]
 | 
						|
 */
 | 
						|
void phy_anti_pulse_set_clr();
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief phy_perf_common_init.
 | 
						|
 *
 | 
						|
 * gain table and notch filter default config initialize.
 | 
						|
 *
 | 
						|
 *@param bw_id              [none.]
 | 
						|
 *@exception                [none.]
 | 
						|
 *@return                   [none.]
 | 
						|
 */
 | 
						|
void phy_perf_common_init(void);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief phy_chn_est_cb.
 | 
						|
 *  cert specail detect, delete in the future.
 | 
						|
 *@param band_id            [band id]
 | 
						|
 *@param chn_ptr            [phy_chn_est_t structue pointer]
 | 
						|
 *@exception                [none.]
 | 
						|
 *@return                   [ERR_OK or ERR_FAIL.]
 | 
						|
 */
 | 
						|
uint32_t phy_chn_est_cb(uint32_t band_id, void *chn_ptr);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief phy_chn_spike_check.
 | 
						|
 *
 | 
						|
 * check if spike detect or not.
 | 
						|
 *
 | 
						|
 *@param bw_id              [none.]
 | 
						|
 *@exception                [none.]
 | 
						|
 *@return                   [none.]
 | 
						|
 */
 | 
						|
void phy_chn_spike_check(void);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief phy_chn_nf_update.
 | 
						|
 *
 | 
						|
 * update each point noise floor.
 | 
						|
 *
 | 
						|
 *@param need_fix_gain      [wheather need fix gain.]
 | 
						|
 *@exception                [none.]
 | 
						|
 *@return                   [none.]
 | 
						|
 */
 | 
						|
void phy_chn_nf_update(uint8_t need_fix_gain);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief phy_chan_est_flag_clear.
 | 
						|
 *
 | 
						|
 * clear all channel estimate flag for band switch.
 | 
						|
 *
 | 
						|
 *@param                    [none.]
 | 
						|
 *@exception                [none.]
 | 
						|
 *@return                   [none.]
 | 
						|
 */
 | 
						|
void phy_chan_est_flag_clear(void);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief phy_chn_est_ai_period_ms_get.
 | 
						|
 *
 | 
						|
 * get phy channel bbai each cycle period.
 | 
						|
 *
 | 
						|
 *@param                    [none.]
 | 
						|
 *@exception                [none.]
 | 
						|
 *@return                   [period counter, unit:ms.]
 | 
						|
 */
 | 
						|
uint32_t phy_chn_est_ai_period_ms_get(void);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief phy_pkt_thd_set.
 | 
						|
 *
 | 
						|
 * set pkt detect threshold depend on scenario.
 | 
						|
 *
 | 
						|
 *@param percent            [from 0 to 100.]
 | 
						|
 *@exception                [none.]
 | 
						|
 *@return                   [ERR_OK or ERR_FAIL.]
 | 
						|
 */
 | 
						|
uint32_t phy_pkt_thd_set(uint8_t percent);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief phy_spike_check_set.
 | 
						|
 *
 | 
						|
 * spike check set.
 | 
						|
 *
 | 
						|
 *@param seg_pwr_en         [segment power enable.]
 | 
						|
 *@param seg_pwr_mask_en    [segment power mask enable.]
 | 
						|
 *@param coeff              [coeff.]
 | 
						|
 *@exception                [none.]
 | 
						|
 *@return                   [none.]
 | 
						|
 */
 | 
						|
void phy_spike_check_set(uint8_t seg_pwr_en, \
 | 
						|
    uint8_t seg_pwr_mask_en, uint8_t coeff);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief phy_acc_seg_pwr_en_set.
 | 
						|
 *@param en                 [en = 0 to 0xff]
 | 
						|
 *@exception                [none.]
 | 
						|
 *@return                   [none.]
 | 
						|
 */
 | 
						|
void phy_acc_seg_pwr_en_set(uint8_t en);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief phy_acc_normal_coeff_set.
 | 
						|
 *@param coeff              [coeff.]
 | 
						|
 *@exception                [none.]
 | 
						|
 *@return                   [none.]
 | 
						|
 */
 | 
						|
void phy_acc_normal_coeff_set(uint8_t coeff);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief phy_acc_seg_pwr_mask_en.
 | 
						|
 *@param en                 [1: enable, 0: disable.]
 | 
						|
 *@exception                [none.]
 | 
						|
 *@return                   [none.]
 | 
						|
 */
 | 
						|
void phy_acc_seg_pwr_mask_en(uint8_t en);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief phy_acc_seg_pwr_mask_thr.
 | 
						|
 *@param thrd               [seg pwr threshhold.]
 | 
						|
 *@exception                [none.]
 | 
						|
 *@return                   [none.]
 | 
						|
 */
 | 
						|
void phy_acc_seg_pwr_mask_thr(uint8_t thrd);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief phy_acc_seg_pwr_mask_sel.
 | 
						|
 *@param sel                [seg pwr select.]
 | 
						|
 *@exception                [none.]
 | 
						|
 *@return                   [none.]
 | 
						|
 */
 | 
						|
void phy_acc_seg_pwr_mask_sel(uint8_t sel);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief phy_impuse_cancel_mode_set.
 | 
						|
 *@param mode               [impuse cancel mode.]
 | 
						|
 *@exception                [none.]
 | 
						|
 *@return                   [none.]
 | 
						|
 */
 | 
						|
void phy_impuse_cancel_mode_set(uint8_t mode);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief phy_impuse_cancel_clip_ratio_set.
 | 
						|
 *@param ratio              [clip ratio.]
 | 
						|
 *@exception                [none.]
 | 
						|
 *@return                   [none.]
 | 
						|
 */
 | 
						|
void phy_impuse_cancel_clip_ratio_set(uint8_t ratio);
 | 
						|
/**
 | 
						|
 *@brief phy_impuse_cancel_blank_ratio_set.
 | 
						|
 *@param ratio              [blank ratio.]
 | 
						|
 *@exception                [none.]
 | 
						|
 *@return                   [none.]
 | 
						|
 */
 | 
						|
void phy_impuse_cancel_blank_ratio_set(uint8_t ratio);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief phy_hpf_bypass_set.
 | 
						|
 *@param hpf_bypass         [high pass filter bypass or open.]
 | 
						|
 *@exception                [none.]
 | 
						|
 *@return                   [none.]
 | 
						|
 */
 | 
						|
void phy_hpf_bypass_set(uint8_t hpf_bypass);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief phy_hpf_alpha_set.
 | 
						|
 *@param hpf_alpha          [alpha for high pass filter.]
 | 
						|
 *@exception                [none.]
 | 
						|
 *@return                   [none.]
 | 
						|
 */
 | 
						|
void phy_hpf_alpha_set(uint8_t hpf_alpha);
 | 
						|
/**
 | 
						|
 *@brief phy_impuse_cancel_set.
 | 
						|
 *
 | 
						|
 * impuse cancel set.
 | 
						|
 *
 | 
						|
 *@param mode             [0:bypass,1:manual,2:one shot,3,continuous.]
 | 
						|
 *@param clip_ratio       [clip ratio.]
 | 
						|
 *@param blank_ratio      [blank ratio.]
 | 
						|
 *@exception              [none.]
 | 
						|
 *@return                 [none.]
 | 
						|
 */
 | 
						|
void phy_impuse_cancel_set(\
 | 
						|
    uint8_t mode, uint8_t clip_ratio, uint8_t blank_ratio);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief phy_impuse_cancel_set.
 | 
						|
 *
 | 
						|
 * impuse cancel set.
 | 
						|
 *
 | 
						|
 *@param hpf_bypass       [0:bypass,1:enable high pass filter.]
 | 
						|
 *@param hpf_alpha        [alpha for high pass filter.]
 | 
						|
 *@exception              [none.]
 | 
						|
 *@return                 [none.]
 | 
						|
 */
 | 
						|
void phy_hpf_set(uint8_t hpf_bypass, uint8_t hpf_alpha);
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
}
 | 
						|
#endif
 | 
						|
 | 
						|
#endif
 |