Lwip transplantation instructions and experience

lwIP is an open-source TCP/IP protocol stack designed for embedded systems, developed by Adam Dunkels at the Swedish Institute of Computer Science. It is capable of running independently without an operating system or being integrated into an existing OS. This flexibility makes it a popular choice in resource-constrained environments. **1. Key Features of lwIP** - Supports IP forwarding across multiple network interfaces. - Implements the ICMP protocol for network diagnostics. - Offers experimental support for UDP (User Datagram Protocol). - Provides a robust TCP implementation with features such as blocking control, RTT estimation, fast recovery, and fast forwarding. - Includes a raw API for direct access to the protocol stack, enhancing application performance. - Optionally supports the Berkeley socket API in multithreaded environments. - Adds support for PPP (Point-to-Point Protocol) in recent versions. - Introduces IP fragment handling in newer releases. - Supports DHCP to dynamically assign IP addresses. **2. Porting lwIP to uC/OS-II** **2.1 System Initialization** Before creating the tcpip_thread task, the sys_init() function must be called. This initializes the necessary memory structures and sets up the environment for lwIP to operate within the uC/OS-II framework. ```c #define MAX_QUEUES 20 #define MAX_QUEUE_ENTRIES 20 typedef struct { OS_EVENT* pQ; // Pointer to uC/OS-II event control block void* pvQEntries[MAX_QUEUE_ENTRIES]; // Message queue entries } TQ_DESCR, *PQ_DESCR; typedef PQ_DESCR sys_mbox_t; // lwIP mailbox is essentially a uC/OS-II message queue static char pcQueueMemoryPool[MAX_QUEUES * sizeof(TQ_DESCR)]; void sys_init(void) { U8_t i; S8_t ucErr; pQueueMem = OSMemCreate((void*)pcQueueMemoryPool, MAX_QUEUES, sizeof(TQ_DESCR), &ucErr); curr_prio_offset = 0; for(i = 0; i < LWIP_TASK_MAX; i++) { lwip_timeouts[i].next = NULL; } } ``` **2.2 Creating a New Task for TCP/IP** In uC/OS-II, each lwIP task corresponds to a thread. The following code demonstrates how to create a new task: ```c #define LWIP_STK_SIZE 10 * 1024 // Stack size for TCP/IP tasks #define LWIP_TASK_MAX 5 // Maximum number of TCP/IP tasks #define LWIP_START_PRIO 5 // Starting priority for TCP/IP tasks OS_STK LWIP_TASK_STK[LWIP_TASK_MAX][LWIP_STK_SIZE]; U8_t curr_prio_offset; sys_thread_t sys_thread_new(void (*function)(void *arg), void *arg, int prio) { if(curr_prio_offset < LWIP_TASK_MAX) { OSTaskCreate(function, (void*)0x1111, &LWIP_TASK_STK[curr_prio_offset][LWIP_STK_SIZE - 1], LWIP_START_PRIO + curr_prio_offset); curr_prio_offset++; return 1; } else { // PRINT("lwip task prio out of range! error!"); } } ``` As shown in the code, the tcpip_thread should be created first to ensure proper task scheduling and operation within the uC/OS-II environment.

Wall-Mounted Digital Signage

Wall-Mounted Digital Signage,Wall-Mounted Screen,Hanging Display,Digital Lcd Display

Shenzhen Risingstar Outdoor High Light LCD Co., Ltd , https://www.risingstarlcd.com