Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
lwipopts.h
Go to the documentation of this file.
1
9#include "stdint.h"
10
11extern void sntp_set_system_time(uint32_t sec);
12
13#ifndef LWIPOPTS_H
14#define LWIPOPTS_H
15
16// -----------------------------------------------------------------------------
17// System and Core Configuration
18// -----------------------------------------------------------------------------
19#define NO_SYS 0 // 0: use operating system (FreeRTOS)
20#define LWIP_TIMERS 1 // Enable lwIP timer support
21#define SYS_LIGHTWEIGHT_PROT 1 // Enable lightweight protection for critical regions
22
23// -----------------------------------------------------------------------------
24// Memory Management
25// -----------------------------------------------------------------------------
26
27#define MEM_LIBC_MALLOC 0 // Do not use libc malloc
28#define MEMP_MEM_MALLOC 0 // Use static memory pools rather than malloc for internal allocations
29#define MEM_ALIGNMENT 4 // Align memory to 4-byte boundaries
30#ifdef PICO_RP2350
31#define MEM_SIZE (16 * 1024) // Total heap size available to lwIP (4 KB); prevents silent issues at lower sizes
32#else
33#define MEM_SIZE (10 * 1024) // Total heap size available to lwIP (16 KB); prevents silent issues at lower sizes [may be able to lower]
34#endif
35#define MEMP_NUM_NETCONN 32 // Maximum number of simultaneously active netconns (was 32)
36#define MEMP_NUM_TCP_PCB 16 // Maximum number of concurrently active TCP protocol control blocks
37#define MEMP_NUM_TCP_PCB_LISTEN 8 // Maximum number of listening TCP PCBs
38#define MEMP_NUM_TCP_SEG 32 // Maximum number of simultaneously queued TCP segments
39#define MEMP_NUM_ARP_QUEUE 10 // Maximum number of ARP request queue entries
40#define MEMP_NUM_NETBUF 16 // Maximum number of network buffers
41#define MEMP_NUM_SYS_TIMEOUT 16 // Maximum number of active timeouts (old value; increased from 10)
42#define NUM_MEMP_PBUF 16 // Number of pbuf structures in the pool
43
44// #define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1 // Allow freeing memory allocated in different contexts
45
46// -----------------------------------------------------------------------------
47// PBUF Buffer Settings
48// -----------------------------------------------------------------------------
49#define PBUF_POOL_SIZE 24 // Total number of pbufs in the pool
50#define PBUF_POOL_BUFSIZE 1460 // Size (in bytes) of each pbuf in the pool - sane as TCP_MSS
51
52#define ETH_PAD_SIZE 0 // Extra padding added to ethernet frames (0 means no extra pad)
53
54// -----------------------------------------------------------------------------
55// TCP Configuration
56// -----------------------------------------------------------------------------
57#define LWIP_TCP 1 // Enable TCP support
58#define LWIP_IPV4 1 // Enable IPv4 support
59#define TCP_TTL 255 // Set default Time-To-Live for TCP packets (max hops)
60#define TCP_QUEUE_OOSEQ 0 // Disable queuing of out-of-order TCP segments
61#define TCP_MSS 1460 // Maximum segment size (bytes)
62#define TCP_SND_BUF (8 * TCP_MSS) // Size of TCP sender buffer (bytes) - may be able to lower
63// #define TCP_WND (PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZE - 60))
64#define TCP_WND (8 * TCP_MSS) // Size of TCP receive window (bytes) - may be able to lower
65#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / TCP_MSS) // Calculate send queue length
66#define TCP_SND_QUEUELEN 32 // Calculate send queue length
67#define TCP_LISTEN_BACKLOG 1 // Enable support for backlog on TCP listen
68#define TCP_MSL 1000 // Maximum Segment Lifetime (ms) [reduces TIME_WAIT duration]
69#define TCP_SYNMAXRTX 3 // Maximum retransmissions for SYN segments
70
71// TCP Keepalive settings:
72#define LWIP_TCP_KEEPALIVE 1 // Enable TCP keepalive functionality
73#define TCP_KEEPIDLE_DEFAULT 10000 // Time (ms) before sending keepalive probes
74#define TCP_KEEPINTVL_DEFAULT 1000 // Interval (ms) between individual keepalive probes (was 2000)
75#define TCP_KEEPCNT_DEFAULT 3 // Maximum number of keepalive probes before closing the connection (was 5)
76
77// TCP additional features:
78#define LWIP_TCP_ABORT 1 // Enable immediate TCP abort to drop connections quickly
79#define LWIP_TCP_FASTOPEN 1 // Enable TCP Fast Open feature
80
81// -----------------------------------------------------------------------------
82// UDP Configuration
83// -----------------------------------------------------------------------------
84#define LWIP_UDP 1 // Enable UDP support - needed for NTP time sync
85#define UDP_TTL 255 // Default Time-To-Live for UDP packets
86
87// -----------------------------------------------------------------------------
88// ICMP / DNS / DHCP / AUTOIP / SNTP
89// -----------------------------------------------------------------------------
90#define LWIP_ICMP 1 // Enable ICMP (e.g., ping)
91#define LWIP_DNS 1 // Enable DNS resolution
92#define DNS_TABLE_SIZE 4 // Maximum DNS table entries
93#define DNS_MAX_NAME_LENGTH 256 // Maximum domain name length for DNS
94#define DNS_MAX_SERVERS 2 // Maximum number of DNS servers
95#define LWIP_DHCP 1 // Enable DHCP client support
96#define LWIP_AUTOIP 0 // Disable AutoIP (self-assigned IP addressing)
97#define LWIP_SNTP 1 // Enable SNTP (Simple Network Time Protocol)
98#define SNTP_SUPPORT 1 // Enable SNTP support
99#define SNTP_CHECK_RESPONSE 1 // Enable SNTP response checking
100#define SNTP_RETRY_TIMEOUT 5000 // Retry timeout for SNTP requests (in ms)
101#define SNTP_SERVER_ADDRESS "pool.ntp.org" // Default NTP server address
102#define SNTP_SERVER_PORT 123 // Default NTP server port
103#define SNTP_SERVER_DNS 1 // Enable DNS server for SNTP
104#define SNTP_MAX_SERVERS 1 // Maximum number of SNTP servers
105#define SNTP_SET_SYSTEM_TIME 1 // Enable setting system time from SNTP
106#define SNTP_UPDATE_DELAY 60*60*1000 // Delay (in ms) between SNTP updates - this will set the imer once an hour
107// Set system time from SNTP
108#define SNTP_SET_SYSTEM_TIME(sec) sntp_set_system_time(sec)
109
110// -----------------------------------------------------------------------------
111// Protocols and Raw API
112// -----------------------------------------------------------------------------
113#define LWIP_RAW 1 // Enable the RAW API for low-level protocol access
114#define LWIP_NETCONN 1 // Used by sockets and netconn API
115#define LWIP_SOCKET 1 // Enable socket API support
116#define LWIP_COMPAT_SOCKETS 0 // Use POSIX-like sockets instead of native lwIP sockets
117
118// -----------------------------------------------------------------------------
119// Threading / OS Integration
120// -----------------------------------------------------------------------------
121#define LWIP_NETCONN_SEM_PER_THREAD 0 // Each thread gets its own netconn semaphore - only if using a single socket from multiple threads
122#define LWIP_SO_RCVTIMEO 1 // Enable support for socket receive timeouts
123#define LWIP_TCPIP_CORE_LOCKING 1 // Enable core locking for thread safety
124#define LWIP_TCPIP_CORE_LOCKING_INPUT 1 // Enable core locking for input processing
125#define TCPIP_THREAD_NAME "tcpip_thread" // Name assigned to the TCP/IP thread
126#define TCPIP_THREAD_STACKSIZE 2048 // Stack size (in bytes) for the TCP/IP thread
127#define TCPIP_THREAD_PRIO 8 // Priority for the TCP/IP thread
128#define TCPIP_MBOX_SIZE 8 // Mailbox size for the TCP/IP thread message queue
129#define DEFAULT_THREAD_STACKSIZE 2048 // Default stack size for lwIP-related threads
130#define DEFAULT_UDP_RECVMBOX_SIZE 8 // Default mailbox size for UDP receive (old value)
131#define DEFAULT_TCP_RECVMBOX_SIZE 8 // Default mailbox size for TCP receive
132#define DEFAULT_ACCEPTMBOX_SIZE 8 // Default mailbox size for accepted connections
133#define DEFAULT_RAW_RECVMBOX_SIZE 8 // Default mailbox size for raw receive (from old settings)
134#define LWIP_TIMEVAL_PRIVATE 0 // Use the standard system timeval structure
135
136// -----------------------------------------------------------------------------
137// ALTCP / Secure Sockets / TLS Support
138// -----------------------------------------------------------------------------
139#ifdef PICO_TCP_ENABLE_TLS
140#define LWIP_ALTCP 1 // Enable the ALTCP abstraction layer
141#define LWIP_ALTCP_TLS 1 // Enable TLS support for ALTCP
142#define LWIP_ALTCP_TLS_MBEDTLS 1 // Enable mbedTLS support for ALTCP
143#else
144#define LWIP_ALTCP 0
145#define LWIP_ALTCP_TLS 0
146#define LWIP_ALTCP_TLS_MBEDTLS 0
147#endif
148
149// -----------------------------------------------------------------------------
150// Interface / Ethernet / Link Layer
151// -----------------------------------------------------------------------------
152#define LWIP_ARP 1 // Enable ARP (Address Resolution Protocol)
153#define LWIP_ETHERNET 1 // Enable Ethernet support
154#define LWIP_NETIF_HOSTNAME 1 // Allow network interfaces to have hostnames
155#define LWIP_NETIF_STATUS_CALLBACK 1 // Enable callbacks on network interface status changes
156#define LWIP_NETIF_LINK_CALLBACK 1 // Enable callbacks on network link state changes
157#define LWIP_NETIF_EXT_STATUS_CALLBACK 1 // Enable extended status callbacks for network interfaces
158#define DHCP_DOES_ARP_CHECK 0 // Disable ARP check for DHCP responses
159#define LWIP_DHCP_DOES_ACD_CHECK 0 // Disable Address Conflict Detection (ACD) for DHCP
160#define LWIP_NETIF_TX_SINGLE_PBUF 1 // Transmit a single pbuf per packet (improves performance)
161#define ETHARP_TABLE_SIZE 127 // Set the size of the ARP table
162
163// -----------------------------------------------------------------------------
164// Checksum and CRCs
165// -----------------------------------------------------------------------------
166#define CHECKSUM_GEN_IP 1 // Generate checksums for outgoing IP packets
167#define CHECKSUM_GEN_UDP 1 // Generate checksums for outgoing UDP packets
168#define CHECKSUM_GEN_TCP 1 // Generate checksums for outgoing TCP packets
169#define CHECKSUM_CHECK_IP 1 // Validate checksums on incoming IP packets
170#define CHECKSUM_CHECK_UDP 1 // Validate checksums on incoming UDP packets
171#define CHECKSUM_CHECK_TCP 1 // Validate checksums on incoming TCP packets
172#define LWIP_CHKSUM_ALGORITHM 3 // Select the checksum algorithm (3 = optimized algorithm)
173
174// -----------------------------------------------------------------------------
175// Statistics and Debugging
176// -----------------------------------------------------------------------------
177#define LWIP_STATS 1 // Enable collection of lwIP statistics
178#define LWIP_STATS_DISPLAY 1 // Enable display routines for statistics
179#define LWIP_PERF 0 // Disable performance testing macros
180
181// -----------------------------------------------------------------------------
182// Debugging (Individual modules only - LWIP_DEBUG must remain undefined!)
183// See https://savannah.nongnu.org/bugs/index.php?62159
184// -----------------------------------------------------------------------------
185#define LWIP_DEBUG 1 // Globally disable debug output to avoid savannah bug (fix applied)
186//#undef LWIP_DEBUG // Ensure the global debug macro is undefined
187#ifndef NDEBUG
188// Enable detailed debug flags only if not in release mode and global debug is off (workaround for savannah bug)
189#ifndef LWIP_DEBUG
190#define ETHARP_DEBUG LWIP_DBG_OFF
191#define NETIF_DEBUG LWIP_DBG_OFF
192#define PBUF_DEBUG LWIP_DBG_OFF
193#define API_LIB_DEBUG LWIP_DBG_OFF
194#define API_MSG_DEBUG LWIP_DBG_OFF
195#define SOCKETS_DEBUG LWIP_DBG_OFF
196#define ICMP_DEBUG LWIP_DBG_OFF
197#define INET_DEBUG LWIP_DBG_OFF
198#define IP_DEBUG LWIP_DBG_OFF
199#define IP_REASS_DEBUG LWIP_DBG_OFF
200#define RAW_DEBUG LWIP_DBG_OFF
201#define MEM_DEBUG LWIP_DBG_OFF
202#define MEMP_DEBUG LWIP_DBG_OFF
203#define SYS_DEBUG LWIP_DBG_OFF
204#define TCP_DEBUG LWIP_DBG_OFF
205#define TCP_INPUT_DEBUG LWIP_DBG_OFF
206#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
207#define TCP_RTO_DEBUG LWIP_DBG_OFF
208#define TCP_CWND_DEBUG LWIP_DBG_OFF
209#define TCP_WND_DEBUG LWIP_DBG_OFF
210#define TCP_FR_DEBUG LWIP_DBG_OFF
211#define TCP_QLEN_DEBUG LWIP_DBG_OFF
212#define TCP_RST_DEBUG LWIP_DBG_OFF
213#define UDP_DEBUG LWIP_DBG_OFF
214#define TCPIP_DEBUG LWIP_DBG_OFF
215#define PPP_DEBUG LWIP_DBG_OFF
216#define SLIP_DEBUG LWIP_DBG_OFF
217#define DHCP_DEBUG LWIP_DBG_OFF
218#define SNTP_DEBUG LWIP_DBG_ON
219#endif
220#endif
221#define ALTCP_MBEDTLS_DEBUG LWIP_DBG_OFF // Disable debugging for ALTCP mbedTLS
222
223#endif /* LWIPOPTS_H */
void sntp_set_system_time(uint32_t sec)