1.10.7 1.11.8 1.12.7 1.13.7 1.22.9 1.23.8 1.24.7 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
Name | Description |
---|---|
DMAC_Initialize | This function initializes the DMAC controller of the device |
DMAC_ChannelCallbackRegister | This function allows a DMAC PLIB client to set an event handler |
DMAC_ChannelTransfer | Schedules a DMA transfer on the specified DMA channel |
DMAC_ChainTransferSetup | Setup a DMA channel for chain transfer |
DMAC_ChannelPatternMatchSetup | Sets up DMA channel for pattern matching |
DMAC_ChannelPatternMatchDisable | Disables the DMA pattern matching |
DMAC_ChannelDisable | This function disables the DMA channel |
DMAC_ChannelIsBusy | Reads the busy status of a channel |
DMAC_ChannelTransferStatusGet | Returns the DMA channel's transfer status |
DMAC_ChannelCRCSetup | DMA Channel CRC setup and enable function |
DMAC_CRCDisable | DMA CRC disable function |
DMAC_CRCRead | DMA CRC read function |
Data types and constants
Name | Type | Description |
---|---|---|
DMAC_ERROR | Enum | Identifies the available DMA operating modes |
DMAC_TRANSFER_EVENT | Enum | Identifies the status of the transfer event |
DMAC_DATA_PATTERN_SIZE | Enum | Identifies the pattern size for data matching |
DMAC_CHANNEL_CALLBACK | Typedef | Pointer to a DMAC Transfer Event handler function |
DMAC_CHANNEL | Enum | Fundamental data object that represents DMA channel number |
DMAC_CRC_SETUP | Struct | Fundamental data object that represents DMA CRC setup parameters |