Dependents:   RTnoV3 RTnoV3_LED RTnoV3_Template RTnoV3_ADC ... more

Committer:
sherckuith
Date:
Sat Dec 31 11:25:27 2011 +0000
Revision:
0:479ce5546098
Ethernet

Who changed what in which revision?

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