nsapi_error_t mbed_lwip_init(emac_interface_t *emac) { // Check if we've already brought up lwip if (!mbed_lwip_get_mac_address()) { // Set up network mbed_lwip_set_mac_address(); sys_sem_new(&lwip_tcpip_inited, 0); sys_sem_new(&lwip_netif_linked, 0); sys_sem_new(&lwip_netif_has_addr, 0); tcpip_init(mbed_lwip_tcpip_init_irq, NULL); sys_arch_sem_wait(&lwip_tcpip_inited, 0); memset(&lwip_netif, 0, sizeof lwip_netif); if (!netif_add(&lwip_netif, #if LWIP_IPV4 0, 0, 0, #endif emac, MBED_NETIF_INIT_FN, tcpip_input)) { return NSAPI_ERROR_DEVICE_ERROR; } netif_set_default(&lwip_netif); netif_set_link_callback(&lwip_netif, mbed_lwip_netif_link_irq); netif_set_status_callback(&lwip_netif, mbed_lwip_netif_status_irq); #if !DEVICE_EMAC eth_arch_enable_interrupts(); #endif } return NSAPI_ERROR_OK; }
nsapi_error_t mbed_lwip_emac_init(emac_interface_t *emac) { #if LWIP_ETHERNET // Choose a MAC address - driver can override mbed_lwip_set_mac_address(&lwip_netif); // Set up network if (!netif_add(&lwip_netif, #if LWIP_IPV4 0, 0, 0, #endif emac, MBED_NETIF_INIT_FN, tcpip_input)) { return NSAPI_ERROR_DEVICE_ERROR; } // Note the MAC address actually in use mbed_lwip_record_mac_address(&lwip_netif); #if !DEVICE_EMAC eth_arch_enable_interrupts(); #endif return NSAPI_ERROR_OK; #else return NSAPI_ERROR_UNSUPPORTED; #endif //LWIP_ETHERNET }