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
EthernetInterface_Mods.hxx
00001 // 00002 // EthernetInterface Modifications to enhance it slightly. 00003 // 00004 // This set of modifications integrates with the mbed standard EthernetInterface stack. 00005 // It does require one-line modifications of both EthernetInterface.h and EthernetInterface.cpp. 00006 // 00007 // See the details at the top of EthernetInterface_Mods.h 00008 // 00009 #include "lpc_phy.h" 00010 00011 static char myName[33]; // holds the name, when setName() is called. 00012 00013 static bool inRange(char testChar, char minChar, char maxChar) 00014 { 00015 if (testChar >= minChar && testChar <= maxChar) 00016 return true; 00017 else 00018 return false; 00019 } 00020 00021 int EthernetInterface::setName(const char * myname) { 00022 int i; 00023 00024 strncpy(myName, myname, 32); 00025 myName[32] = '\0'; // be sure it is NULL terminated. 00026 // make the name 'safe' 00027 for (i=0; i<32 && myName[i]; i++) { 00028 if (!inRange(myName[i], '0', '9') 00029 && !inRange(myName[i], 'A', 'Z') 00030 && !inRange(myName[i], 'a', 'z')) 00031 myName[i] = '-'; 00032 } 00033 netif_set_hostname(&netif, myName); 00034 return 0; 00035 } 00036 00037 const char * EthernetInterface::getName(void) { 00038 return netif_get_hostname(&netif); 00039 } 00040 00041 bool EthernetInterface::is_connected(void) { 00042 uint32_t tmp = lpc_mii_read_data(); 00043 00044 return (tmp & DP8_VALID_LINK) ? true : false; 00045 } 00046 00047 int EthernetInterface::get_transmission_status(void) { // 1 = 1/2 duplex, 2 = full duplex 00048 uint32_t tmp = lpc_mii_read_data(); 00049 00050 if(tmp & DP8_FULLDUPLEX) { 00051 return 2; // "FULL DUPLEX"; 00052 } else { 00053 return 1; // "HALF DUPLEX"; 00054 } 00055 } 00056 00057 int EthernetInterface::get_connection_speed(void) { // 10 or 100 Mb 00058 uint32_t tmp = lpc_mii_read_data(); 00059 00060 return (tmp & DP8_SPEED10MBPS) ? 10 : 100; 00061 } 00062 00063 uint32_t EthernetInterface::mii_read_data(void) { 00064 return lpc_mii_read_data(); // 16-bit MRDD - address 0x2008 4030 00065 } 00066 00067 void EthernetInterface::LinkBlinkOnTraffic(int BlinkIt) 00068 { 00069 uint32_t data; 00070 00071 if (lpc_mii_read(0x19, &data) == ERR_OK) { 00072 data &= ~(1 << 5); // Mode 2, link status blinks on data 00073 if (!BlinkIt) 00074 data |= (1 << 5); // Mode 1, link status only 00075 if (lpc_mii_write(0x19, data) != ERR_OK) { 00076 printf("LED Reconfig attempt failed.\r\n"); 00077 } 00078 } 00079 }
Generated on Thu Jul 14 2022 10:38:38 by 1.7.2