forked from xuos/xiuos
				
			modify lwip to !no_sys
This commit is contained in:
		
							parent
							
								
									4e67992516
								
							
						
					
					
						commit
						fa710bbc37
					
				| 
						 | 
					@ -0,0 +1,12 @@
 | 
				
			||||||
 | 
					include $(KERNEL_ROOT)/services/net/net_server/lwip.mk
 | 
				
			||||||
 | 
					objs += sys_arch.o
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					arch: ${objs}
 | 
				
			||||||
 | 
						@echo "generate $^"
 | 
				
			||||||
 | 
						@mv ${objs} $(KERNEL_ROOT)/services/net/net_server
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					%.o: %.c
 | 
				
			||||||
 | 
						@echo "cc $^"
 | 
				
			||||||
 | 
						@${cc} ${cflags} ${c_useropts} ${INC_DIR} -o $@ -c $^
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,227 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					* Copyright (c) 2001-2003 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 <adam@sics.se>
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					#ifndef LWIP_LWIPOPTS_H
 | 
				
			||||||
 | 
					#define LWIP_LWIPOPTS_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /**
 | 
				
			||||||
 | 
					 * SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain
 | 
				
			||||||
 | 
					 * critical regions during buffer allocation, deallocation and memory
 | 
				
			||||||
 | 
					 * allocation and deallocation.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					 #define SYS_LIGHTWEIGHT_PROT    1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /**
 | 
				
			||||||
 | 
					 * NO_SYS==1: Provides VERY minimal functionality. Otherwise,
 | 
				
			||||||
 | 
					 * use lwIP facilities.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					 #define NO_SYS                  0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /**
 | 
				
			||||||
 | 
					 * NO_SYS_NO_TIMERS==1: Drop support for sys_timeout when NO_SYS==1
 | 
				
			||||||
 | 
					 * Mainly for compatibility to old versions.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					 #define NO_SYS_NO_TIMERS        0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /* ---------- Memory options ---------- */
 | 
				
			||||||
 | 
					 /* MEM_ALIGNMENT: should be set to the alignment of the CPU for which
 | 
				
			||||||
 | 
					 lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2
 | 
				
			||||||
 | 
					 byte alignment -> define MEM_ALIGNMENT to 2. */
 | 
				
			||||||
 | 
					 #define MEM_ALIGNMENT           4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /* MEM_SIZE: the size of the heap memory. If the application will send
 | 
				
			||||||
 | 
					 a lot of data that needs to be copied, this should be set high. */
 | 
				
			||||||
 | 
					 #define MEM_SIZE                (15*1024)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /* 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           25
 | 
				
			||||||
 | 
					 /* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
 | 
				
			||||||
 | 
					 per active UDP "connection". */
 | 
				
			||||||
 | 
					 #define MEMP_NUM_UDP_PCB        4
 | 
				
			||||||
 | 
					 /* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP
 | 
				
			||||||
 | 
					 connections. */
 | 
				
			||||||
 | 
					 #define MEMP_NUM_TCP_PCB        6
 | 
				
			||||||
 | 
					 /* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP
 | 
				
			||||||
 | 
					 connections. */
 | 
				
			||||||
 | 
					 #define MEMP_NUM_TCP_PCB_LISTEN 6
 | 
				
			||||||
 | 
					 /* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP
 | 
				
			||||||
 | 
					 segments. */
 | 
				
			||||||
 | 
					 #define MEMP_NUM_TCP_SEG        150
 | 
				
			||||||
 | 
					 /* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active
 | 
				
			||||||
 | 
					 timeouts. */
 | 
				
			||||||
 | 
					 #define MEMP_NUM_SYS_TIMEOUT    6
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /* ---------- Pbuf options ---------- */
 | 
				
			||||||
 | 
					 /* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
 | 
				
			||||||
 | 
					 #define PBUF_POOL_SIZE          45
 | 
				
			||||||
 | 
					 /* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
 | 
				
			||||||
 | 
					 #define PBUF_POOL_BUFSIZE    \
 | 
				
			||||||
 | 
					 LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /* ---------- TCP options ---------- */
 | 
				
			||||||
 | 
					 #define LWIP_TCP                1
 | 
				
			||||||
 | 
					 #define TCP_TTL                 255
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /* Controls if TCP should queue segments that arrive out of
 | 
				
			||||||
 | 
					 order. Define to 0 if your device is low on memory. */
 | 
				
			||||||
 | 
					 #define TCP_QUEUE_OOSEQ         0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /* TCP Maximum segment size. */
 | 
				
			||||||
 | 
					 #define TCP_MSS                 (1500 - 40)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /* TCP sender buffer space (bytes). */
 | 
				
			||||||
 | 
					 #define TCP_SND_BUF             (10*TCP_MSS)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /*  TCP_SND_QUEUELEN: TCP sender buffer space (pbufs). This must be at least
 | 
				
			||||||
 | 
					 as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 #define TCP_SND_QUEUELEN        (8* TCP_SND_BUF/TCP_MSS)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /* TCP receive window. */
 | 
				
			||||||
 | 
					 #define TCP_WND                 (11*TCP_MSS)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /* ---------- ICMP options ---------- */
 | 
				
			||||||
 | 
					 #define LWIP_ICMP                       1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /* ---------- DHCP options ---------- */
 | 
				
			||||||
 | 
					 /* Define LWIP_DHCP to 1 if you want DHCP configuration of
 | 
				
			||||||
 | 
					 interfaces. DHCP is not implemented in lwIP 0.5.1, however, so
 | 
				
			||||||
 | 
					 turning this on does currently not work. */
 | 
				
			||||||
 | 
					 #define LWIP_DHCP               1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /* ---------- UDP options ---------- */
 | 
				
			||||||
 | 
					 #define LWIP_UDP                1
 | 
				
			||||||
 | 
					 #define UDP_TTL                 255
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /* ---------- Statistics options ---------- */
 | 
				
			||||||
 | 
					 #define LWIP_STATS 0
 | 
				
			||||||
 | 
					 #define LWIP_PROVIDE_ERRNO 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /* ---------- link callback options ---------- */
 | 
				
			||||||
 | 
					 /* LWIP_NETIF_LINK_CALLBACK==1: Support a callback function from an interface
 | 
				
			||||||
 | 
					 * whenever the link changes (i.e., link down)
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					 #define LWIP_NETIF_LINK_CALLBACK        0
 | 
				
			||||||
 | 
					 /*
 | 
				
			||||||
 | 
					     --------------------------------------
 | 
				
			||||||
 | 
					     ---------- Checksum options ----------
 | 
				
			||||||
 | 
					     --------------------------------------
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /* The STM32F4x7 allows computing and verifying the IP,
 | 
				
			||||||
 | 
					     UDP, TCP and ICMP checksums by hardware:
 | 
				
			||||||
 | 
					 - To use this feature let the following define uncommented.
 | 
				
			||||||
 | 
					 - To disable it and process by CPU comment the  the checksum.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					 #define CHECKSUM_BY_HARDWARE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 #ifdef CHECKSUM_BY_HARDWARE
 | 
				
			||||||
 | 
					 /* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.*/
 | 
				
			||||||
 | 
					 #define CHECKSUM_GEN_IP                 0
 | 
				
			||||||
 | 
					 /* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.*/
 | 
				
			||||||
 | 
					 #define CHECKSUM_GEN_UDP                0
 | 
				
			||||||
 | 
					 /* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.*/
 | 
				
			||||||
 | 
					 #define CHECKSUM_GEN_TCP                0
 | 
				
			||||||
 | 
					 /* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.*/
 | 
				
			||||||
 | 
					 #define CHECKSUM_CHECK_IP               0
 | 
				
			||||||
 | 
					 /* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.*/
 | 
				
			||||||
 | 
					 #define CHECKSUM_CHECK_UDP              0
 | 
				
			||||||
 | 
					 /* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.*/
 | 
				
			||||||
 | 
					 #define CHECKSUM_CHECK_TCP              0
 | 
				
			||||||
 | 
					 /*CHECKSUM_CHECK_ICMP==0: Check checksums by hardware for incoming ICMP packets.*/
 | 
				
			||||||
 | 
					 #define CHECKSUM_GEN_ICMP               0
 | 
				
			||||||
 | 
					 #else
 | 
				
			||||||
 | 
					 /* CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets.*/
 | 
				
			||||||
 | 
					 #define CHECKSUM_GEN_IP                 1
 | 
				
			||||||
 | 
					 /* CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets.*/
 | 
				
			||||||
 | 
					 #define CHECKSUM_GEN_UDP                1
 | 
				
			||||||
 | 
					 /* CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets.*/
 | 
				
			||||||
 | 
					 #define CHECKSUM_GEN_TCP                1
 | 
				
			||||||
 | 
					 /* CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets.*/
 | 
				
			||||||
 | 
					 #define CHECKSUM_CHECK_IP               1
 | 
				
			||||||
 | 
					 /* CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets.*/
 | 
				
			||||||
 | 
					 #define CHECKSUM_CHECK_UDP              1
 | 
				
			||||||
 | 
					 /* CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets.*/
 | 
				
			||||||
 | 
					 #define CHECKSUM_CHECK_TCP              1
 | 
				
			||||||
 | 
					 /*CHECKSUM_CHECK_ICMP==1: Check checksums by hardware for incoming ICMP packets.*/
 | 
				
			||||||
 | 
					 #define CHECKSUM_GEN_ICMP               1
 | 
				
			||||||
 | 
					 #endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /*
 | 
				
			||||||
 | 
					     ----------------------------------------------
 | 
				
			||||||
 | 
					     ---------- Sequential layer options ----------
 | 
				
			||||||
 | 
					     ----------------------------------------------
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					 /**
 | 
				
			||||||
 | 
					 * LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c)
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					 #define LWIP_NETCONN                    1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /*
 | 
				
			||||||
 | 
					     ------------------------------------
 | 
				
			||||||
 | 
					     ---------- Socket options ----------
 | 
				
			||||||
 | 
					     ------------------------------------
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					 /**
 | 
				
			||||||
 | 
					 * LWIP_SOCKET==1: Enable Socket API (require to use sockets.c)
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					 #define LWIP_SOCKET                     1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /*
 | 
				
			||||||
 | 
					     ---------------------------------
 | 
				
			||||||
 | 
					     ---------- OS options ----------
 | 
				
			||||||
 | 
					     ---------------------------------
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 #define DEFAULT_UDP_RECVMBOX_SIZE       10
 | 
				
			||||||
 | 
					 #define DEFAULT_TCP_RECVMBOX_SIZE       10
 | 
				
			||||||
 | 
					 #define DEFAULT_ACCEPTMBOX_SIZE         10
 | 
				
			||||||
 | 
					 #define DEFAULT_THREAD_STACKSIZE        1024
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 #define TCPIP_THREAD_NAME              "lwip"
 | 
				
			||||||
 | 
					 #define TCPIP_THREAD_STACKSIZE          512
 | 
				
			||||||
 | 
					 #define TCPIP_MBOX_SIZE                 8
 | 
				
			||||||
 | 
					 #define TCPIP_THREAD_PRIO               3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					   ----------------------------------------
 | 
				
			||||||
 | 
					   ---------- Lwip Debug options ----------
 | 
				
			||||||
 | 
					   ----------------------------------------
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* LWIP_LWIPOPTS_H */
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,370 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (c) 2020 AIIT XUOS Lab
 | 
				
			||||||
 | 
					 * XiUOS is licensed under Mulan PSL v2.
 | 
				
			||||||
 | 
					 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 | 
				
			||||||
 | 
					 * You may obtain a copy of Mulan PSL v2 at:
 | 
				
			||||||
 | 
					 *        http://license.coscl.org.cn/MulanPSL2
 | 
				
			||||||
 | 
					 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 | 
				
			||||||
 | 
					 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 | 
				
			||||||
 | 
					 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 | 
				
			||||||
 | 
					 * See the Mulan PSL v2 for more details.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#include "debug.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <lwip/arch.h>
 | 
				
			||||||
 | 
					#include <lwip/opt.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "lwip/dhcp.h"
 | 
				
			||||||
 | 
					#include "lwip/init.h"
 | 
				
			||||||
 | 
					#include "lwip/netif.h"
 | 
				
			||||||
 | 
					#include "lwip/sio.h"
 | 
				
			||||||
 | 
					#include "tcpip.h"
 | 
				
			||||||
 | 
					#include "tcpip_priv.h"
 | 
				
			||||||
 | 
					#include <lwip/debug.h>
 | 
				
			||||||
 | 
					#include <lwip/stats.h>
 | 
				
			||||||
 | 
					#include <lwip/sys.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if !NO_SYS
 | 
				
			||||||
 | 
					#include "sys_arch.h"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define SYS_THREAD_MAX 4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void sys_init(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // do nothing
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					u32_t sys_jiffies(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					u32_t sys_now(void)
 | 
				
			||||||
 | 
					{   
 | 
				
			||||||
 | 
					  return 1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					sys_prot_t sys_arch_protect(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // return CriticalAreaLock();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void sys_arch_unprotect(sys_prot_t pval)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // CriticalAreaUnLock(pval);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if !NO_SYS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					err_t sys_sem_new(sys_sem_t* sem, u8_t count)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					//     *sem = KSemaphoreCreate((uint16)count);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// #if SYS_STATS
 | 
				
			||||||
 | 
					//     ++lwip_stats.sys.sem.used;
 | 
				
			||||||
 | 
					//     if (lwip_stats.sys.sem.max < lwip_stats.sys.sem.used) {
 | 
				
			||||||
 | 
					//         lwip_stats.sys.sem.max = lwip_stats.sys.sem.used;
 | 
				
			||||||
 | 
					//     }
 | 
				
			||||||
 | 
					// #endif /* SYS_STATS */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//     if (*sem >= 0)
 | 
				
			||||||
 | 
					//         return ERR_OK;
 | 
				
			||||||
 | 
					//     else {
 | 
				
			||||||
 | 
					// #if SYS_STATS
 | 
				
			||||||
 | 
					//         ++lwip_stats.sys.sem.err;
 | 
				
			||||||
 | 
					// #endif /* SYS_STATS */
 | 
				
			||||||
 | 
					//         KPrintf("[sys_arch]:new sem fail!\n");
 | 
				
			||||||
 | 
					//         return ERR_MEM;
 | 
				
			||||||
 | 
					//     }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void sys_sem_free(sys_sem_t* sem)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					// #if SYS_STATS
 | 
				
			||||||
 | 
					//     --lwip_stats.sys.sem.used;
 | 
				
			||||||
 | 
					// #endif /* SYS_STATS */
 | 
				
			||||||
 | 
					//     KSemaphoreDelete(*sem);
 | 
				
			||||||
 | 
					//     *sem = SYS_SEM_NULL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int sys_sem_valid(sys_sem_t* sem)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // return (*sem > SYS_SEM_NULL);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void sys_sem_set_invalid(sys_sem_t* sem)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // *sem = SYS_SEM_NULL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					u32_t sys_arch_sem_wait(sys_sem_t* sem, u32_t timeout)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // x_ticks_t start_tick = 0;
 | 
				
			||||||
 | 
					    // int32 wait_time = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // if (*sem == SYS_SEM_NULL)
 | 
				
			||||||
 | 
					    //     return SYS_ARCH_TIMEOUT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // start_tick = CurrentTicksGain();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // if (0 == timeout)
 | 
				
			||||||
 | 
					    //     wait_time = WAITING_FOREVER;
 | 
				
			||||||
 | 
					    // else
 | 
				
			||||||
 | 
					    //     wait_time = timeout;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // if (KSemaphoreObtain(*sem, wait_time) == EOK)
 | 
				
			||||||
 | 
					    //     return CalculateTimeMsFromTick(CurrentTicksGain() - start_tick);
 | 
				
			||||||
 | 
					    // else
 | 
				
			||||||
 | 
					    //     return SYS_ARCH_TIMEOUT;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void sys_sem_signal(sys_sem_t* sem)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // if (KSemaphoreAbandon(*sem) != EOK)
 | 
				
			||||||
 | 
					    //     KPrintf("[sys_arch]:sem signal fail!\n");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					err_t sys_mutex_new(sys_mutex_t* mutex)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // *mutex = KMutexCreate();
 | 
				
			||||||
 | 
					    // if (*mutex > SYS_MRTEX_NULL)
 | 
				
			||||||
 | 
					    //     return ERR_OK;
 | 
				
			||||||
 | 
					    // else {
 | 
				
			||||||
 | 
					    //     KPrintf("[sys_arch]:new mutex fail!\n");
 | 
				
			||||||
 | 
					    //     return ERR_MEM;
 | 
				
			||||||
 | 
					    // }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void sys_mutex_free(sys_mutex_t* mutex)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // KMutexDelete(*mutex);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void sys_mutex_set_invalid(sys_mutex_t* mutex)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // *mutex = SYS_MRTEX_NULL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					void sys_mutex_lock(sys_mutex_t* mutex)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // KMutexObtain(*mutex, WAITING_FOREVER);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void sys_mutex_unlock(sys_mutex_t* mutex)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // KMutexAbandon(*mutex);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					sys_thread_t sys_thread_new(const char* name, lwip_thread_fn function, void* arg, int stacksize, int prio)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // sys_thread_t handle = -1;
 | 
				
			||||||
 | 
					    // handle = KTaskCreate(name,
 | 
				
			||||||
 | 
					    //     function,
 | 
				
			||||||
 | 
					    //     arg,
 | 
				
			||||||
 | 
					    //     (uint32)stacksize,
 | 
				
			||||||
 | 
					    //     (uint8)prio);
 | 
				
			||||||
 | 
					    // if (handle >= 0) {
 | 
				
			||||||
 | 
					    //     StartupKTask(handle);
 | 
				
			||||||
 | 
					    //     lw_print("lw: [%s] create %s handle %x\n", __func__, name, handle);
 | 
				
			||||||
 | 
					    //     return handle;
 | 
				
			||||||
 | 
					    // }
 | 
				
			||||||
 | 
					    // lw_print("lw: [%s] create %s failed\n", __func__, name);
 | 
				
			||||||
 | 
					    // return -ERROR;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					err_t sys_mbox_new(sys_mbox_t* mbox, int size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // *mbox = KCreateMsgQueue(sizeof(void*), size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// #if SYS_STATS
 | 
				
			||||||
 | 
					//     ++lwip_stats.sys.mbox.used;
 | 
				
			||||||
 | 
					//     if (lwip_stats.sys.mbox.max < lwip_stats.sys.mbox.used) {
 | 
				
			||||||
 | 
					//         lwip_stats.sys.mbox.max = lwip_stats.sys.mbox.used;
 | 
				
			||||||
 | 
					//     }
 | 
				
			||||||
 | 
					// #endif /* SYS_STATS */
 | 
				
			||||||
 | 
					//     if (*mbox < 0) {
 | 
				
			||||||
 | 
					//         lw_error("lw: [%s] alloc %d mbox %p failed\n", __func__, size, mbox);
 | 
				
			||||||
 | 
					//         return ERR_MEM;
 | 
				
			||||||
 | 
					//     }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//     // lw_print("lw: [%s] alloc %d mbox %p ok!\n", __func__, size, mbox);
 | 
				
			||||||
 | 
					//     return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					void sys_mbox_free(sys_mbox_t* mbox)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // KDeleteMsgQueue(*mbox);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int sys_mbox_valid(sys_mbox_t* mbox)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // if (*mbox <= SYS_MBOX_NULL)
 | 
				
			||||||
 | 
					    //     return 0;
 | 
				
			||||||
 | 
					    // else
 | 
				
			||||||
 | 
					    //     return 1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void sys_mbox_set_invalid(sys_mbox_t* mbox)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // *mbox = SYS_MBOX_NULL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void sys_mbox_post(sys_mbox_t* q, void* msg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // KMsgQueueSendwait(*q, &msg, sizeof(void*), WAITING_FOREVER);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					err_t sys_mbox_trypost(sys_mbox_t* q, void* msg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // // if(KMsgQueueSend(*q, &msg, sizeof(void *)) == EOK)
 | 
				
			||||||
 | 
					    // if (KMsgQueueSend(*q, &msg, sizeof(void*)) == EOK)
 | 
				
			||||||
 | 
					    //     return ERR_OK;
 | 
				
			||||||
 | 
					    // else
 | 
				
			||||||
 | 
					    //     return ERR_MEM;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					err_t sys_mbox_trypost_fromisr(sys_mbox_t* q, void* msg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // return sys_mbox_trypost(q, msg);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					u32_t sys_arch_mbox_fetch(sys_mbox_t* q, void** msg, u32_t timeout)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // x_ticks_t start_tick = 0;
 | 
				
			||||||
 | 
					    // int32 wait_time = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // start_tick = CurrentTicksGain();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // if (0 == timeout)
 | 
				
			||||||
 | 
					    //     wait_time = WAITING_FOREVER;
 | 
				
			||||||
 | 
					    // else
 | 
				
			||||||
 | 
					    //     wait_time = timeout;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // if (KMsgQueueRecv(*q, &(*msg), sizeof(void*), wait_time) == EOK) {
 | 
				
			||||||
 | 
					    //     return CalculateTimeMsFromTick(CurrentTicksGain() - start_tick);
 | 
				
			||||||
 | 
					    // } else {
 | 
				
			||||||
 | 
					    //     return SYS_ARCH_TIMEOUT;
 | 
				
			||||||
 | 
					    // }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					u32_t sys_arch_mbox_tryfetch(sys_mbox_t* q, void** msg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // if (KMsgQueueRecv(*q, &(*msg), sizeof(void*), 0) == EOK)
 | 
				
			||||||
 | 
					    //     return ERR_OK;
 | 
				
			||||||
 | 
					    // else
 | 
				
			||||||
 | 
					    //     return SYS_MBOX_EMPTY;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if LWIP_NETCONN_SEM_PER_THREAD
 | 
				
			||||||
 | 
					#error LWIP_NETCONN_SEM_PER_THREAD==1 not supported
 | 
				
			||||||
 | 
					#endif /* LWIP_NETCONN_SEM_PER_THREAD */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* !NO_SYS */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Variables Initialization */
 | 
				
			||||||
 | 
					ip4_addr_t ipaddr;
 | 
				
			||||||
 | 
					ip4_addr_t netmask;
 | 
				
			||||||
 | 
					ip4_addr_t gw;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void lwip_config_input(int eport, struct netif* net)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					//     sys_thread_t th_id = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//     if (eport == 0) {
 | 
				
			||||||
 | 
					//         th_id = sys_thread_new("eth_input", ethernetif_input, net, LWIP_TASK_STACK_SIZE, 30);
 | 
				
			||||||
 | 
					//     } else if (eport == 1) {
 | 
				
			||||||
 | 
					// #ifdef NETIF_ENET1_INIT_FUNC
 | 
				
			||||||
 | 
					//         th_id = sys_thread_new("eth_input2", ethernetif_input2, net, LWIP_TASK_STACK_SIZE, 30);
 | 
				
			||||||
 | 
					// #endif
 | 
				
			||||||
 | 
					//     }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					void lwip_config_tcp(uint8_t enet_port, char* ip, char* mask, char* gw)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					//     static char is_init_0 = 0;
 | 
				
			||||||
 | 
					//     static char is_init_1 = 0;
 | 
				
			||||||
 | 
					//     if (is_init_0 == 0 && is_init_1 == 0) {
 | 
				
			||||||
 | 
					//         sys_sem_new(get_eth_recv_sem(), 0);
 | 
				
			||||||
 | 
					//         sys_sem_new(get_eth_recv_sem2(), 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//         if (chk_lwip_bit(LWIP_INIT_FLAG)) {
 | 
				
			||||||
 | 
					//             lw_print("lw: [%s] already ...\n", __func__);
 | 
				
			||||||
 | 
					//         }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//         set_lwip_bit(LWIP_INIT_FLAG);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//         tcpip_init(NULL, NULL);
 | 
				
			||||||
 | 
					//     }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//     lw_print("lw: [%s] start ...\n", __func__);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//     char* eth_cfg = ethernetif_config_enet_set(enet_port);
 | 
				
			||||||
 | 
					//     ip4_addr_t net_ipaddr, net_netmask, net_gw;
 | 
				
			||||||
 | 
					//     IP4_ADDR(&net_ipaddr, ip[0], ip[1], ip[2], ip[3]);
 | 
				
			||||||
 | 
					//     IP4_ADDR(&net_netmask, mask[0], mask[1], mask[2], mask[3]);
 | 
				
			||||||
 | 
					//     IP4_ADDR(&net_gw, gw[0], gw[1], gw[2], gw[3]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//     if (0 == enet_port) {
 | 
				
			||||||
 | 
					//         if (is_init_0 == 1) {
 | 
				
			||||||
 | 
					//             return;
 | 
				
			||||||
 | 
					//         }
 | 
				
			||||||
 | 
					// #ifndef NETIF_ENET0_INIT_FUNC
 | 
				
			||||||
 | 
					//         lw_print("Not Netif driver for Eport 0\n");
 | 
				
			||||||
 | 
					//         return;
 | 
				
			||||||
 | 
					// #endif
 | 
				
			||||||
 | 
					// #ifdef NETIF_ENET0_INIT_FUNC
 | 
				
			||||||
 | 
					//         lw_print("Add netif eport 0\n");
 | 
				
			||||||
 | 
					//         netif_add(&gnetif, &net_ipaddr, &net_netmask, &net_gw, eth_cfg, NETIF_ENET0_INIT_FUNC,
 | 
				
			||||||
 | 
					//             tcpip_input);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//         netif_set_default(&gnetif);
 | 
				
			||||||
 | 
					//         netif_set_up(&gnetif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//         lw_print("\r\n************************************************\r\n");
 | 
				
			||||||
 | 
					//         lw_print(" Network Configuration\r\n");
 | 
				
			||||||
 | 
					//         lw_print("************************************************\r\n");
 | 
				
			||||||
 | 
					//         lw_print(" IPv4 Address   : %u.%u.%u.%u\r\n", ((u8_t*)&net_ipaddr)[0], ((u8_t*)&net_ipaddr)[1],
 | 
				
			||||||
 | 
					//             ((u8_t*)&net_ipaddr)[2], ((u8_t*)&net_ipaddr)[3]);
 | 
				
			||||||
 | 
					//         lw_print(" IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t*)&net_netmask)[0], ((u8_t*)&net_netmask)[1],
 | 
				
			||||||
 | 
					//             ((u8_t*)&net_netmask)[2], ((u8_t*)&net_netmask)[3]);
 | 
				
			||||||
 | 
					//         lw_print(" IPv4 Gateway   : %u.%u.%u.%u\r\n", ((u8_t*)&net_gw)[0], ((u8_t*)&net_gw)[1],
 | 
				
			||||||
 | 
					//             ((u8_t*)&net_gw)[2], ((u8_t*)&net_gw)[3]);
 | 
				
			||||||
 | 
					//         lw_print("************************************************\r\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//         lwip_config_input(enet_port, &gnetif);
 | 
				
			||||||
 | 
					//         is_init_0 = 1;
 | 
				
			||||||
 | 
					// #endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//     } else if (1 == enet_port) {
 | 
				
			||||||
 | 
					// if (is_init_1 == 1) {
 | 
				
			||||||
 | 
					//             return;
 | 
				
			||||||
 | 
					//         }
 | 
				
			||||||
 | 
					// #ifndef NETIF_ENET1_INIT_FUNC
 | 
				
			||||||
 | 
					//         lw_print("Not Netif driver for Eport 1\n");
 | 
				
			||||||
 | 
					//         return;
 | 
				
			||||||
 | 
					// #endif
 | 
				
			||||||
 | 
					// #ifdef NETIF_ENET1_INIT_FUNC
 | 
				
			||||||
 | 
					//         lw_print("Add netif eport 1\n");
 | 
				
			||||||
 | 
					//         netif_add(&gnetif2, &net_ipaddr, &net_netmask, &net_gw, eth_cfg, NETIF_ENET1_INIT_FUNC,
 | 
				
			||||||
 | 
					//             tcpip_input);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//         // netif_set_default(&gnetif2);
 | 
				
			||||||
 | 
					//         netif_set_up(&gnetif2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//         lw_print("\r\n************************************************\r\n");
 | 
				
			||||||
 | 
					//         lw_print(" Network Configuration\r\n");
 | 
				
			||||||
 | 
					//         lw_print("************************************************\r\n");
 | 
				
			||||||
 | 
					//         lw_print(" IPv4 Address   : %u.%u.%u.%u\r\n", ((u8_t*)&net_ipaddr)[0], ((u8_t*)&net_ipaddr)[1],
 | 
				
			||||||
 | 
					//             ((u8_t*)&net_ipaddr)[2], ((u8_t*)&net_ipaddr)[3]);
 | 
				
			||||||
 | 
					//         lw_print(" IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t*)&net_netmask)[0], ((u8_t*)&net_netmask)[1],
 | 
				
			||||||
 | 
					//             ((u8_t*)&net_netmask)[2], ((u8_t*)&net_netmask)[3]);
 | 
				
			||||||
 | 
					//         lw_print(" IPv4 Gateway   : %u.%u.%u.%u\r\n", ((u8_t*)&net_gw)[0], ((u8_t*)&net_gw)[1],
 | 
				
			||||||
 | 
					//             ((u8_t*)&net_gw)[2], ((u8_t*)&net_gw)[3]);
 | 
				
			||||||
 | 
					//         lw_print("************************************************\r\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//         lwip_config_input(enet_port, &gnetif2);
 | 
				
			||||||
 | 
					//         is_init_1 = 1;
 | 
				
			||||||
 | 
					// #endif
 | 
				
			||||||
 | 
					//     }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,80 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (c) 2020 AIIT XUOS Lab
 | 
				
			||||||
 | 
					 * XiUOS is licensed under Mulan PSL v2.
 | 
				
			||||||
 | 
					 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 | 
				
			||||||
 | 
					 * You may obtain a copy of Mulan PSL v2 at:
 | 
				
			||||||
 | 
					 *        http://license.coscl.org.cn/MulanPSL2
 | 
				
			||||||
 | 
					 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 | 
				
			||||||
 | 
					 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 | 
				
			||||||
 | 
					 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 | 
				
			||||||
 | 
					 * See the Mulan PSL v2 for more details.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef LWIP_ARCH_SYS_ARCH_H
 | 
				
			||||||
 | 
					#define LWIP_ARCH_SYS_ARCH_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <lwip/opt.h>
 | 
				
			||||||
 | 
					#include <lwip/arch.h>
 | 
				
			||||||
 | 
					#include <lwip/netif.h>
 | 
				
			||||||
 | 
					// #include "tcpip.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* LWIP task parameter */
 | 
				
			||||||
 | 
					#define LWIP_LOCAL_PORT             4840
 | 
				
			||||||
 | 
					#define LWIP_TARGET_PORT            LWIP_LOCAL_PORT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define LWIP_DEMO_TIMES             10
 | 
				
			||||||
 | 
					#define LWIP_TASK_STACK_SIZE        4096
 | 
				
			||||||
 | 
					#define LWIP_DEMO_TASK_PRIO         20
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// /* MAC address configuration. */
 | 
				
			||||||
 | 
					// #define configMAC_ADDR {0x02, 0x12, 0x13, 0x10, 0x15, 0x11}
 | 
				
			||||||
 | 
					// #define configMAC_ADDR_ETH1 {0x02, 0x12, 0x13, 0x10, 0x15, 0x12}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* USER CODE END 0 */
 | 
				
			||||||
 | 
					#define SYS_MBOX_NULL  -1
 | 
				
			||||||
 | 
					#define SYS_SEM_NULL   -1
 | 
				
			||||||
 | 
					#define SYS_MRTEX_NULL SYS_SEM_NULL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef s32_t sys_sem_t;
 | 
				
			||||||
 | 
					typedef s32_t sys_mutex_t;
 | 
				
			||||||
 | 
					typedef s32_t sys_mbox_t;
 | 
				
			||||||
 | 
					typedef s32_t sys_thread_t;
 | 
				
			||||||
 | 
					typedef s64_t sys_prot_t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define MS_PER_SYSTICK (float)(1000 / TICK_PER_SECOND)
 | 
				
			||||||
 | 
					#define TICKS_PER_MS (TICK_PER_SECOND / 1000)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//debug rtos with IRQ
 | 
				
			||||||
 | 
					//#define FSL_RTOS_XIUOS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern char lwip_flag;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define LWIP_INIT_FLAG (1 << 0)
 | 
				
			||||||
 | 
					#define LWIP_PRINT_FLAG (1 << 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define set_lwip_bit(__bit) lwip_flag |= (__bit)
 | 
				
			||||||
 | 
					#define clr_lwip_bit(__bit) lwip_flag &= ~(__bit)
 | 
				
			||||||
 | 
					#define chk_lwip_bit(__bit) ((lwip_flag & (__bit)) == (__bit))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern char lwip_ipaddr[];
 | 
				
			||||||
 | 
					extern char lwip_netmask[];
 | 
				
			||||||
 | 
					extern char lwip_gwaddr[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern char lwip_eth0_ipaddr[];
 | 
				
			||||||
 | 
					extern char lwip_eth0_netmask[];
 | 
				
			||||||
 | 
					extern char lwip_eth0_gwaddr[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern char lwip_eth1_ipaddr[];
 | 
				
			||||||
 | 
					extern char lwip_eth1_netmask[];
 | 
				
			||||||
 | 
					extern struct netif gnetif;
 | 
				
			||||||
 | 
					extern sys_sem_t* get_eth_recv_sem();
 | 
				
			||||||
 | 
					extern struct netif gnetif2;
 | 
				
			||||||
 | 
					extern sys_sem_t* get_eth_recv_sem2();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void lwip_tcp_init(void);
 | 
				
			||||||
 | 
					void lwip_config_net(uint8_t enet_port, char *ip, char *mask, char *gw);
 | 
				
			||||||
 | 
					void lwip_config_tcp(uint8_t enet_port, char *ip, char *mask, char *gw);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* LWIP_ARCH_SYS_ARCH_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -146,6 +146,3 @@ sys_msleep(u32_t ms)
 | 
				
			||||||
#endif /* sys_msleep */
 | 
					#endif /* sys_msleep */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* !NO_SYS */
 | 
					#endif /* !NO_SYS */
 | 
				
			||||||
u32_t sys_now(void){
 | 
					 | 
				
			||||||
  return 1;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,206 +0,0 @@
 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
* Copyright (c) 2001-2003 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 <adam@sics.se>
 | 
					 | 
				
			||||||
*
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
#ifndef LWIP_LWIPOPTS_H
 | 
					 | 
				
			||||||
#define LWIP_LWIPOPTS_H
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain
 | 
					 | 
				
			||||||
 * critical regions during buffer allocation, deallocation and memory
 | 
					 | 
				
			||||||
 * allocation and deallocation.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define SYS_LIGHTWEIGHT_PROT    0
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * NO_SYS==1: Provides VERY minimal functionality. Otherwise,
 | 
					 | 
				
			||||||
 * use lwIP facilities.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define NO_SYS                  1
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * NO_SYS_NO_TIMERS==1: Drop support for sys_timeout when NO_SYS==1
 | 
					 | 
				
			||||||
 * Mainly for compatibility to old versions.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define NO_SYS_NO_TIMERS        0
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* ---------- Memory options ---------- */
 | 
					 | 
				
			||||||
/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which
 | 
					 | 
				
			||||||
   lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2
 | 
					 | 
				
			||||||
   byte alignment -> define MEM_ALIGNMENT to 2. */
 | 
					 | 
				
			||||||
#define MEM_ALIGNMENT           4
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* MEM_SIZE: the size of the heap memory. If the application will send
 | 
					 | 
				
			||||||
a lot of data that needs to be copied, this should be set high. */
 | 
					 | 
				
			||||||
#define MEM_SIZE                (30*1024)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* 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           50
 | 
					 | 
				
			||||||
/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
 | 
					 | 
				
			||||||
   per active UDP "connection". */
 | 
					 | 
				
			||||||
#define MEMP_NUM_UDP_PCB        6
 | 
					 | 
				
			||||||
/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP
 | 
					 | 
				
			||||||
   connections. */
 | 
					 | 
				
			||||||
#define MEMP_NUM_TCP_PCB        10
 | 
					 | 
				
			||||||
/* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP
 | 
					 | 
				
			||||||
   connections. */
 | 
					 | 
				
			||||||
#define MEMP_NUM_TCP_PCB_LISTEN 6
 | 
					 | 
				
			||||||
/* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP
 | 
					 | 
				
			||||||
   segments. */
 | 
					 | 
				
			||||||
#define MEMP_NUM_TCP_SEG        12
 | 
					 | 
				
			||||||
/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active
 | 
					 | 
				
			||||||
   timeouts. */
 | 
					 | 
				
			||||||
#define MEMP_NUM_SYS_TIMEOUT    10
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* ---------- Pbuf options ---------- */
 | 
					 | 
				
			||||||
/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
 | 
					 | 
				
			||||||
#define PBUF_POOL_SIZE          10
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
 | 
					 | 
				
			||||||
#define PBUF_POOL_BUFSIZE       500
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* ---------- TCP options ---------- */
 | 
					 | 
				
			||||||
#define LWIP_TCP                1
 | 
					 | 
				
			||||||
#define TCP_TTL                 255
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Controls if TCP should queue segments that arrive out of
 | 
					 | 
				
			||||||
   order. Define to 0 if your device is low on memory. */
 | 
					 | 
				
			||||||
#define TCP_QUEUE_OOSEQ         0
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* TCP Maximum segment size. */
 | 
					 | 
				
			||||||
#define TCP_MSS                 (1500 - 40)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* TCP sender buffer space (bytes). */
 | 
					 | 
				
			||||||
#define TCP_SND_BUF             (4*TCP_MSS)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*  TCP_SND_QUEUELEN: TCP sender buffer space (pbufs). This must be at least
 | 
					 | 
				
			||||||
as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define TCP_SND_QUEUELEN        (2* TCP_SND_BUF/TCP_MSS)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* TCP receive window. */
 | 
					 | 
				
			||||||
#define TCP_WND                 (2*TCP_MSS)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* ---------- ICMP options ---------- */
 | 
					 | 
				
			||||||
#define LWIP_ICMP                       1
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* ---------- DHCP options ---------- */
 | 
					 | 
				
			||||||
/* Define LWIP_DHCP to 1 if you want DHCP configuration of
 | 
					 | 
				
			||||||
interfaces. DHCP is not implemented in lwIP 0.5.1, however, so
 | 
					 | 
				
			||||||
turning this on does currently not work. */
 | 
					 | 
				
			||||||
#define LWIP_DHCP               1
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* ---------- UDP options ---------- */
 | 
					 | 
				
			||||||
#define LWIP_UDP                1
 | 
					 | 
				
			||||||
#define UDP_TTL                 255
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* ---------- Statistics options ---------- */
 | 
					 | 
				
			||||||
#define LWIP_STATS 0
 | 
					 | 
				
			||||||
#define LWIP_PROVIDE_ERRNO 1
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* ---------- link callback options ---------- */
 | 
					 | 
				
			||||||
/* LWIP_NETIF_LINK_CALLBACK==1: Support a callback function from an interface
 | 
					 | 
				
			||||||
* whenever the link changes (i.e., link down)
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
#define LWIP_NETIF_LINK_CALLBACK        0
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
   --------------------------------------
 | 
					 | 
				
			||||||
   ---------- Checksum options ----------
 | 
					 | 
				
			||||||
   --------------------------------------
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*The STM32F4x7 allows comput
 | 
					 | 
				
			||||||
ing and verifying the IP, UDP, TCP and ICMP checksums by hardware:
 | 
					 | 
				
			||||||
- To use this feature let the following define uncommented.
 | 
					 | 
				
			||||||
- To disable it and process by CPU comment the  the checksum.
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
#define CHECKSUM_BY_HARDWARE
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef CHECKSUM_BY_HARDWARE
 | 
					 | 
				
			||||||
/* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.*/
 | 
					 | 
				
			||||||
#define CHECKSUM_GEN_IP                 0
 | 
					 | 
				
			||||||
/* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.*/
 | 
					 | 
				
			||||||
#define CHECKSUM_GEN_UDP                0
 | 
					 | 
				
			||||||
/* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.*/
 | 
					 | 
				
			||||||
#define CHECKSUM_GEN_TCP                0
 | 
					 | 
				
			||||||
/* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.*/
 | 
					 | 
				
			||||||
#define CHECKSUM_CHECK_IP               0
 | 
					 | 
				
			||||||
/* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.*/
 | 
					 | 
				
			||||||
#define CHECKSUM_CHECK_UDP              0
 | 
					 | 
				
			||||||
/* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.*/
 | 
					 | 
				
			||||||
#define CHECKSUM_CHECK_TCP              0
 | 
					 | 
				
			||||||
/*CHECKSUM_CHECK_ICMP==0: Check checksums by hardware for incoming ICMP packets.*/
 | 
					 | 
				
			||||||
#define CHECKSUM_GEN_ICMP               0
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
/* CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets.*/
 | 
					 | 
				
			||||||
#define CHECKSUM_GEN_IP                 1
 | 
					 | 
				
			||||||
/* CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets.*/
 | 
					 | 
				
			||||||
#define CHECKSUM_GEN_UDP                1
 | 
					 | 
				
			||||||
/* CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets.*/
 | 
					 | 
				
			||||||
#define CHECKSUM_GEN_TCP                1
 | 
					 | 
				
			||||||
/* CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets.*/
 | 
					 | 
				
			||||||
#define CHECKSUM_CHECK_IP               1
 | 
					 | 
				
			||||||
/* CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets.*/
 | 
					 | 
				
			||||||
#define CHECKSUM_CHECK_UDP              1
 | 
					 | 
				
			||||||
/* CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets.*/
 | 
					 | 
				
			||||||
#define CHECKSUM_CHECK_TCP              1
 | 
					 | 
				
			||||||
/*CHECKSUM_CHECK_ICMP==1: Check checksums by hardware for incoming ICMP packets.*/
 | 
					 | 
				
			||||||
#define CHECKSUM_GEN_ICMP               1
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
   ----------------------------------------------
 | 
					 | 
				
			||||||
   ---------- Sequential layer options ----------
 | 
					 | 
				
			||||||
   ----------------------------------------------
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c)
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define LWIP_NETCONN                    0
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
   ------------------------------------
 | 
					 | 
				
			||||||
   ---------- Socket options ----------
 | 
					 | 
				
			||||||
   ------------------------------------
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * LWIP_SOCKET==1: Enable Socket API (require to use sockets.c)
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define LWIP_SOCKET                     0
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
   ----------------------------------------
 | 
					 | 
				
			||||||
   ---------- Lwip Debug options ----------
 | 
					 | 
				
			||||||
   ----------------------------------------
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif /* LWIP_LWIPOPTS_H */
 | 
					 | 
				
			||||||
| 
						 | 
					@ -48,7 +48,7 @@
 | 
				
			||||||
 * Include user defined options first. Anything not defined in these files
 | 
					 * Include user defined options first. Anything not defined in these files
 | 
				
			||||||
 * will be set to standard values. Override anything you don't like!
 | 
					 * will be set to standard values. Override anything you don't like!
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
#include "lwipopts.h"
 | 
					#include "arch/lwipopts.h"
 | 
				
			||||||
#include "lwip/debug.h"
 | 
					#include "lwip/debug.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,7 +17,8 @@ objdump = ${toolchain}objdump
 | 
				
			||||||
c_useropts = -O2
 | 
					c_useropts = -O2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
INC_DIR = 	-I$(KERNEL_ROOT)/services/net/libnet \
 | 
					INC_DIR = 	-I$(KERNEL_ROOT)/services/net/libnet \
 | 
				
			||||||
			-I$(KERNEL_ROOT)/services/net/net_server/include/arch \
 | 
								-I$(KERNEL_ROOT)/services/net/net_server \
 | 
				
			||||||
 | 
								-I$(KERNEL_ROOT)/services/net/net_server/arch \
 | 
				
			||||||
			-I$(KERNEL_ROOT)/services/net/net_server/include \
 | 
								-I$(KERNEL_ROOT)/services/net/net_server/include \
 | 
				
			||||||
			-I$(KERNEL_ROOT)/services/net/net_server/include/lwip \
 | 
								-I$(KERNEL_ROOT)/services/net/net_server/include/lwip \
 | 
				
			||||||
			-I$(KERNEL_ROOT)/services/net/net_server/include/netif \
 | 
								-I$(KERNEL_ROOT)/services/net/net_server/include/netif \
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue