Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages

This section provides the DMA request resource.

DMA Initialization

To initialize the DMA module, call the dma_init() function. Configuration data structure does not need to be passed. This function enables the DMA module and clock automatically.

DMA Channel concept

DMA module consists of many channels. The DMA Peripheral driver is designed based on the channel concept. All tasks should start by requesting a DMA channel and end by freeing a DMA channel. By getting a channel allocated, the user can configure and run operations on the DMA module. If a channel is not allocated, a system error may occur.

DMA request concept

DMA request triggers a DMA transfer. The DMA request table is available in the device configuration chapters in a Reference Manual.

DMA Memory allocation

DMA peripheral driver does not allocate memory dynamically. The user must provide the allocated memory pointer for the driver and ensure that the memory is valid. Otherwise, a system error occurs. The user needs to provide the memory for the [dma_channel_t]. The driver must store the status data for every channel and the dma_channel_t is designed for this purpose.

DMA Call diagram

To use the DMA driver, follow these steps:

  1. Initialize the DMA module: dma_init().
  2. Request a DMA channel: dma_request_channel().
  3. Configure the TCD: dma_config_transfer().
  4. Register callback function: dma_register_callback().
  5. Start the DMA channel: dma_start_channel().
  6. [OPTION] Stop the DMA channel: dma_stop_channel().
  7. Free the DMA channel: dma_free_channel().

This example shows how to initialize and configure a memory-to-memory transfer:

uint32_t j, temp;
dma_channel_t chan_handler;
uint8_t *srcAddr, *destAddr;
fsl_rtos_status syncStatus;
srcAddr = malloc(kDmaTestBufferSize);
destAddr = malloc(kDmaTestBufferSize);
if (((uint32_t)srcAddr == 0x0U) & ((uint32_t)destAddr == 0x0U))
{
printf("Fali to allocate memory for test! \r\n");
goto error;
}
// Init the memory buffer. //
for (j = 0; j < kDmaTestBufferSize; j++)
{
srcAddr[j] = j;
destAddr[j] = 0;
}
temp = dma_request_channel(channel, kDmaRequestMux0AlwaysOn62, &chan_handler);
if (temp != channel)
{
printf("Failed to request channel %d !\r\n", channel);
goto error;
}
dma_config_transfer(&chan_handler, kDmaMemoryToMemory,
0x1U,
(uint32_t)srcAddr, (uint32_t)destAddr,
kDmaTestBufferSize);
dma_register_callback(&chan_handler, test_callback, &chan_handler);
dma_start_channel(&chan_handler);
//Wait until channel complete...
dma_stop_channel(&chan_handler);
dma_free_channel(&chan_handler);