本程序是通过向一个二维数组有DMA传输来完成的,从而熟悉一下DMA.
首先加入DMA模块,然后通过ASF EXPLORER找到文档。根据例程的提示形成文件:
这个程序可以看出,只是用了二维数组的前二组,就是第一组向第二组传数据,其中第一组是源,第二组是目地。
通过截图可以观察到,数据已经传输成功。
程序如下:
#include <asf.h>
#define DMA_CH 0
#define DMA_BUF_SIZE 32
uint32_t g_dma_buf[6][DMA_BUF_SIZE];
int main (void)
{
/* Insert system clock initialization code here (sysclk_init()). */
board_init();
pmc_enable_periph_clk(ID_DMAC);
uint32_t i;
uint32_t cfg;
dma_transfer_descriptor_t desc;
for (i = 0; i < DMA_BUF_SIZE; i++) {
g_dma_buf[0][i] = i;
g_dma_buf[1][i] = 0;
}
dmac_init(DMAC);
dmac_set_priority_mode(DMAC, DMAC_PRIORITY_ROUND_ROBIN);
dmac_enable(DMAC);
cfg = DMAC_CFG_SOD_ENABLE |
DMAC_CFG_AHB_PROT(1) |
DMAC_CFG_FIFOCFG_ALAP_CFG;
dmac_channel_set_configuration(DMAC, DMA_CH, cfg);
desc.ul_source_addr = (uint32_t) g_dma_buf[0];
desc.ul_destination_addr = (uint32_t) g_dma_buf[1];
desc.ul_ctrlA = DMAC_CTRLA_BTSIZE(DMA_BUF_SIZE) |
DMAC_CTRLA_SRC_WIDTH_WORD |
DMAC_CTRLA_DST_WIDTH_WORD;
desc.ul_ctrlB = DMAC_CTRLB_SRC_DSCR_FETCH_DISABLE |
DMAC_CTRLB_DST_DSCR_FETCH_DISABLE |
DMAC_CTRLB_FC_MEM2MEM_DMA_FC |
DMAC_CTRLB_SRC_INCR_INCREMENTING |
DMAC_CTRLB_DST_INCR_INCREMENTING;
desc.ul_descriptor_addr = 0;
dmac_channel_single_buf_transfer_init(DMAC, DMA_CH, &desc);
dmac_channel_enable(DMAC, DMA_CH);
while (!dmac_channel_is_transfer_done(DMAC, DMA_CH)) {
}
/* Insert application code here, after the board has been initialized. */
}
|