699 lines
17 KiB
C
699 lines
17 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 HW_PHY_API_H
|
|
#define HW_PHY_API_H
|
|
|
|
#include "os_types.h"
|
|
#include "iot_errno_api.h"
|
|
#include "iot_queue_api.h"
|
|
#include "iot_config_api.h"
|
|
#include "phy_bb.h"
|
|
#include "phy_chn.h"
|
|
#include "os_timer.h"
|
|
#include "plc_chn_est.h"
|
|
#include "iot_pkt_api.h"
|
|
#include "phy_data.h"
|
|
#include "phy_overstress.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define IOT_PHY_FFT_BUF_LEN (512)
|
|
#define PHY_CHN_EST_PRE_DET_CNT (5)
|
|
|
|
/* calibrate linear snr within -/+ 2.5dB*/
|
|
#define PHY_SNR_LINEAR_CAL(SNR_RAW) \
|
|
(((SNR_RAW) * 11453 - 13019) / 10000)
|
|
#define PHY_SNR_CAL_TH (10)
|
|
|
|
//kl3 SPUR:increase tgt pwr get bigger gain
|
|
#define PHY_AGC_RCV_TGT_PWR_SG_SPUR (109)
|
|
|
|
/* 200k spike rx target power uint:dbuv */
|
|
#define PHY_AGC_RCV_TGT_PWR_200K_SPIKE (118)
|
|
|
|
#define PHY_AGC_RCV_TGT_PWR_SG (103)
|
|
|
|
#define PHY_AGC_RCV_TGT_PWR_GP (105)
|
|
|
|
#define PHY_AGC_JUDGE_END_TONE (120)
|
|
|
|
#define PHY_AGC_ACC_STEP_192P (0)
|
|
#define PHY_AGC_ACC_STEP_384P (1)
|
|
#define PHY_AGC_ACC_STEP_768P (2)
|
|
#define PHY_AGC_ACC_STEP_1536P (3)
|
|
#define PHY_AGC_ACC_STEP_3072P (4)
|
|
#define PHY_AGC_ACC_STEP_6144P (5)
|
|
|
|
#define L0 (0)
|
|
#define L1 (1)
|
|
#define L2 (2)
|
|
#define L3 (3)
|
|
#define PEAK (4)
|
|
#define R0 (5)
|
|
#define R1 (6)
|
|
#define R2 (7)
|
|
#define R3 (8)
|
|
|
|
/* delay for chip hang, unit ms */
|
|
#define CHIP_HANG_DELAY 15
|
|
|
|
#define PHY_GET_NF() (g_phy_ctxt.dep.nf)
|
|
#define phy_busy_wait(cycle) \
|
|
do { \
|
|
uint32_t cnt = 0; \
|
|
while (cnt < cycle) {cnt++;} \
|
|
} while(0)
|
|
|
|
/* todo: replace refs to rx_mpdu_start.h ? */
|
|
typedef struct _iot_phy_info{
|
|
/* phy info start */
|
|
uint8_t adc_power;
|
|
uint8_t agc_tbl_entry;
|
|
uint8_t est_dc;
|
|
int8_t est_ppm; /* int8_t type */
|
|
int8_t avg_snr;
|
|
uint8_t pream_sym_detect;
|
|
uint8_t remain_phase_frac;
|
|
uint8_t max_spur_id;
|
|
/* phy info end */
|
|
} iot_phy_info_t;
|
|
|
|
typedef enum {
|
|
PHY_MODE_NORMAL = 0,
|
|
PHY_MODE_TEST = 1,
|
|
PHY_MODE_END = 2,
|
|
} phy_work_mode_id;
|
|
|
|
typedef struct _phy_tx_pwr_cfg_tbl{
|
|
uint8_t dig_tx_factor :5,
|
|
ana_tx_gain :3;
|
|
} phy_tx_pwr_cfg_tbl_t;
|
|
|
|
typedef uint32_t (*iot_phy_chn_tx_cb)(void);
|
|
|
|
typedef struct _phy_chn_est{
|
|
uint8_t spur_8m_done_flag : 1,
|
|
spur_3m_done_flag : 1,
|
|
spur_2m_done_flag : 1,
|
|
pulse_done_flag : 1,
|
|
bcn_check_cnt : 4;
|
|
} phy_chn_est_t;
|
|
|
|
typedef struct _iot_phy_tone_param_ctxt_t {
|
|
/* tone start flag */
|
|
uint32_t tone_start : 1,
|
|
/* retry counter */
|
|
rty_cnt : 31;
|
|
/* tone timer id */
|
|
timer_id_t tone_timer;
|
|
timer_id_t auto_tone_timer;
|
|
timer_id_t rest_tone_timer;
|
|
/* start tone */
|
|
uint16_t start_tone;
|
|
/* end tone */
|
|
uint16_t end_tone;
|
|
/* current tone */
|
|
uint16_t curent_tone;
|
|
/* tone tx interval time value, unit ms */
|
|
uint16_t tx_intval_time_ms;
|
|
} iot_phy_tone_param_ctxt_t;
|
|
|
|
/* global ctxt */
|
|
typedef struct _iot_phy_plat_indep_ctxt {
|
|
/* band info 44 bytes */
|
|
iot_phy_chn_ctxt_t chn;
|
|
|
|
/* tx tone param 24bytes */
|
|
iot_phy_tone_param_ctxt_t tx_tone;
|
|
|
|
/* phy overstress context 12 bytes */
|
|
phy_overstress_ctxt_t ovs_ctxt;
|
|
|
|
iot_phy_chn_tx_cb phy_chn_tx_cb;
|
|
|
|
/* tx pwr reduce dB */
|
|
uint32_t tx_pwr_reduce_db : 8,
|
|
/* target power */
|
|
tgt_pwr : 8,
|
|
/* tx psd fix */
|
|
tx_pwr_psd_fix_db : 6,
|
|
/* work mode */
|
|
work_mode : 1,
|
|
/* notch filter enable */
|
|
notch_filter_en : 1,
|
|
/* spike find */
|
|
spike_shift_en : 1,
|
|
/* det tone extend */
|
|
det_tone_extend_en : 1,
|
|
/* current pm status */
|
|
pm_sts : 2,
|
|
sw_agc_force_off : 1,
|
|
tx_pga : 2,
|
|
cert_force_spike : 1;
|
|
|
|
/* channel estimate 1 byte */
|
|
phy_chn_est_t chn_est;
|
|
/* record nncco fc */
|
|
uint32_t nn_cco_fc[4];
|
|
} iot_phy_plat_indep_ctxt_t;
|
|
|
|
/* phy total ctxt entry */
|
|
typedef struct _phy_ctxt {
|
|
iot_phy_plat_dep_ctxt_t dep;
|
|
iot_phy_plat_indep_ctxt_t indep;
|
|
} phy_ctxt_t;
|
|
|
|
extern phy_ctxt_t g_phy_ctxt;
|
|
|
|
/* phy busy id */
|
|
typedef enum {
|
|
PHY_BUSY_TX,
|
|
PHY_BUSY_RX,
|
|
PHY_BUSY_DUMP,
|
|
PHY_BUSY_MAX
|
|
} PHY_BUSY_ID;
|
|
|
|
/**
|
|
*@brief phy_info_check_entry.
|
|
*
|
|
* Phy API called by MAC task to check channel state.
|
|
*
|
|
*@param phy_info [mpdu start ptr]
|
|
*@param fc [fc ptr]
|
|
*@param role [CCO or STA or IIC.]
|
|
*@exception [none.]
|
|
*@return [ERR_OK or ERR_FAIL.]
|
|
*/
|
|
uint32_t phy_info_check_entry(void *mpdu_st,
|
|
void *fc, uint32_t role, uint8_t mt_mode_sel);
|
|
|
|
/**
|
|
*@brief phy_check_spur_cert_handle.
|
|
*
|
|
* some special handle to cert chck spur.
|
|
*
|
|
*@param notch_alpha [notch alpha]
|
|
*@exception [none.]
|
|
*@return [void]
|
|
*/
|
|
void phy_check_spur_cert_handle(uint16_t notch_alpha);
|
|
|
|
/**
|
|
*@brief phy_work_mode_set.
|
|
*
|
|
* Phy API called by MAC task to set current test mode.
|
|
*
|
|
*@param mode [normal or test mode.]
|
|
*@exception [none.]
|
|
*@return [ERR_OK or ERR_FAIL.]
|
|
*/
|
|
uint32_t phy_work_mode_set(phy_work_mode_id mode);
|
|
|
|
/**
|
|
*@brief iot_phy_chn_dump_start.
|
|
*
|
|
* start ada dump with upper parameters and callback data output API.
|
|
*
|
|
*@param dump_cfg [dump parameters.]
|
|
*@exception [none.]
|
|
*@return [0 sucess and other fail.]
|
|
*/
|
|
uint32_t iot_phy_chn_dump_start(iot_phy_chn_dump_rt_cfg_t *dump_cfg);
|
|
|
|
/**
|
|
*@brief phy_chn_est_ai_by_time.
|
|
*
|
|
* This api can be used for phy channel estimate when phy init or reinit.
|
|
* Also, the upper layer can redo it if channel changed dynmaically. Pls
|
|
* check the return cnt to fit your expectation and avoid block. The input
|
|
* parameter is period with ms unit.
|
|
*
|
|
*@param time_ms [expected time with the unit of ms.]
|
|
*@exception [none.]
|
|
*@return [successful counter.]
|
|
*/
|
|
uint32_t phy_chn_est_ai_by_time(uint32_t time_ms);
|
|
|
|
/**
|
|
*@brief phy_chn_est_pre_detect.
|
|
*
|
|
* do channel estimate after phy init.
|
|
* there'll be very usrful to receive beacon with big attenuation.
|
|
*
|
|
*@param [none.]
|
|
*@exception [none.]
|
|
*@return [none.]
|
|
*/
|
|
void phy_chn_est_pre_detect(void);
|
|
|
|
/**
|
|
*@brief phy_rx_scan_fft_dump.
|
|
*
|
|
*for collecting fft dump data by sending multiple packets,
|
|
*each data packet has a unique packet number, sending completes
|
|
*until up to total packet number.
|
|
*
|
|
*@param buf_ptr [csi data from csi buf.]
|
|
*@param rx_gain [get uint8_t rx_gain parameter for fft dump.]
|
|
*@param cur_pnum [current packet number, sent partially.]
|
|
*@param total_pnum [total packets number to transmit.]
|
|
*@exception [none.]
|
|
*@return [uint32_t err_ok.]
|
|
*/
|
|
uint32_t phy_rx_scan_fft_dump(uint32_t *buf_ptr, int8_t rx_gain,\
|
|
uint16_t cur_pnum, uint16_t total_pnum);
|
|
|
|
/**
|
|
*@brief phy_rx_snr_cal.
|
|
*
|
|
* This API will get the max value between time domain snr and frequency
|
|
* domain snr. The frequency snr must be calibrated firstly.
|
|
*
|
|
*@param phy_info [phy info pointer.]
|
|
*@exception [none.]
|
|
*@return [snr.]
|
|
*/
|
|
int8_t phy_rx_snr_cal(void *phy_info, uint8_t rx_phase);
|
|
|
|
/**
|
|
*@brief phy_rx_snr_cal.
|
|
*
|
|
* snr will mapping to -10 ~ 90 dB. clip to 90 if snr > 90 dB and clip to
|
|
* -10 dB if snr < -10 dB.
|
|
*
|
|
*@param raw_snr [snr raw data.]
|
|
*@exception [none.]
|
|
*@return [mapping snr.]
|
|
*/
|
|
int8_t phy_snr_mapping_minus10_90(int8_t raw_snr);
|
|
|
|
/**
|
|
*@brief phy_fd_short_band_rms_get
|
|
* get current fd short band rms value.
|
|
*@param valid_tone_num [valid tone number.]
|
|
*@param para_int [rms integer.]
|
|
*@param para_frac [rms frac.]
|
|
*@exception [none.]
|
|
*@return [none.]
|
|
*/
|
|
void phy_fd_short_band_rms_get(uint32_t valid_tone_num, uint8_t *para_int, uint8_t *para_frac);
|
|
|
|
/**
|
|
*@brief phy_dbg_sts_print.
|
|
*
|
|
* print rx cnt, tx cnt and status registers.
|
|
*
|
|
*@param [none.]
|
|
*@exception [none.]
|
|
*@return [none.]
|
|
*/
|
|
void phy_dbg_sts_print();
|
|
|
|
/**
|
|
*@brief phy_chn_nf_get.
|
|
*
|
|
* get current noise floor from phy global value.
|
|
*
|
|
*@param [none.]
|
|
*@exception [none.]
|
|
*@return [noise floor.]
|
|
*/
|
|
uint8_t phy_chn_nf_get(void);
|
|
|
|
/**
|
|
*@brief phy_chn_tx_power_get.
|
|
*
|
|
* get current hplc tx power from phy global value.
|
|
*
|
|
*@param [none.]
|
|
*@exception [none.]
|
|
*@return [noise floor.]
|
|
*/
|
|
uint8_t phy_chn_tx_power_get(void);
|
|
|
|
/**
|
|
*@brief phy_idle_set.
|
|
*
|
|
* turn off phy clk.
|
|
*
|
|
*@param [none.]
|
|
*@exception [none.]
|
|
*@return [none.]
|
|
*/
|
|
void phy_idle_set();
|
|
|
|
/**
|
|
*@brief phy_idle_clr.
|
|
*
|
|
* turn on phy clk.
|
|
*
|
|
*@param [none.]
|
|
*@exception [none.]
|
|
*@return [none.]
|
|
*/
|
|
void phy_idle_clr();
|
|
|
|
/**
|
|
*@brief phy_pkt_found_flag_get.
|
|
*
|
|
* check if packet received .
|
|
*
|
|
*@param [none.]
|
|
*@exception [none.]
|
|
*@return [true or others false.]
|
|
*/
|
|
bool_t phy_pkt_found_flag_get(void);
|
|
|
|
/**
|
|
*@brief phy_pkt_found_flag_clr.
|
|
*
|
|
* clear the global packet received flag.
|
|
*
|
|
*@param [none.]
|
|
*@exception [none.]
|
|
*@return [none.]
|
|
*/
|
|
void phy_pkt_found_flag_clr(void);
|
|
|
|
|
|
/**
|
|
*@brief phy_cfg_band_filter_gpio.
|
|
*
|
|
*
|
|
*@param protocol_band_id [plc band id.]
|
|
*@exception [none.]
|
|
*@return [none.]
|
|
*/
|
|
void phy_cfg_band_filter_gpio(uint8_t protocol_band_id);
|
|
|
|
|
|
/**
|
|
*@brief phy_init_band_filter_gpio.
|
|
*
|
|
*
|
|
*@param [none.]
|
|
*@exception [none.]
|
|
*@return [none.]
|
|
*/
|
|
void phy_init_band_filter_gpio();
|
|
|
|
/**
|
|
*@brief phy_rx_tgt_pwr_set.
|
|
*
|
|
* set rx target power of global phy ctxt.
|
|
*
|
|
*@param pwr [rx target power.]
|
|
*@exception [none.]
|
|
*@return [none.]
|
|
*/
|
|
void phy_rx_tgt_pwr_set(uint8_t pwr);
|
|
|
|
/**
|
|
*@brief phy_rx_tgt_pwr_get.
|
|
*
|
|
* get rx target power of global phy ctxt.
|
|
*
|
|
*@param [none.]
|
|
*@exception [none.]
|
|
*@return [none.]
|
|
*/
|
|
uint8_t phy_rx_tgt_pwr_get();
|
|
|
|
/**
|
|
*@brief phy_spike_shift_en_set.
|
|
*
|
|
* set spike shift en flag of global phy ctxt.
|
|
*
|
|
*@param en [enable.]
|
|
*@exception [none.]
|
|
*@return [none.]
|
|
*/
|
|
void phy_spike_shift_en_set(bool_t en);
|
|
|
|
/**
|
|
*@brief phy_spike_shift_en_get.
|
|
*
|
|
* get spike shift en flag of global phy ctxt.
|
|
*
|
|
*@param [none.]
|
|
*@exception [none.]
|
|
*@return [none.]
|
|
*/
|
|
bool_t phy_spike_shift_en_get();
|
|
|
|
/**
|
|
*@brief phy_det_tone_ext_en_set.
|
|
*
|
|
* set detect tone ext en flag of global phy ctxt.
|
|
*
|
|
*@param en [enable.]
|
|
*@exception [none.]
|
|
*@return [none.]
|
|
*/
|
|
void phy_det_tone_ext_en_set(bool_t en);
|
|
|
|
/**
|
|
*@brief phy_det_tone_ext_en_get.
|
|
*
|
|
* get detect tone ext en flag of global phy ctxt.
|
|
*
|
|
*@param [none.]
|
|
*@exception [none.]
|
|
*@return [none.]
|
|
*/
|
|
bool_t phy_det_tone_ext_en_get();
|
|
|
|
/**
|
|
*@brief phy_rise_pwr_flag_set.
|
|
*
|
|
* set rise power flag of global phy ctxt.
|
|
*
|
|
*@param en [enable.]
|
|
*@exception [none.]
|
|
*@return [none.]
|
|
*/
|
|
void phy_rise_pwr_flag_set(bool_t en);
|
|
|
|
/**
|
|
*@brief phy_get_mp_mode.
|
|
*
|
|
* get mp mode
|
|
*
|
|
*@param [none.]
|
|
*@exception [none.]
|
|
*@return [true or flase.]
|
|
*/
|
|
uint32_t phy_get_fw_mode(void);
|
|
|
|
/**
|
|
*@brief phy_swagc_set.
|
|
*
|
|
* disable or enable sw-agc.
|
|
*
|
|
*@param en [true for enable and false for disable.]
|
|
*@exception [none.]
|
|
*@return [0 sucess and other fail.]
|
|
*/
|
|
uint32_t phy_swagc_set(bool_t en);
|
|
|
|
/**
|
|
*@brief phy_busy_get.
|
|
*
|
|
* get dump busy flag from global phy ctxt.
|
|
*
|
|
*@param id [busy status id.]
|
|
*@param phy_ctxt [ctxt pointer.]
|
|
*@exception [none.]
|
|
*@return [true for busy and false for idle.]
|
|
*/
|
|
bool_t phy_busy_get(void *phy_ctxt, PHY_BUSY_ID id);
|
|
|
|
/**
|
|
*@brief phy_ctxt_get.
|
|
*
|
|
* get phy global ctxt pointer.
|
|
*
|
|
*@param [none.]
|
|
*@exception [none.]
|
|
*@return [true for busy and false for idle.]
|
|
*/
|
|
phy_ctxt_t *phy_ctxt_get();
|
|
|
|
/**
|
|
*@brief phy_ctxt_get.
|
|
*
|
|
* detect big spur or pulse in current rx patch.
|
|
*
|
|
*@param [none.]
|
|
*@exception [none.]
|
|
*@return [true or false.]
|
|
*/
|
|
bool_t phy_high_noise_sts_get();
|
|
|
|
/**
|
|
*@brief phy_csma_ignore_cca.
|
|
*
|
|
* force csma tx enable all the time without regard for cca detect.
|
|
*
|
|
*@param [en]
|
|
*@exception [none.]
|
|
*@return [true for enable and false for disable.]
|
|
*/
|
|
void phy_csma_ignore_cca(bool_t en);
|
|
|
|
/**
|
|
*@brief phy_force_ana_td_power. force fd/ana power from reg
|
|
*
|
|
*@param [value.]
|
|
*@exception [none.]
|
|
*@return [0]
|
|
*/
|
|
uint32_t phy_force_ana_td_power(uint32_t value);
|
|
|
|
/**
|
|
*@brief phy_set_tx_pwr_td. set td power
|
|
*
|
|
*@param [value: td power]
|
|
*@exception [none.]
|
|
*@return [0]
|
|
*/
|
|
uint32_t phy_set_tx_pwr_td(uint32_t value);
|
|
|
|
/**
|
|
*@brief phy_get_tx_pwr_td. get td power
|
|
*
|
|
*@param [none.]
|
|
*@exception [none.]
|
|
*@return uint8_t [td pwr]
|
|
*/
|
|
uint8_t phy_get_tx_pwr_td(void);
|
|
|
|
/**
|
|
*@brief phy_set_tx_pwr_ana. set ana power
|
|
*
|
|
*@param [value: ana power]
|
|
*@exception [none.]
|
|
*@return [0]
|
|
*/
|
|
uint32_t phy_set_tx_pwr_ana(uint32_t value);
|
|
|
|
/**
|
|
*@brief phy_set_tx_pwr_fd_frac. set fd frac power
|
|
*
|
|
*@param [value: fd frac power]
|
|
*@exception [none.]
|
|
*@return [0]
|
|
*/
|
|
uint32_t phy_set_tx_pwr_fd_frac(uint32_t value);
|
|
|
|
/**
|
|
*@brief phy_set_tx_pwr_fd_int. set fd int power
|
|
*
|
|
*@param [value: fd int power]
|
|
*@exception [none.]
|
|
*@return [0]
|
|
*/
|
|
uint32_t phy_set_tx_pwr_fd_int(uint32_t value);
|
|
|
|
/**
|
|
*@brief phy_cert_is_hw_agc.
|
|
*
|
|
* check if hw agc should be applied for PHY transparent transfer test mode
|
|
*
|
|
*@param [none.]
|
|
*@exception [none.]
|
|
*@return [1 for enable and 0 for disable.]
|
|
*/
|
|
uint8_t phy_cert_is_hw_agc();
|
|
|
|
/**
|
|
*@brief register_phy_call_mac_bbai_cb.
|
|
*
|
|
* Register callback function for phy call mac api.
|
|
*
|
|
*@param cb [callback function from mac]
|
|
*@exception [time_ms.]
|
|
*@return [ret.]
|
|
*/
|
|
typedef uint32_t (*phy_call_mac_func_cb_t)(uint32_t time_ms);
|
|
void register_phy_call_mac_bbai_cb(phy_call_mac_func_cb_t cb);
|
|
|
|
/**
|
|
*@brief register_phy_get_cert_mode_cb.
|
|
*
|
|
* Register callback function for phy get cert mode.
|
|
*
|
|
*@param cb [callback function from mac]
|
|
*@exception [none.]
|
|
*@return [cert mode.]
|
|
*/
|
|
typedef uint8_t (*phy_get_cert_mode_cb_t)();
|
|
void register_phy_get_cert_mode_cb(phy_get_cert_mode_cb_t cb);
|
|
|
|
/**
|
|
*@brief phy_updata_nf_of_bbai() updata nf of bbai
|
|
*
|
|
*@param [none.]
|
|
*@exception [none.]
|
|
*@return [none.]
|
|
*/
|
|
void phy_updata_nf_of_bbai();
|
|
|
|
/**
|
|
*@brief phy_get_nf_of_bbai() get nf of bbai
|
|
*
|
|
*@param [none.]
|
|
*@exception [none.]
|
|
*@return [bbai nf]
|
|
*/
|
|
uint32_t phy_get_nf_of_bbai();
|
|
|
|
/**
|
|
*@brief phy_channel_est_request() phy channel est request
|
|
*
|
|
*@param [none.]
|
|
*@exception [none.]
|
|
*@return [void]
|
|
*/
|
|
void phy_channel_est_request(void);
|
|
|
|
/**
|
|
*@brief phy_cert_check_spike() phy cert mode check spike
|
|
*
|
|
*@param [none.]
|
|
*@exception [none.]
|
|
*@return [void]
|
|
*/
|
|
void phy_cert_check_spike();
|
|
|
|
/**
|
|
*@brief phy_is_sta_role() judge whether the device is STA.
|
|
*
|
|
*@param [none.]
|
|
*@exception [none.]
|
|
*@return [0: not sta, 1: is sta]
|
|
*/
|
|
uint32_t phy_is_sta_role();
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|
|
|