刚入手dm9000 在初始化的时候设备找不到
| /
- RT - Thread Operating System
/ | 0.4.0 build Jun 18 2014
2006 - 2009 Copyright by rt-thread team
To initialize device:e0 failed. The error code is -1
The Software Version is V1.0.0!
TCP/IP initialized!
System is Run!
相关代码如下:
rt_err_t rt_device_init_all()
{
struct rt_device* device;
struct rt_list_node* node;
struct rt_object_information *information;
register rt_err_t result;
extern struct rt_object_information rt_object_container[];
information = &rt_object_container[RT_Object_Class_Device];
/* for each device */
for (node = information->object_list.next; node != &(information->object_list); node = node->next)
{
rt_err_t (*init)(rt_device_t dev);
device = (struct rt_device*)rt_list_entry(node, struct rt_object, list);
/* get device init handler */
init = device->init;
if (init != RT_NULL && !(device->flag & RT_DEVICE_FLAG_ACTIVATED))
{
result = init(device);
if (result != RT_EOK)
{
rt_kprintf("To initialize device:%s failed. The error code is %d
",
device->parent.name, result);
}
else
{
device->flag |= RT_DEVICE_FLAG_ACTIVATED;
}
}
}
return RT_EOK;
}
rt_err_t eth_device_init(struct eth_device* dev, const char* name)
{
struct netif* netif;
netif = (struct netif*) rt_malloc (sizeof(struct netif));
if (netif == RT_NULL)
{
rt_kprintf("malloc netif failed
");
return -RT_ERROR;
}
rt_memset(netif, 0, sizeof(struct netif));
/* set netif */
dev->netif = netif;
/* register to rt-thread device manager */
rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR);
dev->parent.type = RT_Device_Class_NetIf;
rt_sem_init(&(dev->tx_ack), name, 0, RT_IPC_FLAG_FIFO);
/* set name */
netif->name[0] = name[0];
netif->name[1] = name[1];
/* set hw address to 6 */
netif->hwaddr_len = 6;
/* maximum transfer unit */
netif->mtu = ETHERNET_MTU;
/* broadcast capability */
netif->flags = NETIF_FLAG_BROADCAST;
/* get hardware address */
rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr);
/* set output */
netif->output = ethernetif_output;
netif->linkoutput = ethernetif_linkoutput;
/* add netif to lwip */
if (netif_add(netif, IP_ADDR_ANY, IP_ADDR_BROADCAST, IP_ADDR_ANY, dev,
eth_init, eth_input) == RT_NULL)
{
/* failed, unregister device and free netif */
rt_device_unregister(&(dev->parent));
rt_free(netif);
return -RT_ERROR;
}
netif_set_default(netif);
return RT_EOK;
}
struct netif *
netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
struct ip_addr *gw,
void *state,
err_t (* init)(struct netif *netif),
err_t (* input)(struct pbuf *p, struct netif *netif))
{
static u8_t netifnum = 0;
/* reset new interface configuration state */
netif->ip_addr.addr = 0;
netif->netmask.addr = 0;
netif->gw.addr = 0;
/* netif->flags = 0; */
#if LWIP_DHCP
/* netif not under DHCP control by default */
netif->dhcp = NULL;
#endif /* LWIP_DHCP */
#if LWIP_AUTOIP
/* netif not under AutoIP control by default */
netif->autoip = NULL;
#endif /* LWIP_AUTOIP */
#if LWIP_NETIF_STATUS_CALLBACK
netif->status_callback = NULL;
#endif /* LWIP_NETIF_STATUS_CALLBACK */
#if LWIP_NETIF_LINK_CALLBACK
netif->link_callback = NULL;
#endif /* LWIP_NETIF_LINK_CALLBACK */
#if LWIP_IGMP
netif->igmp_mac_filter = NULL;
#endif /* LWIP_IGMP */
#if ENABLE_LOOPBACK
netif->loop_first = NULL;
netif->loop_last = NULL;
#endif /* ENABLE_LOOPBACK */
/* remember netif specific state information data */
netif->state = state;
netif->num = netifnum++;
netif->input = input;
#if LWIP_NETIF_HWADDRHINT
netif->addr_hint = NULL;
#endif /* LWIP_NETIF_HWADDRHINT*/
#if ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS
netif->loop_cnt_current = 0;
#endif /* ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS */
netif_set_addr(netif, ipaddr, netmask, gw);
/* call user specified initialization function for netif */
if (init(netif) != ERR_OK) {
return NULL;
}
/* add this netif to the list */
netif->next = netif_list;
netif_list = netif;
snmp_inc_iflist();
#if LWIP_IGMP
/* start IGMP processing */
if (netif->flags & NETIF_FLAG_IGMP) {
igmp_start( netif);
}
#endif /* LWIP_IGMP */
LWIP_DEBUGF(NETIF_DEBUG, ("netif: added interface %c%c IP addr ",
netif->name[0], netif->name[1]));
ip_addr_debug_print(NETIF_DEBUG, ipaddr);
LWIP_DEBUGF(NETIF_DEBUG, (" netmask "));
ip_addr_debug_print(NETIF_DEBUG, netmask);
LWIP_DEBUGF(NETIF_DEBUG, (" gw "));
ip_addr_debug_print(NETIF_DEBUG, gw);
LWIP_DEBUGF(NETIF_DEBUG, ("
"));
return netif;
}
好晕啊~
望大神指点!