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

📄 main.c

📁 适用于TSM320C6000系列的EDMA实验原代码
💻 C
字号:
#include "inoutcfg.h"
#include <csl.h>
#include "regs.h"
#include "c6211dsk.h"
#include <c6x.h>
#include <csl_irq.h>
#include <csl_mcbsp.h>
#include <csl_timer.h>
#include <csl_edma.h>
#include <csl_cache.h>

void EdmaIsr (void);
void mcbsp0_init();
void mcbsp0_write(int out_data);
int mcbsp0_read();
extern int codec();
void clear_Buffers();
void initialise_EDMA();
void start_timer1();

#pragma DATA_SECTION(in_data, "mydata");
#pragma DATA_SECTION(cin_data, "mydata");
#pragma DATA_SECTION(disp_buffer, "mydata");
#pragma CODE_SECTION(EdmaIsr, "mycode"); 	/* Place the function in internal program memory */

#define FCPU     	150000000        		/* CPU clock frequency                  */
#define SRATE   	8000            		/* Data sample rate (simulated w/timer  */
#define TPRD     	(FCPU/(4*2*SRATE)) 		/* Timer period, clock mode           	*/
#define TCCINTNUM   10
#define BUFF_SZ 	2 

short in_data[(BUFF_SZ * 2)];  				/* First input buffer for data. EMDA writes input data here */
short cin_data[(BUFF_SZ * 2)]; 				/* Second input buffer (needed for "ping-pong" continuous DMA transfer) */
short disp_buffer[(BUFF_SZ * 2)];

int flag=0xdead;
short sw_buff;      						/* Flag for switching DMA ping-pong buffers */

/* Declare CSL objects */
TIMER_Handle hTimer;   /* Handle for the timer device                 */
EDMA_Handle hEdma;     /* Handle for the EDMA channel                 */
EDMA_Handle hEdmaPing; /* Handle for the ping EDMA reload parameters  */
EDMA_Handle hEdmaPong; /* Handle for the pong EDMA reload parameters  */
EDMA_Config cfgEdma;   /* EDMA configuration structure                */

/* Create the EDMA configuration structure for ping transfers */
EDMA_Config cfgEdmaPing = {  
  /*EDMA_OPT_RMK(
    EDMA_OPT_PRI_LOW,
    EDMA_OPT_ESIZE_32BIT,
    EDMA_OPT_2DS_NO,
    EDMA_OPT_SUM_NONE,
    EDMA_OPT_2DD_NO,
    EDMA_OPT_DUM_INC,
    EDMA_OPT_TCINT_YES,
    EDMA_OPT_TCC_OF(TCCINTNUM),
    EDMA_OPT_LINK_YES,
    EDMA_OPT_FS_NO
     
  )*/ 0x28720002,
  EDMA_SRC_OF(McBSP0_DRR),
  EDMA_CNT_OF(BUFF_SZ),
  EDMA_DST_OF((unsigned int)in_data),
  EDMA_IDX_OF(0x00000004),
  EDMA_RLD_OF(0x00000000)
};                         

/* Create the EDMA configuration structure for pong transfers */
EDMA_Config cfgEdmaPong = {
  /*EDMA_OPT_RMK(
    EDMA_OPT_PRI_LOW,
    EDMA_OPT_ESIZE_32BIT,
    EDMA_OPT_2DS_NO,
    EDMA_OPT_SUM_NONE,
    EDMA_OPT_2DD_NO,
    EDMA_OPT_DUM_INC,
    EDMA_OPT_TCINT_YES,
    EDMA_OPT_TCC_OF(TCCINTNUM),
    EDMA_OPT_LINK_YES,
    EDMA_OPT_FS_NO
  )*/0x28720002,
  EDMA_SRC_OF(McBSP0_DRR),
  EDMA_CNT_OF(BUFF_SZ),
  EDMA_DST_OF((unsigned int)cin_data),
  EDMA_IDX_OF(0x00000004),
  EDMA_RLD_OF(0x00000000)
};                         


void main(void)
{
	sw_buff=0; 					/* Initialise buffer switch flag: Select first input buffer */
 	clear_Buffers(); 
 
	initialise_EDMA();

 	mcbsp0_init();
 	codec();     				/* Initialise the codec */

 	start_timer1();
 	IRQ_globalEnable();			/* Enable the interrupts */
 	for (;;);        			/* Wait for an interrupt */
}


void clear_Buffers()
{
	int i;

	for(i=0;i<(BUFF_SZ * 2);i++)	/* Initialise input data buffers */
	{
		in_data[i]=0;
		cin_data[i]=0;
	}
	
	/* Disable output of Timer 1	*/
	*(unsigned volatile int *)TIMER1_CTRL = 0x000;
}


void initialise_EDMA()
{
	/*	Reset CPU Interrupts */

	IRQ_map(IRQ_EVT_EDMAINT,8);
 	
 	IRQ_configArgs(
 		IRQ_EVT_EDMAINT,
 		EdmaIsr,
 		0x00000000,
 		IRQ_CCMASK_DEFAULT,
 		IRQ_IEMASK_ALL
 	);
 
  	/* Although not required, let's clear all of the EDMA parameter RAM. */
  	/* This makes it easier to view the RAM and see the changes as we    */
  	/* configure it.                                                     */
  	EDMA_clearPram(0x00000000);
   
  	/* Let's open up a timer device, we'll use this to simulate input events */
  	/* at a given sample rate.                                               */
  	hTimer = TIMER_open(TIMER_DEV1, TIMER_OPEN_RESET);

  	/* Lets open up the EDMA channel associated with timer #1. */
  	hEdma = EDMA_open(EDMA_CHA_TINT1, EDMA_OPEN_RESET);

  	/* We also need two EDMA reload parameter sets so let's allocate them */
  	/* here. Notice the -1, this means allocate any available table.      */
  	hEdmaPing = EDMA_allocTable(-1);
  	hEdmaPong = EDMA_allocTable(-1);

  	/* Let's copy the ping reload configuration structure to an */
  	/* intermediate configuration structure.                    */
  	cfgEdma = cfgEdmaPing;
  
  	/* Let's initialize the link fields of the configuration structures */
  	cfgEdmaPing.rld = EDMA_RLD_RMK(0,hEdmaPong);
  	cfgEdmaPong.rld = EDMA_RLD_RMK(0,hEdmaPing);
  	cfgEdma.rld     = EDMA_RLD_RMK(0,hEdmaPong);

  	/* Now let's program up the EDMA channel with the configuration structure */
  	EDMA_config(hEdma, &cfgEdma);   
  
  	/* Let's also configure the reload parameter tables in the EDMA PRAM */
  	/* with the values in the configuration structures.                  */
  	EDMA_config(hEdmaPing, &cfgEdmaPing);
  	EDMA_config(hEdmaPong, &cfgEdmaPong);   

	/* Initialise Enhanced Dynamic Memory Access (EDMA) */
 	EDMA_RSET(ECR,0xffff);
 	EDMA_enableChannel(hEdma);
	flag = EDMA_getChannel(hEdma);
	EDMA_RSET(EER,4);   			/* 0x4 TINT1 is the event */
	EDMA_RSET(CIPR,0xffff);
	EDMA_RSET(CIER,0x4);
 
  	/* Setup the timer. */
  	TIMER_configArgs(hTimer, 
	    TIMER_CTL_OF(0x000003c1), 
    	TIMER_PRD_OF(TPRD), 
    	TIMER_CNT_OF(0)
  	);   

	/* Enable the related interrupts */
  	IRQ_enable(IRQ_EVT_EDMAINT); 
    IRQ_nmiEnable();
  
  	/* Enable the EDMA channel */
  	EDMA_enableChannel(hEdma);   
}


void mcbsp0_init()
{
	/* Set up McBSP0 */
	*(unsigned volatile int *)McBSP0_SPCR = 0;	/* Reset serial port */
  	*(unsigned volatile int *)McBSP0_PCR = 0;  	/* Set pin control reg */
   
   	/* Set rx control reg. one 16 bit data/frame */
   	*(unsigned volatile int *)McBSP0_RCR = 0x10040;
   
   	/* Set tx control reg. one 16 bit data/frame */
   	*(unsigned volatile int *)McBSP0_XCR = 0x10040;
   	
   	*(unsigned volatile int *)McBSP0_DXR = 0;
   
   	/* Setup SP control reg*/
   	*(unsigned volatile int *)McBSP0_SPCR = 0x12001;
}


void mcbsp0_write(int out_data)
{
  	int temp;

  	temp = *(unsigned volatile int *)McBSP0_SPCR & 0x20000;

  	while ( temp == 0)
  	{
  		temp = *(unsigned volatile int *)McBSP0_SPCR & 0x20000;
  	}

  	*(unsigned volatile int *)McBSP0_DXR = out_data;
}


int mcbsp0_read()
{
  	int temp;

  	temp = *(unsigned volatile int *)McBSP0_SPCR & 0x2;

  	while ( temp == 0)
  	{
    	temp = *(unsigned volatile int *)McBSP0_SPCR & 0x2;
  	}

  	temp = *(unsigned volatile int *)McBSP0_DRR;
  	return temp;
}


void start_timer1()
{
  	/* Enable the timer */
  	TIMER_start(hTimer);
}


void EdmaIsr (void)
{
  	int k;
 
  	/* Clear interrupt pending flags so that another EDMA transfer can be initiated and processed */

 	EDMA_RSET(ECR,0xffff);
	EDMA_RSET(CIPR,0xffff);
  
  	/* Select active edma buffer and copy data into auxiliary buffer */

  	if (sw_buff==0) /* Select buffer 1 and copy data to auxiliary buffer*/
    {
    	for(k=0;k<BUFF_SZ;k++)
      	{
      		disp_buffer[2*k]=in_data[2*k];
      		disp_buffer[2*k+1]=0;
      	}
      	sw_buff=1; /* Switch buffer */
    }
  	else /* Select buffer 2 and copy data to auxiliary buffer */
    {
    	for(k=0;k<BUFF_SZ;k++)
      	{
      		disp_buffer[2*k]=cin_data[2*k];
      		disp_buffer[2*k+1]=0;
      	}
      	sw_buff=0; /* Switch buffer */
    }

  	/* Process data in buffer */     
 

 	for(k=0;k<(BUFF_SZ);k++) /* Send all output data one by one */
  	{  
 		mcbsp0_write(disp_buffer[2*k]& 0xfffffffe);
    }

   	return;
}

⌨️ 快捷键说明

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