1 /* -----------------------------------------------------------------------------
\r
2 * Copyright (c) 2013-2014 ARM Limited. All rights reserved.
\r
4 * $Date: 2. January 2014
\r
7 * Project: Ethernet Driver API
\r
8 * -------------------------------------------------------------------------- */
\r
12 \defgroup eth_interface_gr Ethernet Interface
\r
13 \brief Ethernet common definitions (%Driver_ETH.h)
\r
16 <b>Ethernet</b> is a networking technology for exchanging data packages between computer systems. Several microcontrollers integrate
\r
17 an Ethernet MAC (Media Access Control) data-link layer that interfaces to an Ethernet PHY (Physical Interface Transceiver).
\r
19 Wikipedia offers more information about
\r
20 the <a href="http://en.wikipedia.org/wiki/Ethernet" target="_blank"><b>Ethernet</b></a>.
\r
25 The Ethernet PHY connects typically to the Ethernet MAC using an MII (Media Independent Interface) or RMII (Reduced Media Independent Interface).
\r
28 \image html EthernetSchematic.png "Block Diagram of a typical Ethernet Interface"
\r
33 The following header files define the Application Programming Interface (API) for the <b>Ethernet</b> interface:
\r
34 - \b %Driver_ETH.h : Common definitions of the Ethernet PHY and MAC part
\r
35 - \b %Driver_ETH_MAC.h : API for the Ethernet MAC
\r
36 - \b %Driver_ETH_PHY.h : API for the Ethernet PHY
\r
38 The driver implementation of the Ethernet MAC is a typical part of a Device Family Pack (DFP) that supports the peripherals of the microcontroller family.
\r
39 The driver implementation of the Ethernet PHY is a typical part of a \b Network Software Pack, since PHY is typically not integrated into the microcontroller.
\r
42 For parameters, the value marked with (default) is the setting after the driver initialization.
\r
45 **Driver Functions**
\r
47 The driver functions are published in the access struct as explained in \ref DriverFunctions
\r
48 - \ref ARM_DRIVER_ETH_MAC : access struct for <b>Ethernet MAC</b> driver functions.
\r
49 - \ref ARM_DRIVER_ETH_PHY : access struct for <b>Ethernet PHY</b> driver functions.
\r
51 Both drivers are used in combination and usually the Ethernet MAC provides a media interface to the Ethernet PHY.
\r
52 A typical setup sequence for the drivers is shown below:
\r
56 The following example code shows the usage of the Ethernet interface.
\r
59 extern ARM_DRIVER_ETH_MAC Driver_ETH_MAC0;
\r
60 extern ARM_DRIVER_ETH_PHY Driver_ETH_PHY0;
\r
62 static ARM_DRIVER_ETH_MAC *mac;
\r
63 static ARM_DRIVER_ETH_PHY *phy;
\r
64 static ARM_ETH_MAC_ADDR own_mac_address;
\r
65 static ARM_ETH_MAC_CAPABILITIES capabilities;
\r
67 void ethernet_mac_notify (uint32_t event) {
\r
74 void initialize_ethernet_interface (void) {
\r
75 mac = &Driver_ETH_MAC0;
\r
76 phy = &Driver_ETH_PHY0;
\r
78 // Initialize Media Access Controller
\r
79 capabilities = mac->GetCapabilities ();
\r
81 mac->Initialize (ethernet_mac_notify);
\r
82 mac->PowerControl (ARM_POWER_FULL);
\r
84 if (capabilities.mac_address == 0) {
\r
85 // populate own_mac_address with the address to use
\r
86 mac->SetMacAddress(&own_mac_address);
\r
89 mac->GetMacAddress(&own_mac_address);
\r
92 // Initialize Physical Media Interface
\r
93 if (phy->Initialize (mac->PHY_Read, mac->PHY_Write) == ARM_DRIVER_OK) {
\r
94 phy->PowerControl (ARM_POWER_FULL);
\r
95 phy->SetInterface (capabilities.media_interface);
\r
96 phy->SetMode (ARM_ETH_PHY_AUTO_NEGOTIATE);
\r
103 static ARM_ETH_LINK_STATE ethernet_link; // current link status
\r
105 void ethernet_check_link_status (void) {
\r
106 ARM_ETH_LINK_STATE link;
\r
108 link = phy->GetLinkState ();
\r
109 if (link == ethernet_link) {
\r
110 return; // link state unchanged
\r
112 // link state changed
\r
113 ethernet_link = link;
\r
114 if (link == ARM_ETH_LINK_UP) { // start transfer
\r
115 ARM_ETH_LINK_INFO info = phy->GetLinkInfo ();
\r
116 mac->Control(ARM_ETH_MAC_CONFIGURE,
\r
117 info.speed << ARM_ETH_MAC_SPEED_Pos |
\r
118 info.duplex << ARM_ETH_MAC_DUPLEX_Pos |
\r
119 ARM_ETH_MAC_ADDRESS_BROADCAST);
\r
120 mac->Control(ARM_ETH_MAC_CONTROL_TX, 1);
\r
121 mac->Control(ARM_ETH_MAC_CONTROL_RX, 1);
\r
123 else { // stop transfer
\r
124 mac->Control(ARM_ETH_MAC_FLUSH, ARM_ETH_MAC_FLUSH_TX | ARM_ETH_MAC_FLUSH_RX);
\r
125 mac->Control(ARM_ETH_MAC_CONTROL_TX, 0);
\r
126 mac->Control(ARM_ETH_MAC_CONTROL_RX, 0);
\r
134 \defgroup eth_interface_gr Ethernet Interface
\r
143 \enum ARM_ETH_INTERFACE
\r
145 Encodes the supported media interface between Ethernet MAC and Ethernet PHY.
\r
147 The function \ref ARM_ETH_MAC_GetCapabilities retrieves the media interface type encoded in the data field \b media_interface of the struct
\r
148 \ref ARM_ETH_MAC_CAPABILITIES.
\r
150 <b>Parameter for:</b>
\r
151 - \ref ARM_ETH_PHY_SetInterface
\r
155 \enum ARM_ETH_DUPLEX
\r
157 Lists the supported duplex operating types for MAC.
\r
159 <b>Parameter for:</b>
\r
160 - \ref ARM_ETH_MAC_SetMode
\r
165 \typedef ARM_ETH_SPEED
\r
167 Lists the supported operating speeds for MAC.
\r
169 <b>Parameter for:</b>
\r
170 - \ref ARM_ETH_MAC_SetMode
\r
179 \typedef ARM_ETH_LINK_STATE
\r
181 The Ethernet Link status shows if the communication is currently established (up) or interrupted (down).
\r
183 <b>Returned by:</b>
\r
184 - \ref ARM_ETH_PHY_GetLinkState
\r
189 \struct ARM_ETH_LINK_INFO
\r
191 The Ethernet Link information provides parameters about the current established communication.
\r
193 <b>Returned by:</b>
\r
194 - \ref ARM_ETH_PHY_GetLinkInfo
\r
199 \struct ARM_ETH_MAC_ADDR
\r
201 Stores the MAC Address of the Ethernet interface as defined by IEEE 802. Wikipedia offers more information about
\r
202 the <a href="http://en.wikipedia.org/wiki/MAC_address" target="_blank"><b>MAC Address</b></a>.
\r
204 <b>Parameter for:</b>
\r
205 - \ref ARM_ETH_MAC_GetMacAddress, \ref ARM_ETH_MAC_SetMacAddress, \ref ARM_ETH_MAC_SetAddressFilter
\r
211 // End ETH Interface
\r
215 \defgroup eth_interface_types1 Media Interface Types
\r
216 \ingroup eth_interface_gr
\r
217 \brief Ethernet Media Interface type
\r
219 Encodes the supported media interface between Ethernet MAC and Ethernet PHY.
\r
220 The function \ref ARM_ETH_MAC_GetCapabilities retrieves the media interface type encoded in the data field \b media_interface of the struct
\r
221 \ref ARM_ETH_MAC_CAPABILITIES.
\r
223 <b>Parameter for:</b>
\r
224 - \ref ARM_ETH_PHY_SetInterface
\r
227 \def ARM_ETH_INTERFACE_MII
\r
228 \sa ARM_ETH_PHY_SetInterface
\r
229 \def ARM_ETH_INTERFACE_RMII
\r
230 \sa ARM_ETH_PHY_SetInterface
\r
231 \def ARM_ETH_INTERFACE_SMII
\r
232 \sa ARM_ETH_PHY_SetInterface
\r