mbed IP library over Ethernet

Dependencies:   Socket lwip-eth2 lwip-sys lwip_t

Dependents:   tiny_server

Fork of EthernetInterface by mbed official

Files at this revision

API Documentation at this revision

Comitter:
emilmont
Date:
Fri Aug 03 14:43:57 2012 +0000
Parent:
20:0d9ae7845bfe
Child:
22:2a797ba9babe
Commit message:
Add timeout to network initialization

Changed in this revision

EthernetInterface.cpp Show annotated file Show diff for this revision Revisions of this file
EthernetInterface.h Show annotated file Show diff for this revision Revisions of this file
--- a/EthernetInterface.cpp	Wed Aug 01 13:02:38 2012 +0000
+++ b/EthernetInterface.cpp	Fri Aug 03 14:43:57 2012 +0000
@@ -72,7 +72,7 @@
     return 0;
 }
 
-int EthernetInterface::connect() {
+int EthernetInterface::connect(unsigned int timeout_ms) {
     NVIC_SetPriority(ENET_IRQn, ((0x01 << 3) | 0x01));
     NVIC_EnableIRQ(ENET_IRQn);
     
@@ -82,9 +82,9 @@
         netif_set_up(&lpcNetif);
     }
     
-    netif_inited.wait();
-    
-    return 0;
+    // -1: error, 0: timeout
+    int inited = netif_inited.wait(timeout_ms);
+    return (inited > 0) ? (0) : (-1);
 }
 
 int EthernetInterface::disconnect() {
--- a/EthernetInterface.h	Wed Aug 01 13:02:38 2012 +0000
+++ b/EthernetInterface.h	Fri Aug 03 14:43:57 2012 +0000
@@ -45,9 +45,10 @@
 
   /** Connect
   * Bring the interface up, start DHCP if needed.
+  * \param   timeout_ms  timeout in ms (default: (3)s).
   * \return 0 on success, a negative number on failure
   */
-  static int connect();
+  static int connect(unsigned int timeout_ms=3000);
   
   /** Disconnect
   * Bring the interface down