Files
kunlun/dtest/mac_rx_test/hal/inc/hal_rx.h
2024-09-28 14:24:04 +08:00

304 lines
8.3 KiB
C
Executable File

/****************************************************************************
*
* 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 __HAL_PHY_H
#define __HAL_PHY_H
#include "phy_bb.h"
#include "phy_test_api.h"
#include "mac_rx_buf_ring.h"
#define RX_BUF_BYTE_SIZE (sizeof(rx_buf_hdr_t) + 520)
#define RX_BUF_DW_SIZE iot_ceil(RX_BUF_BYTE_SIZE, 4)
#define RX_BUF_NUM (5)
#define PHY_PT_PPM_CAL_NTB (5000000)
#define PHY_DT_PPM_CAL_NTB (100000000)
#define MAX_TMI_NUM (30)
#define MAX_PB_NUM (4)
#define PHY_RX_DBG_EN (0)
#define PHY_RX_ACK_DIS (0)
#define IOT_DTEST_LED_SUPPORT (0)
/* production line golden unit rx ppm calibration */
#define PHY_PPM_CAL_SUPPORT (1)
/* production line transmission success rate test counter */
#define PHY_PDL_RATE_RTY_CNT (100)
#define PHY_PDL_TX_MAGIC_NUM0 (0x55)
#define PHY_PDL_TX_MAGIC_NUM1 (0xaa)
#define RECEV_TX_SNR_THD_VALUE (110)
#define MIN_PPM_THD (-128)
#define MAX_PPM_THD (127)
#define PHY_RX_CRC_RATE_LED_ON (90)
#define PHY_RX_CRC_RATE_LED_OFF (0)
#pragma pack(push) /* save the pack status */
#pragma pack(1) /* 1 byte align */
/* global ctxt */
typedef struct _iot_plc_dt_plat_indep_ctxt {
/* dut flag */
uint8_t dut_flag;
/* rx buf list pointer */
uint8_t **rx_buf_ptr_list;
/* band statistics cnt */
uint16_t band_cnt_rx[MAC_BB_MAX_RATE][MAX_HW_BAND];
mac_rx_phy_info_t *phy_info;
/* print period unit: ms */
uint32_t print_period_ms;
uint8_t *rx_buf[RX_BUF_NUM];
#if IOT_DTEST_ONLY_SUPPORT == 0
uint32_t *tmi_beacon_cnt[MAX_TMI_NUM];
uint32_t *tmi_sof_cnt[MAX_TMI_NUM];
#else
uint32_t tmi_beacon_cnt[MAX_TMI_NUM][MAX_PB_NUM];
uint32_t tmi_sof_cnt[MAX_TMI_NUM][MAX_PB_NUM];
#ifdef MAC_RX_TIME_STAMP_SUPPORT
uint32_t time_stamp[20];
uint32_t pkt_idx;
#endif
mac_rx_phy_info_t phy_info_tmp;
#endif
/* sack cnt */
uint32_t tmi_sack_cnt[MAX_PB_NUM];
/* nncco cnt */
uint32_t tmi_nncco_cnt[MAX_PB_NUM];
/* first pb cnt */
uint32_t fisrt_pb_crc_ok_cnt;
/* second pb cnt */
uint32_t second_pb_crc_ok_cnt;
/* third pb cnt */
uint32_t third_pb_crc_ok_cnt;
/* last pb cnt */
uint32_t last_pb_crc_ok_cnt;
/* last tx local timestamp */
uint32_t tx_ts_last;
/* current tx local timestamp */
uint32_t tx_ts_cur;
/* last rx local timestamp */
uint32_t rx_ts_last;
/* current rx local timestamp */
uint32_t rx_ts_cur;
/* last rx NTB timestamp */
uint32_t rx_ntb_ts_last;
/* current rx NTB timestamp */
uint32_t rx_ntb_ts_cur;
/* ppm calibration start */
bool_t ppm_cal_start;
/* last save ntb */
uint32_t ppm_save_ntb;
} iot_plc_dt_plat_indep_ctxt_t;
typedef struct _iot_mac_sts_info {
uint32_t mac_rx_ring0_dbg_cnt;
uint32_t mac_rx_fc_dbg_cnt;
uint32_t mac_rx_pkt_det_cnt;
} iot_mac_sts_info_t;
/* phy total ctxt entry */
typedef struct _plc_dt_ctxt {
//iot_plc_dt_plat_dep_ctxt_t dep;
iot_plc_dt_plat_indep_ctxt_t indep;
} plc_dt_ctxt_t;
extern plc_dt_ctxt_t g_plc_dt_ctxt;
typedef struct _rx_ring_cfg {
uint32_t ring_sz;
uint32_t buffer_byte_len;
uint32_t low_watermark;
uint32_t rx_desc_enable;
uint32_t rx_desc_offset;
uint32_t payload_enable;
uint32_t payload_offset;
//uint32_t is_pb_hdr_in_payload; /* global ? */
} rx_ring_cfg_t;
typedef struct _phy_plt_case_info {
uint16_t magic_num0 :8,
magic_num1 :8;
uint32_t case_id :8,
tmi :5,
pkt_type :3,
pkt_cnt :16;
uint8_t pwr_set;
uint8_t phase_num;
} phy_plt_case_info_t;
#pragma pack(pop) /* restore the pack status */
/**
*@brief dut_flag_set.
*
* set dut_flag status.
*
*@param none [flag_status.]
*@exception [none.]
*@return [none.]
*/
void dut_flag_set(bool_t flag_status);
/**
*@brief phy_info_ptr_get.
*
* get phy_info pointer.
*
*@param none [none.]
*@exception [none.]
*@return [phy_info pointer.]
*/
mac_rx_phy_info_t *phy_info_ptr_get();
/**
*@brief mac_tmi_cnt_clr.
* clear tmi print counter.
*
*@param need_ack [none.]
*@exception [none.]
*@return [none.]
*/
void mac_tmi_cnt_clr();
/**
*@brief mac_pkt_info_cnt_print.
* print packets detail info and counter.
*
*@param need_ack [none.]
*@exception [none.]
*@return [none.]
*/
void mac_pkt_info_cnt_print();
/**
*@brief phy_granite_loopback.
* This api is for phy reset, mac rx init and rx loopback
*
*@param band_idx [band index.]
*@exception [none.]
*@return [none.]
*/
void phy_granite_loopback(uint32_t band_idx);
/**
*@brief mac_sts_get.
* get rx pacekt statistics.
*
*@param mac_sts [mac rx statistics pointer.]
*@exception [none.]
*@return [0 for success and other fail.]
*/
void mac_sts_get(iot_mac_sts_info_t *mac_sts);
/**
*@brief rx_ring_enable.
* enable ring buffer for rx deriction.
*
*@param ring_id [ring buffer index.]
*@param enable [bool type, true or false.]
*@exception [none.]
*@return [none.]
*/
void rx_ring_enable(uint32_t ring_id, uint32_t enable);
/**
*@brief rx_ring_setup_hw.
* initialize hw parameters with rx ring buffer.
*
*@param ring_id [ring buffer index.]
*@param cfg [hw parameters such as size, len, watermark.]
* [rx enable, rx offset, pld enable, pld offset.]
*@exception [none.]
*@return [none.]
*/
void rx_ring_setup_hw(uint32_t ring_id, rx_ring_cfg_t *cfg);
/**
*@brief mac_rx_single_mode.
* pass true in parameter if need ack packet.
*
*@param need_ack [bool type with true of false.]
*@exception [none.]
*@return [ERR_OK, others ERR_FAIL.]
*/
uint32_t mac_rx_single_mode(bool_t need_ack);
/**
*@brief is_rx_ring0_empty.
* check rx ring buffer is empty or not.
*
*@param none [none.]
*@exception [none.]
*@return [ERR_OK, others ERR_FAIL.]
*/
uint32_t is_rx_ring0_empty();
/**
*@brief mac_rx_init.
* mac rx initialize from phy dtest scenario.
*
*@param band_id [band index.]
*@exception [none.]
*@return [ERR_OK, others ERR_FAIL.]
*/
uint32_t mac_rx_init(uint32_t band_id);
/**
*@brief rx_common_init.
* The common API function is designed for external calling by MP
* or the other compositive scenario.
*
*@param band_idx [band index.]
*@exception [none.]
*@return [none.]
*/
void rx_common_init(uint32_t band_idx);
/**
*@brief pop_rx_buf_from_ring.
* Analyze a packet that come from mac ring buffer and print used info.
*
*@param ring_id [ring buffer id]
*@exception [none.]
*@return [none.]
*/
uint8_t *pop_rx_buf_from_ring(uint32_t ring_id);
/**
*@brief rx_recev_packet.
* This api is for receving packet
*
*@param none [none.]
*@exception [none.]
*@return [0: timeout, 1: rx buffer info.]
*/
uint8_t *rx_recev_packet();
/**
*@brief mac_ntb_ppm_cali_start.
* ppm calibration entry
*
*@param pb_buf [none.]
*@param ppm_cnt [none.]
*@exception [none.]
*@return [ERR_OK, others ERR_FAIL.]
*/
uint32_t mac_ntb_ppm_cali_start(rx_buf_hdr_t *pb_buf, uint32_t ppm_cnt);
#endif