12Oct2012MbedLab
Fork of EthernetNetIf by
LPC2368/if/eth/EthernetNetIf.h@6:22ce63eddd2b, 2012-10-12 (annotated)
- Committer:
- psawant9
- Date:
- Fri Oct 12 16:02:00 2012 +0000
- Revision:
- 6:22ce63eddd2b
- Parent:
- 5:bc7df6da7589
Done
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
psawant9 | 6:22ce63eddd2b | 1 | |
psawant9 | 6:22ce63eddd2b | 2 | /* |
psawant9 | 6:22ce63eddd2b | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
psawant9 | 6:22ce63eddd2b | 4 | |
psawant9 | 6:22ce63eddd2b | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
psawant9 | 6:22ce63eddd2b | 6 | of this software and associated documentation files (the "Software"), to deal |
psawant9 | 6:22ce63eddd2b | 7 | in the Software without restriction, including without limitation the rights |
psawant9 | 6:22ce63eddd2b | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
psawant9 | 6:22ce63eddd2b | 9 | copies of the Software, and to permit persons to whom the Software is |
psawant9 | 6:22ce63eddd2b | 10 | furnished to do so, subject to the following conditions: |
psawant9 | 6:22ce63eddd2b | 11 | |
psawant9 | 6:22ce63eddd2b | 12 | The above copyright notice and this permission notice shall be included in |
psawant9 | 6:22ce63eddd2b | 13 | all copies or substantial portions of the Software. |
psawant9 | 6:22ce63eddd2b | 14 | |
psawant9 | 6:22ce63eddd2b | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
psawant9 | 6:22ce63eddd2b | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
psawant9 | 6:22ce63eddd2b | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
psawant9 | 6:22ce63eddd2b | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
psawant9 | 6:22ce63eddd2b | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
psawant9 | 6:22ce63eddd2b | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
psawant9 | 6:22ce63eddd2b | 21 | THE SOFTWARE. |
psawant9 | 6:22ce63eddd2b | 22 | */ |
psawant9 | 6:22ce63eddd2b | 23 | |
psawant9 | 6:22ce63eddd2b | 24 | /** \file |
psawant9 | 6:22ce63eddd2b | 25 | Ethernet network interface header file |
psawant9 | 6:22ce63eddd2b | 26 | */ |
psawant9 | 6:22ce63eddd2b | 27 | |
psawant9 | 6:22ce63eddd2b | 28 | #ifndef ETHERNETNETIF_H |
psawant9 | 6:22ce63eddd2b | 29 | #define ETHERNETNETIF_H |
psawant9 | 6:22ce63eddd2b | 30 | |
psawant9 | 6:22ce63eddd2b | 31 | struct netif; |
psawant9 | 6:22ce63eddd2b | 32 | |
psawant9 | 6:22ce63eddd2b | 33 | #include "mbed.h" |
psawant9 | 6:22ce63eddd2b | 34 | |
psawant9 | 6:22ce63eddd2b | 35 | #include "if/lwip/LwipNetIf.h" |
psawant9 | 6:22ce63eddd2b | 36 | |
psawant9 | 6:22ce63eddd2b | 37 | ///Ethernet network interface return codes |
psawant9 | 6:22ce63eddd2b | 38 | enum EthernetErr |
psawant9 | 6:22ce63eddd2b | 39 | { |
psawant9 | 6:22ce63eddd2b | 40 | __ETH_MIN = -0xFFFF, |
psawant9 | 6:22ce63eddd2b | 41 | ETH_TIMEOUT, ///<Timeout during setup |
psawant9 | 6:22ce63eddd2b | 42 | ETH_OK = 0 ///<Success |
psawant9 | 6:22ce63eddd2b | 43 | }; |
psawant9 | 6:22ce63eddd2b | 44 | |
psawant9 | 6:22ce63eddd2b | 45 | ///Ethernet network interface |
psawant9 | 6:22ce63eddd2b | 46 | /** |
psawant9 | 6:22ce63eddd2b | 47 | This class provides Ethernet connectivity to the stack |
psawant9 | 6:22ce63eddd2b | 48 | */ |
psawant9 | 6:22ce63eddd2b | 49 | class EthernetNetIf : public LwipNetIf |
psawant9 | 6:22ce63eddd2b | 50 | { |
psawant9 | 6:22ce63eddd2b | 51 | public: |
psawant9 | 6:22ce63eddd2b | 52 | ///Instantiates the Interface and register it against the stack, DHCP will be used |
psawant9 | 6:22ce63eddd2b | 53 | EthernetNetIf(); //W/ DHCP |
psawant9 | 6:22ce63eddd2b | 54 | |
psawant9 | 6:22ce63eddd2b | 55 | ///Instantiates the Interface and register it against the stack, DHCP will not be used |
psawant9 | 6:22ce63eddd2b | 56 | /** |
psawant9 | 6:22ce63eddd2b | 57 | IpAddr is a container class that can be constructed with either 4 bytes or no parameters for a null IP address. |
psawant9 | 6:22ce63eddd2b | 58 | */ |
psawant9 | 6:22ce63eddd2b | 59 | EthernetNetIf(IpAddr ip, IpAddr netmask, IpAddr gateway, IpAddr dns); //W/o DHCP |
psawant9 | 6:22ce63eddd2b | 60 | virtual ~EthernetNetIf(); |
psawant9 | 6:22ce63eddd2b | 61 | |
psawant9 | 6:22ce63eddd2b | 62 | ///Brings the interface up |
psawant9 | 6:22ce63eddd2b | 63 | /** |
psawant9 | 6:22ce63eddd2b | 64 | Uses DHCP if necessary |
psawant9 | 6:22ce63eddd2b | 65 | @param timeout_ms : You can set the timeout parameter in milliseconds, if not it defaults to 15s |
psawant9 | 6:22ce63eddd2b | 66 | @return : ETH_OK on success or ETH_TIMEOUT on timeout |
psawant9 | 6:22ce63eddd2b | 67 | */ |
psawant9 | 6:22ce63eddd2b | 68 | EthernetErr setup(int timeout_ms = 15000); |
psawant9 | 6:22ce63eddd2b | 69 | |
psawant9 | 6:22ce63eddd2b | 70 | virtual void poll(); |
psawant9 | 6:22ce63eddd2b | 71 | |
psawant9 | 6:22ce63eddd2b | 72 | private: |
psawant9 | 6:22ce63eddd2b | 73 | Timer m_ethArpTimer; |
psawant9 | 6:22ce63eddd2b | 74 | Timer m_dhcpCoarseTimer; |
psawant9 | 6:22ce63eddd2b | 75 | Timer m_dhcpFineTimer; |
psawant9 | 6:22ce63eddd2b | 76 | Timer m_igmpTimer; |
psawant9 | 6:22ce63eddd2b | 77 | |
psawant9 | 6:22ce63eddd2b | 78 | bool m_useDhcp; |
psawant9 | 6:22ce63eddd2b | 79 | |
psawant9 | 6:22ce63eddd2b | 80 | netif* m_pNetIf; |
psawant9 | 6:22ce63eddd2b | 81 | |
psawant9 | 6:22ce63eddd2b | 82 | IpAddr m_netmask; |
psawant9 | 6:22ce63eddd2b | 83 | IpAddr m_gateway; |
psawant9 | 6:22ce63eddd2b | 84 | |
psawant9 | 6:22ce63eddd2b | 85 | const char* m_hostname; |
psawant9 | 6:22ce63eddd2b | 86 | |
psawant9 | 6:22ce63eddd2b | 87 | }; |
psawant9 | 6:22ce63eddd2b | 88 | |
psawant9 | 6:22ce63eddd2b | 89 | #endif |
psawant9 | 6:22ce63eddd2b | 90 |