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

Overview

This section describes the programming interface of the DMA Peripheral driver. The DMA driver requests, configures, and uses the DMA hardware. It supports module initialization and DMA channel configuration.

Data Structures

struct  dma_channel_t
 Data structure for the DMA channel management. More...
 
struct  dma_state_t
 Data structure for the DMA controller management. More...
 

Typedefs

typedef void(* dma_callback_t )(void *parameter, dma_channel_status_t status)
 A definition for the DMA channel callback function. More...
 

Enumerations

enum  dma_channel_status_t {
  kDmaIdle,
  kDmaNormal,
  kDmaError
}
 Channel status for the DMA channel. More...
 
enum  dma_channel_type_t {
  kDmaInvalidChannel = 0xFFU,
  kDmaAnyChannel = 0xFEU
}
 Type for the DMA channel, which is used for the DMA channel allocation. More...
 

Variables

DMA_Type *const g_dmaBase [DMA_INSTANCE_COUNT]
 Array for eDMA module register base address. More...
 
DMAMUX_Type *const g_dmamuxBase [DMAMUX_INSTANCE_COUNT]
 Array for DMAMUX module register base address. More...
 
const IRQn_Type g_dmaIrqId [DMA_INSTANCE_COUNT][FSL_FEATURE_DMA_DMAMUX_CHANNELS]
 Two-dimensional array for eDMA channel interrupt vector number. More...
 

DMA Driver

dma_status_t DMA_DRV_Init (dma_state_t *state)
 Initializes the DMA. More...
 
dma_status_t DMA_DRV_Deinit (void)
 De-initializes the DMA. More...
 
dma_status_t DMA_DRV_SetDestTransferSize (dma_channel_t *chn, uint32_t transferSize)
 Updates the DMA destination transfer size. More...
 
dma_status_t DMA_DRV_SetSourceTransferSize (dma_channel_t *chn, uint32_t transferSize)
 Updates the DMA source transfer size. More...
 
dma_status_t DMA_DRV_RegisterCallback (dma_channel_t *chn, dma_callback_t callback, void *para)
 Registers the callback function and a parameter. More...
 
uint32_t DMA_DRV_GetUnfinishedBytes (dma_channel_t *chn)
 Gets the number of unfinished bytes. More...
 
dma_status_t DMA_DRV_ClaimChannel (uint32_t channel, dma_request_source_t source, dma_channel_t *chn)
 Claims a DMA channel. More...
 
uint32_t DMA_DRV_RequestChannel (uint32_t channel, dma_request_source_t source, dma_channel_t *chn)
 Requests a DMA channel. More...
 
dma_status_t DMA_DRV_FreeChannel (dma_channel_t *chn)
 Frees DMA channel hardware and software resource. More...
 
dma_status_t DMA_DRV_StartChannel (dma_channel_t *chn)
 Starts a DMA channel. More...
 
dma_status_t DMA_DRV_StopChannel (dma_channel_t *chn)
 Stops a DMA channel. More...
 
dma_status_t DMA_DRV_ConfigTransfer (dma_channel_t *chn, dma_transfer_type_t type, uint32_t size, uint32_t sourceAddr, uint32_t destAddr, uint32_t length)
 Configures a transfer for the DMA. More...
 
dma_status_t DMA_DRV_ConfigChanLink (dma_channel_t *chn, dma_channel_link_config_t *link_config)
 Configures the channel link feature. More...
 
void DMA_DRV_IRQhandler (uint32_t channel)
 DMA IRQ handler for both an interrupt and an error. More...
 

Data Structure Documentation

struct dma_channel_t

Data Fields

uint8_t channel
 Channel number.
 
uint8_t dmamuxModule
 DMAMUX module index.
 
uint8_t dmamuxChannel
 DMAMUX module channel.
 
dma_callback_t callback
 Callback function for this channel.
 
void * parameter
 Parameter for the callback function.
 
volatile dma_channel_status_t status
 Channel status.
 
struct dma_state_t

Typedef Documentation

typedef void(* dma_callback_t)(void *parameter, dma_channel_status_t status)

A prototype for the callback function registered into the DMA driver.

Enumeration Type Documentation

A structure describing the status of the DMA channel. The user can get the status from the channel callback function.

Enumerator
kDmaIdle 

DMA channel is idle.

kDmaNormal 

DMA channel is occupied.

kDmaError 

Error occurs in the DMA channel.

Enumerator
kDmaInvalidChannel 

Macros indicating the failure of the channel request.

kDmaAnyChannel 

Macros used when requesting a channel.

kEdmaAnyChannel means a request of dynamic channel allocation.

Function Documentation

dma_status_t DMA_DRV_Init ( dma_state_t state)
Parameters
stateDMA state structure used for the DMA internal logic.
Returns
If successful, returns the kStatus_DMA_Success. Otherwise, it returns an error.
dma_status_t DMA_DRV_Deinit ( void  )
Returns
If successful, returns the kStatus_DMA_Success. Otherwise, it returns an error.
dma_status_t DMA_DRV_SetDestTransferSize ( dma_channel_t chn,
uint32_t  transferSize 
)
Parameters
chnA handler for the DMA channel
transferSizeSize of destination at each transfer
Returns
If successful, returns the kStatus_DMA_Success. Otherwise, it returns an error.
dma_status_t DMA_DRV_SetSourceTransferSize ( dma_channel_t chn,
uint32_t  transferSize 
)
Parameters
chnA handler for the DMA channel
transferSizeSize of source at each transfer
Returns
If successful, returns the kStatus_DMA_Success. Otherwise, it returns an error.
dma_status_t DMA_DRV_RegisterCallback ( dma_channel_t chn,
dma_callback_t  callback,
void *  para 
)

The user registers the callback function and a parameter for a specified DMA channel. When the channel interrupt or a channel error happens, the callback and the parameter are called. The user parameter is also provided to give a channel status.

Parameters
chnA handler for the DMA channel
callbackCallback function
paraA parameter for callback functions
Returns
If successful, returns the kStatus_DMA_Success. Otherwise, it returns an error.
uint32_t DMA_DRV_GetUnfinishedBytes ( dma_channel_t chn)

Gets the bytes that remain to be transferred.

Parameters
chnA handler for the DMA channel
Returns
If successful, returns the kStatus_DMA_Success. Otherwise, it returns an error.
dma_status_t DMA_DRV_ClaimChannel ( uint32_t  channel,
dma_request_source_t  source,
dma_channel_t chn 
)
Parameters
channelChannel index which needs to claim.
sourceDMA request source.
chnA handler for the DMA channel
Returns
If successful, returns the kStatus_DMA_Success. Otherwise, it returns an error.
uint32_t DMA_DRV_RequestChannel ( uint32_t  channel,
dma_request_source_t  source,
dma_channel_t chn 
)

This function provides two ways to allocate a DMA channel: static and dynamic allocation. To allocate a channel dynamically, set the channel parameter with the value of kDmaAnyChannel. The driver searches all available free channels and assigns the first channel to the user. To allocate the channel statically, set the channel parameter with the value of a specified channel. If the channel is available, the driver assigns the channel. Notes: The user must provide a handler memory for the DMA channel. The driver initializes the handler and configures the handler memory.

Parameters
channelA DMA channel number. If a channel is assigned with a valid channel number, the DMA driver tries to assign a specified channel. If a channel is assigned with kDmaAnyChannel, the DMA driver searches all available channels and assigns the first channel to the user.
sourceA DMA hardware request.
chnMemory pointing to DMA channel. The user must ensure that the handler memory is valid and that it will not be released or changed by any other code before the channel dma_free_channel() operation.
Returns
If the channel allocation is successful, the return value indicates the requested channel. If not, the driver returns a kDmaInvalidChannel value to indicate that the request operation has failed.
dma_status_t DMA_DRV_FreeChannel ( dma_channel_t chn)

This function frees the relevant software and hardware resources. Both the request and the free operations need to be called as a pair.

Parameters
chnMemory pointing to DMA channel.
Returns
If successful, returns the kStatus_DMA_Success. Otherwise, it returns an error.
dma_status_t DMA_DRV_StartChannel ( dma_channel_t chn)

Starts a DMA channel. The driver starts a DMA channel by enabling the DMA request. A software start bit is not used in the DMA Peripheral driver.

Parameters
chnMemory pointing to the DMA channel.
Returns
If successful, returns the kStatus_DMA_Success. Otherwise, it returns an error.
dma_status_t DMA_DRV_StopChannel ( dma_channel_t chn)
Parameters
chnMemory pointing to the DMA channel.
Returns
If successful, returns the kStatus_DMA_Success. Otherwise, it returns an error.
dma_status_t DMA_DRV_ConfigTransfer ( dma_channel_t chn,
dma_transfer_type_t  type,
uint32_t  size,
uint32_t  sourceAddr,
uint32_t  destAddr,
uint32_t  length 
)

Configures a transfer for the DMA.

Parameters
chnMemory pointing to the DMA channel.
typeTransfer type.
sizeSize to be transferred on each DMA write/read. Source/Dest share the same write/read size.
sourceAddrSource address.
destAddrDestination address.
lengthBytes to be transferred.
Returns
If successful, returns the kStatus_DMA_Success. Otherwise, it returns an error.
dma_status_t DMA_DRV_ConfigChanLink ( dma_channel_t chn,
dma_channel_link_config_t link_config 
)
Parameters
chnMemory pointing to the DMA channel.
link_configConfigure of channel link in DMA.
Returns
If successful, returns the kStatus_DMA_Success. Otherwise, it returns an error.
void DMA_DRV_IRQhandler ( uint32_t  channel)
Parameters
channelDMA channel number.

Variable Documentation

DMA_Type* const g_dmaBase[DMA_INSTANCE_COUNT]
DMAMUX_Type* const g_dmamuxBase[DMAMUX_INSTANCE_COUNT]
const IRQn_Type g_dmaIrqId[DMA_INSTANCE_COUNT][FSL_FEATURE_DMA_DMAMUX_CHANNELS]