1 /* -----------------------------------------------------------------------------
2 * Copyright (c) 2013-2014 ARM Limited. All rights reserved.
4 * $Date: 2. January 2014
7 * Project: Ethernet PHY Driver API
8 * -------------------------------------------------------------------------- */
12 \defgroup eth_phy_interface_gr Ethernet PHY Interface
13 \ingroup eth_interface_gr
14 \brief Driver API for Ethernet PHY Peripheral (%Driver_ETH_PHY.h)
15 \details The following section describes the Ethernet PHY Interface as defined in the %Driver_ETH_PHY.h header file.
17 The %Driver_ETH_PHY.h contains two \#defines that are used to configure the connection between the PHY and the
18 microcontroller device:
22 Usually, the Serial Management Interface (\b SMI) (using MDC and MDIO) is used to access the PHY’s internal registers to read
23 the state of the link (up/down), duplex mode, speed, and to restart auto-negotiation etc. SMI is a serial bus, which allows
24 to connect up to 32 devices. Devices on the bus are accessed using a 5-bit device address. A default device address is
25 hardware configurable by pin-strapping on the device (some pins are sampled when a reset is asserted or at power-up).
27 The device’s internal weak pull-up or pull-down resistors define a default device address. This address can be changed by
28 connecting strong pull-up or pull-down resistors externally. In this case, the \c ETH_PHY_ADDR needs to be defined by the
31 If a microcontroller device offers more than one Ethernet PHY driver, the user needs to set the correct \c ETH_PHY_NUM in his
37 \struct ARM_DRIVER_ETH_PHY
39 The functions of the Ethernet PHY are accessed by function pointers exposed by this structure. Refer to \ref DriverFunctions for
42 Each instance of an Ethernet PHY provides such an access struct. The instance is identified by
43 a postfix number in the symbol name of the access struct, for example:
44 - \b Driver_ETH_PHY0 is the name of the access struct of the first instance (no. 0).
45 - \b Driver_ETH_PHY1 is the name of the access struct of the second instance (no. 1).
48 A configuration setting in the middleware allows connecting the middleware to a specific driver instance <b>Driver_ETH_PHY<i>n</i></b>.
49 The default is \token{0}, which connects a middleware to the first instance of a driver.
50 *****************************************************************************************************************/
54 \typedef ARM_ETH_PHY_Read_t
56 Provides the typedef for the register read function \ref ARM_ETH_MAC_PHY_Read.
59 - \ref ARM_ETH_PHY_Initialize
60 *******************************************************************************************************************/
63 \typedef ARM_ETH_PHY_Write_t
65 Provides the typedef for the register write function \ref ARM_ETH_MAC_PHY_Write.
68 - \ref ARM_ETH_PHY_Initialize
69 *******************************************************************************************************************/
76 ARM_DRIVER_VERSION ARM_ETH_PHY_GetVersion (void) {
80 \fn ARM_DRIVER_VERSION ARM_ETH_PHY_GetVersion (void)
82 The function \b ARM_ETH_PHY_GetVersion returns version information of the driver implementation in \ref ARM_DRIVER_VERSION
83 - API version is the version of the CMSIS-Driver specification used to implement this driver.
84 - Driver version is source code version of the actual driver implementation.
88 extern ARM_DRIVER_ETH_PHY Driver_ETH_PHY0;
89 ARM_DRIVER_ETH_PHY *drv_info;
91 void setup_ethernet_phy (void) {
92 ARM_DRIVER_VERSION version;
94 drv_info = &Driver_ETH_PHY0;
95 version = drv_info->GetVersion ();
96 if (version.api < 0x10A) { // requires at minimum API version 1.10 or higher
102 *****************************************************************************************************************/
104 int32_t ARM_ETH_PHY_Initialize (ARM_ETH_PHY_Read_t fn_read, ARM_ETH_PHY_Write_t fn_write) {
108 \fn int32_t ARM_ETH_PHY_Initialize (ARM_ETH_PHY_Read_t fn_read, ARM_ETH_PHY_Write_t fn_write)
110 The function \b ARM_ETH_PHY_Initialize initializes the Ethernet PHY interface.
111 It is called when the middleware component starts operation.
113 The \ref ARM_ETH_PHY_Initialize function performs the following operations:
114 - Initializes the resources needed for Ethernet PHY peripheral.
115 - Registers the \ref ARM_ETH_MAC_PHY_Read register read access function.
116 - Registers the \ref ARM_ETH_MAC_PHY_Write register write access function.
119 - see \ref eth_interface_gr - Driver Functions
121 *****************************************************************************************************************/
123 int32_t ARM_ETH_PHY_Uninitialize (void) {
127 \fn int32_t ARM_ETH_PHY_Uninitialize (void)
129 The function \b ARM_ETH_PHY_Uninitialize de-initializes the resources of Ethernet PHY interface.
131 It is called when the middleware component stops operation and releases the software resources used by the interface.
132 *****************************************************************************************************************/
134 int32_t ARM_ETH_PHY_PowerControl (ARM_POWER_STATE state) {
138 \fn int32_t ARM_ETH_PHY_PowerControl (ARM_POWER_STATE state)
140 The function \b ARM_ETH_PHY_PowerControl operates the power modes of the Ethernet PHY interface.
142 The parameter \em state sets the operation and can have the following values:
143 - \ref ARM_POWER_FULL : set-up peripheral for data transfers, enable interrupts (NVIC) and optionally DMA.
144 Can be called multiple times. If the peripheral is already in this mode the function performs
145 no operation and returns with \ref ARM_DRIVER_OK.
146 - \ref ARM_POWER_LOW : may use power saving. Returns \ref ARM_DRIVER_ERROR_UNSUPPORTED when not implemented.
147 - \ref ARM_POWER_OFF : terminates any pending data transfers, disables peripheral, disables related interrupts and DMA.
149 Refer to \ref CallSequence for more information.
152 - see \ref eth_interface_gr - Driver Functions
153 *****************************************************************************************************************/
155 int32_t ARM_ETH_PHY_SetInterface (uint32_t interface) {
159 \fn int32_t ARM_ETH_PHY_SetInterface (uint32_t interface)
162 The function \b ARM_ETH_PHY_SetInterface specifies the \ref eth_interface_types1 that links the Ethernet MAC and Ethernet PHY.
163 After initialization of the PHY interface, you can set the media type.
164 The function \ref ARM_ETH_MAC_GetCapabilities retrieves the media interface type encoded in the data field \b media_interface of the structure
165 \ref ARM_ETH_MAC_CAPABILITIES.
167 The parameter \em interface can have the following values:
169 Parameter \em interface | Media Type
170 :-----------------------------|:-------------------------
171 \ref ARM_ETH_INTERFACE_MII | Media Independent Interface (MII)
172 \ref ARM_ETH_INTERFACE_RMII | Reduced Media Independent Interface (RMII)
173 \ref ARM_ETH_INTERFACE_SMII | Serial Media Independent Interface (SMII);
176 Some \em interface values may be unsupported by a driver implementation. For example \ref ARM_ETH_INTERFACE_SMII may return \b ARM_DRIVER_ERROR_UNSUPPORTED.
180 static ARM_ETH_MAC_CAPABILITIES capabilities;
181 static ARM_DRIVER_ETH_MAC *mac;
182 static ARM_DRIVER_ETH_PHY *phy;
184 mac = &Driver_ETH_MAC0;
185 phy = &Driver_ETH_PHY0;
187 // Initialize Media Access Controller
188 capabilities = mac->GetCapabilities ();
190 status = phy->SetInterface (capabilities.media_interface);
191 if (status != ARM_DRIVER_OK) ... // error handling
192 status = phy->SetMode (ARM_ETH_PHY_AUTO_NEGOTIATE);
193 if (status != ARM_DRIVER_OK) ... // error handling
196 *****************************************************************************************************************/
198 int32_t ARM_ETH_PHY_SetMode (uint32_t mode) {
202 \fn int32_t ARM_ETH_PHY_SetMode (uint32_t mode)
204 The function \b ARM_ETH_PHY_SetMode sets the operation mode parameters for the Ethernet PHY.
207 The table below lists the possible values for the parameter \em mode. Values from different categories can be ORed as shown in this example code:
210 phy->SetMode (ARM_ETH_PHY_SPEED_100M | ARM_ETH_PHY_LOOPBACK | ARM_ETH_PHY_DUPLEX_HALF );
214 <table class="cmtable" summary="">
215 <tr><th>Parameter \em mode </th><th> bit </th><th> Category </th> <th>Description</th></tr>
216 <tr><td>\ref ARM_ETH_PHY_SPEED_10M </td><td rowspan="3"> 0..1 </td><td rowspan="3">Link Speed </td> <td>Set the link speed to \token{10 [Mbps]} </td></tr>
217 <tr><td>\ref ARM_ETH_PHY_SPEED_100M </td> <td>Set the link speed to \token{100 [Mbps]} </td></tr>
218 <tr><td>\ref ARM_ETH_PHY_SPEED_1G </td> <td>Set the link speed to \token{1 [Gbps]} </td></tr>
219 <tr><td>\ref ARM_ETH_PHY_DUPLEX_HALF </td><td rowspan="2"> 2 </td><td rowspan="2">Link Mode </td> <td>Set the link mode to half duplex </td></tr>
220 <tr><td>\ref ARM_ETH_PHY_DUPLEX_FULL </td> <td>Set the link mode to full duplex </td></tr>
221 <tr><td>\ref ARM_ETH_PHY_AUTO_NEGOTIATE </td><td> 3 </td><td>Autonegotiation </td> <td>Set the interface to Auto Negotiation mode of transmission parameters</td></tr>
222 <tr><td>\ref ARM_ETH_PHY_LOOPBACK </td><td> 4 </td><td>Loopback </td> <td>Set the interface into a Loop-back test mode </td></tr>
223 <tr><td>\ref ARM_ETH_PHY_ISOLATE </td><td> 5 </td><td>Isolation </td> <td>Set to indicate electrical isolation of PHY interface from MII/RMII interface</td></tr>
227 Some settings may be also taken from configuration pins (example \ref ARM_ETH_PHY_ISOLATE). Check the effect of mode settings in the actual driver implementation.
229 Some \em mode values may be unsupported by a driver implementation. For example \ref ARM_ETH_PHY_SPEED_1G may return \b ARM_DRIVER_ERROR_UNSUPPORTED.
234 static ARM_ETH_MAC_CAPABILITIES capabilities;
235 static ARM_DRIVER_ETH_MAC *mac;
236 static ARM_DRIVER_ETH_PHY *phy;
238 mac = &Driver_ETH_MAC0;
239 phy = &Driver_ETH_PHY0;
241 // Initialize Media Access Controller
242 capabilities = mac->GetCapabilities ();
244 status = phy->SetInterface (capabilities.media_interface);
245 if (status != ARM_DRIVER_OK) ... // error handling
246 status = phy->SetMode (ARM_ETH_PHY_SPEED_100M | ARM_ETH_PHY_DUPLEX_FULL | ARM_ETH_PHY_ISOLATE);
247 if (status != ARM_DRIVER_OK) ... // error handling
253 *****************************************************************************************************************/
255 ARM_ETH_LINK_STATE ARM_ETH_PHY_GetLinkState (void) {
259 \fn ARM_ETH_LINK_STATE ARM_ETH_PHY_GetLinkState (void)
261 The function \b ARM_ETH_PHY_GetLinkState retrieves the connection status of the physical Ethernet link.
264 - see \ref eth_interface_gr - Driver Functions
265 *****************************************************************************************************************/
267 ARM_ETH_LINK_INFO ARM_ETH_PHY_GetLinkInfo (void) {
271 \fn ARM_ETH_LINK_INFO ARM_ETH_PHY_GetLinkInfo (void)
273 The function \b ARM_ETH_PHY_GetLinkInfo retrieves information about the current established communication
274 mode (half/full duplex) and communication speed. Information is only valid when link is up (see \ref ARM_ETH_PHY_GetLinkState).
277 - see \ref eth_interface_gr - Driver Functions
278 *****************************************************************************************************************/
284 // End ETH PHY Interface group; below the groups are included with \ingroup
288 \defgroup eth_phy_mode_ctrls Ethernet PHY Mode
289 \ingroup eth_phy_interface_gr
290 \brief Specify operation modes of the Ethernet PHY interface
293 \def ARM_ETH_PHY_SPEED_10M
294 \sa ARM_ETH_PHY_SetMode
295 \def ARM_ETH_PHY_SPEED_100M
296 \sa ARM_ETH_PHY_SetMode
297 \def ARM_ETH_PHY_SPEED_1G
298 \sa ARM_ETH_PHY_SetMode
299 \def ARM_ETH_PHY_DUPLEX_HALF
300 \sa ARM_ETH_PHY_SetMode
301 \def ARM_ETH_PHY_DUPLEX_FULL
302 \sa ARM_ETH_PHY_SetMode
303 \def ARM_ETH_PHY_AUTO_NEGOTIATE
304 \sa ARM_ETH_PHY_SetMode
305 \def ARM_ETH_PHY_LOOPBACK
306 \sa ARM_ETH_PHY_SetMode
307 \def ARM_ETH_PHY_ISOLATE
308 \sa ARM_ETH_PHY_SetMode