|
发表于 2019-1-28 09:00:06
|
显示全部楼层
/**
******************************************************************************
* File Name : lwipopts.h
* Description : This file overrides LwIP stack default configuration
* done in opt.h file.
******************************************************************************
* This notice applies to any and all portions of this file
* that are not between comment pairs USER CODE BEGIN and
* USER CODE END. Other portions of this file, whether
* inserted by the user or by software development tools
* are owned by their respective copyright owners.
*
* Copyright (c) 2018 STMicroelectronics International N.V.
* 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. Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific written permission.
* 4. This software, including modifications and/or derivative works of this
* software, must execute solely and exclusively on microcontroller or
* microprocessor devices manufactured by or for STMicroelectronics.
* 5. Redistribution and use of this software other than as permitted under
* this license is void and will automatically terminate your rights under
* this license.
*
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion --------------------------------------*/
#ifndef __LWIPOPTS__H__
#define __LWIPOPTS__H__
#include "stm32f4xx_hal.h"
#include <common.h>
/*-----------------------------------------------------------------------------*/
/* Current version of LwIP supported by CubeMx: 2.0.3 -*/
/*-----------------------------------------------------------------------------*/
/* Within 'USER CODE' section, code will be kept by default at each generation */
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
#ifdef __cplusplus
extern "C" {
#endif
/* STM32CubeMX Specific Parameters (not defined in opt.h) ---------------------*/
/* Parameters set in STM32CubeMX LwIP Configuration GUI -*/
//==============================================================================================================
// WITH_RTOS = 1: 使用操作系统
// WITH_RTOS = 0: 不使用操作系统
//==============================================================================================================
#define WITH_RTOS (1u)
//==============================================================================================================
// CHECKSUM_BY_HARDWARE disabled
//==============================================================================================================
#define CHECKSUM_BY_HARDWARE (0u)
//==============================================================================================================
// Value in opt.h for LWIP_DHCP: 0
// LWIP_DHCP = 0:关闭 DHCP 功能
// LWIP_DHCP = 1:开启 DHCP 功能,可以自动分配IP地址。
//==============================================================================================================
#define LWIP_DHCP (1u)
//==============================================================================================================
// Default Value for LWIP_DNS: 0
// LWIP_DNS = 0:关闭 DNS 功能
// LWIP_DNS = 1:开启 DNS 功能,可以支持域名解析功能。
//==============================================================================================================
#define LWIP_DNS (1u)
//==============================================================================================================
// Default Value for MEMP_NUM_NETCONN: 4
// MEMP_NUM_NETCONN: the number of struct netconns.
// (only needed if you use the sequential API, like api_lib.c)
//==============================================================================================================
#define MEMP_NUM_NETCONN (8u)
//==============================================================================================================
// Default Value for MEMP_NUM_UDP_PCB: 4
// MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
// per active UDP "connection".
// (requires the LWIP_UDP option)
//==============================================================================================================
#define MEMP_NUM_UDP_PCB (4u)
//==============================================================================================================
// Default Value for MEMP_NUM_TCP_PCB: 5
// MEMP_NUM_TCP_PCB: the number of simultaneously active TCP connections.
// (requires the LWIP_TCP option)
//==============================================================================================================
#define MEMP_NUM_TCP_PCB (8u)
//==============================================================================================================
// Default Value for MEMP_NUM_TCP_PCB_LISTEN: 8
// MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP connections.
// (requires the LWIP_TCP option)
//==============================================================================================================
#define MEMP_NUM_TCP_PCB_LISTEN (8u)
//==============================================================================================================
// Value in opt.h for MEM_ALIGNMENT: 1
// 内存对齐方式,STM32 是32位机,使用 4 字节对齐。
//==============================================================================================================
#define MEM_ALIGNMENT (4u)
//==============================================================================================================
// Value in opt.h for MEM_SIZE: 1600
// 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.
// 内存堆大小定义,如果要发送大量的需要复制的数据,这个需要设置大一点。默认值是 1600
// 单位:字节
// Heap 设置多大,基本就需要多大的内存。
//==============================================================================================================
#define MEM_SIZE (32*1024u)
//==============================================================================================================
// Value in opt.h for MEMP_NUM_PBUF: 16
// MEMP_NUM_PBUF: the number of memp struct pbufs (used for PBUF_ROM and PBUF_REF).
// If the application sends a lot of data out of ROM (or other static memory),
// this should be set high.
// MEMP_NUM_PBUF: memp结构的pbuf数量,如果应用从ROM或者静态存储区发送大量数据时,设置大一些。
// 修改这个值,编译后对内存的影响不大,16Byte * N。
//==============================================================================================================
#define MEMP_NUM_PBUF (192u)
//==============================================================================================================
// Value in opt.h for MEMP_NUM_TCPIP_MSG_API: 8
// MEMP_NUM_TCPIP_MSG_API: the number of struct tcpip_msg, which are used
// for callback/timeout API communication.
// (only needed if you use tcpip.c)
// tcpip_msg 数量,用于回调、超时等API应用。
// 修改这个值,编译后对内存的影响不大,16Byte * N
//==============================================================================================================
#define MEMP_NUM_TCPIP_MSG_API (192u)
//==============================================================================================================
// Value in opt.h for MEMP_NUM_TCPIP_MSG_INPKT: 8
// MEMP_NUM_TCPIP_MSG_INPKT: the number of struct tcpip_msg, which are used
// for incoming packets.
// (only needed if you use tcpip.c)
// tcpip_msg 数量,用于输入数据接收。
// 修改这个值,编译后对内存的影响不大,16Byte * N
//==============================================================================================================
#define MEMP_NUM_TCPIP_MSG_INPKT (192u)
//==============================================================================================================
// Value in opt.h for PBUF_POOL_SIZE: 16
// PBUF_POOL_SIZE: the number of buffers in the pbuf pool.
//
// pbuf 内存池个数
// PBUF_POOL_SIZE * ( PBUF_POOL_BUFSIZE + header ) = 内存池需要的大小。
// 修改这两个值,对内存的占用影响很大。
//
// PBUF_POOL_SIZE * PBUF_POOL_BUFSIZE 必须要比 TCP_WND 和 TCP_SND_BUF 大。
// 修改参数时,注意检测这几个宏之间的关系。
//==============================================================================================================
#define PBUF_POOL_SIZE (32u)
//==============================================================================================================
// PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. The default is
// designed to accommodate single full size TCP frame in one pbuf, including
// TCP_MSS, IP header, and link header.
// PBUF_POOL_BUFSIZE = LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
//
// pbuf 内存池大小,单个 pbuf 能存下一个完整的 TCP 帧,完整的 TCP 帧大小:
// TCP_MSS+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN = 1460 + 40 + 0 + 18 = 1518
//==============================================================================================================
#define PBUF_POOL_BUFSIZE (1520u)
//==============================================================================================================
// TCP_MSS: TCP Maximum segment size. (default is 536, a conservative default,
// you might want to increase this.)
// For the receive side, this MSS is advertised to the remote side
// when opening a connection. For the transmit size, this MSS sets
// an upper limit on the MSS advertised by the remote host.
// 最大TCP数据分段,加大这个值可以提高通信速率,但是会占用更多的内存。默认值 536.
// TCP 协议在建立连接时,会协商 MSS 值
//==============================================================================================================
#define TCP_MSS (1460u)
//==============================================================================================================
// TCP_WND: The size of a TCP window. This must be at least
// (2 * TCP_MSS) for things to work well.
// ATTENTION: when using TCP_RCV_SCALE, TCP_WND is the total size
// with scaling applied. Maximum window value in the TCP header
// will be TCP_WND >> TCP_RCV_SCALE
// 注意:TCP_WND是发送窗口,这个值对于LWIP的速度影响非常大。
// TCP_WND 不能大于 PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZE - protocol headers).
//==============================================================================================================
#define TCP_WND (24 * TCP_MSS)
//==============================================================================================================
// TCP_WND_UPDATE_THRESHOLD: difference in window to trigger an
// explicit window update
// Value in opt.h for TCP_WND_UPDATE_THRESHOLD: LWIP_MIN(TCP_WND/4, TCP_MSS*4)
//==============================================================================================================
#define TCP_WND_UPDATE_THRESHOLD (4 * TCP_MSS)
//==============================================================================================================
// TCP_SND_BUF: TCP sender buffer space (bytes).
// To achieve good performance, this should be at least 2 * TCP_MSS.
//==============================================================================================================
#define TCP_SND_BUF (24 * 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 - 1))/(TCP_MSS))
//==============================================================================================================
// MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP segments.
// (requires the LWIP_TCP option)
// MEMP_NUM_TCP_SEG should be at least as big as TCP_SND_QUEUELEN.
// MEMP_NUM_TCP_SEG: 最多同时在队列中的TCP段数量,至少要和 TCP_SND_QUEUELEN 一样大。
//==============================================================================================================
#define MEMP_NUM_TCP_SEG (256u)
//==============================================================================================================
// LWIP_ETHERNET==1: enable ethernet support even though ARP might be disabled
// Value in opt.h for LWIP_ETHERNET: LWIP_ARP || PPPOE_SUPPORT -
//==============================================================================================================
#define LWIP_ETHERNET (1u)
//==============================================================================================================
// TCPIP_THREAD_STACKSIZE: The stack size used by the main tcpip thread.
// The stack size value itself is platform-dependent, but is passed to
// sys_thread_new() when the thread is created.
// TCPIP_THREAD 任务栈大小,平台相关配置,注意:单位是4字节
//
// TCPIP_THREAD_PRIO: The priority assigned to the main tcpip thread.
// The priority value itself is platform-dependent, but is passed to
// sys_thread_new() when the thread is created.
// osPriorityIdle = -3, ///< priority: idle (lowest)
// osPriorityLow = -2, ///< priority: low
// osPriorityBelowNormal = -1, ///< priority: below normal
// osPriorityNormal = 0, ///< priority: normal (default)
// osPriorityAboveNormal = +1, ///< priority: above normal
// osPriorityHigh = +2, ///< priority: high
// osPriorityRealtime = +3, ///< priority: realtime (highest)
// 优先级说明:这个是 CubeMX 为了兼容性而修改的枚举类型,对于FreeRTOS,实际优先级等级要加3.
//==============================================================================================================
#define TCPIP_THREAD_STACKSIZE (512u)
#define TCPIP_THREAD_PRIO osPriorityHigh
#define SLIPIF_THREAD_STACKSIZE (512u)
#define SLIPIF_THREAD_PRIO osPriorityHigh
#define DEFAULT_THREAD_STACKSIZE (512u)
#define DEFAULT_THREAD_PRIO osPriorityHigh
//==============================================================================================================
// DEFAULT_UDP_RECVMBOX_SIZE: The mailbox size for the incoming packets on a
// NETCONN_UDP. The queue size value itself is platform-dependent, but is passed
// to sys_mbox_new() when the recvmbox is created.
// 消息邮箱大小,每个邮箱内容占用6个字节,指针+长度。
//==============================================================================================================
#define TCPIP_MBOX_SIZE (6u)
#define DEFAULT_UDP_RECVMBOX_SIZE (6u)
#define DEFAULT_TCP_RECVMBOX_SIZE (6u)
#define DEFAULT_ACCEPTMBOX_SIZE (6u)
//==============================================================================================================
// LWIP_TCP_KEEPALIVE==1: Enable TCP_KEEPIDLE, TCP_KEEPINTVL and TCP_KEEPCNT
// options processing. Note that TCP_KEEPIDLE and TCP_KEEPINTVL have to be set
// in seconds. (does not require sockets.c, and will affect tcp.c)
//
// Keepalive values, compliant with RFC 1122. Don't change this unless you know what you're doing
// 保活机制的参数,满足 RFC1122 标准,不要修改,除非你清楚地知道你在做什么。
// 实际保活机制的默认参数,保活检测的时间间隔太长,如果需要更快发现连接问题,需要缩短保活时间参数。
//
// LWIP_TCP_KEEPALIVE == 1:开启保活机制自定义参数。
// 如果 TCP_KEEPIDLE_DEFAULT 时间内没有数据交互,则发起保活探测(默认值为 7200000ms=2小时)。
// 每 TCP_KEEPINTVL_DEFAULT 时间发送一次保活探测(默认值为 75000 = 75s)。
// TCP_KEEPCNT_DEFAULT:保活探测发送的次数
//==============================================================================================================
#define LWIP_TCP_KEEPALIVE (1u)
#define TCP_KEEPIDLE_DEFAULT (90000u)
#define TCP_KEEPINTVL_DEFAULT (5000u)
#define TCP_KEEPCNT_DEFAULT (3u)
//==============================================================================================================
// LWIP_SO_SNDTIMEO==1: Enable send timeout for sockets/netconns and
// SO_SNDTIMEO processing.
// 注意,调用 netconn_write 函数发送数据,是不能开启发送超时的。
// 如果开启 LWIP_SO_SNDTIMEO == 1,并且 tcp_conn->send_timeout != 0,那么会返回参数错误。
//==============================================================================================================
#define LWIP_SO_SNDTIMEO (0u)
//==============================================================================================================
// LWIP_SO_RCVTIMEO==1: Enable receive timeout for sockets/netconns and
// SO_RCVTIMEO processing.
// 接收超时定义,可以用作心跳超时检测,如果在超时时间内没有收到心跳包,表示连接异常。
// 开启 LWIP_SO_RCVTIMEO == 1,需要设置 tcp_conn->recv_timeout 接收超时时间,单位ms。
//==============================================================================================================
#define LWIP_SO_RCVTIMEO (1u)
//==============================================================================================================
// LWIP_TCPIP_CORE_LOCKING
// Creates a global mutex that is held during TCPIP thread operations.
// Can be locked by client code to perform lwIP operations without changing
// into TCPIP thread using callbacks. See LOCK_TCPIP_CORE() and
// UNLOCK_TCPIP_CORE().
// Your system should provide mutexes supporting priority inversion to use this.
// 内核互斥锁开关,必须开启。
//==============================================================================================================
#define LWIP_TCPIP_CORE_LOCKING 1
//==============================================================================================================
// LWIP_TCPIP_CORE_LOCKING_INPUT: when LWIP_TCPIP_CORE_LOCKING is enabled,
// this lets tcpip_input() grab the mutex for input packets as well,
// instead of allocating a message and passing it to tcpip_thread.
//
// ATTENTION: this does not work when tcpip_input() is called from
// interrupt context!
// tcpip_input() 同样使用竞争内核互斥锁的方式,替代申请发送消息给 tcpip_thread。
// 注意:如果开启输入互斥锁,tcpip_input() 不能在中断中调用!
// 测试结果:在多任务并发的时候,开启 LWIP_TCPIP_CORE_LOCKING_INPUT == 1,可以大幅提高通信速率,特别是稳定性。
// 开启前,多任务并发时,通信速率低且不稳定,发送函数 netconn_write 会阻塞死发送任务。
// 开启后,多任务并发时,通信速率高且稳定,发送函数 netconn_write 不会阻塞死发送任务。
//==============================================================================================================
#define LWIP_TCPIP_CORE_LOCKING_INPUT (1u)
//==============================================================================================================
// SYS_LIGHTWEIGHT_PROT==1: enable inter-task protection (and task-vs-interrupt
// protection) for certain critical regions during buffer allocation, deallocation
// and memory allocation and deallocation.
// ATTENTION: This is required when using lwIP from more than one context! If
// you disable this, you must be sure what you are doing!
//==============================================================================================================
#define SYS_LIGHTWEIGHT_PROT (1u)
//==============================================================================================================
// LWIP_NETCONN_SEM_PER_THREAD==1: Use one (thread-local) semaphore per
// thread calling socket/netconn functions instead of allocating one
// semaphore per netconn (and per select etc.)
// ATTENTION: a thread-local semaphore for API calls is needed:
// - LWIP_NETCONN_THREAD_SEM_GET() returning a sys_sem_t*
// - LWIP_NETCONN_THREAD_SEM_ALLOC() creating the semaphore
// - LWIP_NETCONN_THREAD_SEM_FREE() freeing the semaphore
// The latter 2 can be invoked up by calling netconn_thread_init()/netconn_thread_cleanup().
// Ports may call these for threads created with sys_thread_new().
// 测试结果:开启该宏,编译会报错,目前没有深入分析。
//==============================================================================================================
#define LWIP_NETCONN_SEM_PER_THREAD (0u)
//==============================================================================================================
// 这里是调试相关
// 压力测试,不要打开调试信息输出,输出的信息量太大了!
//==============================================================================================================
/*
extern void print( const INT8U* format, ... );
#ifndef LWIP_PLATFORM_DIAG
#define LWIP_PLATFORM_DIAG(x) print x
#endif
#define U8_F "c"
#define S8_F "c"
#define X8_F "x"
#define U16_F "u"
#define S16_F "d"
#define X16_F "x"
#define U32_F "u"
#define S32_F "d"
#define X32_F "x"
#define LWIP_DEBUG (1u)
// #define NETIF_DEBUG LWIP_DBG_ON
// #define API_MSG_DEBUG LWIP_DBG_ON
// #define MEM_DEBUG LWIP_DBG_ON
// #define MEMP_DEBUG LWIP_DBG_ON
// #define SYS_DEBUG LWIP_DBG_ON
// #define TCP_DEBUG LWIP_DBG_ON
// #define TCP_INPUT_DEBUG LWIP_DBG_ON
// #define TCP_FR_DEBUG LWIP_DBG_ON
// #define TCP_RTO_DEBUG LWIP_DBG_ON
// #define TCP_CWND_DEBUG LWIP_DBG_ON
// #define TCP_WND_DEBUG LWIP_DBG_ON
#define TCP_OUTPUT_DEBUG LWIP_DBG_ON
// #define TCP_RST_DEBUG LWIP_DBG_ON
// #define TCP_QLEN_DEBUG LWIP_DBG_ON
*/
//==============================================================================================================
// 其他宏定义
// CubeMX 生成,没有做改动的部分。
//==============================================================================================================
/*----- Value in opt.h for RECV_BUFSIZE_DEFAULT: INT_MAX -----*/
#define RECV_BUFSIZE_DEFAULT 2000000000
/*----- Value in opt.h for LWIP_STATS: 1 -----*/
#define LWIP_STATS 0
/*----- Value in opt.h for CHECKSUM_GEN_IP: 1 -----*/
#define CHECKSUM_GEN_IP 0
/*----- Value in opt.h for CHECKSUM_GEN_UDP: 1 -----*/
#define CHECKSUM_GEN_UDP 0
/*----- Value in opt.h for CHECKSUM_GEN_TCP: 1 -----*/
#define CHECKSUM_GEN_TCP 0
/*----- Value in opt.h for CHECKSUM_GEN_ICMP: 1 -----*/
#define CHECKSUM_GEN_ICMP 0
/*----- Value in opt.h for CHECKSUM_GEN_ICMP6: 1 -----*/
#define CHECKSUM_GEN_ICMP6 0
/*----- Value in opt.h for CHECKSUM_CHECK_IP: 1 -----*/
#define CHECKSUM_CHECK_IP 0
/*----- Value in opt.h for CHECKSUM_CHECK_UDP: 1 -----*/
#define CHECKSUM_CHECK_UDP 0
/*----- Value in opt.h for CHECKSUM_CHECK_TCP: 1 -----*/
#define CHECKSUM_CHECK_TCP 0
/*----- Value in opt.h for CHECKSUM_CHECK_ICMP: 1 -----*/
#define CHECKSUM_CHECK_ICMP 0
/*----- Value in opt.h for CHECKSUM_CHECK_ICMP6: 1 -----*/
#define CHECKSUM_CHECK_ICMP6 0
/*-----------------------------------------------------------------------------*/
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
#ifdef __cplusplus
}
#endif
#endif /*__LWIPOPTS__H_H */
//================================分割线================================================================================
LWIP V2.0.3, 以上是根据个人的理解,以及反复测试得出的配置,占用内存比较大,但数据速率可以到50Mbps以上,还比较稳定。
在IAR下,只能低优先级优化,不要开中、高优先级优化。工程由 CubeMX 自动生成。
|
|