aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios/os/various/lwip_bindings/lwipthread.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios/os/various/lwip_bindings/lwipthread.h')
-rw-r--r--lib/chibios/os/various/lwip_bindings/lwipthread.h275
1 files changed, 275 insertions, 0 deletions
diff --git a/lib/chibios/os/various/lwip_bindings/lwipthread.h b/lib/chibios/os/various/lwip_bindings/lwipthread.h
new file mode 100644
index 000000000..d3f991637
--- /dev/null
+++ b/lib/chibios/os/various/lwip_bindings/lwipthread.h
@@ -0,0 +1,275 @@
1/*
2 ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/**
18 * @file lwipthread.h
19 * @brief LWIP wrapper thread macros and structures.
20 * @addtogroup LWIP_THREAD
21 * @{
22 */
23
24#ifndef LWIPTHREAD_H
25#define LWIPTHREAD_H
26
27#include <lwip/opt.h>
28
29/**
30 * @brief lwIP default network interface maximum transmission unit (MTU).
31 */
32#if !defined(LWIP_NETIF_MTU) || defined(__DOXYGEN__)
33#define LWIP_NETIF_MTU 1500
34#endif
35
36/**
37 * @brief Default network interface hostname.
38 */
39#if !defined(LWIP_NETIF_HOSTNAME_STRING) || defined(__DOXYGEN__)
40#define LWIP_NETIF_HOSTNAME_STRING "lwip"
41#endif
42
43/**
44 * @brief Default network interface hostname.
45 */
46#if !defined(LWIP_THREAD_NAME) || defined(__DOXYGEN__)
47#define LWIP_THREAD_NAME "lwipthread"
48#endif
49
50/**
51 * @brief lwIP thread priority.
52 */
53#ifndef LWIP_THREAD_PRIORITY
54#define LWIP_THREAD_PRIORITY LOWPRIO
55#endif
56
57/**
58 * @brief lwIP thread stack size.
59 */
60#if !defined(LWIP_THREAD_STACK_SIZE) || defined(__DOXYGEN__)
61#define LWIP_THREAD_STACK_SIZE 672
62#endif
63
64/**
65 * @brief Link poll interval.
66 */
67#if !defined(LWIP_LINK_POLL_INTERVAL) || defined(__DOXYGEN__)
68#define LWIP_LINK_POLL_INTERVAL TIME_S2I(5)
69#endif
70
71/**
72 * @brief IP Address.
73 */
74#if !defined(LWIP_IPADDR) || defined(__DOXYGEN__)
75#define LWIP_IPADDR(p) IP4_ADDR(p, 192, 168, 1, 10)
76#endif
77
78/**
79 * @brief IP Gateway.
80 */
81#if !defined(LWIP_GATEWAY) || defined(__DOXYGEN__)
82#define LWIP_GATEWAY(p) IP4_ADDR(p, 192, 168, 1, 1)
83#endif
84
85/**
86 * @brief IP netmask.
87 */
88#if !defined(LWIP_NETMASK) || defined(__DOXYGEN__)
89#define LWIP_NETMASK(p) IP4_ADDR(p, 255, 255, 255, 0)
90#endif
91
92/**
93 * @brief Transmission timeout.
94 */
95#if !defined(LWIP_SEND_TIMEOUT) || defined(__DOXYGEN__)
96#define LWIP_SEND_TIMEOUT 50
97#endif
98
99/**
100 * @brief Link speed.
101 */
102#if !defined(LWIP_LINK_SPEED) || defined(__DOXYGEN__)
103#define LWIP_LINK_SPEED 100000000
104#endif
105
106/**
107 * @brief MAC Address byte 0.
108 */
109#if !defined(LWIP_ETHADDR_0) || defined(__DOXYGEN__)
110#define LWIP_ETHADDR_0 0xC2
111#endif
112
113/**
114 * @brief MAC Address byte 1.
115 */
116#if !defined(LWIP_ETHADDR_1) || defined(__DOXYGEN__)
117#define LWIP_ETHADDR_1 0xAF
118#endif
119
120/**
121 * @brief MAC Address byte 2.
122 */
123#if !defined(LWIP_ETHADDR_2) || defined(__DOXYGEN__)
124#define LWIP_ETHADDR_2 0x51
125#endif
126
127/**
128 * @brief MAC Address byte 3.
129 */
130#if !defined(LWIP_ETHADDR_3) || defined(__DOXYGEN__)
131#define LWIP_ETHADDR_3 0x03
132#endif
133
134/**
135 * @brief MAC Address byte 4.
136 */
137#if !defined(LWIP_ETHADDR_4) || defined(__DOXYGEN__)
138#define LWIP_ETHADDR_4 0xCF
139#endif
140
141/**
142 * @brief MAC Address byte 5.
143 */
144#if !defined(LWIP_ETHADDR_5) || defined(__DOXYGEN__)
145#define LWIP_ETHADDR_5 0x46
146#endif
147
148/**
149 * @brief Interface name byte 0.
150 */
151#if !defined(LWIP_IFNAME0) || defined(__DOXYGEN__)
152#define LWIP_IFNAME0 'm'
153#endif
154
155/**
156 * @brief Interface name byte 1.
157 */
158#if !defined(LWIP_IFNAME1) || defined(__DOXYGEN__)
159#define LWIP_IFNAME1 's'
160#endif
161
162/**
163 * @brief Utility macro to define an IPv4 address.
164 *
165 * @note Within the networking subsystem, IPv4 network addresses are
166 * stored with LS byte of network address in MS byte of unsigned int.
167 */
168#if BYTE_ORDER == LITTLE_ENDIAN
169#define IP4_ADDR_VALUE(a,b,c,d) \
170 (((u32_t)((d) & 0xff) << 24) | \
171 ((u32_t)((c) & 0xff) << 16) | \
172 ((u32_t)((b) & 0xff) << 8) | \
173 (u32_t)((a) & 0xff))
174#else
175#define IP4_ADDR_VALUE(a,b,c,d) \
176 (((u32_t)((a) & 0xff) << 24) | \
177 ((u32_t)((b) & 0xff) << 16) | \
178 ((u32_t)((c) & 0xff) << 8) | \
179 (u32_t)((d) & 0xff))
180#endif
181
182/**
183 * @brief Startup network assigning modes.
184 */
185typedef enum {
186#if LWIP_DHCP || defined(__DOXYGEN__)
187 /**
188 * @brief Assign a DHCP given address.
189 */
190 NET_ADDRESS_DHCP = 1,
191#endif
192 /**
193 * @brief Assign a statically IPv4 address.
194 */
195 NET_ADDRESS_STATIC = 2,
196#if LWIP_AUTOIP || defined(__DOXYGEN__)
197 /**
198 * @brief Assign an IPv4 link-Local address.
199 */
200 NET_ADDRESS_AUTO = 3
201#endif
202} net_addr_mode_t;
203
204/**
205 * @brief Runtime TCP/IP settings.
206 */
207typedef struct lwipthread_opts {
208 /**
209 * @brief Pointer to MAC address as an array of 6 unsigned bytes.
210 */
211 uint8_t *macaddress;
212 /**
213 * @brief Network address as 32-bit unsigned integer.
214 */
215 uint32_t address;
216 /**
217 * @brief Network subnet mask as 32-bit unsigned integer.
218 */
219 uint32_t netmask;
220 /**
221 * @brief Network gateway as 32-bit unsigned integer.
222 */
223 uint32_t gateway;
224 /**
225 * @brief Startup network addressing mode - static, DHCP, auto.
226 */
227 net_addr_mode_t addrMode;
228 /**
229 * @brief Host name. If NULL, a default string is used.
230 * @note Not checked for validity. In particular, spaces not allowed.
231 */
232#if LWIP_NETIF_HOSTNAME || defined(__DOXYGEN__)
233 const char *ourHostName;
234#endif
235 /**
236 * @brief Link up callback.
237 *
238 * @note Called from the tcpip thread when the link goes up.
239 * Can be NULL to default to lwipDefaultLinkUpCB.
240 */
241 void (*link_up_cb)(void*);
242 /**
243 * @brief Link down callback.
244 *
245 * @note Called from the tcpip thread when the link goes down.
246 * Can be NULL to default to lwipDefaultLinkDownCB.
247 */
248 void (*link_down_cb)(void*);
249} lwipthread_opts_t;
250
251/**
252 * @brief Parameters for lwipReconfigure.
253 * @note Same meaning as in lwipthread_opts_t.
254 */
255typedef struct lwipreconf_opts {
256 uint32_t address;
257 uint32_t netmask;
258 uint32_t gateway;
259 net_addr_mode_t addrMode;
260} lwipreconf_opts_t;
261
262#ifdef __cplusplus
263extern "C" {
264#endif
265 void lwipDefaultLinkUpCB(void *p);
266 void lwipDefaultLinkDownCB(void *p);
267 void lwipInit(const lwipthread_opts_t *opts);
268 void lwipReconfigure(const lwipreconf_opts_t *opts);
269#ifdef __cplusplus
270}
271#endif
272
273#endif /* LWIPTHREAD_H */
274
275/** @} */