2 \defgroup eth_phy_interface_gr Ethernet PHY Interface
3 \ingroup eth_interface_gr
4 \brief Driver API for Ethernet PHY Peripheral (%Driver_ETH_PHY.h)
5 \details The following section describes the Ethernet PHY Interface as defined in the %Driver_ETH_PHY.h header file.
7 The %Driver_ETH_PHY.h contains two \#defines that are used to configure the connection between the PHY and the
8 microcontroller device:
12 Usually, the Serial Management Interface (\b SMI) (using MDC and MDIO) is used to access the PHY’s internal registers to read
13 the state of the link (up/down), duplex mode, speed, and to restart auto-negotiation etc. SMI is a serial bus, which allows
14 to connect up to 32 devices. Devices on the bus are accessed using a 5-bit device address. A default device address is
15 hardware configurable by pin-strapping on the device (some pins are sampled when a reset is asserted or at power-up).
17 The device’s internal weak pull-up or pull-down resistors define a default device address. This address can be changed by
18 connecting strong pull-up or pull-down resistors externally. In this case, the \c ETH_PHY_ADDR needs to be defined by the
21 If a microcontroller device offers more than one Ethernet PHY driver, the user needs to set the correct \c ETH_PHY_NUM in his
27 \struct ARM_DRIVER_ETH_PHY
29 The functions of the Ethernet PHY are accessed by function pointers exposed by this structure. Refer to \ref DriverFunctions for
32 Each instance of an Ethernet PHY provides such an access struct. The instance is identified by
33 a postfix number in the symbol name of the access struct, for example:
34 - \b Driver_ETH_PHY0 is the name of the access struct of the first instance (no. 0).
35 - \b Driver_ETH_PHY1 is the name of the access struct of the second instance (no. 1).
38 A configuration setting in the middleware allows connecting the middleware to a specific driver instance <b>Driver_ETH_PHY<i>n</i></b>.
39 The default is \token{0}, which connects a middleware to the first instance of a driver.
40 *****************************************************************************************************************/
44 \typedef ARM_ETH_PHY_Read_t
46 Provides the typedef for the register read function \ref ARM_ETH_MAC_PHY_Read.
49 - \ref ARM_ETH_PHY_Initialize
50 *******************************************************************************************************************/
53 \typedef ARM_ETH_PHY_Write_t
55 Provides the typedef for the register write function \ref ARM_ETH_MAC_PHY_Write.
58 - \ref ARM_ETH_PHY_Initialize
59 *******************************************************************************************************************/
66 ARM_DRIVER_VERSION ARM_ETH_PHY_GetVersion (void) {
70 \fn ARM_DRIVER_VERSION ARM_ETH_PHY_GetVersion (void)
72 The function \b ARM_ETH_PHY_GetVersion returns version information of the driver implementation in \ref ARM_DRIVER_VERSION
73 - API version is the version of the CMSIS-Driver specification used to implement this driver.
74 - Driver version is source code version of the actual driver implementation.
78 extern ARM_DRIVER_ETH_PHY Driver_ETH_PHY0;
79 ARM_DRIVER_ETH_PHY *drv_info;
81 void setup_ethernet_phy (void) {
82 ARM_DRIVER_VERSION version;
84 drv_info = &Driver_ETH_PHY0;
85 version = drv_info->GetVersion ();
86 if (version.api < 0x10A) { // requires at minimum API version 1.10 or higher
92 *****************************************************************************************************************/
94 int32_t ARM_ETH_PHY_Initialize (ARM_ETH_PHY_Read_t fn_read, ARM_ETH_PHY_Write_t fn_write) {
98 \fn int32_t ARM_ETH_PHY_Initialize (ARM_ETH_PHY_Read_t fn_read, ARM_ETH_PHY_Write_t fn_write)
100 The function \b ARM_ETH_PHY_Initialize initializes the Ethernet PHY interface.
101 It is called when the middleware component starts operation.
103 The \ref ARM_ETH_PHY_Initialize function performs the following operations:
104 - Initializes the resources needed for Ethernet PHY peripheral.
105 - Registers the \ref ARM_ETH_MAC_PHY_Read register read access function.
106 - Registers the \ref ARM_ETH_MAC_PHY_Write register write access function.
109 - see \ref eth_interface_gr - Driver Functions
111 *****************************************************************************************************************/
113 int32_t ARM_ETH_PHY_Uninitialize (void) {
117 \fn int32_t ARM_ETH_PHY_Uninitialize (void)
119 The function \b ARM_ETH_PHY_Uninitialize de-initializes the resources of Ethernet PHY interface.
121 It is called when the middleware component stops operation and releases the software resources used by the interface.
122 *****************************************************************************************************************/
124 int32_t ARM_ETH_PHY_PowerControl (ARM_POWER_STATE state) {
128 \fn int32_t ARM_ETH_PHY_PowerControl (ARM_POWER_STATE state)
130 The function \b ARM_ETH_PHY_PowerControl operates the power modes of the Ethernet PHY interface.
132 The parameter \em state sets the operation and can have the following values:
133 - \ref ARM_POWER_FULL : set-up peripheral for data transfers, enable interrupts (NVIC) and optionally DMA.
134 Can be called multiple times. If the peripheral is already in this mode the function performs
135 no operation and returns with \ref ARM_DRIVER_OK.
136 - \ref ARM_POWER_LOW : may use power saving. Returns \ref ARM_DRIVER_ERROR_UNSUPPORTED when not implemented.
137 - \ref ARM_POWER_OFF : terminates any pending data transfers, disables peripheral, disables related interrupts and DMA.
139 Refer to \ref CallSequence for more information.
142 - see \ref eth_interface_gr - Driver Functions
143 *****************************************************************************************************************/
145 int32_t ARM_ETH_PHY_SetInterface (uint32_t interface) {
149 \fn int32_t ARM_ETH_PHY_SetInterface (uint32_t interface)
152 The function \b ARM_ETH_PHY_SetInterface specifies the \ref eth_interface_types1 that links the Ethernet MAC and Ethernet PHY.
153 After initialization of the PHY interface, you can set the media type.
154 The function \ref ARM_ETH_MAC_GetCapabilities retrieves the media interface type encoded in the data field \b media_interface of the structure
155 \ref ARM_ETH_MAC_CAPABILITIES.
157 The parameter \em interface can have the following values:
159 Parameter \em interface | Media Type
160 :-----------------------------|:-------------------------
161 \ref ARM_ETH_INTERFACE_MII | Media Independent Interface (MII)
162 \ref ARM_ETH_INTERFACE_RMII | Reduced Media Independent Interface (RMII)
163 \ref ARM_ETH_INTERFACE_SMII | Serial Media Independent Interface (SMII);
166 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.
170 static ARM_ETH_MAC_CAPABILITIES capabilities;
171 static ARM_DRIVER_ETH_MAC *mac;
172 static ARM_DRIVER_ETH_PHY *phy;
174 mac = &Driver_ETH_MAC0;
175 phy = &Driver_ETH_PHY0;
177 // Initialize Media Access Controller
178 capabilities = mac->GetCapabilities ();
180 status = phy->SetInterface (capabilities.media_interface);
181 if (status != ARM_DRIVER_OK) ... // error handling
182 status = phy->SetMode (ARM_ETH_PHY_AUTO_NEGOTIATE);
183 if (status != ARM_DRIVER_OK) ... // error handling
186 *****************************************************************************************************************/
188 int32_t ARM_ETH_PHY_SetMode (uint32_t mode) {
192 \fn int32_t ARM_ETH_PHY_SetMode (uint32_t mode)
194 The function \b ARM_ETH_PHY_SetMode sets the operation mode parameters for the Ethernet PHY.
197 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:
200 phy->SetMode (ARM_ETH_PHY_SPEED_100M | ARM_ETH_PHY_LOOPBACK | ARM_ETH_PHY_DUPLEX_HALF );
204 <table class="cmtable" summary="">
205 <tr><th>Parameter \em mode </th><th> bit </th><th> Category </th> <th>Description</th></tr>
206 <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>
207 <tr><td>\ref ARM_ETH_PHY_SPEED_100M </td> <td>Set the link speed to \token{100 [Mbps]} </td></tr>
208 <tr><td>\ref ARM_ETH_PHY_SPEED_1G </td> <td>Set the link speed to \token{1 [Gbps]} </td></tr>
209 <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>
210 <tr><td>\ref ARM_ETH_PHY_DUPLEX_FULL </td> <td>Set the link mode to full duplex </td></tr>
211 <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>
212 <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>
213 <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>
217 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.
219 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.
224 static ARM_ETH_MAC_CAPABILITIES capabilities;
225 static ARM_DRIVER_ETH_MAC *mac;
226 static ARM_DRIVER_ETH_PHY *phy;
228 mac = &Driver_ETH_MAC0;
229 phy = &Driver_ETH_PHY0;
231 // Initialize Media Access Controller
232 capabilities = mac->GetCapabilities ();
234 status = phy->SetInterface (capabilities.media_interface);
235 if (status != ARM_DRIVER_OK) ... // error handling
236 status = phy->SetMode (ARM_ETH_PHY_SPEED_100M | ARM_ETH_PHY_DUPLEX_FULL | ARM_ETH_PHY_ISOLATE);
237 if (status != ARM_DRIVER_OK) ... // error handling
243 *****************************************************************************************************************/
245 ARM_ETH_LINK_STATE ARM_ETH_PHY_GetLinkState (void) {
249 \fn ARM_ETH_LINK_STATE ARM_ETH_PHY_GetLinkState (void)
251 The function \b ARM_ETH_PHY_GetLinkState retrieves the connection status of the physical Ethernet link.
254 - see \ref eth_interface_gr - Driver Functions
255 *****************************************************************************************************************/
257 ARM_ETH_LINK_INFO ARM_ETH_PHY_GetLinkInfo (void) {
261 \fn ARM_ETH_LINK_INFO ARM_ETH_PHY_GetLinkInfo (void)
263 The function \b ARM_ETH_PHY_GetLinkInfo retrieves information about the current established communication
264 mode (half/full duplex) and communication speed. Information is only valid when link is up (see \ref ARM_ETH_PHY_GetLinkState).
267 - see \ref eth_interface_gr - Driver Functions
268 *****************************************************************************************************************/
274 // End ETH PHY Interface group; below the groups are included with \ingroup
278 \defgroup eth_phy_mode_ctrls Ethernet PHY Mode
279 \ingroup eth_phy_interface_gr
280 \brief Specify operation modes of the Ethernet PHY interface
283 \def ARM_ETH_PHY_SPEED_10M
284 \sa ARM_ETH_PHY_SetMode
285 \def ARM_ETH_PHY_SPEED_100M
286 \sa ARM_ETH_PHY_SetMode
287 \def ARM_ETH_PHY_SPEED_1G
288 \sa ARM_ETH_PHY_SetMode
289 \def ARM_ETH_PHY_DUPLEX_HALF
290 \sa ARM_ETH_PHY_SetMode
291 \def ARM_ETH_PHY_DUPLEX_FULL
292 \sa ARM_ETH_PHY_SetMode
293 \def ARM_ETH_PHY_AUTO_NEGOTIATE
294 \sa ARM_ETH_PHY_SetMode
295 \def ARM_ETH_PHY_LOOPBACK
296 \sa ARM_ETH_PHY_SetMode
297 \def ARM_ETH_PHY_ISOLATE
298 \sa ARM_ETH_PHY_SetMode