From f8e862f3b5e69de90d6bf20c2642271d324b4fc3 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 19 Mar 2021 11:40:34 +0000 Subject: switch to lwip-2.1.2 --- .gitmodules | 6 +- app/Makefile | 20 +- app/lwip/lwipopts.h | 432 ++++++++++++++++--------------- app/lwip/pbuf.h | 237 +++++++++++++---- app/lwip_glue.c | 24 ++ app/ntp.c | 8 +- app/project.h | 6 +- app/ptp.c | 2 + app/ref.c | 2 + app/report.c | 2 + app/steth.c | 12 +- lwip/lwip-1.4.1 | 1 - lwip/lwip-2.1.2 | 1 + lwip/lwip-local/port/stm32f4x7/arch/cc.h | 8 +- 14 files changed, 470 insertions(+), 291 deletions(-) delete mode 160000 lwip/lwip-1.4.1 create mode 160000 lwip/lwip-2.1.2 diff --git a/.gitmodules b/.gitmodules index f835cea..3224fac 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "libopencm3"] path = libopencm3 url = git://git.panaceas.org/stm32/libopencm3 -[submodule "lwip/lwip-1.4.1"] - path = lwip/lwip-1.4.1 - url = git://git.panaceas.org/stm32/lwip-1.4.1.git +[submodule "lwip/lwip-2.1.2"] + path = lwip/lwip-2.1.2 + url = git://git.panaceas.org/stm32/lwip-2.1.2 diff --git a/app/Makefile b/app/Makefile index 9c7656e..ab88c83 100644 --- a/app/Makefile +++ b/app/Makefile @@ -37,27 +37,21 @@ HSRCS= events.h gps.h project.h ring.h steth.h time_fn.h ubx.h -LWIP=lwip/lwip-1.4.1 +LWIP=lwip/lwip-2.1.2 LWIP_PATH=.. VPATH=${LWIP_PATH} -LWIP_API= +LWIP_API=${LWIP}/src/api/err.c # ${LWIP}/src/api/err.c ${LWIP}/src/api/netdb.c ${LWIP}/src/api/api_msg.c \ ${LWIP}/src/api/tcpip.c ${LWIP}/src/api/sockets.c ${LWIP}/src/api/api_lib.c \ ${LWIP}/src/api/netbuf.c ${LWIP}/src/api/netifapi.c -LWIP_CORE= \ - ${LWIP}/src/core/memp.c ${LWIP}/src/core/sys.c \ - ${LWIP}/src/core/init.c ${LWIP}/src/core/pbuf.c \ - ${LWIP}/src/core/dhcp.c ${LWIP}/src/core/ipv4/ip_addr.c \ - ${LWIP}/src/core/ipv4/ip.c ${LWIP}/src/core/ipv4/ip_frag.c \ - ${LWIP}/src/core/ipv4/inet.c ${LWIP}/src/core/ipv4/autoip.c \ - ${LWIP}/src/core/ipv4/icmp.c ${LWIP}/src/core/ipv4/inet_chksum.c \ - ${LWIP}/src/core/timers.c ${LWIP}/src/core/def.c \ - ${LWIP}/src/core/netif.c ${LWIP}/src/netif/etharp.c \ - ${LWIP}/src/core/raw.c ${LWIP}/src/core/mem.c \ - ${LWIP}/src/core/udp.c +LWIPDIR=${LWIP}/src + +include ${LWIP_PATH}/${LWIPDIR}/Filelists.mk + +LWIP_CORE= ${COREFILES} ${CORE4FILES} ${NETIFFILES} DEFINES= diff --git a/app/lwip/lwipopts.h b/app/lwip/lwipopts.h index d3c16b6..7d208a3 100644 --- a/app/lwip/lwipopts.h +++ b/app/lwip/lwipopts.h @@ -1,213 +1,219 @@ -/** - ****************************************************************************** - * @file lwipopts.h - * @author MCD Application Team - * @version V1.0.0 - * @date 31-October-2011 - * @brief lwIP Options Configuration. - * This file is based on Utilities\lwip_v1.3.2\src\include\lwip\opt.h - * and contains the lwIP configuration for the STM32F4x7 demonstration. - ****************************************************************************** - * @attention - * - * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS - * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE - * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY - * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING - * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE - * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. - * - *

© COPYRIGHT 2011 STMicroelectronics

- ****************************************************************************** - */ - -#ifndef __LWIPOPTS_H__ -#define __LWIPOPTS_H__ - - -#include - -#define MTU 1500 - -#define ICMP_TTL 64 - -#if 0 -#define ICMP_DEBUG LWIP_DBG_ON -#define UDP_DEBUG LWIP_DBG_ON -#define IP_DEBUG LWIP_DBG_ON -#define ETHARP_DEBUG LWIP_DBG_ON -#define LWIP_DBG_TYPES_ON (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT) -#define LWIP_DEBUG 1 -#define LWIP_PLATFORM_DIAG(a) printf a -#endif - -#define LWIP_PLATFORM_DIAG(a) printf a - -#if 0 -#define LWIP_DEBUG 1 -#define TIMERS_DEBUG LWIP_DBG_ON -#else -#define LWIP_DEBUG 0 -#endif - -/** - * 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 - -/* ---------- 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 (10*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 100 -/* 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 PBUF_POOL_FREE_OOSEQ 0 - -#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 4 - - -#define PBUF_POOL_FREE_OOSEQ 0 - -/* ---------- Pbuf options ---------- */ -/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */ -#define PBUF_POOL_SIZE 20 - -/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */ -#define PBUF_POOL_BUFSIZE ((MTU)+8) - - -/* ---------- TCP options ---------- */ -#define LWIP_TCP 0 -#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 (MTU - 40) /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */ - -/* TCP sender buffer space (bytes). */ -#define TCP_SND_BUF (2*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 -#define LWIP_AUTOIP 0 -#define LWIP_DHCP_BOOTP_FILE 0 - - -/* ---------- UDP options ---------- */ -#define LWIP_UDP 1 -#define UDP_TTL 255 - - -/* ---------- Statistics options ---------- */ -#define LWIP_STATS 0 -#undef LWIP_PROVIDE_ERRNO -#define ETHARP_STATS 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. -*/ - - /* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.*/ -#define CHECKSUM_GEN_IP 1 - /* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.*/ -#define CHECKSUM_GEN_UDP 1 - /* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.*/ -#define CHECKSUM_GEN_TCP 1 - /* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.*/ -#define CHECKSUM_CHECK_IP 1 - /* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.*/ -#define CHECKSUM_CHECK_UDP 1 - /* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.*/ -#define CHECKSUM_CHECK_TCP 1 - - -/* - ---------------------------------------------- - ---------- 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 ---------- - ---------------------------------------- -*/ -//#define LWIP_DEBUG 1 - -#endif /* __LWIPOPTS_H__ */ - -/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ +/** + ****************************************************************************** + * @file lwipopts.h + * @author MCD Application Team + * @version V1.0.0 + * @date 31-October-2011 + * @brief lwIP Options Configuration. + * This file is based on Utilities\lwip_v1.3.2\src\include\lwip\opt.h + * and contains the lwIP configuration for the STM32F4x7 demonstration. + ****************************************************************************** + * @attention + * + * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS + * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE + * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY + * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING + * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE + * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. + * + *

© COPYRIGHT 2011 STMicroelectronics

+ ****************************************************************************** + */ + +#ifndef __LWIPOPTS_H__ +#define __LWIPOPTS_H__ + + +#include + +#define LWIP_IPV4 1 +#define LWIP_IPV6 0 + +#define MTU 1500 + +#define ICMP_TTL 64 + +#define LWIP_TIMERS 1 + + +#if 0 +#define SYS_DEBUG LWIP_DBG_ON +#define DHCP_DEBUG LWIP_DBG_ON +#define ICMP_DEBUG LWIP_DBG_ON +#define UDP_DEBUG LWIP_DBG_ON +#define IP_DEBUG LWIP_DBG_ON +#define ETHARP_DEBUG LWIP_DBG_ON +#define TIMERS_DEBUG LWIP_DBG_ON +#define LWIP_DBG_TYPES_ON (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT) +#define LWIP_DEBUG 1 +#define LWIP_PLATFORM_DIAG(a) printf a +#else +#define LWIP_DEBUG 0 +#endif + + +/** + * 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 1 + +/* ---------- 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 (10*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 100 +/* 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 PBUF_POOL_FREE_OOSEQ 0 + +#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 4 + + +#define PBUF_POOL_FREE_OOSEQ 0 + +/* ---------- Pbuf options ---------- */ +/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */ +#define PBUF_POOL_SIZE 20 + +/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */ +#define PBUF_POOL_BUFSIZE ((MTU)+8) + + +/* ---------- TCP options ---------- */ +#define LWIP_TCP 0 +#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 (MTU - 40) /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */ + +/* TCP sender buffer space (bytes). */ +#define TCP_SND_BUF (2*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 +#define LWIP_AUTOIP 0 +#define LWIP_DHCP_BOOTP_FILE 0 + + +/* ---------- UDP options ---------- */ +#define LWIP_UDP 1 +#define UDP_TTL 255 + + +/* ---------- Statistics options ---------- */ +#define LWIP_STATS 0 +#undef LWIP_PROVIDE_ERRNO +#define ETHARP_STATS 0 + +#define IP_FRAG 1 +#define IP_FRAG_USES_STATIC_BUF 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. +*/ + + /* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.*/ +#define CHECKSUM_GEN_IP 1 + /* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.*/ +#define CHECKSUM_GEN_UDP 1 + /* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.*/ +#define CHECKSUM_GEN_TCP 1 + /* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.*/ +#define CHECKSUM_CHECK_IP 1 + /* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.*/ +#define CHECKSUM_CHECK_UDP 1 + /* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.*/ +#define CHECKSUM_CHECK_TCP 1 + + +/* + ---------------------------------------------- + ---------- 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 ---------- + ---------------------------------------- +*/ +//#define LWIP_DEBUG 1 + +#endif /* __LWIPOPTS_H__ */ + +/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/app/lwip/pbuf.h b/app/lwip/pbuf.h index e8c9691..027bea6 100644 --- a/app/lwip/pbuf.h +++ b/app/lwip/pbuf.h @@ -1,8 +1,13 @@ +/** + * @file + * pbuf API + */ + /* * Copyright (c) 2001-2004 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, + * 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, @@ -11,27 +16,27 @@ * 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. + * 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 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * * This file is part of the lwIP TCP/IP stack. - * + * * Author: Adam Dunkels * */ -#ifndef __LWIP_PBUF_H__ -#define __LWIP_PBUF_H__ +#ifndef LWIP_HDR_PBUF_H +#define LWIP_HDR_PBUF_H #include "lwip/opt.h" #include "lwip/err.h" @@ -40,32 +45,133 @@ extern "C" { #endif -/** Currently, the pbuf_custom code is only needed for one specific configuration - * of IP_FRAG */ -#define LWIP_SUPPORT_CUSTOM_PBUF (IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF) +/** LWIP_SUPPORT_CUSTOM_PBUF==1: Custom pbufs behave much like their pbuf type + * but they are allocated by external code (initialised by calling + * pbuf_alloced_custom()) and when pbuf_free gives up their last reference, they + * are freed by calling pbuf_custom->custom_free_function(). + * Currently, the pbuf_custom code is only needed for one specific configuration + * of IP_FRAG, unless required by external driver/application code. */ +#ifndef LWIP_SUPPORT_CUSTOM_PBUF +#define LWIP_SUPPORT_CUSTOM_PBUF ((IP_FRAG && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG)) +#endif + +/** @ingroup pbuf + * PBUF_NEEDS_COPY(p): return a boolean value indicating whether the given + * pbuf needs to be copied in order to be kept around beyond the current call + * stack without risking being corrupted. The default setting provides safety: + * it will make a copy iof any pbuf chain that does not consist entirely of + * PBUF_ROM type pbufs. For setups with zero-copy support, it may be redefined + * to evaluate to true in all cases, for example. However, doing so also has an + * effect on the application side: any buffers that are *not* copied must also + * *not* be reused by the application after passing them to lwIP. For example, + * when setting PBUF_NEEDS_COPY to (0), after using udp_send() with a PBUF_RAM + * pbuf, the application must free the pbuf immediately, rather than reusing it + * for other purposes. For more background information on this, see tasks #6735 + * and #7896, and bugs #11400 and #49914. */ +#ifndef PBUF_NEEDS_COPY +#define PBUF_NEEDS_COPY(p) ((p)->type_internal & PBUF_TYPE_FLAG_DATA_VOLATILE) +#endif /* PBUF_NEEDS_COPY */ + +/* @todo: We need a mechanism to prevent wasting memory in every pbuf + (TCP vs. UDP, IPv4 vs. IPv6: UDP/IPv4 packets may waste up to 28 bytes) */ #define PBUF_TRANSPORT_HLEN 20 +#if LWIP_IPV6 +#define PBUF_IP_HLEN 40 +#else #define PBUF_IP_HLEN 20 +#endif +/** + * @ingroup pbuf + * Enumeration of pbuf layers + */ typedef enum { - PBUF_TRANSPORT, - PBUF_IP, - PBUF_LINK, - PBUF_RAW + /** Includes spare room for transport layer header, e.g. UDP header. + * Use this if you intend to pass the pbuf to functions like udp_send(). + */ + PBUF_TRANSPORT = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN, + /** Includes spare room for IP header. + * Use this if you intend to pass the pbuf to functions like raw_send(). + */ + PBUF_IP = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN, + /** Includes spare room for link layer header (ethernet header). + * Use this if you intend to pass the pbuf to functions like ethernet_output(). + * @see PBUF_LINK_HLEN + */ + PBUF_LINK = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN, + /** Includes spare room for additional encapsulation header before ethernet + * headers (e.g. 802.11). + * Use this if you intend to pass the pbuf to functions like netif->linkoutput(). + * @see PBUF_LINK_ENCAPSULATION_HLEN + */ + PBUF_RAW_TX = PBUF_LINK_ENCAPSULATION_HLEN, + /** Use this for input packets in a netif driver when calling netif->input() + * in the most common case - ethernet-layer netif driver. */ + PBUF_RAW = 0 } pbuf_layer; + +/* Base flags for pbuf_type definitions: */ + +/** Indicates that the payload directly follows the struct pbuf. + * This makes @ref pbuf_header work in both directions. */ +#define PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS 0x80 +/** Indicates the data stored in this pbuf can change. If this pbuf needs + * to be queued, it must be copied/duplicated. */ +#define PBUF_TYPE_FLAG_DATA_VOLATILE 0x40 +/** 4 bits are reserved for 16 allocation sources (e.g. heap, pool1, pool2, etc) + * Internally, we use: 0=heap, 1=MEMP_PBUF, 2=MEMP_PBUF_POOL -> 13 types free*/ +#define PBUF_TYPE_ALLOC_SRC_MASK 0x0F +/** Indicates this pbuf is used for RX (if not set, indicates use for TX). + * This information can be used to keep some spare RX buffers e.g. for + * receiving TCP ACKs to unblock a connection) */ +#define PBUF_ALLOC_FLAG_RX 0x0100 +/** Indicates the application needs the pbuf payload to be in one piece */ +#define PBUF_ALLOC_FLAG_DATA_CONTIGUOUS 0x0200 + +#define PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP 0x00 +#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF 0x01 +#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL 0x02 +/** First pbuf allocation type for applications */ +#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MIN 0x03 +/** Last pbuf allocation type for applications */ +#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MAX PBUF_TYPE_ALLOC_SRC_MASK + +/** + * @ingroup pbuf + * Enumeration of pbuf types + */ typedef enum { - PBUF_RAM, /* pbuf data is stored in RAM */ - PBUF_ROM, /* pbuf data is stored in ROM */ - PBUF_REF, /* pbuf comes from the pbuf pool */ - PBUF_POOL /* pbuf payload refers to RAM */ + /** pbuf data is stored in RAM, used for TX mostly, struct pbuf and its payload + are allocated in one piece of contiguous memory (so the first payload byte + can be calculated from struct pbuf). + pbuf_alloc() allocates PBUF_RAM pbufs as unchained pbufs (although that might + change in future versions). + This should be used for all OUTGOING packets (TX).*/ + PBUF_RAM = (PBUF_ALLOC_FLAG_DATA_CONTIGUOUS | PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS | PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP), + /** pbuf data is stored in ROM, i.e. struct pbuf and its payload are located in + totally different memory areas. Since it points to ROM, payload does not + have to be copied when queued for transmission. */ + PBUF_ROM = PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF, + /** pbuf comes from the pbuf pool. Much like PBUF_ROM but payload might change + so it has to be duplicated when queued before transmitting, depending on + who has a 'ref' to it. */ + PBUF_REF = (PBUF_TYPE_FLAG_DATA_VOLATILE | PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF), + /** pbuf payload refers to RAM. This one comes from a pool and should be used + for RX. Payload can be chained (scatter-gather RX) but like PBUF_RAM, struct + pbuf and its payload are allocated in one piece of contiguous memory (so + the first payload byte can be calculated from struct pbuf). + Don't use this for TX, if the pool becomes empty e.g. because of TCP queuing, + you are unable to receive TCP acks! */ + PBUF_POOL = (PBUF_ALLOC_FLAG_RX | PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS | PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL) } pbuf_type; /** indicates this packet's data should be immediately passed to the application */ #define PBUF_FLAG_PUSH 0x01U -/** indicates this is a custom pbuf: pbuf_free and pbuf_header handle such a - a pbuf differently */ +/** indicates this is a custom pbuf: pbuf_free calls pbuf_custom->custom_free_function() + when the last reference is released (plus custom PBUF_RAM cannot be trimmed) */ #define PBUF_FLAG_IS_CUSTOM 0x02U /** indicates this pbuf is UDP multicast to be looped back */ #define PBUF_FLAG_MCASTLOOP 0x04U @@ -76,6 +182,7 @@ typedef enum { /** indicates this pbuf includes a TCP FIN flag */ #define PBUF_FLAG_TCP_FIN 0x20U +/** Main packet buffer struct */ struct pbuf { /** next pbuf in singly linked pbuf chain */ struct pbuf *next; @@ -95,8 +202,10 @@ struct pbuf { /** length of this buffer */ u16_t len; - /** pbuf_type as u8_t instead of enum to save space */ - u8_t /*pbuf_type*/ type; + /** a bit field indicating pbuf type and allocation sources + (see PBUF_TYPE_FLAG_*, PBUF_ALLOC_FLAG_* and PBUF_TYPE_ALLOC_SRC_MASK) + */ + u8_t type_internal; /** misc flags */ u8_t flags; @@ -106,10 +215,27 @@ struct pbuf { * that refer to this pbuf. This can be pointers from an application, * the stack itself, or pbuf->next pointers from a chain. */ - u16_t ref; + LWIP_PBUF_REF_T ref; + + /** For incoming packets, this contains the input netif's index */ + u8_t if_idx; + uint64_t ptp_timestamp; }; + +/** Helper struct for const-correctness only. + * The only meaning of this one is to provide a const payload pointer + * for PBUF_ROM type. + */ +struct pbuf_rom { + /** next pbuf in singly linked pbuf chain */ + struct pbuf *next; + + /** pointer to the actual data in the buffer */ + const void *payload; +}; + #if LWIP_SUPPORT_CUSTOM_PBUF /** Prototype for a function to free a custom pbuf */ typedef void (*pbuf_free_custom_fn)(struct pbuf *p); @@ -123,14 +249,13 @@ struct pbuf_custom { }; #endif /* LWIP_SUPPORT_CUSTOM_PBUF */ -#if LWIP_TCP && TCP_QUEUE_OOSEQ /** Define this to 0 to prevent freeing ooseq pbufs when the PBUF_POOL is empty */ #ifndef PBUF_POOL_FREE_OOSEQ #define PBUF_POOL_FREE_OOSEQ 1 #endif /* PBUF_POOL_FREE_OOSEQ */ -#if NO_SYS && PBUF_POOL_FREE_OOSEQ +#if LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ extern volatile u8_t pbuf_free_ooseq_pending; -void pbuf_free_ooseq(); +void pbuf_free_ooseq(void); /** When not using sys_check_timeouts(), call PBUF_CHECK_FREE_OOSEQ() at regular intervals from main level to check if ooseq pbufs need to be freed! */ @@ -138,42 +263,62 @@ void pbuf_free_ooseq(); /* pbuf_alloc() reported PBUF_POOL to be empty -> try to free some \ ooseq queued pbufs now */ \ pbuf_free_ooseq(); }}while(0) -#endif /* NO_SYS && PBUF_POOL_FREE_OOSEQ*/ -#endif /* LWIP_TCP && TCP_QUEUE_OOSEQ */ +#else /* LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ */ + /* Otherwise declare an empty PBUF_CHECK_FREE_OOSEQ */ + #define PBUF_CHECK_FREE_OOSEQ() +#endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ*/ /* Initializes the pbuf module. This call is empty for now, but may not be in future. */ #define pbuf_init() struct pbuf *pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type); +struct pbuf *pbuf_alloc_reference(void *payload, u16_t length, pbuf_type type); #if LWIP_SUPPORT_CUSTOM_PBUF struct pbuf *pbuf_alloced_custom(pbuf_layer l, u16_t length, pbuf_type type, struct pbuf_custom *p, void *payload_mem, u16_t payload_mem_len); #endif /* LWIP_SUPPORT_CUSTOM_PBUF */ -void pbuf_realloc(struct pbuf *p, u16_t size); +void pbuf_realloc(struct pbuf *p, u16_t size); +#define pbuf_get_allocsrc(p) ((p)->type_internal & PBUF_TYPE_ALLOC_SRC_MASK) +#define pbuf_match_allocsrc(p, type) (pbuf_get_allocsrc(p) == ((type) & PBUF_TYPE_ALLOC_SRC_MASK)) +#define pbuf_match_type(p, type) pbuf_match_allocsrc(p, type) u8_t pbuf_header(struct pbuf *p, s16_t header_size); +u8_t pbuf_header_force(struct pbuf *p, s16_t header_size); +u8_t pbuf_add_header(struct pbuf *p, size_t header_size_increment); +u8_t pbuf_add_header_force(struct pbuf *p, size_t header_size_increment); +u8_t pbuf_remove_header(struct pbuf *p, size_t header_size); +struct pbuf *pbuf_free_header(struct pbuf *q, u16_t size); void pbuf_ref(struct pbuf *p); u8_t pbuf_free(struct pbuf *p); -u8_t pbuf_clen(struct pbuf *p); +u16_t pbuf_clen(const struct pbuf *p); void pbuf_cat(struct pbuf *head, struct pbuf *tail); void pbuf_chain(struct pbuf *head, struct pbuf *tail); struct pbuf *pbuf_dechain(struct pbuf *p); -err_t pbuf_copy(struct pbuf *p_to, struct pbuf *p_from); -u16_t pbuf_copy_partial(struct pbuf *p, void *dataptr, u16_t len, u16_t offset); +err_t pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from); +u16_t pbuf_copy_partial(const struct pbuf *p, void *dataptr, u16_t len, u16_t offset); +void *pbuf_get_contiguous(const struct pbuf *p, void *buffer, size_t bufsize, u16_t len, u16_t offset); err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len); +err_t pbuf_take_at(struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset); +struct pbuf *pbuf_skip(struct pbuf* in, u16_t in_offset, u16_t* out_offset); struct pbuf *pbuf_coalesce(struct pbuf *p, pbuf_layer layer); +struct pbuf *pbuf_clone(pbuf_layer l, pbuf_type type, struct pbuf *p); #if LWIP_CHECKSUM_ON_COPY err_t pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr, u16_t len, u16_t *chksum); #endif /* LWIP_CHECKSUM_ON_COPY */ +#if LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE +void pbuf_split_64k(struct pbuf *p, struct pbuf **rest); +#endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */ -u8_t pbuf_get_at(struct pbuf* p, u16_t offset); -u16_t pbuf_memcmp(struct pbuf* p, u16_t offset, const void* s2, u16_t n); -u16_t pbuf_memfind(struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset); -u16_t pbuf_strstr(struct pbuf* p, const char* substr); +u8_t pbuf_get_at(const struct pbuf* p, u16_t offset); +int pbuf_try_get_at(const struct pbuf* p, u16_t offset); +void pbuf_put_at(struct pbuf* p, u16_t offset, u8_t data); +u16_t pbuf_memcmp(const struct pbuf* p, u16_t offset, const void* s2, u16_t n); +u16_t pbuf_memfind(const struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset); +u16_t pbuf_strstr(const struct pbuf* p, const char* substr); #ifdef __cplusplus } #endif -#endif /* __LWIP_PBUF_H__ */ +#endif /* LWIP_HDR_PBUF_H */ diff --git a/app/lwip_glue.c b/app/lwip_glue.c index 065c297..7f63ada 100644 --- a/app/lwip_glue.c +++ b/app/lwip_glue.c @@ -33,6 +33,30 @@ void start_lwip (void) } +static sys_prot_t ethernet_irq_enabled = 1; + +sys_prot_t sys_arch_protect (void) +{ + sys_prot_t ret; + + nvic_disable_irq (NVIC_ETH_IRQ); + compiler_mb(); + + ret = ethernet_irq_enabled; + ethernet_irq_enabled = 0; + + return ret; +} + +void sys_arch_unprotect (sys_prot_t lev) +{ + if (lev) { + ethernet_irq_enabled = 1; + compiler_mb(); + nvic_enable_irq (NVIC_ETH_IRQ); + } +} + diff --git a/app/ntp.c b/app/ntp.c index 2b9e6f3..c2263c9 100644 --- a/app/ntp.c +++ b/app/ntp.c @@ -83,14 +83,16 @@ static uint64_t ntp_ts_ptp (uint64_t v) return ret; } -static void ntp_rx (void *arg, struct udp_pcb *s, struct pbuf *p, struct ip_addr *src_addr, u16_t port) + + +static void ntp_rx (void *arg, struct udp_pcb *s, struct pbuf *p, const ip_addr_t *src_addr, u16_t port) { uint64_t ref = ref_get_irq(); - struct ip_addr dst_addr = *src_addr; + ip_addr_t dst_addr = *src_addr; ntp_packet_t pkt; do { - if (p->type != PBUF_POOL) break; + // if (p->type_internal != PBUF_POOL) break; if (p->len < sizeof (ntp_packet_t)) break; diff --git a/app/project.h b/app/project.h index cfa58a4..d66122b 100644 --- a/app/project.h +++ b/app/project.h @@ -44,11 +44,12 @@ #include +#include #include #include #include #include -#include +#include #include #include @@ -86,6 +87,9 @@ #define HW_CLOCK_LEN 32 #endif +#define CHATTY_PLLS +#define CHATTY_REPORT + #define TRACE do { stdio_drain(); printf("%s:%d\r\n",__FUNCTION__,__LINE__); } while (0) static inline void compiler_mb (void) diff --git a/app/ptp.c b/app/ptp.c index c05d0c3..026e6ec 100644 --- a/app/ptp.c +++ b/app/ptp.c @@ -167,10 +167,12 @@ void ptp_dispatch (uint64_t edge, const char *src) last_edge = edge; obs_phase = edge_to_phase (edge); +#ifdef CHATTY_PLLS printf ("PTP PLL: obs_f=%9d delta_phi=%5d f=%9d %s\r\n", (int) obs_freq, (int) obs_phase, (int) ptp_freq, src); +#endif /*Ignore bogus observations*/ if (obs_freq > (PTP_CLOCK_HZ + (PTP_CLOCK_HZ / 2))) diff --git a/app/ref.c b/app/ref.c index a131fda..6d335ce 100644 --- a/app/ref.c +++ b/app/ref.c @@ -375,10 +375,12 @@ void ref_dispatch (uint64_t edge, const char *src) +#ifdef CHATTY_PLLS printf ("REF PLL: obs_f=%9d delta_phi=%5d f=%9d %s\r\n", (int) obs_freq, (int) obs_phase, (int) ref_freq, src); +#endif /*Ignore bogus observations*/ diff --git a/app/report.c b/app/report.c index f6c84d9..8d2f342 100644 --- a/app/report.c +++ b/app/report.c @@ -3,6 +3,7 @@ void report_time (const char *src, EPOCH e, uint64_t abs, const char *info) { +#ifdef CHATTY_REPORT printf ("RT %s %08x%08x %08x%08x %s\r\n", src, (unsigned) (abs >> 32), @@ -10,6 +11,7 @@ void report_time (const char *src, EPOCH e, uint64_t abs, const char *info) (unsigned) (e.s >> 32), (unsigned) (e.s & 0xffffffff), info); +#endif } diff --git a/app/steth.c b/app/steth.c index 9d56529..2502770 100644 --- a/app/steth.c +++ b/app/steth.c @@ -250,7 +250,6 @@ steth_rx (void) pbuf_realloc (p, len); - return if0.input (p, &if0); } @@ -269,12 +268,6 @@ eth_isr (void) steth_nis(); } -void -steth_isr (void) -{ - if (eth_irq_ack_pending (ETH_DMASR_NIS)) - steth_nis(); -} err_t @@ -487,6 +480,8 @@ void steth_slow_tick (void) //eth_reset(); ETH_MACCR |= ETH_MACCR_RD; running = 0; + + netif_set_link_down (&if0); } if (!phy_link_isup_wtimeo (PHY) && an_happy) { @@ -529,8 +524,11 @@ void steth_slow_tick (void) eth_start(); + + printf ("starting nic\r\n"); running++; + netif_set_link_up (&if0); } // printf("end slow tick\r\n"); diff --git a/lwip/lwip-1.4.1 b/lwip/lwip-1.4.1 deleted file mode 160000 index 5b8b5d4..0000000 --- a/lwip/lwip-1.4.1 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5b8b5d459e7dd890724515bbfad86c705234f9ec diff --git a/lwip/lwip-2.1.2 b/lwip/lwip-2.1.2 new file mode 160000 index 0000000..159e31b --- /dev/null +++ b/lwip/lwip-2.1.2 @@ -0,0 +1 @@ +Subproject commit 159e31b689577dbf69cf0683bbaffbd71fa5ee10 diff --git a/lwip/lwip-local/port/stm32f4x7/arch/cc.h b/lwip/lwip-local/port/stm32f4x7/arch/cc.h index aa0ec4c..ae6efdb 100644 --- a/lwip/lwip-local/port/stm32f4x7/arch/cc.h +++ b/lwip/lwip-local/port/stm32f4x7/arch/cc.h @@ -41,16 +41,16 @@ typedef unsigned short u16_t; typedef signed short s16_t; typedef unsigned long u32_t; typedef signed long s32_t; -typedef u32_t mem_ptr_t; +//typedef u32_t mem_ptr_t; typedef int sys_prot_t; #define U16_F "hu" #define S16_F "d" #define X16_F "hx" -#define U32_F "u" -#define S32_F "d" -#define X32_F "x" +#define U32_F "lu" +#define S32_F "ld" +#define X32_F "lx" #define SZT_F "uz" -- cgit v1.2.3