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 /*****************************************************************************/
36 * @addtogroup emaclite_v4_1
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).
42 * Refer to xemaclite.h for more details.
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.
56 * MODIFICATION HISTORY:
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.
81 ******************************************************************************/
83 #ifndef XEMAC_LITE_L_H /* prevent circular inclusions */
84 #define XEMAC_LITE_L_H /* by using protection macros */
90 /***************************** Include Files *********************************/
92 #include "xil_types.h"
93 #include "xil_assert.h"
96 /************************** Constant Definitions *****************************/
98 * Register offsets for the Ethernet MAC.
100 #define XEL_TXBUFF_OFFSET (0x00000000) /**< Transmit Buffer */
101 #define XEL_MDIOADDR_OFFSET (XEL_TXBUFF_OFFSET + 0x07E4)/**< MDIO Address offset
103 #define XEL_MDIOWR_OFFSET (XEL_TXBUFF_OFFSET + 0x07E8) /**< MDIO write data
105 #define XEL_MDIORD_OFFSET (XEL_TXBUFF_OFFSET + 0x07EC) /**< MDIO read data
107 #define XEL_MDIOCNTR_OFFSET (XEL_TXBUFF_OFFSET + 0x07F0)/**< MDIO Control
109 #define XEL_GIER_OFFSET (XEL_TXBUFF_OFFSET + 0x07F8) /**< Offset for the GIE
111 #define XEL_TSR_OFFSET (XEL_TXBUFF_OFFSET + 0x07FC) /**< Tx status */
112 #define XEL_TPLR_OFFSET (XEL_TXBUFF_OFFSET + 0x07F4) /**< Tx packet length */
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 */
118 #define XEL_MAC_HI_OFFSET (XEL_TXBUFF_OFFSET + 0x14) /**< MAC address hi
120 #define XEL_MAC_LO_OFFSET (XEL_TXBUFF_OFFSET) /**< MAC address lo
123 #define XEL_BUFFER_OFFSET (0x00000800) /**< Next buffer's
127 * MDIO Address/Write Data/Read Data Register Bit Masks
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 */
134 * MDIO Control Register Bit Masks
136 #define XEL_MDIOCNTR_STATUS_MASK 0x00000001 /**< MDIO transfer in
138 #define XEL_MDIOCNTR_ENABLE_MASK 0x00000008 /**< MDIO Enable */
141 * Global Interrupt Enable Register (GIER) Bit Masks
143 #define XEL_GIER_GIE_MASK 0x80000000 /**< Global Enable */
146 * Transmit Status Register (TSR) Bit Masks
148 #define XEL_TSR_XMIT_BUSY_MASK 0x00000001 /**< Xmit complete */
149 #define XEL_TSR_PROGRAM_MASK 0x00000002 /**< Program the MAC
151 #define XEL_TSR_XMIT_IE_MASK 0x00000008 /**< Xmit interrupt
153 #define XEL_TSR_LOOPBACK_MASK 0x00000010 /**< Loop back enable
155 #define XEL_TSR_XMIT_ACTIVE_MASK 0x80000000 /**< Buffer is active,
161 * define for programming the MAC address into the EmacLite
163 #define XEL_TSR_PROG_MAC_ADDR (XEL_TSR_XMIT_BUSY_MASK | XEL_TSR_PROGRAM_MASK)
166 * Receive Status Register (RSR)
168 #define XEL_RSR_RECV_DONE_MASK 0x00000001 /**< Recv complete */
169 #define XEL_RSR_RECV_IE_MASK 0x00000008 /**< Recv interrupt
173 * Transmit Packet Length Register (TPLR)
175 #define XEL_TPLR_LENGTH_MASK_HI 0x0000FF00 /**< Transmit packet length
177 #define XEL_TPLR_LENGTH_MASK_LO 0x000000FF /**< Transmit packet length
181 * Receive Packet Length Register (RPLR)
183 #define XEL_RPLR_LENGTH_MASK_HI 0x0000FF00 /**< Receive packet length
185 #define XEL_RPLR_LENGTH_MASK_LO 0x000000FF /**< Receive packet length
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 */
192 #define XEL_HEADER_OFFSET 12 /**< Offset to length field */
193 #define XEL_HEADER_SHIFT 16 /**< Right shift value to align
197 #define XEL_MAX_FRAME_SIZE (XEL_HEADER_SIZE+XEL_MTU_SIZE+ XEL_FCS_SIZE) /**< Max
198 length of Rx frame used if
200 contains the type (> 1500) */
202 #define XEL_MAX_TX_FRAME_SIZE (XEL_HEADER_SIZE + XEL_MTU_SIZE) /**< Max
203 length of Tx frame */
206 #define XEL_MAC_ADDR_SIZE 6 /**< length of MAC address */
210 * General Ethernet Definitions
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 */
219 /***************** Macros (Inline Functions) Definitions *********************/
221 #define XEmacLite_In32 Xil_In32
222 #define XEmacLite_Out32 Xil_Out32
224 /****************************************************************************/
227 * Read from the specified EmacLite device register.
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.
233 * @return The value read from the register.
235 * @note C-Style signature:
236 * u32 XEmacLite_ReadReg(u32 BaseAddress, u32 RegOffset);
238 ******************************************************************************/
239 #define XEmacLite_ReadReg(BaseAddress, RegOffset) \
240 XEmacLite_In32((BaseAddress) + (RegOffset))
242 /***************************************************************************/
245 * Write to the specified EmacLite device register.
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.
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))
262 /****************************************************************************/
265 * Get the Tx Status Register Contents.
267 * @param BaseAddress is the base address of the device
269 * @return The contents of the Tx Status Register.
271 * @note C-Style signature:
272 * u32 XEmacLite_GetTxStatus(u32 BaseAddress)
274 *****************************************************************************/
275 #define XEmacLite_GetTxStatus(BaseAddress) \
276 (XEmacLite_ReadReg((BaseAddress), XEL_TSR_OFFSET))
279 /****************************************************************************/
282 * Set the Tx Status Register Contents.
284 * @param BaseAddress is the base address of the device
285 * @param Data is the value to be written to the Register.
289 * @note C-Style signature:
290 * u32 XEmacLite_SetTxStatus(u32 BaseAddress, u32 Data)
292 *****************************************************************************/
293 #define XEmacLite_SetTxStatus(BaseAddress, Data) \
294 (XEmacLite_WriteReg((BaseAddress), XEL_TSR_OFFSET, (Data)))
297 /****************************************************************************/
300 * Get the Rx Status Register Contents.
302 * @param BaseAddress is the base address of the device
304 * @return The contents of the Rx Status Register.
306 * @note C-Style signature:
307 * u32 XEmacLite_GetRxStatus(u32 BaseAddress)
309 *****************************************************************************/
310 #define XEmacLite_GetRxStatus(BaseAddress) \
311 (XEmacLite_ReadReg((BaseAddress), XEL_RSR_OFFSET))
314 /****************************************************************************/
317 * Set the Rx Status Register Contents.
319 * @param BaseAddress is the base address of the device
320 * @param Data is the value to be written to the Register.
324 * @note C-Style signature:
325 * u32 XEmacLite_SetRxStatus(u32 BaseAddress, u32 Data)
327 *****************************************************************************/
328 #define XEmacLite_SetRxStatus(BaseAddress, Data) \
329 (XEmacLite_WriteReg((BaseAddress), XEL_RSR_OFFSET, (Data)))
332 /****************************************************************************/
335 * Check to see if the transmission is complete.
337 * @param BaseAddress is the base address of the device
339 * @return TRUE if it is done, or FALSE if it is not.
341 * @note C-Style signature:
342 * int XEmacLite_IsTxDone(u32 BaseAddress)
344 *****************************************************************************/
345 #define XEmacLite_IsTxDone(BaseAddress) \
346 ((XEmacLite_ReadReg((BaseAddress), XEL_TSR_OFFSET) & \
347 XEL_TSR_XMIT_BUSY_MASK) != XEL_TSR_XMIT_BUSY_MASK)
350 /****************************************************************************/
353 * Check to see if the receive is empty.
355 * @param BaseAddress is the base address of the device
357 * @return TRUE if it is empty, or FALSE if it is not.
359 * @note C-Style signature:
360 * int XEmacLite_IsRxEmpty(u32 BaseAddress)
362 *****************************************************************************/
363 #define XEmacLite_IsRxEmpty(BaseAddress) \
364 ((XEmacLite_ReadReg((BaseAddress), XEL_RSR_OFFSET) & \
365 XEL_RSR_RECV_DONE_MASK) != XEL_RSR_RECV_DONE_MASK)
367 /************************** Function Prototypes ******************************/
369 void XEmacLite_SendFrame(UINTPTR BaseAddress, u8 *FramePtr, unsigned ByteCount);
370 u16 XEmacLite_RecvFrame(UINTPTR BaseAddress, u8 *FramePtr);
376 #endif /* end of protection macro */