Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12621 Discussions

Altera TSE driver and example program for lwIP (1.3.2)

Altera_Forum
Honored Contributor II
20,076 Views

After many many requests and complaints about lack of support and/or documentation for support of lwIP for the Altera TSE, I have developed a drop-in TSE driver and example program and made this available to the NIOS II community. This was done for NIOS II 8.1 SP0.01. I don't expect difficulty with version 9.x. 

 

This is for the latest version of lwIP (the latest is as of this post) for a minimal program and HTTP server based on the http server in the lwIP contrib folder. The lwIP TSE driver uses the altera_avalon_tse driver and SGDMA as-is. There is a complete (as in 41-step) set of instructions on creating the project and example program. More information and the link to the driver is available here: 

 

http://lwip.wikia.com/wiki/available_device_drivers#lwip_1.3.2 

 

Please direct any questions, changes for NIOS II 9.1, or comments to this thread. 

 

12-16-2010 update: This example works with NIOS Version 10.0 with some tweaks to the procedure to create the project. Also, a lwIP 1.4 release candidate has been out for a while and it drops into this example (in place of 1.3) without changes. 

 

Bill
0 Kudos
257 Replies
Altera_Forum
Honored Contributor II
1,180 Views

Dear BillA 

Let me give the description of my probelms. I download the LwIP 1.4 and lwip_altera_tse_driver,and set up the Nios2 and TSE sopc project according to some standard TSE Project.The PHY may be is OK,becaucle the net speed in my host displayed is 100Mbps, But I can't send or receive UDP packet, can't set the speed from 100Mbps to 1000Mbps, there are nothing in the interface when I send or receive any packet.I can't down load the example. Can you post the LwIP example again, or send the TSE SoPC project to me,my emails is cngaoxf @yahoo.com.cn. Thank you Let me give my best wishes to you.
0 Kudos
Altera_Forum
Honored Contributor II
1,180 Views

Dear ims 

can you post all the software of udp offload, not just udp_test.c which I can't compile successfully. best Wishes to you
0 Kudos
Altera_Forum
Honored Contributor II
1,180 Views

Dear xf.gao; I’ve sent to your email the code completing udp_test.c from my post (#35). This is basically just an original Bill’s example upgraded with lwIP-1.4.0rc1. You should be able to run the example if (and only if) you are able to run standard Altera’s SimpleSocketServer on your board also. There are no any special requirements to SOPC or BSP. Regards, Igor.

0 Kudos
Altera_Forum
Honored Contributor II
1,180 Views

Dear BillA or ims 

Let me give the description of my probelms in details. I download the LwIP 1.4 and lwip_altera_tse_driver and udp_test,and set up the Nios2 and TSE sopc project according to some standard TSE Project.The PHY may be is OK,becaucle the net speed in my host displayed is 100Mbps, But I can't send or receive UDP packet, can't set the speed from 100Mbps to 1000Mbps, there are nothing in the interface when I send or receive any packet.I can't down load the example. Can you post the LwIPexample again, or send the TSE SoPC project to me,my emails is cngaoxf @yahoo.com.cn. Thank you Let me give my best wishes to you.
0 Kudos
Altera_Forum
Honored Contributor II
1,180 Views

xf.gao, 

 

I think you need to go deeper than the software. Check the wiring to and from the PHY. There is nothing special about the lwIP example. As IMS and I have said a few times here, load the Altera Simple Socket Server demo and debug that because you know without question that should work. If that won't work, it probably is hardware or something in SOPC. But our SOPC won't help you because it's probably the pin connections are bad. The way we connected SGDMA, Descriptor Memory and the busses to the NIOS II CPU are standard. We also followed a basic TSE SOPC example to get going. Be sure your clocks, bridges and desc memory are done exactly as in the example. Hmmm, maybe this is even as simple the hardware is bad or has a bad component. 

 

To answer you directly, I cannot provide the SOPC file since it has our entire product design included. I'll add that we did nothing special with the TSE, SGDMA, Desc Mem and bridges as the reference design we used. 

 

Bill
0 Kudos
Altera_Forum
Honored Contributor II
1,180 Views

Hello, 

sorry for taking up old thread, but did anyone try data receive using LwIP? Whats the maximum throughput? Is it possible to achieve at least 80Mbit/s using 100Mbps link? I suppose data reception should be easier, if I don't need to recalculate checksums and move data to DMA.
0 Kudos
Altera_Forum
Honored Contributor II
1,180 Views

Throughput is dependent on many things - both NIOS II system related things and lwIP build/options related things. There are many things you can do to improve performance - somewhere in this thread IIRC I listed them in what I perceive as the order of importance. 

 

All of our lwIP based NIOS II products have high performance requirements. One was Gigabit and required high transmit bandwidth and TCP couldn't be used so we used our own reliable UDP protocol. We had no problems with 500Mb. The latest product is GigaBit too but performance for receiving is important. We have better performance to run 10/100 over 1000! We have 40Mb throughput and this is far more than we need so no special protocol was used. But in all of these systems internet checksumming is done in the FPGA (Cyclone III). This 40Mb is an effective average rate for us - let me do a test for sustained receive bandwidth and I'll post back here. 

 

So to correct you, receiving is harder (slower) than sending - by quite a bit. And remember, the more you do to improve TCP/IP speeds the less time the NIOS II has for other tasks. You can probably do 80Mb receive but you'd have no time to do anything with the data. :) 

 

High speeds can be achieved but you may have to do a lot to get there. 

 

Bill
0 Kudos
Altera_Forum
Honored Contributor II
1,179 Views

Well basically I need to move received data to DMA or vice-versa. 

I've made such set up: Packet formation in logic (incl. IP checksum) -> SGDMA -> InterNiche. 

However, when I set up all the packet data in SGDMA interrupt, e.g. packet allocation in memory, reading from the dma memory, etc, the interrupt lasts so long, that 3.5mbps packet data is too fast. My data must go between 10-80mbps. The solution would be to write exactly to InterNiche packet buffer using DMA, but then I need to know where InterNiche place the buffer (which I suppose is just malloc/free stuff). Another problem is that I need to do packet allocation on every interrupt and I don't know why InterNiche does packet freeing or other internal stuff. 

The packet is sent using ip_write(). 

 

I would like to test LwIP for its performance in this case, or maybe someone has pointers for my InterNiche setup?
0 Kudos
Altera_Forum
Honored Contributor II
1,180 Views

Hello, 

I've tried to run lwIP on 10.1sp1, but the step-by-step instructions seems to be old. Maybe someone can update it for 10.1sp1 or even version 11.1? 

 

E.g. the 3rd instruction says: Use File -> New -> NIOS II C/C++ Application 

 

There's no such menu item now. Do I need to run "Nios II Application and BSP from Template" or just "C project" ? 

Later, do I need to use simple "Hello World" program or the one with uCOS? 

The menu has changed after step 25, I don't see debug/release settings. Also I am not sure if step 28 path still exists? Then how to set the paths? 

 

I get many include errors, which can't be resolved even adding include dirs like this: 

lwip_NIOS_II_Example -> Properties -> Nios II Application properties -> Nios II Application Paths -> adding all *.h files to the "Application include directories:" place. 

I suppose all the problems are because of bad paths. 

 

Thanks. 

Tomas D.
0 Kudos
Altera_Forum
Honored Contributor II
1,180 Views

Tomas, 

 

For v.11: 

1) Use File -> New -> Nios II Application and BSP from Template 

2) simple "Hello World" is OK 

3) Steps 25-28: Right-click project lwIP_NIOS_II_Example and select Properties, expand <Nios II Application Properties>, select <Nios II Application Paths>, add the paths into <Application include directories> 

 

As for the performance, probably it is possible to tweak lwIP or Iniche to meet your goal, but I would vote for hardware streaming (see UDPOFFLOAD example; ref in msg.# 36 this thread). In my project I use that cores for transmitting only, but receiving ones are also available. lwIP still can be used in background to handle non real-time communications (e.g. web-server or console). 

 

Igor
0 Kudos
Altera_Forum
Honored Contributor II
1,179 Views

 

--- Quote Start ---  

 

1) Use File -> New -> Nios II Application and BSP from Template 

2) simple "Hello World" is OK 

3) Steps 25-28: Right-click project lwIP_NIOS_II_Example and select Properties, expand <Nios II Application Properties>, select <Nios II Application Paths>, add the paths into <Application include directories> 

 

--- Quote End ---  

 

Thanks, will try this out. 

 

 

--- Quote Start ---  

 

As for the performance, probably it is possible to tweak lwIP or Iniche to meet your goal, but I would vote for hardware streaming (see UDPOFFLOAD example; ref in msg.# 36 this thread). In my project I use that cores for transmitting only, but receiving ones are also available. lwIP still can be used in background to handle non real-time communications (e.g. web-server or console). 

--- Quote End ---  

 

 

I've done transmit part using hardware implementation, however if I want full RTP implementation, I need RTSP and RTCP support. That RTCP control stuff (handshaking etc), should be done in lwIP. 

 

Now for receive part, my idea was to open a socket with defined protocol (in my case - UDP) and port. Then stream all the received data to the logic interconnect. I still need ARP/ping/etc, because data transfers doesn't begin if there's no ARP response. If I would choose fully hardware receive interface, then it would be like catching wind in the fields: checking many parameters, e.g. if the packet is ipv4, protocol udp, port, length, etc... Then all these things combined would allow packet to be moved for futher processing. Using a stack, I would like to use a socket for UDP and listen for certain port. All checksumming can be done in hardware. I hope to reach at least 200Mbps of rx stream using this method.
0 Kudos
Altera_Forum
Honored Contributor II
1,179 Views

Tomas, 

 

You do not have to re-implement hardware solution yourself. And you do not have to implement all the protocols in hardware – just mix hardware UDP with software processing for everything else. For received data, for example, using udp_port_to_channel_mapper from udpoffload lib you can split incoming Ethernet traffic into two Avalon-ST streams: 1) UDP packets to specific port; 2) all other ‘unmapped’ stuff. The first stream, as far as I understand, you are ready to handle in hardware. The second stream you can route to Nios and process through lwIP or Iniche to implement ARP, ICMP, RTCP, etc.
0 Kudos
Altera_Forum
Honored Contributor II
1,180 Views

 

--- Quote Start ---  

 

1) Use File -> New -> Nios II Application and BSP from Template 

2) simple "Hello World" is OK 

3) Steps 25-28: Right-click project lwIP_NIOS_II_Example and select Properties, expand <Nios II Application Properties>, select <Nios II Application Paths>, add the paths into <Application include directories> 

--- Quote End ---  

 

 

Firstly, I had problems with include files, so I've moved arch directory to src/include (which is in include path). 

Later, I had problems with lwipopts.h, so I've moved that header and all other .h files from ./ to src/include 

However, I still get compiler errors, trying to solve them now. Did someone experience something like me? 

 

BR, 

Tomas D.
0 Kudos
Altera_Forum
Honored Contributor II
1,180 Views

Tomas, the only paths you need for lwIP are ".", "./lwIP/src/include" and "./lwIP/src/include/ipv4" (assuming lwipopts.h, lwIP and arch folders reside in the root of your project). Moving headers across the tree is bad idea. Also, don't forget to delete ./lwIP/src/core/ipv6 folder.

0 Kudos
Altera_Forum
Honored Contributor II
1,180 Views

 

--- Quote Start ---  

Tomas, the only paths you need for lwIP are ".", "./lwIP/src/include" and "./lwIP/src/include/ipv4" (assuming lwipopts.h, lwIP and arch folders reside in the root of your project). Moving headers across the tree is bad idea. Also, don't forget to delete ./lwIP/src/core/ipv6 folder. 

--- Quote End ---  

 

 

Strange, I get compiler errors because headers are not found. Errors can be found here (http://pastebin.com/j9drkx95). 

 

You can see my tree and include options tree here (http://i55.tinypic.com/rubo60.jpg). 

 

Seems like arch directory should be in src/include? And lwipopts.h too?  

 

BR, 

Tomas D.
0 Kudos
Altera_Forum
Honored Contributor II
1,180 Views

Tomas, the first path should be "." (without slash). Open Makefile, find  

APP_INCLUDE_DIRS += ./ 

and delete trailing slash.
0 Kudos
Altera_Forum
Honored Contributor II
1,192 Views

 

--- Quote Start ---  

Tomas, the first path should be "." (without slash). Open Makefile, find  

APP_INCLUDE_DIRS += ./ 

and delete trailing slash. 

--- Quote End ---  

 

 

Thank You, seems like include problems are now gone. Almost... 

 

Now I get this error: 

**** Build of configuration Nios II for project lwIP_NIOS_II_Example **** make all Info: Building ../lwIP_NIOS_II_Example_bsp make --no-print-directory -C ../lwIP_NIOS_II_Example_bsp Info: Compiling main.c to obj/main.o nios2-elf-gcc -xc -MP -MMD -c -I../lwIP_NIOS_II_Example_bsp/drivers/inc -I../lwIP_NIOS_II_Example_bsp/HAL/inc -I../lwIP_NIOS_II_Example_bsp -I../lwIP_NIOS_II_Example_bsp/drivers/inc -I. -Isrc/include -Isrc/include/ipv4 -DSYSTEM_BUS_WIDTH=32 -pipe -D__hal__ -DALT_NO_INSTRUCTION_EMULATION -DALTERA_TRIPLE_SPEED_MAC -DALT_SINGLE_THREADED -O0 -g -Wall -EL -mno-hw-div -mhw-mul -mno-hw-mulx -o obj/main.o main.c main.c: In function 'lwipProcessTimers': main.c:143: error: 'TCP_TMR_INTERVAL' undeclared (first use in this function) main.c:143: error: (Each undeclared identifier is reported only once main.c:143: error: for each function it appears in.) main.c:143: warning: implicit declaration of function 'tcp_tmr' make: *** Error 1  

 

This define is in include/lwip/tcp_impl.h, however I don't want to add this include into main.c in case I am missing something else. 

 

BR, 

Tomas D.
0 Kudos
Altera_Forum
Honored Contributor II
1,192 Views

Tomas, I have# include "lwip/tcp_impl.h" in my main.c. In lwIP 1.3.2 TCP_TMR_INTERVAL was defined in tcp.h, but starting from lwIP 1.4.0rc1 this definition have been moved into tcp_impl.h. I don’t know why.

0 Kudos
Altera_Forum
Honored Contributor II
1,192 Views

Seems like this causes an error-chain :) 

 

Now I get error here: 

# if LWIP_TIMERS && (MEMP_NUM_SYS_TIMEOUT < (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT)) # error "MEMP_NUM_SYS_TIMEOUT is too low to accomodate all required timeouts"# endif  

 

Error: 

src/core/init.c:152:4: error:# error "MEMP_NUM_SYS_TIMEOUT is too low to accomodate all required timeouts"  

 

Either I need to increase MEMP_NUM_SYS_TIMEOUT or disable some options like DHCP, etc. I choose first one and increase MEMP_NUM_SYS_TIMEOUT from 3 to 5. Then I get these errors: 

 

obj/src/core/timers.o: In function `sys_timeouts_init': C:\Projects\cycloneIII_3c120_dev_niosII\software\lwIP_NIOS_II_Example/src/core/timers.c:245: undefined reference to `sys_now' obj/src/core/timers.o: In function `sys_check_timeouts': C:\Projects\cycloneIII_3c120_dev_niosII\software\lwIP_NIOS_II_Example/src/core/timers.c:365: undefined reference to `sys_now' obj/src/core/timers.o: In function `sys_restart_timeouts': C:\Projects\cycloneIII_3c120_dev_niosII\software\lwIP_NIOS_II_Example/src/core/timers.c:405: undefined reference to `sys_now' collect2: ld returned 1 exit status make: *** Error 1  

 

sys_now() is prototyped in sys.h, but I can't find the function itself. 

 

P.S. Maybe someone use lwIP with MicroC/OS-II?
0 Kudos
Altera_Forum
Honored Contributor II
1,192 Views

I have no experience with UCOS. Does it work without OS and with# define NO_SYS 1 in lwipopts.h?

0 Kudos
Altera_Forum
Honored Contributor II
1,192 Views

 

--- Quote Start ---  

I have no experience with UCOS. Does it work without OS and with# define NO_SYS 1 in lwipopts.h? 

--- Quote End ---  

 

 

No, then I get this: 

 

**** Build of configuration Nios II for project lwIP_NIOS_II_Example **** make all Info: Building ../lwIP_NIOS_II_Example_bsp make --no-print-directory -C ../lwIP_NIOS_II_Example_bsp Info: Compiling alteraTseEthernetif.c to obj/alteraTseEthernetif.o nios2-elf-gcc -xc -MP -MMD -c -I../lwIP_NIOS_II_Example_bsp/drivers/inc -I../lwIP_NIOS_II_Example_bsp/HAL/inc -I../lwIP_NIOS_II_Example_bsp -I../lwIP_NIOS_II_Example_bsp/drivers/inc -I. -Isrc/include -Isrc/include/ipv4 -DSYSTEM_BUS_WIDTH=32 -pipe -D__hal__ -DALT_NO_INSTRUCTION_EMULATION -DALTERA_TRIPLE_SPEED_MAC -DALT_SINGLE_THREADED -O0 -g -Wall -EL -mno-hw-div -mhw-mul -mno-hw-mulx -o obj/alteraTseEthernetif.o alteraTseEthernetif.c In file included from alteraTseEthernetif.c:47: src/include/lwip/sys.h:107: error: expected ')' before '*' token src/include/lwip/sys.h:110: error: expected ')' before '*' token src/include/lwip/sys.h:113: error: expected ')' before '*' token src/include/lwip/sys.h:116: error: expected ')' before '*' token src/include/lwip/sys.h:119: error: expected ')' before '*' token src/include/lwip/sys.h:123: error: expected ')' before '*' token src/include/lwip/sys.h:142: error: conflicting types for 'sys_arch_sem_wait' ./arch/sys_arch.h:60: error: previous declaration of 'sys_arch_sem_wait' was here src/include/lwip/sys.h:185: error: conflicting types for 'sys_arch_mbox_fetch' ./arch/sys_arch.h:57: error: previous declaration of 'sys_arch_mbox_fetch' was here alteraTseEthernetif.c: In function 'low_level_init': alteraTseEthernetif.c:83: warning: value computed is not used make: *** Error 1  

 

Maybe I should try 1.32, since the driver is old? Or maybe I should use hello world example with RTOS enabled?  

 

One guy here (afaik) on this thread succeeded running 1.4 or 1.4rc1, so I hope he could help me here. Ofcourse it would be perfect to get an example of working system with uC/OS-II and lwIP, but I still hope to do it myself.
0 Kudos
Reply