📄 dma.c
字号:
/*************************************************************************/
/* */
/* FILE NAME VERSION */
/* */
/* DMA.c KS32C5000, KS32C50100 : version 1.0 */
/* */
/* COMPONENT */
/* */
/* */
/* */
/* DESCRIPTION */
/* */
/* */
/* AUTHOR */
/* */
/* Young Sun KIM, Samsung Electronics, Inc. */
/* */
/* DATA STRUCTURES */
/* */
/* */
/* FUNCTIONS */
/* */
/* Evalution code for DMA control block */
/* */
/* DEPENDENCIES */
/* */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* in4maker 12-18-1998 timer function updated */
/*************************************************************************/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include "snds.h"
#include "dma.h"
#include "isr.h"
#include "std.h"
#include "uart.h"
#include "timer.h"
#include "down.h"
#include "memory.h"
#include "pollio.h"
#include "sysconf.h"
/* global variable */
volatile U32 Gdma0DoneFlag = 0 ; // GDMA Transfer done interrupt flag
volatile U32 Gdma1DoneFlag = 0 ; // GDMA Transfer done interrupt flag
GDMA_REG rGDMA = {
0, // Control register(CON)
0, // Source address register(SRC)
0, // Destination address register(DST)
0, // Counter register(CNT)
0 // Flag to control dialog (DIALOG)
}; //Define GDMA register's structure
/*******************************************************************
* GDMA TEST TOP MEMU SELECT FUNCTION
*******************************************************************/
void GdmaTest(void)
{
void PrintDmaItems(void);
char items;
IOPDATA= ~0x8; //in GDMA test mode
SysSetInterrupt(nGDMA0_INT, GDMA0isr);
SysSetInterrupt(nGDMA1_INT, GDMA1isr);
SysSetInterrupt(nTIMER0_INT, tm0isr);
do {
PrintDmaItems(); // Main memu for cache test
do {
Print("\rSelect Number?_");
items = get_byte();
}while(is_space(items));
if(is_xdigit(to_upper(items))) {
switch(to_upper(items)) {
case '1': GDMAStartUpDialog(); break;
case '2': GDMAConfigView(); break;
case '3': GdmaMem2MemTest(); break;
case '4': Uart2MemoryTest(SERIAL_DEV0); break;
case '5': Memory2UartTest(SERIAL_DEV0); break;
case '6': Uart2MemoryTest(SERIAL_DEV1); break;
case '7': Memory2UartTest(SERIAL_DEV1); break;
case '8': GdmaRegTest(); break;
case '9': DataDownLoad(); break;
case 'A': ExtGdmaReqTest(); break;
default : break;
}
}
Print("\rPress any key to continue.\r");
while(!is_space(get_byte()));
} while((items!='q')&&(items!='Q'));
}
/*
* Display GDMA test items
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
void PrintDmaItems(void)
{
Print("\n\n");
Print("+---------------------------------------------------+\r") ;
Print("| KS32C5000 GDMA TEST ITEMS |\r") ;
Print("+---------------------------------------------------+\r") ;
Print("| 1. GDMA start up dialog for setup DMA mode. |\r") ;
Print("| 2. GDMA configurations viewer. |\r") ;
Print("| 3. GDMA Memory to Memory test. |\r") ;
Print("| 4. GDMA Uart0 to Memory transfer test. |\r") ;
Print("| 5. GDMA Memory to Uart0 transfer test. |\r") ;
Print("| 6. GDMA Uart1 to Memory transfer test. |\r") ;
Print("| 7. GDMA Memory to Uart1 transfer test. |\r") ;
Print("| 8. GDMA Register Read/Write test. |\r") ;
Print("| 9. UART0 to Memory data transfer through GDMA0. |\r") ;
Print("| A. External GDMA Request Test. |\r") ;
Print("| Q. QUIT - Return to main menu. |\r") ;
Print("+---------------------------------------------------+\r") ;
}
/******************************************************************/
/* GDMA STARTUP DIALOG */
/******************************************************************/
void GDMAStartUpDialog(void)
{
char c;
int i;
/* Initialize GDMA global registers */
rGDMA.CON = 0;
rGDMA.SRC = 0;
rGDMA.DST = 0;
rGDMA.CNT = 0;
rGDMA.DIALOG =1;
/* STARTUP DIALOG FOR UART CONFIGURATION */
Print("\r\r>>> STARTUP DIALOG FOR GDMA CONFIGURATION <<<\r\r");
do {
Print(" > MODE SELECTION MENU <\r");
Print(" --------------------------\r");
Print(" 0. SoftWare.\r");
Print(" 1. External EXTDREQ.\r");
Print(" 2. UART0.\r");
Print(" 3. UART1.\r");
Print(" --------------------------\r");
Print("$ Select Number.> ");
i = get_number();
get_byte(); //dummy for carrige return
} while(i > 3);
switch(i) {
case 1: rGDMA.CON |= GDMA_EXTDREQ; break;
case 2: rGDMA.CON |= GDMA_U0MODE; break;
case 3: rGDMA.CON |= GDMA_U1MODE; break;
default: rGDMA.CON |= GDMA_MEM2MEM;
}
/*
* Address Direction menu
*/
Print("\r\r>>>Abstract for Select Menu.\r\r");
Print("------------------------------------------\r");
Print("-Source Address : SrcAddr, \r");
Print("-Destination Address : DstAddr, \r");
Print("-Address Increase : ++SrcAddr,++DstAddr, \r");
Print("-Address Decrease : --SrcAddr,--DstAddr, \r");
Print("------------------------------------------\r");
/* Destination address direction */
do {
Print("\r$ --DstAddr[1],++DstAddr[0]?_");
c = get_byte();
} while(c!='1' && c!='0');
if(c == '1') rGDMA.CON |= GDMA_DST_DEC;
/* Source address direction */
do {
Print("\r$ --SrcAddr[1],++SrcAddr[0]?_");
c = get_byte();
} while(c!='1' && c!='0');
if(c == '1') rGDMA.CON |= GDMA_SRC_DEC;
/* Stop interrupt enable */
do {
Print("\r$ Enable stop interrupt[1/0]?_");
c = get_byte();
} while(c!='1' && c!='0');
if(c == '1') rGDMA.CON |= GDMA_INT_ENABLE;
/* Transfer direction */
if((rGDMA.CON&GDMA_U0MODE)||(rGDMA.CON&GDMA_U1MODE)) {
do {
Print("\r> Transfer Direction(UART0/UART1 only)");
Print("\r$ Memory to UART.[1], UART to memory[0]?_");
c = get_byte();
} while(c!='1' && c!='0');
if(c == '1') {
rGDMA.CON |= GDMA_MEM2UART;
rGDMA.CON |= GDMA_DST_FIX;
Print("\r$ Destination Addr Fixed.");
}
else {
rGDMA.CON |= GDMA_SRC_FIX;
Print("\r$ Source Addr Fixed.");
}
}
/* Transfer width */
do {
Print("\r\r> TRANSFER WIDTH MENU <\r");
Print(" -----------------------\r");
Print(" 0. Byte(8bit).\r");
Print(" 1. Halfword(16bit).\r");
Print(" 2. Word(32bit).\r");
Print(" 3. No use.\r");
Print(" -----------------------\r");
Print("$ Select Number.> ");
i = get_number();
get_byte(); //dummy for carrige return
} while(i > 3);
switch(i) {
case 0: rGDMA.CON |= GDMA_TX_BYTE; break;
case 1: rGDMA.CON |= GDMA_TX_HALFWORD; break;
case 2: rGDMA.CON |= GDMA_TX_WORD; break;
default: rGDMA.CON |= GDMA_NO_USE;
}
/* GDMA Operation mode */
do {
Print("\r$ Block mode[1] or Single mode[0]?_");
c = get_byte();
} while(c!='1' && c!='0');
if(c == '1') rGDMA.CON |= GDMA_BLOCK;
do {
Print("\r$ Continuous mode[1]?_");
c = get_byte();
} while(c!='1' && c!='0');
if(c == '1') {
if((rGDMA.CON & GDMA_MEM2MEM)||(rGDMA.CON & ~GDMA_BLOCK)){
Print("\rCautious!.Continuous mode should not");
Print(" be used with single mode.");
Print("\rCautious!.This mode can be used with");
Print(" software request mode.");
}
else
rGDMA.CON |= GDMA_CONTINUOUS;
}
do {
Print("\r$ Demand mode[1]?_");
c = get_byte();
} while(c!='1' && c!='0');
if(c == '1') {
if((rGDMA.CON & GDMA_BLOCK)||(rGDMA.CON & GDMA_CONTINUOUS))
Print("\rCautious!. Block & Continuous mode must be zero.");
else
rGDMA.CON |= GDMA_DEMAND;
}
/* Setup GDMA Source/Destination address register & */
/* GDMA Transfer counter register */
switch(rGDMA.CON & GDMA_MODE){
//case GDMA_EXTDREQ: SetUpExtDreq(); break;
case GDMA_U0MODE: GdmaUart0Mem(); break;
case GDMA_U1MODE: GdmaUart1Mem(); break;
default: GdmaMem2MemTest();
}
}
void GDMARegRead(unsigned gdma_channel)
{
if(gdma_channel) {
rGDMA.CON= GDMACON1;
rGDMA.SRC= GDMASRC1;
rGDMA.DST= GDMADST1;
rGDMA.CNT= GDMACNT1;
}
else {
rGDMA.CON= GDMACON0;
rGDMA.SRC= GDMASRC0;
rGDMA.DST= GDMADST0;
rGDMA.CNT= GDMACNT0;
}
}
void GDMARegWrite(unsigned gdma_channel)
{
if(gdma_channel) {
GDMASRC1 = rGDMA.SRC;
GDMADST1 = rGDMA.DST;
GDMACNT1 = rGDMA.CNT;
GDMACON1 = rGDMA.CON;
}
else {
GDMASRC0 = rGDMA.SRC;
GDMADST0 = rGDMA.DST;
GDMACNT0 = rGDMA.CNT;
GDMACON0 = rGDMA.CON;
}
}
void GDMARegPrint(unsigned gdma_channel)
{
if(gdma_channel) {
Print("\r$GDMACON1[0x%08x] = 0x%08x", &GDMACON1,GDMACON1);
Print("\r$GDMASRC1[0x%08x] = 0x%08x", &GDMASRC1,GDMASRC1);
Print("\r$GDMADST1[0x%08x] = 0x%08x", &GDMADST1,GDMADST1);
Print("\r$GDMACNT1[0x%08x] = 0x%08x", &GDMACNT1,GDMACNT1);
}
else {
Print("\r$GDMACON0[0x%08x] = 0x%08x", &GDMACON0,GDMACON0);
Print("\r$GDMASRC0[0x%08x] = 0x%08x", &GDMASRC0,GDMASRC0);
Print("\r$GDMADST0[0x%08x] = 0x%08x", &GDMADST0,GDMADST0);
Print("\r$GDMACNT0[0x%08x] = 0x%08x\r\r", &GDMACNT0,GDMACNT0);
}
}
unsigned GetGdmaChannel(void)
{
char channel;
/* Get GDMA Channel */
do {
Print("\rSelect GDMA Channel[0/1]?_");
channel = get_byte();
}while(is_space(channel) && (channel != '1') && (channel != '0'));
if(channel == '1') return(1);
else return(0);
}
/******************************************************************/
/* GDMA0, GDMA1 MODULE TEST FUCNTION */
/******************************************************************/
/*
* GDMA Memory to Memory test Module
*/
void GdmaMem2MemTest(void)
{
int j;
int repeat;
int gdma_channel;
/* Get GDMA Channel */
gdma_channel = GetGdmaChannel();
/*GDMA memory to memory setup */
SetUpmem2mem();
Print("\r>>Input Memory Test repeat times[0x5]> 0x") ;
repeat = get_num();
if (repeat==0) repeat=(unsigned int)DmaTestLoop;
Print("\r\r - Selected GDMA channel : GDMA%d",gdma_channel);
Print("\r - GDMA%d source address : 0x%08x",gdma_channel,rGDMA.SRC);
Print("\r - GDMA%d destination address : 0x%08x",gdma_channel,rGDMA.DST);
Print("\r - GDMA%d memory test size : 0x%08x",gdma_channel,rGDMA.CNT);
Print("\r - GDMA%d Mem test repeat times: 0x%08x\r\r",gdma_channel,repeat);
for(j=0;j<(repeat*3);j++) {
GdmaTxWidth(j%3); //Transfer width will be changed to 8,16,32bit
GdmaMem2MemTestSub(gdma_channel);
Print("\r>>%dth's transfer is done!\r\r",j+1);
}
}
int GdmaMem2MemTestSub(unsigned gdma_channel)
{
/* Enable Interrupt */
GdmaIntEnable(gdma_channel);
/*Initialize source memory with random pattern */
MemTestInit((U32 *)rGDMA.SRC, (int)rGDMA.CNT);
/* GDMA MODE SET for memory word test*/
if(!rGDMA.DIALOG) {
GdmaMem2Mem(gdma_channel); //default set for mem to mem test
}
else {
GdmaReset(gdma_channel); // GDMA related register all clear to reset state
GDMARegWrite(gdma_channel);
GdmaRunEnable(gdma_channel);
rGDMA.DIALOG = 0; //Off diaglog
}
tmReset(TIMER_DEV1);
tm_init(TIMER_DEV1,(ONE_SECOND/TICKS_PER_SECOND));
TimerStart(TIMER_DEV1);
put_byte('\r');
if(gdma_channel)
while(!Gdma1DoneFlag) DisplayGdma(gdma_channel);
else
while(!Gdma0DoneFlag) DisplayGdma(gdma_channel);
Timer1Stop();
put_byte('\r');
PrtSysTime(TIMER_DEV1,"GDMA Transfer time"); tmReset(TIMER_DEV1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -