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++
12745 Discussions

Altera TSE driver and example program for lwIP (1.3.2)

Altera_Forum
Honored Contributor II
39,934 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
2,069 Views

Tomas, I get the same errors if I define NO_SYS 0 instead of 1. Verify, that you have 

# define NO_SYS 1 

in lwipopts.h and that this macro is not redefined in your code or compiler args.
0 Kudos
Altera_Forum
Honored Contributor II
2,069 Views

 

--- Quote Start ---  

Tomas, I get the same errors if I define NO_SYS 0 instead of 1. Verify, that you have 

# define NO_SYS 1 

in lwipopts.h and that this macro is not redefined in your code or compiler args. 

--- Quote End ---  

 

 

Yep, I use NO_SYS 1, but the error occoured is about sys_now() function. 

 

**** 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: Linking lwIP_NIOS_II_Example.elf nios2-elf-g++ -T'../lwIP_NIOS_II_Example_bsp/linker.x' -msys-crt0='../lwIP_NIOS_II_Example_bsp/obj/HAL/src/crt0.o' -msys-lib=hal_bsp -L../lwIP_NIOS_II_Example_bsp -Wl,-Map=lwIP_NIOS_II_Example.map -O0 -g -Wall -EL -mno-hw-div -mhw-mul -mno-hw-mulx -o lwIP_NIOS_II_Example.elf obj/alteraTseEthernetif.o obj/fs.o obj/fsdata.o obj/httpd.o obj/lwip_tse_mac.o obj/main.o obj/src/api/api_lib.o obj/src/api/api_msg.o obj/src/api/err.o obj/src/api/netbuf.o obj/src/api/netdb.o obj/src/api/netifapi.o obj/src/api/sockets.o obj/src/api/tcpip.o obj/src/core/def.o obj/src/core/dhcp.o obj/src/core/dns.o obj/src/core/init.o obj/src/core/ipv4/autoip.o obj/src/core/ipv4/icmp.o obj/src/core/ipv4/igmp.o obj/src/core/ipv4/inet.o obj/src/core/ipv4/inet_chksum.o obj/src/core/ipv4/ip.o obj/src/core/ipv4/ip_addr.o obj/src/core/ipv4/ip_frag.o obj/src/core/mem.o obj/src/core/memp.o obj/src/core/netif.o obj/src/core/pbuf.o obj/src/core/raw.o obj/src/core/snmp/asn1_dec.o obj/src/core/snmp/asn1_enc.o obj/src/core/snmp/mib2.o obj/src/core/snmp/mib_structs.o obj/src/core/snmp/msg_in.o obj/src/core/snmp/msg_out.o obj/src/core/stats.o obj/src/core/sys.o obj/src/core/tcp.o obj/src/core/tcp_in.o obj/src/core/tcp_out.o obj/src/core/timers.o obj/src/core/udp.o obj/src/netif/etharp.o obj/src/netif/ethernetif.o obj/src/netif/ppp/auth.o obj/src/netif/ppp/chap.o obj/src/netif/ppp/chpms.o obj/src/netif/ppp/fsm.o obj/src/netif/ppp/ipcp.o obj/src/netif/ppp/lcp.o obj/src/netif/ppp/magic.o obj/src/netif/ppp/md5.o obj/src/netif/ppp/pap.o obj/src/netif/ppp/ppp.o obj/src/netif/ppp/ppp_oe.o obj/src/netif/ppp/randm.o obj/src/netif/ppp/vj.o obj/src/netif/slipif.o -lm 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  

 

This function has prototype in sys.h header file, but there is no function itself anywhere... Could You please check where sys_now() function exist in Your project files? 

 

Thanks. 

 

BR, 

Tomas D.
0 Kudos
Altera_Forum
Honored Contributor II
2,069 Views

Tomas, this function is not defined in my project. The only reference to sys_now() in tcp_out.c is removed by preprocessor due to LWIP_TCP_TIMESTAMPS is 0, and 3 references in timers.c — due to LWIP_TIMERS is 0. In lwIP 1.4.0rc1 LWIP_TIMERS is defined in lwIP/src/include/timers.h as  

# define LWIP_TIMERS (!NO_SYS || (NO_SYS && !NO_SYS_NO_TIMERS)) 

So, you should try 

# define NO_SYS_NO_TIMERS 1 

in lwipopts.h. I have this# define in my code (probably added while upgrading from v.1.3.2).
0 Kudos
Altera_Forum
Honored Contributor II
2,069 Views

Hm, there's no such define on lwipopts.h in 1.40. 

Could You please check whats defined here: 

#define MEMP_NUM_SYS_TIMEOUT 3If I leave this number 3, I get the fallowing error: 

 

src/core/init.c:152:4: error:# error "MEMP_NUM_SYS_TIMEOUT is too low to accomodate all required timeouts" make: *** Error 1 So I've increased it to 5. 

 

Maybe I should write to lwIP mailing list? 

 

Edit: 

 

commenting out those three lines of timers lets the code to compile. The system starts, sees that there is link (I've checked removing cable and it catches that there's no link), but arp doesn't respond. No arp - no ping response. 

 

If I create my own function called sys_now() which returns 32bit variable with a number, increased every main cycle - the results are the same.
0 Kudos
Altera_Forum
Honored Contributor II
2,069 Views

Tomas, 

1)# define MEMP_NUM_SYS_TIMEOUT 3 works fine for me 

2) You should ADD# define NO_SYS_NO_TIMERS 1 into lwipopts.h (for lwIP-1.3.2 this was not necessary)
0 Kudos
Altera_Forum
Honored Contributor II
2,069 Views

 

--- Quote Start ---  

 

2) You should ADD# define NO_SYS_NO_TIMERS 1 into lwipopts.h (for lwIP-1.3.2 this was not necessary) 

--- Quote End ---  

 

 

This line helped to solve compilation errors. Now the stack compiles, but it doesn't respond to ARP (and PING) requests. 

 

I am sure my design is OK, because Simple Socket Server and Web Server examples are working fine. 

 

I suppose the problem is RGMII interface. 

 

Edit: 

 

yep, that was RGMII issue - solved now by adding tse_my_system.c file from "Simple Socket Server (RGMII) example". 

 

The stack works, thanks for help! 

 

Edit2: 

 

Now would be cool to run this on uCOS RTOS :-) 

 

BR, 

Tomas D.
0 Kudos
Altera_Forum
Honored Contributor II
2,069 Views

There is a port of lwIP for FreeRTOS. I would think uCOS would be similar to implement (except for the price). 

 

lwIP 1.4.x also now includes an enhanced WEB server with SSI and CGI support. 

 

IPv6 is also available in beta and will be out in the next full lwIP update. 

 

Bill
0 Kudos
Altera_Forum
Honored Contributor II
2,069 Views

Great news! Maybe someone interested in writing a full manual to alterawiki?

0 Kudos
Altera_Forum
Honored Contributor II
2,069 Views

What would the alterawiki manual you wish for cover? There exists a wiki for lwIP although I admit it's far from great. lwIP is not really for a complete beginner at all, but it's a great TCP/IP solution and is well worth the effort if you or your company is serious about having a decent TCP/IP-enabled product. 

 

Bill
0 Kudos
Altera_Forum
Honored Contributor II
2,069 Views

Well, I've success running LwIP 1.4.0, but people is still asking for the same stuff that is deep in the forum instead on one place somewhere. That sample design runs fine, but it would be great to improve it by writing a manual how to modify it to add timer support, dma and all other possible optimizations.

0 Kudos
Altera_Forum
Honored Contributor II
2,069 Views

Yes, you're right - there is very little information to go on after the demo/example is running. Somewhere in this thread I gave a pretty good list of optimizations to implement. This example was meant to be run as easily as possible with the Eclipse IDE and exiting NIOS II libraries. The truth is we use a custom TSE and SGDMA driver because what is there is very inefficient. We also use the FPGA to speed up lwIP further (IP checksum, htons and htonl). We've also had to use UDP when TCP wasn't fast enough. 

 

Bill
0 Kudos
Altera_Forum
Honored Contributor II
2,069 Views

Hm there is simple TSE driver that works, I suppose it's quite good? What about SGDMA? I suppose existing Altera memory-to-memory sgdma should be enough? Anyway, if it's not a commercial secret and You have a spare minute, maybe You can contribute to Altera Wiki?

0 Kudos
Altera_Forum
Honored Contributor II
2,069 Views

Time for some optimizations. 

 

Do anyone use timers to run lwIP? Now I've defined NO_SYS_NO_TIMERS, but I have resources to add 250ms timer and enable LWIP_TIMERS. However if I undefine NO_SYS_NO_TIMERS, I get a chain of errors in all cases ending in unreferenced sys_now(). Where can I find documentation how to set up stack to use hardware timers? 

 

Thanks.
0 Kudos
Altera_Forum
Honored Contributor II
2,069 Views

Thanks for the driver! Works great! 

 

Made a full implementation with FreeRTOS 1.7.0 and LwIP 1.4. Currently working on full integration in the Nios II IDE so it can be used just like OS-II/InternNiche. I hope the port and demo will be added to the FreeRTOS ports / demo's else I will create an install script which sets up the environment. 

 

Yea for a much cheaper solution then the other combo ;)
0 Kudos
Altera_Forum
Honored Contributor II
2,069 Views

Great! Keep this thread updated about Your project :)

0 Kudos
Altera_Forum
Honored Contributor II
2,052 Views

Oke, I created the installer for the BSP, Software Package and Demo. It's available on the FreeRTOS Comunity Contributions page. However I can't post links yet... so if anybody could be so kind to create a link to the port and installer :) 

 

Goto freertos.org in the menu follow "FreeRTOS Interactive -> Download Contributions -> Altera (2) -> Nios updated port and demo for NiosEDS 11.0 and up (includes LwIP)" 

 

Currently we are done, but probably we are going to implement multiple PHY support in the near feature. Hope it's all clear...
0 Kudos
Altera_Forum
Honored Contributor II
2,052 Views

Great news! 

 

http://interactive.freertos.org/entries/20857252-nios-updated-port-and-demo-for-nioseds-11-0-and-up-includes-lwip 

 

Everything is running fine? I suppose there's a latest LwIP release, no modifications, NO_SYS_NO_TIMERS=1?
0 Kudos
Altera_Forum
Honored Contributor II
2,052 Views

FreeRTOS v7.1.0 and LwIP v1.4.0 without IPv6 support is used. 

 

In LwIP I made this patch I created "patch# 7702: Include ability to increase the socket number with defined offset" this so I could more easily build a wrapper for read / write / fnctl / close. I asked if this could be implemented in the dev tree, and maybe it will be if there is enough interest. 

 

I modified Bill's driver a bit, so it releases a semaphore on which the tcp_input task is waiting. This way this task will be rescheduled asap after an RX SGDMA IRQ. 

 

Because of you asked about NO_SYS_NO_TIMERS I checked it out and I noticed that I created my own timer and timer task which seems useless when NO_SYS is set to 0 so I just uploaded the update which disables the timer and timer task because this will be managed by LwIP itself. 

 

The only problem remaining is that I must 'fragmentate' the output myself, the web sever I created can't send the main page ( +/-16KB ) of html/js source in one go. I guess this has to do with an faulty configuration somewhere... still searching for a solution. Hitting the LwIP mailing list in a sec :)
0 Kudos
Altera_Forum
Honored Contributor II
2,052 Views

Hmm disabling the timer task was a bad idea, it makes the stack run quite unstable... enabled it again.

0 Kudos
Altera_Forum
Honored Contributor II
2,052 Views

Maybe it is worth using a hardware timer?

0 Kudos
Altera_Forum
Honored Contributor II
2,052 Views

I guess this would only make a little performance increase, because the only processing that safes is the alt_timer interface checking a timer each system tick right? Or am I overseeing something?

0 Kudos
Reply