Skip to content

Commit 1daf7f1

Browse files
committed
Polling based TCP Client
1 parent e2101a4 commit 1daf7f1

12 files changed

Lines changed: 1278 additions & 3 deletions

File tree

RPi-Pico/CMakeLists.txt

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ target_link_libraries(benchmark
5858
)
5959
pico_add_extra_outputs(benchmark)
6060

61-
if(1)
61+
if(0)
6262
add_executable(TCPclient
6363
src/blink.c
6464
# src/TCPclient.c
@@ -73,7 +73,9 @@ if(1)
7373

7474
# CYW43_NETUTILS
7575
# PICO_CYW43_ARCH_FREERTOS
76-
TEST_TCP_SERVER_IP="192.168.11.28"
76+
TEST_TCP_SERVER_IP=\"${TEST_TCP_SERVER_IP}\"
77+
WIFI_SSID=\"${WIFI_SSID}\"
78+
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
7779
PICO_CYW43_ARCH_POLL
7880
NO_SYS=1
7981
@@ -107,4 +109,62 @@ if(1)
107109
)
108110
109111
pico_add_extra_outputs(TCPclient)
110-
endif()
112+
endif()
113+
114+
add_executable(Wifi
115+
src/blink.c
116+
src/wifi.c
117+
src/Wifi_main.c
118+
)
119+
120+
# enable usb output, disable uart output
121+
pico_enable_stdio_usb(Wifi 1)
122+
pico_enable_stdio_uart(Wifi 0)
123+
124+
target_compile_definitions(Wifi PRIVATE
125+
WIFI_SSID=\"${WIFI_SSID}\"
126+
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
127+
PICO_CYW43_ARCH_POLL
128+
NO_SYS=1
129+
)
130+
131+
target_link_libraries(Wifi
132+
pico_stdlib
133+
pico_rand
134+
pico_lwip
135+
pico_cyw43_arch
136+
pico_lwip_nosys
137+
pico_async_context_poll
138+
)
139+
140+
pico_add_extra_outputs(Wifi)
141+
142+
add_executable(tcp_Client
143+
src/blink.c
144+
src/wifi.c
145+
src/tcp.c
146+
src/tcpClient_main.c
147+
)
148+
149+
# enable usb output, disable uart output
150+
pico_enable_stdio_usb(tcp_Client 1)
151+
pico_enable_stdio_uart(tcp_Client 0)
152+
153+
target_compile_definitions(tcp_Client PRIVATE
154+
WIFI_SSID=\"${WIFI_SSID}\"
155+
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
156+
TEST_TCP_SERVER_IP=\"${TEST_TCP_SERVER_IP}\"
157+
PICO_CYW43_ARCH_POLL
158+
NO_SYS=1
159+
)
160+
161+
target_link_libraries(tcp_Client
162+
pico_stdlib
163+
pico_rand
164+
pico_lwip
165+
pico_cyw43_arch
166+
pico_lwip_nosys
167+
pico_async_context_poll
168+
)
169+
170+
pico_add_extra_outputs(tcp_Client)

RPi-Pico/config/lwipopts.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef _LWIPOPTS_H
2+
#define _LWIPOPTS_H
3+
4+
// Generally you would define your own explicit list of lwIP options
5+
// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html)
6+
//
7+
// This example uses a common include to avoid repetition
8+
#include "lwipopts_examples_common.h"
9+
10+
#if !NO_SYS
11+
#define TCPIP_THREAD_STACKSIZE 1024
12+
#define DEFAULT_THREAD_STACKSIZE 1024
13+
#define DEFAULT_RAW_RECVMBOX_SIZE 8
14+
#define TCPIP_MBOX_SIZE 8
15+
#define LWIP_TIMEVAL_PRIVATE 0
16+
17+
// not necessary, can be done either way
18+
#define LWIP_TCPIP_CORE_LOCKING_INPUT 1
19+
20+
// ping_thread sets socket receive timeout, so enable this feature
21+
#define LWIP_SO_RCVTIMEO 1
22+
23+
#endif
24+
25+
26+
#define LWIP_TIMEVAL_PRIVATE 0
27+
#define LWIP_MPU_COMPATIBLE 0
28+
#define LWIP_PROVIDE_ERRNO
29+
#define LWIP_FREERTOS_SYS_ARCH_PROTECT_USES_MUTEX 1
30+
31+
#endif
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#ifndef _LWIPOPTS_EXAMPLE_COMMONH_H
2+
#define _LWIPOPTS_EXAMPLE_COMMONH_H
3+
4+
// Common settings used in most of the pico_w examples
5+
// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details)
6+
7+
// allow override in some examples
8+
#ifndef NO_SYS
9+
#define NO_SYS 0
10+
#endif
11+
// allow override in some examples
12+
#ifndef LWIP_SOCKET
13+
#define LWIP_SOCKET 0
14+
#endif
15+
#if PICO_CYW43_ARCH_POLL
16+
#define MEM_LIBC_MALLOC 1
17+
#else
18+
// MEM_LIBC_MALLOC is incompatible with non polling versions
19+
#define MEM_LIBC_MALLOC 0
20+
#endif
21+
#define MEM_ALIGNMENT 4
22+
#define MEM_SIZE 4000
23+
#define MEMP_NUM_TCP_SEG 32
24+
#define MEMP_NUM_ARP_QUEUE 10
25+
#define PBUF_POOL_SIZE 24
26+
#define LWIP_ARP 1
27+
#define LWIP_ETHERNET 1
28+
#define LWIP_ICMP 1
29+
#define LWIP_RAW 1
30+
#define TCP_WND (8 * TCP_MSS)
31+
#define TCP_MSS 1460
32+
#define TCP_SND_BUF (8 * TCP_MSS)
33+
#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS))
34+
#define LWIP_NETIF_STATUS_CALLBACK 1
35+
#define LWIP_NETIF_LINK_CALLBACK 1
36+
#define LWIP_NETIF_HOSTNAME 1
37+
#define LWIP_NETCONN 0
38+
#define MEM_STATS 0
39+
#define SYS_STATS 0
40+
#define MEMP_STATS 0
41+
#define LINK_STATS 0
42+
// #define ETH_PAD_SIZE 2
43+
#define LWIP_CHKSUM_ALGORITHM 3
44+
#define LWIP_DHCP 1
45+
#define LWIP_IPV4 1
46+
#define LWIP_TCP 1
47+
#define LWIP_UDP 1
48+
#define LWIP_DNS 1
49+
#define LWIP_TCP_KEEPALIVE 1
50+
#define LWIP_NETIF_TX_SINGLE_PBUF 1
51+
#define DHCP_DOES_ARP_CHECK 0
52+
#define LWIP_DHCP_DOES_ACD_CHECK 0
53+
54+
#ifndef NDEBUG
55+
#define LWIP_DEBUG 1
56+
#define LWIP_STATS 1
57+
#define LWIP_STATS_DISPLAY 1
58+
#endif
59+
60+
#define ETHARP_DEBUG LWIP_DBG_OFF
61+
#define NETIF_DEBUG LWIP_DBG_OFF
62+
#define PBUF_DEBUG LWIP_DBG_OFF
63+
#define API_LIB_DEBUG LWIP_DBG_OFF
64+
#define API_MSG_DEBUG LWIP_DBG_OFF
65+
#define SOCKETS_DEBUG LWIP_DBG_OFF
66+
#define ICMP_DEBUG LWIP_DBG_OFF
67+
#define INET_DEBUG LWIP_DBG_OFF
68+
#define IP_DEBUG LWIP_DBG_OFF
69+
#define IP_REASS_DEBUG LWIP_DBG_OFF
70+
#define RAW_DEBUG LWIP_DBG_OFF
71+
#define MEM_DEBUG LWIP_DBG_OFF
72+
#define MEMP_DEBUG LWIP_DBG_OFF
73+
#define SYS_DEBUG LWIP_DBG_OFF
74+
#define TCP_DEBUG LWIP_DBG_OFF
75+
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
76+
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
77+
#define TCP_RTO_DEBUG LWIP_DBG_OFF
78+
#define TCP_CWND_DEBUG LWIP_DBG_OFF
79+
#define TCP_WND_DEBUG LWIP_DBG_OFF
80+
#define TCP_FR_DEBUG LWIP_DBG_OFF
81+
#define TCP_QLEN_DEBUG LWIP_DBG_OFF
82+
#define TCP_RST_DEBUG LWIP_DBG_OFF
83+
#define UDP_DEBUG LWIP_DBG_OFF
84+
#define TCPIP_DEBUG LWIP_DBG_OFF
85+
#define PPP_DEBUG LWIP_DBG_OFF
86+
#define SLIP_DEBUG LWIP_DBG_OFF
87+
#define DHCP_DEBUG LWIP_DBG_OFF
88+
89+
#endif /* __LWIPOPTS_H__ */

0 commit comments

Comments
 (0)