Skip to content

Commit d34a40a

Browse files
author
Antti Kauppila
committed
Cleaned up Mbed LWIP configurations
1 parent ba7b479 commit d34a40a

File tree

5 files changed

+53
-100
lines changed

5 files changed

+53
-100
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ extern "C" {
4848
#define BYTE_ORDER LITTLE_ENDIAN
4949
#endif
5050

51+
#ifndef LWIP_PROVIDE_ERRNO
5152
/* Use LWIP error codes */
5253
#define LWIP_PROVIDE_ERRNO
54+
#endif
5355

5456
#if defined(__arm__) && defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 6010050)
5557
/* Keil uVision4 tools */

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: 19 additions & 84 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,32 +55,23 @@
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

82-
#undef LWIP_DEBUG
83-
#if MBED_CONF_LWIP_DEBUG_ENABLED
84-
#define LWIP_DEBUG 1
85-
#endif
74+
#define LWIP_DEBUG MBED_CONF_LWIP_DEBUG_ENABLED
8675

8776
#if NO_SYS == 0
8877
#include "cmsis_os2.h"
@@ -102,11 +91,6 @@
10291
// Thread stacks use 8-byte alignment
10392
#define LWIP_ALIGN_UP(pos, align) ((pos) % (align) ? (pos) + ((align) - (pos) % (align)) : (pos))
10493

105-
// Thread stack size for lwip tcpip thread
106-
#ifndef MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE
107-
#define MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE 1200
108-
#endif
109-
11094
#ifdef LWIP_DEBUG
11195
// For LWIP debug, double the stack
11296
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE*2, 8)
@@ -120,11 +104,6 @@
120104
// Thread priority (osPriorityNormal by default)
121105
#define TCPIP_THREAD_PRIO (MBED_CONF_LWIP_TCPIP_THREAD_PRIORITY)
122106

123-
// Thread stack size for lwip system threads
124-
#ifndef MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE
125-
#define MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE 512
126-
#endif
127-
128107
#ifdef LWIP_DEBUG
129108
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE*2, 8)
130109
#else
@@ -143,43 +122,24 @@
143122
#define LWIP_RAM_HEAP_POINTER lwip_ram_heap
144123

145124
// Number of simultaneously queued TCP segments.
146-
#ifdef MBED_CONF_LWIP_MEMP_NUM_TCP_SEG
147125
#define MEMP_NUM_TCP_SEG MBED_CONF_LWIP_MEMP_NUM_TCP_SEG
148-
#endif
149126

150127
// TCP Maximum segment size.
151-
#ifdef MBED_CONF_LWIP_TCP_MSS
152128
#define TCP_MSS MBED_CONF_LWIP_TCP_MSS
153-
#endif
154129

155130
// TCP sender buffer space (bytes).
156-
#ifdef MBED_CONF_LWIP_TCP_SND_BUF
157131
#define TCP_SND_BUF MBED_CONF_LWIP_TCP_SND_BUF
158-
#endif
159132

160133
// TCP sender buffer space (bytes).
161-
#ifdef MBED_CONF_LWIP_TCP_WND
162134
#define TCP_WND MBED_CONF_LWIP_TCP_WND
163-
#endif
164135

165-
#ifdef MBED_CONF_LWIP_TCP_MAXRTX
166136
#define TCP_MAXRTX MBED_CONF_LWIP_TCP_MAXRTX
167-
#endif
168137

169-
#ifdef MBED_CONF_LWIP_TCP_SYNMAXRTX
170138
#define TCP_SYNMAXRTX MBED_CONF_LWIP_TCP_SYNMAXRTX
171-
#endif
172139

173140
// Number of pool pbufs.
174141
// Each requires 684 bytes of RAM (if MSS=536 and PBUF_POOL_BUFSIZE defaulting to be based on MSS)
175-
#ifdef MBED_CONF_LWIP_PBUF_POOL_SIZE
176-
#undef PBUF_POOL_SIZE
177142
#define PBUF_POOL_SIZE MBED_CONF_LWIP_PBUF_POOL_SIZE
178-
#else
179-
#ifndef PBUF_POOL_SIZE
180-
#define PBUF_POOL_SIZE 5
181-
#endif
182-
#endif
183143

184144
#ifdef MBED_CONF_LWIP_PBUF_POOL_BUFSIZE
185145
#undef PBUF_POOL_BUFSIZE
@@ -194,63 +154,38 @@
194154
#endif
195155
#endif
196156

197-
#ifdef MBED_CONF_LWIP_MEM_SIZE
198-
#undef MEM_SIZE
199157
#define MEM_SIZE MBED_CONF_LWIP_MEM_SIZE
200-
#endif
201158

202159
// One tcp_pcb_listen is needed for each TCPServer.
203160
// Each requires 72 bytes of RAM.
204-
#ifdef MBED_CONF_LWIP_TCP_SERVER_MAX
205161
#define MEMP_NUM_TCP_PCB_LISTEN MBED_CONF_LWIP_TCP_SERVER_MAX
206-
#else
207-
#define MEMP_NUM_TCP_PCB_LISTEN 4
208-
#endif
209162

210163
// One is tcp_pcb needed for each TCPSocket.
211164
// Each requires 196 bytes of RAM.
212-
#ifdef MBED_CONF_LWIP_TCP_SOCKET_MAX
213165
#define MEMP_NUM_TCP_PCB MBED_CONF_LWIP_TCP_SOCKET_MAX
214-
#else
215-
#define MEMP_NUM_TCP_PCB 4
216-
#endif
217166

218167
// One udp_pcb is needed for each UDPSocket.
219168
// Each requires 84 bytes of RAM (total rounded to multiple of 512).
220-
#ifdef MBED_CONF_LWIP_UDP_SOCKET_MAX
221169
#define MEMP_NUM_UDP_PCB MBED_CONF_LWIP_UDP_SOCKET_MAX
222-
#else
223-
#define MEMP_NUM_UDP_PCB 4
224-
#endif
225170

226171
// Number of non-pool pbufs.
227172
// Each requires 92 bytes of RAM.
228-
#ifndef MEMP_NUM_PBUF
229-
#define MEMP_NUM_PBUF 8
230-
#endif
173+
#define MEMP_NUM_PBUF MBED_CONF_LWIP_NUM_PBUF
231174

232175
// Each netbuf requires 64 bytes of RAM.
233-
#ifndef MEMP_NUM_NETBUF
234-
#define MEMP_NUM_NETBUF 8
235-
#endif
176+
#define MEMP_NUM_NETBUF MBED_CONF_LWIP_NUM_NETBUF
236177

237178
// One netconn is needed for each UDPSocket, TCPSocket or TCPServer.
238179
// Each requires 236 bytes of RAM (total rounded to multiple of 512).
239-
#ifdef MBED_CONF_LWIP_SOCKET_MAX
240180
#define MEMP_NUM_NETCONN MBED_CONF_LWIP_SOCKET_MAX
241-
#else
242-
#define MEMP_NUM_NETCONN 4
243-
#endif
244181

245182
#if MBED_CONF_LWIP_TCP_ENABLED
246183
#define LWIP_TCP 1
247184
#define TCP_OVERSIZE 0
248185
#define LWIP_TCP_KEEPALIVE 1
249-
#ifdef MBED_CONF_TCP_CLOSE_TIMEOUT
250-
#define TCP_CLOSE_TIMEOUT MBED_CONF_TCP_CLOSE_TIMEOUT
251-
#else
252-
#define TCP_CLOSE_TIMEOUT 1000
253-
#endif
186+
187+
#define TCP_CLOSE_TIMEOUT MBED_CONF_LWIP_TCP_CLOSE_TIMEOUT
188+
254189
#else
255190
#define LWIP_TCP 0
256191
#endif

features/lwipstack/mbed_lib.json

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
"help": "Address timeout mode; true: wait both stack's addresses; false: wait for preferred stack's address",
2222
"value": true
2323
},
24+
"dhcp-timeout": {
25+
"help": "DHCP timeout value",
26+
"value": 60
27+
},
2428
"ethernet-enabled": {
2529
"help": "Enable support for Ethernet interfaces",
2630
"value": true
@@ -74,28 +78,28 @@
7478
"value": 4
7579
},
7680
"memp-num-tcp-seg": {
77-
"help": "Number of simultaneously queued TCP segments. Current default (used if null here) is set to 16 in opt.h, unless overridden by target Ethernet drivers.",
78-
"value": null
81+
"help": "Number of simultaneously queued TCP segments, see LWIP opt.h for more information. Current default is 16.",
82+
"value": 16
7983
},
8084
"tcp-mss": {
81-
"help": "TCP Maximum segment size. Current default (used if null here) is set to 536 in opt.h, unless overridden by target Ethernet drivers.",
82-
"value": null
85+
"help": "TCP Maximum segment size, see LWIP opt.h for more information. Current default is 536.",
86+
"value": 536
8387
},
8488
"tcp-snd-buf": {
85-
"help": "TCP sender buffer space (bytes). Current default (used if null here) is set to (2 * TCP_MSS) in opt.h, unless overridden by target Ethernet drivers.",
86-
"value": null
89+
"help": "TCP sender buffer space (bytes), see LWIP's opt.h for more information. Current default is (2 * TCP_MSS).",
90+
"value": "(2 * TCP_MSS)"
8791
},
8892
"tcp-wnd": {
89-
"help": "TCP sender buffer space (bytes). Current default (used if null here) is set to (4 * TCP_MSS) in opt.h, unless overridden by target Ethernet drivers.",
90-
"value": null
93+
"help": "TCP sender buffer space (bytes), see LWIP's opt.h for more information. Current default is (4 * TCP_MSS).",
94+
"value": "(4 * TCP_MSS)"
9195
},
9296
"tcp-maxrtx": {
93-
"help": "Maximum number of retransmissions of data segments.",
97+
"help": "Maximum number of retransmissions of data segments, see LWIP's opt.h for more information. Current default is 6.",
9498
"value": 6
9599
},
96100
"tcp-synmaxrtx": {
97-
"help": "Maximum number of retransmissions of SYN segments. Current default (used if null here) is set to 6 in opt.h",
98-
"value": null
101+
"help": "Maximum number of retransmissions of SYN segments, see LWIP's opt.h for more information. Current default is 6.",
102+
"value": 6
99103
},
100104
"tcp-close-timeout": {
101105
"help": "Maximum timeout (ms) for TCP close handshaking timeout",
@@ -106,16 +110,16 @@
106110
"value": "osPriorityNormal"
107111
},
108112
"pbuf-pool-size": {
109-
"help": "Number of pbufs in pool - usually used for received packets, so this determines how much data can be buffered between reception and the application reading. If a driver uses PBUF_RAM for reception, less pool may be needed. Current default (used if null here) is set to 5 in lwipopts.h, unless overridden by target Ethernet drivers.",
110-
"value": null
113+
"help": "Number of pbufs in pool - usually used for received packets, so this determines how much data can be buffered between reception and the application reading, see LWIP's opt.h for more information. If a driver uses PBUF_RAM for reception, less pool may be needed. Current default is 5.",
114+
"value": 5
111115
},
112116
"pbuf-pool-bufsize": {
113-
"help": "Size of pbufs in pool. If set to null, lwIP will base the size on the TCP MSS, which is 536 unless overridden by the target",
117+
"help": "Size of pbufs in pool, see LWIP's opt.h for more information.",
114118
"value": null
115119
},
116120
"mem-size": {
117-
"help": "Size of heap (bytes) - used for outgoing packets, and also used by some drivers for reception. Current default (used if null here) is set to 1600 in opt.h, unless overridden by target Ethernet drivers.",
118-
"value": null
121+
"help": "Size of heap (bytes) - used for outgoing packets, and also used by some drivers for reception, see LWIP's opt.h for more information. Current default is 1600.",
122+
"value": 1600
119123
},
120124
"tcpip-thread-stacksize": {
121125
"help": "Stack size for lwip TCPIP thread",
@@ -128,6 +132,14 @@
128132
"ppp-thread-stacksize": {
129133
"help": "Thread stack size for PPP (obsolete: use netsocket/ppp configuration instead)",
130134
"value": 768
135+
},
136+
"num-pbuf": {
137+
"help": "Number of non-pool pbufs, each needs 92 bytes of RAM, see LWIP's opt.h for more information. Current default is 8.",
138+
"value": 8
139+
},
140+
"num-netbuf": {
141+
"help": "Number of netbufs, each netbuf requires 64 bytes of RAM, see LWIP's opt.h for more information. Current default is 8.",
142+
"value": 8
131143
}
132144
},
133145
"target_overrides": {

features/netsocket/ppp/include/ppp_opts.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@
7171
#define PPP_DNS 1
7272

7373
// Used as maximum size for output buffer, to restrict the memory manager get_pool_alloc_unit()
74+
#ifndef PBUF_POOL_BUFSIZE
7475
#define PBUF_POOL_BUFSIZE 536 + 40
76+
#endif
7577

7678
#endif // PPP_SUPPORT
7779

0 commit comments

Comments
 (0)