223 * Use this mode if you do not run an OS on your system. \#define NO_SYS to 1.
224 * Feed incoming packets to netif->input(pbuf, netif) function from mainloop,
225 * *not* *from* *interrupt* *context*. You can allocate a @ref pbuf in interrupt
226 * context and put them into a queue which is processed from mainloop.\n
227 * Call sys_check_timeouts() periodically in the mainloop.\n
228 * Porting: implement all functions in @ref sys_time, @ref sys_prot and
229 * @ref compiler_abstraction.\n
230 * You can only use @ref callbackstyle_api in this mode.\n
231 * Sample code:\n
232 * @include NO_SYS_SampleCode.c
233 */
234
235/**
236 * @defgroup lwip_os OS mode (TCPIP thread)
237 * @ingroup lwip
238 * Use this mode if you run an OS on your system. It is recommended to
239 * use an RTOS that correctly handles priority inversion and
240 * to use @ref LWIP_TCPIP_CORE_LOCKING.\n
241 * Porting: implement all functions in @ref sys_layer.\n
242 * You can use @ref callbackstyle_api together with @ref tcpip_callback,
243 * and all @ref sequential_api.
244 */
245
246/**
247 * @page sys_init System initalization
248A truly complete and generic sequence for initializing the lwIP stack
249cannot be given because it depends on additional initializations for
250your runtime environment (e.g. timers).
251
252We can give you some idea on how to proceed when using the raw API.
253We assume a configuration using a single Ethernet netif and the
254UDP and TCP transport layers, IPv4 and the DHCP client.
255
256Call these functions in the order of appearance:
257
258- lwip_init(): Initialize the lwIP stack and all of its subsystems.
259
260- netif_add(struct netif *netif, ...):
261 Adds your network interface to the netif_list. Allocate a struct
262 netif and pass a pointer to this structure as the first argument.
263 Give pointers to cleared ip_addr structures when using DHCP,
264 or fill them with sane numbers otherwise. The state pointer may be NULL.
265
266 The init function pointer must point to a initialization function for
267 your Ethernet netif interface. The following code illustrates its use.
268
269@code{.c}
270 err_t netif_if_init(struct netif *netif)
271 {
272 u8_t i;
273
274 for (i = 0; i < ETHARP_HWADDR_LEN; i++) {
275 netif->hwaddr[i] = some_eth_addr[i];
276 }
277 init_my_eth_device();
278 return ERR_OK;
279 }
280@endcode
281
282 For Ethernet drivers, the input function pointer must point to the lwIP
283 function ethernet_input() declared in "netif/etharp.h". Other drivers
284 must use ip_input() declared in "lwip/ip.h".
285
286- netif_set_default(struct netif *netif)
287 Registers the default network interface.
288
289- netif_set_link_up(struct netif *netif)
290 This is the hardware link state; e.g. whether cable is plugged for wired
291 Ethernet interface. This function must be called even if you don't know
292 the current state. Having link up and link down events is optional but
293 DHCP and IPv6 discover benefit well from those events.
294
295- netif_set_up(struct netif *netif)
296 This is the administrative (= software) state of the netif, when the
297 netif is fully configured this function must be called.
298
299- dhcp_start(struct netif *netif)
300 Creates a new DHCP client for this interface on the first call.
301 You can peek in the netif->dhcp struct for the actual DHCP status.
302
303- sys_check_timeouts()
304 When the system is running, you have to periodically call
305 sys_check_timeouts() which will handle all timers for all protocols in
306 the stack; add this to your main loop or equivalent.
307 */
308
309/**
310 * @page multithreading Multithreading
311 * lwIP started targeting single-threaded environments. When adding multi-
312 * threading support, instead of making the core thread-safe, another
313 * approach was chosen: there is one main thread running the lwIP core
314 * (also known as the "tcpip_thread"). When running in a multithreaded
315 * environment, raw API functions MUST only be called from the core thread
316 * since raw API functions are not protected from concurrent access (aside
317 * from pbuf- and memory management functions). Application threads using
318 * the sequential- or socket API communicate with this main thread through
319 * message passing.
320 *
321 * As such, the list of functions that may be called from
322 * other threads or an ISR is very limited! Only functions
323 * from these API header files are thread-safe:
324 * - api.h
325 * - netbuf.h
326 * - netdb.h
327 * - netifapi.h
328 * - pppapi.h
329 * - sockets.h
330 * - sys.h
331 *
332 * Additionaly, memory (de-)allocation functions may be
333 * called from multiple threads (not ISR!) with NO_SYS=0
334 * since they are protected by @ref SYS_LIGHTWEIGHT_PROT and/or
335 * semaphores.
336 *
337 * Netconn or Socket API functions are thread safe against the
338 * core thread but they are not reentrant at the control block
339 * granularity level. That is, a UDP or TCP control block must
340 * not be shared among multiple threads without proper locking.
341 *
342 * If @ref SYS_LIGHTWEIGHT_PROT is set to 1 and
343 * @ref LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT is set to 1,
344 * pbuf_free() may also be called from another thread or
345 * an ISR (since only then, mem_free - for PBUF_RAM - may
346 * be called from an ISR: otherwise, the HEAP is only
347 * protected by semaphores).
348 *
349 * How to get threading done right
350 * -------------------------------
351 *
352 * It is strongly recommended to implement the LWIP_ASSERT_CORE_LOCKED()
353 * macro in an application that uses multithreading. lwIP code has
354 * several places where a check for a correct thread context is
355 * implemented which greatly helps the user to get threading done right.
356 * See the example sys_arch.c files in unix and Win32 port
357 * in the contrib repository.
358 *
359 * In short: Copy the functions sys_mark_tcpip_thread() and
360 * sys_check_core_locking() to your port and modify them to work with your OS.
361 * Then let @ref LWIP_ASSERT_CORE_LOCKED() and @ref LWIP_MARK_TCPIP_THREAD()
362 * point to these functions.
363 *
364 * If you use @ref LWIP_TCPIP_CORE_LOCKING, you also need to copy and adapt
365 * the functions sys_lock_tcpip_core() and sys_unlock_tcpip_core().
366 * Let @ref LOCK_TCPIP_CORE() and @ref UNLOCK_TCPIP_CORE() point
367 * to these functions.
368 */
369
370/**
371 * @page optimization Optimization hints
372The first thing you want to optimize is the lwip_standard_checksum()
373routine from src/core/inet.c. You can override this standard
374function with the \#define LWIP_CHKSUM your_checksum_routine().
375
376There are C examples given in inet.c or you might want to
377craft an assembly function for this. RFC1071 is a good
378introduction to this subject.
379
380Other significant improvements can be made by supplying
381assembly or inline replacements for htons() and htonl()
382if you're using a little-endian architecture.
383\#define lwip_htons(x) your_htons()
384\#define lwip_htonl(x) your_htonl()
385If you \#define them to htons() and htonl(), you should
386\#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS to prevent lwIP from
387defining htonx / ntohx compatibility macros.
388
389Check your network interface driver if it reads at
390a higher speed than the maximum wire-speed. If the
391hardware isn't serviced frequently and fast enough
392buffer overflows are likely to occur.
393
394E.g. when using the cs8900 driver, call cs8900if_service(ethif)
395as frequently as possible. When using an RTOS let the cs8900 interrupt
396wake a high priority task that services your driver using a binary
397semaphore or event flag. Some drivers might allow additional tuning
398to match your application and network.
399
400For a production release it is recommended to set LWIP_STATS to 0.
401Note that speed performance isn't influenced much by simply setting
402high values to the memory options.
403 */
Important Information for this Arm website
This site uses cookies to store information on your computer.
By continuing to use our site, you consent to our cookies.
If you are not happy with the use of these cookies, please review our
Cookie Policy
to learn how they can be disabled.
By disabling cookies, some features of the site will not work.