This is the mail archive of the ecos-devel@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC 5/9] * Make changes to ecos wrapper code for lwip


There were a number of lwip API changes in 1.4.1, this patch
modifies the ecos wrapper around lwip so it works with new version

Signed-off-by: Andrew Parlane <andrewp@carallon.com>
Signed-off-by: Will Wagner <willw@carallon.com>
---
 .../enc424j600/current/tests/netconn_test_server.c |   7 +-
 packages/net/lwip_tcpip/current/cdl/lwip_net.cdl   | 122 ++++++----
 packages/net/lwip_tcpip/current/include/arch/cc.h  |   8 +
 .../net/lwip_tcpip/current/include/arch/sys_arch.h |  21 +-
 packages/net/lwip_tcpip/current/include/lwip.h     |   4 +-
 packages/net/lwip_tcpip/current/include/lwipopts.h |  14 ++
 .../net/lwip_tcpip/current/src/ecos/sequential.c   |  31 +--
 packages/net/lwip_tcpip/current/src/ecos/simple.c  |  33 +--
.../net/lwip_tcpip/current/src/ecos/sys_arch.c | 245 +++++++++++++++------
 .../lwip_tcpip/current/tests/httpd_sequential.c    |   5 +-
 packages/net/lwip_tcpip/current/tests/tcpecho.c    |   6 +-
 packages/net/lwip_tcpip/current/tests/udpecho.c    |   2 +-
 12 files changed, 310 insertions(+), 188 deletions(-)

diff --git a/packages/devs/eth/microchip/enc424j600/current/tests/netconn_test_server.c b/packages/devs/eth/microchip/enc424j600/current/tests/netconn_test_server.c
index 55a62c2..6931447 100644
--- a/packages/devs/eth/microchip/enc424j600/current/tests/netconn_test_server.c +++ b/packages/devs/eth/microchip/enc424j600/current/tests/netconn_test_server.c
@@ -149,7 +149,7 @@ void server(cyg_addrword_t arg_p)

     csum =0;

-    while((income_buffer = netconn_recv(newconn)) != NULL)
+ while((netconn_recv(newconn, &income_buffer) == ERR_OK) && (income_buffer != NULL))
     {
         total_len = netbuf_len(income_buffer);
         if(0 != total_len)
@@ -252,10 +252,9 @@ void listener(void)
     do
     {
         diag_printf("l: Waiting for a new connection...\n");
-        newconn = netconn_accept(conn);
-        if (NULL == newconn)
+ if ((netconn_accept(conn, &newconn)) != ERR_OK || (NULL == newconn))
         {
-            diag_printf("l: netconn_accept() return NULL. Exiting.\n");
+ diag_printf("l: netconn_accept() return error or NULL ptr. Exiting.\n");
             cyg_thread_exit();
         }

diff --git a/packages/net/lwip_tcpip/current/cdl/lwip_net.cdl b/packages/net/lwip_tcpip/current/cdl/lwip_net.cdl
index 4512cc5..cd7a8ec 100644
--- a/packages/net/lwip_tcpip/current/cdl/lwip_net.cdl
+++ b/packages/net/lwip_tcpip/current/cdl/lwip_net.cdl
@@ -51,7 +51,8 @@ cdl_package CYGPKG_NET_LWIP {
     requires        CYGPKG_ISOINFRA
     requires        CYGINT_ISO_ERRNO_CODES
 	
-    compile         core/dns.c                  \
+    compile         core/def.c                  \
+                    core/dns.c                  \
                     core/init.c                 \
                     core/mem.c                  \
                     core/memp.c	                \
@@ -63,6 +64,7 @@ cdl_package CYGPKG_NET_LWIP {
                     core/tcp_in.c               \
                     core/tcp_out.c              \
                     core/tcp.c                  \
+                    core/timers.c               \
                     core/udp.c                  \
                     core/ipv4/icmp.c            \
                     core/ipv4/igmp.c            \
@@ -577,6 +579,16 @@ cdl_package CYGPKG_NET_LWIP {
available in the TCP snd_buf for select to return writable."
             }

+            cdl_option CYGNUM_LWIP_TCP_SNDQUEUELOWAT {
+                display         "TCP writeable space"
+                flavor          data
+ default_value { ((CYGNUM_LWIP_TCP_SND_QUEUELEN / 2) > 5) ? (CYGNUM_LWIP_TCP_SND_QUEUELEN / 2) : 5 }
+                description     "
+                    TCP writable space (bytes). This must be less than
+                    TCP_SND_QUEUELEN. It is the amount of pbufs which must
+ be available in the TCP snd_queue for select to return writable."
+            }
+
             cdl_option CYGFUN_LWIP_TCP_LISTEN_BACKLOG {
                 display         "Listen backlog"
                 flavor          bool
@@ -993,51 +1005,8 @@ cdl_package CYGPKG_NET_LWIP {
             display         "Loop interface support"
             flavor          bool
             default_value   0
-            compile         netif/loopif.c
             description     "
                 Support loop interface."
-
-            cdl_component CYGIMP_LWIP_LOOPIF_INSTANCE {
-                display         "Default instance"
-                flavor          bool
-                default_value   1
-                description     "
-                    When enabled, a default loop interface is automatically
-                    set up."
-
-                cdl_option CYGDAT_LWIP_LOOPIF_DEFAULT {
-                    display         "Default netif"
-                    flavor          bool
-                    default_value   0
-                    implements      CYGPKG_LWIP_NETIF_DEFAULT
-                    description     "
- Use this interface as the default network interface."
-                }
-
-                cdl_option CYGDAT_LWIP_LOOPIF_ADDR {
-                    display         "Address"
-                    flavor          data
-                    default_value   { "127,0,0,1" }
-                    description     "
-                        The IP address of this device."
-                }
-
-                cdl_option CYGDAT_LWIP_LOOPIF_NETMASK {
-                    display         "Netmask"
-                    flavor          data
-                    default_value   { "255,255,255,0" }
-                    description     "
-                        The netmask of the local network."
-                }
-
-                cdl_option CYGDAT_LWIP_LOOPIF_GATEWAY {
-                    display         "Gateway"
-                    flavor          data
-                    default_value   { "127,0,0,1" }
-                    description     "
-                        The IP address of the gateway."
-                }
-            }
         }

         cdl_component CYGPKG_LWIP_SLIP {
@@ -1107,7 +1076,6 @@ cdl_package CYGPKG_NET_LWIP {
             compile         ecos/ppp.c          \
                             netif/ppp/auth.c    \
                             netif/ppp/chap.c    \
-                            netif/ppp/chat.c    \
                             netif/ppp/chpms.c   \
                             netif/ppp/fsm.c     \
                             netif/ppp/ipcp.c    \
@@ -1118,8 +1086,6 @@ cdl_package CYGPKG_NET_LWIP {
                             netif/ppp/ppp_oe.c  \
                             netif/ppp/ppp.c     \
                             netif/ppp/randm.c   \
-                            netif/ppp/record.c  \
-                            netif/ppp/timesys.c \
                             netif/ppp/vj.c
             description     "
                 Support PPP functionality. Current PPP support is marked
@@ -1378,6 +1344,23 @@ cdl_package CYGPKG_NET_LWIP {
                 sequential API, like api_lib.c)"
         }

+        cdl_option CYGNUM_LWIP_MEMP_NUM_NETDB {
+            display         "Number of concurrent lwip_addrinfo() calls"
+            flavor          data
+            default_value   1
+            description     "
+                The number of netdb buffers. (only needed if you use DNS)"
+        }
+
+        cdl_option CYGNUM_LWIP_MEMP_NUM_LOCALHOSTLIST {
+            display         "Number of host entries"
+            flavor          data
+            default_value   1
+            description     "
+                The number of host entries in the local host list.
+ (only needed if you use DNS and CYGFUN_LWIP_DNS_LOCAL_HOSTLIST_IS_DYNAMIC == 1)"
+        }
+
         cdl_option CYGNUM_LWIP_MEMP_NUM_TCPIP_MSG_API {
             display         "Struct tcpip_msg"
             flavor          data
@@ -1397,6 +1380,51 @@ cdl_package CYGPKG_NET_LWIP {
                 packets. (only needed if you use tcpip.c)"
         }

+        cdl_option CYGNUM_LWIP_MEMP_NUM_PPPOE_INTERFACES {
+            display         "Number of PPoE interfaces"
+            flavor          data
+            default_value   1
+            description     "
+                The number of concurrently active PPPoE interfaces
+                (only used with CYGFUN_LWIP_PPPOE_SUPPORT)"
+        }
+
+        cdl_option CYGNUM_LWIP_MEMP_NUM_SNMP_ROOTNODE {
+            display         "Number of branches in SNMP tree"
+            flavor          data
+            default_value   30
+            description     "
+ The number of branches in the SNMP tree. (only needed if you use SNMP)"
+        }
+
+        cdl_option CYGNUM_LWIP_MEMP_NUM_SNMP_NODE {
+            display         "Number of leafs in the SNMP tree"
+            flavor          data
+            default_value   50
+            description     "
+ The number of leafs in the SNMP tree. (only needed if you use SNMP)"
+        }
+
+        cdl_option CYGNUM_LWIP_MEMP_NUM_SNMP_VARBIND {
+            display         "Number of concurrent SNMP requests"
+            flavor          data
+            default_value   2
+            description     "
+                Two of of these are used per request: One for input,
+                one for output. (Only needed if you use SNMP)"
+        }
+
+        cdl_option CYGNUM_LWIP_MEMP_NUM_SNMP_VALUE {
+            display         "Number of SNMP OID or values"
+            flavor          data
+            default_value   3
+            description     "
+                The number of OID or values concurrently used.
+                Three of these are used per request: One for the value
+                read and two for OIDs - input and output.
+                (only needed if you use SNMP)"
+        }
+
         cdl_option CYGNUM_LWIP_PBUF_POOL_SIZE {
             display         "Pbuf pool buffers"
             flavor          data
diff --git a/packages/net/lwip_tcpip/current/include/arch/cc.h b/packages/net/lwip_tcpip/current/include/arch/cc.h
index bdb2d17..1d2b74c 100644
--- a/packages/net/lwip_tcpip/current/include/arch/cc.h
+++ b/packages/net/lwip_tcpip/current/include/arch/cc.h
@@ -35,6 +35,7 @@

 #include <string.h>
 #include <errno.h>
+#include <stdlib.h>
 #include <cyg/infra/cyg_type.h>

 typedef int sys_prot_t;
@@ -99,6 +100,7 @@ typedef unsigned    long    mem_ptr_t;
 #define U32_F "lu"
 #define S32_F "ld"
 #define X32_F "lx"
+#define SZT_F "u"

 // Compiler hints for packing structures
 #define PACK_STRUCT_FIELD(x) x
@@ -113,4 +115,10 @@ typedef unsigned    long    mem_ptr_t;
 #define LWIP_PLATFORM_DIAG(x) do {diag_printf x;} while(0)
 #define LWIP_PLATFORM_ASSERT(x) do {CYG_FAIL(x);} while(0)

+// random number generator
+#define LWIP_RAND() rand()
+
+//current time
+#define sys_jiffies() cyg_current_time()
+
 #endif // __LWIP_ARCH_CC_H__
diff --git a/packages/net/lwip_tcpip/current/include/arch/sys_arch.h b/packages/net/lwip_tcpip/current/include/arch/sys_arch.h
index 7b35543..dd5c29e 100644
--- a/packages/net/lwip_tcpip/current/include/arch/sys_arch.h
+++ b/packages/net/lwip_tcpip/current/include/arch/sys_arch.h
@@ -39,10 +39,27 @@

 #if !NO_SYS

-typedef cyg_sem_t *     sys_sem_t;
-typedef cyg_handle_t    sys_mbox_t;
 typedef cyg_handle_t    sys_thread_t;

+typedef struct sys_sem
+{
+    cyg_sem_t *sem;
+    int valid;
+} sys_sem_t;
+
+typedef struct sys_mbox
+{
+    cyg_mbox *mbox;
+    cyg_handle_t handle;
+    int valid;
+} sys_mbox_t;
+
+typedef struct sys_mutex
+{
+    cyg_mutex_t *mutex;
+    int valid;
+} sys_mutex_t;
+
 #define SYS_SEM_NULL    ((sys_sem_t) NULL)
 #define SYS_MBOX_NULL   ((sys_mbox_t) NULL)

diff --git a/packages/net/lwip_tcpip/current/include/lwip.h b/packages/net/lwip_tcpip/current/include/lwip.h
index 3989e8d..085a240 100644
--- a/packages/net/lwip_tcpip/current/include/lwip.h
+++ b/packages/net/lwip_tcpip/current/include/lwip.h
@@ -78,8 +78,8 @@ externC void cyg_lwip_simple_poll(void);

 externC void cyg_lwip_sequential_init(void);

-externC sys_thread_t cyg_lwip_thread_new(char *name,
- void (* thread)(void *arg), void *arg,
+externC sys_thread_t cyg_lwip_thread_new(const char *name,
+                                         lwip_thread_fn thread, void *arg,
void *stack, int stacksize, int prio);

 #endif // CYGFUN_LWIP_MODE_SEQUENTIAL
diff --git a/packages/net/lwip_tcpip/current/include/lwipopts.h b/packages/net/lwip_tcpip/current/include/lwipopts.h
index 83081ad..0afc52a 100644
--- a/packages/net/lwip_tcpip/current/include/lwipopts.h
+++ b/packages/net/lwip_tcpip/current/include/lwipopts.h
@@ -56,6 +56,7 @@
 # define LWIP_PLATFORM_HTONS(__val) CYG_CPU_TO_BE16(__val)
 # define LWIP_PLATFORM_HTONL(__val) CYG_CPU_TO_BE32(__val)
 #endif
+#define LWIP_COMPAT_MUTEX 0


//------------------------------------------------------------------------------
 // Memory options
@@ -102,8 +103,15 @@

CYGNUM_LWIP_MEMP_NUM_USER_SYS_TIMEOUT)
 #define MEMP_NUM_NETBUF             CYGNUM_LWIP_MEMP_NUM_NETBUF
 #define MEMP_NUM_NETCONN            CYGNUM_LWIP_MEMP_NUM_NETCONN
+#define MEMP_NUM_NETDB              CYGNUM_LWIP_MEMP_NUM_NETDB
+#define MEMP_NUM_LOCALHOSTLIST      CYGNUM_LWIP_MEMP_NUM_LOCALHOSTLIST
 #define MEMP_NUM_TCPIP_MSG_API      CYGNUM_LWIP_MEMP_NUM_TCPIP_MSG_API
 #define MEMP_NUM_TCPIP_MSG_INPKT    CYGNUM_LWIP_MEMP_NUM_TCPIP_MSG_INPKT
+#define MEMP_NUM_PPPOE_INTERFACES   CYGNUM_LWIP_MEMP_NUM_PPPOE_INTERFACES
+#define MEMP_NUM_SNMP_ROOTNODE      CYGNUM_LWIP_MEMP_NUM_SNMP_ROOTNODE
+#define MEMP_NUM_SNMP_NODE          CYGNUM_LWIP_MEMP_NUM_SNMP_NODE
+#define MEMP_NUM_SNMP_VARBIND       CYGNUM_LWIP_MEMP_NUM_SNMP_VARBIND
+#define MEMP_NUM_SNMP_VALUE         CYGNUM_LWIP_MEMP_NUM_SNMP_VALUE
 #define PBUF_POOL_SIZE              CYGNUM_LWIP_PBUF_POOL_SIZE


//------------------------------------------------------------------------------
@@ -163,6 +171,7 @@

 #ifdef CYGPKG_LWIP_DHCP
 # define LWIP_DHCP                  1
+# define LWIP_DHCP_BOOTP_FILE       0
 # ifdef CYGPKG_LWIP_ARP
# define DHCP_DOES_ARP_CHECK defined(CYGFUN_LWIP_DHCP_DOES_ARP_CHECK)
 # endif
@@ -244,6 +253,7 @@
 # define TCP_SND_BUF                CYGNUM_LWIP_TCP_SND_BUF
 # define TCP_SND_QUEUELEN           CYGNUM_LWIP_TCP_SND_QUEUELEN
 # define TCP_SNDLOWAT               CYGNUM_LWIP_TCP_SNDLOWAT
+# define TCP_SNDQUEUELOWAT          CYGNUM_LWIP_TCP_SNDQUEUELOWAT
 # ifdef CYGFUN_LWIP_TCP_LISTEN_BACKLOG
 #  define TCP_LISTEN_BACKLOG        1
# define TCP_DEFAULT_LISTEN_BACKLOG CYGNUM_LWIP_TCP_DEFAULT_LISTEN_BACKLOG
@@ -252,9 +262,13 @@
 # define TCP_WND_UPDATE_THRESHOLD   CYGNUM_LWIP_TCP_WND_UPDATE_THRESHOLD
 # ifdef CYGFUN_LWIP_EVENT_API
 #  define LWIP_EVENT_API            1
+# else
+#  define LWIP_EVENT_API            0
 # endif
 # ifdef CYGFUN_LWIP_CALLBACK_API
 #  define LWIP_CALLBACK_API         1
+# else
+#  define LWIP_CALLBACK_API         0
 # endif
 #endif

diff --git a/packages/net/lwip_tcpip/current/src/ecos/sequential.c b/packages/net/lwip_tcpip/current/src/ecos/sequential.c
index 3c9609d..2471cbf 100644
--- a/packages/net/lwip_tcpip/current/src/ecos/sequential.c
+++ b/packages/net/lwip_tcpip/current/src/ecos/sequential.c
@@ -65,7 +65,6 @@
 #include "lwip/memp.h"
 #include "lwip/tcpip.h"

-#include "netif/loopif.h"
 #include "netif/slipif.h"
 #include "netif/etharp.h"
 #include "netif/ppp/ppp.h"
@@ -82,10 +81,6 @@
 #include <cyg/io/eth/netdev.h>
 #endif

-#if LWIP_HAVE_LOOPIF && defined(CYGIMP_LWIP_LOOPIF_INSTANCE)
-static struct netif loopif;
-#endif
-
 #if LWIP_HAVE_SLIPIF && defined(CYGIMP_LWIP_SLIPIF_INSTANCE)
 static struct netif slipif;
 #endif
@@ -103,8 +98,7 @@ static void eth_thread(void *data);

 #endif

-#if (LWIP_HAVE_LOOPIF && defined(CYGIMP_LWIP_LOOPIF_INSTANCE)) || \
-    (LWIP_HAVE_SLIPIF && defined(CYGIMP_LWIP_SLIPIF_INSTANCE))
+#if (LWIP_HAVE_SLIPIF && defined(CYGIMP_LWIP_SLIPIF_INSTANCE))

 //
 // Sets an IP address.
@@ -115,8 +109,7 @@ set_ip_addr(struct ip_addr *addr, u8_t a, u8_t b, u8_t c, u8_t d)
     IP4_ADDR(addr, a, b, c, d);
 }

-#endif // (LWIP_HAVE_LOOPIF && defined(CYGIMP_LWIP_LOOPIF_INSTANCE)) ||
-       // (LWIP_HAVE_SLIPIF && defined(CYGIMP_LWIP_SLIPIF_INSTANCE))
+#endif // (LWIP_HAVE_SLIPIF && defined(CYGIMP_LWIP_SLIPIF_INSTANCE))

 #ifdef CYGFUN_LWIP_SHOW_NETIF_CONFIG

@@ -153,26 +146,6 @@ tcpip_init_done(void *arg)
 {
     cyg_sem_t *sem = arg;

-#if LWIP_HAVE_LOOPIF && defined(CYGIMP_LWIP_LOOPIF_INSTANCE)
-    {
-        struct ip_addr addr, netmask, gateway;
-
-        // Setup default loopback device instance
-        set_ip_addr(&addr, CYGDAT_LWIP_LOOPIF_ADDR);
-        set_ip_addr(&netmask, CYGDAT_LWIP_LOOPIF_NETMASK);
-        set_ip_addr(&gateway, CYGDAT_LWIP_LOOPIF_GATEWAY);
-        netif_add(&loopif, &addr, &netmask, &gateway, NULL,
-                  loopif_init, tcpip_input);
-#ifdef CYGDAT_LWIP_LOOPIF_DEFAULT
-        netif_set_default(&loopif);
-#endif
-#ifdef CYGFUN_LWIP_SHOW_NETIF_CONFIG
-        netif_set_status_callback(&loopif, netif_status_callback);
-#endif
-        netif_set_up(&loopif);
-    }
-#endif
-
 #if LWIP_HAVE_SLIPIF && defined(CYGIMP_LWIP_SLIPIF_INSTANCE)
     {
         struct ip_addr addr, netmask, gateway;
diff --git a/packages/net/lwip_tcpip/current/src/ecos/simple.c b/packages/net/lwip_tcpip/current/src/ecos/simple.c
index 1a347b0..1acb6fa 100644
--- a/packages/net/lwip_tcpip/current/src/ecos/simple.c
+++ b/packages/net/lwip_tcpip/current/src/ecos/simple.c
@@ -58,6 +58,7 @@
 #include "lwip/ip_addr.h"
 #include "lwip/init.h"
 #include "lwip/tcp.h"
+#include "lwip/tcp_impl.h"
 #include "lwip/ip_frag.h"
 #include "lwip/dhcp.h"
 #include "lwip/autoip.h"
@@ -66,11 +67,9 @@
 #include "lwip/memp.h"
 #include "lwip/netif.h"

-#include "netif/loopif.h"
 #include "netif/slipif.h"
 #include "netif/etharp.h"
 #include "netif/ppp/ppp.h"
-#include "netif/ppp/chat.h"

 #include <cyg/infra/diag.h>
 #include <cyg/kernel/kapi.h>
@@ -84,10 +83,6 @@
 #include <cyg/io/eth/netdev.h>
 #endif

-#if LWIP_HAVE_LOOPIF && defined(CYGIMP_LWIP_LOOPIF_INSTANCE)
-static struct netif loopif;
-#endif
-
 #if LWIP_HAVE_SLIPIF && defined(CYGIMP_LWIP_SLIPIF_INSTANCE)
 static struct netif slipif;
 #endif
@@ -157,8 +152,7 @@ static struct lwip_timer lwip_timers[] = {
 static cyg_tick_count_t last_ticks;


-#if (LWIP_HAVE_LOOPIF && defined(CYGIMP_LWIP_LOOPIF_INSTANCE)) || \
-    (LWIP_HAVE_SLIPIF && defined(CYGIMP_LWIP_SLIPIF_INSTANCE))
+#if (LWIP_HAVE_SLIPIF && defined(CYGIMP_LWIP_SLIPIF_INSTANCE))

 //
 // Sets an IP address.
@@ -187,8 +181,7 @@ simple_input(struct pbuf *p, struct netif *netif)
     return ERR_OK;
 }

-#endif // (LWIP_HAVE_LOOPIF && defined(CYGIMP_LWIP_LOOPIF_INSTANCE)) ||
-       // (LWIP_HAVE_SLIPIF && defined(CYGIMP_LWIP_SLIPIF_INSTANCE))
+#endif // (LWIP_HAVE_SLIPIF && defined(CYGIMP_LWIP_SLIPIF_INSTANCE))

 #ifdef CYGFUN_LWIP_SHOW_NETIF_CONFIG

@@ -233,26 +226,6 @@ cyg_lwip_simple_init(void)
     // Initialize the lwIP stack
     lwip_init();

-#if LWIP_HAVE_LOOPIF && defined(CYGIMP_LWIP_LOOPIF_INSTANCE)
-    {
-        struct ip_addr addr, netmask, gateway;
-
-        // Setup default loopback device instance
-        set_ip_addr(&addr, CYGDAT_LWIP_LOOPIF_ADDR);
-        set_ip_addr(&netmask, CYGDAT_LWIP_LOOPIF_NETMASK);
-        set_ip_addr(&gateway, CYGDAT_LWIP_LOOPIF_GATEWAY);
-        netif_add(&loopif, &addr, &netmask, &gateway, NULL,
-                  loopif_init, simple_input);
-#ifdef CYGDAT_LWIP_LOOPIF_DEFAULT
-        netif_set_default(&loopif);
-#endif
-#ifdef CYGFUN_LWIP_SHOW_NETIF_CONFIG
-        netif_set_status_callback(&loopif, netif_status_callback);
-#endif
-        netif_set_up(&loopif);
-    }
-#endif
-
 #if LWIP_HAVE_SLIPIF && defined(CYGIMP_LWIP_SLIPIF_INSTANCE)
     {
         struct ip_addr addr, netmask, gateway;
diff --git a/packages/net/lwip_tcpip/current/src/ecos/sys_arch.c b/packages/net/lwip_tcpip/current/src/ecos/sys_arch.c
index 12ecd52..3ab27d5 100644
--- a/packages/net/lwip_tcpip/current/src/ecos/sys_arch.c
+++ b/packages/net/lwip_tcpip/current/src/ecos/sys_arch.c
@@ -60,6 +60,7 @@
 #include "lwip/def.h"
 #include "lwip/stats.h"
 #include "lwip/debug.h"
+#include "lwip/timers.h"

 // Milliseconds per system tick
 #define MS_PER_TICK ((u32_t) (CYGNUM_HAL_RTC_NUMERATOR / \
@@ -75,9 +76,9 @@
 // Thread structure
 struct lwip_thread {
     struct lwip_thread *next;  // Next thread in linked list
-    struct sys_timeouts to;    // List of timeouts
     cyg_handle_t handle;       // Thread handle
     cyg_thread thread;         // Thread store
+    char name[32];              // thread name
 };

 // A var memory pool is used for allocating semaphores, mboxes and threads
@@ -95,9 +96,6 @@ static cyg_mutex_t stack_mutex;
 static char stack_data[TOTAL_STACKSIZE];
 static char *stack_pos = stack_data;

-// Timeout for threads which were not created by sys_thread_new()
-static struct sys_timeouts to;
-
 // List of threads
 static struct lwip_thread *threads;

@@ -115,7 +113,6 @@ sys_init(void)
 	);
 	
 	threads = NULL;
-	to.next = NULL;
 	
 	cyg_mutex_init(&stack_mutex);
 }
@@ -124,16 +121,15 @@ sys_init(void)
 // Creates and returns a new semaphore. The "count" argument specifies the
 // initial state of the semaphore.
 //
-sys_sem_t
-sys_sem_new(u8_t count)
+err_t
+sys_sem_new(sys_sem_t *s_sem, u8_t count)
 {
-    sys_sem_t sem;
-
     // Allocate semaphore
- sem = (cyg_sem_t *) cyg_mempool_var_try_alloc(var_handle, sizeof(cyg_sem_t));
-    if (!sem)
-        return SYS_SEM_NULL;
-    cyg_semaphore_init(sem, count);
+ s_sem->sem = (cyg_sem_t *) cyg_mempool_var_try_alloc(var_handle, sizeof(cyg_sem_t));
+    if (!s_sem->sem)
+        return ERR_MEM;
+    cyg_semaphore_init(s_sem->sem, count);
+    s_sem->valid = 1;

 #if SYS_STATS
     lwip_stats.sys.sem.used++;
@@ -141,20 +137,21 @@ sys_sem_new(u8_t count)
         lwip_stats.sys.sem.max = lwip_stats.sys.sem.used;
 #endif

-    return sem;
+    return ERR_OK;
 }

 //
 // Deallocates a semaphore.
 //
 void
-sys_sem_free(sys_sem_t sem)
+sys_sem_free(sys_sem_t *s_sem)
 {
-    if (!sem)
+    if (!s_sem || !s_sem->sem)
         return;

-    cyg_semaphore_destroy(sem);
-    cyg_mempool_var_free(var_handle, (void *) sem);
+    cyg_semaphore_destroy(s_sem->sem);
+    cyg_mempool_var_free(var_handle, (void *) s_sem->sem);
+    s_sem->valid = 0;

 #if SYS_STATS
     lwip_stats.sys.sem.used--;
@@ -165,9 +162,9 @@ sys_sem_free(sys_sem_t sem)
 // Signals a semaphore.
 //
 void
-sys_sem_signal(sys_sem_t sem)
+sys_sem_signal(sys_sem_t *s_sem)
 {
-    cyg_semaphore_post(sem);
+    cyg_semaphore_post(s_sem->sem);
 }

 //
@@ -186,41 +183,63 @@ sys_sem_signal(sys_sem_t sem)
 // that uses the sys_arch_sem_wait() function.
 //
 u32_t
-sys_arch_sem_wait(sys_sem_t sem, u32_t timeout)
+sys_arch_sem_wait(sys_sem_t *s_sem, u32_t timeout)
 {
     if (timeout) {
         cyg_tick_count_t start_time = cyg_current_time();

         // Wait for semaphore with timeout
- if (!cyg_semaphore_timed_wait(sem, start_time + MS_TO_TICKS(timeout))) + if (!cyg_semaphore_timed_wait(s_sem->sem, start_time + MS_TO_TICKS(timeout)))
             return SYS_ARCH_TIMEOUT;
         // Return elapsed time
         return TICKS_TO_MS(cyg_current_time() - start_time);
     } else {
         // Wait for semaphore indefinitely
-        cyg_semaphore_wait(sem);
+        cyg_semaphore_wait(s_sem->sem);
         return 0;
     }
 }

 //
+// Check if a sempahore is valid/allocated: return 1 for valid, 0 for invalid
+//
+int
+sys_sem_valid(sys_sem_t *s_sem)
+{
+    if (!s_sem)
+        return 0;
+
+    return s_sem->valid;
+}
+
+//
+// Set a semaphore invalid so that sys_sem_valid returns 0
+//
+void
+sys_sem_set_invalid(sys_sem_t *s_sem)
+{
+    if (!s_sem)
+        return;
+
+    s_sem->valid = 0;
+}
+
+//
// Creates an empty mailbox for maximum "size" elements. Elements stored in
 // mailboxes are pointers. You have to define macros "_MBOX_SIZE" in your
 // lwipopts.h, or ignore this parameter in your implementation and use a
 // default size.
 //
-sys_mbox_t
-sys_mbox_new(int size)
+err_t
+sys_mbox_new(sys_mbox_t *s_mbox, int size)
 {
-	cyg_mbox *mbox;
-	cyg_handle_t handle;
-
     LWIP_UNUSED_ARG(size);

- mbox = (cyg_mbox *) cyg_mempool_var_try_alloc(var_handle, sizeof(cyg_mbox));
-	if (!mbox)
-	    return SYS_MBOX_NULL;
-	cyg_mbox_create(&handle, mbox);
+ s_mbox->mbox = (cyg_mbox *) cyg_mempool_var_try_alloc(var_handle, sizeof(cyg_mbox));
+	if (!s_mbox->mbox)
+	    return ERR_MEM;
+	cyg_mbox_create(&(s_mbox->handle), s_mbox->mbox);
+    s_mbox->valid = 1;

 #if SYS_STATS
     lwip_stats.sys.mbox.used++;
@@ -228,7 +247,7 @@ sys_mbox_new(int size)
         lwip_stats.sys.mbox.max = lwip_stats.sys.mbox.used;
 #endif

-	return handle;
+	return ERR_OK;
 }

 //
@@ -237,17 +256,18 @@ sys_mbox_new(int size)
 // in lwIP and the developer should be notified.
 //
 void
-sys_mbox_free(sys_mbox_t mbox)
+sys_mbox_free(sys_mbox_t *s_mbox)
 {
-    if (!mbox)
+    if (!s_mbox || !s_mbox->handle)
         return;

-    if (cyg_mbox_peek(mbox))
+    if (cyg_mbox_peek(s_mbox->handle))
         LWIP_DEBUGF(SYS_DEBUG | LWIP_DBG_LEVEL_WARNING,
                     ("sys_mbox_free: mbox not empty\n"));

-	cyg_mbox_delete(mbox);
-	cyg_mempool_var_free(var_handle, (void *) mbox);
+	cyg_mbox_delete(s_mbox->handle);
+	cyg_mempool_var_free(var_handle, (void *) s_mbox->mbox);
+    s_mbox->valid = 0;

 #if SYS_STATS
     lwip_stats.sys.mbox.used--;
@@ -267,12 +287,15 @@ static int null_msg;
 // is really posted.
 //
 void
-sys_mbox_post(sys_mbox_t mbox, void *msg)
+sys_mbox_post(sys_mbox_t *s_mbox, void *msg)
 {
+    if (!s_mbox || !s_mbox->handle)
+        return;
+
     // Map NULL messages
     if (!msg)
         msg = &null_msg;
-    while (cyg_mbox_put(mbox, msg) == false);
+    while (cyg_mbox_put(s_mbox->handle, msg) == false);
 }

 //
@@ -280,12 +303,12 @@ sys_mbox_post(sys_mbox_t mbox, void *msg)
 // else, ERR_OK if the "msg" is posted.
 //
 err_t
-sys_mbox_trypost(sys_mbox_t mbox, void *msg)
+sys_mbox_trypost(sys_mbox_t *s_mbox, void *msg)
 {
     // Map NULL messages
     if (!msg)
         msg = &null_msg;
-    return cyg_mbox_tryput(mbox, msg) ? ERR_OK : ERR_MEM;
+    return cyg_mbox_tryput(s_mbox->handle, msg) ? ERR_OK : ERR_MEM;
 }

 //
@@ -304,7 +327,7 @@ sys_mbox_trypost(sys_mbox_t mbox, void *msg)
 // by lwIP.
 //
 u32_t
-sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout)
+sys_arch_mbox_fetch(sys_mbox_t *s_mbox, void **msg, u32_t timeout)
 {
     void *m;

@@ -312,7 +335,7 @@ sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout)
         cyg_tick_count_t start_time = cyg_current_time();

         // Wait for mailbox with timeout
- if (!(m = cyg_mbox_timed_get(mbox, start_time + MS_TO_TICKS(timeout)))) + if (!(m = cyg_mbox_timed_get(s_mbox->handle, start_time + MS_TO_TICKS(timeout))))
             return SYS_ARCH_TIMEOUT;
         // Map NULL messages
         if (m == &null_msg)
@@ -322,7 +345,7 @@ sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout)
         return TICKS_TO_MS(cyg_current_time() - start_time);
     } else {
         // Wait for semaphore indefinitely
-        m = cyg_mbox_get(mbox);
+        m = cyg_mbox_get(s_mbox->handle);
         // Map NULL messages
         if (m == &null_msg)
             m = NULL;
@@ -345,11 +368,11 @@ sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout)
 // although this would introduce unnecessary delays.
 //
 u32_t
-sys_arch_mbox_tryfetch(sys_mbox_t mbox, void **msg)
+sys_arch_mbox_tryfetch(sys_mbox_t *s_mbox, void **msg)
 {
     void *m;

-    m = cyg_mbox_tryget(mbox);
+    m = cyg_mbox_tryget(s_mbox->handle);
     if (!m)
         return SYS_MBOX_EMPTY;

@@ -361,27 +384,115 @@ sys_arch_mbox_tryfetch(sys_mbox_t mbox, void **msg)
 }

 //
-// Returns a pointer to the per-thread sys_timeouts structure. In lwIP, each
-// thread has a list of timeouts which is repressented as a linked list of
-// sys_timeout structures. The sys_timeouts structure holds a pointer to a
-// linked list of timeouts. This function is called by the lwIP timeout
-// scheduler and must not return a NULL value.
+// Check if an mbox is valid/allocated: return 1 for valid, 0 for invalid
+//
+int
+sys_mbox_valid(sys_mbox_t *s_mbox)
+{
+    if (!s_mbox)
+        return 0;
+
+    return s_mbox->valid;
+}
+
 //
-// In a single thread sys_arch implementation, this function will simply return -// a pointer to a global sys_timeouts variable stored in the sys_arch module.
+// Set an mbox invalid so that sys_mbox_valid returns 0
 //
-struct sys_timeouts *
-sys_arch_timeouts(void)
+void
+sys_mbox_set_invalid(sys_mbox_t *s_mbox)
 {
-    cyg_handle_t handle;
-    struct lwip_thread *t;
+    if (!s_mbox)
+        return;
+
+    s_mbox->valid = 0;
+}
+
+//
+// Create and return a new mutex
+//
+err_t
+sys_mutex_new(sys_mutex_t *s_mutex)
+{
+    // Allocate mutex
+ s_mutex->mutex = (cyg_mutex_t *) cyg_mempool_var_try_alloc(var_handle, sizeof(cyg_mutex_t));
+    if (!s_mutex->mutex)
+        return ERR_MEM;
+    cyg_mutex_init(s_mutex->mutex);
+    s_mutex->valid = 1;
+
+#if SYS_STATS
+    lwip_stats.sys.mutex.used++;
+    if (lwip_stats.sys.mutex.used > lwip_stats.sys.mutex.max)
+        lwip_stats.sys.mutex.max = lwip_stats.sys.mutex.used;
+#endif

-    handle = cyg_thread_self();
-    for (t = threads; t; t = t->next)
-        if (t->handle == handle)
-            return &(t->to);
+    return ERR_OK;
+}
+
+//
+// Deallocate a semaphore
+//
+void
+sys_mutex_free(sys_mutex_t *s_mutex)
+{
+    if (!s_mutex || !s_mutex->mutex)
+        return;
+
+    cyg_mutex_destroy(s_mutex->mutex);
+    cyg_mempool_var_free(var_handle, (void *) s_mutex->mutex);
+    s_mutex->valid = 0;
+
+#if SYS_STATS
+    lwip_stats.sys.mutex.used--;
+#endif
+}
+
+//
+// Lock a mutex
+//
+void
+sys_mutex_lock(sys_mutex_t *s_mutex)
+{
+    if (!s_mutex || !s_mutex->mutex)
+        return;
+
+    while (cyg_mutex_lock(s_mutex->mutex) == false);
+}
+
+//
+// Unlock a mutex
+//
+void
+sys_mutex_unlock(sys_mutex_t *s_mutex)
+{
+    if (!s_mutex || !s_mutex->mutex)
+        return;
+
+    cyg_mutex_unlock(s_mutex->mutex);
+}
+
+//
+// Check if a mutex is valid/allocated: return 1 for valid, 0 for invalid
+//
+int
+sys_mutex_valid(sys_mutex_t *s_mutex)
+{
+    if (!s_mutex || !s_mutex->mutex)
+        return 0;
+
+    return s_mutex->valid;
+}
+
+//
+// Set a mutex invalid so that sys_mutex_valid returns 0
+//
+void
+sys_mutex_set_invalid(sys_mutex_t *s_mutex)
+{
+    if (!s_mutex || !s_mutex->mutex)
+        return;

-    return &to;
+    s_mutex->valid = 0;
 }

 //
@@ -392,7 +503,7 @@ sys_arch_timeouts(void)
 // id and the priority are system dependent.
 //
 sys_thread_t
-sys_thread_new(char *name, void (* thread)(void *arg), void *arg,
+sys_thread_new(const char *name, lwip_thread_fn thread, void *arg,
                int stacksize, int prio)
 {
     void *stack;
@@ -415,7 +526,7 @@ sys_thread_new(char *name, void (* thread)(void *arg), void *arg,
 // allowing clients to provide their own stack buffers.
 //
 sys_thread_t
-cyg_lwip_thread_new(char *name, void (* thread)(void *arg), void *arg,
+cyg_lwip_thread_new(const char *name, lwip_thread_fn thread, void *arg,
                     void *stack, int stacksize, int prio)
 {
     struct lwip_thread *t;
@@ -424,7 +535,7 @@ cyg_lwip_thread_new(char *name, void (* thread)(void *arg), void *arg,
             var_handle, sizeof(struct lwip_thread));

     t->next = threads;
-    t->to.next = NULL;
+    strncpy(t->name, name, sizeof(t->name));

     threads = t;

@@ -432,7 +543,7 @@ cyg_lwip_thread_new(char *name, void (* thread)(void *arg), void *arg,
         prio,
         (cyg_thread_entry_t *) thread,
         (cyg_addrword_t) arg,
-        name,
+        t->name,
         stack,
         stacksize,
         &t->handle,
diff --git a/packages/net/lwip_tcpip/current/tests/httpd_sequential.c b/packages/net/lwip_tcpip/current/tests/httpd_sequential.c
index f5769dc..b38b35a 100644
--- a/packages/net/lwip_tcpip/current/tests/httpd_sequential.c
+++ b/packages/net/lwip_tcpip/current/tests/httpd_sequential.c
@@ -143,8 +143,7 @@ http_server_serve(struct netconn *conn)

     // Read the data from the port, blocking if nothing yet there.
     // We assume the request (the part we care about) is in one netbuf.
-    inbuf = netconn_recv(conn);
-    if (!inbuf)
+    if ((netconn_recv(conn, &inbuf) != ERR_OK) || !inbuf)
         return;

     if (netconn_err(conn) == ERR_OK) {
@@ -192,7 +191,7 @@ main_thread_entry(cyg_addrword_t p)
     // Accept client connections
     CYG_TEST_INFO("Running");
     while(1) {
-        client = netconn_accept(server);
+        netconn_accept(server, &client);
         http_server_serve(client);
         netconn_close(client);
         netconn_delete(client);
diff --git a/packages/net/lwip_tcpip/current/tests/tcpecho.c b/packages/net/lwip_tcpip/current/tests/tcpecho.c
index 89f8031..96ec94f 100644
--- a/packages/net/lwip_tcpip/current/tests/tcpecho.c
+++ b/packages/net/lwip_tcpip/current/tests/tcpecho.c
@@ -84,15 +84,15 @@ static void tcpecho_thread_entry(void *arg)

     while (1) {
         // Accept new connection
-        newconn = netconn_accept(conn);
+        err = netconn_accept(conn, &newconn);

         // Process new connection
-        if (newconn != NULL) {
+        if ((err == ERR_OK) && (newconn != NULL)) {
             struct netbuf *buf;
             void *data;
             u16_t len;

-            while ((buf = netconn_recv(newconn)) != NULL) {
+ while ((netconn_recv(newconn, &buf) == ERR_OK) && (buf != NULL)) {
                 do {
                     netbuf_data(buf, &data, &len);
                     err = netconn_write(newconn, data, len, NETCONN_COPY);
diff --git a/packages/net/lwip_tcpip/current/tests/udpecho.c b/packages/net/lwip_tcpip/current/tests/udpecho.c
index 723a806..eb68433 100644
--- a/packages/net/lwip_tcpip/current/tests/udpecho.c
+++ b/packages/net/lwip_tcpip/current/tests/udpecho.c
@@ -82,7 +82,7 @@ udpecho_thread_entry(void *arg)
     netconn_bind(conn, NULL, UDP_PORT);

     while (1) {
-        buf = netconn_recv(conn);
+        netconn_recv(conn, &buf);
         addr = netbuf_fromaddr(buf);
         port = netbuf_fromport(buf);
         netconn_connect(conn, addr, port);
--
1.8.1.msysgit.1



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]