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