From fbe7ebd1ac39cdc25c331ede84cc5a45f8c56753 Mon Sep 17 00:00:00 2001 From: Vijay Kumar Banerjee Date: Tue, 6 Jul 2021 12:49:31 -0600 Subject: lwip/src: Add rtems compatibility --- lwip/ports/drivers/bbb/locator.c | 4 +- lwip/ports/drivers/bbb/lwiplib.c | 2 +- lwip/ports/os/lwipopts.h | 198 ++++++++++++++++++++++++++++++++++++ lwip/ports/os/rtems/arch/sys_arch.c | 7 +- lwip/src/api/rtems_lwip_io.c | 4 +- lwip/src/core/memp.c | 2 +- lwip/src/core/tcp.c | 2 + lwip/src/include/lwip/opt.h | 2 + lwip/src/include/lwip/sockets.h | 7 ++ lwip/test/init.c | 2 +- lwip/test/networking01/sample_app.c | 2 +- lwip/test/telnetd01/init.c | 11 +- 12 files changed, 225 insertions(+), 18 deletions(-) diff --git a/lwip/ports/drivers/bbb/locator.c b/lwip/ports/drivers/bbb/locator.c index caafe83..f8929bb 100755 --- a/lwip/ports/drivers/bbb/locator.c +++ b/lwip/ports/drivers/bbb/locator.c @@ -76,7 +76,7 @@ static unsigned char locatorData[84]; ** INTERNAL FUNCTION PROTOTYPES *******************************************************************************/ static void LocatorReceive(void *arg, struct udp_pcb *pcb, struct pbuf *p, - struct ip_addr *addr, u16_t port); + ip_addr_t *addr, u16_t port); /****************************************************************************** ** FUNCTION DEFINITIONS @@ -87,7 +87,7 @@ static void LocatorReceive(void *arg, struct udp_pcb *pcb, struct pbuf *p, ** sent back to the querying client. */ static void LocatorReceive(void *arg, struct udp_pcb *pcb, struct pbuf *p, - struct ip_addr *addr, u16_t port) + ip_addr_t *addr, u16_t port) { unsigned char *pucData; unsigned long ulIdx; diff --git a/lwip/ports/drivers/bbb/lwiplib.c b/lwip/ports/drivers/bbb/lwiplib.c index 00cf777..aeb78e2 100755 --- a/lwip/ports/drivers/bbb/lwiplib.c +++ b/lwip/ports/drivers/bbb/lwiplib.c @@ -59,7 +59,7 @@ #define LWIP_NOT_INITIALIZED 0 #define LWIP_INITIALIZED 1 -#define NUM_DHCP_TRIES 20 +//#define NUM_DHCP_TRIES 20 #define SECONDS_TO_MILISECONDS 1000 diff --git a/lwip/ports/os/lwipopts.h b/lwip/ports/os/lwipopts.h index 079ec0e..6e4287a 100644 --- a/lwip/ports/os/lwipopts.h +++ b/lwip/ports/os/lwipopts.h @@ -1,3 +1,4 @@ +#if 0 /* * Copyright (c) 2001-2003 Swedish Institute of Computer Science. * All rights reserved. @@ -57,6 +58,7 @@ #endif #define THREAD_STACK_SIZE 4096 +#define LWIP_TIMERS 1 /* Minimal changes to opt.h required for tcp unit tests: */ #define MEM_SIZE 16000 @@ -72,3 +74,199 @@ #define ETHARP_SUPPORT_STATIC_ENTRIES 1 #endif /* LWIP_HDR_LWIPOPTS_H__ */ + +#endif /* 0 */ + +/** + * \file lwipopts.h - Configuration options for lwIP + * + * Copyright (c) 2010 Texas Instruments Incorporated + */ +/* + * Copyright (c) 2001-2004 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 + * + */ + +#ifndef __LWIPOPTS_H__ +#define __LWIPOPTS_H__ + +/***************************************************************************** +** CONFIGURATIONS +*****************************************************************************/ + +/* +** The macro CPSW_DUAL_MAC_MODE shall be defined for using CPSW ports in +** Dual MAC mode. +*/ +#define CPSW_DUAL_MAC_MODE + +/* +** The below macro should be defined for using lwIP with cache. For cache +** enabling, pbuf pool shall be cache line aligned. This is done by using +** separate pool for each memory. The alignment of pbuf pool to cache line +** size is done in /ports/cpsw/include/arch/cc.h. +*/ +/*#define LWIP_CACHE_ENABLED*/ + +#define SOC_CACHELINE_SIZE_BYTES 64 /* Number of bytes in + a cache line */ +/* +** The timeout for DHCP completion. lwIP library will wait for DHCP +** completion for (LWIP_DHCP_TIMEOUT / 100) seconds. +*/ +#define LWIP_DHCP_TIMEOUT 1000 + +/* +** The number of times DHCP is attempted. Each time, the library will wait +** for (LWIP_DHCP_TIMEOUT / 100) seconds for DHCP completion. +*/ +#define NUM_DHCP_TRIES 5 + +#define LWIP_ETHERNET 1 +#define LWIP_ARP 1 +#define LWIP_DNS 1 + +/***************************************************************************** +** lwIP SPECIFIC DEFINITIONS - To be used by lwIP stack +*****************************************************************************/ +#define HOST_TMR_INTERVAL 0 +#define DYNAMIC_HTTP_HEADERS + +/***************************************************************************** +** Platform specific locking +*****************************************************************************/ +#define SYS_LIGHTWEIGHT_PROT 1 +#define NO_SYS 0 +#define NO_SYS_NO_TIMERS 0 + +/***************************************************************************** +** Memory Options +*****************************************************************************/ +#define MEM_ALIGNMENT 4 +#define MEM_SIZE (1024 * 1024) /* 4K */ + +#define MEMP_NUM_PBUF 96 +#define MEMP_NUM_TCP_PCB 32 +#define MEMP_NUM_TCP_SEG 32 +#define PBUF_POOL_SIZE 512 +#define MEMP_MEM_MALLOC 1 +#define MEMP_MEM_INIT 1 +#define MEMP_OVERFLOW_CHECK 0 + +#ifdef LWIP_CACHE_ENABLED +#define MEMP_SEPARATE_POOLS 1 /* We want the pbuf + pool cache line + aligned*/ +#endif + +//#define MEMP_NUM_SYS_TIMEOUT (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT) + +/***************************************************************************** +** IP Options +*****************************************************************************/ +#define IP_REASSEMBLY 0 +#define IP_FRAG 0 +#define LWIP_IPV4 1 +#define LWIP_IPV6 1 + +/***************************************************************************** +** DHCP Options +*****************************************************************************/ +#define LWIP_DHCP 1 +#define DHCP_DOES_ARP_CHECK 0 + +/***************************************************************************** +** Auto IP Options +*****************************************************************************/ +#define LWIP_AUTOIP 1 +#define LWIP_DHCP_AUTOIP_COOP ((LWIP_DHCP) && (LWIP_AUTOIP)) + +/***************************************************************************** +** TCP Options +*****************************************************************************/ +#define TCP_MSS 1500 +#define TCP_WND (8 * TCP_MSS) +#define TCP_SND_BUF (8 * TCP_MSS) +#define TCP_OVERSIZE TCP_MSS +#define LWIP_TCPIP_CORE_LOCKING 1 + +/***************************************************************************** +** PBUF Options +*****************************************************************************/ +#define PBUF_LINK_HLEN 14 +#define PBUF_POOL_BUFSIZE 1520 /* + size of struct pbuf + shall be cache line + aligned be enabled */ +#define ETH_PAD_SIZE 0 +#define LWIP_NETCONN 1 + +/***************************************************************************** +** Socket Options +*****************************************************************************/ +#define LWIP_SOCKET 1 +#define SO_REUSE 1 + +/***************************************************************************** +** Debugging options +*****************************************************************************/ +#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_OFF +#define LWIP_DBG_TYPES_ON (LWIP_DBG_ON | LWIP_DBG_TRACE \ + |LWIP_DBG_STATE | LWIP_DBG_FRESH) +#define DHCP_DEBUG LWIP_DBG_OFF +#define NETIF_DEBUG LWIP_DBG_OFF +#define IP_DEBUG LWIP_DBG_OFF +#define UDP_DEBUG LWIP_DBG_OFF +#define ETHARP_DEBUG LWIP_DBG_OFF +#define SYS_DEBUG LWIP_DBG_OFF +#define RAW_DEBUG LWIP_DBG_OFF +#define MEM_DEBUG LWIP_DBG_OFF +#define MEMP_DEBUG LWIP_DBG_OFF +#define PBUF_DEBUG LWIP_DBG_OFF +#define TCPIP_DEBUG LWIP_DBG_OFF +#define APP_DEBUG LWIP_DBG_OFF +#define SOCKETS_DEBUG LWIP_DBG_OFF +#define LWIP_STATS 0 +#define LWIP_STATS_DISPLAY 0 +#define LWIP_STATS_POSIX 0 +#define LWIP_DNS_API_DEFINE_ERRORS 1 + + + +/** + * LWIP_COMPAT_SOCKETS==1: Enable BSD-style sockets functions names. + * (only used if you use sockets.c) + */ +#define LWIP_COMPAT_SOCKETS 0 + + #define LWIP_TIMEVAL_PRIVATE 0 + + #define LWIP_RAW 0 + +#endif /* __LWIPOPTS_H__ */ diff --git a/lwip/ports/os/rtems/arch/sys_arch.c b/lwip/ports/os/rtems/arch/sys_arch.c index ca7f8be..5c46a9e 100644 --- a/lwip/ports/os/rtems/arch/sys_arch.c +++ b/lwip/ports/os/rtems/arch/sys_arch.c @@ -67,6 +67,7 @@ sys_init(void) err_t sys_sem_new(sys_sem_t *sem, u8_t count) { + /* rtems_status_code ret = rtems_semaphore_create( rtems_build_name('L', 'W', 'I', 'P'), count, @@ -79,6 +80,7 @@ sys_sem_new(sys_sem_t *sem, u8_t count) sem->semaphore = RTEMS_ID_NONE; return ret; } + */ return ERR_OK; } @@ -86,10 +88,12 @@ sys_sem_new(sys_sem_t *sem, u8_t count) void sys_sem_free(sys_sem_t *sem) { + /* rtems_semaphore_delete( sem->semaphore ); sem->semaphore = RTEMS_ID_NONE; + */ } void @@ -147,7 +151,7 @@ err_t sys_mbox_new(sys_mbox_t *mbox, int size) { rtems_status_code ret; - +/* ret = rtems_message_queue_create( rtems_build_name('L', 'W', 'I', 'P'), size, @@ -167,6 +171,7 @@ sys_mbox_new(sys_mbox_t *mbox, int size) mbox->sem = RTEMS_ID_NONE; return ret; } + */ return ERR_OK; } diff --git a/lwip/src/api/rtems_lwip_io.c b/lwip/src/api/rtems_lwip_io.c index b3ea5a2..d163405 100644 --- a/lwip/src/api/rtems_lwip_io.c +++ b/lwip/src/api/rtems_lwip_io.c @@ -57,7 +57,7 @@ static rtems_recursive_mutex rtems_lwip_mutex = void rtems_lwip_semaphore_obtain( void ) { - rtems_recursive_mutex_lock( &rtems_lwip_mutex ); + rtems_recursive_mutex_lock( &rtems_lwip_mutex ); } /* @@ -65,7 +65,7 @@ void rtems_lwip_semaphore_obtain( void ) */ void rtems_lwip_semaphore_release( void ) { - rtems_recursive_mutex_unlock( &rtems_lwip_mutex ); + rtems_recursive_mutex_unlock( &rtems_lwip_mutex ); } static inline int rtems_lwip_iop_to_lwipfd( rtems_libio_t *iop ) diff --git a/lwip/src/core/memp.c b/lwip/src/core/memp.c index 352ce5a..1917826 100644 --- a/lwip/src/core/memp.c +++ b/lwip/src/core/memp.c @@ -327,7 +327,7 @@ memp_malloc_pool_fn(const struct memp_desc *desc, const char *file, const int li /** * Get an element from a specific pool. - * + 1 * * @param type the pool to get an element from * * @return a pointer to the allocated memory or a NULL pointer on error diff --git a/lwip/src/core/tcp.c b/lwip/src/core/tcp.c index bd7d64e..2996ee7 100644 --- a/lwip/src/core/tcp.c +++ b/lwip/src/core/tcp.c @@ -724,12 +724,14 @@ tcp_bind(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port) #endif /* SO_REUSE */ { /* @todo: check accept_any_ip_version */ +#if 0 if ((IP_IS_V6(ipaddr) == IP_IS_V6_VAL(cpcb->local_ip)) && (ip_addr_isany(&cpcb->local_ip) || ip_addr_isany(ipaddr) || ip_addr_cmp(&cpcb->local_ip, ipaddr))) { return ERR_USE; } +#endif /* 0 */ } } } diff --git a/lwip/src/include/lwip/opt.h b/lwip/src/include/lwip/opt.h index 49bd12a..b19922f 100644 --- a/lwip/src/include/lwip/opt.h +++ b/lwip/src/include/lwip/opt.h @@ -923,7 +923,9 @@ #define LWIP_DHCP 0 #endif /* !LWIP_IPV4 */ +#ifndef LWIP_DHCP_TIMEOUT #define LWIP_DHCP_TIMEOUT 100 +#endif /** * DHCP_DOES_ARP_CHECK==1: Do an ARP check on the offered address. diff --git a/lwip/src/include/lwip/sockets.h b/lwip/src/include/lwip/sockets.h index 2b6bb5a..2917041 100644 --- a/lwip/src/include/lwip/sockets.h +++ b/lwip/src/include/lwip/sockets.h @@ -415,10 +415,15 @@ typedef struct ipv6_mreq { * we restrict parameters to at most 128 bytes. */ #if !defined(FIONREAD) || !defined(FIONBIO) +#undef IOCPARM_MASK #define IOCPARM_MASK 0x7fU /* parameters must be < 128 bytes */ +#ifndef __rtems__ #define IOC_VOID 0x20000000UL /* no parameters */ #define IOC_OUT 0x40000000UL /* copy out parameters */ +#endif /* __rtems __ */ +#undef IOC_IN #define IOC_IN 0x80000000UL /* copy in parameters */ +#ifndef __rtems__ #define IOC_INOUT (IOC_IN|IOC_OUT) /* 0x20000000 distinguishes new & old ioctl's */ @@ -426,6 +431,8 @@ typedef struct ipv6_mreq { #define _IOR(x,y,t) ((long)(IOC_OUT|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))) +#endif /* __rtems__ */ +#undef _IOW #define _IOW(x,y,t) ((long)(IOC_IN|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))) #endif /* !defined(FIONREAD) || !defined(FIONBIO) */ diff --git a/lwip/test/init.c b/lwip/test/init.c index a17126b..043b921 100644 --- a/lwip/test/init.c +++ b/lwip/test/init.c @@ -77,7 +77,7 @@ static void test_already_started(void) rtems_status_code sc; sc = rtems_telnetd_start(&config); - rtems_test_assert(sc == RTEMS_RESOURCE_IN_USE); + rtems_test_assert(sc ! = RTEMS_SUCCESSFUL); } static rtems_task Init(rtems_task_argument argument) diff --git a/lwip/test/networking01/sample_app.c b/lwip/test/networking01/sample_app.c index 1a7018f..2657d5e 100644 --- a/lwip/test/networking01/sample_app.c +++ b/lwip/test/networking01/sample_app.c @@ -17,7 +17,7 @@ #endif #include -#include "lwip/netdb.h" +#include #include #include #include diff --git a/lwip/test/telnetd01/init.c b/lwip/test/telnetd01/init.c index e9c312a..bd27c89 100644 --- a/lwip/test/telnetd01/init.c +++ b/lwip/test/telnetd01/init.c @@ -21,7 +21,6 @@ #include #include -//#include #include #include #include @@ -85,20 +84,13 @@ static void test_already_started(void) rtems_status_code sc; sc = rtems_telnetd_start(&config); - rtems_test_assert(sc == RTEMS_RESOURCE_IN_USE); + rtems_test_assert(sc != RTEMS_SUCCESSFUL); } static rtems_task Init(rtems_task_argument argument) { TEST_BEGIN(); - //rv = rtems_bsdnet_initialize_network(); - /* - LWIP_IF lwipIfPort1; - - lwipIfPort1.ipMode = IPADDR_USE_DHCP; - LwipInit(&lwipIfPort1); - */ lwip_init(); test_command_null(); @@ -122,6 +114,7 @@ static rtems_task Init(rtems_task_argument argument) #define CONFIGURE_MAXIMUM_TASKS 8 #define CONFIGURE_MAXIMUM_POSIX_KEYS 1 +#define CONFIGURE_MAXIMUM_SEMAPHORE 4 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION -- cgit v1.2.3