特权同学

【再说FPGA】TSE的loopback功能设置和调试

0
阅读(33519)

TSEloopback功能设置和调试

所谓loopback,便是TSE的收发形成一个闭环,通常是在初步调试验证MAC的基本功能时使用。TSE的这个loopback功能的开启可有两道“门槛”,一个不能少,不仅软件编程开启,而且硬件也有“玄机”,一不留意恐怕你死活也搞不定它。尤其是当原型调试时,你还真搞不懂是loopback没配置好还是MAC的收发不工作。

废话不多说,直接上图。首先在配置TSEIP组件时,需要勾选MAC Options页面的Enable local loopback on MII/GMII/RGMII选项,默认可是不勾选的,所以需要特别开启。在Small MAC模式下,没有loopback功能,所以无从设置。

User guide中对此有专门说明。

其次,在软件编程时,使能Config寄存器的bit15,使LOOP_ENA功能被开启。

具体编程操作时,可以参考如下顺序进行操作。

初始化的代码如下。

//Ethernet初始化

void ethernet_init(void)

{

alt_u32 temp;

//MDIO phy地址设置= 5‘b10000(参考88E1111_datasheet page63

IOWR_ALTERA_TSEMAC_MDIO_ADDR0(MY_TSE_BASE,0x11);

IOWR_ALTERA_TSEMAC_MDIO_ADDR1(MY_TSE_BASE,0x11);

//MAC配置寄存器初始化

//关闭MAC数据流接收和发送使能位

do {

IOWR_ALTERA_TSEMAC_CMD_CONFIG(MY_TSE_BASE,0x00802220);

temp = IORD_ALTERA_TSEMAC_CMD_CONFIG(MY_TSE_BASE);

} while(temp != 0x00800220);

//MAC FIFO配置

/*Tx_section_empty = Max FIFO size - 16

Tx_almost_full = 3

Tx_almost_empty = 8

Rx_section_empty = Max FIFO size - 16

Rx_almost_full = 8

Rx_almost_empty = 8

//Cut Throught Mode, Set this Threshold to 0 to enable Store and Forward Mode

Tx_section_full = 16

//Cut Throught Mode, Set this Threshold to 0 to enable Store and ForwardMode

Rx_section_full = 16*/

IOWR_ALTERA_TSEMAC_TX_SECTION_EMPTY(MY_TSE_BASE,(MY_TSE_TRANSMIT_FIFO_DEPTH-16));

IOWR_ALTERA_TSEMAC_TX_ALMOST_FULL(MY_TSE_BASE,3);

IOWR_ALTERA_TSEMAC_TX_ALMOST_EMPTY(MY_TSE_BASE,8);

IOWR_ALTERA_TSEMAC_RX_SECTION_EMPTY(MY_TSE_BASE,(MY_TSE_RECEIVE_FIFO_DEPTH-16));

IOWR_ALTERA_TSEMAC_RX_ALMOST_FULL(MY_TSE_BASE,8);

IOWR_ALTERA_TSEMAC_RX_ALMOST_EMPTY(MY_TSE_BASE,8);

IOWR_ALTERA_TSEMAC_TX_SECTION_FULL(MY_TSE_BASE,0);

IOWR_ALTERA_TSEMAC_RX_SECTION_FULL(MY_TSE_BASE,0);

//MAC地址配置

//MAC address is 00-1C-23-17-4A-CB

/* Low word (bits 31:0) of MAC address */

IOWR_ALTERA_TSEMAC_MAC_0(MY_TSE_BASE,0x17231c00);

/* High half-word (bits 47:32) of MAC address. Upper 16 bits reserved */

IOWR_ALTERA_TSEMAC_MAC_1(MY_TSE_BASE,0x0000cb4a);

//MAC功能配置

/*//Maximum Frame Length is 1518 bytes

Frm_length = 1518

//Minimum Inter Packet Gap is 12 bytes

Tx_ipg_length = 12

//Maximum Pause Quanta Value for Flow Control

Pause_quant = 0xFFFF

//Set the MAC with the following option:

// 100Mbps, User can get this information from the PHY status/PCS status

//Full Duplex, User can get this information from the PHY status/PCS status

//Padding Removal on Receive

//CRC Removal

//TX MAC Address Insertion on Transmit Packet

//Select mac_0 and mac_1 as the source MAC Address

Command_config Register = 0x00800220*/

IOWR_ALTERA_TSEMAC_FRM_LENGTH(MY_TSE_BASE,1518);

IOWR_ALTERA_TSEMAC_TX_IPG_LENGTH(MY_TSE_BASE,12);

IOWR_ALTERA_TSEMAC_PAUSE_QUANT(MY_TSE_BASE,0xffff);

IOWR_ALTERA_TSEMAC_CMD_CONFIG(MY_TSE_BASE,0x00800220);

//MAC复位

//Set SW_RESET bit to 1

do {

IOWR_ALTERA_TSEMAC_CMD_CONFIG(MY_TSE_BASE,0x00802220);

} while(IORD_ALTERA_TSEMAC_CMD_CONFIG(MY_TSE_BASE) != 0x00800220);

//MAC数据流发送和接收使能

do {//BIT15--loop_enable=1

IOWR_ALTERA_TSEMAC_CMD_CONFIG(MY_TSE_BASE,0x00808223);

temp = IORD_ALTERA_TSEMAC_CMD_CONFIG(MY_TSE_BASE);

} while(temp != 0x00808223);

printf("Ethernet initial successful.\n");

}

TSE的用户收发端的Avalon-ST接口都连接到了onchip-RAM上,实时观测到他们的收发数据帧是完全一致的。说明这个loopback功能和TSE收发已经完全正常了。

Baidu
map