Skip to content

Commit f6c28e5

Browse files
authored
Merge pull request #11586 from AnttiKauppila/lwip_improvements
Cleaned up Mbed LWIP configurations
2 parents 1dac871 + 691fc55 commit f6c28e5

File tree

5 files changed

+91
-134
lines changed

5 files changed

+91
-134
lines changed

features/lwipstack/lwip-sys/arch/cc.h

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
1-
/*
2-
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
3-
* All rights reserved.
4-
*
5-
* Redistribution and use in source and binary forms, with or without modification,
6-
* are permitted provided that the following conditions are met:
7-
*
8-
* 1. Redistributions of source code must retain the above copyright notice,
9-
* this list of conditions and the following disclaimer.
10-
* 2. Redistributions in binary form must reproduce the above copyright notice,
11-
* this list of conditions and the following disclaimer in the documentation
12-
* and/or other materials provided with the distribution.
13-
* 3. The name of the author may not be used to endorse or promote products
14-
* derived from this software without specific prior written permission.
15-
*
16-
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17-
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18-
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19-
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20-
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21-
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24-
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25-
* OF SUCH DAMAGE.
26-
*
27-
* This file is part of the lwIP TCP/IP stack.
28-
*
29-
* Author: Adam Dunkels <[email protected]>
30-
*
31-
*/
32-
#ifndef __CC_H__
33-
#define __CC_H__
1+
/*
2+
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification,
6+
* are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
* 3. The name of the author may not be used to endorse or promote products
14+
* derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17+
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19+
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21+
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25+
* OF SUCH DAMAGE.
26+
*
27+
* This file is part of the lwIP TCP/IP stack.
28+
*
29+
* Author: Adam Dunkels <[email protected]>
30+
*
31+
*/
32+
#ifndef __CC_H__
33+
#define __CC_H__
3434

3535
#include <stdint.h>
3636
#include <stddef.h> /* for size_t */
3737
#include "mbed_toolchain.h"
38+
#include "lwipopts.h"
3839

3940
#ifdef __cplusplus
4041
extern "C" {
@@ -48,8 +49,10 @@ extern "C" {
4849
#define BYTE_ORDER LITTLE_ENDIAN
4950
#endif
5051

52+
#ifndef LWIP_PROVIDE_ERRNO
5153
/* Use LWIP error codes */
5254
#define LWIP_PROVIDE_ERRNO
55+
#endif
5356

5457
#if defined(__arm__) && defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 6010050)
5558
/* Keil uVision4 tools */
@@ -58,22 +61,22 @@ extern "C" {
5861
#define PACK_STRUCT_END
5962
#define PACK_STRUCT_FIELD(fld) fld
6063
#define ALIGNED(n) __align(n)
61-
#elif defined (__IAR_SYSTEMS_ICC__)
64+
#elif defined (__IAR_SYSTEMS_ICC__)
6265
/* IAR Embedded Workbench tools */
6366
#define PACK_STRUCT_BEGIN __packed
6467
#define PACK_STRUCT_STRUCT
6568
#define PACK_STRUCT_END
6669
#define PACK_STRUCT_FIELD(fld) fld
6770
#define IAR_STR(a) #a
6871
#define ALIGNED(n) _Pragma(IAR_STR(data_alignment= ## n ##))
69-
#else
72+
#else
7073
/* GCC tools (CodeSourcery) */
7174
#define PACK_STRUCT_BEGIN
7275
#define PACK_STRUCT_STRUCT __attribute__ ((__packed__))
7376
#define PACK_STRUCT_END
7477
#define PACK_STRUCT_FIELD(fld) fld
7578
#define ALIGNED(n) __attribute__((aligned (n)))
76-
#endif
79+
#endif
7780

7881
/* Provide Thumb-2 routines for GCC to improve performance */
7982
#if defined(TOOLCHAIN_GCC) && defined(__thumb2__)
@@ -115,7 +118,7 @@ MBED_NORETURN void assert_printf(const char *msg, int line, const char *file);
115118
#define LWIP_PLATFORM_DIAG(vars) printf vars
116119
#define LWIP_PLATFORM_ASSERT(flag) { assert_printf((flag), __LINE__, __FILE__); }
117120
#endif // MBED_CONF_LWIP_USE_MBED_TRACE
118-
#endif
121+
#endif
119122

120123
#if TRACE_TO_ASCII_HEX_DUMP
121124
#define TRACE_TO_ASCII_HEX_DUMPF(prefix, len, data) trace_to_ascii_hex_dump(prefix, len, data)
@@ -180,4 +183,4 @@ SET_MEMP_SECTION(memp_memory_TCPIP_MSG_API_base);
180183
}
181184
#endif
182185

183-
#endif /* __CC_H__ */
186+
#endif /* __CC_H__ */

features/lwipstack/lwip/src/include/lwip/lwip_errno.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ extern "C" {
4444
#endif
4545

4646
#ifdef LWIP_PROVIDE_ERRNO
47+
#if LWIP_PROVIDE_ERRNO == 1
4748

4849
#define EPERM 1 /* Operation not permitted */
4950
#define ENOENT 2 /* No such file or directory */
@@ -177,6 +178,7 @@ extern "C" {
177178
extern int errno;
178179
#endif
179180

181+
#endif //LWIP_PROVIDE_ERRNO == 1
180182
#else /* LWIP_PROVIDE_ERRNO */
181183

182184
/* Define LWIP_ERRNO_STDINCLUDE if you want to include <errno.h> here */

features/lwipstack/lwipopts.h

Lines changed: 18 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,21 @@
2525
#include <sys/time.h>
2626
#endif
2727
#include "nsapi_types.h"
28+
#include "mbed_retarget.h"
29+
2830
// Operating System
2931
#define NO_SYS 0
3032

31-
#if MBED_CONF_LWIP_IPV4_ENABLED
32-
#define LWIP_IPV4 1
33-
#else
34-
#define LWIP_IPV4 0
35-
#endif
36-
#if MBED_CONF_LWIP_IPV6_ENABLED
37-
#define LWIP_IPV6 1
38-
#else
39-
#define LWIP_IPV6 0
40-
#endif
4133
#if !MBED_CONF_LWIP_IPV4_ENABLED && !MBED_CONF_LWIP_IPV6_ENABLED
4234
#error "Either IPv4 or IPv6 must be enabled."
4335
#endif
4436

37+
#define LWIP_IPV4 MBED_CONF_LWIP_IPV4_ENABLED
38+
39+
#define LWIP_IPV6 MBED_CONF_LWIP_IPV6_ENABLED
40+
41+
#define LWIP_PROVIDE_ERRNO 0
42+
4543
// On dual stack configuration how long to wait for both or preferred stack
4644
// addresses before completing bring up.
4745
#if LWIP_IPV4 && LWIP_IPV6
@@ -57,25 +55,19 @@
5755
#define BOTH_ADDR_TIMEOUT 0
5856
#endif
5957

60-
// Configurable DHCP timeout. DHCP timeout can be configured for specific usecase requirement.
61-
#ifdef MBED_CONF_LWIP_DHCP_TIMEOUT
62-
#define DHCP_TIMEOUT (MBED_CONF_LWIP_DHCP_TIMEOUT)
63-
#else
64-
#define DHCP_TIMEOUT 60
65-
#endif
58+
59+
#define DHCP_TIMEOUT MBED_CONF_LWIP_DHCP_TIMEOUT
6660

6761
#define LINK_TIMEOUT 60
6862

6963
#define PREF_IPV4 1
7064
#define PREF_IPV6 2
7165

72-
#if MBED_CONF_LWIP_IP_VER_PREF == 4
73-
#define IP_VERSION_PREF PREF_IPV4
74-
#endif
7566
#if MBED_CONF_LWIP_IP_VER_PREF == 6
7667
#define IP_VERSION_PREF PREF_IPV6
77-
#endif
78-
#ifndef IP_VERSION_PREF
68+
#elif MBED_CONF_LWIP_IP_VER_PREF == 4
69+
#define IP_VERSION_PREF PREF_IPV4
70+
#else
7971
#error "Either IPv4 or IPv6 must be preferred."
8072
#endif
8173

@@ -103,11 +95,6 @@
10395
// Thread stacks use 8-byte alignment
10496
#define LWIP_ALIGN_UP(pos, align) ((pos) % (align) ? (pos) + ((align) - (pos) % (align)) : (pos))
10597

106-
// Thread stack size for lwip tcpip thread
107-
#ifndef MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE
108-
#define MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE 1200
109-
#endif
110-
11198
#ifdef LWIP_DEBUG
11299
// For LWIP debug, double the stack
113100
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE*2, 8)
@@ -121,11 +108,6 @@
121108
// Thread priority (osPriorityNormal by default)
122109
#define TCPIP_THREAD_PRIO (MBED_CONF_LWIP_TCPIP_THREAD_PRIORITY)
123110

124-
// Thread stack size for lwip system threads
125-
#ifndef MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE
126-
#define MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE 512
127-
#endif
128-
129111
#ifdef LWIP_DEBUG
130112
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE*2, 8)
131113
#else
@@ -144,43 +126,24 @@
144126
#define LWIP_RAM_HEAP_POINTER lwip_ram_heap
145127

146128
// Number of simultaneously queued TCP segments.
147-
#ifdef MBED_CONF_LWIP_MEMP_NUM_TCP_SEG
148129
#define MEMP_NUM_TCP_SEG MBED_CONF_LWIP_MEMP_NUM_TCP_SEG
149-
#endif
150130

151131
// TCP Maximum segment size.
152-
#ifdef MBED_CONF_LWIP_TCP_MSS
153132
#define TCP_MSS MBED_CONF_LWIP_TCP_MSS
154-
#endif
155133

156134
// TCP sender buffer space (bytes).
157-
#ifdef MBED_CONF_LWIP_TCP_SND_BUF
158135
#define TCP_SND_BUF MBED_CONF_LWIP_TCP_SND_BUF
159-
#endif
160136

161137
// TCP sender buffer space (bytes).
162-
#ifdef MBED_CONF_LWIP_TCP_WND
163138
#define TCP_WND MBED_CONF_LWIP_TCP_WND
164-
#endif
165139

166-
#ifdef MBED_CONF_LWIP_TCP_MAXRTX
167140
#define TCP_MAXRTX MBED_CONF_LWIP_TCP_MAXRTX
168-
#endif
169141

170-
#ifdef MBED_CONF_LWIP_TCP_SYNMAXRTX
171142
#define TCP_SYNMAXRTX MBED_CONF_LWIP_TCP_SYNMAXRTX
172-
#endif
173143

174144
// Number of pool pbufs.
175145
// Each requires 684 bytes of RAM (if MSS=536 and PBUF_POOL_BUFSIZE defaulting to be based on MSS)
176-
#ifdef MBED_CONF_LWIP_PBUF_POOL_SIZE
177-
#undef PBUF_POOL_SIZE
178146
#define PBUF_POOL_SIZE MBED_CONF_LWIP_PBUF_POOL_SIZE
179-
#else
180-
#ifndef PBUF_POOL_SIZE
181-
#define PBUF_POOL_SIZE 5
182-
#endif
183-
#endif
184147

185148
#ifdef MBED_CONF_LWIP_PBUF_POOL_BUFSIZE
186149
#undef PBUF_POOL_BUFSIZE
@@ -195,63 +158,38 @@
195158
#endif
196159
#endif
197160

198-
#ifdef MBED_CONF_LWIP_MEM_SIZE
199-
#undef MEM_SIZE
200161
#define MEM_SIZE MBED_CONF_LWIP_MEM_SIZE
201-
#endif
202162

203163
// One tcp_pcb_listen is needed for each TCPServer.
204164
// Each requires 72 bytes of RAM.
205-
#ifdef MBED_CONF_LWIP_TCP_SERVER_MAX
206165
#define MEMP_NUM_TCP_PCB_LISTEN MBED_CONF_LWIP_TCP_SERVER_MAX
207-
#else
208-
#define MEMP_NUM_TCP_PCB_LISTEN 4
209-
#endif
210166

211167
// One is tcp_pcb needed for each TCPSocket.
212168
// Each requires 196 bytes of RAM.
213-
#ifdef MBED_CONF_LWIP_TCP_SOCKET_MAX
214169
#define MEMP_NUM_TCP_PCB MBED_CONF_LWIP_TCP_SOCKET_MAX
215-
#else
216-
#define MEMP_NUM_TCP_PCB 4
217-
#endif
218170

219171
// One udp_pcb is needed for each UDPSocket.
220172
// Each requires 84 bytes of RAM (total rounded to multiple of 512).
221-
#ifdef MBED_CONF_LWIP_UDP_SOCKET_MAX
222173
#define MEMP_NUM_UDP_PCB MBED_CONF_LWIP_UDP_SOCKET_MAX
223-
#else
224-
#define MEMP_NUM_UDP_PCB 4
225-
#endif
226174

227175
// Number of non-pool pbufs.
228176
// Each requires 92 bytes of RAM.
229-
#ifndef MEMP_NUM_PBUF
230-
#define MEMP_NUM_PBUF 8
231-
#endif
177+
#define MEMP_NUM_PBUF MBED_CONF_LWIP_NUM_PBUF
232178

233179
// Each netbuf requires 64 bytes of RAM.
234-
#ifndef MEMP_NUM_NETBUF
235-
#define MEMP_NUM_NETBUF 8
236-
#endif
180+
#define MEMP_NUM_NETBUF MBED_CONF_LWIP_NUM_NETBUF
237181

238182
// One netconn is needed for each UDPSocket, TCPSocket or TCPServer.
239183
// Each requires 236 bytes of RAM (total rounded to multiple of 512).
240-
#ifdef MBED_CONF_LWIP_SOCKET_MAX
241184
#define MEMP_NUM_NETCONN MBED_CONF_LWIP_SOCKET_MAX
242-
#else
243-
#define MEMP_NUM_NETCONN 4
244-
#endif
245185

246186
#if MBED_CONF_LWIP_TCP_ENABLED
247187
#define LWIP_TCP 1
248188
#define TCP_OVERSIZE 0
249189
#define LWIP_TCP_KEEPALIVE 1
250-
#ifdef MBED_CONF_TCP_CLOSE_TIMEOUT
251-
#define TCP_CLOSE_TIMEOUT MBED_CONF_TCP_CLOSE_TIMEOUT
252-
#else
253-
#define TCP_CLOSE_TIMEOUT 1000
254-
#endif
190+
191+
#define TCP_CLOSE_TIMEOUT MBED_CONF_LWIP_TCP_CLOSE_TIMEOUT
192+
255193
#else
256194
#define LWIP_TCP 0
257195
#endif

0 commit comments

Comments
 (0)