lwip1.4.0 is able to run now!

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1437 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
mbbill@gmail.com 2011-05-27 06:05:56 +00:00
parent 1d56e975cb
commit e9e1c20aeb
1 changed files with 25 additions and 10 deletions

View File

@ -128,8 +128,18 @@ static err_t ethernetif_init(struct netif *netif)
netif->hwaddr_len = 6; netif->hwaddr_len = 6;
/* maximum transfer unit */ /* maximum transfer unit */
netif->mtu = ETHERNET_MTU; netif->mtu = ETHERNET_MTU;
/* broadcast capability */
netif->flags = NETIF_FLAG_BROADCAST; /* NOTE: the NETIF_FLAG_UP and NETIF_FLAG_LINK_UP flag is not set here.
They should be set by netif_set_up() and netif_set_link_up() automatically */
netif->flags = NETIF_FLAG_BROADCAST |
NETIF_FLAG_ETHARP;
#ifdef LWIP_IGMP
netif->flags |= NETIF_FLAG_IGMP;
#endif
#ifdef LWIP_DHCP
netif->flags |= NETIF_FLAG_DHCP;
#endif
/* get hardware address */ /* get hardware address */
rt_device_control(&(eth_dev->parent), NIOCTL_GADDR, netif->hwaddr); rt_device_control(&(eth_dev->parent), NIOCTL_GADDR, netif->hwaddr);
@ -145,19 +155,19 @@ static err_t ethernetif_init(struct netif *netif)
/* ethernetif APIs */ /* ethernetif APIs */
rt_err_t eth_device_init(struct eth_device* dev, const char* name) rt_err_t eth_device_init(struct eth_device* dev, const char* name)
{ {
struct netif* netif; struct netif* pnetif;
/* allocate memory */ /* allocate memory */
netif = (struct netif*) rt_malloc (sizeof(struct netif)); pnetif = (struct netif*) rt_malloc (sizeof(struct netif));
if (netif == RT_NULL) if (pnetif == RT_NULL)
{ {
rt_kprintf("malloc netif failed\n"); rt_kprintf("malloc netif failed\n");
return -RT_ERROR; return -RT_ERROR;
} }
rt_memset(netif, 0, sizeof(struct netif)); rt_memset(pnetif, 0, sizeof(struct netif));
/* set netif */ /* set netif */
dev->netif = netif; dev->netif = pnetif;
/* register to rt-thread device manager */ /* register to rt-thread device manager */
rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR); rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR);
dev->parent.type = RT_Device_Class_NetIf; dev->parent.type = RT_Device_Class_NetIf;
@ -168,18 +178,23 @@ rt_err_t eth_device_init(struct eth_device* dev, const char* name)
/* NOTE: eth_init will be called back by netif_add, we should put some initialization /* NOTE: eth_init will be called back by netif_add, we should put some initialization
code to eth_init(). See include/lwip/netif.h line 97 */ code to eth_init(). See include/lwip/netif.h line 97 */
eth_dev = dev; eth_dev = dev;
if (netif_add(netif, IP_ADDR_ANY, IP_ADDR_BROADCAST, IP_ADDR_ANY, dev, if (netif_add(pnetif, IP_ADDR_ANY, IP_ADDR_BROADCAST, IP_ADDR_ANY, dev,
ethernetif_init, ethernet_input) == RT_NULL) ethernetif_init, ethernet_input) == RT_NULL)
{ {
/* failed, unregister device and free netif */ /* failed, unregister device and free netif */
rt_device_unregister(&(dev->parent)); rt_device_unregister(&(dev->parent));
rt_free(netif); rt_free(pnetif);
eth_dev = RT_NULL; eth_dev = RT_NULL;
return -RT_ERROR; return -RT_ERROR;
} }
eth_dev = RT_NULL; eth_dev = RT_NULL;
netif_set_default(netif); netif_set_default(pnetif);
/* We bring up the netif here cause we still don't have a call back function
which indicates the ethernet interface status from the ethernet driver. */
netif_set_up(pnetif);
netif_set_link_up(pnetif);
return RT_EOK; return RT_EOK;
} }