⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 此dma 也是SBC开发板的
💻 C
字号:
//LED GPIO#define GPBCON	(*(volatile unsigned long *)0x56000010)#define GPBDAT	(*(volatile unsigned long *)0x56000014)#define GPBUP	(*(volatile unsigned long *)0x56000018)// Set Uart#define UART_CTL_BASE	0x50000000#define	reg(i)	(*(volatile unsigned long *)(UART_CTL_BASE + i))#define	Utrstat0	reg(0x10)#define Utxh0	reg(0x20)#define start_send_addr1 (*(char *)0x0)#define start_send_addr2 (*(char *)0x31000000)//DMA register#define DISRC0	(*(volatile unsigned long *)0x4b000000)// source address register#define DISRCC0	(*(volatile unsigned long *)0x4b000004)// source control register#define DIDST0	(*(volatile unsigned long *)0x4b000008)// destination address reg#define DIDSTC0	(*(volatile unsigned long *)0x4b00000c)// destination control reg#define DCON0	(*(volatile unsigned long *)0x4b000010)// control register#define DSTAT0	(*(volatile unsigned long *)0x4b000014)// staut register#define DCSRC0	(*(volatile unsigned long *)0x4b000018)// current source addr reg#define DCDST0	(*(volatile unsigned long *)0x4b00001c)// current destin addr reg#define DMASKTRIG0 (*(volatile unsigned long *)0x4b000020)// trriger mask register//data argument#define DMA_SRC	0x30000100	//source address#define DMA_DST	0x31000000	//destination address#define DMA_SIZE 1024		//bytes void InitLed(){	GPBCON = (GPBCON & ~0x3fc000) | 0x154000;	GPBUP &= ~0x780;}void LedPlay(int iLedVal){	GPBDAT=(GPBDAT | 0x780) &( ~(( iLedVal & 0x78) << 4));}void Delay(int msec){	int iDelay = msec * 2048;	while(iDelay)		iDelay--;}void send(char* start_address, int len){		int i = 0;		for(i = 0; i < len; i++ )	{		while(!(Utrstat0 & 0x4));		Utxh0 = *(start_address + i);	}}void StartDma(){	DISRC0 = DMA_SRC;	DISRCC0 = (0<<1)|(0<<0);	DIDST0 = DMA_DST;	DIDSTC0 = (0<<1)|(0<<0);	DCON0 = (1<<31)|(1<<30)|(1<<28)|(1<<27)|(1<<22)|(2<<20)|(DMA_SIZE/16);	DMASKTRIG0 = (1<<1)|1;		//open chanel sent out applice software}int IsDmaEnd(){	return ((DSTAT0 & 0xfffff) == 0);}int Main(){	int i, j = 0;	volatile int *piSrc = (int *)DMA_SRC;	volatile int *piDst = (int *)DMA_DST;	InitLed();	StartDma();	while(!IsDmaEnd());	for(i = 0;i < DMA_SIZE/4;i++)		if(*piSrc++ != *piDst++)			break;	LedPlay(0x18);	Delay(100);	if(i<DMA_SIZE/4)			LedPlay(0x38);	//three led bright failed	else	{			LedPlay(0x48);			//two led bright success		send(start_send_addr1, 27);		// uart send 		send(start_send_addr2, 27);		// uart send 	}//	send(start_send_address, 400);		// uart send  	//  light led 	while(1)	{		LedPlay(j);		j++;		Delay(10);	}	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -