308 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			308 lines
		
	
	
		
			10 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. | ||
|  | 
 | ||
|  | ****************************************************************************/ | ||
|  | #include "rf_tx_test_lib.h"
 | ||
|  | #include "mac_sys_reg.h"
 | ||
|  | #include "hw_reg_api.h"
 | ||
|  | #include "mac_tx_hw.h"
 | ||
|  | #include "iot_errno.h"
 | ||
|  | #include "iot_io.h"
 | ||
|  | #include "mac_pdev.h"
 | ||
|  | #include "iot_bitops.h"
 | ||
|  | #include "hw_phy_init.h"
 | ||
|  | #include "hw_tonemap.h"
 | ||
|  | #include "phy_chn.h"
 | ||
|  | #include "mac_crc.h"
 | ||
|  | #include "mpdu_header.h"
 | ||
|  | #include "mac_desc_engine.h"
 | ||
|  | #include "mac_rx_hw.h"
 | ||
|  | #include "mac_cert_test.h"
 | ||
|  | #include "tx_desc_reg_api.h"
 | ||
|  | #include "tx_test_lib.h"
 | ||
|  | #include "rf_hw_tonemap.h"
 | ||
|  | #include "phy_rf_chn.h"
 | ||
|  | #include "mac_rf_tx_hw.h"
 | ||
|  | 
 | ||
|  | #if ((HW_PLATFORM >= HW_PLATFORM_FPGA) && (IOT_FTM_SUPPORT || \
 | ||
|  |     CPLC_IOT_CERT_SUPPORT) && HPLC_RF_DEV_SUPPORT) | ||
|  | 
 | ||
|  | #include "mac_rf_sched_hw.h"
 | ||
|  | #include "mac_rf_common_hw.h"
 | ||
|  | 
 | ||
|  | uint32_t mac_rf_sche_set_cfg(void *vdev, hw_sched_cmd_t *cmdlist, | ||
|  |     uint16_t cmd_num, uint32_t bcn_pd, uint32_t start_ntb) | ||
|  | { | ||
|  |     (void)vdev; | ||
|  |     mac_rf_sched_enable_bp(NULL, 0); | ||
|  |     //mac_rf_sched_set_bp_ahead_alert(NULL, 10);
 | ||
|  |     /*set cmd list and cmd num*/ | ||
|  |     mac_rf_sched_set_bp_cmd_list(NULL, cmdlist, cmd_num); | ||
|  |     /*set bcn period*/ | ||
|  |     mac_rf_sched_set_bp_dur(NULL, bcn_pd); | ||
|  |     mac_rf_sched_set_bp_start_ntb(NULL, start_ntb); | ||
|  |     /*trig*/ | ||
|  |     mac_rf_sched_trigger_bp(NULL); | ||
|  | 
 | ||
|  |     mac_rf_sched_enable_bp(NULL, 1); | ||
|  | 
 | ||
|  |     return 0; | ||
|  | } | ||
|  | 
 | ||
|  | void rf_mpdu_tx_beacon_test(uint32_t proto, mac_rf_queue_ctxt_t *tx_ctxt, | ||
|  |     rf_tx_mpdu_end *mpdu_end, uint8_t qid, uint8_t bcast, | ||
|  |     uint8_t delimiter_type, uint32_t nid, uint32_t dtei, uint32_t stei, | ||
|  |     uint8_t phr_mcs, uint8_t pld_mcs, uint8_t pld_idx, uint8_t pb_num, | ||
|  |     uint16_t pkt_len, uint8_t *pkt) | ||
|  | { | ||
|  |     rf_tx_mpdu_start *rf_mpdu; | ||
|  |     rf_tx_pb_start *pb; | ||
|  |     rf_tx_dummy_node *dummy; | ||
|  |     uint32_t pb_sz; | ||
|  |     uint8_t pb_hdr_resv_crc_len; | ||
|  |     uint32_t swq_id = qid; | ||
|  |     uint32_t option = mac_rf_get_option(); | ||
|  |     uint32_t tx_fl = 20 * 25000;  // 20ms
 | ||
|  | 
 | ||
|  |     mac_desc_get(&g_mac_desc_eng,PLC_TX_MPDU_START_POOL, (void**)&rf_mpdu); | ||
|  |     mac_desc_get(&g_mac_desc_eng,PLC_TX_DUMMY_NODE_POOL, (void**)&dummy); | ||
|  |     mac_desc_get(&g_mac_desc_eng,PLC_TX_PB_START_POOL, (void**)&pb); | ||
|  |     IOT_ASSERT(rf_mpdu && pb && dummy); | ||
|  |     dummy->desc_type = DESC_TYPE_TX_DUMMY; | ||
|  |     dummy->notify_hw_tx_done = 1; | ||
|  |     dummy->tx_done = 1; | ||
|  |     dummy->next = NULL; | ||
|  | 
 | ||
|  |     pb_sz = phy_rf_get_pbsz(pld_idx); | ||
|  | 
 | ||
|  |     /* get pb header + crc length */ | ||
|  |     pb_hdr_resv_crc_len = mac_get_pb_hdr_resv_crc_len(delimiter_type, proto); | ||
|  | 
 | ||
|  |     iot_pkt_t *test_data = ftm_fill_mac_data(delimiter_type, | ||
|  |         (pb_sz - pb_hdr_resv_crc_len), pkt, pkt_len); | ||
|  | 
 | ||
|  |     /* fill rf mac info */ | ||
|  |     mac_rf_tx_mpdu_fill_macinfo(rf_mpdu, (rf_tx_mpdu_start *)dummy, pb, | ||
|  |         mpdu_end, proto, 0, 0, 0, 0, 0, 0, 0, | ||
|  |         (uint32_t)iot_pkt_data(test_data)-(uint32_t)test_data, 1, 1, phr_mcs, | ||
|  |         0, 0, pld_mcs, pld_idx, 0, 0, swq_id, option, pb_num, tx_fl); | ||
|  | 
 | ||
|  |     /* fill phyinfo */ | ||
|  |     mac_rf_tx_mpdu_fill_phyinfo(rf_mpdu, 0); | ||
|  | 
 | ||
|  |     /* fill fc */ | ||
|  |     mac_rf_tx_mpdu_fill_phrinfo(rf_mpdu, proto, delimiter_type, 0, nid, 0, stei, | ||
|  |         dtei, pld_mcs, 0, (uint16_t)pld_idx, 0, 0, 1); | ||
|  | 
 | ||
|  |     iot_printf("rf beacon proto = %d, hwq = %d, phr_mcs = %d, pld_mcs = %d, " | ||
|  |         "pld_idx:%d, pb_num = %d\n", proto, qid, phr_mcs, pld_mcs, | ||
|  |         pld_idx, pb_num); | ||
|  | 
 | ||
|  |     /* send */ | ||
|  |     mac_rf_tx_hw_mpdu(tx_ctxt, qid, rf_mpdu); | ||
|  | } | ||
|  | 
 | ||
|  | void rf_mpdu_tx_sof_test(uint32_t proto, mac_rf_queue_ctxt_t *tx_ctxt, | ||
|  |     rf_tx_mpdu_end *mpdu_end, uint8_t qid, uint8_t bcast, | ||
|  |     uint8_t delimiter_type,uint32_t nid, uint32_t dtei, uint32_t stei, | ||
|  |     uint8_t phr_mcs, uint8_t pld_mcs, uint8_t pld_idx, uint8_t pb_num, | ||
|  |     uint8_t need_ack, uint16_t pkt_len, uint8_t *pkt) | ||
|  | { | ||
|  |     rf_tx_mpdu_start *rf_mpdu; | ||
|  |     rf_tx_pb_start *pb; | ||
|  |     rf_tx_dummy_node *dummy; | ||
|  |     uint32_t pb_sz; | ||
|  |     uint32_t bitmap; | ||
|  |     uint32_t swq_id = qid; | ||
|  |     uint32_t option = mac_rf_get_option(); | ||
|  |     uint32_t tx_fl = 20 * 25000;  // 20ms
 | ||
|  | 
 | ||
|  |     pb_sz = phy_rf_get_pbsz(pld_idx); | ||
|  | 
 | ||
|  |     /* get header + crc length */ | ||
|  |     uint8_t pb_hdr_resv_crc_len = | ||
|  |         mac_get_pb_hdr_resv_crc_len(delimiter_type, proto); | ||
|  | 
 | ||
|  |     iot_pkt_t *test_data = ftm_fill_mac_data(delimiter_type, | ||
|  |         ((pb_sz - pb_hdr_resv_crc_len) * pb_num), pkt, pkt_len); | ||
|  | 
 | ||
|  |     bitmap = 0xffffffff >> (32 - pb_num); | ||
|  | 
 | ||
|  |     mac_desc_get(&g_mac_desc_eng, PLC_TX_MPDU_START_POOL, (void**)&rf_mpdu); | ||
|  |     mac_desc_get(&g_mac_desc_eng,PLC_TX_DUMMY_NODE_POOL, (void**)&dummy); | ||
|  |     IOT_ASSERT(rf_mpdu && dummy); | ||
|  |     dummy->desc_type = DESC_TYPE_TX_DUMMY; | ||
|  |     dummy->notify_hw_tx_done = 1; | ||
|  |     dummy->tx_done = 1; | ||
|  |     dummy->next = NULL; | ||
|  | 
 | ||
|  |     mac_rf_tx_mpdu_form_pb(&pb, test_data, bitmap, pb_sz); | ||
|  | 
 | ||
|  |     /* fill rf mac info */ | ||
|  |     mac_rf_tx_mpdu_fill_macinfo(rf_mpdu, (rf_tx_mpdu_start *)dummy, pb, | ||
|  |         mpdu_end, proto, need_ack, 0, 0, 0, 0, 0, 0, | ||
|  |         (uint32_t)iot_pkt_data(test_data)-(uint32_t)test_data, 1, 1, phr_mcs, | ||
|  |         0, 0, pld_mcs, pld_idx, 0, 0, swq_id, option, pb_num, tx_fl); | ||
|  | 
 | ||
|  |     /* fill phyinfo */ | ||
|  |     mac_rf_tx_mpdu_fill_phyinfo(rf_mpdu, 0); | ||
|  | 
 | ||
|  |     /* fill fc */ | ||
|  |     mac_rf_tx_mpdu_fill_phrinfo(rf_mpdu, proto, delimiter_type, 0, nid, 0, stei, | ||
|  |         dtei, pld_mcs, 0, (uint16_t)pld_idx, 0, 0, 1); | ||
|  | 
 | ||
|  |     iot_printf("rf sof proto = %d, hwq = %d, phr_mcs = %d, pld_mcs = %d, " | ||
|  |         "pld_idx:%d, pb_num = %d\n", proto, qid, phr_mcs, pld_mcs, | ||
|  |         pld_idx, pb_num); | ||
|  | 
 | ||
|  |     /* send */ | ||
|  |     mac_rf_tx_hw_mpdu(tx_ctxt, qid, rf_mpdu); | ||
|  | } | ||
|  | 
 | ||
|  | uint32_t mac_rf_tx_mpdu_fill_ack_fcinfo(rf_tx_mpdu_start *mpdu_start, | ||
|  |     uint32_t proto, uint32_t delimter, uint32_t network, uint32_t nid, | ||
|  |     uint32_t rx_result, uint32_t stei, uint32_t dtei, uint32_t snr, | ||
|  |     uint32_t load, uint32_t ext_deli) | ||
|  | { | ||
|  |     IOT_ASSERT(mpdu_start); | ||
|  |     frame_control_t *fc =  (frame_control_t *)&mpdu_start->phr0; | ||
|  |     fc->delimiter_type = delimter; | ||
|  |     fc->network_type = network; | ||
|  |     fc->nid = nid; | ||
|  |     fc->vf.rf_sack.rx_result = rx_result; | ||
|  |     fc->vf.rf_sack.stei = stei; | ||
|  |     fc->vf.rf_sack.dtei = dtei; | ||
|  |     fc->vf.rf_sack.snr = snr; | ||
|  |     fc->vf.rf_sack.load = load; | ||
|  |     fc->vf.rf_sack.ext_deli = ext_deli; | ||
|  |     fc->vf.rf_sack.version = 0; | ||
|  |     return 0; | ||
|  | } | ||
|  | 
 | ||
|  | void rf_mpdu_tx_ack_test(uint32_t proto, mac_rf_queue_ctxt_t *tx_ctxt, | ||
|  |     rf_tx_mpdu_end *mpdu_end, uint8_t qid, uint8_t delimiter_type, | ||
|  |     uint32_t nid, uint32_t phr_mcs, uint32_t rx_result, uint32_t stei, | ||
|  |     uint32_t dtei, uint32_t snr, uint32_t load, uint32_t ext_deli) | ||
|  | { | ||
|  |     rf_tx_mpdu_start *rf_mpdu; | ||
|  |     rf_tx_dummy_node *dummy; | ||
|  |     uint32_t swq_id = qid; | ||
|  |     uint32_t option = mac_rf_get_option(); | ||
|  |     uint32_t tx_fl = 20 * 25000;  // 20ms
 | ||
|  |     mac_desc_get(&g_mac_desc_eng,PLC_TX_MPDU_START_POOL, (void**)&rf_mpdu); | ||
|  |     mac_desc_get(&g_mac_desc_eng,PLC_TX_DUMMY_NODE_POOL, (void**)&dummy); | ||
|  |     IOT_ASSERT(rf_mpdu && dummy); | ||
|  |     dummy->desc_type = DESC_TYPE_TX_DUMMY; | ||
|  |     dummy->notify_hw_tx_done = 1; | ||
|  |     dummy->tx_done = 1; | ||
|  |     dummy->next = NULL; | ||
|  | 
 | ||
|  |     /* fill rf mac info */ | ||
|  |     mac_rf_tx_mpdu_fill_macinfo(rf_mpdu, (rf_tx_mpdu_start *)dummy, | ||
|  |         NULL, mpdu_end, proto, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, phr_mcs, 0, 0, | ||
|  |         0, 0, 0, 0, swq_id, option, 0, tx_fl); | ||
|  | 
 | ||
|  |     /* fill phyinfo */ | ||
|  |     mac_rf_tx_mpdu_fill_phyinfo(rf_mpdu, 0); | ||
|  | 
 | ||
|  |     mac_rf_tx_mpdu_fill_ack_fcinfo(rf_mpdu, proto, delimiter_type, 0, | ||
|  |         nid, rx_result, stei, dtei, snr, load, ext_deli); | ||
|  | 
 | ||
|  |     iot_printf("rf sack proto = %d, hwq = %d, phr_mcs = %d\n", | ||
|  |         proto, qid, phr_mcs); | ||
|  | 
 | ||
|  |     /* send */ | ||
|  |     mac_rf_tx_hw_mpdu(tx_ctxt, qid, rf_mpdu); | ||
|  | } | ||
|  | 
 | ||
|  | void rf_mpdu_send_test(mac_rf_queue_ctxt_t *tx_ctxt, uint8_t qid, | ||
|  |     uint8_t bcast, uint8_t delimiter_type,uint32_t nid, uint32_t dtei, | ||
|  |     uint32_t stei,uint8_t phr_mcs, uint8_t pld_mcs, uint8_t pld_idx, | ||
|  |     uint8_t pb_num, uint8_t need_ack, uint32_t rx_result, uint32_t snr, | ||
|  |     uint32_t load, uint32_t ext_deli, uint16_t pkt_len, uint8_t *pkt) | ||
|  | { | ||
|  |     rf_tx_mpdu_end *end; | ||
|  |     /* mac protocol */ | ||
|  |     uint32_t proto = PHY_PROTO_TYPE_GET(); | ||
|  | 
 | ||
|  |     mac_desc_get(&g_mac_desc_eng, PLC_TX_MPDU_END_POOL, (void**)&end); | ||
|  |     IOT_ASSERT(end); | ||
|  |     end->tx_done = 0; | ||
|  |     end->tx_ok = 0; | ||
|  | 
 | ||
|  |     switch(delimiter_type){ | ||
|  |     case FC_DELIM_BEACON: | ||
|  |     { | ||
|  |         rf_mpdu_tx_beacon_test(proto, tx_ctxt, end, qid, bcast, FC_DELIM_BEACON, | ||
|  |             nid, dtei, stei, phr_mcs, pld_mcs, pld_idx, pb_num, pkt_len, pkt); | ||
|  |         break; | ||
|  |     } | ||
|  |     case FC_DELIM_SOF: | ||
|  |     { | ||
|  |         rf_mpdu_tx_sof_test(proto, tx_ctxt, end, qid, bcast, FC_DELIM_SOF, nid, | ||
|  |             dtei, stei, phr_mcs, pld_mcs, pld_idx, pb_num, need_ack, | ||
|  |             pkt_len, pkt); | ||
|  |         break; | ||
|  |     } | ||
|  |     case FC_DELIM_SACK: | ||
|  |     { | ||
|  |         rf_mpdu_tx_ack_test(proto, tx_ctxt, end, qid, FC_DELIM_SACK, nid, | ||
|  |             phr_mcs, rx_result, stei, dtei, snr, load, ext_deli); | ||
|  |         break; | ||
|  |     } | ||
|  |     default: | ||
|  |         IOT_ASSERT(0); | ||
|  |     } | ||
|  | } | ||
|  | 
 | ||
|  | #else
 | ||
|  | 
 | ||
|  | uint32_t mac_rf_sche_set_cfg(void *vdev, hw_sched_cmd_t *cmdlist, | ||
|  |     uint16_t cmd_num, uint32_t bcn_pd, uint32_t start_ntb) | ||
|  | { | ||
|  |     (void)vdev; | ||
|  |     (void)cmdlist; | ||
|  |     (void)cmd_num; | ||
|  |     (void)bcn_pd; | ||
|  |     (void)start_ntb; | ||
|  |     return 0; | ||
|  | } | ||
|  | 
 | ||
|  | void rf_mpdu_send_test(mac_rf_queue_ctxt_t *tx_ctxt, uint8_t qid, | ||
|  |     uint8_t bcast, uint8_t delimiter_type,uint32_t nid, uint32_t dtei, | ||
|  |     uint32_t stei,uint8_t phr_mcs, uint8_t pld_mcs, uint8_t pld_idx, | ||
|  |     uint8_t pb_num, uint8_t need_ack, uint32_t rx_result, uint32_t snr, | ||
|  |     uint32_t load, uint32_t ext_deli, uint16_t pkt_len, uint8_t *pkt) | ||
|  | { | ||
|  |     (void)tx_ctxt; | ||
|  |     (void)qid; | ||
|  |     (void)bcast; | ||
|  |     (void)delimiter_type; | ||
|  |     (void)nid; | ||
|  |     (void)dtei; | ||
|  |     (void)stei; | ||
|  |     (void)phr_mcs; | ||
|  |     (void)pld_mcs; | ||
|  |     (void)pld_idx; | ||
|  |     (void)pb_num; | ||
|  |     (void)need_ack; | ||
|  |     (void)rx_result; | ||
|  |     (void)snr; | ||
|  |     (void)load; | ||
|  |     (void)ext_deli; | ||
|  |     (void)pkt_len; | ||
|  |     (void)pkt; | ||
|  | } | ||
|  | 
 | ||
|  | #endif
 |