lwip代码分析

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发送批量数据,并测试传输性能的例程。

image-20231008155050017

TCP参数

先看几个TCP相关的参数

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

image-20231008155222432

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

image-20231008155653659

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

image-20231008155850927

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值