The MCUXpresso SDK provides a peripheral driver for the Direct Memory Access (DMA) of MCUXpresso SDK devices.
Typical use case
DMA Operation
Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/dma
|
typedef void(* | dma_callback )(struct _dma_handle *handle, void *userData, bool transferDone, uint32_t intmode) |
| Define Callback function for DMA. More...
|
|
|
enum | dma_priority_t {
kDMA_ChannelPriority0 = 0,
kDMA_ChannelPriority1,
kDMA_ChannelPriority2,
kDMA_ChannelPriority3,
kDMA_ChannelPriority4,
kDMA_ChannelPriority5,
kDMA_ChannelPriority6,
kDMA_ChannelPriority7
} |
| DMA channel priority. More...
|
|
enum | dma_irq_t {
kDMA_IntA,
kDMA_IntB,
kDMA_IntError
} |
| DMA interrupt flags. More...
|
|
enum | dma_trigger_type_t {
kDMA_NoTrigger = 0,
kDMA_LowLevelTrigger = DMA_CHANNEL_CFG_HWTRIGEN(1) | DMA_CHANNEL_CFG_TRIGTYPE(1),
kDMA_HighLevelTrigger,
kDMA_FallingEdgeTrigger = DMA_CHANNEL_CFG_HWTRIGEN(1),
kDMA_RisingEdgeTrigger
} |
| DMA trigger type. More...
|
|
enum | dma_trigger_burst_t {
kDMA_SingleTransfer = 0,
kDMA_LevelBurstTransfer = DMA_CHANNEL_CFG_TRIGBURST(1),
kDMA_EdgeBurstTransfer1 = DMA_CHANNEL_CFG_TRIGBURST(1),
kDMA_EdgeBurstTransfer2,
kDMA_EdgeBurstTransfer4,
kDMA_EdgeBurstTransfer8,
kDMA_EdgeBurstTransfer16,
kDMA_EdgeBurstTransfer32,
kDMA_EdgeBurstTransfer64,
kDMA_EdgeBurstTransfer128,
kDMA_EdgeBurstTransfer256,
kDMA_EdgeBurstTransfer512,
kDMA_EdgeBurstTransfer1024
} |
| DMA trigger burst. More...
|
|
enum | dma_burst_wrap_t {
kDMA_NoWrap = 0,
kDMA_SrcWrap = DMA_CHANNEL_CFG_SRCBURSTWRAP(1),
kDMA_DstWrap = DMA_CHANNEL_CFG_DSTBURSTWRAP(1),
kDMA_SrcAndDstWrap
} |
| DMA burst wrapping. More...
|
|
enum | dma_transfer_type_t {
kDMA_MemoryToMemory = 0x0U,
kDMA_PeripheralToMemory,
kDMA_MemoryToPeripheral,
kDMA_StaticToStatic
} |
| DMA transfer type. More...
|
|
enum | _dma_transfer_status { kStatus_DMA_Busy = MAKE_STATUS(kStatusGroup_DMA, 0)
} |
| DMA transfer status. More...
|
|
|
static bool | DMA_ChannelIsActive (DMA_Type *base, uint32_t channel) |
| Return whether DMA channel is processing transfer. More...
|
|
static void | DMA_EnableChannelInterrupts (DMA_Type *base, uint32_t channel) |
| Enables the interrupt source for the DMA transfer. More...
|
|
static void | DMA_DisableChannelInterrupts (DMA_Type *base, uint32_t channel) |
| Disables the interrupt source for the DMA transfer. More...
|
|
static void | DMA_EnableChannel (DMA_Type *base, uint32_t channel) |
| Enable DMA channel. More...
|
|
static void | DMA_DisableChannel (DMA_Type *base, uint32_t channel) |
| Disable DMA channel. More...
|
|
static void | DMA_EnableChannelPeriphRq (DMA_Type *base, uint32_t channel) |
| Set PERIPHREQEN of channel configuration register. More...
|
|
static void | DMA_DisableChannelPeriphRq (DMA_Type *base, uint32_t channel) |
| Get PERIPHREQEN value of channel configuration register. More...
|
|
void | DMA_ConfigureChannelTrigger (DMA_Type *base, uint32_t channel, dma_channel_trigger_t *trigger) |
| Set trigger settings of DMA channel. More...
|
|
uint32_t | DMA_GetRemainingBytes (DMA_Type *base, uint32_t channel) |
| Gets the remaining bytes of the current DMA descriptor transfer. More...
|
|
static void | DMA_SetChannelPriority (DMA_Type *base, uint32_t channel, dma_priority_t priority) |
| Set priority of channel configuration register. More...
|
|
static dma_priority_t | DMA_GetChannelPriority (DMA_Type *base, uint32_t channel) |
| Get priority of channel configuration register. More...
|
|
void | DMA_CreateDescriptor (dma_descriptor_t *desc, dma_xfercfg_t *xfercfg, void *srcAddr, void *dstAddr, void *nextDesc) |
| Create application specific DMA descriptor to be used in a chain in transfer. More...
|
|
|
void | DMA_AbortTransfer (dma_handle_t *handle) |
| Abort running transfer by handle. More...
|
|
void | DMA_CreateHandle (dma_handle_t *handle, DMA_Type *base, uint32_t channel) |
| Creates the DMA handle. More...
|
|
void | DMA_SetCallback (dma_handle_t *handle, dma_callback callback, void *userData) |
| Installs a callback function for the DMA transfer. More...
|
|
void | DMA_PrepareTransfer (dma_transfer_config_t *config, void *srcAddr, void *dstAddr, uint32_t byteWidth, uint32_t transferBytes, dma_transfer_type_t type, void *nextDesc) |
| Prepares the DMA transfer structure. More...
|
|
status_t | DMA_SubmitTransfer (dma_handle_t *handle, dma_transfer_config_t *config) |
| Submits the DMA transfer request. More...
|
|
void | DMA_StartTransfer (dma_handle_t *handle) |
| DMA start transfer. More...
|
|
void | DMA_HandleIRQ (void) |
| DMA IRQ handler for descriptor transfer complete. More...
|
|
Data Fields |
uint32_t | xfercfg |
| Transfer configuration.
|
|
void * | srcEndAddr |
| Last source address of DMA transfer.
|
|
void * | dstEndAddr |
| Last destination address of DMA transfer.
|
|
void * | linkToNextDesc |
| Address of next DMA descriptor in chain.
|
|
Data Fields |
bool | valid |
| Descriptor is ready to transfer.
|
|
bool | reload |
| Reload channel configuration register after current descriptor is exhausted.
|
|
bool | swtrig |
| Perform software trigger. More...
|
|
bool | clrtrig |
| Clear trigger.
|
|
bool | intA |
| Raises IRQ when transfer is done and set IRQA status register flag.
|
|
bool | intB |
| Raises IRQ when transfer is done and set IRQB status register flag.
|
|
uint8_t | byteWidth |
| Byte width of data to transfer.
|
|
uint8_t | srcInc |
| Increment source address by 'srcInc' x 'byteWidth'.
|
|
uint8_t | dstInc |
| Increment destination address by 'dstInc' x 'byteWidth'.
|
|
uint16_t | transferCount |
| Number of transfers.
|
|
bool dma_xfercfg_t::swtrig |
Transfer if fired when 'valid' is set
struct dma_channel_trigger_t |
struct dma_transfer_config_t |
Invoked when transfer of descriptor with interrupt flag finishes
typedef void(* dma_callback)(struct _dma_handle *handle, void *userData, bool transferDone, uint32_t intmode) |
Enumerator |
---|
kDMA_ChannelPriority0 |
Highest channel priority - priority 0.
|
kDMA_ChannelPriority1 |
Channel priority 1.
|
kDMA_ChannelPriority2 |
Channel priority 2.
|
kDMA_ChannelPriority3 |
Channel priority 3.
|
kDMA_ChannelPriority4 |
Channel priority 4.
|
kDMA_ChannelPriority5 |
Channel priority 5.
|
kDMA_ChannelPriority6 |
Channel priority 6.
|
kDMA_ChannelPriority7 |
Lowest channel priority - priority 7.
|
Enumerator |
---|
kDMA_IntA |
DMA interrupt flag A.
|
kDMA_IntB |
DMA interrupt flag B.
|
kDMA_IntError |
DMA interrupt flag error.
|
Enumerator |
---|
kDMA_NoTrigger |
Trigger is disabled.
|
kDMA_LowLevelTrigger |
Low level active trigger.
|
kDMA_HighLevelTrigger |
High level active trigger.
|
kDMA_FallingEdgeTrigger |
Falling edge active trigger.
|
kDMA_RisingEdgeTrigger |
Rising edge active trigger.
|
Enumerator |
---|
kDMA_SingleTransfer |
Single transfer.
|
kDMA_LevelBurstTransfer |
Burst transfer driven by level trigger.
|
kDMA_EdgeBurstTransfer1 |
Perform 1 transfer by edge trigger.
|
kDMA_EdgeBurstTransfer2 |
Perform 2 transfers by edge trigger.
|
kDMA_EdgeBurstTransfer4 |
Perform 4 transfers by edge trigger.
|
kDMA_EdgeBurstTransfer8 |
Perform 8 transfers by edge trigger.
|
kDMA_EdgeBurstTransfer16 |
Perform 16 transfers by edge trigger.
|
kDMA_EdgeBurstTransfer32 |
Perform 32 transfers by edge trigger.
|
kDMA_EdgeBurstTransfer64 |
Perform 64 transfers by edge trigger.
|
kDMA_EdgeBurstTransfer128 |
Perform 128 transfers by edge trigger.
|
kDMA_EdgeBurstTransfer256 |
Perform 256 transfers by edge trigger.
|
kDMA_EdgeBurstTransfer512 |
Perform 512 transfers by edge trigger.
|
kDMA_EdgeBurstTransfer1024 |
Perform 1024 transfers by edge trigger.
|
Enumerator |
---|
kDMA_NoWrap |
Wrapping is disabled.
|
kDMA_SrcWrap |
Wrapping is enabled for source.
|
kDMA_DstWrap |
Wrapping is enabled for destination.
|
kDMA_SrcAndDstWrap |
Wrapping is enabled for source and destination.
|
Enumerator |
---|
kDMA_MemoryToMemory |
Transfer from memory to memory (increment source and destination)
|
kDMA_PeripheralToMemory |
Transfer from peripheral to memory (increment only destination)
|
kDMA_MemoryToPeripheral |
Transfer from memory to peripheral (increment only source)
|
kDMA_StaticToStatic |
Peripheral to static memory (do not increment source or destination)
|
Enumerator |
---|
kStatus_DMA_Busy |
Channel is busy and can't handle the transfer request.
|
void DMA_Init |
( |
DMA_Type * |
base | ) |
|
This function enable the DMA clock, set descriptor table and enable DMA peripheral.
- Parameters
-
base | DMA peripheral base address. |
void DMA_Deinit |
( |
DMA_Type * |
base | ) |
|
This function gates the DMA clock.
- Parameters
-
base | DMA peripheral base address. |
static bool DMA_ChannelIsActive |
( |
DMA_Type * |
base, |
|
|
uint32_t |
channel |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | DMA peripheral base address. |
channel | DMA channel number. |
- Returns
- True for active state, false otherwise.
static void DMA_EnableChannelInterrupts |
( |
DMA_Type * |
base, |
|
|
uint32_t |
channel |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | DMA peripheral base address. |
channel | DMA channel number. |
static void DMA_DisableChannelInterrupts |
( |
DMA_Type * |
base, |
|
|
uint32_t |
channel |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | DMA peripheral base address. |
channel | DMA channel number. |
static void DMA_EnableChannel |
( |
DMA_Type * |
base, |
|
|
uint32_t |
channel |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | DMA peripheral base address. |
channel | DMA channel number. |
static void DMA_DisableChannel |
( |
DMA_Type * |
base, |
|
|
uint32_t |
channel |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | DMA peripheral base address. |
channel | DMA channel number. |
static void DMA_EnableChannelPeriphRq |
( |
DMA_Type * |
base, |
|
|
uint32_t |
channel |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | DMA peripheral base address. |
channel | DMA channel number. |
static void DMA_DisableChannelPeriphRq |
( |
DMA_Type * |
base, |
|
|
uint32_t |
channel |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | DMA peripheral base address. |
channel | DMA channel number. |
- Returns
- True for enabled PeriphRq, false for disabled.
- Parameters
-
base | DMA peripheral base address. |
channel | DMA channel number. |
trigger | trigger configuration. |
uint32_t DMA_GetRemainingBytes |
( |
DMA_Type * |
base, |
|
|
uint32_t |
channel |
|
) |
| |
- Parameters
-
base | DMA peripheral base address. |
channel | DMA channel number. |
- Returns
- The number of bytes which have not been transferred yet.
static void DMA_SetChannelPriority |
( |
DMA_Type * |
base, |
|
|
uint32_t |
channel, |
|
|
dma_priority_t |
priority |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | DMA peripheral base address. |
channel | DMA channel number. |
priority | Channel priority value. |
static dma_priority_t DMA_GetChannelPriority |
( |
DMA_Type * |
base, |
|
|
uint32_t |
channel |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | DMA peripheral base address. |
channel | DMA channel number. |
- Returns
- Channel priority value.
- Parameters
-
desc | DMA descriptor address. |
xfercfg | Transfer configuration for DMA descriptor. |
srcAddr | Address of last item to transmit |
dstAddr | Address of last item to receive. |
nextDesc | Address of next descriptor in chain. |
This function aborts DMA transfer specified by handle.
- Parameters
-
handle | DMA handle pointer. |
void DMA_CreateHandle |
( |
dma_handle_t * |
handle, |
|
|
DMA_Type * |
base, |
|
|
uint32_t |
channel |
|
) |
| |
This function is called if using transaction API for DMA. This function initializes the internal state of DMA handle.
- Parameters
-
handle | DMA handle pointer. The DMA handle stores callback function and parameters. |
base | DMA peripheral base address. |
channel | DMA channel number. |
This callback is called in DMA IRQ handler. Use the callback to do something after the current major loop transfer completes.
- Parameters
-
handle | DMA handle pointer. |
callback | DMA callback function pointer. |
userData | Parameter for callback function. |
This function prepares the transfer configuration structure according to the user input.
- Parameters
-
config | The user configuration structure of type dma_transfer_t. |
srcAddr | DMA transfer source address. |
dstAddr | DMA transfer destination address. |
byteWidth | DMA transfer destination address width(bytes). |
transferBytes | DMA transfer bytes to be transferred. |
type | DMA transfer type. |
nextDesc | Chain custom descriptor to transfer. |
- Note
- The data address and the data width must be consistent. For example, if the SRC is 4 bytes, so the source address must be 4 bytes aligned, or it shall result in source address error(SAE).
This function submits the DMA transfer request according to the transfer configuration structure. If the user submits the transfer request repeatedly, this function packs an unprocessed request as a TCD and enables scatter/gather feature to process it in the next time.
- Parameters
-
handle | DMA handle pointer. |
config | Pointer to DMA transfer configuration structure. |
- Return values
-
kStatus_DMA_Success | It means submit transfer request succeed. |
kStatus_DMA_QueueFull | It means TCD queue is full. Submit transfer request is not allowed. |
kStatus_DMA_Busy | It means the given channel is busy, need to submit request later. |
This function enables the channel request. User can call this function after submitting the transfer request or before submitting the transfer request.
- Parameters
-
handle | DMA handle pointer. |
void DMA_HandleIRQ |
( |
void |
| ) |
|
This function clears the channel major interrupt flag and call the callback function if it is not NULL.