附上代码 OS_STK_DATA data; ST_NETCONN *__pstConn, *__pstNewConn; struct netbuf *__pstNetbuf; int k,i; k = 1; (void)p_arg;
//ConsoleSem = OSSemCreate(1); lwip_input = OSSemCreate(0); next = OSSemCreate(1); lwip_output = OSSemCreate(1); Sem1 = OSSemCreate(0); pri_info(); //Entrance to the lwip stack. LWIP_main(p_arg);(就是这里,如果后面不加FOR循环,就PING 不通了) for(;;){ AT91F_PIO_ClearOutput( AT91D_BASE_PIO_LED, led_mask[0]); OSTimeDlyHMSM(0, 0, 0, SPEED); AT91F_PIO_SetOutput( AT91D_BASE_PIO_LED, led_mask[0] ) ; OSTimeDlyHMSM(0, 0, 0, SPEED); } __pstConn = netconn_new(NETCONN_TCP); netconn_bind(__pstConn, NULL, 80); netconn_listen(__pstConn); while(TRUE) { __pstNewConn = netconn_accept(__pstConn); if(__pstNewConn != NULL) { __pstNetbuf = netconn_recv(__pstNewConn); if(__pstNetbuf != NULL) { netconn_write(__pstNewConn, "HTTP/1.1 200 OK
Content-type: text/html
", 44, NETCONN_COPY); netconn_write(__pstNewConn, "<body><h1>这是LWIP TCP测试!</h1></body>", 40, NETCONN_COPY); netbuf_delete(__pstNetbuf); } netconn_close(__pstNewConn); while(netconn_delete(__pstNewConn) != ERR_OK) OSTimeDlyHMSM(0, 0, 1, 0);
} } }
--------------------------- 下面是LWIP初始化的代码 void LWIP_main(void *arg) { extern err_t ethernetif_init(struct netif *stNetif); u8_t err; struct ip_addr ipaddr, netmask, gw; sys_sem_t sem; static st_netif netif_test;
//netifnum = 0; //for count netif->num
sys_init(); mem_init(); memp_init(); pbuf_init();
//mainthread netif_init();
sem = sys_sem_new(0); tcpip_init(NULL, NULL); tcpip_init(tcpip_init_done, &sem); sys_sem_wait(sem); sys_sem_free(sem); udp_init();
//* 建立并配置EMAC接口 IP4_ADDR(&ipaddr, (PST_NET_CFG_PARAM->ulFlag == NET_CFG_FLAG)?macGetIPAddr(0):OURIP1, (PST_NET_CFG_PARAM->ulFlag == NET_CFG_FLAG)?macGetIPAddr(1):OURIP2, (PST_NET_CFG_PARAM->ulFlag == NET_CFG_FLAG)?macGetIPAddr(2):OURIP3, (PST_NET_CFG_PARAM->ulFlag == NET_CFG_FLAG)?macGetIPAddr(3):OURIP4); IP4_ADDR(&netmask, (PST_NET_CFG_PARAM->ulFlag == NET_CFG_FLAG)?macGetNetMask(0):NETMASK1, (PST_NET_CFG_PARAM->ulFlag == NET_CFG_FLAG)?macGetNetMask(1):NETMASK2, (PST_NET_CFG_PARAM->ulFlag == NET_CFG_FLAG)?macGetNetMask(2):NETMASK3, (PST_NET_CFG_PARAM->ulFlag == NET_CFG_FLAG)?macGetNetMask(3):NETMASK4); IP4_ADDR(&gw, (PST_NET_CFG_PARAM->ulFlag == NET_CFG_FLAG)?macGetGateway(0):GATEWAY1, (PST_NET_CFG_PARAM->ulFlag == NET_CFG_FLAG)?macGetGateway(1):GATEWAY2, (PST_NET_CFG_PARAM->ulFlag == NET_CFG_FLAG)?macGetGateway(2):GATEWAY3, (PST_NET_CFG_PARAM->ulFlag == NET_CFG_FLAG)?macGetGateway(3):GATEWAY4); netif_add(&netif_test,&ipaddr, &netmask, &gw, NULL, ethernetif_init,tcpip_input); netif_set_default(&netif_test); netif_set_up(&netif_test);
}
|