lwIP is an open source TCP/IP protocol stack for embedded systems developed by Adam Dunkels of the Swedish Institute of Computer Science (Swedish InsTItute of Computer Science). Lwip can be ported to the operating system and run independently without an operating system.
1. Characteristics of LwIP(1) Support IP forwarding under multiple network interfaces
(2) Support for ICMP protocol
(3) Includes experimentally extended UDP (User Datagram Protocol)
(4) TCP (Transmission Control Protocol) including blocking control, RTT estimation and fast recovery and fast forwarding
(5) Provide a dedicated internal callback interface (Raw API) to improve application performance
(6) Optional Berkeley interface API (in the case of multithreading)
(7) Support for ppp in the latest version
(8) Added support for IP fragments in the new version.
(9) Support DHCP protocol to dynamically allocate ip address.
2 Lwip transplantation on ucos. 2.1 System initializationSys_int must be called before the tcpip stack task tcpip_thread is created.
#define MAX_QUEUES 20
#define MAX_QUEUE_ENTRIES 20
Typedef struct {
OS_EVENT* pQ; / / ucos pointer to the event control block
Void* pvQEntries[MAX_QUEUE_ENTRIES];//Message Queue
//Max_QUEUE_ENTRIES maximum number of messages in the message queue
} TQ_DESCR, *PQ_DESCR;
Typedef PQ_DESCR sys_mbox_t; / / visible lwip mbox is actually ucos 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 );//Create a memory partition for the message queue
//init lwip task prio offset
Curr_prio_offset = 0;
//init lwip_TImeouts for every lwip task
/ / Initialize the lwip timing event table, the specific implementation reference to the following chapter
For(i=0;i"LWIP_TASK_MAX;i++){
lwip_TImeouts[i].next = NULL;
}
}
2.2 Create a new process related to tcp/ipThe process in lwip is the task in ucos. The code to create a new process is as follows:
#define LWIP_STK_SIZE The stack size of 10*1024// and tcp/ip related tasks. Can be based on the situation
/ / Set, 44b0 development board has 8M sdram, so set up
//It doesn't matter at all:)
//max number of lwip tasks
#define LWIP_TASK_MAX 5 //Maximum number of tasks related to tcp/ip
//first prio of lwip tasks
#define LWIP_START_PRIO 5 //The starting priority of the task associated with tcp/ip, in this case the priority can be
//From (5-9). Note that tcpip_thread should be the highest priority among all tcp/ip related processes. In this case it is priority 5
/ / If the user needs to create tasks related to tcp / ip, such as uart tasks, etc.
//Do not use the priority of 5-9
OS_STK LWIP_TASK_STK[LWIP_TASK_MAX][LWIP_STK_SIZE];//and tcp/ip related processes
// stack area
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 you can see from the code, tcpip_thread should be created first.
Ring And Fork Type Insulated Terminals
Ring And Fork Type Insulated Terminals,High quality insulated terminal,copper tube terminal
Taixing Longyi Terminals Co.,Ltd. , https://www.lycopperterminals.com