Dependencies:   mbed

Committer:
gbeardall
Date:
Mon Oct 17 10:39:17 2011 +0000
Revision:
0:715023d993d6

        

Who changed what in which revision?

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