lwIP(Lightweight IP)是一个为嵌入式系统设计的轻量级TCP/IP协议栈。它旨在为资源受限的环境提供完整的网络协议功能,同时保持低内存使用和代码大小。由于其模块化的设计,开发者可以根据需要选择包含或排除特定功能,以满足特定应用的资源要求。
Xilinx的lwIP是基于开源lwIP TCP/IP协议栈的一个适应版本,专门为Xilinx的硬件平台,如Zynq-7000和MicroBlaze,进行了优化和集成。Xilinx为其硬件平台提供了lwIP的库,使得开发者可以轻松地在其FPGA和SoC设计中实现网络通信功能。
以lwip TCP Perf Client为例,这是一个fpga作为TCP Client,像TCP Server发送批量数据,并测试传输性能的例程。

TCP参数
先看几个TCP相关的参数
TCP_CONN_PORT表示TCP的端口号,在Server中,需要指定该端口号,如果发现tcp一直不通,但ping是可以通的,多半原因是这个端口被占用了;TCP_SERVER_IP_ADDRESS表示TCP Server的IP地址

FPGA的IP地址是在main.c里面指定的:

如果TCP Server使用网络调试助手接收数据,设置如下:(需要注意,本地端口号应该是5001,跟代码中匹配)

main函数
main函数的内容如下:
int main(void)
{
struct netif *netif;
/* the mac address of the board. this should be unique per board */
unsigned char mac_ethernet_address[] = {
0x00, 0x0a, 0x35, 0x00, 0x01, 0x02 };
netif = &server_netif;
#if defined (__arm__) && !defined (ARMR5)
#if XPAR_GIGE_PCS_PMA_SGMII_CORE_PRESENT == 1 || \
XPAR_GIGE_PCS_PMA_1000BASEX_CORE_PRESENT == 1
ProgramSi5324();
ProgramSfpPhy();
#endif
#endif
/* Define this board specific macro in order perform PHY reset
* on ZCU102
*/
#ifdef XPS_BOARD_ZCU102
IicPhyReset();
#endif
init_platform();
xil_printf("\r\n\r\n");
xil_printf("-----lwIP RAW Mode TCP Client Application-----\r\n");
/* initialize lwIP */
lwip_init();
/* Add network interface to the netif_list, and set it as default */
if (!xemac_add(netif, NULL, NULL, NULL, mac_ethernet_address,
PLATFORM_EMAC_BASEADDR)) {
xil_printf("Error adding N/W interface\r\n");
return -1;
}
netif_set_default(netif);
/* now enable interrupts */
platform_enable_interrupts();
/* specify that the network if is up */
netif_set_up(netif);
assign_default_ip(&(netif->ip_addr), &(netif->netmask), &(netif->gw));
print_ip_settings(&(netif->ip_addr), &(netif->n

最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



