3.3.2 启动流程
1、lwip初始化在:int lwip_system_init(void)
2、使用lwip注册设备:
- int rt_hw_gd32_eth_init(void)
- {
- rt_kprintf("rt_gd32_eth_init...\n");
-
- /* enable ethernet clock */
- rcu_periph_clock_enable(RCU_ENET);
- rcu_periph_clock_enable(RCU_ENETTX);
- rcu_periph_clock_enable(RCU_ENETRX);
-
- nvic_configuration(); //中断配置
-
- /* configure the GPIO ports for ethernet pins */
- enet_gpio_config(); //管脚配置
-
- /* set autonegotiation mode */
- gd32_emac_device0.phy_mode = EMAC_PHY_AUTO;
- gd32_emac_device0.ETHERNET_MAC = ETHERNET_MAC0; //寄存器地址
- gd32_emac_device0.ETHER_MAC_IRQ = ENET_IRQn;
- // OUI 00-00-0E FUJITSU LIMITED
- gd32_emac_device0.dev_addr[0] = 0x00; //mac地址
- gd32_emac_device0.dev_addr[1] = 0x00;
- gd32_emac_device0.dev_addr[2] = 0x0E;
- /* set mac address: (only for test) */
- gd32_emac_device0.dev_addr[3] = 0x12;
- gd32_emac_device0.dev_addr[4] = 0x34;
- gd32_emac_device0.dev_addr[5] = 0x56;
- gd32_emac_device0.parent.parent.init = gd32_emac_init; //mac初始化
- gd32_emac_device0.parent.parent.open = gd32_emac_open;
- gd32_emac_device0.parent.parent.close = gd32_emac_close;
- gd32_emac_device0.parent.parent.read = gd32_emac_read;
- gd32_emac_device0.parent.parent.write = gd32_emac_write;
- gd32_emac_device0.parent.parent.control = gd32_emac_control;
- gd32_emac_device0.parent.parent.user_data = RT_NULL;
- gd32_emac_device0.parent.eth_rx = gd32_emac_rx;
- gd32_emac_device0.parent.eth_tx = gd32_emac_tx;
- /* init tx buffer free semaphore */
- rt_sem_init(&gd32_emac_device0.tx_buf_free, "tx_buf0", EMAC_TXBUFNB, RT_IPC_FLAG_FIFO);
- eth_device_init(&(gd32_emac_device0.parent), "e0"); //lwip向系统注册网卡e0-----
-
- /* change device link status */
- eth_device_linkchange(&(gd32_emac_device0.parent), RT_TRUE);
-
- return 0;
- }
- INIT_DEVICE_EXPORT(rt_hw_gd32_eth_init);
|