DMA編程--DMAC
1. 通道數-- s3c6410有四個DMAC控制器,每個控制器有8個通道,
每個DMA Controller又提供16 個外設DMA Request Lines,能讓16個外設進行DMA請求.
2.請求源--source
系統中支持64個 DMA Sources,每個DMA Controller支持16個DMA Sources,
讓這16個DMA Sources進行DMA Request,但由於只有8個DMA Transfer Channel,
所以只能同時有8個DMA Sources進行DMA Transfer。
3.工作模式--Demand/Handshake
/*
The DMA controller supports four types of transfer:
memory-to-peripheral
peripheral-to-memory
memory-to-memory
peripheral-to-peripheral.
Each transfer type can have either
*/
4.編程步驟:
4.1--Decide whether use secure DMAC(SDMAC) or general DMAC(DMAC). In order to use general DMAC,
disable secure DMA control register(SDMA_SEL) of system controller. (Reset value is SDMAC).
4.2--Select a free DMA channel with the priority needed. Where DMA channel 0 has the highest priority and DMA
channel 7 the lowest priority.
4.3--Clear any pending interrupts on the channel to be used by writing to the DMACIntTCClr and DMACIntErrClr
registers. The previous channel operation might have left interrupts active.
4.4--Write the source address into the DMACCxSrcAddr register.
4.5--Write the destination address into the DMACCxDestAddr register.
4.6--Write the address of the next LLI into the DMACCxLLI register.
If the transfer comprises of a single packet of data then must be written into this register.
Offset Contents
Next LLI address Source Address for next transfer
Next LLI address + 0x04 Destination Address for next transfer
Next LLI address + 0x08 Next LLI address for next transfer
Next LLI address + 0x0C DMACCxControl0 data for next transfer
Next LLI address + 0x10 DMACCxControl1 data for next transfer
4.7--Write the control information into the DMACCxControl register.
4.8--Write the channel configuration information into the DMACCxConfiguration register.
If the Enable bit is set then the DMA channel is automatically enabled.
//串口dma-->DMA0 0 DMA_UART0[0] UART0 DMA source 0--DMA0/通道0
#define SDMA_SEL *((volatile unsigned long*)0x7E00F110)
#define DMACC0Control0 *((volatile unsigned long*)0x7500010c)
#define DMACC0Control1 *((volatile unsigned long *)0x7DB00110)
#define DMACConfiguration *((volatile unsigned long *)0x7DB00030)
#define DMACC0Configuration *((volatile unsigned long*)0x75000114)
#define DMACC0LLI *((volatile unsigned long*)0x75000108)
#define DMACC0SrcAddr *((volatile unsigned long*)0x75000100)
#define DMACC0DestAddr *((volatile unsigned long*)0x75000104)
#define UTXH0 (volatile unsigned long *)0x7F005020
char src[100] = "\n\rHello World->";
void dma_init()
{
//DMA控制器的選擇(SDMAC0)
SDMA_SEL = 0;
/* 如果外設的工作時鐘與DMA控制器的時鐘不相同, 要使能"同步邏輯" */
DMACSync = 0;
//DMA控制器使能
DMACConfiguration = 1;
//初始化源地址
DMACC0SrcAddr = (unsigned int)src;
//初始化目的地址
DMACC0DestAddr = (unsigned int)UTXH0;
//對控制寄存器進行配置
/*
源地址自增
目的地址固定、
目標主機選擇AHB主機2
源主機選擇AHB主機1
*/
DMACC0Control0 =(1<<25) | (1 << 26)| (1<<31);
DMACC0Control1 = 0x64; //傳輸的大小
//DMACC0Control0 |= (0x3<<12)|(0x3<<15)|(0x2<<18)|(0x2<<21)|(0x0<<24)|(0x7<<25);
//開啓channel0 DMA
/*
流控制和傳輸類型:Memory to peripheral 爲 001
目標外設:DMA_UART0_1,源外設:DMA_MEM
*/
DMACC0Configuration = (1<<6) | (1<<11) | (1<<14) | (1<<15);
DMACC0Configuration = 1; /*1 -->channel enabled.*/
}