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.h@50:957161ecdd16, 2015-07-07 (annotated)
- Committer:
- WiredHome
- Date:
- Tue Jul 07 14:10:01 2015 +0000
- Revision:
- 50:957161ecdd16
- Child:
- 53:bbcf2853e575
- Child:
- 55:3adba67dc7df
Integrate the setName API, as well as ability to determine if link is up, and connected rate.
Who changed what in which revision?
User | Revision | Line number | New 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 | 50:957161ecdd16 | 38 | /** setName |
WiredHome | 50:957161ecdd16 | 39 | * |
WiredHome | 50:957161ecdd16 | 40 | * Set the network name for this device. Apply this before |
WiredHome | 50:957161ecdd16 | 41 | * calling 'connect'. |
WiredHome | 50:957161ecdd16 | 42 | * |
WiredHome | 50:957161ecdd16 | 43 | * \example |
WiredHome | 50:957161ecdd16 | 44 | * EthernetInterface eth; |
WiredHome | 50:957161ecdd16 | 45 | * ... |
WiredHome | 50:957161ecdd16 | 46 | * if (0 == eth.init()) { |
WiredHome | 50:957161ecdd16 | 47 | * eth.setName("Sensor 3"); |
WiredHome | 50:957161ecdd16 | 48 | * if (0 == eth.connect()) { |
WiredHome | 50:957161ecdd16 | 49 | * ... |
WiredHome | 50:957161ecdd16 | 50 | * |
WiredHome | 50:957161ecdd16 | 51 | * \param myname is the name to assign for this node. |
WiredHome | 50:957161ecdd16 | 52 | * Only the first 32 characters will be used if the |
WiredHome | 50:957161ecdd16 | 53 | * name is longer. |
WiredHome | 50:957161ecdd16 | 54 | * Only '0'-'9', 'A'-'Z', 'a'-'z' are accepted, |
WiredHome | 50:957161ecdd16 | 55 | * any others are converted to '-'. |
WiredHome | 50:957161ecdd16 | 56 | * \return 0 on success, a negative number on failure. |
WiredHome | 50:957161ecdd16 | 57 | */ |
WiredHome | 50:957161ecdd16 | 58 | static int setName(const char * myname); |
WiredHome | 50:957161ecdd16 | 59 | |
WiredHome | 50:957161ecdd16 | 60 | /** getName |
WiredHome | 50:957161ecdd16 | 61 | * |
WiredHome | 50:957161ecdd16 | 62 | * Get the network name for this device. |
WiredHome | 50:957161ecdd16 | 63 | * |
WiredHome | 50:957161ecdd16 | 64 | * \return pointer to the name (or null) |
WiredHome | 50:957161ecdd16 | 65 | */ |
WiredHome | 50:957161ecdd16 | 66 | static const char * getName(void); |
WiredHome | 50:957161ecdd16 | 67 | |
WiredHome | 50:957161ecdd16 | 68 | /** is_connected |
WiredHome | 50:957161ecdd16 | 69 | * |
WiredHome | 50:957161ecdd16 | 70 | * Determine if the interface is up and connected. |
WiredHome | 50:957161ecdd16 | 71 | * |
WiredHome | 50:957161ecdd16 | 72 | * \example |
WiredHome | 50:957161ecdd16 | 73 | * if (eth.is_connected()) |
WiredHome | 50:957161ecdd16 | 74 | * ethLED = 1; |
WiredHome | 50:957161ecdd16 | 75 | * else |
WiredHome | 50:957161ecdd16 | 76 | * ethLED = 0; |
WiredHome | 50:957161ecdd16 | 77 | * |
WiredHome | 50:957161ecdd16 | 78 | * \return true if connected, false if not connected. |
WiredHome | 50:957161ecdd16 | 79 | */ |
WiredHome | 50:957161ecdd16 | 80 | static bool is_connected(void); |
WiredHome | 50:957161ecdd16 | 81 | |
WiredHome | 50:957161ecdd16 | 82 | /** get_transmission_status - full or half duplex. |
WiredHome | 50:957161ecdd16 | 83 | * |
WiredHome | 50:957161ecdd16 | 84 | * \return 1 = 1/2 (half) duplex, 2 = 2/2 (full) duplex |
WiredHome | 50:957161ecdd16 | 85 | */ |
WiredHome | 50:957161ecdd16 | 86 | int get_transmission_status(void); // 1 = 1/2 duplex, 2 = full duplex |
WiredHome | 50:957161ecdd16 | 87 | |
WiredHome | 50:957161ecdd16 | 88 | /** get the speed of the connection. |
WiredHome | 50:957161ecdd16 | 89 | * |
WiredHome | 50:957161ecdd16 | 90 | * \return 10 or 100 Mb |
WiredHome | 50:957161ecdd16 | 91 | */ |
WiredHome | 50:957161ecdd16 | 92 | int get_connection_speed(void); // 10 or 100 Mb |
WiredHome | 50:957161ecdd16 | 93 | |
WiredHome | 50:957161ecdd16 | 94 | /** get the current value in the MII data register. |
WiredHome | 50:957161ecdd16 | 95 | * |
WiredHome | 50:957161ecdd16 | 96 | * \return mii register value |
WiredHome | 50:957161ecdd16 | 97 | */ |
WiredHome | 50:957161ecdd16 | 98 | uint32_t mii_read_data(void); |
WiredHome | 50:957161ecdd16 | 99 | |
WiredHome | 50:957161ecdd16 | 100 | |
WiredHome | 50:957161ecdd16 | 101 | #endif // ETHERNETINTERFACE_MODS_H |