+/rtos

git clone https://git.julia.blue/+/rtos

Joseph RyanRe-add usblib files83915e3

master
44.5 KiB1282 linesraw
1//*****************************************************************************
2//
3// usbdma.c - USB Library DMA handling functions.
4//
5// Copyright (c) 2012-2017 Texas Instruments Incorporated.  All rights reserved.
6// Software License Agreement
7//
8// Texas Instruments (TI) is supplying this software for use solely and
9// exclusively on TI's microcontroller products. The software is owned by
10// TI and/or its suppliers, and is protected under applicable copyright
11// laws. You may not combine this software with "viral" open-source
12// software in order to form a larger program.
13//
14// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
15// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
16// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
18// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
19// DAMAGES, FOR ANY REASON WHATSOEVER.
20//
21// This is part of revision 2.1.4.178 of the Tiva USB Library.
22//
23//*****************************************************************************
24
25#include "tivaware/hw_ints.h"
26#include "tivaware/hw_memmap.h"
27#include "tivaware/hw_sysctl.h"
28#include "tivaware/hw_types.h"
29#include "tivaware/hw_udma.h"
30#include "tivaware/rom.h"
31#include "tivaware/rom_map.h"
32#include "tivaware/rtos_bindings.h"
33#include "tivaware/udma.h"
34#include "tivaware/usb.h"
35#include "usblib/usblib.h"
36#include "usblib/usblibpriv.h"
37#include <stdbool.h>
38#include <stdint.h>
39
40#define ASSERT(X)
41
42//*****************************************************************************
43//
44//! \addtogroup usblib_dma_api Internal USB DMA functions
45//! @{
46//
47//*****************************************************************************
48
49//*****************************************************************************
50//
51// There are two sets of functions in this file, one is used with uDMA while
52// the other is used with USB controllers with an integrated DMA controller.
53// The functions with the IDMA prefix are for the integrated DMA controller and
54// the functions that are specific to the uDMA controller are prefixed with
55// uDMA.  Any common functions are have just the DMA prefix.
56//
57//*****************************************************************************
58static tUSBDMAInstance g_psUSBDMAInst[1];
59
60//*****************************************************************************
61//
62// Macros used to determine if a uDMA endpoint configuration is used for
63// receive or transmit.
64//
65//*****************************************************************************
66#define UDMAConfigIsRx(ui32Config)                                             \
67    ((ui32Config & UDMA_SRC_INC_NONE) == UDMA_SRC_INC_NONE)
68#define UDMAConfigIsTx(ui32Config)                                             \
69    ((ui32Config & UDMA_DEST_INC_NONE) == UDMA_DEST_INC_NONE)
70
71//*****************************************************************************
72//
73// USBLibDMAChannelStatus() for USB controllers that use the uDMA for DMA.
74//
75//*****************************************************************************
76static uint32_t uDMAUSBChannelStatus(tUSBDMAInstance* psUSBDMAInst,
77                                     uint32_t ui32Channel) {
78    uint32_t ui32Status;
79
80    //
81    // Initialize the current status to no events.
82    //
83    ui32Status = USBLIBSTATUS_DMA_IDLE;
84
85    //
86    // Check if there is a pending DMA transfer.
87    //
88    if (psUSBDMAInst->ui32Complete & (1 << (ui32Channel - 1))) {
89        //
90        // Return that the DMA transfer has completed and clear the
91        // DMA pending flag.
92        //
93        ui32Status = USBLIBSTATUS_DMA_COMPLETE;
94    } else if (psUSBDMAInst->ui32Pending & (1 << (ui32Channel - 1))) {
95        //
96        // DMA transfer is still pending.
97        //
98        ui32Status = USBLIBSTATUS_DMA_PENDING;
99    } else {
100        //
101        // DMA transfer is still pending.
102        //
103        ui32Status = USBLIBSTATUS_DMA_IDLE;
104    }
105
106    return (ui32Status);
107}
108
109//*****************************************************************************
110//
111// USBLibDMAChannelStatus() for USB controllers with an integrated DMA
112// controller.
113//
114//*****************************************************************************
115static uint32_t iDMAUSBChannelStatus(tUSBDMAInstance* psUSBDMAInst,
116                                     uint32_t ui32Channel) {
117    uint32_t ui32Status;
118
119    //
120    // Initialize the current status to no events.
121    //
122    ui32Status = USBLIBSTATUS_DMA_IDLE;
123
124    //
125    // Check if an error has occurred.
126    //
127    if (USBDMAChannelStatus(psUSBDMAInst->ui32Base, ui32Channel) ==
128        USB_DMA_STATUS_ERROR) {
129        ui32Status = USBLIBSTATUS_DMA_ERROR;
130    }
131    //
132    // Otherwise check if there a pending DMA transfer has completed.
133    //
134    else if (psUSBDMAInst->ui32Complete & (1 << (ui32Channel - 1))) {
135        //
136        // Return that the DMA transfer has completed and clear the
137        // DMA pending flag.
138        //
139        ui32Status = USBLIBSTATUS_DMA_COMPLETE;
140    } else if (psUSBDMAInst->ui32Pending & (1 << (ui32Channel - 1))) {
141        //
142        // DMA transfer is still pending.
143        //
144        ui32Status = USBLIBSTATUS_DMA_PENDING;
145    } else {
146        //
147        // DMA Channel is idle.
148        //
149        ui32Status = USBLIBSTATUS_DMA_IDLE;
150    }
151
152    return (ui32Status);
153}
154
155//*****************************************************************************
156//
157// USBLibDMAIntStatus() for USB controllers that use uDMA.
158//
159//*****************************************************************************
160static uint32_t uDMAUSBIntStatus(tUSBDMAInstance* psUSBDMAInst) {
161    uint32_t ui32Status, ui32Pending;
162    int32_t i32Channel;
163
164    //
165    // Initialize the current status to no events.
166    //
167    ui32Status = 0;
168
169    //
170    // No pending interrupts by default.
171    //
172    ui32Status = 0;
173
174    //
175    // Save the pending channels.
176    //
177    ui32Pending = psUSBDMAInst->ui32Pending;
178
179    //
180    // Loop through channels to find out if any pending DMA transfers have
181    // completed.
182    //
183    for (i32Channel = 0; i32Channel < USB_MAX_DMA_CHANNELS; i32Channel++) {
184        //
185        // If pending and stopped then the DMA completed.
186        //
187        if ((ui32Pending & 1) &&
188            (MAP_uDMAChannelModeGet(i32Channel) == UDMA_MODE_STOP)) {
189            ui32Status |= (1 << i32Channel);
190        }
191        ui32Pending >>= 1;
192
193        //
194        // Done if this is zero.
195        //
196        if (ui32Pending == 0) {
197            break;
198        }
199    }
200
201    return (ui32Status);
202}
203
204//*****************************************************************************
205//
206// USBLibDMAIntStatus() for USB controllers with an integrated DMA controller.
207//
208//*****************************************************************************
209static uint32_t iDMAUSBIntStatus(tUSBDMAInstance* psUSBDMAInst) {
210    //
211    // Read the current DMA status, unfortunately this clears the
212    // pending interrupt status.
213    //
214    return (USBDMAChannelIntStatus(psUSBDMAInst->ui32Base));
215}
216
217//*****************************************************************************
218//
219// USBLibDMAIntStatusClear() for USB controllers that use uDMA for DMA or have
220// an integrated DMA controller.
221//
222//*****************************************************************************
223static void DMAUSBIntStatusClear(tUSBDMAInstance* psUSBDMAInst,
224                                 uint32_t ui32Status) {
225    //
226    // Clear out the requested interrupts.  Since the USB interface does not
227    // have a true interrupt clear, this clears the current completed
228    // status for the requested channels.
229    //
230    psUSBDMAInst->ui32Complete &= ~ui32Status;
231
232    return;
233}
234
235//*****************************************************************************
236//
237// USBLibDMAIntHandler() for USB controllers that use uDMA for DMA or have an
238// integrated DMA controller.
239//
240//*****************************************************************************
241static void DMAUSBIntHandler(tUSBDMAInstance* psUSBDMAInst,
242                             uint32_t ui32DMAIntStatus) {
243    uint32_t ui32Channel;
244
245    if (ui32DMAIntStatus == 0) {
246        return;
247    }
248
249    //
250    // Determine if the uDMA is used or the USB DMA controller.
251    //
252    for (ui32Channel = 0; ui32Channel < USB_MAX_DMA_CHANNELS; ui32Channel++) {
253        //
254        // Mark any pending interrupts as completed.
255        //
256        if (ui32DMAIntStatus & 1) {
257            psUSBDMAInst->ui32Pending &= ~(1 << ui32Channel);
258            psUSBDMAInst->ui32Complete |= (1 << ui32Channel);
259        }
260
261        //
262        // Check the next channel.
263        //
264        ui32DMAIntStatus >>= 1;
265
266        //
267        // Break if there are no more pending DMA interrupts.
268        //
269        if (ui32DMAIntStatus == 0) {
270            break;
271        }
272    }
273}
274
275//*****************************************************************************
276//
277// USBLibDMAChannelEnable() for USB controllers that use uDMA.
278//
279//*****************************************************************************
280static void uDMAUSBChannelEnable(tUSBDMAInstance* psUSBDMAInst,
281                                 uint32_t ui32Channel) {
282    uint32_t ui32IntEnabled;
283
284    //
285    // Save if the interrupt was enabled or not.
286    //
287    ui32IntEnabled = ROM_IntIsEnabled(psUSBDMAInst->ui32IntNum);
288
289    //
290    // Disable the USB interrupt if it was enabled.
291    //
292    if (ui32IntEnabled) {
293        OS_INT_DISABLE(psUSBDMAInst->ui32IntNum);
294    }
295
296    //
297    // Mark this channel as pending and not complete.
298    //
299    psUSBDMAInst->ui32Pending |= (1 << (ui32Channel - 1));
300    psUSBDMAInst->ui32Complete &= ~(1 << (ui32Channel - 1));
301
302    //
303    // Enable DMA for the endpoint.
304    //
305    if (UDMAConfigIsRx(psUSBDMAInst->pui32Config[ui32Channel - 1])) {
306        MAP_USBEndpointDMAEnable(psUSBDMAInst->ui32Base,
307                                 psUSBDMAInst->pui8Endpoint[ui32Channel - 1],
308                                 USB_EP_DEV_OUT | USB_EP_HOST_IN);
309    } else {
310        MAP_USBEndpointDMAEnable(psUSBDMAInst->ui32Base,
311                                 psUSBDMAInst->pui8Endpoint[ui32Channel - 1],
312                                 USB_EP_DEV_IN | USB_EP_HOST_OUT);
313    }
314
315    //
316    // Enable the DMA in the uDMA controller.
317    //
318    MAP_uDMAChannelEnable(ui32Channel - 1);
319
320    //
321    // Enable the USB interrupt if it was enabled before.
322    //
323    if (ui32IntEnabled) {
324        OS_INT_ENABLE(psUSBDMAInst->ui32IntNum);
325    }
326}
327
328//*****************************************************************************
329//
330// USBLibDMAChannelEnable() for USB controllers with an integrated DMA
331// controller.
332//
333//*****************************************************************************
334static void iDMAUSBChannelEnable(tUSBDMAInstance* psUSBDMAInst,
335                                 uint32_t ui32Channel) {
336    uint32_t ui32IntEnabled;
337
338    //
339    // Save if the interrupt was enabled or not.
340    //
341    ui32IntEnabled = ROM_IntIsEnabled(psUSBDMAInst->ui32IntNum);
342
343    //
344    // Disable the USB interrupt if it was enabled.
345    //
346    if (ui32IntEnabled) {
347        OS_INT_DISABLE(psUSBDMAInst->ui32IntNum);
348    }
349
350    //
351    // Mark this channel as pending and not complete.
352    //
353    psUSBDMAInst->ui32Pending |= (1 << (ui32Channel - 1));
354    psUSBDMAInst->ui32Complete &= ~(1 << (ui32Channel - 1));
355
356    //
357    // Enable the interrupt for this DMA channel.
358    //
359    USBDMAChannelIntEnable(psUSBDMAInst->ui32Base, ui32Channel - 1);
360
361    //
362    // Enable the DMA channel.
363    //
364    USBDMAChannelEnable(psUSBDMAInst->ui32Base, ui32Channel - 1);
365
366    //
367    // Enable the USB interrupt if it was enabled before.
368    //
369    if (ui32IntEnabled) {
370        OS_INT_ENABLE(psUSBDMAInst->ui32IntNum);
371    }
372}
373
374//*****************************************************************************
375//
376// USBLibDMAChannelDisable() for USB controllers that use uDMA.
377//
378//*****************************************************************************
379static void uDMAUSBChannelDisable(tUSBDMAInstance* psUSBDMAInst,
380                                  uint32_t ui32Channel) {
381    //
382    // Disable DMA for the endpoint.
383    //
384    if (UDMAConfigIsRx(psUSBDMAInst->pui32Config[ui32Channel - 1])) {
385        MAP_USBEndpointDMADisable(psUSBDMAInst->ui32Base,
386                                  psUSBDMAInst->pui8Endpoint[ui32Channel - 1],
387                                  USB_EP_DEV_OUT);
388    } else {
389        MAP_USBEndpointDMADisable(psUSBDMAInst->ui32Base,
390                                  psUSBDMAInst->pui8Endpoint[ui32Channel - 1],
391                                  USB_EP_DEV_IN);
392    }
393
394    //
395    // Disable the DMA channel in the uDMA controller.
396    //
397    MAP_uDMAChannelDisable(ui32Channel - 1);
398
399    //
400    // Clear out any pending or complete flag set for this DMA channel.
401    //
402    psUSBDMAInst->ui32Pending &= ~(1 << (ui32Channel - 1));
403    psUSBDMAInst->ui32Complete &= ~(1 << (ui32Channel - 1));
404}
405
406//*****************************************************************************
407//
408// USBLibDMAChannelDisable() for USB controllers with an integrated DMA
409// controller.
410//
411//*****************************************************************************
412static void iDMAUSBChannelDisable(tUSBDMAInstance* psUSBDMAInst,
413                                  uint32_t ui32Channel) {
414    //
415    // Disable the DMA channel.
416    //
417    USBDMAChannelDisable(psUSBDMAInst->ui32Base, ui32Channel - 1);
418
419    //
420    // Disable the interrupt for this DMA channel.
421    //
422    USBDMAChannelIntDisable(psUSBDMAInst->ui32Base, ui32Channel - 1);
423
424    //
425    // Clear out any pending or complete flag set for this DMA channel.
426    //
427    psUSBDMAInst->ui32Pending &= ~(1 << (ui32Channel - 1));
428    psUSBDMAInst->ui32Complete &= ~(1 << (ui32Channel - 1));
429}
430
431//*****************************************************************************
432//
433// USBLibDMAChannelIntEnable() for USB controllers that use uDMA.
434//
435//*****************************************************************************
436static void uDMAUSBChannelIntEnable(tUSBDMAInstance* psUSBDMAInst,
437                                    uint32_t ui32Channel) {
438    //
439    // There is no way to Enable channel interrupts when using uDMA.
440    //
441}
442
443//*****************************************************************************
444//
445// USBLibDMAChannelIntEnable() for USB controllers with an integrated DMA
446// controller.
447//
448//*****************************************************************************
449static void iDMAUSBChannelIntEnable(tUSBDMAInstance* psUSBDMAInst,
450                                    uint32_t ui32Channel) {
451    //
452    // Enable the interrupt for this DMA channel.
453    //
454    USBDMAChannelIntEnable(psUSBDMAInst->ui32Base, ui32Channel - 1);
455}
456
457//*****************************************************************************
458//
459// USBLibDMAChannelIntDisable() for USB controllers that use uDMA.
460//
461//*****************************************************************************
462static void uDMAUSBChannelIntDisable(tUSBDMAInstance* psUSBDMAInst,
463                                     uint32_t ui32Channel) {
464    //
465    // There is no way to Disable channel interrupts when using uDMA.
466    //
467}
468
469//*****************************************************************************
470//
471// USBLibDMAChannelIntDisable() for USB controllers with an integrated DMA
472// controller.
473//
474//*****************************************************************************
475static void iDMAUSBChannelIntDisable(tUSBDMAInstance* psUSBDMAInst,
476                                     uint32_t ui32Channel) {
477    //
478    // Disable the interrupt for this DMA channel.
479    //
480    USBDMAChannelIntDisable(psUSBDMAInst->ui32Base, ui32Channel - 1);
481}
482
483//*****************************************************************************
484//
485// USBLibDMATransfer() for USB controllers that use the uDMA controller.
486//
487//*****************************************************************************
488static uint32_t uDMAUSBTransfer(tUSBDMAInstance* psUSBDMAInst,
489                                uint32_t ui32Channel, void* pvBuffer,
490                                uint32_t ui32Size) {
491    void* pvFIFO;
492    uint32_t uluDMAChannel;
493    uint32_t ui32PacketCount;
494    uint32_t ui32TransferCount;
495
496    if ((ui32Size < 64) || ((uint32_t)pvBuffer & 0x3)) {
497        return (0);
498    }
499
500    //
501    // Mark this channel as pending and not complete.
502    //
503    psUSBDMAInst->ui32Pending |= (1 << (ui32Channel - 1));
504    psUSBDMAInst->ui32Complete &= ~(1 << (ui32Channel - 1));
505
506    //
507    // Save the pointer to the data and the byte count.
508    //
509    psUSBDMAInst->ppui32Data[ui32Channel - 1] = pvBuffer;
510    psUSBDMAInst->pui32Count[ui32Channel - 1] = ui32Size;
511
512    //
513    // Need the address of the FIFO.
514    //
515    pvFIFO = (void*)USBFIFOAddrGet(psUSBDMAInst->ui32Base,
516                                   psUSBDMAInst->pui8Endpoint[ui32Channel - 1]);
517
518    //
519    // Calculate the uDMA channel for this RX channel.
520    //
521    uluDMAChannel = UDMA_CHANNEL_USBEP1RX + ui32Channel - 1;
522
523    ui32TransferCount = ui32Size;
524
525    if ((psUSBDMAInst->pui32Config[ui32Channel - 1] & UDMA_SIZE_32) ==
526        UDMA_SIZE_32) {
527        ui32TransferCount >>= 2;
528    } else if ((psUSBDMAInst->pui32Config[ui32Channel - 1] & UDMA_SIZE_32) ==
529               UDMA_SIZE_32) {
530        ui32TransferCount >>= 1;
531    }
532
533    //
534    // If source increment is none this is an RX transfer.
535    //
536    if (UDMAConfigIsRx(psUSBDMAInst->pui32Config[ui32Channel - 1])) {
537        MAP_uDMAChannelTransferSet(uluDMAChannel, UDMA_MODE_BASIC, pvFIFO,
538                                   pvBuffer, ui32TransferCount);
539    } else {
540        MAP_uDMAChannelTransferSet(uluDMAChannel, UDMA_MODE_BASIC, pvBuffer,
541                                   pvFIFO, ui32TransferCount);
542    }
543
544    //
545    // Set the mode based on the size of the transfer.  More than one
546    // packet requires mode 1.
547    //
548    if (ui32Size > psUSBDMAInst->pui32MaxPacketSize[ui32Channel - 1]) {
549        //
550        // Calculate the number of packets required for this transfer.
551        //
552        ui32PacketCount =
553            ((ui32Size / psUSBDMAInst->pui32MaxPacketSize[ui32Channel - 1]));
554
555        //
556        // Set the packet count so that the last packet does not generate
557        // another IN request.
558        //
559        USBEndpointPacketCountSet(psUSBDMAInst->ui32Base,
560                                  psUSBDMAInst->pui8Endpoint[ui32Channel - 1],
561                                  ui32PacketCount);
562
563        //
564        // Configure the USB endpoint in mode 1 for this DMA transfer.
565        //
566        USBEndpointDMAConfigSet(psUSBDMAInst->ui32Base,
567                                psUSBDMAInst->pui8Endpoint[ui32Channel - 1],
568                                psUSBDMAInst->pui32EPDMAMode1[ui32Channel - 1]);
569    } else {
570        //
571        // Configure the USB endpoint in mode 0 for this DMA transfer.
572        //
573        USBEndpointDMAConfigSet(psUSBDMAInst->ui32Base,
574                                psUSBDMAInst->pui8Endpoint[ui32Channel - 1],
575                                psUSBDMAInst->pui32EPDMAMode0[ui32Channel - 1]);
576    }
577
578    //
579    // Enable the uDMA channel to start the transfer
580    //
581    uDMAUSBChannelEnable(psUSBDMAInst, ui32Channel);
582
583    return (ui32Size);
584}
585
586//*****************************************************************************
587//
588// USBLibDMATransfer() for USB controllers with an integrated DMA controller.
589//
590//*****************************************************************************
591static uint32_t iDMAUSBTransfer(tUSBDMAInstance* psUSBDMAInst,
592                                uint32_t ui32Channel, void* pvBuffer,
593                                uint32_t ui32Size) {
594    uint32_t ui32PacketCount;
595
596    if ((uint32_t)pvBuffer & 0x3) {
597        return (0);
598    }
599
600    //
601    // Mark this channel as pending and not complete.
602    //
603    psUSBDMAInst->ui32Pending |= (1 << (ui32Channel - 1));
604    psUSBDMAInst->ui32Complete &= ~(1 << (ui32Channel - 1));
605
606    //
607    // Save the pointer to the data and the byte count.
608    //
609    psUSBDMAInst->ppui32Data[ui32Channel - 1] = pvBuffer;
610    psUSBDMAInst->pui32Count[ui32Channel - 1] = ui32Size;
611
612    //
613    // Set the address.
614    //
615    USBDMAChannelAddressSet(psUSBDMAInst->ui32Base, ui32Channel - 1, pvBuffer);
616
617    //
618    // Set the number of transfers.
619    //
620    USBDMAChannelCountSet(psUSBDMAInst->ui32Base, ui32Channel - 1, ui32Size);
621
622    //
623    // Set the mode based on the size of the transfer.  More than one
624    // packet requires mode 1.
625    //
626    if (ui32Size > psUSBDMAInst->pui32MaxPacketSize[ui32Channel - 1]) {
627        //
628        // Calculate the number of packets required for this transfer.
629        //
630        ui32PacketCount =
631            ui32Size / psUSBDMAInst->pui32MaxPacketSize[ui32Channel - 1];
632
633        if (ui32Size % psUSBDMAInst->pui32MaxPacketSize[ui32Channel - 1]) {
634            ui32PacketCount += 1;
635        }
636
637        USBEndpointPacketCountSet(psUSBDMAInst->ui32Base,
638                                  psUSBDMAInst->pui8Endpoint[ui32Channel - 1],
639                                  ui32PacketCount);
640
641        //
642        // Configure the USB DMA controller for mode 1.
643        //
644        USBEndpointDMAConfigSet(psUSBDMAInst->ui32Base,
645                                psUSBDMAInst->pui8Endpoint[ui32Channel - 1],
646                                psUSBDMAInst->pui32EPDMAMode1[ui32Channel - 1]);
647
648        USBDMAChannelConfigSet(psUSBDMAInst->ui32Base, ui32Channel - 1,
649                               psUSBDMAInst->pui8Endpoint[ui32Channel - 1],
650                               psUSBDMAInst->pui32Config[ui32Channel - 1] |
651                                   USB_DMA_CFG_MODE_1);
652
653        //
654        // Enable DMA on the endpoint.
655        //
656        if (psUSBDMAInst->pui32Config[ui32Channel - 1] & USB_DMA_CFG_DIR_TX) {
657            //
658            // Make sure that DMA is enabled on the endpoint.
659            //
660            MAP_USBEndpointDMAEnable(
661                psUSBDMAInst->ui32Base,
662                psUSBDMAInst->pui8Endpoint[ui32Channel - 1], USB_EP_HOST_OUT);
663        } else {
664            //
665            // Make sure that DMA is enabled on the endpoint.
666            //
667            MAP_USBEndpointDMAEnable(
668                psUSBDMAInst->ui32Base,
669                psUSBDMAInst->pui8Endpoint[ui32Channel - 1], USB_EP_HOST_IN);
670        }
671
672        //
673        // Enable the DMA channel.
674        //
675        USBDMAChannelEnable(psUSBDMAInst->ui32Base, ui32Channel - 1);
676    } else {
677        //
678        // Configure the USB DMA controller for mode 0.
679        //
680        USBEndpointDMAConfigSet(psUSBDMAInst->ui32Base,
681                                psUSBDMAInst->pui8Endpoint[ui32Channel - 1],
682                                psUSBDMAInst->pui32EPDMAMode0[ui32Channel - 1]);
683
684        USBDMAChannelConfigSet(psUSBDMAInst->ui32Base, ui32Channel - 1,
685                               psUSBDMAInst->pui8Endpoint[ui32Channel - 1],
686                               psUSBDMAInst->pui32Config[ui32Channel - 1] |
687                                   USB_DMA_CFG_MODE_0);
688
689        //
690        // In mode 0 only enable DMA transfer for mode 0.
691        //
692        if (psUSBDMAInst->pui32Config[ui32Channel - 1] & USB_DMA_CFG_DIR_TX) {
693            //
694            // Make sure that DMA is enabled on the endpoint.
695            //
696            MAP_USBEndpointDMAEnable(
697                psUSBDMAInst->ui32Base,
698                psUSBDMAInst->pui8Endpoint[ui32Channel - 1], USB_EP_HOST_OUT);
699            //
700            // Enable the DMA channel.
701            //
702            USBDMAChannelEnable(psUSBDMAInst->ui32Base, ui32Channel - 1);
703        } else {
704            //
705            // Make sure that DMA is disabled on the endpoint, it will
706            // be enabled when the endpoint interrupt occurs.
707            //
708            MAP_USBEndpointDMADisable(
709                psUSBDMAInst->ui32Base,
710                psUSBDMAInst->pui8Endpoint[ui32Channel - 1], USB_EP_HOST_IN);
711        }
712    }
713
714    return (ui32Size);
715}
716
717//*****************************************************************************
718//
719// USBLibDMAChannelAllocate() for USB controllers that use uDMA for DMA.
720//
721//*****************************************************************************
722static uint32_t uDMAUSBChannelAllocate(tUSBDMAInstance* psUSBDMAInst,
723                                       uint8_t ui8Endpoint,
724                                       uint32_t ui32MaxPacketSize,
725                                       uint32_t ui32Config) {
726    uint32_t ui32Channel;
727
728    //
729    // The DMA channels are organized in pairs on this controller and the
730    // transmit channels are 1, 3, and 5 while receive are 0, 2, and 4.
731    //
732    if (ui32Config & USB_DMA_EP_RX) {
733        ui32Channel = 0;
734    } else {
735        ui32Channel = 1;
736    }
737
738    //
739    // Search for an available DMA channel to use.
740    //
741    for (; ui32Channel < USB_MAX_DMA_CHANNELS_0; ui32Channel += 2) {
742        //
743        // If the current endpoint value is zero then this channel is
744        // available.
745        //
746        if (psUSBDMAInst->pui8Endpoint[ui32Channel] == 0) {
747            //
748            // Save the endpoint for this DMA channel.
749            //
750            psUSBDMAInst->pui8Endpoint[ui32Channel] = ui8Endpoint;
751
752            //
753            // Save the maximum packet size for the endpoint.
754            //
755            psUSBDMAInst->pui32MaxPacketSize[ui32Channel] = ui32MaxPacketSize;
756
757            //
758            // Set the channel configuration based on the direction.
759            //
760            if (ui32Config & USB_DMA_EP_RX) {
761                psUSBDMAInst->pui32Config[ui32Channel] =
762                    UDMA_SIZE_8 | UDMA_SRC_INC_NONE | UDMA_DST_INC_8 |
763                    UDMA_ARB_64;
764
765                //
766                // If in device mode and Isochronous.
767                //
768                if (((ui32Config & USB_DMA_EP_HOST) == 0) &&
769                    ((ui32Config & USB_DMA_EP_TYPE_M) ==
770                     USB_DMA_EP_TYPE_ISOC)) {
771                    //
772                    // USB_EP_AUTO_REQUEST is required for device
773                    // Isochronous endpoints.
774                    //
775                    psUSBDMAInst->pui32EPDMAMode0[ui32Channel] =
776                        USB_EP_DMA_MODE_0 | USB_EP_AUTO_REQUEST |
777                        USB_EP_HOST_IN;
778                } else {
779                    psUSBDMAInst->pui32EPDMAMode0[ui32Channel] =
780                        USB_EP_DMA_MODE_0 | USB_EP_AUTO_CLEAR | USB_EP_HOST_IN;
781                }
782
783                //
784                // Do not set auto request in device mode unless it is an
785                // isochronous endpoint.
786                //
787                if (((ui32Config & USB_DMA_EP_HOST) == 0) &&
788                    ((ui32Config & USB_DMA_EP_TYPE_M) !=
789                     USB_DMA_EP_TYPE_ISOC)) {
790                    psUSBDMAInst->pui32EPDMAMode1[ui32Channel] =
791                        USB_EP_DMA_MODE_1 | USB_EP_HOST_IN | USB_EP_AUTO_CLEAR;
792                } else {
793                    psUSBDMAInst->pui32EPDMAMode1[ui32Channel] =
794                        USB_EP_DMA_MODE_1 | USB_EP_HOST_IN |
795                        USB_EP_AUTO_REQUEST | USB_EP_AUTO_CLEAR;
796                }
797            } else {
798                psUSBDMAInst->pui32Config[ui32Channel] =
799                    UDMA_SIZE_8 | UDMA_SRC_INC_8 | UDMA_DST_INC_NONE |
800                    UDMA_ARB_64;
801
802                psUSBDMAInst->pui32EPDMAMode0[ui32Channel] =
803                    USB_EP_DMA_MODE_0 | USB_EP_HOST_OUT;
804                psUSBDMAInst->pui32EPDMAMode1[ui32Channel] =
805                    USB_EP_DMA_MODE_1 | USB_EP_HOST_OUT | USB_EP_AUTO_SET;
806            }
807
808            //
809            // Map the uDMA channel to the given endpoint.
810            //
811            MAP_USBEndpointDMAChannel(psUSBDMAInst->ui32Base, ui8Endpoint,
812                                      ui32Channel);
813
814            //
815            // Clear out the attributes on this channel.
816            //
817            MAP_uDMAChannelAttributeDisable(ui32Channel, UDMA_ATTR_ALL);
818
819            //
820            // Configure the uDMA channel for the pipe
821            //
822            MAP_uDMAChannelControlSet(ui32Channel,
823                                      psUSBDMAInst->pui32Config[ui32Channel]);
824
825            if (ui32Config & USB_DMA_EP_RX) {
826                MAP_USBEndpointDMADisable(psUSBDMAInst->ui32Base, ui8Endpoint,
827                                          USB_EP_DEV_OUT);
828            } else {
829                MAP_USBEndpointDMADisable(psUSBDMAInst->ui32Base, ui8Endpoint,
830                                          USB_EP_DEV_IN);
831            }
832
833            //
834            // Outside of this function all channels are 1 based as
835            // zero is not a valid channel.
836            //
837            return (ui32Channel + 1);
838        }
839    }
840    return (0);
841}
842
843//*****************************************************************************
844//
845// USBLibDMAChannelAllocate() for USB controllers with an integrated DMA
846// controller.
847//
848//*****************************************************************************
849static uint32_t iDMAUSBChannelAllocate(tUSBDMAInstance* psUSBDMAInst,
850                                       uint8_t ui8Endpoint,
851                                       uint32_t ui32MaxPacketSize,
852                                       uint32_t ui32Config) {
853    uint32_t ui32Channel;
854
855    //
856    // Search for an available DMA channel to use.
857    //
858    for (ui32Channel = 0; ui32Channel < USB_MAX_DMA_CHANNELS_0; ui32Channel++) {
859        //
860        // If the current endpoint value is zero then this channel is
861        // available.
862        //
863        if (psUSBDMAInst->pui8Endpoint[ui32Channel] == 0) {
864            //
865            // Clear out the attributes on this channel.
866            //
867            USBDMAChannelDisable(psUSBDMAInst->ui32Base, ui32Channel);
868
869            //
870            // Save the endpoint for this DMA channel.
871            //
872            psUSBDMAInst->pui8Endpoint[ui32Channel] = ui8Endpoint;
873
874            //
875            // Save the maximum packet size for the endpoint.
876            //
877            psUSBDMAInst->pui32MaxPacketSize[ui32Channel] = ui32MaxPacketSize;
878
879            //
880            // Assign the endpoint to the channel and set the direction.
881            //
882            if (ui32Config & USB_DMA_EP_RX) {
883                psUSBDMAInst->pui32Config[ui32Channel] =
884                    USB_DMA_CFG_DIR_RX | USB_DMA_CFG_BURST_NONE |
885                    USB_DMA_CFG_INT_EN;
886
887                //
888                // If in device mode and Isochronous.
889                //
890                if (((ui32Config & USB_DMA_EP_HOST) == 0) &&
891                    ((ui32Config & USB_DMA_EP_TYPE_M) ==
892                     USB_DMA_EP_TYPE_ISOC)) {
893                    //
894                    // USB_EP_AUTO_REQUEST is required for device
895                    // Isochronous endpoints.
896                    //
897                    psUSBDMAInst->pui32EPDMAMode0[ui32Channel] =
898                        USB_EP_DMA_MODE_0 | USB_EP_AUTO_REQUEST |
899                        USB_EP_HOST_IN;
900                } else {
901                    psUSBDMAInst->pui32EPDMAMode0[ui32Channel] =
902                        USB_EP_DMA_MODE_0 | USB_EP_AUTO_CLEAR | USB_EP_HOST_IN;
903                }
904
905                //
906                // Do not set auto request in device mode unless it is an
907                // isochronous endpoint.
908                //
909                if (((ui32Config & USB_DMA_EP_HOST) == 0) &&
910                    ((ui32Config & USB_DMA_EP_TYPE_M) !=
911                     USB_DMA_EP_TYPE_ISOC)) {
912                    psUSBDMAInst->pui32EPDMAMode1[ui32Channel] =
913                        USB_EP_DMA_MODE_1 | USB_EP_HOST_IN | USB_EP_AUTO_CLEAR;
914                } else {
915                    psUSBDMAInst->pui32EPDMAMode1[ui32Channel] =
916                        USB_EP_DMA_MODE_1 | USB_EP_HOST_IN |
917                        USB_EP_AUTO_REQUEST | USB_EP_AUTO_CLEAR;
918                }
919            } else {
920                psUSBDMAInst->pui32Config[ui32Channel] =
921                    USB_DMA_CFG_DIR_TX | USB_DMA_CFG_BURST_NONE |
922                    USB_DMA_CFG_INT_EN;
923
924                psUSBDMAInst->pui32EPDMAMode0[ui32Channel] =
925                    USB_EP_DMA_MODE_0 | USB_EP_HOST_OUT;
926                psUSBDMAInst->pui32EPDMAMode1[ui32Channel] =
927                    USB_EP_DMA_MODE_1 | USB_EP_HOST_OUT | USB_EP_AUTO_SET;
928            }
929
930            //
931            // Outside of this function all channels are 1 based as
932            // zero is not a valid channel.
933            //
934            return (ui32Channel + 1);
935        }
936    }
937    return (0);
938}
939
940//*****************************************************************************
941//
942// USBLibDMAChannelRelease() for USB controllers that use uDMA for DMA.
943//
944//*****************************************************************************
945static void uDMAUSBChannelRelease(tUSBDMAInstance* psUSBDMAInst,
946                                  uint8_t ui32Channel) {
947    ASSERT(ui32Channel < USB_MAX_DMA_CHANNELS_0);
948
949    //
950    // Clear out the attributes on this channel.
951    //
952    MAP_uDMAChannelAttributeDisable(ui32Channel - 1, UDMA_ATTR_ALL);
953
954    if (psUSBDMAInst->pui8Endpoint[ui32Channel] & USB_DMA_EP_RX) {
955        MAP_USBEndpointDMADisable(
956            psUSBDMAInst->ui32Base,
957            (psUSBDMAInst->pui8Endpoint[ui32Channel] & ~USB_DMA_EP_RX),
958            USB_EP_DEV_OUT);
959    } else {
960        MAP_USBEndpointDMADisable(
961            psUSBDMAInst->ui32Base,
962            (psUSBDMAInst->pui8Endpoint[ui32Channel] & ~USB_DMA_EP_RX),
963            USB_EP_DEV_IN);
964    }
965
966    //
967    // Clear out the state for this endpoint.
968    //
969    psUSBDMAInst->pui8Endpoint[ui32Channel - 1] = 0;
970    psUSBDMAInst->pui32Config[ui32Channel - 1] = 0;
971    psUSBDMAInst->ui32Pending &= ~(1 << (ui32Channel - 1));
972    psUSBDMAInst->ui32Complete &= ~(1 << (ui32Channel - 1));
973    psUSBDMAInst->pui32MaxPacketSize[ui32Channel - 1] = 0;
974}
975
976//*****************************************************************************
977//
978// DMAChannelRelease() for USB controllers with an integrated DMA controller.
979//
980//*****************************************************************************
981static void iDMAUSBChannelRelease(tUSBDMAInstance* psUSBDMAInst,
982                                  uint8_t ui32Channel) {
983    ASSERT(ui32Channel < USB_MAX_DMA_CHANNELS);
984
985    //
986    // Clear out the attributes on this channel.
987    //
988    USBDMAChannelDisable(psUSBDMAInst->ui32Base, ui32Channel);
989
990    //
991    // Clear out the state for this endpoint.
992    //
993    psUSBDMAInst->pui8Endpoint[ui32Channel - 1] = 0;
994    psUSBDMAInst->pui32Config[ui32Channel - 1] = 0;
995    psUSBDMAInst->ui32Pending &= ~(1 << (ui32Channel - 1));
996    psUSBDMAInst->ui32Complete &= ~(1 << (ui32Channel - 1));
997    psUSBDMAInst->pui32MaxPacketSize[ui32Channel - 1] = 0;
998}
999
1000//*****************************************************************************
1001//
1002// USBLibDMAUnitSizeSet() for USB controllers that use uDMA for DMA.
1003//
1004//*****************************************************************************
1005static void uDMAUSBUnitSizeSet(tUSBDMAInstance* psUSBDMAInst,
1006                               uint32_t ui32Channel, uint32_t ui32BitSize) {
1007    uint32_t ui32Value;
1008
1009    ASSERT((ui32BitSize == 8) || (ui32BitSize == 16) || (ui32BitSize == 32));
1010
1011    ASSERT(ui32Channel < USB_MAX_DMA_CHANNELS_0);
1012
1013    if (ui32BitSize == 8) {
1014        ui32Value = UDMA_SIZE_8;
1015
1016        if (UDMAConfigIsRx(psUSBDMAInst->pui32Config[ui32Channel - 1])) {
1017            //
1018            // Receive increments destination and not source.
1019            //
1020            ui32Value |= UDMA_DST_INC_8 | UDMA_SRC_INC_NONE;
1021        } else {
1022            //
1023            // Transmit increments source and not destination.
1024            //
1025            ui32Value |= UDMA_SRC_INC_8 | UDMA_DST_INC_NONE;
1026        }
1027    } else if (ui32BitSize == 16) {
1028        ui32Value = UDMA_SIZE_16;
1029
1030        if (UDMAConfigIsRx(psUSBDMAInst->pui32Config[ui32Channel - 1])) {
1031            //
1032            // Receive increments destination and not source.
1033            //
1034            ui32Value |= UDMA_DST_INC_16 | UDMA_SRC_INC_NONE;
1035        } else {
1036            //
1037            // Transmit increments source and not destination.
1038            //
1039            ui32Value |= UDMA_SRC_INC_16 | UDMA_DST_INC_NONE;
1040        }
1041    } else {
1042        ui32Value = UDMA_SIZE_32;
1043
1044        if (UDMAConfigIsRx(psUSBDMAInst->pui32Config[ui32Channel - 1])) {
1045            //
1046            // Receive increments destination and not source.
1047            //
1048            ui32Value |= (UDMA_DST_INC_32 | UDMA_SRC_INC_NONE);
1049        } else {
1050            //
1051            // Transmit increments source and not destination.
1052            //
1053            ui32Value |= (UDMA_SRC_INC_32 | UDMA_DST_INC_NONE);
1054        }
1055    }
1056
1057    //
1058    // Keep the current arbitration size and or in the size.
1059    //
1060    psUSBDMAInst->pui32Config[ui32Channel - 1] &= 0x00ffffff;
1061    psUSBDMAInst->pui32Config[ui32Channel - 1] |= ui32Value;
1062    MAP_uDMAChannelControlSet(ui32Channel - 1,
1063                              psUSBDMAInst->pui32Config[ui32Channel - 1]);
1064}
1065
1066//*****************************************************************************
1067//
1068// USBLibDMAUnitSizeSet() for USB controllers that have an integrated DMA
1069// controller.
1070//
1071//*****************************************************************************
1072static void iDMAUSBUnitSizeSet(tUSBDMAInstance* psUSBDMAInst,
1073                               uint32_t ui32Channel, uint32_t ui32BitSize) {}
1074
1075//*****************************************************************************
1076//
1077// USBLibDMAArbSizeSet() for USB controllers that use uDMA for DMA.
1078//
1079//*****************************************************************************
1080static void uDMAUSBArbSizeSet(tUSBDMAInstance* psUSBDMAInst,
1081                              uint32_t ui32Channel, uint32_t ui32ArbSize) {
1082    uint32_t ui32Value;
1083
1084    ASSERT(ui32Channel < USB_MAX_DMA_CHANNELS_0);
1085
1086    //
1087    // Get the arbitration size value.
1088    //
1089    if (ui32ArbSize == 2) {
1090        ui32Value = UDMA_ARB_2;
1091    } else if (ui32ArbSize == 4) {
1092        ui32Value = UDMA_ARB_4;
1093    } else if (ui32ArbSize == 8) {
1094        ui32Value = UDMA_ARB_8;
1095    } else if (ui32ArbSize == 16) {
1096        ui32Value = UDMA_ARB_16;
1097    } else if (ui32ArbSize == 32) {
1098        ui32Value = UDMA_ARB_32;
1099    } else if (ui32ArbSize == 64) {
1100        ui32Value = UDMA_ARB_64;
1101    } else if (ui32ArbSize == 128) {
1102        ui32Value = UDMA_ARB_128;
1103    } else if (ui32ArbSize == 256) {
1104        ui32Value = UDMA_ARB_256;
1105    } else {
1106        //
1107        // Default to arbitration size of 1.
1108        //
1109        ui32Value = UDMA_ARB_1;
1110    }
1111
1112    //
1113    // Keep the current size and or in the new arbitration size.
1114    //
1115    psUSBDMAInst->pui32Config[ui32Channel - 1] &= 0xff000000;
1116    psUSBDMAInst->pui32Config[ui32Channel - 1] |= ui32Value;
1117
1118    //
1119    // Set the uDMA channel control, remember its channel starts at 0 and
1120    // not 1.
1121    //
1122    MAP_uDMAChannelControlSet(ui32Channel - 1,
1123                              psUSBDMAInst->pui32Config[ui32Channel - 1]);
1124}
1125
1126//*****************************************************************************
1127//
1128// USBLibDMAArbSizeSet() for USB controllers that have an integrated DMA
1129// controller.
1130//
1131//*****************************************************************************
1132static void iDMAUSBArbSizeSet(tUSBDMAInstance* psUSBDMAInst,
1133                              uint32_t ui32Channel, uint32_t ui32ArbSize) {}
1134
1135//*****************************************************************************
1136//
1137// USBLibDMAStatus() for USB controllers that use uDMA for DMA or have an
1138// integrated DMA controller.
1139//
1140//*****************************************************************************
1141static uint32_t DMAUSBStatus(tUSBDMAInstance* psUSBDMAInst) {
1142    return (0);
1143}
1144
1145//*****************************************************************************
1146//
1147//! This function is used to return the current DMA pointer for a given
1148//! DMA channel.
1149//!
1150//! \param psUSBDMAInst is a generic instance pointer that can be used to
1151//! distinguish between different hardware instances.
1152//! \param ui32Channel is the DMA channel number for this request.
1153//!
1154//! This function returns the address that is in use by the DMA channel passed
1155//! in via the \e ui32Channel parameter.  This is not the real-time pointer,
1156//! but the starting address of the DMA transfer for this DMA channel.
1157//!
1158//! \return The current DMA address for the given DMA channel.
1159//
1160//*****************************************************************************
1161void* USBLibDMAAddrGet(tUSBDMAInstance* psUSBDMAInst, uint32_t ui32Channel) {
1162    return (psUSBDMAInst->ppui32Data[ui32Channel - 1]);
1163}
1164
1165//*****************************************************************************
1166//
1167//! This function is used to return the current DMA transfer size for a given
1168//! DMA channel.
1169//!
1170//! \param psUSBDMAInst is a generic instance pointer that can be used to
1171//! distinguish between different hardware instances.
1172//! \param ui32Channel is the DMA channel number for this request.
1173//!
1174//! This function returns the DMA transfer size that is in use by the DMA
1175//! channel passed in via the \e ui32Channel parameter.
1176//!
1177//! \return The current DMA transfer size for the given DMA channel.
1178//
1179//*****************************************************************************
1180uint32_t USBLibDMASizeGet(tUSBDMAInstance* psUSBDMAInst, uint32_t ui32Channel) {
1181    return (psUSBDMAInst->pui32Count[ui32Channel - 1]);
1182}
1183
1184//*****************************************************************************
1185//
1186//! This function is used to initialize the DMA interface for a USB instance.
1187//!
1188//! \param ui32Index is the index of the USB controller for this instance.
1189//!
1190//! This function performs any initialization and configuration of the DMA
1191//! portions of the USB controller.  This function returns a pointer that
1192//! is used with the remaining USBLibDMA APIs or the function returns zero
1193//! if the requested controller cannot support DMA.  If this function is called
1194//! when already initialized it will not reinitialize the DMA controller and
1195//! will instead return the previously initialized DMA instance.
1196//!
1197//! \return A pointer to use with USBLibDMA APIs.
1198//
1199//*****************************************************************************
1200tUSBDMAInstance* USBLibDMAInit(uint32_t ui32Index) {
1201    uint32_t ui32Channel;
1202
1203    ASSERT(ui32Index == 0);
1204
1205    //
1206    // Make sure that the DMA has not already been initialized.
1207    //
1208    if (g_psUSBDMAInst[0].ui32Base == USB0_BASE) {
1209        return (&g_psUSBDMAInst[0]);
1210    }
1211
1212    //
1213    // Save the base address of the USB controller.
1214    //
1215    g_psUSBDMAInst[0].ui32Base = USB0_BASE;
1216
1217    //
1218    // Save the interrupt number for the USB controller.
1219    //
1220    g_psUSBDMAInst[0].ui32IntNum = INT_USB0_TM4C123;
1221
1222    //
1223    // Initialize the function pointers.
1224    //
1225    g_psUSBDMAInst[0].pfnArbSizeSet = uDMAUSBArbSizeSet;
1226    g_psUSBDMAInst[0].pfnChannelAllocate = uDMAUSBChannelAllocate;
1227    g_psUSBDMAInst[0].pfnChannelDisable = uDMAUSBChannelDisable;
1228    g_psUSBDMAInst[0].pfnChannelEnable = uDMAUSBChannelEnable;
1229    g_psUSBDMAInst[0].pfnChannelIntEnable = uDMAUSBChannelIntEnable;
1230    g_psUSBDMAInst[0].pfnChannelIntDisable = uDMAUSBChannelIntDisable;
1231    g_psUSBDMAInst[0].pfnChannelRelease = uDMAUSBChannelRelease;
1232    g_psUSBDMAInst[0].pfnChannelStatus = uDMAUSBChannelStatus;
1233    g_psUSBDMAInst[0].pfnIntHandler = DMAUSBIntHandler;
1234    g_psUSBDMAInst[0].pfnIntStatus = uDMAUSBIntStatus;
1235    g_psUSBDMAInst[0].pfnIntStatusClear = DMAUSBIntStatusClear;
1236    g_psUSBDMAInst[0].pfnStatus = DMAUSBStatus;
1237    g_psUSBDMAInst[0].pfnTransfer = uDMAUSBTransfer;
1238    g_psUSBDMAInst[0].pfnUnitSizeSet = uDMAUSBUnitSizeSet;
1239
1240    //
1241    // These devices have a different USB interrupt number.
1242    //
1243    if (CLASS_IS_TM4C129) {
1244        g_psUSBDMAInst[0].ui32IntNum = INT_USB0_TM4C129;
1245    }
1246
1247    //
1248    // Initialize the function pointers for the integrated USB DMA controller.
1249    //
1250    if (USBControllerVersion(g_psUSBDMAInst[0].ui32Base) ==
1251        USB_CONTROLLER_VER_1) {
1252        g_psUSBDMAInst[0].pfnArbSizeSet = iDMAUSBArbSizeSet;
1253        g_psUSBDMAInst[0].pfnChannelAllocate = iDMAUSBChannelAllocate;
1254        g_psUSBDMAInst[0].pfnChannelStatus = iDMAUSBChannelStatus;
1255        g_psUSBDMAInst[0].pfnIntStatus = iDMAUSBIntStatus;
1256        g_psUSBDMAInst[0].pfnChannelIntEnable = iDMAUSBChannelIntEnable;
1257        g_psUSBDMAInst[0].pfnChannelIntDisable = iDMAUSBChannelIntDisable;
1258        g_psUSBDMAInst[0].pfnTransfer = iDMAUSBTransfer;
1259        g_psUSBDMAInst[0].pfnChannelRelease = iDMAUSBChannelRelease;
1260        g_psUSBDMAInst[0].pfnChannelEnable = iDMAUSBChannelEnable;
1261        g_psUSBDMAInst[0].pfnChannelDisable = iDMAUSBChannelDisable;
1262        g_psUSBDMAInst[0].pfnUnitSizeSet = iDMAUSBUnitSizeSet;
1263    }
1264
1265    //
1266    // Clear out the endpoint and the current configuration.
1267    //
1268    for (ui32Channel = 0; ui32Channel < USB_MAX_DMA_CHANNELS; ui32Channel++) {
1269        g_psUSBDMAInst[0].pui8Endpoint[ui32Channel] = 0;
1270        g_psUSBDMAInst[0].pui32Config[ui32Channel] = 0;
1271        g_psUSBDMAInst[0].ui32Pending = 0;
1272        g_psUSBDMAInst[0].ui32Complete = 0;
1273    }
1274    return (&g_psUSBDMAInst[0]);
1275}
1276
1277//*****************************************************************************
1278//
1279// Close the Doxygen group.
1280//! @}
1281//
1282//*****************************************************************************