Mercurial > ecos
view packages/io/eth/current/src/lwip/lw.diff @ 208:e0c0827131d1 ecos
Merge from eCos master repository on 2002-05-20-20:11:54-BST
| author | jlarmour |
|---|---|
| date | Mon, 20 May 2002 22:19:26 +0000 |
| parents | |
| children | d2c90368aeef |
line wrap: on
line source
diff -Nur lwip-0.5.3/proj/ecos/Makefile lwip.ecos/proj/ecos/Makefile --- lwip-0.5.3/proj/ecos/Makefile Thu Jan 1 02:00:00 1970 +++ lwip.ecos/proj/ecos/Makefile Tue Apr 2 18:17:49 2002 @@ -0,0 +1,76 @@ +CCDEP=arm-elf-gcc +CC=arm-elf-gcc +AR=arm-elf-ar +#CFLAGS=-g -Wall -DIPv4 -DLWIP_DEBUG +#CFLAGS=-Wall -DIPv4 +CFLAGS=-g -Wall -DIPv4 +LDFLAGS=-nostdlib -L$(ECOSLIB) -Ttarget.ld -Wl,-static -Wl,--gc-sections -finit-priority +LWIPARCH=ecos +ARFLAGS=rs +LWIPDIR=../../src + +ECOSDIR=/home/jani/ecos/build/lwip/edb/install +ECOSINC=$(ECOSDIR)/include +ECOSLIB=$(ECOSDIR)/lib + +CFLAGS:=$(CFLAGS) \ + -I$(LWIPDIR)/include -I$(LWIPDIR)/arch/$(LWIPARCH)/include -I$(LWIPDIR)/include/ipv4 \ + -Iapps -I$(ECOSINC) -I. + +# COREFILES, CORE4FILES: The minimum set of files needed for lwIP. +COREFILES=$(LWIPDIR)/core/mem.c $(LWIPDIR)/core/memp.c $(LWIPDIR)/core/netif.c \ + $(LWIPDIR)/core/pbuf.c $(LWIPDIR)/core/stats.c $(LWIPDIR)/core/sys.c \ + $(LWIPDIR)/core/tcp.c $(LWIPDIR)/core/tcp_input.c \ + $(LWIPDIR)/core/tcp_output.c $(LWIPDIR)/core/udp.c +CORE4FILES=$(LWIPDIR)/core/ipv4/icmp.c $(LWIPDIR)/core/ipv4/ip.c \ + $(LWIPDIR)/core/inet.c $(LWIPDIR)/core/ipv4/ip_addr.c + + +# APIFILES: The files which implement the sequential and socket APIs. +APIFILES=$(LWIPDIR)/api/api_lib.c $(LWIPDIR)/api/api_msg.c $(LWIPDIR)/api/tcpip.c \ + $(LWIPDIR)/api/err.c $(LWIPDIR)/api/sockets.c + +# NETIFFILES: Files implementing various generic network interface functions.' +NETIFFILES= $(LWIPDIR)/netif/arp.c + +# ARCHFILES: Architecture specific files. +ARCHFILES=$(wildcard $(LWIPDIR)/arch/$(LWIPARCH)/*.c $(LWIPDIR)/arch/$(LWIPARCH)/netif/*.c) + + +# APPFILES: Applications. +APPFILES=apps/tcpecho.c apps/httpd.c apps/fs.c apps/udpecho.c apps/shell.c + +# LWIPFILES: All the above. +LWIPFILES=$(COREFILES) $(CORE4FILES) $(APIFILES) $(NETIFFILES) $(ARCHFILES) +#LWIPFILESW=$(wildcard $(LWIPFILES)) +#LWIPOBJS=$(notdir $(LWIPFILESW:.c=.o)) +LWIPOBJS=$(notdir $(LWIPFILES:.c=.o)) + +LWIPLIB=liblwip4.a +APPLIB=liblwipapps.a +APPOBJS=$(notdir $(APPFILES:.c=.o)) + +%.o: + $(CC) $(CFLAGS) -c $(<:.o=.c) + +all ipv4 compile: simhost +.PHONY: all + +clean: + rm -f *.o $(LWIPLIB) $(APPLIB) simhost *.s .depend* *.core core + +depend dep: .depend + +include .depend + +$(APPLIB): $(APPOBJS) + $(AR) $(ARFLAGS) $(APPLIB) $? + +$(LWIPLIB): $(LWIPOBJS) + $(AR) $(ARFLAGS) $(LWIPLIB) $? + +.depend: simhost.c $(LWIPFILES) $(APPFILES) + $(CCDEP) $(CFLAGS) -MM $^ > .depend || rm -f .depend + +simhost: .depend $(LWIPLIB) $(APPLIB) simhost.o $(APPFILES) $(ECOSLIB)/libtarget.a + $(CC) $(CFLAGS) $(LDFLAGS) -o simhost simhost.o $(APPLIB) $(LWIPLIB) diff -Nur lwip-0.5.3/proj/ecos/README lwip.ecos/proj/ecos/README --- lwip-0.5.3/proj/ecos/README Thu Jan 1 02:00:00 1970 +++ lwip.ecos/proj/ecos/README Tue Apr 2 19:12:52 2002 @@ -0,0 +1,21 @@ +Building the test prog with ecos+lwip + +I suppose you have a working ecos build with your target.... + +There: + +#ecosconfig add net_drivers +and select lwip and unselect standalone driver and debugging +(after patching io/eth's cdl script with ioeth.diff first to see lwIP as an option) +and build the ecos libs as usual + + +Here: + +copy the files in unixsim/apps over here.Don't overwrite makefsdata or else the +httpd data won't be aligned and won't work on platforms which require >1 alignment (ARM) + +modify ECOSDIR in the Makefile to point to your ecos project dir +#make +and you should have an ecos exec with lwIP linked to it. + diff -Nur lwip-0.5.3/proj/ecos/apps/makefsdata lwip.ecos/proj/ecos/apps/makefsdata --- lwip-0.5.3/proj/ecos/apps/makefsdata Thu Jan 1 02:00:00 1970 +++ lwip.ecos/proj/ecos/apps/makefsdata Tue Apr 2 16:05:10 2002 @@ -0,0 +1,70 @@ +#!/usr/bin/perl + +open(OUTPUT, "> fsdata.c"); + +chdir("fs"); +open(FILES, "find . -type f -o -name CVS -a -prune -type f |"); + +while($file = <FILES>) { + + chop($file); + + open(HEADER, "> /tmp/header") || die $!; + print(HEADER "HTTP/1.0 200 OK\r\n"); + if($file =~ /\.html$/) { + print(HEADER "Content-Type: text/html\r\n"); + } elsif($file =~ /\.gif$/) { + print(HEADER "Content-Type: image/gif\r\n"); + } elsif($file =~ /\.png$/) { + print(HEADER "Content-Type: image/png\r\n"); + } elsif($file =~ /\.jpg$/) { + print(HEADER "Content-Type: image/jpeg\r\n"); + } else { + print(HEADER "Content-Type: text/plain\r\n"); + } + print(HEADER "\r\n"); + close(HEADER); + + system("cat /tmp/header $file > /tmp/file"); + + open(FILE, "/tmp/file"); + unlink("/tmp/file"); + unlink("/tmp/header"); + + $file =~ s/\.//; + $fvar = $file; + $fvar =~ s-/-_-g; + $fvar =~ s-\.-_-g; + print(OUTPUT "static const char data".$fvar."[] __attribute__ ((aligned)) = {\n"); + $i = 0; + while(read(FILE, $data, 1)) { + if($i == 0) { + print(OUTPUT "\t"); + } + printf(OUTPUT "%#02x, ", unpack("C", $data)); + $i++; + if($i == 10) { + print(OUTPUT "\n"); + $i = 0; + } + } + print(OUTPUT "};\n\n"); + close(FILE); + push(@fvars, $fvar); + push(@files, $file); +} + +for($i = 0; $i < @fvars; $i++) { + $file = $files[$i]; + $fvar = $fvars[$i]; + + if($i == 0) { + $prevfile = "NULL"; + } else { + $prevfile = "file" . $fvars[$i - 1]; + } + print(OUTPUT "static const struct fsdata_file file".$fvar."[] = {{$prevfile, \"$file\", "); + print(OUTPUT "data$fvar, sizeof(data$fvar)}};\n\n"); +} + +print(OUTPUT "#define FS_ROOT file$fvars[$i - 1]\n\n"); diff -Nur lwip-0.5.3/proj/ecos/lwipopts.h lwip.ecos/proj/ecos/lwipopts.h --- lwip-0.5.3/proj/ecos/lwipopts.h Thu Jan 1 02:00:00 1970 +++ lwip.ecos/proj/ecos/lwipopts.h Fri Mar 29 15:05:06 2002 @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels <adam@sics.se> + * + * $Id: lw.diff,v 1.1 2002/05/20 22:24:22 jlarmour Exp $ + */ +#ifndef __LWIPOPTS_H__ +#define __LWIPOPTS_H__ + +/* ---------- Memory options ---------- */ +/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which + lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2 + byte alignment -> define MEM_ALIGNMENT to 2. */ +#define MEM_ALIGNMENT 4 + +/* MEM_SIZE: the size of the heap memory. If the application will send +a lot of data that needs to be copied, this should be set high. */ +#define MEM_SIZE 1000 + +/* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application + sends a lot of data out of ROM (or other static memory), this + should be set high. */ +#define MEMP_NUM_PBUF 8 +/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One + per active UDP "connection". */ +#define MEMP_NUM_UDP_PCB 4 +/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP + connections. */ +#define MEMP_NUM_TCP_PCB 5 +/* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP + connections. */ +#define MEMP_NUM_TCP_PCB_LISTEN 8 +/* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP + segments. */ +#define MEMP_NUM_TCP_SEG 8 +/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active + timeouts. */ +#define MEMP_NUM_SYS_TIMEOUT 3 + + +/* The following four are used only with the sequential API and can be + set to 0 if the application only will use the raw API. */ +/* MEMP_NUM_NETBUF: the number of struct netbufs. */ +#define MEMP_NUM_NETBUF 2 +/* MEMP_NUM_NETCONN: the number of struct netconns. */ +#define MEMP_NUM_NETCONN 4 +/* MEMP_NUM_APIMSG: the number of struct api_msg, used for + communication between the TCP/IP stack and the sequential + programs. */ +#define MEMP_NUM_API_MSG 8 +/* MEMP_NUM_TCPIPMSG: the number of struct tcpip_msg, which is used + for sequential API communication and incoming packets. Used in + src/api/tcpip.c. */ +#define MEMP_NUM_TCPIP_MSG 8 + +/* These two control is reclaimer functions should be compiled + in. Should always be turned on (1). */ +#define MEM_RECLAIM 1 +#define MEMP_RECLAIM 1 + +/* ---------- Pbuf options ---------- */ +/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */ +#define PBUF_POOL_SIZE 6 + +/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */ +#define PBUF_POOL_BUFSIZE 128 + +/* PBUF_LINK_HLEN: the number of bytes that should be allocated for a + link level header. */ +#define PBUF_LINK_HLEN 16 + +/* ---------- TCP options ---------- */ +#define LWIP_TCP 1 +#define TCP_TTL 255 + +/* Controls if TCP should queue segments that arrive out of + order. Define to 0 if your device is low on memory. */ +#define TCP_QUEUE_OOSEQ 1 + +/* TCP Maximum segment size. */ +#define TCP_MSS 128 + +/* TCP sender buffer space (bytes). */ +#define TCP_SND_BUF 256 + +/* TCP sender buffer space (pbufs). This must be at least = 2 * + TCP_SND_BUF/TCP_MSS for things to work. */ +#define TCP_SND_QUEUELEN 4 * TCP_SND_BUF/TCP_MSS + +/* TCP receive window. */ +#define TCP_WND 1024 + +/* Maximum number of retransmissions of data segments. */ +#define TCP_MAXRTX 12 + +/* Maximum number of retransmissions of SYN segments. */ +#define TCP_SYNMAXRTX 4 + +/* ---------- ARP options ---------- */ +#define ARP_TABLE_SIZE 10 + +/* ---------- IP options ---------- */ +/* Define IP_FORWARD to 1 if you wish to have the ability to forward + IP packets across network interfaces. If you are going to run lwIP + on a device with only one network interface, define this to 0. */ +#define IP_FORWARD 1 + +/* If defined to 1, IP options are allowed (but not parsed). If + defined to 0, all packets with IP options are dropped. */ +#define IP_OPTIONS 1 + +/* ---------- ICMP options ---------- */ +#define ICMP_TTL 255 + + +/* ---------- DHCP options ---------- */ +/* Define LWIP_DHCP to 1 if you want DHCP configuration of + interfaces. DHCP is not implemented in lwIP 0.5.1, however, so + turning this on does currently not work. */ +#define LWIP_DHCP 0 + +/* 1 if you want to do an ARP check on the offered address + (recommended). */ +#define DHCP_DOES_ARP_CHECK 1 + +/* ---------- UDP options ---------- */ +#define LWIP_UDP 1 +#define UDP_TTL 255 + + +/* ---------- Statistics options ---------- */ +#define STATS + +#ifdef STATS +#define LINK_STATS +#define IP_STATS +#define ICMP_STATS +#define UDP_STATS +#define TCP_STATS +#define MEM_STATS +#define MEMP_STATS +#define PBUF_STATS +#define SYS_STATS +#endif /* STATS */ + +#endif /* __LWIPOPTS_H__ */ diff -Nur lwip-0.5.3/proj/ecos/simhost.c lwip.ecos/proj/ecos/simhost.c --- lwip-0.5.3/proj/ecos/simhost.c Thu Jan 1 02:00:00 1970 +++ lwip.ecos/proj/ecos/simhost.c Fri Mar 29 14:45:33 2002 @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels <adam@sics.se> + * + * $Id: lw.diff,v 1.1 2002/05/20 22:24:22 jlarmour Exp $ + */ + +#include "lwip/debug.h" + +#include <unistd.h> + +#include "lwip/opt.h" + +#include "lwip/mem.h" +#include "lwip/memp.h" +#include "lwip/sys.h" + +#include "lwip/stats.h" + +#include "netif/ecosif.h" +//#include "netif/loopif.h" + +#include "lwip/tcpip.h" + +#include "lwip/ip_addr.h" + +#include "arch/perf.h" + +#include "httpd.h" +#include "tcpecho.h" +#include "udpecho.h" +#include "shell.h" + +/*-----------------------------------------------------------------------------------*/ +static void +tcp_timeout(void *data) +{ +#if TCP_DEBUG + tcp_debug_print_pcbs(); +#endif /* TCP_DEBUG */ + sys_timeout(5000, tcp_timeout, NULL); +} +/*-----------------------------------------------------------------------------------*/ +static void +tcpip_init_done(void *arg) +{ + sys_sem_t *sem; + sem = arg; + sys_sem_signal(*sem); +} +/*-----------------------------------------------------------------------------------*/ +static void +main_thread(void *arg) +{ + struct ip_addr ipaddr, netmask, gw; + sys_sem_t sem; + netif_init(); + + sem = sys_sem_new(0); + tcpip_init(tcpip_init_done, &sem); + sys_sem_wait(sem); + sys_sem_free(sem); + printf("TCP/IP initialized.\n"); + + IP4_ADDR(&gw, 192,168,1,1); + IP4_ADDR(&ipaddr, 192,168,1,99); + IP4_ADDR(&netmask, 255,255,255,0); + + netif_set_default(netif_add(&ipaddr, &netmask, &gw, ecosif_init, tcpip_input)); + IP4_ADDR(&gw, 127,0,0,1); + IP4_ADDR(&ipaddr, 127,0,0,1); + IP4_ADDR(&netmask, 255,0,0,0); + +// netif_add(&ipaddr, &netmask, &gw, loopif_init, tcpip_input); +// udpecho_init(); +// shell_init(); +// tcpecho_init(); + httpd_init(); + printf("Applications started.\n"); + /* Block for ever. */ + sem = sys_sem_new(0); + sys_sem_wait(sem); +} +/*-----------------------------------------------------------------------------------*/ +int +main(int argc, char **argv) +{ +#ifdef STATS + stats_init(); +#endif /* STATS */ + sys_init(); + mem_init(); + memp_init(); + pbuf_init(); + + + + printf("System initialized.\n"); + + sys_thread_new((void *)(main_thread), (void*)"simhost"); + while(1) + {cyg_thread_delay(1000);} + return 0; +} +/*-----------------------------------------------------------------------------------*/ + + + + + + + + diff -Nur lwip-0.5.3/src/arch/ecos/README lwip.ecos/src/arch/ecos/README --- lwip-0.5.3/src/arch/ecos/README Thu Jan 1 02:00:00 1970 +++ lwip.ecos/src/arch/ecos/README Tue Apr 2 19:17:23 2002 @@ -0,0 +1,47 @@ +eCos port of lwIP +====================== + +Introduction +------------- +This is a beta version of the lwIP port to eCos.It was tested on a Cirrus Logic +EDB72111 board with ARM and it responds to ping and runs the unixsim apps(http,tcpecho,shell,etc) +The motivation behind it is that the current TCP stack in eCos is too large both +as code size and as memory footprint for a board with 128K FLASH + 128K RAM. +BTW this port is just working it still need optimization. + +Description +------------ + +The port consists of 3 main parts + +I) the eCos specific sys_arch implemetation +- src/arch/ecos/sys_arch.c +- sys/arch/ecos/include/.... +This maps lwIP semaphores, mailboxes and threads to their eCos counterparts +along with the required header files defining endianness and primitive data types + +II) the interface to the hw network drivers +- io/eth/lwip/eth_drv.c in the eCos repository +This part consists of a hardware independent net driver which glues eCos +low-level ethernet drivers to the lwIP stack (modeled after the two such drivers +existing in eCos : the standalone for RedBoot and the other one for the BSD stack) +This driver implements the 3 callbacks needed by hw specific drivers. +It currently uses the polling model like the standalone driver and not interrupts. +This makes the whole thing less intrusive + +III) the eCos specific lwIP netif +- src/arch/ecos/netif/ecosif.c +This file implements the lwIP netif model with init/input/output functions.This +calls into and is called from eth_drv.c described above + +Usage +------- + +The way to build an eCos app with lwIP is to just link the lwIP libs to your app and then +the whole thing to libtarget.a from eCos as usual.So this way lwIP is more like part of you app +than part of eCos.For an example of Makefile see the one in proj/ecos heavily based on +unixim/ecos from the lwip distribution. + +The organisation should change.Ideally there would be an eCos package +to simply add to your project and configure just like any other package. + diff -Nur lwip-0.5.3/src/arch/ecos/include/arch/cc.h lwip.ecos/src/arch/ecos/include/arch/cc.h --- lwip-0.5.3/src/arch/ecos/include/arch/cc.h Thu Jan 1 02:00:00 1970 +++ lwip.ecos/src/arch/ecos/include/arch/cc.h Thu Mar 14 23:23:00 2002 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels <adam@sics.se> + * + * $Id: lw.diff,v 1.1 2002/05/20 22:24:22 jlarmour Exp $ + */ +#ifndef __ARCH_CC_H__ +#define __ARCH_CC_H__ + +typedef unsigned char u8_t; +typedef signed char s8_t; +typedef unsigned short u16_t; +typedef signed short s16_t; +typedef unsigned long u32_t; +typedef signed long s32_t; + + +#define PACK_STRUCT_FIELD(x) x __attribute__((packed)) +#define PACK_STRUCT_STRUCT __attribute__((packed)) +#define PACK_STRUCT_BEGIN +#define PACK_STRUCT_END + +#endif /* __ARCH_CC_H__ */ diff -Nur lwip-0.5.3/src/arch/ecos/include/arch/cpu.h lwip.ecos/src/arch/ecos/include/arch/cpu.h --- lwip-0.5.3/src/arch/ecos/include/arch/cpu.h Thu Jan 1 02:00:00 1970 +++ lwip.ecos/src/arch/ecos/include/arch/cpu.h Fri Mar 15 22:08:00 2002 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels <adam@sics.se> + * + * $Id: lw.diff,v 1.1 2002/05/20 22:24:22 jlarmour Exp $ + */ +#ifndef __ARCH_CPU_H__ +#define __ARCH_CPU_H__ + +#if (CYG_BYTEORDER == CYG_LSBFIRST) +#define BYTE_ORDER LITTLE_ENDIAN +#else +#define BYTE_ORDER BIG_ENDIAN +#endif + +#endif /* __ARCH_CPU_H__ */ diff -Nur lwip-0.5.3/src/arch/ecos/include/arch/init.h lwip.ecos/src/arch/ecos/include/arch/init.h --- lwip-0.5.3/src/arch/ecos/include/arch/init.h Thu Jan 1 02:00:00 1970 +++ lwip.ecos/src/arch/ecos/include/arch/init.h Wed Dec 12 00:00:00 2001 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels <adam@sics.se> + * + * $Id: lw.diff,v 1.1 2002/05/20 22:24:22 jlarmour Exp $ + */ +#ifndef __ARCH_INIT_H__ +#define __ARCH_INIT_H__ + +#define TCPIP_INIT_DONE(arg) sys_sem_signal(*(sys_sem_t *)arg) + +#endif /* __ARCH_INIT_H__ */ + + + + diff -Nur lwip-0.5.3/src/arch/ecos/include/arch/lib.h lwip.ecos/src/arch/ecos/include/arch/lib.h --- lwip-0.5.3/src/arch/ecos/include/arch/lib.h Thu Jan 1 02:00:00 1970 +++ lwip.ecos/src/arch/ecos/include/arch/lib.h Thu Mar 14 23:27:00 2002 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels <adam@sics.se> + * + * $Id: lw.diff,v 1.1 2002/05/20 22:24:22 jlarmour Exp $ + */ +#ifndef __ARCH_LIB_H__ +#define __ARCH_LIB_H__ + +#endif /* __ARCH_LIB_H__ */ diff -Nur lwip-0.5.3/src/arch/ecos/include/arch/perf.h lwip.ecos/src/arch/ecos/include/arch/perf.h --- lwip-0.5.3/src/arch/ecos/include/arch/perf.h Thu Jan 1 02:00:00 1970 +++ lwip.ecos/src/arch/ecos/include/arch/perf.h Wed Dec 12 00:00:00 2001 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels <adam@sics.se> + * + * $Id: lw.diff,v 1.1 2002/05/20 22:24:22 jlarmour Exp $ + */ +#ifndef __PERF_H__ +#define __PERF_H__ + +#define PERF_START /* null definition */ +#define PERF_STOP(x) /* null definition */ + +#endif /* __PERF_H__ */ diff -Nur lwip-0.5.3/src/arch/ecos/include/arch/sys_arch.h lwip.ecos/src/arch/ecos/include/arch/sys_arch.h --- lwip-0.5.3/src/arch/ecos/include/arch/sys_arch.h Thu Jan 1 02:00:00 1970 +++ lwip.ecos/src/arch/ecos/include/arch/sys_arch.h Thu Mar 14 23:53:00 2002 @@ -0,0 +1,13 @@ +#ifndef __SYS_ECOS_H__ +#define __SYS_ECOS_H__ + +#include <cyg/kernel/kapi.h> + +#define SYS_MBOX_NULL (sys_mbox_t)NULL +#define SYS_SEM_NULL (sys_sem_t)NULL + +typedef cyg_sem_t * sys_sem_t; +typedef cyg_handle_t sys_mbox_t; +typedef cyg_thread * sys_thread_t; +#endif /* __SYS_ECOS_H__ */ + diff -Nur lwip-0.5.3/src/arch/ecos/include/netif/ecosif.h lwip.ecos/src/arch/ecos/include/netif/ecosif.h --- lwip-0.5.3/src/arch/ecos/include/netif/ecosif.h Thu Jan 1 02:00:00 1970 +++ lwip.ecos/src/arch/ecos/include/netif/ecosif.h Tue Mar 19 23:38:00 2002 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels <adam@sics.se> + * + * $Id: lw.diff,v 1.1 2002/05/20 22:24:22 jlarmour Exp $ + */ +#ifndef __ECOSIF_H__ +#define __ECOSIF_H__ + +#include "lwip/netif.h" + +void ecosif_init(struct netif *netif); + +#endif /* __ECOSIF_H__ */ diff -Nur lwip-0.5.3/src/arch/ecos/lib_arch.c lwip.ecos/src/arch/ecos/lib_arch.c --- lwip-0.5.3/src/arch/ecos/lib_arch.c Thu Jan 1 02:00:00 1970 +++ lwip.ecos/src/arch/ecos/lib_arch.c Wed Dec 12 00:00:00 2001 @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels <adam@sics.se> + * + * $Id: lw.diff,v 1.1 2002/05/20 22:24:22 jlarmour Exp $ + */ + +/* These are generic implementations of various library functions used + * throughout the lwIP code. When porting, those should be optimized + * for the particular processor architecture, preferably coded in + * assembler. + */ + +#include "lwip/arch.h" + +u16_t +htons(u16_t n) +{ + return ((n & 0xff) << 8) | ((n & 0xff00) >> 8); +} +/*-----------------------------------------------------------------------------------*/ +u16_t +ntohs(u16_t n) +{ + return htons(n); +} +/*-----------------------------------------------------------------------------------*/ +u32_t +htonl(u32_t n) +{ + return ((n & 0xff) << 24) | + ((n & 0xff00) << 8) | + ((n & 0xff0000) >> 8) | + ((n & 0xff000000) >> 24); +} +/*-----------------------------------------------------------------------------------*/ +u32_t +ntohl(u32_t n) +{ + return htonl(n); +} +/*-----------------------------------------------------------------------------------*/ +void +bcopy(const void *src, void *dst, unsigned int size) +{ + char *csrc, *cdst; + unsigned int i; + + csrc = (char *)src; + cdst = dst; + + for(i = 0; i < size; ++i) { + cdst[i] = csrc[i]; + } +} +/*-----------------------------------------------------------------------------------*/ +void +bzero(void *s, int n) +{ + for(--n ;n >= 0; --n) { + ((char *)s)[n] = 0; + } +} +/*-----------------------------------------------------------------------------------*/ diff -Nur lwip-0.5.3/src/arch/ecos/netif/ecosif.c lwip.ecos/src/arch/ecos/netif/ecosif.c --- lwip-0.5.3/src/arch/ecos/netif/ecosif.c Thu Jan 1 02:00:00 1970 +++ lwip.ecos/src/arch/ecos/netif/ecosif.c Tue Apr 2 16:13:46 2002 @@ -0,0 +1,327 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels <adam@sics.se> + * + * $Id: lw.diff,v 1.1 2002/05/20 22:24:22 jlarmour Exp $ + */ + +#include "lwip/debug.h" + +#include "lwip/opt.h" +#include "lwip/def.h" +#include "lwip/ip.h" +#include "lwip/mem.h" +#include "lwip/pbuf.h" +#include "lwip/sys.h" + +#include "netif/arp.h" + + +#define IFNAME0 'c' +#define IFNAME1 'y' + +static const struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}}; + +struct ecosif { + struct eth_addr *ethaddr; + /* Add whatever per-interface state that is needed here. */ +}; + +static struct netif *this_netif; + +/* Forward declarations. */ +static void ecosif_input(struct netif *netif, char*buf, int len); +static err_t ecosif_output(struct netif *netif, struct pbuf *p, + struct ip_addr *ipaddr); + +/* Entry points in the eCos hw independent driver */ +extern void eth_drv_write(char *, char *, int); +extern void init_hw_drivers(unsigned char *hw_addr,void (*pig)(char *,int)); + +/* + * This is called from eCos when data is read from the driver + */ +void lwip_input(char *buf, int len) +{ + ecosif_input((struct netif*)this_netif,buf,len); +} + + +extern void input_thread(void *arg); + +static void +low_level_init(struct netif *netif) +{ + struct ecosif *ecosif; + + ecosif = netif->state; + + /* Init eCos low level driver which sets MAC address */ + init_hw_drivers((unsigned char *)ecosif->ethaddr->addr,lwip_input); + printf("MAC address : %X:%X:%X:%X:%X:%X\n", + (unsigned char)(ecosif->ethaddr->addr[0]), + (unsigned char)(ecosif->ethaddr->addr[1]), + (unsigned char)(ecosif->ethaddr->addr[2]), + (unsigned char)(ecosif->ethaddr->addr[3]), + (unsigned char)(ecosif->ethaddr->addr[4]), + (unsigned char)(ecosif->ethaddr->addr[5])); + sys_thread_new(input_thread,(void*)"poll_thread"); +} +/* + * low_level_output(): + * + * Should do the actual transmission of the packet. The packet is + * contained in the pbuf that is passed to the function. This pbuf + * might be chained.We pass the data down to the eCos hw independent + * ethernet driver + */ + +static err_t +low_level_output(struct ecosif *ecosif, struct pbuf *p) +{ + struct pbuf *q; + char buf[1500]; + char *bufptr; + + /* initiate transfer(); */ + bufptr = &buf[0]; + + for(q = p; q != NULL; q = q->next) { + /* Send the data from the pbuf to the interface, one pbuf at a + time. The size of the data in each pbuf is kept in the ->len + variable. */ + /* send data from(q->payload, q->len); */ + bcopy(q->payload, bufptr, q->len); + bufptr += q->len; + } + + /* signal that packet should be sent(); */ + eth_drv_write(NULL, buf, p->tot_len); + return ERR_OK; +} +/*-----------------------------------------------------------------------------------*/ +/* + * ecosif_output(): + * + * This function is called by the TCP/IP stack when an IP packet + * should be sent. It calls the function called low_level_output() to + * do the actuall transmission of the packet. + * + */ +/*-----------------------------------------------------------------------------------*/ +static err_t +ecosif_output(struct netif *netif, struct pbuf *p, + struct ip_addr *ipaddr) +{ + struct ecosif *ecosif; + struct pbuf *q; + struct eth_hdr *ethhdr; + struct eth_addr *dest, mcastaddr; + struct ip_addr *queryaddr; + err_t err; + u8_t i; + + ecosif = netif->state; + + /* Make room for Ethernet header. */ + if(pbuf_header(p, sizeof(struct eth_hdr)) != 0) { + /* The pbuf_header() call shouldn't fail, but we allocate an extra + pbuf just in case. */ + q = pbuf_alloc(PBUF_LINK, sizeof(struct eth_hdr), PBUF_RAM); + if(q == NULL) { + return ERR_MEM; + } + pbuf_chain(q, p); + p = q; + } + + /* Construct Ethernet header. Start with looking up deciding which + MAC address to use as a destination address. Broadcasts and + multicasts are special, all other addresses are looked up in the + ARP table. */ + queryaddr = ipaddr; + if(ip_addr_isany(ipaddr) || + ip_addr_isbroadcast(ipaddr, &(netif->netmask))) { + dest = (struct eth_addr *)ðbroadcast; + } else if(ip_addr_ismulticast(ipaddr)) { + /* Hash IP multicast address to MAC address. */ + mcastaddr.addr[0] = 0x01; + mcastaddr.addr[1] = 0x0; + mcastaddr.addr[2] = 0x5e; + mcastaddr.addr[3] = ip4_addr2(ipaddr) & 0x7f; + mcastaddr.addr[4] = ip4_addr3(ipaddr); + mcastaddr.addr[5] = ip4_addr4(ipaddr); + dest = &mcastaddr; + } else { + if(ip_addr_maskcmp(ipaddr, &(netif->ip_addr), &(netif->netmask))) { + /* Use destination IP address if the destination is on the same + subnet as we are. */ + queryaddr = ipaddr; + } else { + /* Otherwise we use the default router as the address to send + the Ethernet frame to. */ + queryaddr = &(netif->gw); + } + dest = arp_lookup(queryaddr); + } + + + /* If the arp_lookup() didn't find an address, we send out an ARP + query for the IP address. */ + if(dest == NULL) { + q = arp_query(netif, ecosif->ethaddr, queryaddr); + if(q != NULL) { + printf("Sending ARP after query\n"); + err = low_level_output(ecosif, q); + pbuf_free(q); + return err; + } + return ERR_MEM; + } + ethhdr = p->payload; + + for(i = 0; i < 6; i++) { + ethhdr->dest.addr[i] = dest->addr[i]; + ethhdr->src.addr[i] = ecosif->ethaddr->addr[i]; + } + + ethhdr->type = htons(ETHTYPE_IP); + + return low_level_output(ecosif, p); + +} + + + +/* + * ecosif_input(): + * This function is called when the eCos hw independent driver + * has some data to pass up to lwIP.It does it through lwip_input. + */ + +static void +ecosif_input(struct netif *netif, char * bufptr, int len) +{ + struct ecosif *ecosif; + struct eth_hdr *ethhdr; + struct pbuf *p, *q; + + ecosif = netif->state; + /* We allocate a pbuf chain of pbufs from the pool. */ + p = pbuf_alloc(PBUF_LINK, len, PBUF_POOL); + + if(p != NULL) { + /* We iterate over the pbuf chain until we have read the entire + packet into the pbuf. */ + for(q = p; q != NULL; q = q->next) { + /* Read enough bytes to fill this pbuf in the chain. The + avaliable data in the pbuf is given by the q->len + variable. */ + /* read data into(q->payload, q->len); */ + bcopy(bufptr, q->payload, q->len); + bufptr += q->len; + } + /* acknowledge that packet has been read(); */ + } else { + /* drop packet(); */ + } + + if(p == NULL) { + DEBUGF(ECOSIF_DEBUG, ("ecosif_input: low_level_input returned NULL\n")); + return; + } + ethhdr = p->payload; + + switch(htons(ethhdr->type)) { + case ETHTYPE_IP: + DEBUGF(ECOSIF_DEBUG, ("ecosif_input: IP packet\n")); + arp_ip_input(netif, p); + pbuf_header(p, -14); +#if LWIP_DEBUG + if(ip_lookup(p->payload, netif)) { +#endif + netif->input(p, netif); +#if LWIP_DEBUG + } else { + printf("ecosif_input: lookup failed!\n"); + } +#endif + break; + case ETHTYPE_ARP: + DEBUGF(ECOSIF_DEBUG, ("ecosif_input: ARP packet\n")); + p = arp_arp_input(netif, ecosif->ethaddr, p); + if(p != NULL) { + DEBUGF(ECOSIF_DEBUG, ("ecosif_input: Sending ARP reply\n")); + low_level_output(ecosif, p); + pbuf_free(p); + } + break; + default: + pbuf_free(p); + break; + } +} +/*-----------------------------------------------------------------------------------*/ +static void +arp_timer(void *arg) +{ + arp_tmr(); + sys_timeout(ARP_TMR_INTERVAL, (sys_timeout_handler)arp_timer, NULL); +} +/*-----------------------------------------------------------------------------------*/ +/* + * ecosif_init(): + * + * Should be called at the beginning of the program to set up the + * network interface. It calls the function low_level_init() to do the + * actual setup of the hardware. + * + */ +/*-----------------------------------------------------------------------------------*/ +void +ecosif_init(struct netif *netif) +{ + struct ecosif *ecosif; + + this_netif = netif; + ecosif = mem_malloc(sizeof(struct ecosif)); + netif->state = ecosif; + netif->name[0] = IFNAME0; + netif->name[1] = IFNAME1; + netif->output = ecosif_output; + + ecosif->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]); + low_level_init(netif); + arp_init(); + + sys_timeout(ARP_TMR_INTERVAL, (sys_timeout_handler)arp_timer, NULL); +} +/*-----------------------------------------------------------------------------------*/ diff -Nur lwip-0.5.3/src/arch/ecos/sys_arch.c lwip.ecos/src/arch/ecos/sys_arch.c --- lwip-0.5.3/src/arch/ecos/sys_arch.c Thu Jan 1 02:00:00 1970 +++ lwip.ecos/src/arch/ecos/sys_arch.c Tue Apr 2 19:05:58 2002 @@ -0,0 +1,181 @@ +/* + * This file implements the eCos specific sys_arch functions used by lwIP + */ + +#include <cyg/kernel/kapi.h> + +#include "lwip/sys.h" +#include "lwip/def.h" +#include "lwip/debug.h" + +//FIXME use CYG_HWR_whatever for RTC + +/* lwIp timeouts are milliseconds, eCos time unit is clock tick */ +//1s = 1000ms = 100ticks (eCos default is 100 tick per second for most(all?) platforms) +#define tick_to_msec(tick) ((u16_t)(tick*10+1)) +#define msec_to_tick(msec) ((cyg_tick_count_t)(msec+9)/10) + +/* We use a common var mempool for allocating semaphores, mboxes and threads... */ +#define VARMEMPOOLSIZE 0x4000 /* tunable */ +static char memvar[VARMEMPOOLSIZE]; +static cyg_mempool_var var_mempool; +static cyg_handle_t var_mempool_h; + +/* ...and a fix mempool for allocating thread stacks */ + +#define LWIP_THREAD_STACK_SIZE 0x2000 /* tunable */ +#define MAX_THREADS 4 /* tunable */ + +static char memfix[LWIP_THREAD_STACK_SIZE * MAX_THREADS]; +static cyg_mempool_fix fix_mempool; +static cyg_handle_t fix_mempool_h; + +/* List of threads: associate eCos thread info with lwIP timeout info */ +struct lwip_thread { + struct lwip_thread * next; + struct sys_timeouts to; + cyg_handle_t th; + cyg_thread t; +} *threads; + +/*FIXME: the timeout struct used for non-lwIP threads -eCos + * there might be threads which are not created through + * sys_thread_new but access lwIP stuff (i.e. net interrupt) + * This must go away. + * */ +struct sys_timeouts global_timeout; + +/* Set up memory pools and threads*/ +void sys_init(void) +{ + cyg_mempool_var_create(memvar, sizeof(memvar), &var_mempool_h, &var_mempool); + + cyg_mempool_fix_create(memfix, sizeof(memfix), + LWIP_THREAD_STACK_SIZE, &fix_mempool_h, &fix_mempool); + threads = NULL; + global_timeout.next = NULL; +} + +/* Message boxes */ + +sys_mbox_t sys_mbox_new(void) +{ + cyg_mbox * mbox; + cyg_handle_t m; + mbox = (cyg_mbox *)cyg_mempool_var_alloc(var_mempool_h, sizeof(cyg_mbox)); + cyg_mbox_create(&m, mbox); + return m; +} + +void sys_mbox_free(sys_mbox_t mbox) +{ + cyg_mbox_delete(mbox); +} + +//FIXME returns false maybe retry? +void sys_mbox_post(sys_mbox_t mbox, void *data) +{ +#if 0 + if (cyg_mbox_put(mbox, data)==false) + printf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaaa\n"); +#endif + cyg_mbox_put(mbox,data); +} + +u16_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **data, u16_t timeout) +{ + void *d; + cyg_tick_count_t end_time, start_time,lool; + static int pig = 0; + if (timeout) { + start_time = cyg_current_time(); + lool = start_time + msec_to_tick(timeout); + d = cyg_mbox_timed_get(mbox, lool); + end_time = cyg_current_time(); + + if (d == NULL) + return 0; + } else { + d = cyg_mbox_get(mbox); + } + *data = d; + return tick_to_msec(end_time - start_time); +} + +/* Semaphores */ + +sys_sem_t sys_sem_new(u8_t count) +{ + sys_sem_t sem; + + sem = (cyg_sem_t *)cyg_mempool_var_alloc(var_mempool_h, sizeof(cyg_sem_t)); + cyg_semaphore_init(sem, count); + return sem; +} + +u16_t sys_arch_sem_wait(sys_sem_t sem, u16_t timeout) +{ + cyg_bool_t r; + cyg_tick_count_t end_time, start_time; + + if (timeout) { + start_time = cyg_current_time(); + r = cyg_semaphore_timed_wait(sem, start_time + msec_to_tick(timeout)); + end_time = cyg_current_time(); + + if (r == false) + return 0; + } else { + cyg_semaphore_wait(sem); + } + + return tick_to_msec(end_time - start_time); +} + +void sys_sem_signal(sys_sem_t sem) +{ + cyg_semaphore_post(sem); +} + +void sys_sem_free(sys_sem_t sem) +{ + cyg_semaphore_destroy(sem); +} + +/* Thread creation */ + +void sys_thread_new(void (*function) (void *arg), void *arg) +{ + struct lwip_thread * nt; + void * stack; + + nt = (struct lwip_thread *)cyg_mempool_var_alloc(var_mempool_h, sizeof(struct lwip_thread)); + + nt->next = threads; + nt->to.next = NULL; + + threads = nt; + + stack = cyg_mempool_fix_alloc(fix_mempool_h); + + cyg_thread_create(12, (cyg_thread_entry_t *)function, (cyg_addrword_t)arg, + (char *)arg , stack, LWIP_THREAD_STACK_SIZE, &(nt->th), &(nt->t) ); + + cyg_thread_resume(nt->th); +} + +/* Find current thread's timeout info */ + +struct sys_timeouts *sys_arch_timeouts(void) +{ + cyg_handle_t ct; + struct lwip_thread *t; + + ct = cyg_thread_self(); + for(t = threads; t; t = t->next) + if (t->th == ct) + return &(t->to); + + printf("tmobad@@@@@\n"); + return &global_timeout; +}
