13
13
class EMACPhy : public NanostackEthernetPhy
14
14
{
15
15
public:
16
- EMACPhy (NanostackMemoryManager &mem, EMAC &m) : memory_manager(mem), emac(m), device_id(- 1 ) { }
16
+ EMACPhy (NanostackMemoryManager &mem, EMAC &m);
17
17
virtual int8_t phy_register ();
18
18
virtual void get_mac_address (uint8_t *mac);
19
19
virtual void set_mac_address (uint8_t *mac);
@@ -52,6 +52,25 @@ static int8_t emac_phy_tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handl
52
52
return single_phy->tx (data_ptr, data_len, tx_handle, data_flow);
53
53
}
54
54
55
+ EMACPhy::EMACPhy (NanostackMemoryManager &mem, EMAC &m) : memory_manager(mem), emac(m), device_id(-1 )
56
+ {
57
+ /* Same default address logic as lwIP glue uses */
58
+ #if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE)
59
+ mac_addr[0 ] = MBED_MAC_ADDR_0;
60
+ mac_addr[1 ] = MBED_MAC_ADDR_1;
61
+ mac_addr[2 ] = MBED_MAC_ADDR_2;
62
+ mac_addr[3 ] = MBED_MAC_ADDR_3;
63
+ mac_addr[4 ] = MBED_MAC_ADDR_4;
64
+ mac_addr[5 ] = MBED_MAC_ADDR_5;
65
+ #else
66
+ mbed_mac_address ((char *) mac_addr);
67
+ #endif
68
+ /* We have a default MAC address, so do don't force them to supply one */
69
+ /* They may or may not update hwaddr with their address */
70
+ emac.get_hwaddr (mac_addr);
71
+ }
72
+
73
+
55
74
void EMACPhy::emac_phy_rx (emac_mem_buf_t *mem)
56
75
{
57
76
const uint8_t *ptr = NULL ;
@@ -115,23 +134,11 @@ int8_t EMACPhy::phy_register()
115
134
return -1 ;
116
135
}
117
136
118
- /* Same default address logic as lwIP glue uses */
119
- #if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE)
120
- mac_addr[0 ] = MBED_MAC_ADDR_0;
121
- mac_addr[1 ] = MBED_MAC_ADDR_1;
122
- mac_addr[2 ] = MBED_MAC_ADDR_2;
123
- mac_addr[3 ] = MBED_MAC_ADDR_3;
124
- mac_addr[4 ] = MBED_MAC_ADDR_4;
125
- mac_addr[5 ] = MBED_MAC_ADDR_5;
126
- #else
127
- mbed_mac_address ((char *) mac_addr);
128
- #endif
129
-
130
137
phy.phy_MTU = emac.get_mtu_size ();
131
- /* We have a default MAC address, so do don't force them to supply one */
132
- /* They may or may not update hwaddr with their address */
133
- emac. get_hwaddr (mac_addr);
134
- /* Then we write back either what they gave us, or our default */
138
+ /* Set the address - this could be either board default, what they
139
+ * told us with EMAC::get_mac_address, or something manually specified
140
+ * with EMACPhy::set_mac_address
141
+ */
135
142
emac.set_hwaddr (mac_addr);
136
143
137
144
emac.set_all_multicast (true );
@@ -171,7 +178,7 @@ void EMACPhy::set_mac_address(uint8_t *mac)
171
178
memcpy (mac_addr, mac, sizeof mac_addr);
172
179
}
173
180
174
- nsapi_error_t Nanostack::add_ethernet_interface (EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out)
181
+ nsapi_error_t Nanostack::add_ethernet_interface (EMAC &emac, bool default_if, Nanostack::EthernetInterface **interface_out, const uint8_t *mac_addr )
175
182
{
176
183
if (single_phy) {
177
184
return NSAPI_ERROR_DEVICE_ERROR;
@@ -182,6 +189,10 @@ nsapi_error_t Nanostack::add_ethernet_interface(EMAC &emac, bool default_if, Onb
182
189
return NSAPI_ERROR_NO_MEMORY;
183
190
}
184
191
192
+ if (mac_addr) {
193
+ single_phy->set_mac_address (const_cast <uint8_t *>(mac_addr));
194
+ }
195
+
185
196
Nanostack::EthernetInterface *interface;
186
197
187
198
interface = new (nothrow) Nanostack::EthernetInterface (*single_phy);
@@ -197,5 +208,14 @@ nsapi_error_t Nanostack::add_ethernet_interface(EMAC &emac, bool default_if, Onb
197
208
*interface_out = interface;
198
209
199
210
return NSAPI_ERROR_OK;
211
+
212
+ }
213
+
214
+ nsapi_error_t Nanostack::add_ethernet_interface (EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out)
215
+ {
216
+ Nanostack::EthernetInterface *interface;
217
+ nsapi_error_t err = add_ethernet_interface (emac, default_if, &interface);
218
+ *interface_out = interface;
219
+ return err;
200
220
}
201
221
#endif
0 commit comments