原創聲明:
本原創教程由芯驛電子科技(上海)有限公司(ALINX)創作,版權歸本公司所有,如需轉載,需授權并注明出處。
適用于板卡型號:
AXU2CGA/AXU2CGB/AXU3EG/AXU4EV-E/AXU4EV-P/AXU5EV-E/AXU5EV-P /AXU9EG/AXU15EG
vivado工程目錄為“ps_hello/vivado”
vitis工程目錄為“ps_net/vitis”
軟件工程師工作內容
以下為軟件工程師負責內容。
開發板有兩路千兆以太網,通過RGMII接口連接,本實驗演示如何使用Vitis自帶的LWIP模板進行PS端千兆以太網TCP通信。
LWIP雖然是輕量級協議棧,但如果從來沒有使用過,使用起來會有一定的困難,建議先熟悉LWIP的相關知識。
1. Vitis程序開發
1.1 LWIP庫修改
由于自帶的LWIP庫只能識別部分phy芯片,如果開發板所用的phy芯片不在默認支持范圍內,要修改庫文件。也可以直接使用修改過的庫替換原有的庫。
1) 找到庫文件目錄“X:\xxx\Vitis\2020.1\data\embeddedsw\ThirdParty\sw_services”
2)找到要修改的文件目錄“lwip211_v1_2\src\contrib\ports\xilinx\netif”中文件“xaxiemacif_physpeed.c”和“xemacpsif_physpeed.c”要修改。
3)修改PL端的“xaxiemacif_physpeed.c”文件,添加相關宏定義
4)添加phy速度獲取函數
unsignedintget_phy_speed_ksz9031(XAxiEthernet*xaxiemacp,u32phy_addr){ u16control; u16status; u16partner_capabilities; xil_printf("StartPHYautonegotiation\r\n"); XAxiEthernet_PhyWrite(xaxiemacp,phy_addr,IEEE_PAGE_ADDRESS_REGISTER,2); XAxiEthernet_PhyRead(xaxiemacp,phy_addr,IEEE_CONTROL_REG_MAC,&control); //control|=IEEE_RGMII_TXRX_CLOCK_DELAYED_MASK; control&=~(0x10); XAxiEthernet_PhyWrite(xaxiemacp,phy_addr,IEEE_CONTROL_REG_MAC,control); XAxiEthernet_PhyWrite(xaxiemacp,phy_addr,IEEE_PAGE_ADDRESS_REGISTER,0); XAxiEthernet_PhyRead(xaxiemacp,phy_addr,IEEE_AUTONEGO_ADVERTISE_REG,&control); control|=IEEE_ASYMMETRIC_PAUSE_MASK; control|=IEEE_PAUSE_MASK; control|=ADVERTISE_100; control|=ADVERTISE_10; XAxiEthernet_PhyWrite(xaxiemacp,phy_addr,IEEE_AUTONEGO_ADVERTISE_REG,control); XAxiEthernet_PhyRead(xaxiemacp,phy_addr,IEEE_1000_ADVERTISE_REG_OFFSET, &control); control|=ADVERTISE_1000; XAxiEthernet_PhyWrite(xaxiemacp,phy_addr,IEEE_1000_ADVERTISE_REG_OFFSET, control); XAxiEthernet_PhyWrite(xaxiemacp,phy_addr,IEEE_PAGE_ADDRESS_REGISTER,0); XAxiEthernet_PhyRead(xaxiemacp,phy_addr,IEEE_COPPER_SPECIFIC_CONTROL_REG, &control); control|=(7<<12); /*?max?number?of?gigabit?attempts?*/ control?|=(1<<11); /*?enable?downshift?*/ XAxiEthernet_PhyWrite(xaxiemacp,?phy_addr,?IEEE_COPPER_SPECIFIC_CONTROL_REG, control); XAxiEthernet_PhyRead(xaxiemacp,?phy_addr,?IEEE_CONTROL_REG_OFFSET,&control); control?|=?IEEE_CTRL_AUTONEGOTIATE_ENABLE; control?|=?IEEE_STAT_AUTONEGOTIATE_RESTART; XAxiEthernet_PhyWrite(xaxiemacp,?phy_addr,?IEEE_CONTROL_REG_OFFSET,?control); XAxiEthernet_PhyRead(xaxiemacp,?phy_addr,?IEEE_CONTROL_REG_OFFSET,&control); control?|=?IEEE_CTRL_RESET_MASK; XAxiEthernet_PhyWrite(xaxiemacp,?phy_addr,?IEEE_CONTROL_REG_OFFSET,?control); while(1){ XAxiEthernet_PhyRead(xaxiemacp,?phy_addr,?IEEE_CONTROL_REG_OFFSET,&control); if(control?&?IEEE_CTRL_RESET_MASK) continue; else break; } xil_printf("Waiting?for?PHY?to?complete?autonegotiation.\r\n"); XAxiEthernet_PhyRead(xaxiemacp,?phy_addr,?IEEE_STATUS_REG_OFFSET,&status); while(!(status?&?IEEE_STAT_AUTONEGOTIATE_COMPLETE)){ sleep(1); XAxiEthernet_PhyRead(xaxiemacp,?phy_addr,?IEEE_STATUS_REG_OFFSET, &status); } xil_printf("autonegotiation?complete?\r\n"); XAxiEthernet_PhyRead(xaxiemacp,?phy_addr,0x1f,&partner_capabilities); if((partner_capabilities?&0x40)==0x40)/*?1000Mbps?*/ return1000; elseif((partner_capabilities?&0x20)==0x20)/*?100Mbps?*/ return100; elseif((partner_capabilities?&0x10)==0x10)/*?10Mbps?*/ return10; else return0;}
5) 修改函數“get_IEEE_phy_speed”,添加對KSZ9031的支持。
unsignedget_IEEE_phy_speed(XAxiEthernet*xaxiemacp){ u16phy_identifier; u16phy_model; u8phytype;#ifdefXPAR_AXIETHERNET_0_BASEADDR u32phy_addr=detect_phy(xaxiemacp); /*GetthePHYIdentifierandModelnumber*/ XAxiEthernet_PhyRead(xaxiemacp,phy_addr,PHY_IDENTIFIER_1_REG,&phy_identifier); XAxiEthernet_PhyRead(xaxiemacp,phy_addr,PHY_IDENTIFIER_2_REG,&phy_model);/*DependinguponwhatmanufacturerPHYisconnected,adifferentmaskis*neededtodeterminethespecificmodelnumberofthePHY.*/ if(phy_identifier==MARVEL_PHY_IDENTIFIER){ phy_model=phy_model&MARVEL_PHY_MODEL_NUM_MASK; if(phy_model==MARVEL_PHY_88E1116R_MODEL){ returnget_phy_speed_88E1116R(xaxiemacp,phy_addr); }elseif(phy_model==MARVEL_PHY_88E1111_MODEL){ returnget_phy_speed_88E1111(xaxiemacp,phy_addr); } }elseif(phy_identifier==TI_PHY_IDENTIFIER){ phy_model=phy_model&TI_PHY_DP83867_MODEL; phytype=XAxiEthernet_GetPhysicalInterface(xaxiemacp); if(phy_model==TI_PHY_DP83867_MODEL&&phytype==XAE_PHY_TYPE_SGMII){ returnget_phy_speed_TI_DP83867_SGMII(xaxiemacp,phy_addr); } if(phy_model==TI_PHY_DP83867_MODEL){ returnget_phy_speed_TI_DP83867(xaxiemacp,phy_addr); } } elseif(phy_identifier==MICREL_PHY_IDENTIFIER) { xil_printf("Phy%disKSZ9031\n\r",phy_addr); get_phy_speed_ksz9031(xaxiemacp,phy_addr); } else{ LWIP_DEBUGF(NETIF_DEBUG,("XAxiEthernetget_IEEE_phy_speed:DetectedPHYwithunknownidentifier/model.\r\n")); }#endif#ifdefPCM_PMA_CORE_PRESENT returnget_phy_negotiated_speed(xaxiemacp,phy_addr);#endif}
6) 修改PS端“xemacpsif_physpeed.c”文件添加宏定義
7) 添加phy速度獲取函數
staticu32_tget_phy_speed_ksz9031(XEmacPs*xemacpsp,u32_tphy_addr){ u16_ttemp; u16_tcontrol; u16_tstatus; u16_tstatus_speed; u32_ttimeout_counter=0; u32_ttemp_speed; u32_tphyregtemp; xil_printf("StartPHYautonegotiation\r\n"); XEmacPs_PhyWrite(xemacpsp,phy_addr,IEEE_PAGE_ADDRESS_REGISTER,2); XEmacPs_PhyRead(xemacpsp,phy_addr,IEEE_CONTROL_REG_MAC,&control); control|=IEEE_RGMII_TXRX_CLOCK_DELAYED_MASK; XEmacPs_PhyWrite(xemacpsp,phy_addr,IEEE_CONTROL_REG_MAC,control); XEmacPs_PhyWrite(xemacpsp,phy_addr,IEEE_PAGE_ADDRESS_REGISTER,0); XEmacPs_PhyRead(xemacpsp,phy_addr,IEEE_AUTONEGO_ADVERTISE_REG,&control); control|=IEEE_ASYMMETRIC_PAUSE_MASK; control|=IEEE_PAUSE_MASK; control|=ADVERTISE_100; control|=ADVERTISE_10; XEmacPs_PhyWrite(xemacpsp,phy_addr,IEEE_AUTONEGO_ADVERTISE_REG,control); XEmacPs_PhyRead(xemacpsp,phy_addr,IEEE_1000_ADVERTISE_REG_OFFSET, &control); control|=ADVERTISE_1000; XEmacPs_PhyWrite(xemacpsp,phy_addr,IEEE_1000_ADVERTISE_REG_OFFSET, control); XEmacPs_PhyWrite(xemacpsp,phy_addr,IEEE_PAGE_ADDRESS_REGISTER,0); XEmacPs_PhyRead(xemacpsp,phy_addr,IEEE_COPPER_SPECIFIC_CONTROL_REG, &control); control|=(7<<12); /*?max?number?of?gigabit?attempts?*/ control?|=(1<<11); /*?enable?downshift?*/ XEmacPs_PhyWrite(xemacpsp,?phy_addr,?IEEE_COPPER_SPECIFIC_CONTROL_REG, control); XEmacPs_PhyRead(xemacpsp,?phy_addr,?IEEE_CONTROL_REG_OFFSET,&control); control?|=?IEEE_CTRL_AUTONEGOTIATE_ENABLE; control?|=?IEEE_STAT_AUTONEGOTIATE_RESTART; XEmacPs_PhyWrite(xemacpsp,?phy_addr,?IEEE_CONTROL_REG_OFFSET,?control); XEmacPs_PhyRead(xemacpsp,?phy_addr,?IEEE_CONTROL_REG_OFFSET,&control); control?|=?IEEE_CTRL_RESET_MASK; XEmacPs_PhyWrite(xemacpsp,?phy_addr,?IEEE_CONTROL_REG_OFFSET,?control); while(1){ XEmacPs_PhyRead(xemacpsp,?phy_addr,?IEEE_CONTROL_REG_OFFSET,&control); if(control?&?IEEE_CTRL_RESET_MASK) continue; else break; } XEmacPs_PhyRead(xemacpsp,?phy_addr,?IEEE_STATUS_REG_OFFSET,&status); xil_printf("Waiting?for?PHY?to?complete?autonegotiation.\r\n"); while(!(status?&?IEEE_STAT_AUTONEGOTIATE_COMPLETE)){ sleep(1); XEmacPs_PhyRead(xemacpsp,?phy_addr, IEEE_COPPER_SPECIFIC_STATUS_REG_2,&temp); timeout_counter++; if(timeout_counter?==30){ xil_printf("Auto?negotiation?error?\r\n"); return; } XEmacPs_PhyRead(xemacpsp,?phy_addr,?IEEE_STATUS_REG_OFFSET,&status); } xil_printf("autonegotiation?complete?\r\n"); XEmacPs_PhyRead(xemacpsp,?phy_addr,0x1f, &status_speed); if((status_speed?&0x40)==0x40)/*?1000Mbps?*/ return1000; elseif((status_speed?&0x20)==0x20)/*?100Mbps?*/ return100; elseif((status_speed?&0x10)==0x10)/*?10Mbps?*/ return10; else return0; return?XST_SUCCESS;}
8)修改函數“get_IEEE_phy_speed”,添加對KSZ9031的支持
staticu32_tget_IEEE_phy_speed(XEmacPs*xemacpsp,u32_tphy_addr){ u16_tphy_identity; u32_tRetStatus; XEmacPs_PhyRead(xemacpsp,phy_addr,PHY_IDENTIFIER_1_REG, &phy_identity); if(phy_identity==MICREL_PHY_IDENTIFIER){ RetStatus=get_phy_speed_ksz9031(xemacpsp,phy_addr); }elseif(phy_identity==PHY_TI_IDENTIFIER){ RetStatus=get_TI_phy_speed(xemacpsp,phy_addr); }elseif(phy_identity==PHY_REALTEK_IDENTIFIER){ RetStatus=get_Realtek_phy_speed(xemacpsp,phy_addr); }else{ RetStatus=get_Marvell_phy_speed(xemacpsp,phy_addr); } returnRetStatus;}
1.2 創建APP工程時基于LWIP模板
2.下載調試
測試環境要求有一臺支持dhcp的路由器,開發板連接路由器可以自動獲取IP地址,實驗主機和開發板在一個網絡,可以相互通信。
2.1 以太網測試
1) 連接串口打開串口調試終端,連接好PS端以太網網線到路由器,運行Vitis下載程序
2)可以看到串口打印出一些信息,可以看到自動獲取到地址為“192.168.1.63”,連接速度1000Mbps,tcp端口為7
3) 使用telnet連接
4) 當輸入一個字符時,開發板返回相同字符
3. 實驗總結
通過實驗我們更加深刻了解到Vitis程序的開發,本實驗只是簡單的講解如何創建一個LWIP應用,LWIP可以完成UDP、TCP等協議,在后續的教程中我們會提供基于以太網的具體應用,例如ADC采集數據通過以太網發送,攝像頭數據通過以太網發送上位機顯示。
-
FPGA
+關注
關注
1630文章
21769瀏覽量
604648 -
以太網
+關注
關注
40文章
5449瀏覽量
172175 -
LwIP
+關注
關注
2文章
87瀏覽量
27263 -
Zynq
+關注
關注
10文章
610瀏覽量
47224 -
MPSoC
+關注
關注
0文章
199瀏覽量
24300
發布評論請先 登錄
相關推薦
評論