|
把lwip移植完了,但是写了个程序还是用不了。不知道怎么测试是否移植正确了?还是我的测试程序写的有问题?
#include "opt.h"
#include "mem.h"
#include "memp.h"
#include "sys.h"
#include "stats.h"
#include "tcpip.h"
#include "loopif.h"
//#include "netif/eth4510if.h"
//#include "netif/eth91c92if.h"
#include "ip_addr.h"
#include "debug.h"
#include "cs8900if.h"
#define LWIP_DEBUG 1
static void tcpip_init_done(void* arg)
{
sys_sem_t *sem;
sem = (sys_sem_t *)arg;
sys_sem_signal(*sem);
}
void LWIP_Main(void* arg)
{
u8_t err;
struct ip_addr ipaddr, netmask, gw;
sys_sem_t sem;
struct netif *smcif,*loif;
//init the lwip
#ifdef STATS
stats_init();
#endif /* STATS */
sys_init();
mem_init();
memp_init();
pbuf_init();
//OSSemPend(ConsoleSem,0,&err);
printf("==================System initialized.==================\r\n");
//OSSemPost(ConsoleSem);
netif_init();
sem = sys_sem_new(0);
tcpip_init(tcpip_init_done, &sem);
sys_sem_wait(sem);
sys_sem_free(sem);
udp_init();
//OSSemPend(ConsoleSem,0,&err);
printf("==================TCP/IP initialized.==================\r\n");
//OSSemPost(ConsoleSem);
//init the loop if first,since the last append if would serv first
IP4_ADDR(&gw, 127,0,0,1);
IP4_ADDR(&ipaddr, 127,0,0,1);
IP4_ADDR(&netmask, 255,0,0,0);
// allocate netif structure
loif = mem_malloc(sizeof(struct netif));
netif_add(loif,&ipaddr, &netmask, &gw, NULL,loopif_init,tcpip_input);
printf("================mem_malloced and netif_added ====================\r\n");
netif_set_up(loif);
//OSSemPend(ConsoleSem,0,&err);
printf("==============Net Interface Attached==============\r\n");
printf("==================127.0.0.1===================\r\n");
//OSSemPost(ConsoleSem);
//dhcp is disabled by yang
#if( LWIP_DHCP==1)
{
struct netif *netif;
IP4_ADDR(&gw, 0,0,0,0);
IP4_ADDR(&ipaddr, 0,0,0,0);
IP4_ADDR(&netmask, 0,0,0,0);
netif = netif_add(&ipaddr, &netmask, &gw, NULL, ethernetif_init,
tcpip_input);
netif_set_default(netif);
dhcp_init();
dhcp_start(netif);
}
#else
// IP4_ADDR(&gw, 192,168,0,1);
// IP4_ADDR(&ipaddr, 192,168,0,111);
// IP4_ADDR(&netmask, 255,255,255,0);
IP4_ADDR(&gw, 192,168,2,1);
IP4_ADDR(&ipaddr, 192,168,2,123);
IP4_ADDR(&netmask, 255,255,255,0);
/* allocate netif structure */
smcif = mem_malloc(sizeof(struct netif));
printf("==============Before netif_set_default ==============\r\n");
netif_set_default(netif_add(smcif,&ipaddr, &netmask, &gw,NULL,cs8900if_init,cs8900if_input));
//here we add a flag_up to enable the netif
netif_set_up(smcif);
//OSSemPend(ConsoleSem,0,&err);
printf("==============Net Interface Attached==============\r\n");
printf("==================192,168,2,123===================\r\n");
//OSSemPost(ConsoleSem);
#endif
// udpecho_init();
//tcpecho_init();
/*shell_init();
tcpecho_init();
httpd_init();
udpecho_init();*/
//It's job is done,halt this task forever
while(1)
{
OSTimeDly(OS_TICKS_PER_SEC*100);//block every hour //minite
}
} |
|