3.23.8 Direct Memory Access Controller (DMAC)

The Direct Memory Access (DMA) Controller is a bus master module useful for data transfers between different devices without CPU intervention. The source and destination of a DMA transfer can be any of the memory mapped modules existent in the device such as SPI, UART, PMP, etc., or memory itself.

The DMA Controller can also be used to generate CRC on the data been transferred through the channel

Using The Library

User can use either callback mechanism or polling mechanism to determine DMA transfer completion.

  • With polling, the application will need to continuously poll to check if the DMA has completed the transfer.

  • With callback, the registered callback function will be called when the transfer is completed. This means the application do not have to poll continuously.

Callback method

This example demonstrates DMA transfer with callback

#define USART1_TRANSMIT_ADDRESS     (U1TXREG)

uint8_t txBuffer[] = "Hello World!";

void DMAC_Callback(DMAC_TRANSFER_EVENT status, uintptr_t context)
{
      if(status == DMAC_TRANSFER_EVENT_COMPLETE)
      {
           // Transfer is completed.
      }
}

 int main ( void )
{
      SYS_Initialize ( NULL );

      DMAC_ChannelCallbackRegister(DMAC_CHANNEL_1, DMAC_Callback, 0);

      DMAC_ChannelTransfer(DMAC_CHANNEL_1, txBuffer, sizeof(txBuffer), (const void *)USART1_TRANSMIT_ADDRESS, 1, 1);

}

Polling method

This example demonstrates DMA transfer with polling

#define USART1_TRANSMIT_ADDRESS     (&U1TXREG)

uint8_t txBuffer[] = "Hello World!";

int main ( void )
{
      SYS_Initialize ( NULL );

      DMAC_ChannelTransfer(DMAC_CHANNEL_1, txBuffer, sizeof(txBuffer), (const void *)USART1_TRANSMIT_ADDRESS, 1, 1);

      while(DMAC_ChannelIsBusy(DMAC_CHANNEL_1));
}

Library Interface

peripheral library provides the following interfaces:

Functions

NameDescription
DMAC_InitializeThis function initializes the DMAC controller of the device
DMAC_ChannelCallbackRegisterThis function allows a DMAC PLIB client to set an event handler
DMAC_ChannelTransferSchedules a DMA transfer on the specified DMA channel
DMAC_ChainTransferSetupSetup a DMA channel for chain transfer
DMAC_ChannelPatternMatchSetupSets up DMA channel for pattern matching
DMAC_ChannelPatternMatchDisableDisables the DMA pattern matching
DMAC_ChannelDisableThis function disables the DMA channel
DMAC_ChannelIsBusyReads the busy status of a channel
DMAC_ChannelTransferStatusGetReturns the DMA channel's transfer status
DMAC_ChannelCRCSetupDMA Channel CRC setup and enable function
DMAC_CRCDisableDMA CRC disable function
DMAC_CRCReadDMA CRC read function

Data types and constants

NameTypeDescription
DMAC_ERROREnumIdentifies the available DMA operating modes
DMAC_TRANSFER_EVENTEnumIdentifies the status of the transfer event
DMAC_DATA_PATTERN_SIZEEnumIdentifies the pattern size for data matching
DMAC_CHANNEL_CALLBACKTypedefPointer to a DMAC Transfer Event handler function
DMAC_CHANNELEnumFundamental data object that represents DMA channel number
DMAC_CRC_SETUPStructFundamental data object that represents DMA CRC setup parameters