Hi,
Some news, I finally started to write a TCP/IP stack from scratch (named mbedNet), with performance and simplicity in head, using zero copy. All using 100% C code. This will be easily embeddable in C++ objects.
So far ping time on a 100Mbps LAN is around 150µs:
20 packets transmitted, 20 received, 0% packet loss, time 18997ms
rtt min/avg/max/mdev = 0.137/0.146/0.212/0.020 ms
I started to implement the socket API for UDP (the one I need the most for now).
Here is a sample initialization code:
#include <mbednet/mbedNetIF.h>
#include <mbednet/ARP.h>
#include <mbednet/ICMPv4.h>
#include <mbednet/UDPv4.h>
#include <mbednet/Sockets.h>
Ethernet_Addr_t myMAC = {0x00, 0x10, 0x33, 0x2e, 0x18, 0x7f};
IPv4_Addr_t ip = {192, 168, 138, 47},
netmask = {255, 255, 255, 0},
gateway = {192, 168, 138, 254};
NetIF_t *mbedNetIF;
mbedNetIF = NetIF_RegisterInterface(&ip, &netmask, &gateway, &mbedNetIF_Driver, (void *)&myMAC);
ethernet.RegisterProtocol(&arp); /* add ARP support over ethernet */
ethernet.RegisterProtocol(&ipv4); /* add IPv4 support over ethernet */
ipv4.RegisterProtocol(&icmpv4); /* add ICMPv4 support over IPv4 */
ipv4.RegisterProtocol(&udpv4); /* add UDPv4 support over IPv4 */
udpv4.RegisterAPI(&sockets); /* add socket API on UDPv4 */
The stack is very modular, and if a protocol or api isn't needed, it is easy to leave it aside.
Then have the frame processing in the application loop(s), or from a thread in a RTOS environment, by calling:
NetIF_ProcessFrames(); /* Non blocking call, will check for frames in the registered interfaces, process them if any, then return */
The Ethernet driver only uses 100% CMSIS code, no interrupt handler. I take advantage of the nice circular buffers provided by the EMAC block on the LPC1768 (nice piece of hardware).
My plans are to finish the stack up with complete implementation (v4 only, no IPv6 for the moment, but there is room for it) of:
- ARP (with arp cache and expiration)
- ICMP echo/reply
- IP
- UDP
- Sockets for raw frames and UDP
- loopback interface
The stack will be tunable for use in no RTOS environment as well as inside an RTOS environment which is providing the minimum services like FreeRTOS and CoOS for example (mutexes, mailboxes, semaphores, ...)
So far the stack is very fast and stable, it doesn't crash like all the bad experiences I had previously with the adaptations of lwIP (I'm not saying lwIP is problematic, but just that the ports so far to LPC1768 are not perfects, and lwIP is rather complex to configure).
I'll share a first version of the source code when it is usable.
Regards,
Benoît.
PS: I use this stack with CoOS v1.14 + latest CMSIS as libraries, it is very stable so far.
The current official port of the lwIP TCP/IP stack seems to only kinda work on mbed. It is not clear to me how others live with this, but certainly the lwIP stack is capable of performing better. If you want to see how lwIP is supposed to work on an ARM Cortex-M3 microcontroller, please watch the following YouTube video:
I see absolutely no reason why lwIP shouldn't work on mbed1768 at least as good as on the Stellaris LM3S6965 MCU, which is actually less capable than the LPC1768.
The first thing we need to fix the lwIP implementation on embed is the lwIP stack as a proper mbed library in source code, so that it can be reconfigured and recompiled for specific projects. To this end, I've just published the library lwip_1_4_0_rc2. This is the latest available lwIP 1.4.0.rc2 adapted to compile with the C++ mbed compiler. This library contains an unfinished Ethernet driver for mbed1768 in the file
eth_driver.cpp
. This is an interrupt-driven driver, which does not depend on the polled mbed Ethernet class. Instead, this driver is written only by means of the low-level CMSIS interface"LPC17xx.h"
.The Ethernet driver is incomplete yet, because without the proper debugger for mbed, and without really knowing how to configure the separate PHY of the mbed1768 board I ran out of time to make this work. I have left comments starting with 'TBD:' in all places that still need attention.
I really count here on the open source spirit of the mbed community to finish the job. I think that it would be great to have a robust TCP/IP stack and HTTP server with CGI and SSI, which wouldn't be just a toy, but could work in hard real-time applications that do other things than merely serving web pages or exchange TCP or UDP packets. It is really not much left to do to have such a library.
To test the lwip_1_4_0_rc2 library, I've also just published the (qp_lwip) test program. This test program should work on mbed1768 exactly like in the aforementioned video, except instead of writing to the OLED display it will blink LEDs on the mbed board.
Miro