Download Stellaris Peripheral Driver Library User's Guide

Transcript
USB Controller
DMAChannelTransferSet(DMA_CHANNEL_USBEP1TX, DMA_MODE_BASIC, pData,
USBFIFOAddr(USB0_BASE, USB_EP_1), 64);
//
// Start the transfer.
//
DMAChannelEnable(DMA_CHANNEL_USBEP1TX);
Because the uDMA interrupt occurs on the same interrupt vector as any other USB interrupt, the
application must perform an extra check to determine what was the actual source of the interrupt.
It is important to note that this DMA interrupt does not mean that the USB transfer is complete,
but that the data has been transferred to the USB controller’s FIFO. There will also be an interrupt
indicating that the USB transfer is complete. However, both events need to be handled in the same
interrupt routine. This because if other code in the system holds off the USB interrupt routine, both
the uDMA complete and transfer complete can occur before the USB interrupt handler is called.
The USB has no status bit indicating that the interrupt was due to a DMA complete, which means
that the application must remember if a DMA transaction was in progress. The example below
shows the g_ulFlags global variable being used to remember that a DMA transfer was pending.
Example: Interrupt handling with uDMA.
if((g_ulFlags & EP1_DMA_IN_PEND) &&
(DMAChannelModeGet(DMA_CHANNEL_USBEP1TX) == DMA_MODE_STOP))
{
//
// Handle the DMA complete case.
//
...
}
//
// Get the interrupt status.
//
ulStatus = USBIntStatusEndpoint(USB0_BASE);
if(ulStatus & USB_INTEP_DEV_IN_1)
{
//
// Handler the transfer complete case.
//
...
}
To use the USB device controller with an OUT endpoint, the application must use a receive
uDMA channel. When calling USBDevEndpointConfigSet() for an endpoint that uses uDMA, the
application must set extra flags in the ulFlags parameter. The USB_EP_DMA_MODE_0 and
USB_EP_DMA_MODE_1 control the mode of the transaction, USB_EP_AUTO_CLEAR allows the
data to be received automatically without needing to manually acknowledge that the data has been
read. If the transfer size is not known USB_EP_DMA_MODE_1 should be used as it will not generate an interrupt when each packet is sent over USB and will interrupt if a short packet is received.
In USB_EP_DMA_MODE_1, the last short packet will remain in the FIFO and need to be read by
software when the interrupt is received. If the full transfer size is known, USB_EP_DMA_MODE_0
can be used since it will not interrupt the processor after each packet and will complete even if
the last packet is a short packet. The USB_EP_AUTO_CLEAR flag should normally be specified
when using uDMA to allow the USB controller to transfer multiple packets without interruption of the
microcontroller. The example below configures endpoint 1 as a Device mode Bulk OUT endpoint
using DMA mode 1 with a max packet size of 64 bytes.
Example: Configure endpoint 1 receive channel:
September 09, 2011
451