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 }
int lwip_bringup(void) { // Check if we've already connected if (lwip_get_ip_address()) { return NSAPI_ERROR_PARAMETER; } // Check if we've already brought up lwip if (!lwip_get_mac_address()) { // Set up network lwip_set_mac_address(); sys_sem_new(&lwip_tcpip_inited, 0); sys_sem_new(&lwip_netif_linked, 0); sys_sem_new(&lwip_netif_up, 0); tcpip_init(lwip_tcpip_init_irq, NULL); sys_arch_sem_wait(&lwip_tcpip_inited, 0); memset(&lwip_netif, 0, sizeof lwip_netif); netif_add(&lwip_netif, 0, 0, 0, NULL, eth_arch_enetif_init, tcpip_input); netif_set_default(&lwip_netif); netif_set_link_callback (&lwip_netif, lwip_netif_link_irq); netif_set_status_callback(&lwip_netif, lwip_netif_status_irq); eth_arch_enable_interrupts(); } // Zero out socket set lwip_arena_init(); // Connect to the network dhcp_start(&lwip_netif); // Wait for an IP Address u32_t ret = sys_arch_sem_wait(&lwip_netif_up, 15000); if (ret == SYS_ARCH_TIMEOUT) { return NSAPI_ERROR_DHCP_FAILURE; } return 0; }
int EthernetInterface::connect(unsigned int timeout_ms) { eth_arch_enable_interrupts(); int inited; if (use_dhcp) { dhcp_start(&netif); // Wait for an IP Address // -1: error, 0: timeout inited = netif_up.wait(timeout_ms); } else { netif_set_up(&netif); // Wait for the link up inited = netif_linked.wait(timeout_ms); } return (inited > 0) ? (0) : (-1); }
static NyLPC_TBool start(const struct NyLPC_TEthAddr* i_eth_addr,NyLPC_TiEthernetDevice_onEvent i_handler,void* i_param) { _driver.rx_idx=0; _driver.tx_idx=0; //ISRw割り込み設定 _event_handler=i_handler; _event_param=i_param; if(!low_level_init((const NyLPC_TUInt8*)(i_eth_addr->addr),6)){ return NyLPC_TBool_FALSE; } //TXメモリマネージャの準備(バッファのアライメントは16,パディングも16にしてね。謎バイトが2個いるから。) NyLPC_cEthernetMM_initialize(TX_BUF); //Ethernetの割込み開始設定 NyLPC_cIsr_enterCritical(); //Ethernetの初期化シーケンス。割込みONとか { eth_arch_enable_interrupts(); } NyLPC_cIsr_exitCritical(); return NyLPC_TBool_TRUE; }