]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/BSP/microblaze_0/libsrc/emaclite_v4_0/src/xemaclite_l.h
a0b812105e9ac4b0cae989c484e2da7ed70c2ec7
[freertos] / FreeRTOS / Demo / MicroBlaze_Kintex7_EthernetLite / BSP / microblaze_0 / libsrc / emaclite_v4_0 / src / xemaclite_l.h
1 /******************************************************************************
2 *
3 * Copyright (C) 2004 - 2014 Xilinx, Inc.  All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 *
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
30 *
31 ******************************************************************************/
32 /*****************************************************************************/
33 /**
34 *
35 * @file xemaclite_l.h
36 *
37 * This header file contains identifiers and basic driver functions and macros
38 * that can be used to access the Xilinx Ethernet Lite 10/100 MAC (EmacLite).
39 *
40 * Refer to xemaclite.h for more details.
41 *
42 * @note
43 *
44 * The functions and macros in this file assume that the proper device address is
45 * provided in the argument. If the ping buffer is the source or destination,
46 * the argument should be DeviceAddress + XEL_(T/R)XBUFF_OFFSET. If the pong
47 * buffer is the source or destination, the argument should be
48 * DeviceAddress + XEL_(T/R)XBUFF_OFFSET + XEL_BUFFER_OFFSET. The driver does
49 * not take the different buffers into consideration.
50 * For more details on the ping/pong buffer configuration please refer to the
51 * Ethernet Lite 10/100 Media Access Controller hardware specification.
52 *
53 * <pre>
54 * MODIFICATION HISTORY:
55 *
56 * Ver   Who  Date     Changes
57 * ----- ---- -------- -----------------------------------------------
58 * 1.00a ecm  06/01/02 First release
59 * 1.01a ecm  03/31/04 Additional functionality and the _AlignedRead and
60 *                     AlignedWrite functions.
61 *                     Moved the bulk of description to xemaclite.h
62 * 1.11a mta  03/21/07 Updated to new coding style
63 * 2.00a ktn  02/16/09 Added support for MDIO and internal loop back
64 * 3.00a ktn  10/22/09 The macros have been renamed to remove _m from the name.
65 *                     The macros changed in this file are
66 *                     XEmacLite_mReadReg changed to XEmacLite_mReadReg,
67 *                     XEmacLite_mWriteReg changed to XEmacLite_mWriteReg,
68 *                     XEmacLite_mGetTxStatus changed to XEmacLite_GetTxStatus,
69 *                     XEmacLite_mSetTxStatus changed to XEmacLite_SetTxStatus,
70 *                     XEmacLite_mGetRxStatus changed to XEmacLite_GetRxStatus,
71 *                     XEmacLite_mSetRxStatus changed to XEmacLite_SetRxStatus,
72 *                     XEmacLite_mIsTxDone changed to XEmacLite_IsTxDone and
73 *                     XEmacLite_mIsRxEmpty changed to XEmacLite_IsRxEmpty.
74 * </pre>
75 *
76 ******************************************************************************/
77
78 #ifndef XEMAC_LITE_L_H          /* prevent circular inclusions */
79 #define XEMAC_LITE_L_H          /* by using protection macros */
80
81 #ifdef __cplusplus
82 extern "C" {
83 #endif
84
85 /***************************** Include Files *********************************/
86
87 #include "xil_types.h"
88 #include "xil_assert.h"
89 #include "xil_io.h"
90
91 /************************** Constant Definitions *****************************/
92 /**
93  * Register offsets for the Ethernet MAC.
94  */
95 #define XEL_TXBUFF_OFFSET (0x00000000)                  /**< Transmit Buffer */
96 #define XEL_MDIOADDR_OFFSET (XEL_TXBUFF_OFFSET + 0x07E4)/**< MDIO Address offset
97                                                              register */
98 #define XEL_MDIOWR_OFFSET  (XEL_TXBUFF_OFFSET + 0x07E8) /**< MDIO write data
99                                                              register offset */
100 #define XEL_MDIORD_OFFSET (XEL_TXBUFF_OFFSET + 0x07EC)  /**< MDIO read data
101                                                              register offset*/
102 #define XEL_MDIOCNTR_OFFSET (XEL_TXBUFF_OFFSET + 0x07F0)/**< MDIO Control
103                                                              Register offset */
104 #define XEL_GIER_OFFSET   (XEL_TXBUFF_OFFSET + 0x07F8)  /**< Offset for the GIE
105                                                              Register */
106 #define XEL_TSR_OFFSET    (XEL_TXBUFF_OFFSET + 0x07FC)  /**< Tx status */
107 #define XEL_TPLR_OFFSET   (XEL_TXBUFF_OFFSET + 0x07F4)  /**< Tx packet length */
108
109 #define XEL_RXBUFF_OFFSET (0x00001000)                  /**< Receive Buffer */
110 #define XEL_RSR_OFFSET    (XEL_RXBUFF_OFFSET + 0x07FC)  /**< Rx status */
111 #define XEL_RPLR_OFFSET   (XEL_RXBUFF_OFFSET + 0x0C)    /**< Rx packet length */
112
113 #define XEL_MAC_HI_OFFSET (XEL_TXBUFF_OFFSET + 0x14)    /**< MAC address hi
114                                                              offset */
115 #define XEL_MAC_LO_OFFSET (XEL_TXBUFF_OFFSET)           /**< MAC address lo
116                                                              offset */
117
118 #define XEL_BUFFER_OFFSET (0x00000800)                  /**< Next buffer's
119                                                              offset  same for
120                                                              both TX and RX */
121 /**
122  * MDIO Address/Write Data/Read Data Register Bit Masks
123  */
124 #define XEL_MDIO_ADDRESS_MASK           0x00003E0       /**< PHY Address mask */
125 #define XEL_MDIO_ADDRESS_SHIFT          0x5             /**< PHY Address shift*/
126 #define XEL_MDIO_OP_MASK                0x00000400      /**< PHY read access */
127
128 /**
129  * MDIO Control Register Bit Masks
130  */
131 #define XEL_MDIOCNTR_STATUS_MASK        0x00000001      /**< MDIO transfer in
132                                                              Progress */
133 #define XEL_MDIOCNTR_ENABLE_MASK        0x00000008      /**<  MDIO Enable */
134
135 /**
136  * Global Interrupt Enable Register (GIER) Bit Masks
137  */
138 #define XEL_GIER_GIE_MASK               0x80000000      /**< Global Enable */
139
140 /**
141  * Transmit Status Register (TSR) Bit Masks
142  */
143 #define XEL_TSR_XMIT_BUSY_MASK          0x00000001      /**< Xmit complete */
144 #define XEL_TSR_PROGRAM_MASK            0x00000002      /**< Program the MAC
145                                                              address */
146 #define XEL_TSR_XMIT_IE_MASK            0x00000008      /**< Xmit interrupt
147                                                              enable bit */
148 #define XEL_TSR_LOOPBACK_MASK           0x00000010      /**< Loop back enable
149                                                              bit */
150 #define XEL_TSR_XMIT_ACTIVE_MASK        0x80000000      /**< Buffer is active,
151                                                              SW bit only. This
152                                                              is not documented
153                                                              in the HW spec */
154
155 /**
156  * define for programming the MAC address into the EmacLite
157  */
158 #define XEL_TSR_PROG_MAC_ADDR   (XEL_TSR_XMIT_BUSY_MASK | XEL_TSR_PROGRAM_MASK)
159
160 /**
161  * Receive Status Register (RSR)
162  */
163 #define XEL_RSR_RECV_DONE_MASK          0x00000001      /**< Recv complete */
164 #define XEL_RSR_RECV_IE_MASK            0x00000008      /**< Recv interrupt
165                                                              enable bit */
166
167 /**
168  * Transmit Packet Length Register (TPLR)
169  */
170 #define XEL_TPLR_LENGTH_MASK_HI         0x0000FF00 /**< Transmit packet length
171                                                           upper byte */
172 #define XEL_TPLR_LENGTH_MASK_LO         0x000000FF /**< Transmit packet length
173                                                           lower byte */
174
175 /**
176  * Receive Packet Length Register (RPLR)
177  */
178 #define XEL_RPLR_LENGTH_MASK_HI         0x0000FF00 /**< Receive packet length
179                                                           upper byte */
180 #define XEL_RPLR_LENGTH_MASK_LO         0x000000FF /**< Receive packet length
181                                                           lower byte */
182
183 #define XEL_HEADER_SIZE                 14  /**< Size of header in bytes */
184 #define XEL_MTU_SIZE                    1500 /**< Max size of data in frame */
185 #define XEL_FCS_SIZE                    4    /**< Size of CRC */
186
187 #define XEL_HEADER_OFFSET               12   /**< Offset to length field */
188 #define XEL_HEADER_SHIFT                16   /**< Right shift value to align
189                                                   length */
190
191
192 #define XEL_MAX_FRAME_SIZE (XEL_HEADER_SIZE+XEL_MTU_SIZE+ XEL_FCS_SIZE) /**< Max
193                                                 length of Rx frame  used if
194                                                 length/type field
195                                                 contains the type (> 1500) */
196
197 #define XEL_MAX_TX_FRAME_SIZE (XEL_HEADER_SIZE + XEL_MTU_SIZE)  /**< Max
198                                                 length of Tx frame */
199
200
201 #define XEL_MAC_ADDR_SIZE               6       /**< length of MAC address */
202
203
204 /*
205  * General Ethernet Definitions
206  */
207 #define XEL_ETHER_PROTO_TYPE_IP         0x0800  /**< IP Protocol */
208 #define XEL_ETHER_PROTO_TYPE_ARP        0x0806  /**< ARP Protocol */
209 #define XEL_ETHER_PROTO_TYPE_VLAN       0x8100  /**< VLAN Tagged */
210 #define XEL_ARP_PACKET_SIZE             28      /**< Max ARP packet size */
211 #define XEL_HEADER_IP_LENGTH_OFFSET     16      /**< IP Length Offset */
212 #define XEL_VLAN_TAG_SIZE               4       /**< VLAN Tag Size */
213
214 /***************** Macros (Inline Functions) Definitions *********************/
215
216 #define XEmacLite_In32 Xil_In32
217 #define XEmacLite_Out32 Xil_Out32
218
219 /****************************************************************************/
220 /**
221 *
222 * Read from the specified EmacLite device register.
223 *
224 * @param        BaseAddress contains the base address of the device.
225 * @param        RegOffset contains the offset from the 1st register of the
226 *               device to select the specific register.
227 *
228 * @return       The value read from the register.
229 *
230 * @note         C-Style signature:
231 *               u32 XEmacLite_ReadReg(u32 BaseAddress, u32 RegOffset);
232 *
233 ******************************************************************************/
234 #define XEmacLite_ReadReg(BaseAddress, RegOffset) \
235         XEmacLite_In32((BaseAddress) + (RegOffset))
236
237 /***************************************************************************/
238 /**
239 *
240 * Write to the specified EmacLite device register.
241 *
242 * @param        BaseAddress contains the base address of the device.
243 * @param        RegOffset contains the offset from the 1st register of the
244 *               device to select the specific register.
245 * @param        RegisterValue is the value to be written to the register.
246 *
247 * @return       None.
248 *
249 * @note         C-Style signature:
250 *               void XEmacLite_WriteReg(u32 BaseAddress, u32 RegOffset,
251 *                                       u32 RegisterValue);
252 ******************************************************************************/
253 #define XEmacLite_WriteReg(BaseAddress, RegOffset, RegisterValue) \
254         XEmacLite_Out32((BaseAddress) + (RegOffset), (RegisterValue))
255
256
257 /****************************************************************************/
258 /**
259 *
260 * Get the Tx Status Register Contents.
261 *
262 * @param        BaseAddress is the base address of the device
263 *
264 * @return       The contents of the Tx Status Register.
265 *
266 * @note         C-Style signature:
267 *               u32 XEmacLite_GetTxStatus(u32 BaseAddress)
268 *
269 *****************************************************************************/
270 #define XEmacLite_GetTxStatus(BaseAddress)                      \
271         (XEmacLite_ReadReg((BaseAddress), XEL_TSR_OFFSET))
272
273
274 /****************************************************************************/
275 /**
276 *
277 * Set the Tx Status Register Contents.
278 *
279 * @param        BaseAddress is the base address of the device
280 * @param        Data is the value to be written to the Register.
281 *
282 * @return       None.
283 *
284 * @note         C-Style signature:
285 *               u32 XEmacLite_SetTxStatus(u32 BaseAddress, u32 Data)
286 *
287 *****************************************************************************/
288 #define XEmacLite_SetTxStatus(BaseAddress, Data)                        \
289         (XEmacLite_WriteReg((BaseAddress), XEL_TSR_OFFSET, (Data)))
290
291
292 /****************************************************************************/
293 /**
294 *
295 * Get the Rx Status Register Contents.
296 *
297 * @param        BaseAddress is the base address of the device
298 *
299 * @return       The contents of the Rx Status Register.
300 *
301 * @note         C-Style signature:
302 *               u32 XEmacLite_GetRxStatus(u32 BaseAddress)
303 *
304 *****************************************************************************/
305 #define XEmacLite_GetRxStatus(BaseAddress)                      \
306         (XEmacLite_ReadReg((BaseAddress), XEL_RSR_OFFSET))
307
308
309 /****************************************************************************/
310 /**
311 *
312 * Set the Rx Status Register Contents.
313 *
314 * @param        BaseAddress is the base address of the device
315 * @param        Data is the value to be written to the Register.
316 *
317 * @return       None.
318 *
319 * @note         C-Style signature:
320 *               u32 XEmacLite_SetRxStatus(u32 BaseAddress, u32 Data)
321 *
322 *****************************************************************************/
323 #define XEmacLite_SetRxStatus(BaseAddress, Data)                        \
324         (XEmacLite_WriteReg((BaseAddress), XEL_RSR_OFFSET, (Data)))
325
326
327 /****************************************************************************/
328 /**
329 *
330 * Check to see if the transmission is complete.
331 *
332 * @param        BaseAddress is the base address of the device
333 *
334 * @return       TRUE if it is done, or FALSE if it is not.
335 *
336 * @note         C-Style signature:
337 *               int XEmacLite_IsTxDone(u32 BaseAddress)
338 *
339 *****************************************************************************/
340 #define XEmacLite_IsTxDone(BaseAddress)                 \
341                  ((XEmacLite_ReadReg((BaseAddress), XEL_TSR_OFFSET) &    \
342                          XEL_TSR_XMIT_BUSY_MASK) != XEL_TSR_XMIT_BUSY_MASK)
343
344
345 /****************************************************************************/
346 /**
347 *
348 * Check to see if the receive is empty.
349 *
350 * @param        BaseAddress is the base address of the device
351 *
352 * @return       TRUE if it is empty, or FALSE if it is not.
353 *
354 * @note         C-Style signature:
355 *               int XEmacLite_IsRxEmpty(u32 BaseAddress)
356 *
357 *****************************************************************************/
358 #define XEmacLite_IsRxEmpty(BaseAddress) \
359                   ((XEmacLite_ReadReg((BaseAddress), XEL_RSR_OFFSET) & \
360                         XEL_RSR_RECV_DONE_MASK) != XEL_RSR_RECV_DONE_MASK)
361
362 /************************** Function Prototypes ******************************/
363
364 void XEmacLite_SendFrame(u32 BaseAddress, u8 *FramePtr, unsigned ByteCount);
365 u16 XEmacLite_RecvFrame(u32 BaseAddress, u8 *FramePtr);
366
367 #ifdef __cplusplus
368 }
369 #endif
370
371 #endif /* end of protection macro */