682 lines
		
	
	
		
			22 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			682 lines
		
	
	
		
			22 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
#include "hw_reg_api.h"
 | 
						|
#include "rx_entry.h"
 | 
						|
#include "plc_utils.h"
 | 
						|
#include "mac_reset.h"
 | 
						|
#include "mac_sys_reg.h"
 | 
						|
#include "mac_rx_reg.h"
 | 
						|
#include "hw_phy_init.h"
 | 
						|
#include "iot_pkt_api.h"
 | 
						|
#include "os_mem.h"
 | 
						|
#include "rx_pb_reorder.h"
 | 
						|
#include "phy_reg.h"
 | 
						|
#include "phy_bb.h"
 | 
						|
#include "phy_chn.h"
 | 
						|
#include "hw_tonemask.h"
 | 
						|
#include "iot_io.h"
 | 
						|
#include "phy_ana.h"
 | 
						|
#include "iot_config.h"
 | 
						|
#include "plc_protocol.h"
 | 
						|
#include "phy_rxtd_reg.h"
 | 
						|
#include "phy_dfe_reg.h"
 | 
						|
#include "tx_mpdu_start.h"
 | 
						|
#include "phy_cal.h"
 | 
						|
#include "iot_errno_api.h"
 | 
						|
#if IOT_DTEST_ONLY_SUPPORT == 0
 | 
						|
#include "iot_cal_data.h"
 | 
						|
#endif
 | 
						|
#include "math_log10.h"
 | 
						|
#include "hw_phy_api.h"
 | 
						|
#include "tx_entry.h"
 | 
						|
#include "iot_gpio_api.h"
 | 
						|
#include "iot_crc_api.h"
 | 
						|
#include "mac_init_api.h"
 | 
						|
#include "hw_tx.h"
 | 
						|
#include "hw_rx.h"
 | 
						|
#include "mpdu_header.h"
 | 
						|
#include "hal_rx.h"
 | 
						|
 | 
						|
uint8_t *rx_recev_packet()
 | 
						|
{
 | 
						|
    uint8_t *rx_buf_info = NULL;
 | 
						|
    uint32_t start_time = 0, end_time = 0;
 | 
						|
    uint64_t time_span = 0;
 | 
						|
 | 
						|
    start_time = RGF_MAC_READ_REG(CFG_RD_NTB_ADDR);
 | 
						|
    while(true)//is_rx_ring0_empty()
 | 
						|
    {
 | 
						|
        end_time = RGF_MAC_READ_REG(CFG_RD_NTB_ADDR);
 | 
						|
        time_span = end_time - start_time;
 | 
						|
        if (time_span < 0) { // wrap around
 | 
						|
            time_span = (0x100000000LL) - start_time + end_time;
 | 
						|
        }
 | 
						|
        if((uint64_t)time_span > 2000*TICKS_MS) {
 | 
						|
            iot_printf("[fail]golden unit is not online\n");
 | 
						|
            return NULL;
 | 
						|
        }
 | 
						|
        if(((uint64_t)time_span)%(200*TICKS_MS) < 100
 | 
						|
            && time_span / (200 * TICKS_MS) != 0) {
 | 
						|
            mac_tx_mpdu_test(NULL, mpdu_start);
 | 
						|
            dt_mac_tx_hwq0_re_trig();
 | 
						|
        }
 | 
						|
        if(!is_rx_ring0_empty()) {
 | 
						|
            rx_buf_info = pop_rx_buf_from_ring(0);
 | 
						|
            if (rx_buf_info) {
 | 
						|
                return rx_buf_info;
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
uint32_t mac_rx_init(uint32_t band_id)
 | 
						|
{
 | 
						|
    static volatile uint8_t first_rx_init_flag = 0;
 | 
						|
 | 
						|
    if(!first_rx_init_flag)
 | 
						|
    {
 | 
						|
        uint32_t tmp = RX_BUF_NUM;
 | 
						|
#if IOT_DTEST_ONLY_SUPPORT == 0
 | 
						|
        iot_pkt_t *pkt_buf = NULL;
 | 
						|
        while(tmp--){
 | 
						|
            IOT_PKT_GET(pkt_buf, RX_BUF_BYTE_SIZE, 0, IOT_FTM_MID);
 | 
						|
            if(!pkt_buf) {
 | 
						|
                iot_printf("iot_pkt_get rx_buf fail\n");
 | 
						|
                return ERR_FAIL;
 | 
						|
            }
 | 
						|
            g_plc_dt_ctxt.indep.rx_buf[tmp] = \
 | 
						|
                (uint8_t *)iot_pkt_put(pkt_buf, RX_BUF_BYTE_SIZE);
 | 
						|
        }
 | 
						|
        tmp = MAX_TMI_NUM;
 | 
						|
        while(tmp--){
 | 
						|
            IOT_PKT_GET(pkt_buf, MAX_PB_NUM * 4, 0, IOT_FTM_MID);
 | 
						|
            if(!pkt_buf) {
 | 
						|
                iot_printf("iot_pkt_get tmi_beacon_cnt fail\n");
 | 
						|
                return ERR_FAIL;
 | 
						|
            }
 | 
						|
            g_plc_dt_ctxt.indep.tmi_beacon_cnt[tmp] = \
 | 
						|
                (uint32_t *)iot_pkt_put(pkt_buf, MAX_PB_NUM * 4);
 | 
						|
        }
 | 
						|
        tmp = MAX_TMI_NUM;
 | 
						|
        while(tmp--){
 | 
						|
            IOT_PKT_GET(pkt_buf, MAX_PB_NUM * 4, 0, IOT_FTM_MID);
 | 
						|
            if(!pkt_buf) {
 | 
						|
                iot_printf("iot_pkt_get tmi_sof_cnt fail\n");
 | 
						|
                return ERR_FAIL;
 | 
						|
            }
 | 
						|
            g_plc_dt_ctxt.indep.tmi_sof_cnt[tmp] = \
 | 
						|
                (uint32_t *)iot_pkt_put(pkt_buf, MAX_PB_NUM * 4);
 | 
						|
        }
 | 
						|
        IOT_PKT_GET(pkt_buf, sizeof(mac_rx_phy_info_t), 0, IOT_FTM_MID);
 | 
						|
        if(!pkt_buf) {
 | 
						|
            iot_printf("iot_pkt_get phy_info fail\n");
 | 
						|
            return ERR_FAIL;
 | 
						|
        }
 | 
						|
        g_plc_dt_ctxt.indep.phy_info = \
 | 
						|
            (mac_rx_phy_info_t *)iot_pkt_put(pkt_buf, sizeof(mac_rx_phy_info_t));
 | 
						|
#else
 | 
						|
        g_plc_dt_ctxt.indep.phy_info = &g_plc_dt_ctxt.indep.phy_info_tmp;
 | 
						|
        tmp = RX_BUF_NUM;
 | 
						|
        while(tmp--) {
 | 
						|
            g_plc_dt_ctxt.indep.rx_buf[tmp] = \
 | 
						|
                (uint8_t *)os_mem_malloc(PLC_PHY_COMMON_MID, RX_BUF_BYTE_SIZE);
 | 
						|
        }
 | 
						|
#endif
 | 
						|
        /* update flag */
 | 
						|
        first_rx_init_flag = 1;
 | 
						|
    }
 | 
						|
 | 
						|
#if IOT_DTEST_ONLY_SUPPORT == 0
 | 
						|
    /* mac pre init */
 | 
						|
    mac_pre_phy_reinit();
 | 
						|
    /* reset phy */
 | 
						|
    phy_reset(PHY_RST_REASON_COLD);
 | 
						|
    /* release idle mode */
 | 
						|
    mac_force_phy_tx_ready(0, 0);
 | 
						|
    mac_set_sw_idle_mode(1,0);
 | 
						|
    mac_set_sw_idle_mode(0,0);
 | 
						|
#else
 | 
						|
    /* reset phy */
 | 
						|
    phy_reset(PHY_RST_REASON_COLD);
 | 
						|
#endif
 | 
						|
 | 
						|
    /* ada soft reset */
 | 
						|
    warm_rst_ada();
 | 
						|
 | 
						|
    phy_init(glb_cfg.m_type, band_id, phy_band_to_tonemask_id_get(band_id),
 | 
						|
        true);
 | 
						|
 | 
						|
    /* init phy dtest path */
 | 
						|
    phy_rx_path_init();
 | 
						|
 | 
						|
    /* init mac path */
 | 
						|
    mac_rx_path_init();
 | 
						|
 | 
						|
    return 0;
 | 
						|
}
 | 
						|
 | 
						|
void rx_ring_setup_hw(uint32_t ring_id, rx_ring_cfg_t *cfg)
 | 
						|
{
 | 
						|
    (void)ring_id;
 | 
						|
    (void)cfg;
 | 
						|
 | 
						|
    uint32_t tmp;
 | 
						|
    uint32_t i;
 | 
						|
 | 
						|
    /* malloc pointer array to ensure access by mac */
 | 
						|
    g_plc_dt_ctxt.indep.rx_buf_ptr_list = \
 | 
						|
        (uint8_t **)os_mem_malloc(IOT_FTM_MID, sizeof(uint8_t*)*RX_BUF_NUM);
 | 
						|
 | 
						|
    /* init the rx ring buf */
 | 
						|
    for (i = 0; i < RX_BUF_NUM; i++) {
 | 
						|
        g_plc_dt_ctxt.indep.rx_buf_ptr_list[i] = g_plc_dt_ctxt.indep.rx_buf[i];
 | 
						|
    }
 | 
						|
    RGF_RX_WRITE_REG(CFG_BUFFER_RING0_0_ADDR, \
 | 
						|
        (uint32_t)g_plc_dt_ctxt.indep.rx_buf_ptr_list);
 | 
						|
 | 
						|
    /* set ring sz and buf len */
 | 
						|
    tmp = RGF_RX_READ_REG(CFG_BUFFER_RING0_1_ADDR);
 | 
						|
    REG_FIELD_SET(CFG_RING0_BUF_SIZE, tmp, RX_BUF_DW_SIZE);
 | 
						|
    REG_FIELD_SET(CFG_RING0_BUF_NUM, tmp, RX_BUF_NUM);
 | 
						|
    RGF_RX_WRITE_REG(CFG_BUFFER_RING0_1_ADDR, tmp);
 | 
						|
 | 
						|
    /* set rd idx = 0 as default */
 | 
						|
    tmp = RGF_RX_READ_REG(CFG_BUFFER_RING0_2_ADDR);
 | 
						|
    REG_FIELD_SET(CFG_RING0_RD_IDX, tmp, 0);
 | 
						|
    RGF_RX_WRITE_REG(CFG_BUFFER_RING0_2_ADDR, tmp);
 | 
						|
 | 
						|
    /* set desc and payload offset */
 | 
						|
    tmp = RGF_RX_READ_REG(CFG_BUFFER_RING0_3_ADDR);
 | 
						|
    REG_FIELD_SET(CFG_RING0_DESC_EN, tmp, 1);
 | 
						|
    REG_FIELD_SET(CFG_RING0_PAYLOAD_EN, tmp, 1);
 | 
						|
    REG_FIELD_SET(CFG_RING0_DESC_OFFSET, tmp, 0);
 | 
						|
    REG_FIELD_SET(CFG_RING0_PAYLOAD_OFFSET, tmp, \
 | 
						|
        iot_ceil(sizeof(rx_buf_hdr_t), 4));
 | 
						|
    RGF_RX_WRITE_REG(CFG_BUFFER_RING0_3_ADDR, tmp);
 | 
						|
 | 
						|
    return;
 | 
						|
}
 | 
						|
 | 
						|
void rx_ring_enable(uint32_t ring_id, uint32_t enable)
 | 
						|
{
 | 
						|
    (void)ring_id;
 | 
						|
    uint32_t tmp;
 | 
						|
    tmp = RGF_RX_READ_REG(CFG_BUFFER_RING0_2_ADDR);
 | 
						|
    REG_FIELD_SET(CFG_RING0_EN, tmp, enable);
 | 
						|
    RGF_RX_WRITE_REG(CFG_BUFFER_RING0_2_ADDR, tmp);
 | 
						|
 | 
						|
    return;
 | 
						|
}
 | 
						|
 | 
						|
uint32_t is_rx_ring0_empty()
 | 
						|
{
 | 
						|
    uint32_t rd_idx, wr_idx;
 | 
						|
    rd_idx = RX_RING_GET_RD_IDX(0);
 | 
						|
    wr_idx = RX_RING_GET_WR_IDX(0);
 | 
						|
 | 
						|
    return (rd_idx == wr_idx);
 | 
						|
}
 | 
						|
 | 
						|
/*TODO: use api or  formal parameter instead of Macro*/
 | 
						|
uint8_t *pop_rx_buf_from_ring(uint32_t ring_id)
 | 
						|
{
 | 
						|
    (void)ring_id;
 | 
						|
    uint32_t rd_idx = 0;
 | 
						|
    uint8_t *rx_buf_start;
 | 
						|
    rx_buf_hdr_t *pb_buf;
 | 
						|
    static uint32_t enq_time = 0, cur_time = 0;
 | 
						|
    static int64_t time_span = 0;
 | 
						|
    uint8_t pre_sym = 0, max_spur_id = 0;
 | 
						|
    int8_t snr = 0;
 | 
						|
 | 
						|
    rd_idx = RX_RING_GET_RD_IDX(0);
 | 
						|
    rx_buf_start = g_plc_dt_ctxt.indep.rx_buf[rd_idx];
 | 
						|
    pb_buf = (rx_buf_hdr_t *)rx_buf_start;
 | 
						|
 | 
						|
    /* get nid */
 | 
						|
    uint32_t nid = mac_get_nid_from_fc( \
 | 
						|
        phy_proto_type_get(), \
 | 
						|
        mac_rx_mpdu_st_get_fc_addr(&pb_buf->mpdu_st) \
 | 
						|
        );
 | 
						|
 | 
						|
#if PHY_PPM_CAL_SUPPORT == 1
 | 
						|
    /* get fc delimiter */
 | 
						|
    uint32_t delimiter = mac_get_rx_delimiter_from_fc( \
 | 
						|
        phy_proto_type_get(), \
 | 
						|
        mac_rx_mpdu_st_get_fc_addr(&pb_buf->mpdu_st) \
 | 
						|
        );
 | 
						|
 | 
						|
#if PHY_RX_DBG_EN
 | 
						|
    if (dut_flag == false) {
 | 
						|
        iot_printf("[Debug]pop pb_buf addr:%x, dut:%d\r\n", \
 | 
						|
            g_plc_dt_ctxt.indep.pb_buf, g_plc_dt_ctxt.indep.dut_flag);
 | 
						|
        for(uint32_t j = 5; j < 8; j++)
 | 
						|
        {
 | 
						|
            iot_printf("[Debug] addr:%d, value:%02x\r\n", j,rx_buf_start[j]);
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    /* check fail pkt */
 | 
						|
    if (nid != glb_cfg.nid) {
 | 
						|
        iot_printf("[Debug]rx mpdu done:%d, nid%x \n", \
 | 
						|
            mac_rx_att_get_rx_mpdu_done(&pb_buf->att), nid);
 | 
						|
    }
 | 
						|
 | 
						|
#endif //PHY_RX_DBG_EN
 | 
						|
 | 
						|
    /* TODO: mpdu_done valid only for first pb and nid */
 | 
						|
    if ((pb_buf->pb_ed.rx_pb_done == 1) && (
 | 
						|
        nid == glb_cfg.nid)) {
 | 
						|
        if (g_plc_dt_ctxt.indep.dut_flag == false && \
 | 
						|
            delimiter == FC_DELIM_BEACON) {
 | 
						|
#if IOT_DTEST_ONLY_SUPPORT == 0
 | 
						|
            if (g_phy_cpu_share_ctxt.pt_mode_entry) {
 | 
						|
#else
 | 
						|
            if (0) {
 | 
						|
#endif
 | 
						|
                mac_ntb_ppm_cali_start(pb_buf, PHY_PT_PPM_CAL_NTB);
 | 
						|
            } else {
 | 
						|
                /* ctrl beacon ppm cal cycle */
 | 
						|
                if (g_plc_dt_ctxt.indep.ppm_cal_start) {
 | 
						|
                    if ((RGF_MAC_READ_REG(CFG_RD_NTB_ADDR) - \
 | 
						|
                        g_plc_dt_ctxt.indep.ppm_save_ntb) >= PHY_DT_PPM_CAL_NTB) {
 | 
						|
                        mac_ntb_ppm_cali_start(pb_buf, PHY_DT_PPM_CAL_NTB);
 | 
						|
                        g_plc_dt_ctxt.indep.ppm_cal_start = false;
 | 
						|
                    }
 | 
						|
                } else {
 | 
						|
                    g_plc_dt_ctxt.indep.ppm_save_ntb = \
 | 
						|
                        RGF_MAC_READ_REG(CFG_RD_NTB_ADDR);
 | 
						|
                    mac_ntb_ppm_cali_start(pb_buf, PHY_DT_PPM_CAL_NTB);
 | 
						|
                    g_plc_dt_ctxt.indep.ppm_cal_start = true;
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
#else //PHY_PPM_CAL_SUPPORT == 1
 | 
						|
    if ((pb_buf->pb_ed.rx_pb_done == 1) && \
 | 
						|
        (nid == glb_cfg.nid)) {
 | 
						|
#endif //PHY_PPM_CAL_SUPPORT == 1
 | 
						|
        if((pb_buf->pb_ed.rx_pb_crc_err == 0) && \
 | 
						|
        (pb_buf->att.is_fcserr == 0))
 | 
						|
        {
 | 
						|
            if(1 == pb_buf->mpdu_ed.rx_buf_num)
 | 
						|
                g_plc_dt_ctxt.indep.fisrt_pb_crc_ok_cnt++;
 | 
						|
            else if(2 == pb_buf->mpdu_ed.rx_buf_num)
 | 
						|
                g_plc_dt_ctxt.indep.second_pb_crc_ok_cnt++;
 | 
						|
            else if(3 == pb_buf->mpdu_ed.rx_buf_num)
 | 
						|
                g_plc_dt_ctxt.indep.third_pb_crc_ok_cnt++;
 | 
						|
            else if(4 == pb_buf->mpdu_ed.rx_buf_num)
 | 
						|
                g_plc_dt_ctxt.indep.last_pb_crc_ok_cnt++;
 | 
						|
#if SUPPORT_SMART_GRID
 | 
						|
            if(PHY_PROTO_TYPE_GET() == PLC_PROTO_TYPE_SG)
 | 
						|
            {
 | 
						|
                switch(pb_buf->mpdu_st.fc.sg_fc.delimiter_type)
 | 
						|
                {
 | 
						|
                    case FC_DELIM_BEACON:
 | 
						|
                        g_plc_dt_ctxt.indep.tmi_beacon_cnt[pb_buf->mpdu_st.fc.sg_fc.vf.bcn.tmi]\
 | 
						|
                        [pb_buf->mpdu_ed.rx_buf_num-1] += 1;
 | 
						|
                        break;
 | 
						|
                    case FC_DELIM_SOF:
 | 
						|
                        g_plc_dt_ctxt.indep.tmi_sof_cnt[pb_buf->mpdu_st.fc.sg_fc.vf.sof.tmi_ext + \
 | 
						|
                        pb_buf->mpdu_st.fc.sg_fc.vf.sof.tmi]\
 | 
						|
                        [pb_buf->mpdu_ed.rx_buf_num-1] += 1;
 | 
						|
                        break;
 | 
						|
                    case FC_DELIM_SACK:
 | 
						|
                        g_plc_dt_ctxt.indep.tmi_sack_cnt[pb_buf->mpdu_ed.rx_buf_num-1] += 1;
 | 
						|
                        break;
 | 
						|
                    case FC_DELIM_NNCCO:
 | 
						|
                        g_plc_dt_ctxt.indep.tmi_nncco_cnt[pb_buf->mpdu_ed.rx_buf_num-1] += 1;
 | 
						|
                        break;
 | 
						|
                    default:
 | 
						|
                        break;
 | 
						|
                }
 | 
						|
            } else
 | 
						|
#endif
 | 
						|
#if SUPPORT_SOUTHERN_POWER_GRID
 | 
						|
            if(PHY_PROTO_TYPE_GET() == PLC_PROTO_TYPE_SPG)
 | 
						|
            {
 | 
						|
                switch(pb_buf->mpdu_st.fc.spg_fc.delimiter_type)
 | 
						|
                {
 | 
						|
                    case FC_DELIM_BEACON:
 | 
						|
                        g_plc_dt_ctxt.indep.tmi_beacon_cnt[pb_buf->mpdu_st.fc.spg_fc.vf.bcn.tmi]\
 | 
						|
                        [pb_buf->mpdu_ed.rx_buf_num-1] += 1;
 | 
						|
                        break;
 | 
						|
                    case FC_DELIM_SOF:
 | 
						|
                        g_plc_dt_ctxt.indep.tmi_sof_cnt[pb_buf->mpdu_st.fc.spg_fc.vf.sof.tmi_ext + \
 | 
						|
                        pb_buf->mpdu_st.fc.spg_fc.vf.sof.tmi]\
 | 
						|
                        [pb_buf->mpdu_ed.rx_buf_num-1] += 1;
 | 
						|
                        break;
 | 
						|
                    case FC_DELIM_SACK:
 | 
						|
                        g_plc_dt_ctxt.indep.tmi_sack_cnt[pb_buf->mpdu_ed.rx_buf_num-1] += 1;
 | 
						|
                        break;
 | 
						|
                    case FC_DELIM_NNCCO:
 | 
						|
                        g_plc_dt_ctxt.indep.tmi_nncco_cnt[pb_buf->mpdu_ed.rx_buf_num-1] += 1;
 | 
						|
                        break;
 | 
						|
                    default:
 | 
						|
                        break;
 | 
						|
                }
 | 
						|
            } else
 | 
						|
#endif
 | 
						|
#if SUPPORT_GREEN_PHY
 | 
						|
            if(PHY_PROTO_TYPE_GET() == PLC_PROTO_TYPE_GP)
 | 
						|
            {
 | 
						|
                switch(pb_buf->mpdu_st.fc.hpav_fc.delimiter_type)
 | 
						|
                {
 | 
						|
                    case FC_DELIM_BEACON:
 | 
						|
                        g_plc_dt_ctxt.indep.tmi_beacon_cnt[0][pb_buf->mpdu_ed.rx_buf_num-1] += 1;
 | 
						|
                        break;
 | 
						|
                    case FC_DELIM_SOF:
 | 
						|
                        g_plc_dt_ctxt.indep.tmi_sof_cnt[pb_buf->mpdu_st.fc.hpav_fc.vf_av.sof.tmi_av]\
 | 
						|
                        [pb_buf->mpdu_ed.rx_buf_num-1] += 1;
 | 
						|
                        break;
 | 
						|
                    case FC_DELIM_SACK:
 | 
						|
                        g_plc_dt_ctxt.indep.tmi_sack_cnt[pb_buf->mpdu_ed.rx_buf_num-1] += 1;
 | 
						|
                        break;
 | 
						|
                    case FC_DELIM_NNCCO:
 | 
						|
                        g_plc_dt_ctxt.indep.tmi_nncco_cnt[pb_buf->mpdu_ed.rx_buf_num-1] += 1;
 | 
						|
                        break;
 | 
						|
                    default:
 | 
						|
                        break;
 | 
						|
                }
 | 
						|
            }
 | 
						|
#endif
 | 
						|
            {
 | 
						|
                //do not del this case
 | 
						|
            }
 | 
						|
 | 
						|
            /* rate and band info */
 | 
						|
            if(pb_buf->att.rx_band_sel < MAX_HW_BAND && \
 | 
						|
                pb_buf->att.resv < MAC_BB_MAX_RATE){
 | 
						|
                g_plc_dt_ctxt.indep.band_cnt_rx[pb_buf->att.resv][pb_buf->att.rx_band_sel] += 1;
 | 
						|
            }
 | 
						|
            else{
 | 
						|
                IOT_ASSERT(0);
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        if (pb_buf->att.is_fcserr == 0) {
 | 
						|
            /* fresh gain by cco */
 | 
						|
#if PHY_RX_PKT_FILTER_CCO == 1
 | 
						|
            if(pb_buf->mpdu_st.fc.spg_fc.vf.bcn.src_tei == 1 || \
 | 
						|
                pb_buf->mpdu_st.fc.spg_fc.vf.sof.src_tei == 1 || \
 | 
						|
                pb_buf->mpdu_st.fc.sg_fc.vf.bcn.src_tei == 1 || \
 | 
						|
                pb_buf->mpdu_st.fc.sg_fc.vf.sof.src_tei == 1 || \
 | 
						|
                pb_buf->mpdu_st.fc.hpav_fc.vf_av.sof.src_tei == 1 || \
 | 
						|
                pb_buf->mpdu_st.fc.hpav_fc.vf_av.rtscts.src_tei == 1 || \
 | 
						|
                pb_buf->mpdu_st.fc.hpav_fc.vf_av.sound.stei == 1)
 | 
						|
#else
 | 
						|
            if(1)
 | 
						|
#endif
 | 
						|
            {
 | 
						|
                /*fix char print error*/
 | 
						|
                g_plc_dt_ctxt.indep.phy_info->gain = pb_buf->mpdu_st.phy.agc_tbl_entry;
 | 
						|
                g_plc_dt_ctxt.indep.phy_info->rmi = pb_buf->mpdu_st.phy.adc_power;
 | 
						|
                if(pb_buf->mpdu_st.phy.est_dc & 0x10){
 | 
						|
                    g_plc_dt_ctxt.indep.phy_info->est_dc = pb_buf->mpdu_st.phy.est_dc | 0xE0;
 | 
						|
                }
 | 
						|
                else{
 | 
						|
                    g_plc_dt_ctxt.indep.phy_info->est_dc = pb_buf->mpdu_st.phy.est_dc & 0x1F;
 | 
						|
                }
 | 
						|
                g_plc_dt_ctxt.indep.phy_info->est_ppm = pb_buf->mpdu_st.phy.est_ppm;
 | 
						|
 | 
						|
                /* snr cal */
 | 
						|
                snr = pb_buf->mpdu_st.phy.avg_snr; // raw_snr_from_phy
 | 
						|
                g_plc_dt_ctxt.indep.phy_info->avr_snr = snr;
 | 
						|
                pre_sym = pb_buf->mpdu_st.phy.pream_sym_detect;
 | 
						|
                max_spur_id = pb_buf->mpdu_st.phy.max_spur_id;
 | 
						|
            }
 | 
						|
#ifdef MAC_RX_TIME_STAMP_SUPPORT
 | 
						|
            /* pkt time stamp */
 | 
						|
            if(!pb_buf->mpdu_st.fc.spg_fc.delimiter_type)
 | 
						|
                time_stamp[pkt_idx++] = pb_buf->mpdu_ed.local_ts;
 | 
						|
#endif
 | 
						|
 | 
						|
            /* clr done sts */
 | 
						|
            pb_buf->att.rx_mpdu_done = 0;
 | 
						|
            pb_buf->pb_ed.rx_pb_done = 0;
 | 
						|
        }
 | 
						|
 | 
						|
        /* cal phy info counter */
 | 
						|
        phy_info_cnt_cal(g_plc_dt_ctxt.indep.phy_info);
 | 
						|
 | 
						|
        if(++rd_idx >= RX_BUF_NUM)
 | 
						|
            rd_idx = 0;
 | 
						|
        RX_RING_SET_RD_IDX(0, rd_idx);
 | 
						|
 | 
						|
        cur_time = RGF_MAC_READ_REG(CFG_RD_NTB_ADDR);
 | 
						|
        time_span = cur_time - enq_time;
 | 
						|
        if (time_span < 0) { // wrap around
 | 
						|
            time_span = (0x100000000LL) - enq_time + cur_time;
 | 
						|
        }
 | 
						|
        /*agc gain info*/
 | 
						|
        if((uint64_t)time_span > g_plc_dt_ctxt.indep.print_period_ms*TICKS_MS)
 | 
						|
        {
 | 
						|
            /* print phy info */
 | 
						|
            phy_info_cnt_print(g_plc_dt_ctxt.indep.phy_info);
 | 
						|
 | 
						|
            iot_printf("pre_num:%hd, maxspr:%hd\r\n",\
 | 
						|
                pre_sym, max_spur_id);
 | 
						|
            enq_time = cur_time;
 | 
						|
#ifdef MAC_RX_TIME_STAMP_SUPPORT
 | 
						|
            if(pkt_idx > 0){
 | 
						|
                for(uint32_t i= 0; i<pkt_idx; i++){
 | 
						|
                    iot_printf("[T]:raw-%-10d\r\n", time_stamp[i]);
 | 
						|
                }
 | 
						|
                pkt_idx = 0;
 | 
						|
            }
 | 
						|
#endif
 | 
						|
        }
 | 
						|
        return rx_buf_start;
 | 
						|
    }
 | 
						|
    else {
 | 
						|
        if (++rd_idx >= RX_BUF_NUM) {
 | 
						|
            rd_idx = 0;
 | 
						|
        }
 | 
						|
        RX_RING_SET_RD_IDX(0, rd_idx);
 | 
						|
 | 
						|
        return NULL;
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
/* mac rx pkt single */
 | 
						|
uint32_t mac_rx_single_mode(bool_t need_ack)
 | 
						|
{
 | 
						|
    uint8_t tmp = 0;
 | 
						|
    uint32_t start_time = 0, end_time = 0;
 | 
						|
    uint64_t time_span = 0;
 | 
						|
    rx_buf_hdr_t *pb_buf;
 | 
						|
    static uint32_t rx_ok_cnt = 0;
 | 
						|
    uint32_t crc32 = 0;
 | 
						|
    uint32_t crc32_cnt = 0;
 | 
						|
    uint32_t pb_size = 0;
 | 
						|
    uint16_t cpu1_shift_cnt = 0;
 | 
						|
#if IOT_DTEST_ONLY_SUPPORT == 0 || \
 | 
						|
    IOT_DTEST_LED_SUPPORT == 1
 | 
						|
    bool_t gpio_val = 0;
 | 
						|
#endif
 | 
						|
    uint32_t ret = ERR_FAIL;
 | 
						|
 | 
						|
    /* mac tx common init interface */
 | 
						|
    if(need_ack){
 | 
						|
        tx_common_init(IOT_PLC_PHY_BAND_DFT);
 | 
						|
    }
 | 
						|
 | 
						|
    /* add led init */
 | 
						|
#if IOT_DTEST_LED_SUPPORT == 1
 | 
						|
    gpio_mtx_enable();
 | 
						|
    apb_enable(APB_GPIO);
 | 
						|
    gpio_pin_select(32, 3);
 | 
						|
    gpio_pin_select(33, 3);
 | 
						|
#endif
 | 
						|
 | 
						|
    /* fix A phase */
 | 
						|
    phy_rx_phase_force_set(true, PLC_PHASE_A);
 | 
						|
 | 
						|
    /* check if rx ring has content */
 | 
						|
    uint8_t *rx_buf_tmp;
 | 
						|
    start_time = RGF_MAC_READ_REG(CFG_RD_NTB_ADDR);
 | 
						|
    do {
 | 
						|
#ifdef MAC_RX_FC_ERR_PRINT_PPM_SUPPORT
 | 
						|
       int32_t tmp1 = PHY_READ_REG(CFG_BB_FC_CRC_ERROR_CNTR_ADDR);
 | 
						|
       if(tmp1)
 | 
						|
       {
 | 
						|
            tmp1 = PHY_RX_FD_READ_REG(CFG_BB_FREQ_ERROR_ADDR);
 | 
						|
            tmp1 = REG_FIELD_GET(SW_FREQ_ERROR_PPM,tmp1);
 | 
						|
            if(tmp1 > 511){
 | 
						|
                tmp1 = tmp1 - 1024;
 | 
						|
            }
 | 
						|
            iot_printf("fc err, ppm=%d\r\n", tmp1);
 | 
						|
#ifdef MAC_RX_TIME_STAMP_SUPPORT
 | 
						|
            tmp1 = RGF_MAC_READ_REG(CFG_RD_NTB_ADDR);
 | 
						|
            iot_printf("fc err time stamp=%d\r\n", tmp1);
 | 
						|
#endif
 | 
						|
            PHY_WRITE_REG(CFG_BB_FC_PLD_CNTR_CLR_ADDR,0x2);
 | 
						|
        }
 | 
						|
#endif
 | 
						|
        while (!is_rx_ring0_empty())
 | 
						|
        {
 | 
						|
            rx_buf_tmp = pop_rx_buf_from_ring(0);
 | 
						|
            if (rx_buf_tmp) {
 | 
						|
                if(need_ack){
 | 
						|
                    /* tx back with phy info */
 | 
						|
                    uint8_t *pb_addr_ptr = \
 | 
						|
                        (uint8_t *)phy_get_pb_buf_ptr_from_mpdu(mpdu_start);
 | 
						|
                    *pb_addr_ptr++ = 'W';
 | 
						|
                    *pb_addr_ptr++ = 'U';
 | 
						|
                    *pb_addr_ptr++ = '-';
 | 
						|
                    *pb_addr_ptr++ = 'Q';
 | 
						|
                    *pb_addr_ptr++ = 'I';
 | 
						|
                    mac_tx_mpdu_test(NULL, mpdu_start);
 | 
						|
                    dt_mac_tx_hwq0_re_trig();
 | 
						|
                }
 | 
						|
 | 
						|
                pb_buf = (rx_buf_hdr_t *)rx_buf_tmp;
 | 
						|
                if(!pb_buf->pb_ed.rx_pb_crc_err)
 | 
						|
                {
 | 
						|
                    rx_ok_cnt++;
 | 
						|
                    /* led on */
 | 
						|
#if IOT_DTEST_LED_SUPPORT == 1
 | 
						|
                    gpio_val = !gpio_val;
 | 
						|
                    if(gpio_val) {
 | 
						|
                        gpio_pin_wpu(32,1);
 | 
						|
                        gpio_pin_wpd(32,0);
 | 
						|
                        gpio_pin_wpu(33,1);
 | 
						|
                        gpio_pin_wpd(33,0);
 | 
						|
                    } else {
 | 
						|
                        gpio_pin_wpu(32,0);
 | 
						|
                        gpio_pin_wpd(32,1);
 | 
						|
                        gpio_pin_wpu(33,0);
 | 
						|
                        gpio_pin_wpd(33,1);
 | 
						|
                    }
 | 
						|
#endif
 | 
						|
                }
 | 
						|
 | 
						|
                tmp = PHY_DFE_READ_REG(CFG_BB_SW_ADJUST_GAIN_ADDR);
 | 
						|
                if(REG_FIELD_GET(SW_RX_GAIN_LEFT_SHIFT, tmp) == 1 && \
 | 
						|
                    REG_FIELD_GET(SW_RX_GAIN_SHIFT_BITS, tmp) == 2) {
 | 
						|
                    cpu1_shift_cnt++;
 | 
						|
                }
 | 
						|
 | 
						|
                /* get fc delimiter */
 | 
						|
                uint32_t delimiter = mac_get_rx_delimiter_from_fc( \
 | 
						|
                    phy_proto_type_get(), \
 | 
						|
                    mac_rx_mpdu_st_get_fc_addr(&pb_buf->mpdu_st) \
 | 
						|
                    );
 | 
						|
 | 
						|
                /* init fc message */
 | 
						|
                rx_fc_msg_t rx_fc_msg = { 0 };
 | 
						|
                /* get info from fc */
 | 
						|
                mac_get_rx_frm_msg_from_fc( \
 | 
						|
                    phy_proto_type_get(), \
 | 
						|
                    mac_rx_mpdu_st_get_fc_addr(&pb_buf->mpdu_st), \
 | 
						|
                    &rx_fc_msg);
 | 
						|
 | 
						|
                /* TODO: support gp and bcn in the future */
 | 
						|
                if (delimiter == FC_DELIM_SOF) {
 | 
						|
                    /* pb crc check: first word for soft crc */
 | 
						|
                    ret = phy_get_pb_size( \
 | 
						|
                        glb_cfg.m_type, \
 | 
						|
                        rx_fc_msg.tmi, \
 | 
						|
                        rx_fc_msg.tmi_ext, \
 | 
						|
                        &pb_size);
 | 
						|
 | 
						|
                    /* check valid */
 | 
						|
                    if (ret != ERR_OK || !pb_size) {
 | 
						|
                        continue;
 | 
						|
                    }
 | 
						|
 | 
						|
                    /* use sw crc32 and bypass hw crc */
 | 
						|
                    crc32 = iot_getcrc32( \
 | 
						|
                        rx_buf_tmp + sizeof(rx_buf_hdr_t) + sizeof(uint32_t), \
 | 
						|
                         pb_size - (sizeof(uint32_t) << 1));
 | 
						|
                    if(crc32 != \
 | 
						|
                        *(uint32_t *)(rx_buf_tmp + sizeof(rx_buf_hdr_t))) {
 | 
						|
                        crc32_cnt++;
 | 
						|
#if PHY_DBG_EN
 | 
						|
                        iot_printf("[CRC]fail: crc:%x\n", \
 | 
						|
                            *(uint32_t *)(rx_buf_tmp + sizeof(rx_buf_hdr_t)));
 | 
						|
#endif
 | 
						|
                    }
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
        end_time = RGF_MAC_READ_REG(CFG_RD_NTB_ADDR);
 | 
						|
        time_span = end_time - start_time;
 | 
						|
        if (time_span < 0) { // wrap around
 | 
						|
            time_span = (0x100000000LL) - start_time + end_time;
 | 
						|
        }
 | 
						|
        if((uint64_t)time_span > g_plc_dt_ctxt.indep.print_period_ms*TICKS_MS) {
 | 
						|
            start_time = end_time;
 | 
						|
            mac_pkt_info_cnt_print();
 | 
						|
            /* nf cal */
 | 
						|
            tmp = PHY_RXTD_READ_REG(CFG_BB_AGC_NOISE_CAL_ADDR);
 | 
						|
            if(REG_FIELD_GET(SW_CAL_NOISE_DONE,tmp)) {
 | 
						|
                g_phy_ctxt.dep.nf = REG_FIELD_GET(SW_CAL_NOISE_PWR,tmp);
 | 
						|
            }
 | 
						|
            REG_FIELD_SET(SW_CAL_NOISE_START, tmp, 1);
 | 
						|
            PHY_RXTD_WRITE_REG(CFG_BB_AGC_NOISE_CAL_ADDR, tmp);
 | 
						|
            iot_printf("current nf:%d!\n", g_phy_ctxt.dep.nf);
 | 
						|
 | 
						|
            /* crc cnt */
 | 
						|
            iot_printf("check pb crc fail cnt:%d!\n", crc32_cnt);
 | 
						|
            crc32_cnt = 0;
 | 
						|
 | 
						|
            /* dbg cnt */
 | 
						|
#if IOT_DTEST_ONLY_SUPPORT == 0
 | 
						|
            iot_printf("[DBG]:192p:%d, 384p:%d, 768p:%d, 1536p:%d, " \
 | 
						|
                "3072p:%d, 6144p:%d, shift:%d\n", \
 | 
						|
                g_phy_cpu_share_ctxt.nf_192p, \
 | 
						|
                g_phy_cpu_share_ctxt.nf_384p, \
 | 
						|
                g_phy_cpu_share_ctxt.nf_768p, \
 | 
						|
                g_phy_cpu_share_ctxt.nf_1536p, \
 | 
						|
                g_phy_cpu_share_ctxt.nf_3072p, \
 | 
						|
                g_phy_cpu_share_ctxt.nf_6144p, \
 | 
						|
                cpu1_shift_cnt);
 | 
						|
#else
 | 
						|
            iot_printf("[DBG]:shift:%d\n", cpu1_shift_cnt);
 | 
						|
#endif
 | 
						|
            cpu1_shift_cnt = 0;
 | 
						|
        }
 | 
						|
 | 
						|
#if IOT_DTEST_ONLY_SUPPORT == 0
 | 
						|
        /* led fresh */
 | 
						|
        if(rx_ok_cnt > 0) {
 | 
						|
            gpio_val = !gpio_val;
 | 
						|
            iot_gpio_value_set(32, gpio_val);
 | 
						|
            iot_gpio_value_set(33, gpio_val);
 | 
						|
            rx_ok_cnt = 0;
 | 
						|
        }
 | 
						|
#endif
 | 
						|
    } while (true); /* keep check */
 | 
						|
 | 
						|
    return 0;
 | 
						|
}
 | 
						|
 | 
						|
void phy_gp_hybrid_mode_init()
 | 
						|
{
 | 
						|
    /* not support for kunlun1 */
 | 
						|
}
 | 
						|
 | 
						|
void phy_gp_burst_init()
 | 
						|
{
 | 
						|
    /* not support for kunlun1 */
 | 
						|
}
 | 
						|
 |