]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/BSP/microblaze_0/libsrc/emaclite_v4_2/src/xemaclite.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.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.h
36 * @addtogroup emaclite_v4_1
37 * @{
38 * @details
39 *
40 * The Xilinx Ethernet Lite (EmacLite) driver. This driver supports the Xilinx
41 * Ethernet Lite 10/100 MAC (EmacLite).
42 *
43 * The Xilinx Ethernet Lite 10/100 MAC supports the following features:
44 *   - Media Independent Interface (MII) for connection to external
45 *     10/100 Mbps PHY transceivers
46 *   - Independent internal transmit and receive buffers
47 *   - CSMA/CD compliant operations for half-duplex modes
48 *   - Unicast and broadcast
49 *   - Automatic FCS insertion
50 *   - Automatic pad insertion on transmit
51 *   - Configurable ping/pong buffers for either/both transmit and receive
52 *     buffer areas
53 *   - Interrupt driven mode
54 *   - Internal loop back
55 *   - MDIO Support to access PHY Registers
56 *
57 * The Xilinx Ethernet Lite 10/100 MAC does not support the following features:
58 *   - multi-frame buffering
59 *     only 1 transmit frame is allowed into each transmit buffer,
60 *     only 1 receive frame is allowed into each receive buffer.
61 *     the hardware blocks reception until buffer is emptied
62 *   - Pause frame (flow control) detection in full-duplex mode
63 *   - Programmable inter frame gap
64 *   - Multicast and promiscuous address filtering
65 *   - Automatic source address insertion or overwrite
66 *
67 * <b>Driver Description</b>
68 *
69 * The device driver enables higher layer software (e.g., an application) to
70 * communicate to the EmacLite. The driver handles transmission and reception
71 * of Ethernet frames, as well as configuration of the controller. It does not
72 * handle protocol stack functionality such as Link Layer Control (LLC) or the
73 * Address Resolution Protocol (ARP). The protocol stack that makes use of the
74 * driver handles this functionality. This implies that the driver is simply a
75 * pass-through mechanism between a protocol stack and the EmacLite.
76 *
77 * Since the driver is a simple pass-through mechanism between a protocol stack
78 * and the EmacLite, no assembly or disassembly of Ethernet frames is done at
79 * the driver-level. This assumes that the protocol stack passes a correctly
80 * formatted Ethernet frame to the driver for transmission, and that the driver
81 * does not validate the contents of an incoming frame. A single device driver
82 * can support multiple EmacLite devices.
83 *
84 * The driver supports interrupt driven mode and the default mode of operation
85 * is polled mode. If interrupts are desired, XEmacLite_InterruptEnable() must
86 * be called.
87 *
88 * <b>Device Configuration</b>
89 *
90 * The device can be configured in various ways during the FPGA implementation
91 * process.  Configuration parameters are stored in the xemaclite_g.c file.
92 * A table is defined where each entry contains configuration information for an
93 * EmacLite device. This information includes such things as the base address
94 * of the memory-mapped device and the number of buffers.
95 *
96 * <b>Interrupt Processing</b>
97 *
98 * After _Initialize is called, _InterruptEnable can be called to enable the
99 * interrupt driven functionality. If polled operation is desired, just call
100 * _Send and check the return code. If XST_FAILURE is returned, call _Send with
101 * the same data until XST_SUCCESS is returned. The same idea applies to _Recv.
102 * Call _Recv until the returned length is non-zero at which point the received
103 * data is in the buffer provided in the function call.
104 *
105 * The Transmit and Receive interrupts are enabled within the _InterruptEnable
106 * function and disabled in the _InterruptDisable function. The _Send and _Recv
107 * functions acknowledge the EmacLite generated interrupts associated with each
108 * function.
109 * It is the application's responsibility to acknowledge any associated Interrupt
110 * Controller interrupts if it is used in the system.
111 *
112 * <b>Memory Buffer Alignment</b>
113 *
114 * The alignment of the input/output buffers for the _Send and _Recv routine is
115 * not required to be 32 bits. If the buffer is not aligned on a 32-bit boundary
116 * there will be a performance impact while the driver aligns the data for
117 * transmission or upon reception.
118 *
119 * For optimum performance, the user should provide a 32-bit aligned buffer
120 * to the _Send and _Recv routines.
121 *
122 * <b>Asserts</b>
123 *
124 * Asserts are used within all Xilinx drivers to enforce constraints on argument
125 * values. Asserts can be turned off on a system-wide basis by defining, at
126 * compile time, the NDEBUG identifier.  By default, asserts are turned on and it
127 * is recommended that application developers leave asserts on during
128 * development.
129 *
130 * @note
131 *
132 * This driver requires EmacLite hardware version 1.01a and higher. It is not
133 * compatible with earlier versions of the EmacLite hardware. Use version 1.00a
134 * software driver for hardware version 1.00a/b.
135 *
136 * The RX hardware is enabled from powerup and there is no disable. It is
137 * possible that frames have been received prior to the initialization
138 * of the driver. If this situation is possible, call XEmacLite_FlushReceive()
139 * to empty the receive buffers after initialization.
140 *
141 * This driver is intended to be RTOS and processor independent.  It works
142 * with physical addresses only.  Any needs for dynamic memory management,
143 * threads or thread mutual exclusion, virtual memory, or cache control must
144 * be satisfied by the layer above this driver.
145 *
146 * <pre>
147 * MODIFICATION HISTORY:
148 *
149 * Ver   Who  Date     Changes
150 * ----- ---- -------- -----------------------------------------------
151 * 1.01a ecm  01/30/04 First release
152 * 1.11a mta  03/21/07 Updated to new coding style
153 * 1.12a mta  11/28/07 Added the function XEmacLite_CfgInitialize,
154 *                     moved the functions XEmacLite_LookupConfig and
155 *                     XEmacLite_Initialize to xemaclite_sinit.c for removing
156 *                     the dependency on the static config table and
157 *                     xparameters.h from the driver initialization
158 * 1.13a sv   02/1/08  Updated the TxBufferAvailable routine to return
159 *                     busy status properly and added macros for Tx/Rx status
160 * 1.14a sdm  08/22/08 Removed support for static interrupt handlers from the MDD
161 *                     file
162 * 2.00a ktn  02/16/09 Added support for MDIO and internal loop back
163 * 2.01a ktn  07/20/09 Updated the XEmacLite_AlignedWrite and
164 *                     XEmacLite_AlignedRead functions to use volatile
165 *                     variables so that they are not optimized.
166 *                     Modified the XEmacLite_EnableInterrupts and
167 *                     XEmacLite_DisableInterrupts functions to enable/disable
168 *                     the interrupt in the Ping buffer as this is used to enable
169 *                     the interrupts for both Ping and Pong Buffers.
170 *                     The interrupt enable bit in the Pong buffer is not used by
171 *                     the HW.
172 *                     Modified XEmacLite_Send function to use Ping buffers
173 *                     Interrupt enable bit since this alone is used to enable
174 *                     the interrupts for both Ping and Pong Buffers.
175 * 3.00a ktn  10/22/09 Updated driver to use the HAL Processor APIs/macros.
176 *                     The macros have been renamed to remove _m from the name in
177 *                     all the driver files.
178 *                     The macros changed in this file are
179 *                     XEmacLite_mNextTransmitAddr is XEmacLite_NextTransmitAddr,
180 *                     XEmacLite_mNextReceiveAddr is XEmacLite_NextReceiveAddr,
181 *                     XEmacLite_mIsMdioConfigured is XEmacLite_IsMdioConfigured,
182 *                     XEmacLite_mIsLoopbackConfigured is
183 *                     XEmacLite_IsLoopbackConfigured.
184 *                     See xemaclite_i.h for the macros which have changed.
185 * 3.01a ktn  07/08/10 The macro XEmacLite_GetReceiveDataLength in the
186 *                     xemaclite.c file is changed to a static function.
187 *                     XEmacLite_GetReceiveDataLength and XEmacLite_Recv
188 *                     functions  are updated to support little endian
189 *                     MicroBlaze.
190 * 3.02a sdm  07/22/11 Removed redundant code in XEmacLite_Recv functions for
191 *                     CR617290
192 * 3.03a asa  04/05/12 Defined the flag __LITTLE_ENDIAN__ for cases where the
193 *                     driver is compiled with ARM toolchain.
194 * 3.04a srt  04/13/13 Removed warnings (CR 705000).
195 * 4.0   adk  19/12/13 Updated as per the New Tcl API's
196 * 4.1   nsk  07/13/15 Added Length check in XEmacLite_AlignedWrite function
197 *                     in xemaclite_l.c file to avoid extra write operation
198 *                     (CR 843707).
199 * 4.2   sk   11/10/15 Used UINTPTR instead of u32 for Baseaddress CR# 867425.
200 *                     Changed the prototype of XEmacLite_CfgInitialize API.
201 * 4.2   adk  11/18/15 Fix compilation errors due to conflicting data types
202 *                     CR#917930
203 * 4.2   adk  29/02/16 Updated interrupt example to support Zynq and ZynqMP
204 *                     CR#938244.
205 *
206 * </pre>
207 *
208 *
209 ******************************************************************************/
210 #ifndef XEMACLITE_H             /* prevent circular inclusions */
211 #define XEMACLITE_H             /* by using protection macros */
212
213 #ifdef __cplusplus
214 extern "C" {
215 #endif
216
217 /***************************** Include Files *********************************/
218
219 #include "xenv.h"
220 #include "xil_types.h"
221 #include "xil_assert.h"
222 #include "xstatus.h"
223 #include "xemaclite_l.h"
224
225 #ifdef __ARMEL__
226 #ifndef __LITTLE_ENDIAN__
227 #define __LITTLE_ENDIAN__
228 #endif
229 #endif
230 /************************** Constant Definitions *****************************/
231 /*
232  * Device information
233  */
234 #define XEL_DEVICE_NAME  "xemaclite"
235 #define XEL_DEVICE_DESC  "Xilinx Ethernet Lite 10/100 MAC"
236
237 /**************************** Type Definitions *******************************/
238
239 /**
240  * This typedef contains configuration information for a device.
241  */
242 typedef struct {
243         u16 DeviceId;    /**< Unique ID  of device */
244         UINTPTR BaseAddress; /**< Device base address */
245         u8 TxPingPong;   /**< 1 if TX Pong buffer configured, 0 otherwise */
246         u8 RxPingPong;   /**< 1 if RX Pong buffer configured, 0 otherwise */
247         u8 MdioInclude;  /**< 1 if MDIO is enabled, 0 otherwise */
248         u8 Loopback;     /**< 1 if internal loopback is enabled, 0 otherwise */
249 } XEmacLite_Config;
250
251
252 /*
253  * Callback when data is sent or received .
254  * @param       CallBackRef is a callback reference passed in by the upper layer
255  *              when setting the callback functions, and passed back to the
256  *              upper layer when the callback is invoked.
257  */
258 typedef void (*XEmacLite_Handler) (void *CallBackRef);
259
260 /**
261  * The XEmacLite driver instance data. The user is required to allocate a
262  * variable of this type for every EmacLite device in the system. A pointer
263  * to a variable of this type is then passed to the driver API functions.
264  */
265 typedef struct {
266         XEmacLite_Config EmacLiteConfig; /* Device configuration */
267         u32 IsReady;                     /* Device is initialized and ready */
268
269         u32 NextTxBufferToUse;           /* Next TX buffer to write to */
270         u32 NextRxBufferToUse;           /* Next RX buffer to read from */
271
272         /*
273          * Callbacks
274          */
275         XEmacLite_Handler RecvHandler;
276         void *RecvRef;
277         XEmacLite_Handler SendHandler;
278         void *SendRef;
279
280 } XEmacLite;
281
282 /***************** Macros (Inline Functions) Definitions *********************/
283
284 /****************************************************************************/
285 /**
286 *
287 * Return the next expected Transmit Buffer's address.
288 *
289 * @param        InstancePtr is the pointer to the instance of the driver to
290 *               be worked on
291 *
292 * @note         C-Style signature:
293 *               u32 XEmacLite_NextTransmitAddr(XEmacLite *InstancePtr);
294 *
295 * This macro returns the address of the next transmit buffer to put data into.
296 * This is used to determine the destination of the next transmit data frame.
297 *
298 *****************************************************************************/
299 #define XEmacLite_NextTransmitAddr(InstancePtr)                         \
300         ((InstancePtr)->EmacLiteConfig.BaseAddress +                    \
301                 (InstancePtr)->NextTxBufferToUse) + XEL_TXBUFF_OFFSET
302
303 /****************************************************************************/
304 /**
305 *
306 * Return the next expected Receive Buffer's address.
307 *
308 * @param        InstancePtr is the pointer to the instance of the driver to
309 *               be worked on
310 *
311 * @note         C-Style signature:
312 *               u32 XEmacLite_NextReceiveAddr(XEmacLite *InstancePtr);
313 *
314 * This macro returns the address of the next receive buffer to read data from.
315 * This is the expected receive buffer address if the driver is in sync.
316 *
317 *****************************************************************************/
318 #define XEmacLite_NextReceiveAddr(InstancePtr)                          \
319         ((InstancePtr)->EmacLiteConfig.BaseAddress +                    \
320         (InstancePtr)->NextRxBufferToUse)
321
322 /*****************************************************************************/
323 /**
324 *
325 * This macro determines if the device is currently configured for MDIO.
326 *
327 * @param        InstancePtr is the pointer to the instance of the
328 *               EmacLite driver.
329 *
330 * @return
331 *               - TRUE if the device is configured for MDIO.
332 *               - FALSE if the device is NOT configured for MDIO.
333 *
334 * @note         C-Style signature:
335 *               int XEmacLite_IsMdioConfigured(XEmacLite *InstancePtr)
336 *
337 ******************************************************************************/
338 #define XEmacLite_IsMdioConfigured(InstancePtr)                         \
339         ((InstancePtr)->EmacLiteConfig.MdioInclude == 1)
340
341 /*****************************************************************************/
342 /**
343 *
344 * This macro determines if the device is currently configured for internal
345 * loopback.
346 *
347 * @param        InstancePtr is the pointer to the instance of the
348 *               EmacLite driver.
349 *
350 * @return
351 *               - TRUE if the device is configured for internal loopback.
352 *               - FALSE if the device is NOT configured for internal loopback.
353 *
354 * @note         C-Style signature:
355 *               int XEmacLite_IsLoopbackConfigured(XEmacLite *InstancePtr)
356 *
357 ******************************************************************************/
358 #define XEmacLite_IsLoopbackConfigured(InstancePtr)                     \
359             ((InstancePtr)->EmacLiteConfig.Loopback == 1)
360
361 /************************** Variable Definitions *****************************/
362
363 /************************** Function Prototypes ******************************/
364
365 /*
366  * Functions in xemaclite.c
367  */
368 int XEmacLite_CfgInitialize(XEmacLite *InstancePtr,
369                                 XEmacLite_Config *EmacLiteConfigPtr,
370                                 UINTPTR EffectiveAddr);
371 void XEmacLite_SetMacAddress(XEmacLite *InstancePtr, u8 *AddressPtr);
372 int XEmacLite_TxBufferAvailable(XEmacLite *InstancePtr);
373 void XEmacLite_FlushReceive(XEmacLite *InstancePtr);
374
375 int XEmacLite_Send(XEmacLite *InstancePtr, u8 *FramePtr, unsigned ByteCount);
376 u16 XEmacLite_Recv(XEmacLite *InstancePtr, u8 *FramePtr);
377
378 int XEmacLite_PhyRead(XEmacLite *InstancePtr, u32 PhyAddress, u32 RegNum,
379                         u16 *PhyDataPtr);
380 int XEmacLite_PhyWrite(XEmacLite *InstancePtr, u32 PhyAddress, u32 RegNum,
381                         u16 PhyData);
382
383 void XEmacLite_EnableLoopBack(XEmacLite *InstancePtr);
384 void XEmacLite_DisableLoopBack(XEmacLite *InstancePtr);
385
386 /*
387  * Initialization functions in xemaclite_sinit.c
388  */
389 XEmacLite_Config *XEmacLite_LookupConfig(u16 DeviceId);
390 int XEmacLite_Initialize(XEmacLite *InstancePtr, u16 DeviceId);
391
392 /*
393  * Interrupt driven functions in xemaclite_intr.c
394  */
395 int XEmacLite_EnableInterrupts(XEmacLite *InstancePtr);
396 void XEmacLite_DisableInterrupts(XEmacLite *InstancePtr);
397
398 void XEmacLite_InterruptHandler(void *InstancePtr);
399
400 void XEmacLite_SetRecvHandler(XEmacLite *InstancePtr, void *CallBackRef,
401                               XEmacLite_Handler FuncPtr);
402 void XEmacLite_SetSendHandler(XEmacLite *InstancePtr, void *CallBackRef,
403                               XEmacLite_Handler FuncPtr);
404
405 /*
406  * Selftest function in xemaclite_selftest.c
407  */
408 int XEmacLite_SelfTest(XEmacLite *InstancePtr);
409
410 #ifdef __cplusplus
411 }
412 #endif
413
414 #endif /* end of protection macro */
415
416
417 /** @} */