Dependencies:   mbed

Committer:
robertcook
Date:
Wed Jun 13 18:39:46 2012 +0000
Revision:
0:32a0996dff0f

        

Who changed what in which revision?

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