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 03 02:07:18 2018 +0000
Revision:
56:fc5d4611c70e
Parent:
55:3adba67dc7df
Revise error returns for unique ident of failures.

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 // CAUTION: This works with the LPC1768, but some of the interfaces may be unique to that part.
WiredHome 50:957161ecdd16 8 //
WiredHome 50:957161ecdd16 9 // Two steps integrate this:
WiredHome 50:957161ecdd16 10 //
WiredHome 50:957161ecdd16 11 // STEP 1: edit EthernetInterface.h as follows:
WiredHome 50:957161ecdd16 12 //
WiredHome 50:957161ecdd16 13 // class EthernetInterface {
WiredHome 50:957161ecdd16 14 // public:
WiredHome 50:957161ecdd16 15 // ... normal EthernetInterface APIs
WiredHome 50:957161ecdd16 16 //
WiredHome 50:957161ecdd16 17 // add this in the public section, at the bottom
WiredHome 50:957161ecdd16 18 // #include "EthernetInterface_Mods.h"
WiredHome 50:957161ecdd16 19 // };
WiredHome 50:957161ecdd16 20 //
WiredHome 50:957161ecdd16 21 // STEP 2: edit EthernetInterface.cpp as follows:
WiredHome 50:957161ecdd16 22 //
WiredHome 50:957161ecdd16 23 // // add this at the end of the file
WiredHome 50:957161ecdd16 24 // #include "EthernetInterface_Mods.hxx"
WiredHome 50:957161ecdd16 25 //
WiredHome 50:957161ecdd16 26 #ifndef ETHERNETINTERFACE_MODS_H
WiredHome 50:957161ecdd16 27 #define ETHERNETINTERFACE_MODS_H
WiredHome 50:957161ecdd16 28
WiredHome 50:957161ecdd16 29 //#include "lpc_phy.h" // needed for is_connected()
WiredHome 50:957161ecdd16 30
WiredHome 50:957161ecdd16 31 /** \brief DP83848 PHY status definitions */
WiredHome 50:957161ecdd16 32 #define DP8_REMOTEFAULT (1 << 6) /**< Remote fault */
WiredHome 50:957161ecdd16 33 #define DP8_FULLDUPLEX (1 << 2) /**< 1=full duplex */
WiredHome 50:957161ecdd16 34 #define DP8_SPEED10MBPS (1 << 1) /**< 1=10MBps speed */
WiredHome 50:957161ecdd16 35 #define DP8_VALID_LINK (1 << 0) /**< 1=Link active */
WiredHome 50:957161ecdd16 36
WiredHome 50:957161ecdd16 37
WiredHome 55:3adba67dc7df 38 /** setName
WiredHome 55:3adba67dc7df 39 *
WiredHome 55:3adba67dc7df 40 * Set the network name for this device. Apply this before
WiredHome 55:3adba67dc7df 41 * calling 'connect'.
WiredHome 55:3adba67dc7df 42 *
WiredHome 55:3adba67dc7df 43 * \example
WiredHome 55:3adba67dc7df 44 * EthernetInterface eth;
WiredHome 55:3adba67dc7df 45 * ...
WiredHome 55:3adba67dc7df 46 * if (0 == eth.init()) {
WiredHome 55:3adba67dc7df 47 * eth.setName("Sensor 3");
WiredHome 55:3adba67dc7df 48 * if (0 == eth.connect()) {
WiredHome 55:3adba67dc7df 49 * ...
WiredHome 55:3adba67dc7df 50 *
WiredHome 55:3adba67dc7df 51 * \param myname is the name to assign for this node.
WiredHome 55:3adba67dc7df 52 * Only the first 32 characters will be used if the
WiredHome 55:3adba67dc7df 53 * name is longer.
WiredHome 55:3adba67dc7df 54 * Only '0'-'9', 'A'-'Z', 'a'-'z' are accepted,
WiredHome 55:3adba67dc7df 55 * any others are converted to '-'.
WiredHome 55:3adba67dc7df 56 * \return 0 on success, a negative number on failure.
WiredHome 55:3adba67dc7df 57 */
WiredHome 55:3adba67dc7df 58 static int setName(const char * myname);
WiredHome 50:957161ecdd16 59
WiredHome 55:3adba67dc7df 60 /** getName
WiredHome 55:3adba67dc7df 61 *
WiredHome 55:3adba67dc7df 62 * Get the network name for this device.
WiredHome 55:3adba67dc7df 63 *
WiredHome 55:3adba67dc7df 64 * \return pointer to the name (or null)
WiredHome 55:3adba67dc7df 65 */
WiredHome 55:3adba67dc7df 66 static const char * getName(void);
WiredHome 50:957161ecdd16 67
WiredHome 55:3adba67dc7df 68 /** is_connected
WiredHome 55:3adba67dc7df 69 *
WiredHome 55:3adba67dc7df 70 * Determine if the interface is up and connected.
WiredHome 55:3adba67dc7df 71 *
WiredHome 55:3adba67dc7df 72 * \example
WiredHome 55:3adba67dc7df 73 * if (eth.is_connected())
WiredHome 55:3adba67dc7df 74 * ethLED = 1;
WiredHome 55:3adba67dc7df 75 * else
WiredHome 55:3adba67dc7df 76 * ethLED = 0;
WiredHome 55:3adba67dc7df 77 *
WiredHome 55:3adba67dc7df 78 * \return true if connected, false if not connected.
WiredHome 55:3adba67dc7df 79 */
WiredHome 55:3adba67dc7df 80 static bool is_connected(void);
WiredHome 55:3adba67dc7df 81
WiredHome 55:3adba67dc7df 82 /** get_transmission_status - full or half duplex.
WiredHome 55:3adba67dc7df 83 *
WiredHome 55:3adba67dc7df 84 * \return 1 = 1/2 (half) duplex, 2 = 2/2 (full) duplex
WiredHome 55:3adba67dc7df 85 */
WiredHome 55:3adba67dc7df 86 int get_transmission_status(void); // 1 = 1/2 duplex, 2 = full duplex
WiredHome 50:957161ecdd16 87
WiredHome 55:3adba67dc7df 88 /** get the speed of the connection.
WiredHome 55:3adba67dc7df 89 *
WiredHome 55:3adba67dc7df 90 * \return 10 or 100 Mb
WiredHome 55:3adba67dc7df 91 */
WiredHome 55:3adba67dc7df 92 int get_connection_speed(void); // 10 or 100 Mb
WiredHome 55:3adba67dc7df 93
WiredHome 55:3adba67dc7df 94 /** get the current value in the MII data register.
WiredHome 55:3adba67dc7df 95 *
WiredHome 55:3adba67dc7df 96 * \return mii register value
WiredHome 55:3adba67dc7df 97 */
WiredHome 55:3adba67dc7df 98 uint32_t mii_read_data(void);
WiredHome 55:3adba67dc7df 99
WiredHome 55:3adba67dc7df 100
WiredHome 55:3adba67dc7df 101
WiredHome 55:3adba67dc7df 102 /** set whether the link signal blinks on traffic, or is steady.
WiredHome 55:3adba67dc7df 103 *
WiredHome 55:3adba67dc7df 104 * @param[in] BlinkIt when non-zero sets the PHY register accordingly.
WiredHome 55:3adba67dc7df 105 *
WiredHome 55:3adba67dc7df 106 * @code
WiredHome 55:3adba67dc7df 107 * EthernetInterface eth;
WiredHome 55:3adba67dc7df 108 * eth.init();
WiredHome 55:3adba67dc7df 109 * eth.connect();
WiredHome 55:3adba67dc7df 110 * eth.LinkBlinkOnTraffic(1);
WiredHome 55:3adba67dc7df 111 * @endcode
WiredHome 55:3adba67dc7df 112 */
WiredHome 55:3adba67dc7df 113 void LinkBlinkOnTraffic(int BlinkIt);
WiredHome 50:957161ecdd16 114
WiredHome 50:957161ecdd16 115 #endif // ETHERNETINTERFACE_MODS_H