1
1
#include " STM32Ethernet.h"
2
2
#include " Dhcp.h"
3
3
4
+ EthernetClass::EthernetClass ()
5
+ {
6
+ MACAddressDefault ();
7
+ }
8
+
4
9
int EthernetClass::begin (unsigned long timeout, unsigned long responseTimeout)
5
10
{
6
11
static DhcpClass s_dhcp;
7
12
_dhcp = &s_dhcp;
8
- stm32_eth_init (MACAddressDefault () , NULL , NULL , NULL );
13
+ stm32_eth_init (_mac_address , NULL , NULL , NULL );
9
14
10
15
// Now try to get our config info from a DHCP server
11
- int ret = _dhcp->beginWithDHCP (mac_address , timeout, responseTimeout);
16
+ int ret = _dhcp->beginWithDHCP (_mac_address , timeout, responseTimeout);
12
17
if (ret == 1 ) {
13
18
_dnsServerAddress = _dhcp->getDnsServerIp ();
14
19
}
@@ -39,7 +44,7 @@ void EthernetClass::begin(IPAddress local_ip, IPAddress subnet, IPAddress gatewa
39
44
40
45
void EthernetClass::begin (IPAddress local_ip, IPAddress subnet, IPAddress gateway, IPAddress dns_server)
41
46
{
42
- stm32_eth_init (MACAddressDefault () , local_ip.raw_address (), gateway.raw_address (), subnet.raw_address ());
47
+ stm32_eth_init (_mac_address , local_ip.raw_address (), gateway.raw_address (), subnet.raw_address ());
43
48
/* If there is a local DHCP informs it of our manual IP configuration to
44
49
prevent IP conflict */
45
50
stm32_DHCP_manual_config ();
@@ -58,7 +63,7 @@ int EthernetClass::begin(uint8_t *mac_address, unsigned long timeout, unsigned l
58
63
if (ret == 1 ) {
59
64
_dnsServerAddress = _dhcp->getDnsServerIp ();
60
65
}
61
- MACAddress (mac_address);
66
+ setMACAddress (mac_address);
62
67
return ret;
63
68
}
64
69
@@ -86,14 +91,14 @@ void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dn
86
91
begin (mac_address, local_ip, dns_server, gateway, subnet);
87
92
}
88
93
89
- void EthernetClass::begin (uint8_t *mac , IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet)
94
+ void EthernetClass::begin (uint8_t *mac_address , IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet)
90
95
{
91
- stm32_eth_init (mac , local_ip.raw_address (), gateway.raw_address (), subnet.raw_address ());
96
+ stm32_eth_init (mac_address , local_ip.raw_address (), gateway.raw_address (), subnet.raw_address ());
92
97
/* If there is a local DHCP informs it of our manual IP configuration to
93
98
prevent IP conflict */
94
99
stm32_DHCP_manual_config ();
95
100
_dnsServerAddress = dns_server;
96
- MACAddress (mac );
101
+ setMACAddress (mac_address );
97
102
}
98
103
99
104
EthernetLinkStatus EthernetClass::linkStatus ()
@@ -135,31 +140,36 @@ void EthernetClass::schedule(void)
135
140
136
141
uint8_t *EthernetClass::MACAddressDefault (void )
137
142
{
138
- if ((mac_address [0 ] + mac_address [1 ] + mac_address [2 ] + mac_address [3 ] + mac_address [4 ] + mac_address [5 ]) == 0 ) {
143
+ if ((_mac_address [0 ] + _mac_address [1 ] + _mac_address [2 ] + _mac_address [3 ] + _mac_address [4 ] + _mac_address [5 ]) == 0 ) {
139
144
uint32_t baseUID = *(uint32_t *)UID_BASE;
140
- mac_address [0 ] = 0x00 ;
141
- mac_address [1 ] = 0x80 ;
142
- mac_address [2 ] = 0xE1 ;
143
- mac_address [3 ] = (baseUID & 0x00FF0000 ) >> 16 ;
144
- mac_address [4 ] = (baseUID & 0x0000FF00 ) >> 8 ;
145
- mac_address [5 ] = (baseUID & 0x000000FF );
145
+ _mac_address [0 ] = 0x00 ;
146
+ _mac_address [1 ] = 0x80 ;
147
+ _mac_address [2 ] = 0xE1 ;
148
+ _mac_address [3 ] = (baseUID & 0x00FF0000 ) >> 16 ;
149
+ _mac_address [4 ] = (baseUID & 0x0000FF00 ) >> 8 ;
150
+ _mac_address [5 ] = (baseUID & 0x000000FF );
146
151
}
147
- return mac_address ;
152
+ return _mac_address ;
148
153
}
149
154
150
- void EthernetClass::MACAddress ( uint8_t *mac )
155
+ void EthernetClass::setMACAddress ( const uint8_t *mac_address )
151
156
{
152
- mac_address [0 ] = mac [0 ];
153
- mac_address [1 ] = mac [1 ];
154
- mac_address [2 ] = mac [2 ];
155
- mac_address [3 ] = mac [3 ];
156
- mac_address [4 ] = mac [4 ];
157
- mac_address [5 ] = mac [5 ];
157
+ _mac_address [0 ] = mac_address [0 ];
158
+ _mac_address [1 ] = mac_address [1 ];
159
+ _mac_address [2 ] = mac_address [2 ];
160
+ _mac_address [3 ] = mac_address [3 ];
161
+ _mac_address [4 ] = mac_address [4 ];
162
+ _mac_address [5 ] = mac_address [5 ];
158
163
}
159
164
160
- uint8_t * EthernetClass::MACAddress (void )
165
+ void EthernetClass::MACAddress (uint8_t *mac_address )
161
166
{
162
- return mac_address;
167
+ mac_address[0 ] = _mac_address[0 ];
168
+ mac_address[1 ] = _mac_address[1 ];
169
+ mac_address[2 ] = _mac_address[2 ];
170
+ mac_address[3 ] = _mac_address[3 ];
171
+ mac_address[4 ] = _mac_address[4 ];
172
+ mac_address[5 ] = _mac_address[5 ];
163
173
}
164
174
165
175
IPAddress EthernetClass::localIP ()
0 commit comments