在lwip ARP中创建原始UDP连接
我目前正在创建一个简单的以太网传输协议。我有一个SP605 Xilinx评估板,我正在使用它调试我们项目的以太网部分。我试图分解这个例子,但到目前为止都没有成功。目前,沟通只需要一种方式。目前,我正在尝试查看通过netcat发送的数据。我还打开了wireshark,看到系统反复出现问题: 22171323.697811000 Xilinx_00:01:02广播在lwip ARP中创建原始UDP连接,udp,lwip,microblaze,Udp,Lwip,Microblaze,我目前正在创建一个简单的以太网传输协议。我有一个SP605 Xilinx评估板,我正在使用它调试我们项目的以太网部分。我试图分解这个例子,但到目前为止都没有成功。目前,沟通只需要一种方式。目前,我正在尝试查看通过netcat发送的数据。我还打开了wireshark,看到系统反复出现问题: 22171323.697811000 Xilinx_00:01:02广播 ARP 60谁拥有192.168.1.11?告诉192.168.1.10 我可以看到主机回复为: 22171323.697811000
ARP 60谁拥有192.168.1.11?告诉192.168.1.10 我可以看到主机回复为: 22171323.697811000 Xilinx_00:01:02广播
ARP 60谁拥有192.168.1.11?告诉192.168.1.10 我觉得我在配置上有一些问题,但无法弄清楚它是什么。我认为这可能与没有设置recv处理程序有关,但我不确定 下面是我正在使用的代码。lwip_init()模拟了Xilinx提供的示例中的调用
/*
* main.c
*
* Created on: Sep 24, 2013
* Author: Ian
*/
#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include "lwip/init.h"
#include "xparameters.h"
#include "netif/xadapter.h"
#include "xenv_standalone.h"
#include "platform_config.h"
#include "xparameters.h"
#include "xintc.h"
#include "xil_exception.h"
#include "mb_interface.h"
#include "xtmrctr_l.h"
#include "lwip/udp.h"
#include "lwipopts.h"
#include "xil_printf.h"
struct ip_addr ipaddr, ipaddr_remote, netmask, gw;
void udp_test(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port);
void print_ip(char *msg, struct ip_addr *ip)
{
print(msg);
xil_printf("%d.%d.%d.%d\r\n", ip4_addr1(ip), ip4_addr2(ip),
ip4_addr3(ip), ip4_addr4(ip));
}
void print_ip_settings(struct ip_addr *ip, struct ip_addr *mask, struct ip_addr *gw)
{
print_ip("Board IP: ", ip);
print_ip("Netmask : ", mask);
print_ip("Gateway : ", gw);
}
int main()
{
err_t error;
struct netif *netif, server_netif;
struct udp_pcb *udp_1;
struct pbuf *p;
char data[8] = "01234567";
u16_t Port;
Port = 69;
int count = 0;
int n = 0;
int buflen = 8;
/* 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;
xil_printf("\r\n\r\n");
xil_printf("-----lwIP RAW Application ------\r\n");
/* initliaze IP addresses to be used */
IP4_ADDR(&ipaddr_remote, 192, 168, 1, 11);
IP4_ADDR(&ipaddr, 192, 168, 1, 10);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP4_ADDR(&gw, 192, 168, 1, 1);
print_ip_settings(&ipaddr, &netmask, &gw);
lwip_init();
if (!xemac_add(netif, &ipaddr, &netmask, &gw, mac_ethernet_address, PLATFORM_EMAC_BASEADDR)) {
xil_printf("Error adding N/W interface\r\n");
return -1;
}
netif_set_default(netif);
netif_set_up(netif);
Xil_ExceptionEnable(); //Setup complete start interrupts
udp_1 = udp_new();
error = udp_bind(udp_1, IP_ADDR_ANY, Port);
if (error != 0)
{
xil_printf("Failed %d\r\n", error);
}
else if (error == 0)
{
xil_printf("Success\r\n");
}
error = udp_connect(udp_1, &ipaddr_remote, Port);
if (error != 0)
{
xil_printf("Failed %d\r\n", error);
}
else if (error == 0)
{
xil_printf("Success\r\n");
}
while(1)
{
count++;
xemacif_input(netif);
if (count == 100000)
{
p = pbuf_alloc(PBUF_TRANSPORT, buflen, PBUF_POOL);
if (!p) {
xil_printf("error allocating pbuf\r\n");
return ERR_MEM;
}
memcpy(p->payload, data, buflen);
udp_send(udp_1, p);
xil_printf("SEND\r\n");
count = 0;
pbuf_free(p);
}
}
data[1] = '2';
}
/*
*main.c
*
*创建日期:2013年9月24日
*作者:伊恩
*/
#包括
#包括
#包括
#包括“lwip/init.h”
#包括“xparameters.h”
#包括“netif/xadapter.h”
#包括“xenv_standalone.h”
#包括“platform_config.h”
#包括“xparameters.h”
#包括“xintc.h”
#包括“xil_exception.h”
#包括“mb_interface.h”
#包括“xtmrctr_l.h”
#包括“lwip/udp.h”
#包括“lwipopts.h”
#包括“xil_printf.h”
结构ip地址ip地址,ip地址远程,网络掩码,gw;
void udp_测试(void*arg、struct udp_pcb*pcb、struct pbuf*p、struct ip_addr*addr、u16_t端口);
无效打印ip(字符*消息,结构ip地址*ip)
{
印刷品(味精);
xil_printf(“%d.%d.%d.%d\r\n”、ip4_地址1(ip)、ip4_地址2(ip),
ip4_地址3(ip),ip4_地址4(ip));
}
无效打印ip设置(结构ip地址*ip,结构ip地址*掩码,结构ip地址*gw)
{
打印ip(“板ip:,ip”);
打印ip(“网络掩码:”,掩码);
打印ip(“网关:”,gw);
}
int main()
{
错误;
结构netif*netif,服务器netif;
结构udp_pcb*udp_1;
结构pbuf*p;
字符数据[8]=“01234567”;
u16_t端口;
端口=69;
整数计数=0;
int n=0;
int-buflen=8;
/*电路板的mac地址。每个电路板的mac地址应该是唯一的*/
无符号字符mac_以太网_地址[]={0x00,0x0a,0x35,0x00,0x01,0x02};
netif=&server\u netif;
xil_printf(“\r\n\r\n”);
xil_printf(“----lwIP原始应用程序----\r\n”);
/*初始化要使用的IP地址*/
IP4地址(ipaddr远程地址,192、168、1、11);
IP4地址(ipaddr,192、168、1、10);
IP4_地址(网络掩码,255、255、255、0);
IP4地址(&gw,192,168,1,1);
打印ip设置(&ipaddr、&netmask、&gw);
lwip_init();
如果(!xemac\u add(netif、&ipaddr、&netmask、&gw、mac\u以太网地址、平台\u EMAC\u BASEADDR)){
xil_printf(“添加N/W接口时出错\r\N”);
返回-1;
}
netif\u设置默认值(netif);
netif设置(netif);
Xil_ExceptionEnable();//设置完成启动中断
udp_1=udp_new();
错误=udp_绑定(udp_1,IP_ADDR_ANY,端口);
如果(错误!=0)
{
xil_printf(“失败%d\r\n”,错误);
}
else if(错误==0)
{
xil_printf(“成功”\r\n);
}
错误=udp\U连接(udp\U 1和ipaddr\U远程端口);
如果(错误!=0)
{
xil_printf(“失败%d\r\n”,错误);
}
else if(错误==0)
{
xil_printf(“成功”\r\n);
}
而(1)
{
计数++;
xemacif_输入(netif);
如果(计数=100000)
{
p=pbuf_alloc(pbuf_传输、buflen、pbuf_池);
如果(!p){
xil_printf(“分配pbuf时出错\r\n”);
返回ERR_MEM;
}
memcpy(p->payload,data,buflen);
udp_发送(udp_1,p);
xil_printf(“发送\r\n”);
计数=0;
无pbuf_(p);
}
}
数据[1]=“2”;
}
好的,基本上这就是我的发现
当我使用Xilinx xapp1026时,它与sp605_AxiEth_32kb_缓存项目有问题。它在一开始就被挂起来了。我无法诊断该项目,但我切换到sp605_EthernetLite_32kb_缓存示例项目。我只能假设微博客中断初始化失败导致ARP无法添加,并迫使系统反复进入循环。在AxiEth示例中,中断未能初始化的原因尚不清楚
一旦来到这里,我就能够通过剥离提供的系统并使用以下代码使程序正常工作:
/*
* Copyright (c) 2007 Xilinx, Inc. All rights reserved.
*
* Xilinx, Inc.
* XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
* COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
* ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR
* STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION
* IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE
* FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
* XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
* THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO
* ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE
* FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#include <stdio.h>
#include <string.h>
#include "lwip/udp.h"
#include "xparameters.h"
#include "netif/xadapter.h"
#include "platform.h"
#include "platform_config.h"
#include "lwipopts.h"
#ifndef __PPC__
#include "xil_printf.h"
#endif
void print_headers();
int start_applications();
int transfer_data();
void platform_enable_interrupts();
void lwip_init(void);
void tcp_fasttmr(void);
void tcp_slowtmr(void);
#if LWIP_DHCP==1
extern volatile int dhcp_timoutcntr;
err_t dhcp_start(struct netif *netif);
#endif
extern volatile int TxPerfConnMonCntr;
extern volatile int TcpFastTmrFlag;
extern volatile int TcpSlowTmrFlag;
void print_ip(char *msg, struct ip_addr *ip)
{
print(msg);
xil_printf("%d.%d.%d.%d\r\n", ip4_addr1(ip), ip4_addr2(ip),
ip4_addr3(ip), ip4_addr4(ip));
}
void print_ip_settings(struct ip_addr *ip, struct ip_addr *mask, struct ip_addr *gw)
{
print_ip("Board IP: ", ip);
print_ip("Netmask : ", mask);
print_ip("Gateway : ", gw);
}
int main()
{
struct netif *netif, server_netif;
struct ip_addr ipaddr, netmask, gw;
// Added stuff for the creation of a basic UDP
err_t error;
struct ip_addr ip_remote;
struct udp_pcb *udp_1;
struct pbuf *p;
char data[8] = "01234567";
u16_t Port = 12;
int buflen = 8;
int count = 0;
/* 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 (init_platform() < 0) {
xil_printf("ERROR initializing platform.\r\n");
return -1;
}
xil_printf("\r\n\r\n");
xil_printf("-----lwIP RAW Mode Demo Application ------\r\n");
/* initliaze IP addresses to be used */
#if (LWIP_DHCP==0)
IP4_ADDR(&ipaddr, 192, 168, 1, 10);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP4_ADDR(&gw, 192, 168, 1, 1);
print_ip_settings(&ipaddr, &netmask, &gw);
#endif
lwip_init();
#if (LWIP_DHCP==1)
ipaddr.addr = 0;
gw.addr = 0;
netmask.addr = 0;
#endif
/* Add network interface to the netif_list, and set it as default */
if (!xemac_add(netif, &ipaddr, &netmask, &gw, mac_ethernet_address, PLATFORM_EMAC_BASEADDR)) {
xil_printf("Error adding N/W interface\r\n");
return -1;
}
netif_set_default(netif);
/* specify that the network if is up */
netif_set_up(netif);
/* now enable interrupts */
platform_enable_interrupts();
#if (LWIP_DHCP==1)
/* Create a new DHCP client for this interface.
* Note: you must call dhcp_fine_tmr() and dhcp_coarse_tmr() at
* the predefined regular intervals after starting the client.
*/
dhcp_start(netif);
dhcp_timoutcntr = 24;
TxPerfConnMonCntr = 0;
while(((netif->ip_addr.addr) == 0) && (dhcp_timoutcntr > 0)) {
xemacif_input(netif);
if (TcpFastTmrFlag) {
tcp_fasttmr();
TcpFastTmrFlag = 0;
}
if (TcpSlowTmrFlag) {
tcp_slowtmr();
TcpSlowTmrFlag = 0;
}
}
if (dhcp_timoutcntr <= 0) {
if ((netif->ip_addr.addr) == 0) {
xil_printf("DHCP Timeout\r\n");
xil_printf("Configuring default IP of 192.168.1.10\r\n");
IP4_ADDR(&(netif->ip_addr), 192, 168, 1, 10);
IP4_ADDR(&(netif->netmask), 255, 255, 255, 0);
IP4_ADDR(&(netif->gw), 192, 168, 1, 1);
}
}
/* receive and process packets */
print_ip_settings(&(netif->ip_addr), &(netif->netmask), &(netif->gw));
#endif
/* start the application (web server, rxtest, txtest, etc..) */
xil_printf("Setup Done");
IP4_ADDR(&ip_remote, 192, 168, 1, 11);
udp_1 = udp_new();
error = udp_bind(udp_1, IP_ADDR_ANY, Port);
if (error != 0)
{
xil_printf("Failed %d\r\n", error);
}
else if (error == 0)
{
xil_printf("Success\r\n");
}
error = udp_connect(udp_1, &ip_remote, Port);
if (error != 0)
{
xil_printf("Failed %d\r\n", error);
}
else if (error == 0)
{
xil_printf("Success\r\n");
}
while (1)
{
xemacif_input(netif);
count++;
if (count == 80000)
{
p = pbuf_alloc(PBUF_TRANSPORT, buflen, PBUF_POOL);
if (!p) {
xil_printf("error allocating pbuf\r\n");
return ERR_MEM;
}
memcpy(p->payload, data, buflen);
udp_send(udp_1, p);
xil_printf("SEND\r\n");
count = 0;
pbuf_free(p);
}
}
/* never reached */
cleanup_platform();
return 0;
}
/*
*版权所有(c)2007 Xilinx,Inc.保留所有权利。
*
*锡林克斯公司。
*XILINX以“原样”的形式提供此设计、代码或信息
*谢谢你。通过以下方式提供此设计、代码或信息:
*此功能的一种可能实现,应用程序或
*根据标准,XILINX不表示此实现
*不存在任何侵权索赔,您对此负责
*以获取实施过程中可能需要的任何权利。
*XILINX明确否认与以下内容有关的任何担保:
*实施的充分性,包括但不限于
*本实施是免费的任何保证或声明
*从侵权索赔、默示适销性保证
*以及适合特定用途。
*
*/
#包括
#包括
#包括“lwip/udp.h”
#包括“xparameters.h”
#包括“netif/xadapter.h”
#包括“platform.h”
#包括“platform_config.h”
#包括“lwipopts.h”
#ifndef\uuu PPC__
#包括“xil_printf.h”
#恩迪夫
无效打印标题();
int start_应用程序();
int传输_数据();
void platform_enable_interrupts();
无效lwip_init(无效);
无效tcp_fasttmr(无效);
无效tcp_slowtmr(无效);
#如果LWIP_DHCP==1
外部易失性int-dhcpu-timoutcntr;
dhcp启动错误(结构netif*netif);
#恩迪夫
外部易失性int-txperfconmoncntr;
外部挥发性int TcpFa