使用版本lwip1.3.0
一、配置文件
新建arch\cc.h
typedef unsigned char u8_t; /* Unsigned 8 bit quantity */
typedef signed char s8_t; /* Signed 8 bit quantity */
typedef unsigned short u16_t; /* Unsigned 16 bit quantity */
typedef signed short s16_t; /* Signed 16 bit quantity */
typedef unsigned long u32_t; /* Unsigned 32 bit quantity */
typedef signed long s32_t; /* Signed 32 bit quantity */
typedef u32_t mem_ptr_t;
#if defined (WIN32)
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_STRUCT
#define PACK_STRUCT_END
#define PACK_STRUCT_FIELD(x) x
#endif
#ifndef LWIP_PLATFORM_ASSERT
#define LWIP_PLATFORM_ASSERT(x) \
do \
{ printf("Assertion \"%s\" failed at line %d in %s\n", x, __LINE__, __FILE__); \
} while(0)
#endif
arch\perf.h
#define PERF_START /* null definition */
#define PERF_STOP(x) /* null definition */
include\lwipopts.h
#define SYS_LIGHTWEIGHT_PROT 0
#define NO_SYS 1
#define MEM_ALIGNMENT 4
二、移植代码
修改netif\ethernetif.c
#if 0改为1然后编译,出错的地方就是需要移植的地方。
static err_t
low_level_output(struct netif *netif, struct pbuf *p)
{
char* pBuffer = buffer;
int nLen = 0;
for(q = p; q != NULL; q = q->next) {
// send data from(q->payload, q->len);
memcpy(pBuffer,q->payload, q->len);
pBuffer += q->len;
nLen += q->len;
}
//发送数据包
EthernetSend(buffer,nLen);
}
static struct pbuf *
low_level_input(struct netif *netif)
{
//接收数据
len = EthernetRead(buffer,1024);
if(len < 1) return NULL;
char* pBuffer = buffer;
for(q = p; q != NULL; q = q->next) {
/* Read enough bytes to fill this pbuf in the chain. The
* available data in the pbuf is given by the q->len
* variable. */
// read data into(q->payload, q->len);
memcpy(q->payload,pBuffer,q->len);
pBuffer += q->len;
}
}
static void
low_level_init(struct netif *netif)
{//初始化
EthernetInit();
}
说明:需要移植的地方跟UIP很相似,实现网卡初始化,收发数据包函数即可。
不同的地方是lwip还要一个定时器,我直接使用了uip的实现方法。
int main(int argc, char* argv[])
{
struct timer periodic_timer;
Init_lwIP();
UDP_Test_Init();
http_init();
timer_set(&periodic_timer, 500);
while(1)
{
ethernetif_input(&netif);
if(timer_expired(&periodic_timer))
{
tcp_tmr();
dhcp_fine_tmr();
}
}
return 0;
}
移植完成