]> begriffs open source - cmsis/blob - CMSIS/DoxyGen/Driver/src/Driver_ETH_PHY.c
Adapted and prepared structure to add Cortex-A and CMSIS-Zone documentation
[cmsis] / CMSIS / DoxyGen / Driver / src / Driver_ETH_PHY.c
1 /* -----------------------------------------------------------------------------
2  * Copyright (c) 2013-2014 ARM Limited. All rights reserved.
3  *  
4  * $Date:        2. January 2014
5  * $Revision:    V2.00
6  *  
7  * Project:      Ethernet PHY Driver API
8  * -------------------------------------------------------------------------- */
9
10
11 /**
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.
16
17 The %Driver_ETH_PHY.h contains two \#defines that are used to configure the connection between the PHY and the
18 microcontroller device:
19 - \c ETH_PHY_NUM and
20 - \c ETH_PHY_ADDR
21
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).
26
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
29 user.
30
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
32 application.
33 @{
34 */
35
36 /**
37 \struct     ARM_DRIVER_ETH_PHY
38 \details
39 The functions of the Ethernet PHY are accessed by function pointers exposed by this structure. Refer to \ref DriverFunctions for 
40 overview information.
41
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).
46
47
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 *****************************************************************************************************************/
51
52
53 /**
54 \typedef    ARM_ETH_PHY_Read_t
55 \details
56 Provides the typedef for the register read function \ref ARM_ETH_MAC_PHY_Read.
57
58 <b>Parameter for:</b>
59   - \ref ARM_ETH_PHY_Initialize
60 *******************************************************************************************************************/
61
62 /**
63 \typedef    ARM_ETH_PHY_Write_t
64 \details
65 Provides the typedef for the register write function \ref ARM_ETH_MAC_PHY_Write.
66
67 <b>Parameter for:</b>
68   - \ref ARM_ETH_PHY_Initialize
69 *******************************************************************************************************************/
70
71
72 //
73 // Functions
74 //
75
76 ARM_DRIVER_VERSION ARM_ETH_PHY_GetVersion (void)  {
77   return { 0, 0 };
78 }
79 /**
80 \fn     ARM_DRIVER_VERSION ARM_ETH_PHY_GetVersion (void)
81 \details
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.
85
86 Example:
87 \code
88 extern ARM_DRIVER_ETH_PHY Driver_ETH_PHY0;
89 ARM_DRIVER_ETH_PHY *drv_info;
90  
91 void setup_ethernet_phy (void)  {
92   ARM_DRIVER_VERSION  version;
93  
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
97     // error handling
98     return;
99   }
100 }
101 \endcode
102 *****************************************************************************************************************/
103
104 int32_t ARM_ETH_PHY_Initialize (ARM_ETH_PHY_Read_t fn_read, ARM_ETH_PHY_Write_t fn_write)  {
105   return 0;
106 }
107 /**
108 \fn       int32_t ARM_ETH_PHY_Initialize (ARM_ETH_PHY_Read_t fn_read, ARM_ETH_PHY_Write_t fn_write)
109 \details
110 The function \b ARM_ETH_PHY_Initialize initializes the Ethernet PHY interface. 
111 It is called when the middleware component starts operation.
112
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.
117
118 \b Example:
119  - see \ref eth_interface_gr - Driver Functions
120
121 *****************************************************************************************************************/
122
123 int32_t ARM_ETH_PHY_Uninitialize (void)  {
124   return 0;
125 }
126 /**
127 \fn       int32_t ARM_ETH_PHY_Uninitialize (void)
128 \details
129 The function \b ARM_ETH_PHY_Uninitialize de-initializes the resources of Ethernet PHY interface.
130
131 It is called when the middleware component stops operation and releases the software resources used by the interface.
132 *****************************************************************************************************************/
133
134 int32_t ARM_ETH_PHY_PowerControl (ARM_POWER_STATE state)  {
135   return 0;
136 }
137 /**
138 \fn int32_t ARM_ETH_PHY_PowerControl (ARM_POWER_STATE state)
139 \details     
140 The function \b ARM_ETH_PHY_PowerControl operates the power modes of the Ethernet PHY interface.  
141
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.
148       
149 Refer to \ref CallSequence for more information.
150
151 \b Example:
152  - see \ref eth_interface_gr - Driver Functions
153 *****************************************************************************************************************/
154
155 int32_t ARM_ETH_PHY_SetInterface (uint32_t interface)  {
156   return 0;
157 }
158 /**
159 \fn int32_t ARM_ETH_PHY_SetInterface (uint32_t interface)
160
161 \details
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. 
166
167 The parameter \em interface can have the following values:
168
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); 
174
175 \note
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.
177
178 \b Example:
179 \code
180 static ARM_ETH_MAC_CAPABILITIES capabilities;
181 static ARM_DRIVER_ETH_MAC *mac;
182 static ARM_DRIVER_ETH_PHY *phy;
183  
184 mac = &Driver_ETH_MAC0;
185 phy = &Driver_ETH_PHY0;
186  
187 // Initialize Media Access Controller
188 capabilities = mac->GetCapabilities ();
189 ...
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
194 ...
195 \endcode
196 *****************************************************************************************************************/
197
198 int32_t ARM_ETH_PHY_SetMode (uint32_t mode)  {
199   return 0;
200 }
201 /**
202 \fn int32_t ARM_ETH_PHY_SetMode (uint32_t mode)
203 \details
204 The function \b ARM_ETH_PHY_SetMode sets the operation mode parameters for the Ethernet PHY.
205
206
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:
208
209 \code
210 phy->SetMode (ARM_ETH_PHY_SPEED_100M | ARM_ETH_PHY_LOOPBACK | ARM_ETH_PHY_DUPLEX_HALF );
211 \endcode
212 \n
213
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>
224 </table>
225
226 \note
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.
228 \note
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.
230
231
232 \b Example:
233 \code
234 static ARM_ETH_MAC_CAPABILITIES capabilities;
235 static ARM_DRIVER_ETH_MAC *mac;
236 static ARM_DRIVER_ETH_PHY *phy;
237  
238 mac = &Driver_ETH_MAC0;
239 phy = &Driver_ETH_PHY0;
240  
241 // Initialize Media Access Controller
242 capabilities = mac->GetCapabilities ();
243 ...
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
248 ...
249 \endcode
250
251
252
253 *****************************************************************************************************************/
254
255 ARM_ETH_LINK_STATE ARM_ETH_PHY_GetLinkState (void)  {
256   return 0;
257 }
258 /**
259 \fn ARM_ETH_LINK_STATE ARM_ETH_PHY_GetLinkState (void)
260 \details
261 The function \b ARM_ETH_PHY_GetLinkState retrieves the connection status of the physical Ethernet link.
262
263 \b Example:
264  - see \ref eth_interface_gr - Driver Functions
265 *****************************************************************************************************************/
266
267 ARM_ETH_LINK_INFO ARM_ETH_PHY_GetLinkInfo (void)  {
268   return 0;
269 }
270 /**
271 \fn ARM_ETH_LINK_INFO ARM_ETH_PHY_GetLinkInfo (void)
272 \details
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).
275
276 \b Example:
277  - see \ref eth_interface_gr - Driver Functions
278 *****************************************************************************************************************/
279
280
281 /**
282 @}
283 */ 
284 // End ETH PHY Interface group; below the groups are included with \ingroup
285
286
287 /**
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
291 \details
292 @{
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
309 @}
310 */
311
312
313