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@53:bbcf2853e575, 2017-04-09 (annotated)
- Committer:
- WiredHome
- Date:
- Sun Apr 09 20:58:42 2017 +0000
- Revision:
- 53:bbcf2853e575
- Parent:
- 50:957161ecdd16
Added an API to configure the PHY to blink the Link LED on data traffic.
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 | 53:bbcf2853e575 | 17 | // add this in the public section, at the bottom |
WiredHome | 53:bbcf2853e575 | 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 | 53:bbcf2853e575 | 38 | /** setName |
WiredHome | 53:bbcf2853e575 | 39 | * |
WiredHome | 53:bbcf2853e575 | 40 | * Set the network name for this device. Apply this before |
WiredHome | 53:bbcf2853e575 | 41 | * calling 'connect'. |
WiredHome | 53:bbcf2853e575 | 42 | * |
WiredHome | 53:bbcf2853e575 | 43 | * \example |
WiredHome | 53:bbcf2853e575 | 44 | * EthernetInterface eth; |
WiredHome | 53:bbcf2853e575 | 45 | * ... |
WiredHome | 53:bbcf2853e575 | 46 | * if (0 == eth.init()) { |
WiredHome | 53:bbcf2853e575 | 47 | * eth.setName("Sensor 3"); |
WiredHome | 53:bbcf2853e575 | 48 | * if (0 == eth.connect()) { |
WiredHome | 53:bbcf2853e575 | 49 | * ... |
WiredHome | 53:bbcf2853e575 | 50 | * |
WiredHome | 53:bbcf2853e575 | 51 | * \param myname is the name to assign for this node. |
WiredHome | 53:bbcf2853e575 | 52 | * Only the first 32 characters will be used if the |
WiredHome | 53:bbcf2853e575 | 53 | * name is longer. |
WiredHome | 53:bbcf2853e575 | 54 | * Only '0'-'9', 'A'-'Z', 'a'-'z' are accepted, |
WiredHome | 53:bbcf2853e575 | 55 | * any others are converted to '-'. |
WiredHome | 53:bbcf2853e575 | 56 | * \return 0 on success, a negative number on failure. |
WiredHome | 53:bbcf2853e575 | 57 | */ |
WiredHome | 53:bbcf2853e575 | 58 | static int setName(const char * myname); |
WiredHome | 50:957161ecdd16 | 59 | |
WiredHome | 53:bbcf2853e575 | 60 | /** getName |
WiredHome | 53:bbcf2853e575 | 61 | * |
WiredHome | 53:bbcf2853e575 | 62 | * Get the network name for this device. |
WiredHome | 53:bbcf2853e575 | 63 | * |
WiredHome | 53:bbcf2853e575 | 64 | * \return pointer to the name (or null) |
WiredHome | 53:bbcf2853e575 | 65 | */ |
WiredHome | 53:bbcf2853e575 | 66 | static const char * getName(void); |
WiredHome | 50:957161ecdd16 | 67 | |
WiredHome | 53:bbcf2853e575 | 68 | /** is_connected |
WiredHome | 53:bbcf2853e575 | 69 | * |
WiredHome | 53:bbcf2853e575 | 70 | * Determine if the interface is up and connected. |
WiredHome | 53:bbcf2853e575 | 71 | * |
WiredHome | 53:bbcf2853e575 | 72 | * \example |
WiredHome | 53:bbcf2853e575 | 73 | * if (eth.is_connected()) |
WiredHome | 53:bbcf2853e575 | 74 | * ethLED = 1; |
WiredHome | 53:bbcf2853e575 | 75 | * else |
WiredHome | 53:bbcf2853e575 | 76 | * ethLED = 0; |
WiredHome | 53:bbcf2853e575 | 77 | * |
WiredHome | 53:bbcf2853e575 | 78 | * \return true if connected, false if not connected. |
WiredHome | 53:bbcf2853e575 | 79 | */ |
WiredHome | 53:bbcf2853e575 | 80 | static bool is_connected(void); |
WiredHome | 53:bbcf2853e575 | 81 | |
WiredHome | 53:bbcf2853e575 | 82 | /** get_transmission_status - full or half duplex. |
WiredHome | 53:bbcf2853e575 | 83 | * |
WiredHome | 53:bbcf2853e575 | 84 | * \return 1 = 1/2 (half) duplex, 2 = 2/2 (full) duplex |
WiredHome | 53:bbcf2853e575 | 85 | */ |
WiredHome | 53:bbcf2853e575 | 86 | int get_transmission_status(void); // 1 = 1/2 duplex, 2 = full duplex |
WiredHome | 50:957161ecdd16 | 87 | |
WiredHome | 53:bbcf2853e575 | 88 | /** get the speed of the connection. |
WiredHome | 53:bbcf2853e575 | 89 | * |
WiredHome | 53:bbcf2853e575 | 90 | * \return 10 or 100 Mb |
WiredHome | 53:bbcf2853e575 | 91 | */ |
WiredHome | 53:bbcf2853e575 | 92 | int get_connection_speed(void); // 10 or 100 Mb |
WiredHome | 53:bbcf2853e575 | 93 | |
WiredHome | 53:bbcf2853e575 | 94 | /** get the current value in the MII data register. |
WiredHome | 53:bbcf2853e575 | 95 | * |
WiredHome | 53:bbcf2853e575 | 96 | * \return mii register value |
WiredHome | 53:bbcf2853e575 | 97 | */ |
WiredHome | 53:bbcf2853e575 | 98 | uint32_t mii_read_data(void); |
WiredHome | 53:bbcf2853e575 | 99 | |
WiredHome | 53:bbcf2853e575 | 100 | /** set whether the link signal blinks on traffic, or is steady. |
WiredHome | 53:bbcf2853e575 | 101 | * |
WiredHome | 53:bbcf2853e575 | 102 | * \param BlinkIt when non-zero sets the PHY register accordingly. |
WiredHome | 53:bbcf2853e575 | 103 | * |
WiredHome | 53:bbcf2853e575 | 104 | * \code |
WiredHome | 53:bbcf2853e575 | 105 | * EthernetInterface eth; |
WiredHome | 53:bbcf2853e575 | 106 | * eth.init(); |
WiredHome | 53:bbcf2853e575 | 107 | * eth.connect(); |
WiredHome | 53:bbcf2853e575 | 108 | * eth.LinkBlinkOnTraffic(1); |
WiredHome | 53:bbcf2853e575 | 109 | * \endcode |
WiredHome | 53:bbcf2853e575 | 110 | */ |
WiredHome | 53:bbcf2853e575 | 111 | void LinkBlinkOnTraffic(int BlinkIt); |
WiredHome | 50:957161ecdd16 | 112 | |
WiredHome | 50:957161ecdd16 | 113 | #endif // ETHERNETINTERFACE_MODS_H |