FUNCTIONAL Update from mbed v49: Add APIs for setName/getName so device is name addressible. Also APIs for getting link stats. Also, minor derivative to reduce compiler warnings and tag read-only parameters as const.

Dependencies:   Socket lwip-eth lwip-sys lwip

Dependents:   WattEye X10Svr SSDP_Server

Fork of EthernetInterface by mbed official

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Tue Jul 07 14:10:01 2015 +0000
Parent:
49:2fc406e2553f
Child:
51:664fdba28cd5
Commit message:
Integrate the setName API, as well as ability to determine if link is up, and connected rate.

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
EthernetInterface_Mods.h Show annotated file Show diff for this revision Revisions of this file
EthernetInterface_Mods.hxx Show annotated file Show diff for this revision Revisions of this file
Socket.lib Show annotated file Show diff for this revision Revisions of this file
lwip-eth.lib Show annotated file Show diff for this revision Revisions of this file
lwip-sys.lib Show annotated file Show diff for this revision Revisions of this file
lwip.lib Show annotated file Show diff for this revision Revisions of this file
--- a/EthernetInterface.cpp	Thu Mar 12 16:58:57 2015 +0000
+++ b/EthernetInterface.cpp	Tue Jul 07 14:10:01 2015 +0000
@@ -153,4 +153,5 @@
     return networkmask;
 }
 
+#include "EthernetInterface_Mods.hxx"
 
--- a/EthernetInterface.h	Thu Mar 12 16:58:57 2015 +0000
+++ b/EthernetInterface.h	Tue Jul 07 14:10:01 2015 +0000
@@ -79,6 +79,8 @@
    * \return a pointer to a string containing the Network mask
    */
   static char* getNetworkMask();
+  
+  #include "EthernetInterface_Mods.h" 
 };
 
 #include "TCPSocketConnection.h"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface_Mods.h	Tue Jul 07 14:10:01 2015 +0000
@@ -0,0 +1,101 @@
+//
+// EthernetInterface Modifications to enhance it slightly.
+//
+// This set of modifications integrates with the mbed standard EthernetInterface stack.
+// It does require one-line modifications of both EthernetInterface.h and EthernetInterface.cpp.
+//
+// CAUTION: This works with the LPC1768, but some of the interfaces may be unique to that part.
+//
+// Two steps integrate this:
+//
+// STEP 1: edit EthernetInterface.h as follows:
+//
+//      class EthernetInterface {
+//      public:
+//          ... normal EthernetInterface APIs
+//
+            // add this in the public section, at the bottom
+//          #include "EthernetInterface_Mods.h" 
+//      };
+//
+// STEP 2: edit EthernetInterface.cpp as follows:
+//
+//      // add this at the end of the file
+//      #include "EthernetInterface_Mods.hxx"
+//
+#ifndef ETHERNETINTERFACE_MODS_H
+#define ETHERNETINTERFACE_MODS_H
+
+//#include "lpc_phy.h"    // needed for is_connected()
+
+/** \brief DP83848 PHY status definitions */
+#define DP8_REMOTEFAULT    (1 << 6)   /**< Remote fault */
+#define DP8_FULLDUPLEX     (1 << 2)   /**< 1=full duplex */
+#define DP8_SPEED10MBPS    (1 << 1)   /**< 1=10MBps speed */
+#define DP8_VALID_LINK     (1 << 0)   /**< 1=Link active */
+
+
+  /** setName 
+  *
+  * Set the network name for this device. Apply this before
+  * calling 'connect'.
+  *
+  * \example
+  * EthernetInterface eth;
+  * ...
+  *     if (0 == eth.init()) {
+  *         eth.setName("Sensor 3");
+  *         if (0 == eth.connect()) {
+  *             ...
+  *
+  * \param myname is the name to assign for this node. 
+  *        Only the first 32 characters will be used if the 
+  *        name is longer.
+  *        Only '0'-'9', 'A'-'Z', 'a'-'z' are accepted,
+  *        any others are converted to '-'.
+  * \return 0 on success, a negative number on failure.
+  */
+  static int setName(const char * myname);
+
+  /** getName
+  *
+  * Get the network name for this device.
+  *
+  * \return pointer to the name (or null)
+  */
+  static const char * getName(void);
+
+  /** is_connected
+  *
+  * Determine if the interface is up and connected.
+  * 
+  * \example
+  *      if (eth.is_connected())
+  *         ethLED = 1;
+  *      else
+  *         ethLED = 0;
+  *
+  * \return true if connected, false if not connected.
+  */
+  static bool is_connected(void);
+
+  /** get_transmission_status - full or half duplex.
+  *
+  * \return 1 = 1/2 (half) duplex, 2 = 2/2 (full) duplex
+  */
+  int get_transmission_status(void);  // 1 = 1/2 duplex, 2 = full duplex
+ 
+  /** get the speed of the connection.
+  *
+  * \return 10 or 100 Mb
+  */
+  int get_connection_speed(void);     // 10 or 100 Mb
+ 
+  /** get the current value in the MII data register.
+  *
+  * \return mii register value
+  */
+  uint32_t mii_read_data(void);
+  
+
+#endif // ETHERNETINTERFACE_MODS_H
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface_Mods.hxx	Tue Jul 07 14:10:01 2015 +0000
@@ -0,0 +1,65 @@
+//
+// EthernetInterface Modifications to enhance it slightly.
+//
+// This set of modifications integrates with the mbed standard EthernetInterface stack.
+// It does require one-line modifications of both EthernetInterface.h and EthernetInterface.cpp.
+//
+// See the details at the top of EthernetInterface_Mods.h
+//
+#include "lpc_phy.h"
+
+static char myName[33];  // holds the name, when setName() is called.
+
+static bool inRange(char testChar, char minChar, char maxChar)
+{
+    if (testChar >= minChar && testChar <= maxChar) 
+        return true;
+    else
+        return false;
+}
+
+int EthernetInterface::setName(const char * myname) {
+    int i;
+    
+    strncpy(myName, myname, 32);
+    myName[32] = '\0';  // be sure it is NULL terminated.
+    // make the name 'safe'
+    for (i=0; i<32 && myName[i]; i++) {
+        if (!inRange(myName[i], '0', '9')
+        &&  !inRange(myName[i], 'A', 'Z')
+        &&  !inRange(myName[i], 'a', 'z'))
+            myName[i] = '-';
+    }
+    netif_set_hostname(&netif, myName);
+    return 0;
+}
+
+const char * EthernetInterface::getName(void) {
+    return netif_get_hostname(&netif);
+}
+
+bool EthernetInterface::is_connected(void) {
+    uint32_t tmp = lpc_mii_read_data();
+    
+    return (tmp & DP8_VALID_LINK) ? true : false;
+}
+
+int EthernetInterface::get_transmission_status(void) {  // 1 = 1/2 duplex, 2 = full duplex
+    uint32_t tmp = lpc_mii_read_data();
+    
+    if(tmp & DP8_FULLDUPLEX) {
+        return 2;   // "FULL DUPLEX";
+    } else {
+        return 1;   // "HALF DUPLEX";
+    }
+}
+
+int EthernetInterface::get_connection_speed(void) {     // 10 or 100 Mb
+    uint32_t tmp = lpc_mii_read_data();
+    
+    return (tmp & DP8_SPEED10MBPS) ? 10 : 100;
+}
+
+uint32_t EthernetInterface::mii_read_data(void) {
+    return lpc_mii_read_data();  // 16-bit MRDD - address 0x2008 4030
+}  
\ No newline at end of file
--- a/Socket.lib	Thu Mar 12 16:58:57 2015 +0000
+++ b/Socket.lib	Tue Jul 07 14:10:01 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/Socket/#434906b5b977
+http://mbed.org/users/mbed_official/code/Socket/#5abbc0e39fb1
--- a/lwip-eth.lib	Thu Mar 12 16:58:57 2015 +0000
+++ b/lwip-eth.lib	Tue Jul 07 14:10:01 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/lwip-eth/#ba0a1c5bf54e
+http://mbed.org/users/mbed_official/code/lwip-eth/#dd496edab2cc
--- a/lwip-sys.lib	Thu Mar 12 16:58:57 2015 +0000
+++ b/lwip-sys.lib	Tue Jul 07 14:10:01 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/lwip-sys/#7d4b24b58e04
+http://mbed.org/users/mbed_official/code/lwip-sys/#413514db649c
--- a/lwip.lib	Thu Mar 12 16:58:57 2015 +0000
+++ b/lwip.lib	Tue Jul 07 14:10:01 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/lwip/#1046f8be4d44
+http://mbed.org/users/mbed_official/code/lwip/#52b94de224f0