1 /******************************************************************************
3 * Copyright (C) 2004 - 2014 Xilinx, Inc. All rights reserved.
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
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
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.
31 ******************************************************************************/
32 /*****************************************************************************/
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).
40 * Refer to xemaclite.h for more details.
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.
54 * MODIFICATION HISTORY:
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.
76 ******************************************************************************/
78 #ifndef XEMAC_LITE_L_H /* prevent circular inclusions */
79 #define XEMAC_LITE_L_H /* by using protection macros */
85 /***************************** Include Files *********************************/
87 #include "xil_types.h"
88 #include "xil_assert.h"
91 /************************** Constant Definitions *****************************/
93 * Register offsets for the Ethernet MAC.
95 #define XEL_TXBUFF_OFFSET (0x00000000) /**< Transmit Buffer */
96 #define XEL_MDIOADDR_OFFSET (XEL_TXBUFF_OFFSET + 0x07E4)/**< MDIO Address offset
98 #define XEL_MDIOWR_OFFSET (XEL_TXBUFF_OFFSET + 0x07E8) /**< MDIO write data
100 #define XEL_MDIORD_OFFSET (XEL_TXBUFF_OFFSET + 0x07EC) /**< MDIO read data
102 #define XEL_MDIOCNTR_OFFSET (XEL_TXBUFF_OFFSET + 0x07F0)/**< MDIO Control
104 #define XEL_GIER_OFFSET (XEL_TXBUFF_OFFSET + 0x07F8) /**< Offset for the GIE
106 #define XEL_TSR_OFFSET (XEL_TXBUFF_OFFSET + 0x07FC) /**< Tx status */
107 #define XEL_TPLR_OFFSET (XEL_TXBUFF_OFFSET + 0x07F4) /**< Tx packet length */
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 */
113 #define XEL_MAC_HI_OFFSET (XEL_TXBUFF_OFFSET + 0x14) /**< MAC address hi
115 #define XEL_MAC_LO_OFFSET (XEL_TXBUFF_OFFSET) /**< MAC address lo
118 #define XEL_BUFFER_OFFSET (0x00000800) /**< Next buffer's
122 * MDIO Address/Write Data/Read Data Register Bit Masks
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 */
129 * MDIO Control Register Bit Masks
131 #define XEL_MDIOCNTR_STATUS_MASK 0x00000001 /**< MDIO transfer in
133 #define XEL_MDIOCNTR_ENABLE_MASK 0x00000008 /**< MDIO Enable */
136 * Global Interrupt Enable Register (GIER) Bit Masks
138 #define XEL_GIER_GIE_MASK 0x80000000 /**< Global Enable */
141 * Transmit Status Register (TSR) Bit Masks
143 #define XEL_TSR_XMIT_BUSY_MASK 0x00000001 /**< Xmit complete */
144 #define XEL_TSR_PROGRAM_MASK 0x00000002 /**< Program the MAC
146 #define XEL_TSR_XMIT_IE_MASK 0x00000008 /**< Xmit interrupt
148 #define XEL_TSR_LOOPBACK_MASK 0x00000010 /**< Loop back enable
150 #define XEL_TSR_XMIT_ACTIVE_MASK 0x80000000 /**< Buffer is active,
156 * define for programming the MAC address into the EmacLite
158 #define XEL_TSR_PROG_MAC_ADDR (XEL_TSR_XMIT_BUSY_MASK | XEL_TSR_PROGRAM_MASK)
161 * Receive Status Register (RSR)
163 #define XEL_RSR_RECV_DONE_MASK 0x00000001 /**< Recv complete */
164 #define XEL_RSR_RECV_IE_MASK 0x00000008 /**< Recv interrupt
168 * Transmit Packet Length Register (TPLR)
170 #define XEL_TPLR_LENGTH_MASK_HI 0x0000FF00 /**< Transmit packet length
172 #define XEL_TPLR_LENGTH_MASK_LO 0x000000FF /**< Transmit packet length
176 * Receive Packet Length Register (RPLR)
178 #define XEL_RPLR_LENGTH_MASK_HI 0x0000FF00 /**< Receive packet length
180 #define XEL_RPLR_LENGTH_MASK_LO 0x000000FF /**< Receive packet length
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 */
187 #define XEL_HEADER_OFFSET 12 /**< Offset to length field */
188 #define XEL_HEADER_SHIFT 16 /**< Right shift value to align
192 #define XEL_MAX_FRAME_SIZE (XEL_HEADER_SIZE+XEL_MTU_SIZE+ XEL_FCS_SIZE) /**< Max
193 length of Rx frame used if
195 contains the type (> 1500) */
197 #define XEL_MAX_TX_FRAME_SIZE (XEL_HEADER_SIZE + XEL_MTU_SIZE) /**< Max
198 length of Tx frame */
201 #define XEL_MAC_ADDR_SIZE 6 /**< length of MAC address */
205 * General Ethernet Definitions
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 */
214 /***************** Macros (Inline Functions) Definitions *********************/
216 #define XEmacLite_In32 Xil_In32
217 #define XEmacLite_Out32 Xil_Out32
219 /****************************************************************************/
222 * Read from the specified EmacLite device register.
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.
228 * @return The value read from the register.
230 * @note C-Style signature:
231 * u32 XEmacLite_ReadReg(u32 BaseAddress, u32 RegOffset);
233 ******************************************************************************/
234 #define XEmacLite_ReadReg(BaseAddress, RegOffset) \
235 XEmacLite_In32((BaseAddress) + (RegOffset))
237 /***************************************************************************/
240 * Write to the specified EmacLite device register.
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.
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))
257 /****************************************************************************/
260 * Get the Tx Status Register Contents.
262 * @param BaseAddress is the base address of the device
264 * @return The contents of the Tx Status Register.
266 * @note C-Style signature:
267 * u32 XEmacLite_GetTxStatus(u32 BaseAddress)
269 *****************************************************************************/
270 #define XEmacLite_GetTxStatus(BaseAddress) \
271 (XEmacLite_ReadReg((BaseAddress), XEL_TSR_OFFSET))
274 /****************************************************************************/
277 * Set the Tx Status Register Contents.
279 * @param BaseAddress is the base address of the device
280 * @param Data is the value to be written to the Register.
284 * @note C-Style signature:
285 * u32 XEmacLite_SetTxStatus(u32 BaseAddress, u32 Data)
287 *****************************************************************************/
288 #define XEmacLite_SetTxStatus(BaseAddress, Data) \
289 (XEmacLite_WriteReg((BaseAddress), XEL_TSR_OFFSET, (Data)))
292 /****************************************************************************/
295 * Get the Rx Status Register Contents.
297 * @param BaseAddress is the base address of the device
299 * @return The contents of the Rx Status Register.
301 * @note C-Style signature:
302 * u32 XEmacLite_GetRxStatus(u32 BaseAddress)
304 *****************************************************************************/
305 #define XEmacLite_GetRxStatus(BaseAddress) \
306 (XEmacLite_ReadReg((BaseAddress), XEL_RSR_OFFSET))
309 /****************************************************************************/
312 * Set the Rx Status Register Contents.
314 * @param BaseAddress is the base address of the device
315 * @param Data is the value to be written to the Register.
319 * @note C-Style signature:
320 * u32 XEmacLite_SetRxStatus(u32 BaseAddress, u32 Data)
322 *****************************************************************************/
323 #define XEmacLite_SetRxStatus(BaseAddress, Data) \
324 (XEmacLite_WriteReg((BaseAddress), XEL_RSR_OFFSET, (Data)))
327 /****************************************************************************/
330 * Check to see if the transmission is complete.
332 * @param BaseAddress is the base address of the device
334 * @return TRUE if it is done, or FALSE if it is not.
336 * @note C-Style signature:
337 * int XEmacLite_IsTxDone(u32 BaseAddress)
339 *****************************************************************************/
340 #define XEmacLite_IsTxDone(BaseAddress) \
341 ((XEmacLite_ReadReg((BaseAddress), XEL_TSR_OFFSET) & \
342 XEL_TSR_XMIT_BUSY_MASK) != XEL_TSR_XMIT_BUSY_MASK)
345 /****************************************************************************/
348 * Check to see if the receive is empty.
350 * @param BaseAddress is the base address of the device
352 * @return TRUE if it is empty, or FALSE if it is not.
354 * @note C-Style signature:
355 * int XEmacLite_IsRxEmpty(u32 BaseAddress)
357 *****************************************************************************/
358 #define XEmacLite_IsRxEmpty(BaseAddress) \
359 ((XEmacLite_ReadReg((BaseAddress), XEL_RSR_OFFSET) & \
360 XEL_RSR_RECV_DONE_MASK) != XEL_RSR_RECV_DONE_MASK)
362 /************************** Function Prototypes ******************************/
364 void XEmacLite_SendFrame(u32 BaseAddress, u8 *FramePtr, unsigned ByteCount);
365 u16 XEmacLite_RecvFrame(u32 BaseAddress, u8 *FramePtr);
371 #endif /* end of protection macro */