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
Diff: EthernetInterface_Mods.hxx
- Revision:
- 50:957161ecdd16
- Child:
- 53:bbcf2853e575
--- /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