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

Committer:
WiredHome
Date:
Tue Jul 07 14:10:01 2015 +0000
Revision:
50:957161ecdd16
Child:
53:bbcf2853e575
Integrate the setName API, as well as ability to determine if link is up, and connected rate.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 50:957161ecdd16 1 //
WiredHome 50:957161ecdd16 2 // EthernetInterface Modifications to enhance it slightly.
WiredHome 50:957161ecdd16 3 //
WiredHome 50:957161ecdd16 4 // This set of modifications integrates with the mbed standard EthernetInterface stack.
WiredHome 50:957161ecdd16 5 // It does require one-line modifications of both EthernetInterface.h and EthernetInterface.cpp.
WiredHome 50:957161ecdd16 6 //
WiredHome 50:957161ecdd16 7 // See the details at the top of EthernetInterface_Mods.h
WiredHome 50:957161ecdd16 8 //
WiredHome 50:957161ecdd16 9 #include "lpc_phy.h"
WiredHome 50:957161ecdd16 10
WiredHome 50:957161ecdd16 11 static char myName[33]; // holds the name, when setName() is called.
WiredHome 50:957161ecdd16 12
WiredHome 50:957161ecdd16 13 static bool inRange(char testChar, char minChar, char maxChar)
WiredHome 50:957161ecdd16 14 {
WiredHome 50:957161ecdd16 15 if (testChar >= minChar && testChar <= maxChar)
WiredHome 50:957161ecdd16 16 return true;
WiredHome 50:957161ecdd16 17 else
WiredHome 50:957161ecdd16 18 return false;
WiredHome 50:957161ecdd16 19 }
WiredHome 50:957161ecdd16 20
WiredHome 50:957161ecdd16 21 int EthernetInterface::setName(const char * myname) {
WiredHome 50:957161ecdd16 22 int i;
WiredHome 50:957161ecdd16 23
WiredHome 50:957161ecdd16 24 strncpy(myName, myname, 32);
WiredHome 50:957161ecdd16 25 myName[32] = '\0'; // be sure it is NULL terminated.
WiredHome 50:957161ecdd16 26 // make the name 'safe'
WiredHome 50:957161ecdd16 27 for (i=0; i<32 && myName[i]; i++) {
WiredHome 50:957161ecdd16 28 if (!inRange(myName[i], '0', '9')
WiredHome 50:957161ecdd16 29 && !inRange(myName[i], 'A', 'Z')
WiredHome 50:957161ecdd16 30 && !inRange(myName[i], 'a', 'z'))
WiredHome 50:957161ecdd16 31 myName[i] = '-';
WiredHome 50:957161ecdd16 32 }
WiredHome 50:957161ecdd16 33 netif_set_hostname(&netif, myName);
WiredHome 50:957161ecdd16 34 return 0;
WiredHome 50:957161ecdd16 35 }
WiredHome 50:957161ecdd16 36
WiredHome 50:957161ecdd16 37 const char * EthernetInterface::getName(void) {
WiredHome 50:957161ecdd16 38 return netif_get_hostname(&netif);
WiredHome 50:957161ecdd16 39 }
WiredHome 50:957161ecdd16 40
WiredHome 50:957161ecdd16 41 bool EthernetInterface::is_connected(void) {
WiredHome 50:957161ecdd16 42 uint32_t tmp = lpc_mii_read_data();
WiredHome 50:957161ecdd16 43
WiredHome 50:957161ecdd16 44 return (tmp & DP8_VALID_LINK) ? true : false;
WiredHome 50:957161ecdd16 45 }
WiredHome 50:957161ecdd16 46
WiredHome 50:957161ecdd16 47 int EthernetInterface::get_transmission_status(void) { // 1 = 1/2 duplex, 2 = full duplex
WiredHome 50:957161ecdd16 48 uint32_t tmp = lpc_mii_read_data();
WiredHome 50:957161ecdd16 49
WiredHome 50:957161ecdd16 50 if(tmp & DP8_FULLDUPLEX) {
WiredHome 50:957161ecdd16 51 return 2; // "FULL DUPLEX";
WiredHome 50:957161ecdd16 52 } else {
WiredHome 50:957161ecdd16 53 return 1; // "HALF DUPLEX";
WiredHome 50:957161ecdd16 54 }
WiredHome 50:957161ecdd16 55 }
WiredHome 50:957161ecdd16 56
WiredHome 50:957161ecdd16 57 int EthernetInterface::get_connection_speed(void) { // 10 or 100 Mb
WiredHome 50:957161ecdd16 58 uint32_t tmp = lpc_mii_read_data();
WiredHome 50:957161ecdd16 59
WiredHome 50:957161ecdd16 60 return (tmp & DP8_SPEED10MBPS) ? 10 : 100;
WiredHome 50:957161ecdd16 61 }
WiredHome 50:957161ecdd16 62
WiredHome 50:957161ecdd16 63 uint32_t EthernetInterface::mii_read_data(void) {
WiredHome 50:957161ecdd16 64 return lpc_mii_read_data(); // 16-bit MRDD - address 0x2008 4030
WiredHome 50:957161ecdd16 65 }