ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
在前面的章节也说了lwipopts.h文件的作用,而此刻在操作系统中移植,我们首先要将添加了操作系统的工程拿过来,把lwipopts.h文件修改一下,该文件最重要的宏定义就是NO\_SYS,我们把它定义为0就表示使用操作系统,当然,在使用操作系统的时候我们一般都会使用NETCONN API 与Socket API编程,那么就需要将宏LWIP\_NETCONN与LWIP\_SOCKET定义为1,表示使能这两种API编程,lwipopts.h简单修改一下即可,然后再添加一下线程运行的一些宏定义,必须修改的部分具体见代码清单 8‑2加粗部分,而其他宏定义是根据实际情况进行修改即可。 ``` 1 #ifndef __LWIPOPTS_H__ 2 #define __LWIPOPTS_H__ 3 4 /** 5 * SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain 6 * critical regions during buffer allocation, deallocation and memory 7 * allocation and deallocation. 8 */ 9 #define SYS_LIGHTWEIGHT_PROT 1 10 11 /** 12 * NO_SYS==1: Provides VERY minimal functionality. Otherwise, 13 * use lwIP facilities. 14 */ 15 #define NO_SYS 0 16 17 /** 18 * NO_SYS_NO_TIMERS==1: Drop support for sys_timeout when NO_SYS==1 19 * Mainly for compatibility to old versions. 20 */ 21 #define NO_SYS_NO_TIMERS 0 22 23 /* ---------- Memory options ---------- */ 24 /* MEM_ALIGNMENT: should be set to the alignment of the CPU for which 25 lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2 26 byte alignment -> define MEM_ALIGNMENT to 2. */ 27 #define MEM_ALIGNMENT 4 28 29 /* MEM_SIZE: the size of the heap memory. If the application will send 30 a lot of data that needs to be copied, this should be set high. */ 31 #define MEM_SIZE (15*1024) 32 33 /* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application 34 sends a lot of data out of ROM (or other static memory), this 35 should be set high. */ 36 #define MEMP_NUM_PBUF 25 37 /* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One 38 per active UDP "connection". */ 39 #define MEMP_NUM_UDP_PCB 4 40 /* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP 41 connections. */ 42 #define MEMP_NUM_TCP_PCB 6 43 /* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP 44 connections. */ 45 #define MEMP_NUM_TCP_PCB_LISTEN 6 46 /* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP 47 segments. */ 48 #define MEMP_NUM_TCP_SEG 150 49 /* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active 50 timeouts. */ 51 #define MEMP_NUM_SYS_TIMEOUT 6 52 53 54 /* ---------- Pbuf options ---------- */ 55 /* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */ 56 #define PBUF_POOL_SIZE 45 57 /* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */ 58 #define PBUF_POOL_BUFSIZE \ 59 LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN) 60 61 /* ---------- TCP options ---------- */ 62 #define LWIP_TCP 1 63 #define TCP_TTL 255 64 65 /* Controls if TCP should queue segments that arrive out of 66 order. Define to 0 if your device is low on memory. */ 67 #define TCP_QUEUE_OOSEQ 0 68 69 /* TCP Maximum segment size. */ 70 #define TCP_MSS (1500 - 40) 71 72 /* TCP sender buffer space (bytes). */ 73 #define TCP_SND_BUF (10*TCP_MSS) 74 75 /* TCP_SND_QUEUELEN: TCP sender buffer space (pbufs). This must be at least 76 as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. */ 77 78 #define TCP_SND_QUEUELEN (8* TCP_SND_BUF/TCP_MSS) 79 80 /* TCP receive window. */ 81 #define TCP_WND (11*TCP_MSS) 82 83 84 /* ---------- ICMP options ---------- */ 85 #define LWIP_ICMP 1 86 87 88 /* ---------- DHCP options ---------- */ 89 /* Define LWIP_DHCP to 1 if you want DHCP configuration of 90 interfaces. DHCP is not implemented in lwIP 0.5.1, however, so 91 turning this on does currently not work. */ 92 #define LWIP_DHCP 1 93 94 95 /* ---------- UDP options ---------- */ 96 #define LWIP_UDP 1 97 #define UDP_TTL 255 98 99 100 /* ---------- Statistics options ---------- */ 101 #define LWIP_STATS 0 102 #define LWIP_PROVIDE_ERRNO 1 103 104 /* ---------- link callback options ---------- */ 105 /* LWIP_NETIF_LINK_CALLBACK==1: Support a callback function from an interface 106 * whenever the link changes (i.e., link down) 107 */ 108 #define LWIP_NETIF_LINK_CALLBACK 0 109 /* 110 -------------------------------------- 111 ---------- Checksum options ---------- 112 -------------------------------------- 113 */ 114 115 /* The STM32F4x7 allows computing and verifying the IP, 116 UDP, TCP and ICMP checksums by hardware: 117 - To use this feature let the following define uncommented. 118 - To disable it and process by CPU comment the the checksum. 119 */ 120 #define CHECKSUM_BY_HARDWARE 121 122 123 #ifdef CHECKSUM_BY_HARDWARE 124 /* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.*/ 125 #define CHECKSUM_GEN_IP 0 126 /* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.*/ 127 #define CHECKSUM_GEN_UDP 0 128 /* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.*/ 129 #define CHECKSUM_GEN_TCP 0 130 /* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.*/ 131 #define CHECKSUM_CHECK_IP 0 132 /* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.*/ 133 #define CHECKSUM_CHECK_UDP 0 134 /* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.*/ 135 #define CHECKSUM_CHECK_TCP 0 136 /*CHECKSUM_CHECK_ICMP==0: Check checksums by hardware for incoming ICMP packets.*/ 137 #define CHECKSUM_GEN_ICMP 0 138 #else 139 /* CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets.*/ 140 #define CHECKSUM_GEN_IP 1 141 /* CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets.*/ 142 #define CHECKSUM_GEN_UDP 1 143 /* CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets.*/ 144 #define CHECKSUM_GEN_TCP 1 145 /* CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets.*/ 146 #define CHECKSUM_CHECK_IP 1 147 /* CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets.*/ 148 #define CHECKSUM_CHECK_UDP 1 149 /* CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets.*/ 150 #define CHECKSUM_CHECK_TCP 1 151 /*CHECKSUM_CHECK_ICMP==1: Check checksums by hardware for incoming ICMP packets.*/ 152 #define CHECKSUM_GEN_ICMP 1 153 #endif 154 155 156 /* 157 ---------------------------------------------- 158 ---------- Sequential layer options ---------- 159 ---------------------------------------------- 160 */ 161 /** 162 * LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c) 163 */ 164 #define LWIP_NETCONN 1 165 166 /* 167 ------------------------------------ 168 ---------- Socket options ---------- 169 ------------------------------------ 170 */ 171 /** 172 * LWIP_SOCKET==1: Enable Socket API (require to use sockets.c) 173 */ 174 #define LWIP_SOCKET 1 175 176 /* 177 --------------------------------- 178 ---------- OS options ---------- 179 --------------------------------- 180 */ 181 182 183 #define DEFAULT_UDP_RECVMBOX_SIZE 10 184 #define DEFAULT_TCP_RECVMBOX_SIZE 10 185 #define DEFAULT_ACCEPTMBOX_SIZE 10 186 #define DEFAULT_THREAD_STACKSIZE 1024 187 188 189 #define TCPIP_THREAD_NAME "lwip" 190 #define TCPIP_THREAD_STACKSIZE 512 191 #define TCPIP_MBOX_SIZE 8 192 #define TCPIP_THREAD_PRIO 3 ```