#include "jesd_csu_lte_fdd.h"
#include "jesd_csu.h"
#include "phy_para.h"

int32_t jesd_csu_init_lte_fdd()
{
	jesd_csu_init(JESD_LTEFDD_ANT_NUM, JESD_LTEFDD_MARGIN, FDD_MODE);
	stJesdCsuNodePara txCsuNode[JESD_LTEFDD_TX_NODENUM];
	stJesdCsuNodePara rxCsuNode[JESD_LTEFDD_RX_NODENUM];
    //tx的链表地址
    uint32_t txListAddr = JESD_LTEFDD_TX_LIST_ADDR; // 0x8A000000
    //rx的链表地址
    uint32_t rxListAddr = JESD_LTEFDD_RX_LIST_ADDR; // 0x8A008000 
	int32_t i = 0;

	// tx/rx, subframe 0~9
	for (i = 0; i < JESD_LTEFDD_TX_NODENUM; i++)
	{
		if (0 == (i&0x1))
		{
			txCsuNode[i].dataAddr = JESD_LTEFDD_TX_SLOT_EVEN_DATA_ADDR;
			txCsuNode[i].yStep = (JESD_LTEFDD_SUBFRAME_SAM_CNT<<2);
			txCsuNode[i].allNum = (JESD_LTEFDD_SUBFRAME_SAM_CNT<<2)*JESD_LTEFDD_ANT_NUM;

			rxCsuNode[i].dataAddr = JESD_LTEFDD_RX_SLOT_EVEN_DATA_ADDR;
			rxCsuNode[i].yStep = (JESD_LTEFDD_SUBFRAME_SAM_CNT<<2);
			rxCsuNode[i].allNum = (JESD_LTEFDD_SUBFRAME_SAM_CNT<<2)*JESD_LTEFDD_ANT_NUM;
		}
		else if (1 == (i&0x1))
		{
			txCsuNode[i].dataAddr = JESD_LTEFDD_TX_SLOT_ODD_DATA_ADDR;
			txCsuNode[i].yStep = (JESD_LTEFDD_SUBFRAME_SAM_CNT<<2);
			txCsuNode[i].allNum = (JESD_LTEFDD_SUBFRAME_SAM_CNT<<2)*JESD_LTEFDD_ANT_NUM;

			rxCsuNode[i].dataAddr = JESD_LTEFDD_RX_SLOT_ODD_DATA_ADDR;
			rxCsuNode[i].yStep = (JESD_LTEFDD_SUBFRAME_SAM_CNT<<2);
			rxCsuNode[i].allNum = (JESD_LTEFDD_SUBFRAME_SAM_CNT<<2)*JESD_LTEFDD_ANT_NUM;
		}
	}
	
	jesd_csu_tx_cfg(txListAddr, JESD_LTEFDD_TX_NODENUM, txCsuNode, JESD_CSU_CH0, 0);	
	jesd_csu_rx_cfg(rxListAddr, JESD_LTEFDD_RX_NODENUM, rxCsuNode, JESD_CSU_CH0, 0);	
#if 0
	jesd_csu_tx_list_init(txListAddr, JESD_LTEFDD_TX_NODENUM, txCsuNode);
	jesd_csu_tx_dmaReg_Cfg(JESD_CSU_CH0, txListAddr, JESD_LTEFDD_TX_NODENUM);
	jesd_csu_rx_list_init(rxListAddr, JESD_LTEFDD_RX_NODENUM, rxCsuNode);
	jesd_csu_rx_dmaReg_Cfg(JESD_CSU_CH0, rxListAddr, JESD_LTEFDD_RX_NODENUM);
#endif
	return 0;
}

int32_t jesd_csu_init_lte_fdd_slot0()
{
	jesd_csu_init(JESD_LTEFDD_ANT_NUM, JESD_LTEFDD_MARGIN, FDD_MODE);
	stJesdCsuNodePara txCsuNode[JESD_LTEFDD_TX_NODENUM];
	stJesdCsuNodePara rxCsuNode[JESD_LTEFDD_RX_NODENUM];
    //tx的链表地址
    uint32_t txListAddr = JESD_LTEFDD_TX_LIST_ADDR; // 0x8A000000
    //rx的链表地址
    uint32_t rxListAddr = JESD_LTEFDD_RX_LIST_ADDR; // 0x8A008000 
	int32_t i = 0;

	// tx/rx, subframe 0~9
	for (i = 0; i < JESD_LTEFDD_TX_NODENUM; i++)
	{
		if (0 == (i&0x1))
		{
			txCsuNode[i].dataAddr = JESD_LTEFDD_TX_SLOT_EVEN_DATA_ADDR;
			txCsuNode[i].yStep = (JESD_LTEFDD_SUBFRAME_SAM_CNT<<2);
			txCsuNode[i].allNum = (JESD_LTEFDD_SUBFRAME_SAM_CNT<<2)*JESD_LTEFDD_ANT_NUM;

			rxCsuNode[i].dataAddr = JESD_LTEFDD_RX_SLOT_EVEN_DATA_ADDR;
			rxCsuNode[i].yStep = (JESD_LTEFDD_SUBFRAME_SAM_CNT<<2);
			rxCsuNode[i].allNum = (JESD_LTEFDD_SUBFRAME_SAM_CNT<<2)*JESD_LTEFDD_ANT_NUM;
		}
		else if (1 == (i&0x1))
		{
			txCsuNode[i].dataAddr = JESD_LTEFDD_TX_SLOT_ODD_DATA_ADDR;
			txCsuNode[i].yStep = (JESD_LTEFDD_SUBFRAME_SAM_CNT<<2);
			txCsuNode[i].allNum = (JESD_LTEFDD_SUBFRAME_SAM_CNT<<2)*JESD_LTEFDD_ANT_NUM;

			rxCsuNode[i].dataAddr = JESD_LTEFDD_RX_SLOT_ODD_DATA_ADDR;
			rxCsuNode[i].yStep = (JESD_LTEFDD_SUBFRAME_SAM_CNT<<2);
			rxCsuNode[i].allNum = (JESD_LTEFDD_SUBFRAME_SAM_CNT<<2)*JESD_LTEFDD_ANT_NUM;
		}
	}
	
	jesd_csu_tx_cfg(txListAddr, 1, txCsuNode, JESD_CSU_CH0, 0);	
	jesd_csu_rx_cfg(rxListAddr, 1, rxCsuNode, JESD_CSU_CH0, 0);	
#if 0
	jesd_csu_tx_list_init(txListAddr, JESD_LTEFDD_TX_NODENUM, txCsuNode);
	jesd_csu_tx_dmaReg_Cfg(JESD_CSU_CH0, txListAddr, JESD_LTEFDD_TX_NODENUM);
	jesd_csu_rx_list_init(rxListAddr, JESD_LTEFDD_RX_NODENUM, rxCsuNode);
	jesd_csu_rx_dmaReg_Cfg(JESD_CSU_CH0, rxListAddr, JESD_LTEFDD_RX_NODENUM);
#endif
	return 0;
}


#if 0
int32_t jesd_csu_start_lte()
{
	jesd_csu_start();

	return 0;
}
#endif

