156 lines
		
	
	
		
			4.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			156 lines
		
	
	
		
			4.7 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 "mac_rf_pdev.h"
 | 
						|
#include "iot_errno.h"
 | 
						|
#include "iot_config.h"
 | 
						|
#if HW_PLATFORM == HW_PLATFORM_SIMU
 | 
						|
#include "simulator_txrx.h"
 | 
						|
#endif
 | 
						|
#include "mac_pdev.h"
 | 
						|
#include "mac_rf_rx_hw.h"
 | 
						|
#include "mac_rf_tx_hw.h"
 | 
						|
#include "plc_const.h"
 | 
						|
#include "mac_msg.h"
 | 
						|
#include "mac.h"
 | 
						|
#include "iot_io.h"
 | 
						|
#include "mac_rf_vdev.h"
 | 
						|
#include "iot_system.h"
 | 
						|
 | 
						|
#if HPLC_RF_DEV_SUPPORT
 | 
						|
#include "mac_rf_rx_buf_ring.h"
 | 
						|
 | 
						|
extern uint32_t g_fw_mode;
 | 
						|
static iot_mem_pool_t* g_mac_rf_pdev_pool;
 | 
						|
 | 
						|
void mac_set_rf_pdev_tx_comp(mac_rf_pdev_t *rf_pdev, \
 | 
						|
    mac_rf_tx_hw_comp_t tx_comp_cb)
 | 
						|
{
 | 
						|
    IOT_ASSERT(rf_pdev);
 | 
						|
    rf_pdev->tx_comp = tx_comp_cb;
 | 
						|
}
 | 
						|
 | 
						|
void mac_set_rf_pdev_rx_cb(mac_rf_pdev_t *rf_pdev, \
 | 
						|
    mac_rf_rx_t rx_cb)
 | 
						|
{
 | 
						|
    IOT_ASSERT(rf_pdev);
 | 
						|
    rf_pdev->rx = rx_cb;
 | 
						|
}
 | 
						|
 | 
						|
uint32_t mac_rf_pdev_init(pdevid_t pdev_id)
 | 
						|
{
 | 
						|
    mac_rf_pdev_t *rf_pdev = NULL;
 | 
						|
 | 
						|
    if (pdev_id >= MAX_PDEV_NUM) {
 | 
						|
        return ERR_INVAL;
 | 
						|
    }
 | 
						|
    mac_pdev_t *pdev = get_pdev_ptr(pdev_id);
 | 
						|
    if (!pdev) {
 | 
						|
        return ERR_INVAL;
 | 
						|
    }
 | 
						|
 | 
						|
    if(!pdev->mac_rf_pdev) {
 | 
						|
        /* create global pdev pool */
 | 
						|
        iot_mem_pool_new(PLC_MAC_RF_MID, MAX_RF_PDEV_NUM, \
 | 
						|
            sizeof(mac_rf_pdev_t), \
 | 
						|
            &g_mac_rf_pdev_pool, 0);
 | 
						|
    }
 | 
						|
 | 
						|
    if(!pdev->mac_rf_pdev) {
 | 
						|
        /* alloc a pdev */
 | 
						|
        rf_pdev = iot_mem_pool_alloc(g_mac_rf_pdev_pool);
 | 
						|
        rf_pdev->rf_pdev_id = RF_PDEV_ID;
 | 
						|
        rf_pdev->parent_pdev_id = pdev_id;
 | 
						|
 | 
						|
        /* init vdev pool in the pdev */
 | 
						|
        if (iot_mem_pool_init(PLC_MAC_RF_MID, MAX_RF_VDEV_NUM,
 | 
						|
            sizeof(mac_rf_vdev_t), &rf_pdev->rf_vdev_pool, 0) != 0) {
 | 
						|
            return ERR_NOMEM;
 | 
						|
        }
 | 
						|
        rf_pdev->cur_rf_vdev_num = 0;
 | 
						|
 | 
						|
        pdev->mac_rf_pdev = rf_pdev;
 | 
						|
    }
 | 
						|
    rf_pdev = pdev->mac_rf_pdev;
 | 
						|
 | 
						|
    /* register tx callback */
 | 
						|
    mac_set_rf_pdev_tx_comp(pdev->mac_rf_pdev, mac_rf_tx_hw_mpdu_comp);
 | 
						|
 | 
						|
    if (g_fw_mode != FTM_MODE) {
 | 
						|
        /* register rx callback */
 | 
						|
        mac_set_rf_pdev_rx_cb(pdev->mac_rf_pdev, mac_rf_rx_hw_mpdu);
 | 
						|
    } else {
 | 
						|
        /* register rx callback */
 | 
						|
        mac_set_rf_pdev_rx_cb(pdev->mac_rf_pdev, mac_rf_rx_hw_mpdu_internal);
 | 
						|
    }
 | 
						|
 | 
						|
#if HW_PLATFORM == HW_PLATFORM_SIMU
 | 
						|
    /* init simulator layer */
 | 
						|
    simulator_init_ex(&rf_pdev->simu, rf_pdev,
 | 
						|
        NULL, NULL, mac_rf_tx_hw_mpdu_comp,
 | 
						|
        NULL, NULL, mac_rf_rx_hw_mpdu, WORKMODE_RF);
 | 
						|
#else
 | 
						|
    /* init chip tx rx */
 | 
						|
    mac_rf_tx_hw_init(pdev->mac_rf_pdev);
 | 
						|
    mac_rf_rx_hw_init();
 | 
						|
#endif
 | 
						|
 | 
						|
    if (g_fw_mode != FTM_MODE) {
 | 
						|
        /* init hwq & ring for each pdev */
 | 
						|
        mac_rf_rx_ring_ctxt_init(&rf_pdev->ring_hdl);
 | 
						|
#if HW_PLATFORM == HW_PLATFORM_SIMU
 | 
						|
        simu_set_rx_ring_ptr(&rf_pdev->simu, &rf_pdev->ring_hdl.ring[0]);
 | 
						|
#endif
 | 
						|
 | 
						|
        mac_rf_q_init(&rf_pdev->hwq_hdl);
 | 
						|
 | 
						|
        /* BCN */
 | 
						|
        mac_rf_q_alloc_hwq(&rf_pdev->hwq_hdl,
 | 
						|
            mac_rf_q_get_swq_type(PLC_BCN_REGION_BCN, (lid_t)0, 0));
 | 
						|
 | 
						|
        /* CSMA */
 | 
						|
        mac_rf_q_alloc_hwq(&rf_pdev->hwq_hdl,
 | 
						|
            mac_rf_q_get_swq_type(PLC_BCN_REGION_CSMA, (lid_t)0, 0));
 | 
						|
#if !ENA_RF_ONLY_ONE_CSMA_HWQ
 | 
						|
        mac_rf_q_alloc_hwq(&rf_pdev->hwq_hdl,
 | 
						|
            mac_rf_q_get_swq_type(PLC_BCN_REGION_CSMA, (lid_t)1, 0));
 | 
						|
        mac_rf_q_alloc_hwq(&rf_pdev->hwq_hdl,
 | 
						|
            mac_rf_q_get_swq_type(PLC_BCN_REGION_CSMA, (lid_t)2, 0));
 | 
						|
        mac_rf_q_alloc_hwq(&rf_pdev->hwq_hdl,
 | 
						|
            mac_rf_q_get_swq_type(PLC_BCN_REGION_CSMA, (lid_t)3, 0));
 | 
						|
        mac_rf_q_alloc_hwq(&rf_pdev->hwq_hdl,
 | 
						|
            mac_rf_q_get_swq_type(PLC_BCN_REGION_CSMA, (lid_t)3, 1));
 | 
						|
#endif
 | 
						|
        /* BCSMA */
 | 
						|
        mac_rf_q_alloc_hwq(&rf_pdev->hwq_hdl,
 | 
						|
            mac_rf_q_get_swq_type(PLC_BCN_REGION_BCSMA, (lid_t)4, 0));
 | 
						|
    }
 | 
						|
 | 
						|
   return 0;
 | 
						|
}
 | 
						|
 | 
						|
mac_rf_pdev_t * IRAM_ATTR get_rf_pdev_ptr(uint32_t plc_pdev_id,
 | 
						|
    uint32_t rf_pdev_id)
 | 
						|
{
 | 
						|
    if (rf_pdev_id >= MAX_RF_PDEV_NUM) {
 | 
						|
        IOT_ASSERT(0);
 | 
						|
        return NULL;
 | 
						|
    }
 | 
						|
    mac_pdev_t *plc_pdev = get_pdev_ptr(plc_pdev_id);
 | 
						|
    return plc_pdev->mac_rf_pdev;
 | 
						|
}
 | 
						|
 | 
						|
#endif /* HPLC_RF_DEV_SUPPORT */
 |