8
8
#include " arm_hal_phy.h"
9
9
#include " EMAC.h"
10
10
11
- class EMACPhy : public NanostackEthernetPhy
12
- {
11
+ class EMACPhy : public NanostackEthernetPhy {
13
12
public:
14
13
EMACPhy (NanostackMemoryManager &mem, EMAC &m);
15
14
virtual int8_t phy_register ();
16
15
virtual void get_mac_address (uint8_t *mac);
17
16
virtual void set_mac_address (uint8_t *mac);
18
17
19
- int8_t address_write (phy_address_type_e , uint8_t *);
20
- int8_t tx (uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle,data_protocol_e data_flow);
18
+ int8_t address_write (phy_address_type_e, uint8_t *);
19
+ int8_t tx (uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle, data_protocol_e data_flow);
21
20
22
21
void emac_phy_rx (emac_mem_buf_t *mem);
23
22
@@ -34,65 +33,65 @@ static EMACPhy *single_phy;
34
33
35
34
extern " C"
36
35
{
37
- static int8_t emac_phy_address_write (phy_address_type_e address_type, uint8_t *address_ptr)
38
- {
39
- return single_phy->address_write (address_type, address_ptr);
40
- }
36
+ static int8_t emac_phy_address_write (phy_address_type_e address_type, uint8_t *address_ptr)
37
+ {
38
+ return single_phy->address_write (address_type, address_ptr);
39
+ }
41
40
42
- static int8_t emac_phy_interface_state_control (phy_interface_state_e, uint8_t )
43
- {
44
- return -1 ;
45
- }
41
+ static int8_t emac_phy_interface_state_control (phy_interface_state_e, uint8_t )
42
+ {
43
+ return -1 ;
44
+ }
46
45
47
- static int8_t emac_phy_tx (uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle,data_protocol_e data_flow)
48
- {
49
- return single_phy->tx (data_ptr, data_len, tx_handle, data_flow);
50
- }
46
+ static int8_t emac_phy_tx (uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle, data_protocol_e data_flow)
47
+ {
48
+ return single_phy->tx (data_ptr, data_len, tx_handle, data_flow);
49
+ }
51
50
52
- EMACPhy::EMACPhy (NanostackMemoryManager &mem, EMAC &m) : memory_manager(mem), emac(m), device_id(-1 )
53
- {
54
- /* Same default address logic as lwIP glue uses */
51
+ EMACPhy::EMACPhy (NanostackMemoryManager &mem, EMAC &m) : memory_manager(mem), emac(m), device_id(-1 )
52
+ {
53
+ /* Same default address logic as lwIP glue uses */
55
54
#if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE)
56
- mac_addr[0 ] = MBED_MAC_ADDR_0;
57
- mac_addr[1 ] = MBED_MAC_ADDR_1;
58
- mac_addr[2 ] = MBED_MAC_ADDR_2;
59
- mac_addr[3 ] = MBED_MAC_ADDR_3;
60
- mac_addr[4 ] = MBED_MAC_ADDR_4;
61
- mac_addr[5 ] = MBED_MAC_ADDR_5;
55
+ mac_addr[0 ] = MBED_MAC_ADDR_0;
56
+ mac_addr[1 ] = MBED_MAC_ADDR_1;
57
+ mac_addr[2 ] = MBED_MAC_ADDR_2;
58
+ mac_addr[3 ] = MBED_MAC_ADDR_3;
59
+ mac_addr[4 ] = MBED_MAC_ADDR_4;
60
+ mac_addr[5 ] = MBED_MAC_ADDR_5;
62
61
#else
63
- mbed_mac_address ((char *) mac_addr);
62
+ mbed_mac_address ((char *) mac_addr);
64
63
#endif
65
- /* We have a default MAC address, so do don't force them to supply one */
66
- /* They may or may not update hwaddr with their address */
67
- emac.get_hwaddr (mac_addr);
68
- }
64
+ /* We have a default MAC address, so do don't force them to supply one */
65
+ /* They may or may not update hwaddr with their address */
66
+ emac.get_hwaddr (mac_addr);
67
+ }
69
68
70
69
71
- void EMACPhy::emac_phy_rx (emac_mem_buf_t *mem)
72
- {
73
- const uint8_t *ptr = NULL ;
74
- uint8_t *tmpbuf = NULL ;
75
- uint32_t total_len;
76
-
77
- if (memory_manager.get_next (mem) == NULL ) {
78
- // Easy contiguous case
79
- ptr = static_cast <const uint8_t *>(memory_manager.get_ptr (mem));
80
- total_len = memory_manager.get_len (mem);
81
- } else {
82
- // Nanostack can't accept chunked data - make temporary contiguous copy
83
- total_len = memory_manager.get_total_len (mem);
84
- ptr = tmpbuf = static_cast <uint8_t *>(ns_dyn_mem_temporary_alloc (total_len));
85
- if (tmpbuf) {
86
- memory_manager.copy_from_buf (tmpbuf, total_len, mem);
70
+ void EMACPhy::emac_phy_rx (emac_mem_buf_t *mem)
71
+ {
72
+ const uint8_t *ptr = NULL ;
73
+ uint8_t *tmpbuf = NULL ;
74
+ uint32_t total_len;
75
+
76
+ if (memory_manager.get_next (mem) == NULL ) {
77
+ // Easy contiguous case
78
+ ptr = static_cast <const uint8_t *>(memory_manager.get_ptr (mem));
79
+ total_len = memory_manager.get_len (mem);
80
+ } else {
81
+ // Nanostack can't accept chunked data - make temporary contiguous copy
82
+ total_len = memory_manager.get_total_len (mem);
83
+ ptr = tmpbuf = static_cast <uint8_t *>(ns_dyn_mem_temporary_alloc (total_len));
84
+ if (tmpbuf) {
85
+ memory_manager.copy_from_buf (tmpbuf, total_len, mem);
86
+ }
87
87
}
88
- }
89
88
90
- if (ptr && phy.phy_rx_cb ) {
91
- phy.phy_rx_cb (ptr, total_len, 0xff , 0 , device_id);
89
+ if (ptr && phy.phy_rx_cb ) {
90
+ phy.phy_rx_cb (ptr, total_len, 0xff , 0 , device_id);
91
+ }
92
+ ns_dyn_mem_free (tmpbuf);
93
+ memory_manager.free (mem);
92
94
}
93
- ns_dyn_mem_free (tmpbuf);
94
- memory_manager.free (mem);
95
- }
96
95
97
96
} // extern "C"
98
97
@@ -106,7 +105,7 @@ int8_t EMACPhy::address_write(phy_address_type_e address_type, uint8_t *address_
106
105
return 0 ;
107
106
}
108
107
109
- int8_t EMACPhy::tx (uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle,data_protocol_e data_flow)
108
+ int8_t EMACPhy::tx (uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle, data_protocol_e data_flow)
110
109
{
111
110
emac_mem_buf_t *mem = memory_manager.alloc_pool (data_len, 0 );
112
111
if (!mem) {
@@ -126,7 +125,7 @@ int8_t EMACPhy::phy_register()
126
125
127
126
phy.PHY_MAC = mac_addr;
128
127
phy.address_write = emac_phy_address_write;
129
- phy.driver_description = const_cast <char *>(" ETH" );
128
+ phy.driver_description = const_cast <char *>(" ETH" );
130
129
phy.link_type = PHY_LINK_ETHERNET_TYPE;
131
130
phy.phy_MTU = 0 ;
132
131
phy.phy_header_length = 0 ;
@@ -153,9 +152,9 @@ int8_t EMACPhy::phy_register()
153
152
emac.set_all_multicast (true );
154
153
155
154
device_id = arm_net_phy_register (&phy);
156
- // driver_readiness_status_callback = driver_status_cb;
155
+ // driver_readiness_status_callback = driver_status_cb;
157
156
158
- if (device_id < 0 ){
157
+ if (device_id < 0 ) {
159
158
// tr_error("Ethernet Driver failed to register with Stack. RetCode=%i", eth_driver_enabled);
160
159
// driver_readiness_status_callback(0, eth_interface_id);
161
160
emac.power_down ();
@@ -188,7 +187,7 @@ nsapi_error_t Nanostack::add_ethernet_interface(EMAC &emac, bool default_if, Nan
188
187
}
189
188
190
189
if (mac_addr) {
191
- single_phy->set_mac_address (const_cast <uint8_t *>(mac_addr));
190
+ single_phy->set_mac_address (const_cast <uint8_t *>(mac_addr));
192
191
}
193
192
194
193
Nanostack::EthernetInterface *interface;
0 commit comments