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 can be integrated into an operating system or run independently without one, making it highly flexible for various embedded applications. **1. Key Features of lwIP** - Supports IP forwarding across multiple network interfaces. - Provides support for the ICMP (Internet Control Message Protocol). - Includes experimental extensions for UDP (User Datagram Protocol). - Implements TCP (Transmission Control Protocol) with features like blocking control, RTT estimation, fast recovery, and fast forwarding. - Offers a dedicated raw API for direct application interaction, improving performance. - Optionally supports the Berkeley socket API in multi-threaded environments. - Adds support for PPP (Point-to-Point Protocol) in recent versions. - Introduces IP fragmentation handling in newer releases. - Enables dynamic IP address allocation via the DHCP (Dynamic Host Configuration Protocol). **2. lwIP Porting on uC/OS** **2.1 System Initialization** Before initializing the TCP/IP stack task `tcpip_thread`, the `sys_init()` function must be called. This function sets up memory pools and initializes internal structures used by lwIP. ```c #define MAX_QUEUES 20 #define MAX_QUEUE_ENTRIES 20 typedef struct { OS_EVENT* pQ; // Pointer to uC/OS 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 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 New Tasks for TCP/IP** In lwIP, tasks are managed as threads within uC/OS. The following code demonstrates how to create new tasks: ```c #define LWIP_STK_SIZE 10 * 1024 // Stack size for TCP/IP-related 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]; // Task stacks 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 priority out of range! Error!"); } } ``` As shown, the `tcpip_thread` should be created first to ensure proper execution order. This setup allows lwIP to work efficiently within the uC/OS environment, enabling real-time communication capabilities in embedded systems.

High-Tni LCD Panel

High-Tni Lcd Panel,High-Tni Lcd,Hi-Tni Lcd,Outdoor High Brightness Lcd Panel

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