Recently I was told that there really lack of enough document && demo regarding the lwIP stack with SDK. So I would like to share more detail regarding this topic, and hope it will been helpful and useful.
Introduction
lwIP stack on KSDK
- <ksdk_install_dir>/middleware/tcpip/lwip
lwIP stack on KSDK - Code Structure
This subfolder includes the latest stable lwIP 1.4.1 source code which can be downloaded from this link: download.savannah.gnu.org/releases/lwip/
This subfolder includes the adapter code which adapts lwIP stack to SDK.
lwIP stack on KSDK - Source Code
Structure of source code under is shown below:
lwIP stack on KSDK – Adapter code
Ethernet driver adapter code
OSA adapter code
Additional code
lwIP stack configuration code
Ethernet Driver Adapter Code
− Ethernet hardware initialization
− Network interface initialization
− Send packet to Ethernet hardware
− Receive packet from Ethernet hardware
− Pass packet to lwIP stack
- In <ksdk_install_dir>/platform/drivers/inc/fsl_enet_driver.h,
#define ENET_RECEIVE_ALL_INTERRUPT 0 to enable polling mode.
Or set
#define ENET_RECEIVE_ALL_INTERRUPT 1 to enable interrupt mode.
OSA Adapter Code
−Semaphore
−Mutex
−Mailbox
−Thread
Additional Code
−Typedefs
−Compiler hints for packing and platform specific
−Diagnostic output
lwIP Stack Configuration Code
− Module support (Code size)
Default inclusions:
ARP (LWIP_ARP)
UDP (LWIP_UDP) and UDP-Lite (LWIP_UDPLITE)
TCP (LWIP_TCP) -- this is a big one!
Statistics (LWIP_STATS)
……
Default exclusions:
DHCP (LWIP_DHCP)
AUTOIP (LWIP_AUTOIP)
SNMP (LWIP_SNMP)
IGMP (LWIP_IGMP)
PPP (PPP_SUPPORT)
− Memory management (RAM usage)
lwIP’s custom heap-based mem_malloc
C standard library malloc and free
Memory pools
lwIP Stack Porting Guide
Possible Situation for Porting
New Soc with Limited RAM
In current KSDK, the main RAM consumption for lwIP is show below:
In lwip/port/lwipopts.h:
#define MEM_SIZE (12*1024) /**the size of ram_heap/
#define PBUF_POOL_SIZE 10 /*the number of buffers in the pbuf pool. */
#define PBUF_POOL_BUFSIZE 1518 /* the size of each pbuf in the pbuf pool. */
In lwip/include/opt.h:
#define MEMP_MEM_MALLOC 1 /*Use mem_malloc/mem_free to do allocate*/
#define MEM_LIBC_MALLOC 1 /*Use malloc/free/realloc provided by C-library*/
New Soc NOT Support PIT timer
#define HWTIMER_LL_DEVIF kPitDevif // Use hardware timer PIT
#define HWTIMER_LL_SRCCLK kBusClock // Source Clock for PIT
#define HWTIMER_LL_ID 3
#define HWTIMER_PERIOD 1000 // 1 ms interval
Lightweight TCP/IP (lwIP) Stack Porting v
Lightweight TCP/IP (lwIP) Stack Porting Guide
Lightweight TCP/IP (lwIP) Stack Porting Guide