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