const static char Test[]="hello world !\n";
const static char Test1[]="I hope it successed!\n";
int count=0;
void Delay(unsigned long ulVal)
{
while ( --ulVal != 0 );
}
void
httpd_init(void)
{
struct udp_pcb *pcb;
struct ip_addr PCipaddr;
struct pbuf *p,*pbuffer;
err_t err;
IP4_ADDR(&PCipaddr,10,1,1,52);
p = pbuf_alloc(PBUF_RAW,sizeof(Test),PBUF_RAM);
p->payload=(void *)Test;
pbuffer = pbuf_alloc(PBUF_RAW,sizeof(Test1),PBUF_RAM);
pbuffer->payload=(void *)Test1;
pcb = udp_new();
err=udp_bind(pcb, IP_ADDR_ANY,60000);
if(err==ERR_OK)
{printf("bound ok ! \n");}
err=udp_connect(pcb,&PCipaddr,60000);
if(err==ERR_OK)
{printf("connect ok !\n");}
while( count++ < 20 )
{
err=udp_send(pcb,p);
if(err==ERR_OK)
{ printf("udp_send OK \n"); }
//Delay(1000000);
// Delay(1000000);
// Delay(1000000);
// err=udp_send(pcb,pbuffer);
}
}
--
View this message in context: http://www.nabble.com/how-to-send-udp-messages-circularly---tp24321123p24321123.html
Sent from the lwip-users mailing list archive at Nabble.com.
_______________________________________________
lwip-users mailing list
lwip-...@nongnu.org
http://lists.nongnu.org/mailman/listinfo/lwip-users
Try using a different pbuf for each send.
Kieran
}
--
View this message in context: http://www.nabble.com/how-to-send-udp-messages-circularly---tp24321123p24321597.html
Sent from the lwip-users mailing list archive at Nabble.com.
_______________________________________________
Yes, but you have a loop that re-uses those pbufs 20 times. Try using a
Unfortunately,it is still not work.when i removed the loop ,sent two
different pbufs, only the last string i can find.
Then ,i try to use two different pcbs to send data,i can only get the
last string.
I am going crazy overhere....
Best Regards
the_gadfly
------------------
// while( count++ < 20 )
//{
err=udp_send(pcb,p);
if(err==ERR_OK)
{ printf("udp_send OK \n"); }
//Delay(1000000);
// Delay(1000000);
// Delay(1000000);
err=udp_send(pcb,pbuffer);
--
View this message in context: http://www.nabble.com/how-to-send-udp-messages-circularly---tp24321123p24322519.html
Sent from the lwip-users mailing list archive at Nabble.com.
_______________________________________________
Could you send a wireshark pcap of what you see.
What setting do you have for ARP_QUEUEING?
Also, what happens if you just send the first string once?
What happens if you change the code by replacing:
p->payload = (void *)Test;
with:
memcpy(p->payload, Test, sizeof(Test));
Also, as well as changing the way you get the data in the payload region
of the pbuf, you should also use PBUF_TRANSPORT rather than PBUF_RAW to
make sure there is space for the headers in the calls to pbuf_alloc();
1 I uploaded the Ethereal files .
2 I set ARP_QUEUEING to 1 ,in lwipopts.h
3 When i changed "p->payload = (void *)Test;"to"memcpy(p->payload, Test,
sizeof (Test));",the udp content changed to "00000...",you can find it in
the file.
4 I changed to PBUF_TRANSPORT,it is no use.
5 Your patience is impressive! thank you again!
the_gadfly
http://www.nabble.com/file/p24323559/you_can_open_them_by_Ethereal.rar
you_can_open_them_by_Ethereal.rar
--
View this message in context: http://www.nabble.com/how-to-send-udp-messages-circularly---tp24321123p24323559.html
Sent from the lwip-users mailing list archive at Nabble.com.
_______________________________________________
I don't have a rar archive reader to hand, sorry. Can you avoid
packaging them? Just attaching the files to your email should be fine
as they shouldn't be very big.
> 2 I set ARP_QUEUEING to 1 ,in lwipopts.h
>
> 3 When i changed "p->payload = (void *)Test;"to"memcpy(p->payload, Test,
> sizeof (Test));",the udp content changed to "00000...",you can find it in
> the file.
That's odd.
> 5 Your patience is impressive! thank you again!
I guess my best suggestion would be to go back to the "lwip-http"
example that you based this code on (can you show us the code that you
started from, it's not clear from your email which example you meant)
and check that it works. Then change it to what you want to do a little
at a time and check at each stage that it still works. This should
quickly show up what you're doing wrong.
Any good compiler will optimize this away to nothing, I guess. If you
really want to delay like that, you'd have to use a volatile variable.
> }
> void
> httpd_init(void)
>
From where (which thread, what point, e.g. after stack initialization?)
do you call httpd_init()? This whole thing could be a threading problem:
a mistake that many lwIP beginners make is to use the raw API from
multiple threads - it may only be used from the tcpip_thread and not
from interrupt level!
> {
> struct udp_pcb *pcb;
> struct ip_addr PCipaddr;
> struct pbuf *p,*pbuffer;
> err_t err;
>
> IP4_ADDR(&PCipaddr,10,1,1,52);
>
> p = pbuf_alloc(PBUF_RAW,sizeof(Test),PBUF_RAM);
> p->payload=(void *)Test;
>
Like Kieran already indicated: the above 2 lines are totally wrong usage
of the pbuf API:
- PBUF_RAW means NO additional headers whereas you want to send a UDP
packet which means there will have to be UDP, IP and ARP headers added.
Use PBUF_TRANSPORT for sending UDP data.
- When allocating a PBUF_RAM, you get one continous region of memory:
struct pbuf is at the beginning, the data buffer follows. For PBUF_RAM
pbufs you *must not* mess with the payload pointer! Instead, copy the
data from the original location into the pbuf using memcpy(p->payload,
src, len); if you want to do it like you did (p->payload = x), use
PBUF_REF instead of PBUF_RAM or lwIP might even corrupt your RAM by
writing to places it shouldn't.
> pbuffer = pbuf_alloc(PBUF_RAW,sizeof(Test1),PBUF_RAM);
> pbuffer->payload=(void *)Test1;
>
>
>
> pcb = udp_new();
> err=udp_bind(pcb, IP_ADDR_ANY,60000);
> if(err==ERR_OK)
> {printf("bound ok ! \n");}
> err=udp_connect(pcb,&PCipaddr,60000);
> if(err==ERR_OK)
> {printf("connect ok !\n");}
> while( count++ < 20 )
> {
>
>
> err=udp_send(pcb,p);
> if(err==ERR_OK)
> { printf("udp_send OK \n"); }
> //Delay(1000000);
> // Delay(1000000);
> // Delay(1000000);
> // err=udp_send(pcb,pbuffer);
>
> }
>
> }
This may be stupid, but did you check err == ERR_OK in all places, e.g.
did you see the printf's?
If all this didn't help, it could still be that your MAC or OS port has
a bug...
Simon
Best Regard
the_gadfly
--
View this message in context: http://www.nabble.com/how-to-send-udp-messages-circularly---tp24321123p24324593.html
Sent from the lwip-users mailing list archive at Nabble.com.
_______________________________________________
Best Regard
the_gadfly
--
View this message in context: http://www.nabble.com/how-to-send-udp-messages-circularly---tp24321123p24324594.html
Sent from the lwip-users mailing list archive at Nabble.com.
_______________________________________________
If his driver does an immediate send of the pbuf and waits for it to
transmit, you can use one pbuf with UDP.
Bill
According your replys , I modified my code.However ,it went to the old
problem that not sending UDP packets.I checked the
etherarp.c , it said that the etharp_tmr should be called every
ARP_TMR_INTERVAL(10 seconds e.g).So i added the etharp_tmr in
the main loop and etharp_init() in lwip_init().But it seems useless...
(wrong way ?)
In the Ethereal , i can see arps : the board asked and PC answerd.I don't
konw why the board hold them.
is there anything (*_tmr or other things ) i missing? is there any mistake
with my code ?
PS: i use altera stratia II and Nios ii IDE without OS.
Best Regards
the_gadfly
-------------------------------------------
int main(void)
{
//0.6.4 struct netif *netif;
struct netif netif;
struct ip_addr ipaddr, netmask, gw;
struct ip_addr udpDestIpAddr;
struct pbuf *p;
struct udp_pcb *pcb;
err_t err;
char Test[]="hello world !";
unsigned int now, lasttime;
int j=0;
alt_avalon_lan91c111_if* dev_list_ptr =
(alt_avalon_lan91c111_if*)alt_ethernet_device_list.next;
printf("UDP-server using Light-weight IP (LWIP)\n\n");
/* Initialize lwip */
lwip_init();
printf ("Setting IP address to: %d.%d.%d.%d\n", IPADDR0, IPADDR1, IPADDR2,
IPADDR3);
printf ("Setting netmask to: %d.%d.%d.%d\n", NETMASK0, NETMASK1, NETMASK2,
NETMASK3);
printf ("Setting gateway address to: %d.%d.%d.%d\n\n\n", GWADDR0, GWADDR1,
GWADDR2, GWADDR3);
IP4_ADDR(&ipaddr, IPADDR0, IPADDR1, IPADDR2, IPADDR3);
IP4_ADDR(&netmask, NETMASK0, NETMASK1, NETMASK2, NETMASK3);
IP4_ADDR(&gw, GWADDR0, GWADDR1, GWADDR2, GWADDR3);
//0.6.4 netif = netif_add(&ipaddr, &netmask, &gw,
netif_add(&netif, &ipaddr, &netmask,
&gw,(void*)dev_list_ptr,lan91c111if_init, ip_input);
//0.6.4 netif_set_default(&netif);
netif_set_default(&netif);
IP4_ADDR(&udpDestIpAddr, 10, 1 ,1, 52);
p = pbuf_alloc(PBUF_TRANSPORT,sizeof(Test),PBUF_RAM);
memcpy(p->payload, Test, sizeof(Test));
pcb = udp_new();
udp_bind(pcb, IP_ADDR_ANY, 60000);
udp_connect(pcb, &udpDestIpAddr, 60000);
err=udp_send(pcb,p);
if(err==ERR_OK)
{printf("send ok !\n");}
pbuf_free(p);
udp_remove(pcb);
lasttime = get_milliseconds();
while(1)
{
//0.6.4 lan91c111if_service(netif);
lan91c111if_service(&netif);
now = get_milliseconds();
if ((now - lasttime)*1000/alt_ticks_per_second() > ARP_TMR_INTERVAL)
{
lasttime = now;
etharp_tmr(); // Every 10 s execute etharp_tmr()
}
if (++j==1000) {
ip_reass_timer();
j=0;
}
}
}
--
View this message in context: http://www.nabble.com/how-to-send-udp-messages-circularly---tp24321123p24372824.html
Probably, but I'm not sure what without looking in detail. My
suggestion of starting with a simple UDP example that works, and then
changing it to do what you want, is still the best I can I think of.
Kieran
---------- lwip_web_server.c--------------
nt main(void)
{
//0.6.4 struct netif *netif;
struct netif netif;
struct ip_addr ipaddr, netmask, gw;
//struct ip_addr udpDestIpAddr;
//struct pbuf *p;
//struct udp_pcb *pcb;
//err_t err;
//char Test[]="hello world !";
unsigned int now, lasttime;
int j=0;
alt_avalon_lan91c111_if* dev_list_ptr =
(alt_avalon_lan91c111_if*)alt_ethernet_device_list.next;
printf("UDP-server using Light-weight IP (LWIP)\n\n");
/* Initialize lwip */
lwip_init();
printf ("Setting IP address to: %d.%d.%d.%d\n", IPADDR0, IPADDR1, IPADDR2,
IPADDR3);
printf ("Setting netmask to: %d.%d.%d.%d\n", NETMASK0, NETMASK1, NETMASK2,
NETMASK3);
printf ("Setting gateway address to: %d.%d.%d.%d\n\n\n", GWADDR0, GWADDR1,
GWADDR2, GWADDR3);
IP4_ADDR(&ipaddr, IPADDR0, IPADDR1, IPADDR2, IPADDR3);
IP4_ADDR(&netmask, NETMASK0, NETMASK1, NETMASK2, NETMASK3);
IP4_ADDR(&gw, GWADDR0, GWADDR1, GWADDR2, GWADDR3);
//0.6.4 netif = netif_add(&ipaddr, &netmask, &gw,
netif_add(&netif, &ipaddr, &netmask,
&gw,(void*)dev_list_ptr,lan91c111if_init, ip_input);
//0.6.4 netif_set_default(&netif);
netif_set_default(&netif);
//IP4_ADDR(&udpDestIpAddr, 10, 1 ,1, 52);
udp_echo_init(); // defined in httpd.c
/*
p = pbuf_alloc(PBUF_TRANSPORT,sizeof(Test),PBUF_RAM);
memcpy(p->payload, Test, sizeof(Test));
pcb = udp_new();
udp_bind(pcb, IP_ADDR_ANY, 60000);
udp_connect(pcb, &udpDestIpAddr, 60000);
err=udp_send(pcb,p);
if(err==ERR_OK)
{printf("send ok !\n");}
pbuf_free(p);
udp_remove(pcb);
*/
lasttime = get_milliseconds();
while(1)
{
//0.6.4 lan91c111if_service(netif);
lan91c111if_service(&netif);
now = get_milliseconds();
if ((now - lasttime)*1000/alt_ticks_per_second() > ARP_TMR_INTERVAL)
{
lasttime = now;
etharp_tmr(); // Ever 10s execute etharp_tmr()
}
if (++j==1000) {
ip_reass_timer();
j=0;
}
}
}
-----------------httpd.c------------------
void udp_echo_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct
ip_addr *addr, u16_t port)
{ struct ip_addr ipaddr;
IP4_ADDR(&ipaddr,10,1,1,52);
if (p != NULL)
{
udp_connect(pcb,&ipaddr,60000);
udp_send(pcb, p);
pbuf_free(p);
}
}
void udp_echo_init(void)
{
struct udp_pcb * pcb;
pcb = udp_new();
udp_bind(pcb, IP_ADDR_ANY, 60000) ;
udp_recv(pcb, udp_echo_recv, NULL);
}
--
View this message in context: http://www.nabble.com/how-to-send-udp-messages-circularly---tp24321123p24373631.html
Sent from the lwip-users mailing list archive at Nabble.com.
_______________________________________________
The explanation for that could be simple (and nearly described by
yourself): In order to really send the packet, the MAC address needs to
be known. Since it is already in the cache when a packet has been
received, udp_send() called from udp_echo_recv() can send the packet
directly. However, in the main function, you send to a destination that
is not in the ARP cache and so the MAC address must be resolved (the
packet for which you saw).
Now the question is why the ARP response is not received correctly by
your device, or if it is received, why it does not lead to sending out
the queued packets. Having a look at the stats (must be turned on in
lwipopts.h) can tell you how many packets were sent/received by each
layer and if there were errors.
BTW, did you already tell us the version of lwIP you're using? There are
'suspicious' comments that suggest old versions in your code. Also, I
think I remember Altera not really shipping the latest version (if you
have the latest version of theirs software, at all).
Simon
_______________________________________________
IP_FRAG
xmit: 0
rexmit: 0
recv: 0
fw: 0
drop: 0
chkerr: 0
lenerr: 0
memerr: 0
rterr: 0
proterr: 0
opterr: 0
err: 0
cachehit: 0
IP
xmit: 1
rexmit: 0
recv: 0
fw: 0
drop: 0
chkerr: 0
lenerr: 0
memerr: 0
rterr: 0
proterr: 0
opterr: 0
err: 0
cachehit: 0
ICMP
xmit: 0
rexmit: 0
recv: 0
fw: 0
drop: 0
chkerr: 0
lenerr: 0
memerr: 0
rterr: 0
proterr: 0
opterr: 0
err: 0
cachehit: 0
UDP
xmit: 1
rexmit: 0
recv: 0
fw: 0
drop: 0
chkerr: 0
lenerr: 0
memerr: 0
rterr: 0
proterr: 0
opterr: 0
err: 0
cachehit: 0
TCP
xmit: 0
rexmit: 0
recv: 0
fw: 0
drop: 0
chkerr: 0
lenerr: 0
memerr: 0
rterr: 0
proterr: 0
opterr: 0
err: 0
cachehit: 0
PBUF
avail: 32
used: 0
max: 0
err: 0
alloc_locked: 0
refresh_locked: 0
MEM HEAP
avail: 65536
used: 100
max: 188
err: 0
MEM PBUF
avail: 32
used: 0
max: 0
err: 0
MEM RAW_PCB
avail: 4
used: 0
max: 0
err: 0
MEM UDP_PCB
avail: 4
used: 1
max: 1
err: 0
MEM TCP_PCB
avail: 5
used: 0
max: 0
err: 0
MEM TCP_PCB_LISTEN
avail: 8
used: 0
max: 0
err: 0
MEM TCP_SEG
avail: 16
used: 0
max: 0
err: 0
MEM NETBUF
avail: 0
used: 0
max: 0
err: 0
MEM NETCONN
avail: 0
used: 0
max: 0
err: 0
MEM API_MSG
avail: 0
used: 0
max: 0
err: 0
MEM TCP_MSG
avail: 0
used: 0
max: 0
err: 0
MEM TIMEOUT
avail: 0
used: 0
max: 0
err: 0
--
View this message in context: http://www.nabble.com/how-to-send-udp-messages-circularly---tp24321123p24386993.html
Sent from the lwip-users mailing list archive at Nabble.com.
_______________________________________________
That's going to be a big problem - 0.7.1 is over 5 years old, and lwIP
has changed a lot since then. I would try and find a more up to date
port.
Kieran
Wow, that's really old.
> http://forum.niosforum.com/forum/index.php?showtopic=949 (I haven't
> found
> any newly than it )
> This version even do not have stats_diplay ,i modified lwip/stats.c and
> stats.h depend on lwip-1.1.0.luckily,it display well :)
Even 1.1.0 is too old. Please upgrade to 1.3.0 (or even 1.3.1 release candidate in some weeks) and try again. I'm afraid we cannot help you with such an old version as 0.7.1.
To upgrade the version yourself, just download 1.3.0 from http://savannah.nongnu.org/projects/lwip (-> go to download section) and replace the old 0.7.1 version with the new version. After recompiling your NIOS project, and fixing the warnings you get during compiling, it should just work.
Oh, and the stats you printed indicate there are *no* packets received at all. This is a bit strange but might be a problem of your old version or port.
Simon
--
Neu: GMX Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
für nur 19,99 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02
Are you sure it should just work? I would be pleasantly surprised if no
changes were needed to the port with such a big change in lwIP. Can
anyone report success with a change like this?
Kieran
Your sincerely
the_gadfly
--
View this message in context: http://www.nabble.com/how-to-send-udp-messages-circularly---tp24321123p24391009.html
Sent from the lwip-users mailing list archive at Nabble.com.
_______________________________________________
Hm, I don't know about 0.7.1, but he talked also about 1.1.0 and that's
what I did to get an existing port to work with 1.3.0: copied it, got
some (minor) compiling errors, fixed them and it worked. Since I started
working with lwIP when 1.1.0 was out, I don't know about 0.7.1 :-(
Anyway, Altera has been shipping 1.1.0 or 1.2.0 with their NIOS-II
development software for some years now, and that version is surely easy
to upgrade to 1.3.0.
Simon
Why did you download an old version from the forums when Altera ships a
newer version with the NIOS-II EDS? They are supporting Interniche as
'primary' TCP/IP stack, but lwIP is still shipped for 'legacy' projects
(or at least with the last version I checked last year).
I think I remember this software being free for private usage and
available at www.altera.com.
I have their Cyclone III 8.1 NEEK development kit and it had nothing lwIP
related in it except for an Ethernet driver for the lan91c111 in files:
altera_avalon_lan91c111.c
altera_avalon_lan91c111.h
altera_avalon_lan91c111_lwip.h
altera_avalon_lan91c111_regs.h
Bill
I think the last version I checked it with was 7.0, but you had to
manually select to install it during setup. Do they only deliver the
Interniche stack with current versions? That's too bad :-(
Simon
They supply only Interniche for the following reasons:
1. It's allegedly supported - most code is Interniche's, some is Altera's.
2. It supports Altera's Triple Speed Ethernet for the Cyclone II/III and
Stratix. I found no driver for this TSE for lwip.
But the problems/disadvantages with Interniche:
1. Interniche requires uC/OS-II. They have a "super loop" non-OS interface
but it's undocumented and I found no evidence of anyone saying they got it
to work.
2. It has a nominal fee for the basic stuff. Add-ons (SNMP, etc.) cost
more.
3. Even the lowest level parts of their Ethernet driver are tied into
Interniche source and data structures. This makes porting lwIP to the TSE
very difficult.
4. Their TSE driver is buggy - even in the parts that can be adapted for use
with lwIP. One bug is evident by a compiler warning in production code. I
had no problem locking up their driver in testing.
5. Their driver is inefficient (e.g., 4-deep function calls to set up DMA,
the TX routine polls waiting for each TX packet to be sent, if the TX is
unaligned, there is a memcpy in the driver to an aligned buffer which is
then TXed, etc.).
6 They support scatter-gather DMA in hardware but their driver doesn't take
advantage of it.
7. Software timing loops may have to be adjusted to allow auto-negotiation
to complete.
8. They document max 108MbS on a GigE link using as optimized a hardware
system as they could including hardware checksumming.
9. It's not nearly as configurable as lwIP.
The good parts:
1. It works out of the box. But bugs are evident if it's stressed in any
way and under some error conditions.
2. The scatter-gather DMA is nice if utilized.
3. The included WEB server is fairly complete.
Bill
Just this week I found bugs in Interniche IP fragmentation routines as
well as in the handling of IP options.
> The good parts:
> 2. The scatter-gather DMA is nice if utilized.
>
Most processors with integrated 100Mbit MAC supports scatter-gather.
Not really a noteworthy feature unless it supports some more advanced
features such as automatic TCP/IP header length detection so that the
scatter transfer can separate the TCP/IP or UDP/IP header from the
payload, even when the headers may have varying lengths due to header
options and vlan tags.
If combined with a finely grained MMU, such a feature would allow true
zero copy without the hazzle of having to handle pbuf chains in the
application layer.
/Timmy Brolin
Well, I do think simple scatter/gather is a worthy feature for TX since
lwIP can create pbuf queues that then don't have to be memcpy'd before
sending. I'd say automatic length detection is 'nice-to-have' as a
speedup, but 2-byte alignmen instertion after the MAC header often also
does the trick
Simon
Did you manage to implement "a udp client that only sends data to PC" ?
can you share code or give a noob a hint at where to start?
Cheers.
Sir
--
View this message in context: http://www.nabble.com/how-to-send-udp-messages-circularly---tp24321123p25453430.html