first
This commit is contained in:
2
rt-thread/components/net/lwip/port/README.md
Normal file
2
rt-thread/components/net/lwip/port/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
This folder is common for LWIP.
|
||||
|
10
rt-thread/components/net/lwip/port/SConscript
Normal file
10
rt-thread/components/net/lwip/port/SConscript
Normal file
@@ -0,0 +1,10 @@
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
path = [cwd]
|
||||
|
||||
src = Glob('*.c')
|
||||
|
||||
group = DefineGroup('lwIP', src, depend = ['RT_USING_LWIP'], CPPPATH = path)
|
||||
|
||||
Return('group')
|
13
rt-thread/components/net/lwip/port/arch/bpstruct.h
Normal file
13
rt-thread/components/net/lwip/port/arch/bpstruct.h
Normal file
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-02-20 Meco Man add RT-Thread copyright
|
||||
*/
|
||||
|
||||
#if defined(__ICCARM__) || defined(_WIN32)
|
||||
#pragma pack(1)
|
||||
#endif
|
110
rt-thread/components/net/lwip/port/arch/cc.h
Normal file
110
rt-thread/components/net/lwip/port/arch/cc.h
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-02-20 Meco Man add RT-Thread copyright
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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: cc.h,v 1.1.1.1 2004/12/16 14:17:13 bear Exp $
|
||||
*/
|
||||
#ifndef __ARCH_CC_H__
|
||||
#define __ARCH_CC_H__
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
#ifndef BYTE_ORDER
|
||||
#ifdef ARCH_CPU_BIG_ENDIAN
|
||||
#define BYTE_ORDER BIG_ENDIAN
|
||||
#else
|
||||
#define BYTE_ORDER LITTLE_ENDIAN
|
||||
#endif /* ARCH_CPU_BIG_ENDIAN */
|
||||
#endif /* BYTE_ORDER */
|
||||
|
||||
#if RT_USING_LWIP_VER_NUM < 0x20000
|
||||
#include <stdint.h>
|
||||
typedef uint8_t u8_t;
|
||||
typedef int8_t s8_t;
|
||||
typedef uint16_t u16_t;
|
||||
typedef int16_t s16_t;
|
||||
typedef uint32_t u32_t;
|
||||
typedef int32_t s32_t;
|
||||
typedef uintptr_t mem_ptr_t;
|
||||
|
||||
#define U16_F "hu"
|
||||
#define S16_F "hd"
|
||||
#define X16_F "hx"
|
||||
#define U32_F "lu"
|
||||
#define S32_F "ld"
|
||||
#define X32_F "lx"
|
||||
#endif /* RT_USING_LWIP_VER_NUM < 0x20000 */
|
||||
|
||||
#if defined(__CC_ARM) /* ARMCC compiler */
|
||||
#define PACK_STRUCT_FIELD(x) x
|
||||
#define PACK_STRUCT_STRUCT __attribute__ ((__packed__))
|
||||
#define PACK_STRUCT_BEGIN
|
||||
#define PACK_STRUCT_END
|
||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /*Arm Compiler 6*/
|
||||
#define PACK_STRUCT_FIELD(x) x
|
||||
#define PACK_STRUCT_STRUCT __attribute__((packed))
|
||||
#define PACK_STRUCT_BEGIN
|
||||
#define PACK_STRUCT_END
|
||||
#elif defined(__IAR_SYSTEMS_ICC__) /* IAR Compiler */
|
||||
#define PACK_STRUCT_BEGIN
|
||||
#define PACK_STRUCT_STRUCT
|
||||
#define PACK_STRUCT_END
|
||||
#define PACK_STRUCT_FIELD(x) x
|
||||
#define PACK_STRUCT_USE_INCLUDES
|
||||
#elif defined(__GNUC__) /* GNU GCC Compiler */
|
||||
#define PACK_STRUCT_FIELD(x) x
|
||||
#define PACK_STRUCT_STRUCT __attribute__((packed))
|
||||
#define PACK_STRUCT_BEGIN
|
||||
#define PACK_STRUCT_END
|
||||
#elif defined(_MSC_VER)
|
||||
#define PACK_STRUCT_FIELD(x) x
|
||||
#define PACK_STRUCT_STRUCT
|
||||
#define PACK_STRUCT_BEGIN
|
||||
#define PACK_STRUCT_END
|
||||
#define PACK_STRUCT_USE_INCLUDES
|
||||
#endif
|
||||
|
||||
void sys_arch_assert(const char* file, int line);
|
||||
#define LWIP_PLATFORM_DIAG(x) do {rt_kprintf x;} while(0)
|
||||
#define LWIP_PLATFORM_ASSERT(x) do {rt_kprintf(x); sys_arch_assert(__FILE__, __LINE__);}while(0)
|
||||
|
||||
#endif /* __ARCH_CC_H__ */
|
13
rt-thread/components/net/lwip/port/arch/epstruct.h
Normal file
13
rt-thread/components/net/lwip/port/arch/epstruct.h
Normal file
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-02-20 Meco Man add RT-Thread copyright
|
||||
*/
|
||||
|
||||
#if defined(__ICCARM__) || defined(_WIN32)
|
||||
#pragma pack()
|
||||
#endif
|
52
rt-thread/components/net/lwip/port/arch/perf.h
Normal file
52
rt-thread/components/net/lwip/port/arch/perf.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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: perf.h,v 1.1.1.1 2004/12/16 14:17:13 bear Exp $
|
||||
*/
|
||||
#ifndef __ARCH_PERF_H__
|
||||
#define __ARCH_PERF_H__
|
||||
|
||||
//#include <sys/times.h>
|
||||
|
||||
#define PERF_START /* null definition */
|
||||
#define PERF_STOP(x) /* null definition */
|
||||
|
||||
/*
|
||||
void perf_print(unsigned long c1l, unsigned long c1h,
|
||||
unsigned long c2l, unsigned long c2h,
|
||||
char *key);
|
||||
|
||||
void perf_print_times(struct tms *start, struct tms *end, char *key);
|
||||
|
||||
void perf_init(char *fname);
|
||||
*/
|
||||
#endif /* __ARCH_PERF_H__ */
|
67
rt-thread/components/net/lwip/port/arch/sys_arch.h
Normal file
67
rt-thread/components/net/lwip/port/arch/sys_arch.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-02-20 Meco Man add RT-Thread copyright
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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: sys_arch.h,v 1.3 2005/03/13 16:03:23 bear Exp $
|
||||
*/
|
||||
#ifndef __ARCH_SYS_ARCH_H__
|
||||
#define __ARCH_SYS_ARCH_H__
|
||||
|
||||
#include "arch/cc.h"
|
||||
#include <rtthread.h>
|
||||
|
||||
#define SYS_MBOX_NULL RT_NULL
|
||||
#define SYS_SEM_NULL RT_NULL
|
||||
|
||||
typedef rt_uint32_t sys_prot_t;
|
||||
|
||||
#define SYS_MBOX_SIZE 10
|
||||
#define SYS_LWIP_TIMER_NAME "timer"
|
||||
#define SYS_LWIP_MBOX_NAME "mbox"
|
||||
#define SYS_LWIP_SEM_NAME "sem"
|
||||
#define SYS_LWIP_MUTEX_NAME "mu"
|
||||
|
||||
typedef rt_sem_t sys_sem_t;
|
||||
typedef rt_mutex_t sys_mutex_t;
|
||||
typedef rt_mailbox_t sys_mbox_t;
|
||||
typedef rt_thread_t sys_thread_t;
|
||||
|
||||
#endif /* __ARCH_SYS_ARCH_H__ */
|
1266
rt-thread/components/net/lwip/port/ethernetif.c
Normal file
1266
rt-thread/components/net/lwip/port/ethernetif.c
Normal file
File diff suppressed because it is too large
Load Diff
657
rt-thread/components/net/lwip/port/lwipopts.h
Normal file
657
rt-thread/components/net/lwip/port/lwipopts.h
Normal file
@@ -0,0 +1,657 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-02-23 Meco Man integrate v1.4.1 v2.0.3 and v2.1.2 porting layer
|
||||
* 2022-02-25 xiangxistu modify the default config through v1.4.1
|
||||
*/
|
||||
|
||||
#ifndef __LWIPOPTS_H__
|
||||
#define __LWIPOPTS_H__
|
||||
|
||||
#include <rtconfig.h>
|
||||
|
||||
/* ---------- LIBC and standard header files ---------- */
|
||||
#include <limits.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/errno.h>
|
||||
#define LWIP_ERRNO_INCLUDE "sys/errno.h"
|
||||
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#define LWIP_NO_UNISTD_H 0
|
||||
#define LWIP_NO_STDDEF_H 0
|
||||
#define LWIP_NO_STDINT_H 0
|
||||
#define LWIP_NO_INTTYPES_H 0
|
||||
#define LWIP_NO_LIMITS_H 0
|
||||
#define LWIP_NO_CTYPE_H 0
|
||||
#define LWIP_SOCKET_SELECT 1
|
||||
#define LWIP_SOCKET_POLL 1
|
||||
|
||||
#define LWIP_RAND rand
|
||||
|
||||
#ifndef SSIZE_MAX
|
||||
#define SSIZE_MAX INT_MAX
|
||||
#endif
|
||||
|
||||
/* some errno not defined in newlib */
|
||||
#ifndef ENSRNOTFOUND
|
||||
#define ENSRNOTFOUND 163 /* Domain name not found */
|
||||
#endif
|
||||
|
||||
/* ---------- Basic Configuration ---------- */
|
||||
#define LWIP_IPV4 1
|
||||
|
||||
#ifdef RT_USING_LWIP_IPV6
|
||||
#define LWIP_IPV6 1
|
||||
#else
|
||||
#define LWIP_IPV6 0
|
||||
#endif /* RT_USING_LWIP_IPV6 */
|
||||
|
||||
#define NO_SYS 0
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
#define LWIP_SOCKET 1
|
||||
#define LWIP_NETCONN 1
|
||||
|
||||
#ifdef RT_LWIP_IGMP
|
||||
#define LWIP_IGMP 1
|
||||
#else
|
||||
#define LWIP_IGMP 0
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_ICMP
|
||||
#define LWIP_ICMP 1
|
||||
#else
|
||||
#define LWIP_ICMP 0
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_SNMP
|
||||
#define LWIP_SNMP 1
|
||||
#else
|
||||
#define LWIP_SNMP 0
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_DNS
|
||||
#define LWIP_DNS 1
|
||||
#else
|
||||
#define LWIP_DNS 0
|
||||
#endif
|
||||
|
||||
#define LWIP_HAVE_LOOPIF 0
|
||||
|
||||
#define LWIP_PLATFORM_BYTESWAP 0
|
||||
|
||||
/* #define RT_LWIP_DEBUG */
|
||||
|
||||
#ifdef RT_LWIP_DEBUG
|
||||
#define LWIP_DEBUG
|
||||
#endif
|
||||
|
||||
/* ---------- Debug options ---------- */
|
||||
#ifdef LWIP_DEBUG
|
||||
#ifdef RT_LWIP_SYS_DEBUG
|
||||
#define SYS_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define SYS_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_ETHARP_DEBUG
|
||||
#define ETHARP_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define ETHARP_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_PPP_DEBUG
|
||||
#define PPP_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define PPP_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_MEM_DEBUG
|
||||
#define MEM_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define MEM_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_MEMP_DEBUG
|
||||
#define MEMP_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define MEMP_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_PBUF_DEBUG
|
||||
#define PBUF_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define PBUF_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_API_LIB_DEBUG
|
||||
#define API_LIB_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define API_LIB_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_API_MSG_DEBUG
|
||||
#define API_MSG_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define API_MSG_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_TCPIP_DEBUG
|
||||
#define TCPIP_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define TCPIP_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_NETIF_DEBUG
|
||||
#define NETIF_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define NETIF_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_SOCKETS_DEBUG
|
||||
#define SOCKETS_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define SOCKETS_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_DNS_DEBUG
|
||||
#define DNS_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define DNS_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_AUTOIP_DEBUG
|
||||
#define AUTOIP_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define AUTOIP_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_DHCP_DEBUG
|
||||
#define DHCP_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define DHCP_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_IP_DEBUG
|
||||
#define IP_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define IP_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_IP_REASS_DEBUG
|
||||
#define IP_REASS_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define IP_REASS_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_ICMP_DEBUG
|
||||
#define ICMP_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define ICMP_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_IGMP_DEBUG
|
||||
#define IGMP_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define IGMP_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_UDP_DEBUG
|
||||
#define UDP_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define UDP_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_TCP_DEBUG
|
||||
#define TCP_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define TCP_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_TCP_INPUT_DEBUG
|
||||
#define TCP_INPUT_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_TCP_OUTPUT_DEBUG
|
||||
#define TCP_OUTPUT_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_TCP_RTO_DEBUG
|
||||
#define TCP_RTO_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define TCP_RTO_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_TCP_CWND_DEBUG
|
||||
#define TCP_CWND_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define TCP_CWND_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_TCP_WND_DEBUG
|
||||
#define TCP_WND_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define TCP_WND_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_TCP_FR_DEBUG
|
||||
#define TCP_FR_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define TCP_FR_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_TCP_QLEN_DEBUG
|
||||
#define TCP_QLEN_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define TCP_QLEN_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_TCP_RST_DEBUG
|
||||
#define TCP_RST_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define TCP_RST_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#endif /* LWIP_DEBUG */
|
||||
|
||||
#define LWIP_DBG_TYPES_ON (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT)
|
||||
|
||||
/* ---------- Memory options ---------- */
|
||||
#define MEMCPY(dst,src,len) rt_memcpy(dst,src,len)
|
||||
#define SMEMCPY(dst,src,len) MEMCPY(dst,src,len)
|
||||
|
||||
#ifdef RT_LWIP_MEM_ALIGNMENT
|
||||
#define MEM_ALIGNMENT RT_LWIP_MEM_ALIGNMENT
|
||||
#else
|
||||
#define MEM_ALIGNMENT 4
|
||||
#endif
|
||||
|
||||
#define MEMP_OVERFLOW_CHECK 1
|
||||
#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1
|
||||
|
||||
//#define MEM_LIBC_MALLOC 1
|
||||
//#define MEM_USE_POOLS 1
|
||||
//#define MEMP_USE_CUSTOM_POOLS 1
|
||||
//#define MEM_SIZE (1024*64)
|
||||
|
||||
#define MEMP_MEM_MALLOC 0
|
||||
|
||||
/* 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 32 //16
|
||||
|
||||
/* the number of struct netconns */
|
||||
#ifdef RT_MEMP_NUM_NETCONN
|
||||
#define MEMP_NUM_NETCONN RT_MEMP_NUM_NETCONN
|
||||
#endif
|
||||
|
||||
/* the number of UDP protocol control blocks. One per active RAW "connection". */
|
||||
#ifdef RT_LWIP_RAW_PCB_NUM
|
||||
#define MEMP_NUM_RAW_PCB RT_LWIP_RAW_PCB_NUM
|
||||
#endif
|
||||
|
||||
/* the number of UDP protocol control blocks. One per active UDP "connection". */
|
||||
#ifdef RT_LWIP_UDP_PCB_NUM
|
||||
#define MEMP_NUM_UDP_PCB RT_LWIP_UDP_PCB_NUM
|
||||
#endif
|
||||
|
||||
/* the number of simulatenously active TCP connections. */
|
||||
#ifdef RT_LWIP_TCP_PCB_NUM
|
||||
#define MEMP_NUM_TCP_PCB RT_LWIP_TCP_PCB_NUM
|
||||
#endif
|
||||
|
||||
/* the number of simultaneously queued TCP */
|
||||
#ifdef RT_LWIP_TCP_SEG_NUM
|
||||
#define MEMP_NUM_TCP_SEG RT_LWIP_TCP_SEG_NUM
|
||||
#else
|
||||
#define MEMP_NUM_TCP_SEG TCP_SND_QUEUELEN
|
||||
#endif
|
||||
|
||||
/*
|
||||
* You can re-define following setting in rtcofnig.h to overwrite the default
|
||||
* setting in the lwip opts.h
|
||||
*/
|
||||
/* 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_TCPIP_MSG_*: 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_API 16
|
||||
// #define MEMP_NUM_TCPIP_MSG_INPKT 16
|
||||
|
||||
/* ---------- Pbuf options ---------- */
|
||||
/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
|
||||
#ifdef RT_LWIP_PBUF_NUM
|
||||
#define PBUF_POOL_SIZE RT_LWIP_PBUF_NUM
|
||||
#endif
|
||||
|
||||
/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
|
||||
#ifdef RT_LWIP_PBUF_POOL_BUFSIZE
|
||||
#define PBUF_POOL_BUFSIZE RT_LWIP_PBUF_POOL_BUFSIZE
|
||||
#endif
|
||||
|
||||
/* PBUF_LINK_HLEN: the number of bytes that should be allocated for a
|
||||
link level header. */
|
||||
#define PBUF_LINK_HLEN 16
|
||||
|
||||
#ifdef RT_LWIP_ETH_PAD_SIZE
|
||||
#define ETH_PAD_SIZE RT_LWIP_ETH_PAD_SIZE
|
||||
#endif
|
||||
|
||||
#ifdef LWIP_USING_NAT
|
||||
#define IP_NAT 1
|
||||
#else
|
||||
#define IP_NAT 0
|
||||
#endif
|
||||
|
||||
/* ---------- TCP options ---------- */
|
||||
#ifdef RT_LWIP_TCP
|
||||
#define LWIP_TCP 1
|
||||
#else
|
||||
#define LWIP_TCP 0
|
||||
#endif
|
||||
|
||||
#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 1460
|
||||
|
||||
/* TCP sender buffer space (bytes). */
|
||||
#ifdef RT_LWIP_TCP_SND_BUF
|
||||
#define TCP_SND_BUF RT_LWIP_TCP_SND_BUF
|
||||
#else
|
||||
#define TCP_SND_BUF (TCP_MSS * 2)
|
||||
#endif
|
||||
|
||||
/* 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 writable space (bytes). This must be less than or equal
|
||||
to TCP_SND_BUF. It is the amount of space which must be
|
||||
available in the tcp snd_buf for select to return writable */
|
||||
#define TCP_SNDLOWAT (TCP_SND_BUF/2)
|
||||
#define TCP_SNDQUEUELOWAT TCP_SND_QUEUELEN/2
|
||||
|
||||
/* TCP receive window. */
|
||||
#ifdef RT_LWIP_TCP_WND
|
||||
#define TCP_WND RT_LWIP_TCP_WND
|
||||
#else
|
||||
#define TCP_WND (TCP_MSS * 2)
|
||||
#endif
|
||||
|
||||
/* Maximum number of retransmissions of data segments. */
|
||||
#define TCP_MAXRTX 12
|
||||
|
||||
/* Maximum number of retransmissions of SYN segments. */
|
||||
#define TCP_SYNMAXRTX 4
|
||||
|
||||
/* tcpip thread options */
|
||||
#ifdef RT_LWIP_TCPTHREAD_PRIORITY
|
||||
#define TCPIP_MBOX_SIZE RT_LWIP_TCPTHREAD_MBOX_SIZE
|
||||
#define TCPIP_THREAD_PRIO RT_LWIP_TCPTHREAD_PRIORITY
|
||||
#define TCPIP_THREAD_STACKSIZE RT_LWIP_TCPTHREAD_STACKSIZE
|
||||
#else
|
||||
#define TCPIP_MBOX_SIZE 8
|
||||
#define TCPIP_THREAD_PRIO 128
|
||||
#define TCPIP_THREAD_STACKSIZE 4096
|
||||
#endif
|
||||
#define TCPIP_THREAD_NAME "tcpip"
|
||||
#define DEFAULT_TCP_RECVMBOX_SIZE 10
|
||||
|
||||
/* ---------- ARP options ---------- */
|
||||
#define LWIP_ARP 1
|
||||
#define ARP_TABLE_SIZE 10
|
||||
#define ARP_QUEUEING 1
|
||||
|
||||
/* ---------- Checksum options ---------- */
|
||||
#ifdef RT_LWIP_USING_HW_CHECKSUM
|
||||
#define CHECKSUM_GEN_IP 0
|
||||
#define CHECKSUM_GEN_UDP 0
|
||||
#define CHECKSUM_GEN_TCP 0
|
||||
#define CHECKSUM_GEN_ICMP 0
|
||||
#define CHECKSUM_CHECK_IP 0
|
||||
#define CHECKSUM_CHECK_UDP 0
|
||||
#define CHECKSUM_CHECK_TCP 0
|
||||
#define CHECKSUM_CHECK_ICMP 0
|
||||
#endif
|
||||
|
||||
/* ---------- 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 0
|
||||
|
||||
/* IP reassembly and segmentation.These are orthogonal even
|
||||
* if they both deal with IP fragments */
|
||||
#ifdef RT_LWIP_REASSEMBLY_FRAG
|
||||
#define IP_REASSEMBLY 1
|
||||
#define IP_FRAG 1
|
||||
#define IP_REASS_MAX_PBUFS 10
|
||||
#define MEMP_NUM_REASSDATA 10
|
||||
#else
|
||||
#define IP_REASSEMBLY 0
|
||||
#define IP_FRAG 0
|
||||
#endif
|
||||
|
||||
/* ---------- ICMP options ---------- */
|
||||
#define ICMP_TTL 255
|
||||
|
||||
/* ---------- DHCP options ---------- */
|
||||
/* Define LWIP_DHCP to 1 if you want DHCP configuration of
|
||||
interfaces. */
|
||||
#ifdef RT_LWIP_DHCP
|
||||
#define LWIP_DHCP 1
|
||||
#else
|
||||
#define LWIP_DHCP 0
|
||||
#endif
|
||||
|
||||
/* 1 if you want to do an ARP check on the offered address
|
||||
(recommended). */
|
||||
#define DHCP_DOES_ARP_CHECK (LWIP_DHCP)
|
||||
|
||||
/* ---------- AUTOIP options ------- */
|
||||
#define LWIP_AUTOIP 0
|
||||
#define LWIP_DHCP_AUTOIP_COOP (LWIP_DHCP && LWIP_AUTOIP)
|
||||
|
||||
/* ---------- UDP options ---------- */
|
||||
#ifdef RT_LWIP_UDP
|
||||
#define LWIP_UDP 1
|
||||
#else
|
||||
#define LWIP_UDP 0
|
||||
#endif
|
||||
|
||||
#define LWIP_UDPLITE 0
|
||||
#define UDP_TTL 255
|
||||
#define DEFAULT_UDP_RECVMBOX_SIZE 1
|
||||
|
||||
/* ---------- RAW options ---------- */
|
||||
#ifdef RT_LWIP_RAW
|
||||
#define LWIP_RAW 1
|
||||
#else
|
||||
#define LWIP_RAW 0
|
||||
#endif
|
||||
|
||||
#define DEFAULT_RAW_RECVMBOX_SIZE 1
|
||||
#define DEFAULT_ACCEPTMBOX_SIZE 10
|
||||
|
||||
/* ---------- Statistics options ---------- */
|
||||
#ifdef RT_LWIP_STATS
|
||||
#define LWIP_STATS 1
|
||||
#define LWIP_STATS_DISPLAY 1
|
||||
#else
|
||||
#define LWIP_STATS 0
|
||||
#endif
|
||||
|
||||
#if LWIP_STATS
|
||||
#define LINK_STATS 1
|
||||
#define IP_STATS 1
|
||||
#define ICMP_STATS 1
|
||||
#define IGMP_STATS 1
|
||||
#define IPFRAG_STATS 1
|
||||
#define UDP_STATS 1
|
||||
#define TCP_STATS 1
|
||||
#define MEM_STATS 1
|
||||
#define MEMP_STATS 1
|
||||
#define PBUF_STATS 1
|
||||
#define SYS_STATS 1
|
||||
#define MIB2_STATS 1
|
||||
#endif /* LWIP_STATS */
|
||||
|
||||
/* ---------- PPP options ---------- */
|
||||
#ifdef RT_LWIP_PPP
|
||||
#define PPP_SUPPORT 1 /* Set > 0 for PPP */
|
||||
#else
|
||||
#define PPP_SUPPORT 0 /* Set > 0 for PPP */
|
||||
#endif
|
||||
|
||||
#if PPP_SUPPORT
|
||||
#define NUM_PPP 1 /* Max PPP sessions. */
|
||||
|
||||
/* Select modules to enable. Ideally these would be set in the makefile but
|
||||
* we're limited by the command line length so you need to modify the settings
|
||||
* in this file.
|
||||
*/
|
||||
#ifdef RT_LWIP_PPPOE
|
||||
#define PPPOE_SUPPORT 1
|
||||
#else
|
||||
#define PPPOE_SUPPORT 0
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_PPPOS
|
||||
#define PPPOS_SUPPORT 1
|
||||
#else
|
||||
#define PPPOS_SUPPORT 0
|
||||
#endif
|
||||
|
||||
#define PAP_SUPPORT 1 /* Set > 0 for PAP. */
|
||||
#define CHAP_SUPPORT 1 /* Set > 0 for CHAP. */
|
||||
#define MSCHAP_SUPPORT 0 /* Set > 0 for MSCHAP (NOT FUNCTIONAL!) */
|
||||
#define CBCP_SUPPORT 0 /* Set > 0 for CBCP (NOT FUNCTIONAL!) */
|
||||
#define CCP_SUPPORT 0 /* Set > 0 for CCP (NOT FUNCTIONAL!) */
|
||||
#define VJ_SUPPORT 1 /* Set > 0 for VJ header compression. */
|
||||
#define MD5_SUPPORT 1 /* Set > 0 for MD5 (see also CHAP) */
|
||||
|
||||
#endif /* PPP_SUPPORT */
|
||||
|
||||
/**
|
||||
* LWIP_POSIX_SOCKETS_IO_NAMES==1: Enable POSIX-style sockets functions names.
|
||||
* Disable this option if you use a POSIX operating system that uses the same
|
||||
* names (read, write & close). (only used if you use sockets.c)
|
||||
*/
|
||||
#ifndef LWIP_POSIX_SOCKETS_IO_NAMES
|
||||
#define LWIP_POSIX_SOCKETS_IO_NAMES 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* LWIP_TCP_KEEPALIVE==1: Enable TCP_KEEPIDLE, TCP_KEEPINTVL and TCP_KEEPCNT
|
||||
* options processing. Note that TCP_KEEPIDLE and TCP_KEEPINTVL have to be set
|
||||
* in seconds. (does not require sockets.c, and will affect tcp.c)
|
||||
*/
|
||||
#ifndef LWIP_TCP_KEEPALIVE
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* LWIP_NETIF_HOSTNAME==1: Support netif hostname
|
||||
*/
|
||||
#ifndef LWIP_NETIF_HOSTNAME
|
||||
#define LWIP_NETIF_HOSTNAME 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* RT_LWIP_NETIF_NAMESIZE support netif name length(in netif.c)
|
||||
*/
|
||||
#ifdef RT_LWIP_NETIF_NAMESIZE
|
||||
#if (RT_LWIP_NETIF_NAMESIZE < 2)
|
||||
#warning NETIF_NAMESIZE too small, the value must be greater than or equal to 6.
|
||||
#endif
|
||||
#define NETIF_NAMESIZE RT_LWIP_NETIF_NAMESIZE
|
||||
#endif /* RT_LWIP_NETIF_NAMESIZE */
|
||||
|
||||
/**
|
||||
* LWIP_NETIF_API==1: Support netif api (in netifapi.c)
|
||||
*/
|
||||
#ifndef LWIP_NETIF_API
|
||||
#define LWIP_NETIF_API 1
|
||||
#endif
|
||||
|
||||
/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active timeouts. */
|
||||
#define MEMP_NUM_SYS_TIMEOUT (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT + (LWIP_IPV6 ? (1 + (2*LWIP_IPV6)) : 0))
|
||||
|
||||
/*
|
||||
* LWIP_COMPAT_SOCKETS==1: Enable BSD-style sockets functions names.
|
||||
* (only used if you use sockets.c)
|
||||
*/
|
||||
#ifdef SAL_USING_POSIX
|
||||
#define LWIP_COMPAT_SOCKETS 0
|
||||
#else
|
||||
#ifndef LWIP_COMPAT_SOCKETS
|
||||
#define LWIP_COMPAT_SOCKETS 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* LWIP_SO_SNDTIMEO==1: Enable send timeout for sockets/netconns and
|
||||
* SO_SNDTIMEO processing.
|
||||
*/
|
||||
#ifndef LWIP_SO_SNDTIMEO
|
||||
#define LWIP_SO_SNDTIMEO 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* LWIP_SO_RCVTIMEO==1: Enable receive timeout for sockets/netconns and
|
||||
* SO_RCVTIMEO processing.
|
||||
*/
|
||||
#ifndef LWIP_SO_RCVTIMEO
|
||||
#define LWIP_SO_RCVTIMEO 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* LWIP_SO_RCVBUF==1: Enable SO_RCVBUF processing.
|
||||
*/
|
||||
#ifndef LWIP_SO_RCVBUF
|
||||
#define LWIP_SO_RCVBUF 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* If LWIP_SO_RCVBUF is used, this is the default value for recv_bufsize.
|
||||
*/
|
||||
#ifndef RECV_BUFSIZE_DEFAULT
|
||||
#define RECV_BUFSIZE_DEFAULT 8192
|
||||
#endif
|
||||
|
||||
/**
|
||||
* SO_REUSE==1: Enable SO_REUSEADDR option.
|
||||
*/
|
||||
#ifndef SO_REUSE
|
||||
#define SO_REUSE 0
|
||||
#endif
|
||||
|
||||
#if RT_USING_LWIP_VER_NUM >= 0x20000 /* >= v2.0.0 */
|
||||
#if RT_USING_LWIP_VER_NUM < 0x20102 /* >= v2.0.0 && < v2.1.2 */
|
||||
#define LWIP_HOOK_IP4_ROUTE_SRC(dest, src) lwip_ip4_route_src(dest, src)
|
||||
#else /* >= v2.1.2 */
|
||||
#define LWIP_HOOK_IP4_ROUTE_SRC(src, dest) lwip_ip4_route_src(dest, src)
|
||||
#endif
|
||||
#endif /* RT_USING_LWIP_VER_NUM >= 0x20000 */
|
||||
|
||||
#endif /* __LWIPOPTS_H__ */
|
10
rt-thread/components/net/lwip/port/lwippools.h
Normal file
10
rt-thread/components/net/lwip/port/lwippools.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#if 1
|
||||
LWIP_MALLOC_MEMPOOL_START
|
||||
LWIP_MALLOC_MEMPOOL((unsigned char)128, 256)
|
||||
LWIP_MALLOC_MEMPOOL((unsigned char)128, 512)
|
||||
LWIP_MALLOC_MEMPOOL((unsigned char)128, 1024)
|
||||
LWIP_MALLOC_MEMPOOL((unsigned char)128, 1514)
|
||||
LWIP_MALLOC_MEMPOOL((unsigned char)128, 1536)
|
||||
LWIP_MALLOC_MEMPOOL((unsigned char)128, 4096)
|
||||
LWIP_MALLOC_MEMPOOL_END
|
||||
#endif
|
63
rt-thread/components/net/lwip/port/netif/ethernetif.h
Normal file
63
rt-thread/components/net/lwip/port/netif/ethernetif.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-02-22 xiangxistu integrate v1.4.1 v2.0.3 and v2.1.2 porting layer
|
||||
*/
|
||||
|
||||
#ifndef __NETIF_ETHERNETIF_H__
|
||||
#define __NETIF_ETHERNETIF_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "lwip/netif.h"
|
||||
#include <rtthread.h>
|
||||
|
||||
#define NIOCTL_GADDR 0x01
|
||||
#ifndef RT_LWIP_ETH_MTU
|
||||
#define ETHERNET_MTU 1500
|
||||
#else
|
||||
#define ETHERNET_MTU RT_LWIP_ETH_MTU
|
||||
#endif
|
||||
|
||||
/* eth flag with auto_linkup or phy_linkup */
|
||||
#define ETHIF_LINK_AUTOUP 0x0000
|
||||
#define ETHIF_LINK_PHYUP 0x0100
|
||||
|
||||
struct eth_device
|
||||
{
|
||||
/* inherit from rt_device */
|
||||
struct rt_device parent;
|
||||
|
||||
/* network interface for lwip */
|
||||
struct netif *netif;
|
||||
|
||||
rt_uint16_t flags;
|
||||
rt_uint8_t link_changed;
|
||||
rt_uint8_t link_status;
|
||||
rt_uint8_t rx_notice;
|
||||
|
||||
struct rt_spinlock spinlock;
|
||||
|
||||
/* eth device interface */
|
||||
struct pbuf* (*eth_rx)(rt_device_t dev);
|
||||
rt_err_t (*eth_tx)(rt_device_t dev, struct pbuf* p);
|
||||
};
|
||||
|
||||
int eth_system_device_init(void);
|
||||
void eth_device_deinit(struct eth_device *dev);
|
||||
rt_err_t eth_device_ready(struct eth_device* dev);
|
||||
rt_err_t eth_device_init(struct eth_device * dev, const char *name);
|
||||
rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_uint16_t flag);
|
||||
rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __NETIF_ETHERNETIF_H__ */
|
779
rt-thread/components/net/lwip/port/sys_arch.c
Normal file
779
rt-thread/components/net/lwip/port/sys_arch.c
Normal file
@@ -0,0 +1,779 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2012-12-8 Bernard add file header
|
||||
* export bsd socket symbol for RT-Thread Application Module
|
||||
* 2013-05-25 Bernard port to v1.4.1
|
||||
* 2017-03-26 HuangXiHans port to v2.0.2
|
||||
* 2017-11-15 Bernard add lock for init_done callback
|
||||
* 2018-11-02 MurphyZhao port to v2.1.0
|
||||
* 2020-06-20 liuxianliang port to v2.1.2
|
||||
* 2021-06-25 liuxianliang port to v2.0.3
|
||||
* 2022-01-18 Meco Man remove v2.0.2
|
||||
* 2022-02-20 Meco Man integrate v1.4.1 v2.0.3 and v2.1.2 porting layer
|
||||
* 2023-10-31 xqyjlj fix spinlock`s deadlock
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rthw.h>
|
||||
|
||||
#include <arch/sys_arch.h>
|
||||
#include <lwip/sys.h>
|
||||
#include <lwip/opt.h>
|
||||
#include <lwip/stats.h>
|
||||
#include <lwip/err.h>
|
||||
#include <lwip/debug.h>
|
||||
#include <lwip/netif.h>
|
||||
#include <lwip/netifapi.h>
|
||||
#include <lwip/tcpip.h>
|
||||
#include <lwip/sio.h>
|
||||
#include <lwip/init.h>
|
||||
#include <lwip/dhcp.h>
|
||||
#include <lwip/inet.h>
|
||||
#include <netif/ethernetif.h>
|
||||
#include <netif/etharp.h>
|
||||
|
||||
#ifdef RT_USING_SMP
|
||||
static struct rt_mutex _mutex = {0};
|
||||
#else
|
||||
static RT_DEFINE_SPINLOCK(_spinlock);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Initialize the ethernetif layer and set network interface device up
|
||||
*/
|
||||
static void tcpip_init_done_callback(void *arg)
|
||||
{
|
||||
rt_sem_release((rt_sem_t)arg);
|
||||
}
|
||||
|
||||
/**
|
||||
* LwIP system initialization
|
||||
*/
|
||||
int lwip_system_init(void)
|
||||
{
|
||||
rt_err_t rc;
|
||||
struct rt_semaphore done_sem;
|
||||
static rt_bool_t init_ok = RT_FALSE;
|
||||
|
||||
if (init_ok)
|
||||
{
|
||||
rt_kprintf("lwip system already init.\n");
|
||||
return 0;
|
||||
}
|
||||
#ifdef RT_USING_SMP
|
||||
rt_mutex_init(&_mutex, "sys_arch", RT_IPC_FLAG_FIFO);
|
||||
#endif
|
||||
|
||||
extern int eth_system_device_init_private(void);
|
||||
eth_system_device_init_private();
|
||||
|
||||
/* set default netif to NULL */
|
||||
netif_default = RT_NULL;
|
||||
|
||||
rc = rt_sem_init(&done_sem, "done", 0, RT_IPC_FLAG_FIFO);
|
||||
if (rc != RT_EOK)
|
||||
{
|
||||
LWIP_ASSERT("Failed to create semaphore", 0);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
tcpip_init(tcpip_init_done_callback, (void *)&done_sem);
|
||||
|
||||
/* waiting for initialization done */
|
||||
if (rt_sem_take(&done_sem, RT_WAITING_FOREVER) != RT_EOK)
|
||||
{
|
||||
rt_sem_detach(&done_sem);
|
||||
|
||||
return -1;
|
||||
}
|
||||
rt_sem_detach(&done_sem);
|
||||
|
||||
rt_kprintf("lwIP-%d.%d.%d initialized!\n", LWIP_VERSION_MAJOR, LWIP_VERSION_MINOR, LWIP_VERSION_REVISION);
|
||||
|
||||
init_ok = RT_TRUE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
INIT_PREV_EXPORT(lwip_system_init);
|
||||
|
||||
void sys_init(void)
|
||||
{
|
||||
/* nothing on RT-Thread porting */
|
||||
}
|
||||
|
||||
void lwip_sys_init(void)
|
||||
{
|
||||
lwip_system_init();
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new semaphore
|
||||
*
|
||||
* @return the operation status, ERR_OK on OK; others on error
|
||||
*/
|
||||
err_t sys_sem_new(sys_sem_t *sem, u8_t count)
|
||||
{
|
||||
static unsigned short counter = 0;
|
||||
char tname[RT_NAME_MAX];
|
||||
sys_sem_t tmpsem;
|
||||
|
||||
RT_DEBUG_NOT_IN_INTERRUPT;
|
||||
|
||||
rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_SEM_NAME, counter);
|
||||
counter ++;
|
||||
|
||||
tmpsem = rt_sem_create(tname, count, RT_IPC_FLAG_FIFO);
|
||||
if (tmpsem == RT_NULL)
|
||||
{
|
||||
return ERR_MEM;
|
||||
}
|
||||
else
|
||||
{
|
||||
*sem = tmpsem;
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Deallocate a semaphore
|
||||
*/
|
||||
void sys_sem_free(sys_sem_t *sem)
|
||||
{
|
||||
RT_DEBUG_NOT_IN_INTERRUPT;
|
||||
rt_sem_delete(*sem);
|
||||
}
|
||||
|
||||
/*
|
||||
* Signal a semaphore
|
||||
*/
|
||||
void sys_sem_signal(sys_sem_t *sem)
|
||||
{
|
||||
rt_sem_release(*sem);
|
||||
}
|
||||
|
||||
/*
|
||||
* Block the thread while waiting for the semaphore to be signaled
|
||||
*
|
||||
* @return If the timeout argument is non-zero, it will return the number of milliseconds
|
||||
* spent waiting for the semaphore to be signaled; If the semaphore isn't signaled
|
||||
* within the specified time, it will return SYS_ARCH_TIMEOUT; If the thread doesn't
|
||||
* wait for the semaphore, it will return zero
|
||||
*/
|
||||
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
|
||||
{
|
||||
rt_err_t ret;
|
||||
s32_t t;
|
||||
u32_t tick;
|
||||
|
||||
RT_DEBUG_NOT_IN_INTERRUPT;
|
||||
|
||||
/* get the begin tick */
|
||||
tick = rt_tick_get();
|
||||
if (timeout == 0)
|
||||
{
|
||||
t = RT_WAITING_FOREVER;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* convert msecond to os tick */
|
||||
if (timeout < (1000 / RT_TICK_PER_SECOND))
|
||||
t = 1;
|
||||
else
|
||||
t = timeout / (1000 / RT_TICK_PER_SECOND);
|
||||
}
|
||||
|
||||
ret = rt_sem_take(*sem, t);
|
||||
|
||||
if (ret == -RT_ETIMEOUT)
|
||||
{
|
||||
return SYS_ARCH_TIMEOUT;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ret == RT_EOK)
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
/* get elapse msecond */
|
||||
tick = rt_tick_get() - tick;
|
||||
|
||||
/* convert tick to msecond */
|
||||
tick = tick * (1000 / RT_TICK_PER_SECOND);
|
||||
if (tick == 0)
|
||||
tick = 1;
|
||||
|
||||
return tick;
|
||||
}
|
||||
|
||||
#ifndef sys_sem_valid
|
||||
/** Check if a semaphore is valid/allocated:
|
||||
* return 1 for valid, 0 for invalid
|
||||
*/
|
||||
int sys_sem_valid(sys_sem_t *sem)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (*sem) ret = 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef sys_sem_set_invalid
|
||||
/** Set a semaphore invalid so that sys_sem_valid returns 0
|
||||
*/
|
||||
void sys_sem_set_invalid(sys_sem_t *sem)
|
||||
{
|
||||
*sem = RT_NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ====================== Mutex ====================== */
|
||||
|
||||
/** Create a new mutex
|
||||
* @param mutex pointer to the mutex to create
|
||||
* @return a new mutex
|
||||
*/
|
||||
err_t sys_mutex_new(sys_mutex_t *mutex)
|
||||
{
|
||||
static unsigned short counter = 0;
|
||||
char tname[RT_NAME_MAX];
|
||||
sys_mutex_t tmpmutex;
|
||||
|
||||
RT_DEBUG_NOT_IN_INTERRUPT;
|
||||
|
||||
rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_MUTEX_NAME, counter);
|
||||
counter ++;
|
||||
|
||||
tmpmutex = rt_mutex_create(tname, RT_IPC_FLAG_PRIO);
|
||||
if (tmpmutex == RT_NULL)
|
||||
{
|
||||
return ERR_MEM;
|
||||
}
|
||||
else
|
||||
{
|
||||
*mutex = tmpmutex;
|
||||
return ERR_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/** Lock a mutex
|
||||
* @param mutex the mutex to lock
|
||||
*/
|
||||
void sys_mutex_lock(sys_mutex_t *mutex)
|
||||
{
|
||||
RT_DEBUG_NOT_IN_INTERRUPT;
|
||||
rt_mutex_take(*mutex, RT_WAITING_FOREVER);
|
||||
return;
|
||||
}
|
||||
|
||||
/** Unlock a mutex
|
||||
* @param mutex the mutex to unlock
|
||||
*/
|
||||
void sys_mutex_unlock(sys_mutex_t *mutex)
|
||||
{
|
||||
rt_mutex_release(*mutex);
|
||||
}
|
||||
|
||||
/** Delete a semaphore
|
||||
* @param mutex the mutex to delete
|
||||
*/
|
||||
void sys_mutex_free(sys_mutex_t *mutex)
|
||||
{
|
||||
RT_DEBUG_NOT_IN_INTERRUPT;
|
||||
rt_mutex_delete(*mutex);
|
||||
}
|
||||
|
||||
#ifndef sys_mutex_valid
|
||||
/** Check if a mutex is valid/allocated:
|
||||
* return 1 for valid, 0 for invalid
|
||||
*/
|
||||
int sys_mutex_valid(sys_mutex_t *mutex)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (*mutex) ret = 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef sys_mutex_set_invalid
|
||||
/** Set a mutex invalid so that sys_mutex_valid returns 0
|
||||
*/
|
||||
void sys_mutex_set_invalid(sys_mutex_t *mutex)
|
||||
{
|
||||
*mutex = RT_NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ====================== Mailbox ====================== */
|
||||
|
||||
/*
|
||||
* Create an empty mailbox for maximum "size" elements
|
||||
*
|
||||
* @return the operation status, ERR_OK on OK; others on error
|
||||
*/
|
||||
err_t sys_mbox_new(sys_mbox_t *mbox, int size)
|
||||
{
|
||||
static unsigned short counter = 0;
|
||||
char tname[RT_NAME_MAX];
|
||||
sys_mbox_t tmpmbox;
|
||||
|
||||
RT_DEBUG_NOT_IN_INTERRUPT;
|
||||
|
||||
rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_MBOX_NAME, counter);
|
||||
counter ++;
|
||||
|
||||
tmpmbox = rt_mb_create(tname, size, RT_IPC_FLAG_FIFO);
|
||||
if (tmpmbox != RT_NULL)
|
||||
{
|
||||
*mbox = tmpmbox;
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
/*
|
||||
* Deallocate a mailbox
|
||||
*/
|
||||
void sys_mbox_free(sys_mbox_t *mbox)
|
||||
{
|
||||
RT_DEBUG_NOT_IN_INTERRUPT;
|
||||
rt_mb_delete(*mbox);
|
||||
return;
|
||||
}
|
||||
|
||||
/** Post a message to an mbox - may not fail
|
||||
* -> blocks if full, only used from tasks not from ISR
|
||||
* @param mbox mbox to posts the message
|
||||
* @param msg message to post (ATTENTION: can be NULL)
|
||||
*/
|
||||
void sys_mbox_post(sys_mbox_t *mbox, void *msg)
|
||||
{
|
||||
RT_DEBUG_NOT_IN_INTERRUPT;
|
||||
rt_mb_send_wait(*mbox, (rt_ubase_t)msg, RT_WAITING_FOREVER);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to post the "msg" to the mailbox
|
||||
*
|
||||
* @return return ERR_OK if the "msg" is posted, ERR_MEM if the mailbox is full
|
||||
*/
|
||||
err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg)
|
||||
{
|
||||
if (rt_mb_send(*mbox, (rt_ubase_t)msg) == RT_EOK)
|
||||
{
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
#if (LWIP_VERSION_MAJOR * 100 + LWIP_VERSION_MINOR) >= 201 /* >= v2.1.0 */
|
||||
err_t sys_mbox_trypost_fromisr(sys_mbox_t *q, void *msg)
|
||||
{
|
||||
return sys_mbox_trypost(q, msg);
|
||||
}
|
||||
#endif /* (LWIP_VERSION_MAJOR * 100 + LWIP_VERSION_MINOR) >= 201 */
|
||||
|
||||
/** Wait for a new message to arrive in the mbox
|
||||
* @param mbox mbox to get a message from
|
||||
* @param msg pointer where the message is stored
|
||||
* @param timeout maximum time (in milliseconds) to wait for a message
|
||||
* @return time (in milliseconds) waited for a message, may be 0 if not waited
|
||||
or SYS_ARCH_TIMEOUT on timeout
|
||||
* The returned time has to be accurate to prevent timer jitter!
|
||||
*/
|
||||
u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
|
||||
{
|
||||
rt_err_t ret;
|
||||
s32_t t;
|
||||
u32_t tick;
|
||||
|
||||
RT_DEBUG_NOT_IN_INTERRUPT;
|
||||
|
||||
/* get the begin tick */
|
||||
tick = rt_tick_get();
|
||||
|
||||
if(timeout == 0)
|
||||
{
|
||||
t = RT_WAITING_FOREVER;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* convirt msecond to os tick */
|
||||
if (timeout < (1000 / RT_TICK_PER_SECOND))
|
||||
t = 1;
|
||||
else
|
||||
t = timeout / (1000 / RT_TICK_PER_SECOND);
|
||||
}
|
||||
/*When the waiting msg is generated by the application through signaling mechanisms,
|
||||
only by using interruptible mode can the program be made runnable again*/
|
||||
ret = rt_mb_recv_interruptible(*mbox, (rt_ubase_t *)msg, t);
|
||||
if(ret != RT_EOK)
|
||||
{
|
||||
return SYS_ARCH_TIMEOUT;
|
||||
}
|
||||
|
||||
/* get elapse msecond */
|
||||
tick = rt_tick_get() - tick;
|
||||
|
||||
/* convert tick to msecond */
|
||||
tick = tick * (1000 / RT_TICK_PER_SECOND);
|
||||
if (tick == 0)
|
||||
tick = 1;
|
||||
|
||||
return tick;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup sys_mbox
|
||||
* This is similar to sys_arch_mbox_fetch, however if a message is not
|
||||
* present in the mailbox, it immediately returns with the code
|
||||
* SYS_MBOX_EMPTY. On success 0 is returned.
|
||||
* To allow for efficient implementations, this can be defined as a
|
||||
* function-like macro in sys_arch.h instead of a normal function. For
|
||||
* example, a naive implementation could be:
|
||||
* \#define sys_arch_mbox_tryfetch(mbox,msg) sys_arch_mbox_fetch(mbox,msg,1)
|
||||
* although this would introduce unnecessary delays.
|
||||
*
|
||||
* @param mbox mbox to get a message from
|
||||
* @param msg pointer where the message is stored
|
||||
* @return 0 (milliseconds) if a message has been received
|
||||
* or SYS_MBOX_EMPTY if the mailbox is empty
|
||||
*/
|
||||
u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = rt_mb_recv(*mbox, (rt_ubase_t *)msg, 0);
|
||||
if(ret == -RT_ETIMEOUT)
|
||||
{
|
||||
return SYS_ARCH_TIMEOUT;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ret == RT_EOK)
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef sys_mbox_valid
|
||||
/** Check if an mbox is valid/allocated:
|
||||
* return 1 for valid, 0 for invalid
|
||||
*/
|
||||
int sys_mbox_valid(sys_mbox_t *mbox)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (*mbox) ret = 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef sys_mbox_set_invalid
|
||||
/** Set an mbox invalid so that sys_mbox_valid returns 0
|
||||
*/
|
||||
void sys_mbox_set_invalid(sys_mbox_t *mbox)
|
||||
{
|
||||
*mbox = RT_NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ====================== System ====================== */
|
||||
|
||||
/*
|
||||
* Start a new thread named "name" with priority "prio" that will begin
|
||||
* its execution in the function "thread()". The "arg" argument will be
|
||||
* passed as an argument to the thread() function
|
||||
*/
|
||||
sys_thread_t sys_thread_new(const char *name,
|
||||
lwip_thread_fn thread,
|
||||
void *arg,
|
||||
int stacksize,
|
||||
int prio)
|
||||
{
|
||||
rt_thread_t t;
|
||||
|
||||
RT_DEBUG_NOT_IN_INTERRUPT;
|
||||
|
||||
/* create thread */
|
||||
t = rt_thread_create(name, thread, arg, stacksize, prio, 20);
|
||||
RT_ASSERT(t != RT_NULL);
|
||||
|
||||
/* startup thread */
|
||||
rt_thread_startup(t);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
sys_prot_t sys_arch_protect(void)
|
||||
{
|
||||
#ifdef RT_USING_SMP
|
||||
rt_mutex_take(&_mutex, RT_WAITING_FOREVER);
|
||||
return 0;
|
||||
#else
|
||||
rt_base_t level;
|
||||
level = rt_spin_lock_irqsave(&_spinlock);
|
||||
return level;
|
||||
#endif
|
||||
}
|
||||
|
||||
void sys_arch_unprotect(sys_prot_t pval)
|
||||
{
|
||||
#ifdef RT_USING_SMP
|
||||
RT_UNUSED(pval);
|
||||
rt_mutex_release(&_mutex);
|
||||
#else
|
||||
rt_spin_unlock_irqrestore(&_spinlock, pval);
|
||||
#endif
|
||||
}
|
||||
|
||||
void sys_arch_assert(const char *file, int line)
|
||||
{
|
||||
rt_kprintf("\nAssertion: %d in %s, thread %s\n",
|
||||
line, file, rt_thread_self()->parent.name);
|
||||
RT_ASSERT(0);
|
||||
}
|
||||
|
||||
u32_t sys_jiffies(void)
|
||||
{
|
||||
return rt_tick_get();
|
||||
}
|
||||
|
||||
u32_t sys_now(void)
|
||||
{
|
||||
return rt_tick_get_millisecond();
|
||||
}
|
||||
|
||||
rt_weak void mem_init(void)
|
||||
{
|
||||
}
|
||||
|
||||
void *mem_calloc(mem_size_t count, mem_size_t size)
|
||||
{
|
||||
return rt_calloc(count, size);
|
||||
}
|
||||
|
||||
void *mem_trim(void *mem, mem_size_t size)
|
||||
{
|
||||
// return rt_realloc(mem, size);
|
||||
/* not support trim yet */
|
||||
return mem;
|
||||
}
|
||||
|
||||
void *mem_malloc(mem_size_t size)
|
||||
{
|
||||
return rt_malloc(size);
|
||||
}
|
||||
|
||||
void mem_free(void *mem)
|
||||
{
|
||||
rt_free(mem);
|
||||
}
|
||||
|
||||
#ifdef RT_LWIP_PPP
|
||||
u32_t sio_read(sio_fd_t fd, u8_t *buf, u32_t size)
|
||||
{
|
||||
u32_t len;
|
||||
|
||||
RT_ASSERT(fd != RT_NULL);
|
||||
|
||||
len = rt_device_read((rt_device_t)fd, 0, buf, size);
|
||||
if (len <= 0)
|
||||
return 0;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
u32_t sio_write(sio_fd_t fd, u8_t *buf, u32_t size)
|
||||
{
|
||||
RT_ASSERT(fd != RT_NULL);
|
||||
return rt_device_write((rt_device_t)fd, 0, buf, size);
|
||||
}
|
||||
|
||||
void sio_read_abort(sio_fd_t fd)
|
||||
{
|
||||
rt_kprintf("read_abort\n");
|
||||
}
|
||||
|
||||
void ppp_trace(int level, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
rt_size_t length;
|
||||
static char rt_log_buf[RT_CONSOLEBUF_SIZE];
|
||||
|
||||
va_start(args, format);
|
||||
length = rt_vsprintf(rt_log_buf, format, args);
|
||||
rt_device_write((rt_device_t)rt_console_get_device(), 0, rt_log_buf, length);
|
||||
va_end(args);
|
||||
}
|
||||
#endif /* RT_LWIP_PPP */
|
||||
|
||||
#if LWIP_VERSION_MAJOR >= 2 /* >= v2.x */
|
||||
#if MEM_OVERFLOW_CHECK || MEMP_OVERFLOW_CHECK
|
||||
/**
|
||||
* Check if a mep element was victim of an overflow or underflow
|
||||
* (e.g. the restricted area after/before it has been altered)
|
||||
*
|
||||
* @param p the mem element to check
|
||||
* @param size allocated size of the element
|
||||
* @param descr1 description of the element source shown on error
|
||||
* @param descr2 description of the element source shown on error
|
||||
*/
|
||||
void mem_overflow_check_raw(void *p, size_t size, const char *descr1, const char *descr2)
|
||||
{
|
||||
#if MEM_SANITY_REGION_AFTER_ALIGNED || MEM_SANITY_REGION_BEFORE_ALIGNED
|
||||
u16_t k;
|
||||
u8_t *m;
|
||||
|
||||
#if MEM_SANITY_REGION_AFTER_ALIGNED > 0
|
||||
m = (u8_t *)p + size;
|
||||
for (k = 0; k < MEM_SANITY_REGION_AFTER_ALIGNED; k++) {
|
||||
if (m[k] != 0xcd) {
|
||||
char errstr[128];
|
||||
rt_snprintf(errstr, sizeof(errstr), "detected mem overflow in %s%s", descr1, descr2);
|
||||
LWIP_ASSERT(errstr, 0);
|
||||
}
|
||||
}
|
||||
#endif /* MEM_SANITY_REGION_AFTER_ALIGNED > 0 */
|
||||
|
||||
#if MEM_SANITY_REGION_BEFORE_ALIGNED > 0
|
||||
m = (u8_t *)p - MEM_SANITY_REGION_BEFORE_ALIGNED;
|
||||
for (k = 0; k < MEM_SANITY_REGION_BEFORE_ALIGNED; k++) {
|
||||
if (m[k] != 0xcd) {
|
||||
char errstr[128];
|
||||
rt_snprintf(errstr, sizeof(errstr), "detected mem underflow in %s%s", descr1, descr2);
|
||||
LWIP_ASSERT(errstr, 0);
|
||||
}
|
||||
}
|
||||
#endif /* MEM_SANITY_REGION_BEFORE_ALIGNED > 0 */
|
||||
#else
|
||||
LWIP_UNUSED_ARG(p);
|
||||
LWIP_UNUSED_ARG(descr1);
|
||||
LWIP_UNUSED_ARG(descr2);
|
||||
#endif /* MEM_SANITY_REGION_AFTER_ALIGNED || MEM_SANITY_REGION_BEFORE_ALIGNED */
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the restricted area of a mem element.
|
||||
*/
|
||||
void mem_overflow_init_raw(void *p, size_t size)
|
||||
{
|
||||
#if MEM_SANITY_REGION_BEFORE_ALIGNED > 0 || MEM_SANITY_REGION_AFTER_ALIGNED > 0
|
||||
u8_t *m;
|
||||
#if MEM_SANITY_REGION_BEFORE_ALIGNED > 0
|
||||
m = (u8_t *)p - MEM_SANITY_REGION_BEFORE_ALIGNED;
|
||||
rt_memset(m, 0xcd, MEM_SANITY_REGION_BEFORE_ALIGNED);
|
||||
#endif
|
||||
#if MEM_SANITY_REGION_AFTER_ALIGNED > 0
|
||||
m = (u8_t *)p + size;
|
||||
rt_memset(m, 0xcd, MEM_SANITY_REGION_AFTER_ALIGNED);
|
||||
#endif
|
||||
#else /* MEM_SANITY_REGION_BEFORE_ALIGNED > 0 || MEM_SANITY_REGION_AFTER_ALIGNED > 0 */
|
||||
LWIP_UNUSED_ARG(p);
|
||||
LWIP_UNUSED_ARG(size);
|
||||
#endif /* MEM_SANITY_REGION_BEFORE_ALIGNED > 0 || MEM_SANITY_REGION_AFTER_ALIGNED > 0 */
|
||||
}
|
||||
#endif /* MEM_OVERFLOW_CHECK || MEMP_OVERFLOW_CHECK */
|
||||
|
||||
#ifdef LWIP_HOOK_IP4_ROUTE_SRC
|
||||
struct netif *lwip_ip4_route_src(const ip4_addr_t *dest, const ip4_addr_t *src)
|
||||
{
|
||||
struct netif *netif;
|
||||
|
||||
if (src == NULL)
|
||||
return NULL;
|
||||
|
||||
/* iterate through netifs */
|
||||
for (netif = netif_list; netif != NULL; netif = netif->next)
|
||||
{
|
||||
/* is the netif up, does it have a link and a valid address? */
|
||||
if (netif_is_up(netif) && netif_is_link_up(netif) && !ip4_addr_isany_val(*netif_ip4_addr(netif)))
|
||||
{
|
||||
/* source ip address equals netif's ip address? */
|
||||
if (ip4_addr_cmp(src, netif_ip4_addr(netif)))
|
||||
{
|
||||
return netif;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif /* LWIP_HOOK_IP4_ROUTE_SRC */
|
||||
#endif /*LWIP_VERSION_MAJOR >= 2 */
|
||||
|
||||
#if LWIP_SOCKET
|
||||
#include <lwip/sockets.h>
|
||||
RTM_EXPORT(lwip_accept);
|
||||
RTM_EXPORT(lwip_bind);
|
||||
RTM_EXPORT(lwip_shutdown);
|
||||
RTM_EXPORT(lwip_getpeername);
|
||||
RTM_EXPORT(lwip_getsockname);
|
||||
RTM_EXPORT(lwip_getsockopt);
|
||||
RTM_EXPORT(lwip_setsockopt);
|
||||
RTM_EXPORT(lwip_close);
|
||||
RTM_EXPORT(lwip_connect);
|
||||
RTM_EXPORT(lwip_listen);
|
||||
RTM_EXPORT(lwip_recv);
|
||||
RTM_EXPORT(lwip_read);
|
||||
RTM_EXPORT(lwip_recvfrom);
|
||||
RTM_EXPORT(lwip_send);
|
||||
RTM_EXPORT(lwip_sendto);
|
||||
RTM_EXPORT(lwip_socket);
|
||||
RTM_EXPORT(lwip_write);
|
||||
RTM_EXPORT(lwip_select);
|
||||
RTM_EXPORT(lwip_ioctl);
|
||||
RTM_EXPORT(lwip_fcntl);
|
||||
RTM_EXPORT(lwip_htons);
|
||||
RTM_EXPORT(lwip_htonl);
|
||||
|
||||
#if LWIP_DNS
|
||||
#include <lwip/netdb.h>
|
||||
RTM_EXPORT(lwip_gethostbyname);
|
||||
RTM_EXPORT(lwip_gethostbyname_r);
|
||||
RTM_EXPORT(lwip_freeaddrinfo);
|
||||
RTM_EXPORT(lwip_getaddrinfo);
|
||||
#endif /* LWIP_DNS */
|
||||
#endif /* LWIP_SOCKET */
|
||||
|
||||
#if LWIP_DHCP
|
||||
#include <lwip/dhcp.h>
|
||||
RTM_EXPORT(dhcp_start);
|
||||
RTM_EXPORT(dhcp_renew);
|
||||
RTM_EXPORT(dhcp_stop);
|
||||
#endif /* LWIP_DHCP */
|
||||
|
||||
#if LWIP_NETIF_API
|
||||
#include <lwip/netifapi.h>
|
||||
RTM_EXPORT(netifapi_netif_set_addr);
|
||||
#endif /* LWIP_NETIF_API */
|
||||
|
||||
#if LWIP_NETIF_LINK_CALLBACK
|
||||
RTM_EXPORT(netif_set_link_callback);
|
||||
#endif /* LWIP_NETIF_LINK_CALLBACK */
|
||||
|
||||
#if LWIP_NETIF_STATUS_CALLBACK
|
||||
RTM_EXPORT(netif_set_status_callback);
|
||||
#endif /* LWIP_NETIF_STATUS_CALLBACK */
|
||||
|
||||
RTM_EXPORT(netif_find);
|
||||
RTM_EXPORT(netif_set_addr);
|
||||
RTM_EXPORT(netif_set_ipaddr);
|
||||
RTM_EXPORT(netif_set_gw);
|
||||
RTM_EXPORT(netif_set_netmask);
|
Reference in New Issue
Block a user