1 /******************************************************************************
3 * Copyright (C) 2010 - 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 /*****************************************************************************/
35 * @file xusbps_endpoint.h
36 * @addtogroup usbps_v2_1
39 * This is an internal file containung the definitions for endpoints. It is
40 * included by the xusbps_endpoint.c which is implementing the endpoint
41 * functions and by xusbps_intr.c.
44 * MODIFICATION HISTORY:
46 * Ver Who Date Changes
47 * ----- ---- -------- --------------------------------------------------------
48 * 1.00a wgr 10/10/10 First release
51 ******************************************************************************/
52 #ifndef XUSBPS_ENDPOINT_H
53 #define XUSBPS_ENDPOINT_H
59 /***************************** Include Files *********************************/
61 #include "xil_cache.h"
63 #include "xil_types.h"
65 /**************************** Type Definitions *******************************/
67 /************************** Constant Definitions *****************************/
71 * Endpoint Device Transfer Descriptor
73 * The dTD describes to the device controller the location and quantity of data
74 * to be sent/received for given transfer. The driver does not attempt to
75 * modify any field in an active dTD except the Next Link Pointer.
77 #define XUSBPS_dTDNLP 0x00 /**< Pointer to the next descriptor */
78 #define XUSBPS_dTDTOKEN 0x04 /**< Descriptor Token */
79 #define XUSBPS_dTDBPTR0 0x08 /**< Buffer Pointer 0 */
80 #define XUSBPS_dTDBPTR1 0x0C /**< Buffer Pointer 1 */
81 #define XUSBPS_dTDBPTR2 0x10 /**< Buffer Pointer 2 */
82 #define XUSBPS_dTDBPTR3 0x14 /**< Buffer Pointer 3 */
83 #define XUSBPS_dTDBPTR4 0x18 /**< Buffer Pointer 4 */
84 #define XUSBPS_dTDBPTR(n) (XUSBPS_dTDBPTR0 + (n) * 0x04)
85 #define XUSBPS_dTDRSRVD 0x1C /**< Reserved field */
87 /* We use the reserved field in the dTD to store user data. */
88 #define XUSBPS_dTDUSERDATA XUSBPS_dTDRSRVD /**< Reserved field */
91 /** @name dTD Next Link Pointer (dTDNLP) bit positions.
94 #define XUSBPS_dTDNLP_T_MASK 0x00000001
95 /**< USB dTD Next Link Pointer Terminate Bit */
96 #define XUSBPS_dTDNLP_ADDR_MASK 0xFFFFFFE0
97 /**< USB dTD Next Link Pointer Address [31:5] */
101 /** @name dTD Token (dTDTOKEN) bit positions.
104 #define XUSBPS_dTDTOKEN_XERR_MASK 0x00000008 /**< dTD Transaction Error */
105 #define XUSBPS_dTDTOKEN_BUFERR_MASK 0x00000020 /**< dTD Data Buffer Error */
106 #define XUSBPS_dTDTOKEN_HALT_MASK 0x00000040 /**< dTD Halted Flag */
107 #define XUSBPS_dTDTOKEN_ACTIVE_MASK 0x00000080 /**< dTD Active Bit */
108 #define XUSBPS_dTDTOKEN_MULTO_MASK 0x00000C00 /**< Multiplier Override Field [1:0] */
109 #define XUSBPS_dTDTOKEN_IOC_MASK 0x00008000 /**< Interrupt on Complete Bit */
110 #define XUSBPS_dTDTOKEN_LEN_MASK 0x7FFF0000 /**< Transfer Length Field */
114 /***************** Macros (Inline Functions) Definitions *********************/
116 /*****************************************************************************/
122 * Many of the following macros modify Device Queue Head (dQH) data structures
123 * and Device Transfer Descriptor (dTD) data structures. Those structures can
124 * potentially reside in CACHED memory. Therefore, it's the callers
125 * responsibility to ensure cache coherency by using provided
127 * XUsbPs_dQHInvalidateCache()
128 * XUsbPs_dQHFlushCache()
129 * XUsbPs_dTDInvalidateCache()
130 * XUsbPs_dTDFlushCache()
134 ******************************************************************************/
135 #define XUsbPs_dTDInvalidateCache(dTDPtr) \
136 Xil_DCacheInvalidateRange((unsigned int)dTDPtr, sizeof(XUsbPs_dTD))
138 #define XUsbPs_dTDFlushCache(dTDPtr) \
139 Xil_DCacheFlushRange((unsigned int)dTDPtr, sizeof(XUsbPs_dTD))
141 #define XUsbPs_dQHInvalidateCache(dQHPtr) \
142 Xil_DCacheInvalidateRange((unsigned int)dQHPtr, sizeof(XUsbPs_dQH))
144 #define XUsbPs_dQHFlushCache(dQHPtr) \
145 Xil_DCacheFlushRange((unsigned int)dQHPtr, sizeof(XUsbPs_dQH))
147 /*****************************************************************************/
150 * This macro sets the Transfer Length for the given Transfer Descriptor.
152 * @param dTDPtr is pointer to the dTD element.
153 * @param Len is the length to be set. Range: 0..16384
155 * @note C-style signature:
156 * void XUsbPs_dTDSetTransferLen(u32 dTDPtr, u32 Len)
158 ******************************************************************************/
159 #define XUsbPs_dTDSetTransferLen(dTDPtr, Len) \
160 XUsbPs_WritedTD(dTDPtr, XUSBPS_dTDTOKEN, \
161 (XUsbPs_ReaddTD(dTDPtr, XUSBPS_dTDTOKEN) & \
162 ~XUSBPS_dTDTOKEN_LEN_MASK) | ((Len) << 16))
165 /*****************************************************************************/
168 * This macro gets the Next Link pointer of the given Transfer Descriptor.
170 * @param dTDPtr is pointer to the dTD element.
172 * @return TransferLength field of the descriptor.
174 * @note C-style signature:
175 * u32 XUsbPs_dTDGetTransferLen(u32 dTDPtr)
177 ******************************************************************************/
178 #define XUsbPs_dTDGetNLP(dTDPtr) \
179 (XUsbPs_dTD *) ((XUsbPs_ReaddTD(dTDPtr, XUSBPS_dTDNLP)\
180 & XUSBPS_dTDNLP_ADDR_MASK))
183 /*****************************************************************************/
186 * This macro sets the Next Link pointer of the given Transfer Descriptor.
188 * @param dTDPtr is a pointer to the dTD element.
189 * @param NLP is the Next Link Pointer
191 * @note C-style signature:
192 * void XUsbPs_dTDSetTransferLen(u32 dTDPtr, u32 Len)
194 ******************************************************************************/
195 #define XUsbPs_dTDSetNLP(dTDPtr, NLP) \
196 XUsbPs_WritedTD(dTDPtr, XUSBPS_dTDNLP, \
197 (XUsbPs_ReaddTD(dTDPtr, XUSBPS_dTDNLP) & \
198 ~XUSBPS_dTDNLP_ADDR_MASK) | \
199 ((NLP) & XUSBPS_dTDNLP_ADDR_MASK))
202 /*****************************************************************************/
205 * This macro gets the Transfer Length for the given Transfer Descriptor.
207 * @param dTDPtr is a pointer to the dTD element.
209 * @return TransferLength field of the descriptor.
211 * @note C-style signature:
212 * u32 XUsbPs_dTDGetTransferLen(u32 dTDPtr)
214 ******************************************************************************/
215 #define XUsbPs_dTDGetTransferLen(dTDPtr) \
216 (u32) ((XUsbPs_ReaddTD(dTDPtr, XUSBPS_dTDTOKEN) \
217 & XUSBPS_dTDTOKEN_LEN_MASK) >> 16)
220 /*****************************************************************************/
223 * This macro sets the Interrupt On Complete (IOC) bit for the given Transfer
226 * @param dTDPtr is a pointer to the dTD element.
228 * @note C-style signature:
229 * void XUsbPs_dTDSetIOC(u32 dTDPtr)
231 ******************************************************************************/
232 #define XUsbPs_dTDSetIOC(dTDPtr) \
233 XUsbPs_WritedTD(dTDPtr, XUSBPS_dTDTOKEN, \
234 XUsbPs_ReaddTD(dTDPtr, XUSBPS_dTDTOKEN) | \
235 XUSBPS_dTDTOKEN_IOC_MASK)
238 /*****************************************************************************/
241 * This macro sets the Terminate bit for the given Transfer Descriptor.
243 * @param dTDPtr is a pointer to the dTD element.
245 * @note C-style signature:
246 * void XUsbPs_dTDSetTerminate(u32 dTDPtr)
248 ******************************************************************************/
249 #define XUsbPs_dTDSetTerminate(dTDPtr) \
250 XUsbPs_WritedTD(dTDPtr, XUSBPS_dTDNLP, \
251 XUsbPs_ReaddTD(dTDPtr, XUSBPS_dTDNLP) | \
252 XUSBPS_dTDNLP_T_MASK)
255 /*****************************************************************************/
258 * This macro clears the Terminate bit for the given Transfer Descriptor.
260 * @param dTDPtr is a pointer to the dTD element.
262 * @note C-style signature:
263 * void XUsbPs_dTDClrTerminate(u32 dTDPtr)
265 ******************************************************************************/
266 #define XUsbPs_dTDClrTerminate(dTDPtr) \
267 XUsbPs_WritedTD(dTDPtr, XUSBPS_dTDNLP, \
268 XUsbPs_ReaddTD(dTDPtr, XUSBPS_dTDNLP) & \
269 ~XUSBPS_dTDNLP_T_MASK)
272 /*****************************************************************************/
275 * This macro checks if the given descriptor is active.
277 * @param dTDPtr is a pointer to the dTD element.
280 * - TRUE: The buffer is active.
281 * - FALSE: The buffer is not active.
283 * @note C-style signature:
284 * int XUsbPs_dTDIsActive(u32 dTDPtr)
286 ******************************************************************************/
287 #define XUsbPs_dTDIsActive(dTDPtr) \
288 ((XUsbPs_ReaddTD(dTDPtr, XUSBPS_dTDTOKEN) & \
289 XUSBPS_dTDTOKEN_ACTIVE_MASK) ? TRUE : FALSE)
292 /*****************************************************************************/
295 * This macro sets the Active bit for the given Transfer Descriptor.
297 * @param dTDPtr is a pointer to the dTD element.
299 * @note C-style signature:
300 * void XUsbPs_dTDSetActive(u32 dTDPtr)
302 ******************************************************************************/
303 #define XUsbPs_dTDSetActive(dTDPtr) \
304 XUsbPs_WritedTD(dTDPtr, XUSBPS_dTDTOKEN, \
305 XUsbPs_ReaddTD(dTDPtr, XUSBPS_dTDTOKEN) | \
306 XUSBPS_dTDTOKEN_ACTIVE_MASK)
309 /*****************************************************************************/
312 * This macro reads the content of a field in a Transfer Descriptor.
314 * @param dTDPtr is a pointer to the dTD element.
315 * @param Id is the field ID inside the dTD element to read.
317 * @note C-style signature:
318 * u32 XUsbPs_ReaddTD(u32 dTDPtr, u32 Id)
320 ******************************************************************************/
321 #define XUsbPs_ReaddTD(dTDPtr, Id) (*(u32 *)((u32)(dTDPtr) + (u32)(Id)))
323 /*****************************************************************************/
326 * This macro writes a value to a field in a Transfer Descriptor.
328 * @param dTDPtr is pointer to the dTD element.
329 * @param Id is the field ID inside the dTD element to read.
330 * @param Val is the value to write to the field.
332 * @note C-style signature:
333 * u32 XUsbPs_WritedTD(u32 dTDPtr, u32 Id, u32 Val)
335 ******************************************************************************/
336 #define XUsbPs_WritedTD(dTDPtr, Id, Val) \
337 (*(u32 *) ((u32)(dTDPtr) + (u32)(Id)) = (u32)(Val))
340 /******************************************************************************/
342 * Endpoint Device Queue Head
344 * Device queue heads are arranged in an array in a continuous area of memory
345 * pointed to by the ENDPOINTLISTADDR pointer. The device controller will index
346 * into this array based upon the endpoint number received from the USB bus.
347 * All information necessary to respond to transactions for all primed
348 * transfers is contained in this list so the Device Controller can readily
349 * respond to incoming requests without having to traverse a linked list.
351 * The device Endpoint Queue Head (dQH) is where all transfers are managed. The
352 * dQH is a 48-byte data structure, but must be aligned on a 64-byte boundary.
353 * During priming of an endpoint, the dTD (device transfer descriptor) is
354 * copied into the overlay area of the dQH, which starts at the nextTD pointer
355 * DWord and continues through the end of the buffer pointers DWords. After a
356 * transfer is complete, the dTD status DWord is updated in the dTD pointed to
357 * by the currentTD pointer. While a packet is in progress, the overlay area of
358 * the dQH is used as a staging area for the dTD so that the Device Controller
359 * can access needed information with little minimal latency.
362 * Software must ensure that no interface data structure reachable by the
363 * Device Controller spans a 4K-page boundary. The first element of the
364 * Endpoint Queue Head List must be aligned on a 4K boundary.
366 #define XUSBPS_dQHCFG 0x00 /**< dQH Configuration */
367 #define XUSBPS_dQHCPTR 0x04 /**< dQH Current dTD Pointer */
368 #define XUSBPS_dQHdTDNLP 0x08 /**< dTD Next Link Ptr in dQH
370 #define XUSBPS_dQHdTDTOKEN 0x0C /**< dTD Token in dQH overlay */
371 #define XUSBPS_dQHSUB0 0x28 /**< USB dQH Setup Buffer 0 */
372 #define XUSBPS_dQHSUB1 0x2C /**< USB dQH Setup Buffer 1 */
375 /** @name dQH Configuration (dQHCFG) bit positions.
378 #define XUSBPS_dQHCFG_IOS_MASK 0x00008000
379 /**< USB dQH Interrupt on Setup Bit */
380 #define XUSBPS_dQHCFG_MPL_MASK 0x07FF0000
381 /**< USB dQH Maximum Packet Length
383 #define XUSBPS_dQHCFG_MPL_SHIFT 16
384 #define XUSBPS_dQHCFG_ZLT_MASK 0x20000000
385 /**< USB dQH Zero Length Termination
387 #define XUSBPS_dQHCFG_MULT_MASK 0xC0000000
388 /* USB dQH Number of Transactions Field
390 #define XUSBPS_dQHCFG_MULT_SHIFT 30
394 /*****************************************************************************/
397 * This macro sets the Maximum Packet Length field of the give Queue Head.
399 * @param dQHPtr is a pointer to the dQH element.
400 * @param Len is the length to be set.
402 * @note C-style signature:
403 * void XUsbPs_dQHSetMaxPacketLen(u32 dQHPtr, u32 Len)
405 ******************************************************************************/
406 #define XUsbPs_dQHSetMaxPacketLen(dQHPtr, Len) \
407 XUsbPs_WritedQH(dQHPtr, XUSBPS_dQHCFG, \
408 (XUsbPs_ReaddQH(dQHPtr, XUSBPS_dQHCFG) & \
409 ~XUSBPS_dQHCFG_MPL_MASK) | ((Len) << 16))
411 /*****************************************************************************/
414 * This macro sets the Interrupt On Setup (IOS) bit for an endpoint.
416 * @param dQHPtr is a pointer to the dQH element.
418 * @note C-style signature:
419 * void XUsbPs_dQHSetIOS(u32 dQHPtr)
421 ******************************************************************************/
422 #define XUsbPs_dQHSetIOS(dQHPtr) \
423 XUsbPs_WritedQH(dQHPtr, XUSBPS_dQHCFG, \
424 XUsbPs_ReaddQH(dQHPtr, XUSBPS_dQHCFG) | \
425 XUSBPS_dQHCFG_IOS_MASK)
427 /*****************************************************************************/
430 * This macro clears the Interrupt On Setup (IOS) bit for an endpoint.
432 * @param dQHPtr is a pointer to the dQH element.
434 * @note C-style signature:
435 * void XUsbPs_dQHClrIOS(u32 dQHPtr)
437 ******************************************************************************/
438 #define XUsbPs_dQHClrIOS(dQHPtr) \
439 XUsbPs_WritedQH(dQHPtr, XUSBPS_dQHCFG, \
440 XUsbPs_ReaddQH(dQHPtr, XUSBPS_dQHCFG) & \
441 ~XUSBPS_dQHCFG_IOS_MASK)
443 /*****************************************************************************/
446 * This macro enables Zero Length Termination for the endpoint.
448 * @param dQHPtr is a pointer to the dQH element.
450 * @note C-style signature:
451 * void XUsbPs_dQHEnableZLT(u32 dQHPtr)
454 ******************************************************************************/
455 #define XUsbPs_dQHEnableZLT(dQHPtr) \
456 XUsbPs_WritedQH(dQHPtr, XUSBPS_dQHCFG, \
457 XUsbPs_ReaddQH(dQHPtr, XUSBPS_dQHCFG) & \
458 ~XUSBPS_dQHCFG_ZLT_MASK)
461 /*****************************************************************************/
464 * This macro disables Zero Length Termination for the endpoint.
466 * @param dQHPtr is a pointer to the dQH element.
468 * @note C-style signature:
469 * void XUsbPs_dQHDisableZLT(u32 dQHPtr)
472 ******************************************************************************/
473 #define XUsbPs_dQHDisableZLT(dQHPtr) \
474 XUsbPs_WritedQH(dQHPtr, XUSBPS_dQHCFG, \
475 XUsbPs_ReaddQH(dQHPtr, XUSBPS_dQHCFG) | \
476 XUSBPS_dQHCFG_ZLT_MASK)
478 /*****************************************************************************/
481 * This macro reads the content of a field in a Queue Head.
483 * @param dQHPtr is a pointer to the dQH element.
484 * @param Id is the Field ID inside the dQH element to read.
486 * @note C-style signature:
487 * u32 XUsbPs_ReaddQH(u32 dQHPtr, u32 Id)
489 ******************************************************************************/
490 #define XUsbPs_ReaddQH(dQHPtr, Id) (*(u32 *)((u32)(dQHPtr) + (u32) (Id)))
492 /*****************************************************************************/
495 * This macro writes a value to a field in a Queue Head.
497 * @param dQHPtr is a pointer to the dQH element.
498 * @param Id is the Field ID inside the dQH element to read.
499 * @param Val is the Value to write to the field.
501 * @note C-style signature:
502 * u32 XUsbPs_WritedQH(u32 dQHPtr, u32 Id, u32 Val)
504 ******************************************************************************/
505 #define XUsbPs_WritedQH(dQHPtr, Id, Val) \
506 (*(u32 *) ((u32)(dQHPtr) + (u32)(Id)) = (u32)(Val))
514 #endif /* XUSBPS_ENDPOINT_H */