]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A5_SAMA5D2x_Xplained_IAR/AtmelFiles/drivers/peripherals/gmac.h
Add SAMA5D2 Xplained IAR demo.
[freertos] / FreeRTOS / Demo / CORTEX_A5_SAMA5D2x_Xplained_IAR / AtmelFiles / drivers / peripherals / gmac.h
1 /* ----------------------------------------------------------------------------\r
2  *         SAM Software Package License\r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2015, Atmel Corporation\r
5  *\r
6  * All rights reserved.\r
7  *\r
8  * Redistribution and use in source and binary forms, with or without\r
9  * modification, are permitted provided that the following conditions are met:\r
10  *\r
11  * - Redistributions of source code must retain the above copyright notice,\r
12  * this list of conditions and the disclaimer below.\r
13  *\r
14  * Atmel's name may not be used to endorse or promote products derived from\r
15  * this software without specific prior written permission.\r
16  *\r
17  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR\r
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
20  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,\r
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
23  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
27  * ----------------------------------------------------------------------------\r
28  */\r
29 \r
30 /** \file */\r
31 \r
32 /** \addtogroup gmac_module\r
33  * @{\r
34  * Provides the interface to configure and use the GMAC peripheral.\r
35  *\r
36  * \section gmac_usage Usage\r
37  * - Configure Gmac::GMAC_NCFG with gmac_configure(), some of related controls\r
38  *   are also available, such as:\r
39  *   - gmac_set_link_speed(): Setup GMAC working clock.\r
40  *   - gmac_full_duplex_enable(): Working in full duplex or not.\r
41  *   - gmac_cpy_all_enable(): Copying all valid frames (\ref GMAC_NCFG_CAF).\r
42  *   - ...\r
43  * - Setup Gmac::GMAC_NCR with gmac_network_control(), more related controls\r
44  *   can modify with:\r
45  *   - gmac_receive_enable(): Enable/Disable Rx.\r
46  *   - gmac_transmit_enable(): Enable/Disable Tx.\r
47  *   - gmac_broadcast_disable(): Enable/Disable broadcast receiving.\r
48  *   - ...\r
49  * - Manage GMAC interrupts with GMAC_EnableIt(), gmac_disable_it(),\r
50  *   gmac_get_it_mask() and gmac_get_it_status().\r
51  * - Manage GMAC Tx/Rx status with gmac_get_tx_status(), gmac_get_rx_status()\r
52  *   gmac_clear_tx_status() and gmac_clear_rx_status().\r
53  * - Manage GMAC Queue with gmac_set_tx_queue(), GMAC_GetTxQueue(),\r
54  *   gmac_set_rx_queue() and GMAC_GetRxQueue(), the queue descriptor can define\r
55  *   by \ref _gmac_rx_descriptor and \ref _gmac_tx_descriptor.\r
56  * - Manage PHY through GMAC is performed by\r
57  *   - gmac_management_enable(): Enable/Disable PHY management.\r
58  *   - gmac_phy_maintain(): Execute PHY management commands.\r
59  *   - gmac_phy_data(): Return PHY management data.\r
60  *   - gmac_is_idle(): Check if PHY is idle.\r
61  * - Setup GMAC parameters with following functions:\r
62  *   - gmac_set_hash(): Set Hash value.\r
63  *   - gmac_set_address(): Set MAC address.\r
64  * - Enable/Disable GMAC transceiver clock via GMAC_TransceiverClockEnable()\r
65  * - Switch GMAC MII/RMII mode through gmac_enable_rgmii()\r
66  *\r
67  * For more accurate information, please look at the GMAC section of the\r
68  * Datasheet.\r
69  *\r
70  * \sa \ref gmacd_module\r
71  *\r
72  * Related files:\n\r
73  * gmac.c\n\r
74  * gmac.h.\n\r
75  *\r
76  *   \defgroup gmac_defines GMAC Defines\r
77  *   \defgroup gmac_structs GMAC Data Structs\r
78  *   \defgroup gmac_functions GMAC Functions\r
79  */\r
80 /**@}*/\r
81 \r
82 #ifndef _GMAC_H_\r
83 #define _GMAC_H_\r
84 \r
85 /*----------------------------------------------------------------------------\r
86  *        Headers\r
87  *----------------------------------------------------------------------------*/\r
88 \r
89 #include "chip.h"\r
90 \r
91 #include <stdbool.h>\r
92 #include <stdint.h>\r
93 \r
94 /*----------------------------------------------------------------------------\r
95  *        Defines\r
96  *----------------------------------------------------------------------------*/\r
97 \r
98 /** \addtogroup gmac_defines\r
99         @{*/\r
100 \r
101 #ifdef CONFIG_HAVE_GMAC_QUEUES\r
102 #define GMAC_NUM_QUEUES 3\r
103 #else\r
104 #define GMAC_NUM_QUEUES 1\r
105 #endif\r
106 \r
107 #define GMAC_MAX_FRAME_LENGTH       1536\r
108 #define GMAC_MAX_JUMBO_FRAME_LENGTH 10240\r
109 \r
110 enum _gmac_duplex {\r
111         GMAC_DUPLEX_HALF = 0,\r
112         GMAC_DUPLEX_FULL = 1,\r
113 };\r
114 \r
115 enum _gmac_speed {\r
116         GMAC_SPEED_10M   = 0,\r
117         GMAC_SPEED_100M  = 1,\r
118 };\r
119 \r
120 /* Bits contained in struct _gmac_desc addr when used for RX*/\r
121 #define GMAC_RX_ADDR_OWN  (1u << 0)\r
122 #define GMAC_RX_ADDR_WRAP (1u << 1)\r
123 #define GMAC_RX_ADDR_MASK 0xfffffffcu\r
124 \r
125 /* Bits contained in struct _gmac_desc status when used for RX */\r
126 #define GMAC_RX_STATUS_LENGTH_MASK 0x3fffu\r
127 #define GMAC_RX_STATUS_SOF         (1u << 14)\r
128 #define GMAC_RX_STATUS_EOF         (1u << 15)\r
129 \r
130 /* Bits contained in struct _gmac_desc status when used for TX */\r
131 #define GMAC_TX_STATUS_LASTBUF (1u << 15)\r
132 #define GMAC_TX_STATUS_WRAP    (1u << 30)\r
133 #define GMAC_TX_STATUS_USED    (1u << 31)\r
134 \r
135 /**@}*/\r
136 \r
137 /*----------------------------------------------------------------------------\r
138  *        Types\r
139  *----------------------------------------------------------------------------*/\r
140 \r
141 /** \addtogroup gmac_structs\r
142         @{*/\r
143 \r
144 /** Transmit/Receive buffer descriptor struct */\r
145 struct _gmac_desc {\r
146         uint32_t addr;\r
147         uint32_t status;\r
148 };\r
149 \r
150 /**     @}*/\r
151 \r
152 /*----------------------------------------------------------------------------\r
153  *        Exported functions\r
154  *----------------------------------------------------------------------------*/\r
155 \r
156 #ifdef __cplusplus\r
157 extern "C" {\r
158 #endif\r
159 \r
160 /**\r
161  * TODO\r
162  */\r
163 extern bool gmac_configure(Gmac *gmac);\r
164 \r
165 /**\r
166  *  \brief Write NCR register value\r
167  */\r
168 extern void gmac_set_network_control_register(Gmac * gmac, uint32_t ncr);\r
169 \r
170 /**\r
171  *  \brief Get NCR register value\r
172  */\r
173 extern uint32_t gmac_get_network_control_register(Gmac * gmac);\r
174 \r
175 /**\r
176  *  \brief Set network configuration register\r
177  */\r
178 extern void gmac_set_network_config_register(Gmac* gmac, uint32_t ncfgr);\r
179 \r
180 /**\r
181  *  \brief Get network configuration register\r
182  */\r
183 \r
184 extern uint32_t gmac_get_network_config_register(Gmac* gmac);\r
185 \r
186 /**\r
187  *  \brief Enable MDI with PHY\r
188  *  \param gmac Pointer to an Gmac instance.\r
189  */\r
190 extern void gmac_enable_mdio(Gmac* gmac);\r
191 \r
192 /**\r
193  *  \brief Disable MDI with PHY\r
194  *  \param gmac Pointer to an Gmac instance.\r
195  */\r
196 extern void gmac_disable_mdio(Gmac* gmac);\r
197 \r
198 /**\r
199  *  \brief Execute PHY read command\r
200  */\r
201 extern bool gmac_phy_read(Gmac* gmac, uint8_t phy_addr, uint8_t reg_addr,\r
202                 uint16_t* data, uint32_t retries);\r
203 \r
204 /**\r
205  *  \brief Execute PHY write command\r
206  */\r
207 extern bool gmac_phy_write(Gmac* gmac, uint8_t phy_addr, uint8_t reg_addr,\r
208                 uint16_t data, uint32_t retries);\r
209 \r
210 /**\r
211  *  \brief Enable MII mode for GMAC, called once after autonegotiate\r
212  *  \param gmac Pointer to an Gmac instance.\r
213  */\r
214 extern void gmac_enable_mii(Gmac* gmac);\r
215 \r
216 /**\r
217  *  \brief Enable RMII mode for GMAC, called once after autonegotiate\r
218  *  \param gmac Pointer to an Gmac instance.\r
219  *  \param duplex: 1 full duplex 0 half duplex\r
220  *  \param speed: 0 10M 1 100M\r
221  */\r
222 extern void gmac_enable_rmii(Gmac* gmac, enum _gmac_speed speed,\r
223                 enum _gmac_duplex duplex);\r
224 \r
225 /**\r
226  *  \brief Setup the GMAC for the link : speed 100M/10M and Full/Half duplex\r
227  *  \param gmac Pointer to an Gmac instance.\r
228  *  \param speed Link speed, 0 for 10M, 1 for 100M\r
229  *  \param fullduplex 1 for Full Duplex mode\r
230  */\r
231 extern void gmac_set_link_speed(Gmac* gmac, enum _gmac_speed speed,\r
232                 enum _gmac_duplex duplex);\r
233 \r
234 /**\r
235  *  \brief Enable local loop back\r
236  *  \param gmac Pointer to an Gmac instance.\r
237  */\r
238 extern void gmac_enable_local_loopback(Gmac* gmac);\r
239 \r
240 /**\r
241  *  \brief Disable local loop back\r
242  *  \param gmac Pointer to an Gmac instance.\r
243  */\r
244 extern void gmac_disable_local_loopback(Gmac* gmac);\r
245 \r
246 /**\r
247  *  \brief Return transmit status\r
248  */\r
249 extern uint32_t gmac_get_tx_status(Gmac* gmac);\r
250 \r
251 /**\r
252  *  \brief Clear transmit status\r
253  */\r
254 extern void gmac_clear_tx_status(Gmac* gmac, uint32_t mask);\r
255 \r
256 /**\r
257  *  \brief Return receive status\r
258  */\r
259 extern uint32_t gmac_get_rx_status(Gmac* gmac);\r
260 \r
261 /**\r
262  *  \brief Clear receive status\r
263  */\r
264 extern void gmac_clear_rx_status(Gmac* gmac, uint32_t mask);\r
265 \r
266 /**\r
267  *  \brief Enable/Disable GMAC receive.\r
268  */\r
269 extern void gmac_receive_enable(Gmac* gmac, bool enable);\r
270 \r
271 /**\r
272  *  \brief Enable/Disable GMAC transmit.\r
273  */\r
274 extern void gmac_transmit_enable(Gmac* gmac, bool enable);\r
275 \r
276 /**\r
277  *  \brief Set RX descriptor address\r
278  */\r
279 void gmac_set_rx_desc(Gmac* gmac, uint8_t queue, struct _gmac_desc* desc);\r
280 \r
281 /**\r
282  *  \brief Get RX descriptor address\r
283  */\r
284 struct _gmac_desc* gmac_get_rx_desc(Gmac* gmac, uint8_t queue);\r
285 \r
286 /**\r
287  *  \brief Set TX descriptor address\r
288  */\r
289 void gmac_set_tx_desc(Gmac* gmac, uint8_t queue, struct _gmac_desc* desc);\r
290 \r
291 /**\r
292  *  \brief Get TX descriptor address\r
293  */\r
294 struct _gmac_desc* gmac_get_tx_desc(Gmac* gmac, uint8_t queue);\r
295 \r
296 /**\r
297  *  \brief Return interrupt mask.\r
298  */\r
299 extern uint32_t gmac_get_it_mask(Gmac* gmac, uint8_t queue);\r
300 \r
301 /**\r
302  *  \brief Enable interrupt(s).\r
303  */\r
304 extern void gmac_enable_it(Gmac* gmac, uint8_t queue, uint32_t mask);\r
305 \r
306 /**\r
307  *  \brief Disable interrupt(s).\r
308  */\r
309 extern void gmac_disable_it(Gmac * gmac, uint8_t queue, uint32_t mask);\r
310 \r
311 /**\r
312  *  \brief Return interrupt status mask.\r
313  */\r
314 extern uint32_t gmac_get_it_status(Gmac* gmac, uint8_t queue);\r
315 \r
316 /**\r
317  *  \brief Set MAC Address\r
318  */\r
319 extern void gmac_set_mac_addr(Gmac* gmac, uint8_t sa_idx, uint8_t* mac);\r
320 \r
321 /**\r
322  *  \brief Set MAC Address using two 32-bit integers\r
323  */\r
324 extern void gmac_set_mac_addr32(Gmac* gmac, uint8_t sa_idx,\r
325                          uint32_t mac_top, uint32_t mac_bottom);\r
326 \r
327 /**\r
328  *  \brief Set MAC Address using a 64-bit integer\r
329  */\r
330 extern void gmac_set_mac_addr64(Gmac* gmac, uint8_t sa_idx, uint64_t mac);\r
331 \r
332 /**\r
333  *  \brief Clear all statistics registers\r
334  */\r
335 extern void gmac_clear_statistics(Gmac* gmac);\r
336 \r
337 /**\r
338  *  \brief Increase all statistics registers\r
339  */\r
340 extern void gmac_increase_statistics(Gmac* gmac);\r
341 \r
342 /**\r
343  *  \brief Enable/Disable statistics registers writing.\r
344  */\r
345 extern void gmac_enable_statistics_write(Gmac* gmac, bool enable);\r
346 \r
347 /**\r
348  *  \brief Start transmission\r
349  */\r
350 extern void gmac_start_transmission(Gmac* gmac);\r
351 \r
352 /**\r
353  *  \brief Halt transmission\r
354  */\r
355 extern void gmac_halt_transmission(Gmac* gmac);\r
356 \r
357 #ifdef __cplusplus\r
358 }\r
359 #endif\r
360 \r
361 #endif /* _GMAC_H_ */\r