The DMADRV driver makes it possible to write code using DMA which will work regardless of the type of DMA controller on the underlying microcontroller. It will also make it possible to use DMA in several modules, without the modules knowing of each others existence. The driver does not preclude use of the native emlib API of the underlying DMA controller, on the contrary, this will often result in more efficient code and is a necessity when doing complex DMA operations. The housekeeping functions of this driver will be valuable even in this use-case.
The source files for the DMA driver library resides in the emdrv/dmadrv folder, and are named dmadrv.c and dmadrv.h.
Some properties of the DMADRV driver are compile-time configurable. These properties are stored in a file named dmadrv_config.h. A template for this file, containing default values, resides in the emdrv/config folder. Currently the configuration options are:
Both configuration options will help reduce the drivers ram memory footprint.
To configure DMADRV, provide your own configuration file. Here is a sample dmadrv_config.h file:
#ifndef __SILICON_LABS_DMADRV_CONFIG_H__ #define __SILICON_LABS_DMADRV_CONFIG_H__ // DMADRV DMA interrupt priority configuration option. // Set DMA interrupt priority. Range is 0..7, 0 is highest priority. #define EMDRV_DMADRV_DMA_IRQ_PRIORITY 4 // DMADRV channel count configuration option. // Number of DMA channels to support. A lower DMA channel count will reduce // ram memory footprint. #define EMDRV_DMADRV_DMA_CH_COUNT 4 // DMADRV native API configuration option. // Use the native emlib api of the DMA controller, but still use DMADRV // housekeeping functions as AllocateChannel/FreeChannel etc. #define EMDRV_DMADRV_USE_NATIVE_API #endif
This section contain brief descriptions of the functions in the API. You will find detailed information on input and output parameters and return values by clicking on the hyperlinked function names. Most functions return an error code, ECODE_EMDRV_DMADRV_OK is returned on success, see ecode.h and dmadrv.h for other error codes.
Your application code must include one header file: dmadrv.h.
DMADRV_Init(), DMADRV_DeInit()
These functions initializes or deinitializes the DMADRV driver. Typically DMADRV_Init() is called once in your startup code.
DMADRV_AllocateChannel(), DMADRV_FreeChannel()
DMA channel reserve and release functions. It is recommended that application code check that DMADRV_AllocateChannel() returns ECODE_EMDRV_DMADRV_OK before starting a DMA transfer.
DMADRV_MemoryPeripheral()
Start a DMA transfer from memory to a peripheral.
DMADRV_PeripheralMemory()
Start a DMA transfer from a peripheral to memory.
DMADRV_MemoryPeripheralPingPong()
Start a DMA ping-pong transfer from memory to a peripheral.
DMADRV_PeripheralMemoryPingPong()
Start a DMA ping-pong transfer from a peripheral to memory.
DMADRV_LdmaStartTransfer()
Start a DMA transfer on a LDMA controller. This function can only be used when configuration option EMDRV_DMADRV_USE_NATIVE_API is defined. It is a wrapper around similar emlib ldma function, but adds support for completion callback and user defined callback function parameter.
DMADRV_StopTransfer()
Stop an ongoing DMA transfer.
DMADRV_TransferActive()
Check if a transfer is ongoing.
DMADRV_TransferCompletePending()
Check if a transfer completion is pending.
DMADRV_TransferDone()
Check if a transfer has completed.
DMADRV_TransferRemainingCount()
Get number of items remaining in a transfer.
Transfer a text string to USART1.
#include "dmadrv.h" char str[] = "Hello DMA !"; unsigned int channel; int main( void ) { // Initialize DMA. DMADRV_Init(); // Request a DMA channel. DMADRV_AllocateChannel( &channel, NULL ); // Start the DMA transfer. DMADRV_MemoryPeripheral( channel, dmadrvPeripheralSignal_USART1_TXBL, (void*)&(USART1->TXDATA), str, true, sizeof( str ), dmadrvDataSize1, NULL, NULL ); return 0; }