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

📄 appmain.c

📁 一个ccs开发环境下的滤波器程序
💻 C
字号:
/*
 * 		DSK C5402 FIR FILTER 
 */

/*
 *  ======== appMain.c ========
 */

/* Preprocessor includes, definitions */
#include <std.h>
#include <csl.h>
#include <csl_irq.h>

#include "appMain.h"
#include "dsk5402_dma_ad50.h"

// #include <dsplib.h>

//******* DMA BUFFERS  *****************************************	

#define	DIM_BUFFER	128							  // max 511 
#pragma DATA_SECTION(inBuffer,  "audio_buffer1"); // Circular addressing: those sections must be aligned in memory
#pragma DATA_SECTION(outBuffer, "audio_buffer2"); // See linker command file

int		inBuffer[DIM_BUFFER];
int		outBuffer[DIM_BUFFER];

//******* FIR COEFF.   *****************************************

// we have 5 different types of 16 taps FIR filters, one for each raw of the matrix below;
// The FIR routine of DSPLIB makes use of circular addressing for the filter coefficents, so 
// the start address in memory of each raw of the matrix must be multiple of 32, for a 16 taps filter.
// This is why each raw has been padded with 16 dummy zeros.
// The section coefficients in then "32 words" aligned in memory by the Linker Command File.

#define MAX_FILTER_TYPE	5
unsigned int 	filterType = 0;

#pragma DATA_SECTION(coeffs,"coefficients");	// Circular addressing: this section must be aligned
int 	coeffs[MAX_FILTER_TYPE][32]={
	/* All  Pass Filter */
	{32767,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	/* Low  Pass Filter */ 
	{-1299,-994,-182,1067,2567,4055,5249,5914,5914,5249,4055,2567,1067,-182,-994,-1299, 
		0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	/* High Pass Filter */ 
	{-120,5245,-3421,2451,-11216,40,-24657,29610,29610,-24657,40,-11216,2451,-3421,5245,-120,
		0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	/* Band Pass Filter */ 
	{921,-2494,137,-3654,-2485,-2063,-9015,16165,16165,-9015,-2063,-2485,-3654,137,-2494,921, 
		0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	/* Band Stop Filter */
	{491,165,-2159,772,-6697,10044,648,12297,12297,648,10044,-6697,772,-2159,165,491,
		0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
	 }; 

//******* FIR DELAY LINE  *****************************************	

#pragma DATA_SECTION(delaybuff,"delay");		// Circular addressing: this section must be aligned
int 	delaybuff[16]={0}; 						// See linker command file
int 	*delayptr1 = &(delaybuff[0]); 


/*
 *  ======== main ========
 */

Void main()
{	
	static ioport unsigned int port0000;		//  LEDS I/O Port
	static int led = 1;
	
	CSL_init();

    clear_buffer(inBuffer, DIM_BUFFER);
    clear_buffer(outBuffer, DIM_BUFFER);

    /* Initialize and setup the driver with default parameters */
    DSK5402_DMA_AD50_setup(NULL);       
    
    // Start DMA 
	startDma((Ptr) inBuffer, (Ptr) outBuffer,  DIM_BUFFER);
    
	// Setup Interrupt
    myIRQ_setVecs ((unsigned int) RESET);		
    IRQ_clear(IRQ_EVT_DMAC4);
    IRQ_enable(IRQ_EVT_DMAC4);
    IRQ_globalEnable(); 	
    
    /* Fall into idle loop and blink the leds */
	
	while(1){
		delay(1000);
		port0000 &=0xFFF8;
		port0000 |= led;
		led <<=1 ;	
		led = (led == 16 ? 1 : led);
	}
    	                 
}


/*
 *  ======== audioProcess ========
 */
void audioProcess(int type, int *inp, int *out, int dim)
{
	int i;		
				
	filterType = getDipSwStatus();				/* Comment this line if you want to enable the filter */
										        /* by changing the value of the filterType  variable */

	filterType = (filterType >= MAX_FILTER_TYPE ? 0 : filterType);

	fir(inp, &coeffs[filterType][0], out, &delayptr1, 16, dim); 	
	
 	// Mask the LSB for the D/A converter (we use the default 15 bit configuration)
 	for (i = 0; i < dim; i++) 
        out[i] = out[i] & 0xfffe;
 	
} /* end of audioProcess() */


/*
 *  ======== C54XX_DMA_MCBSP_isr ========
 */
interrupt Void DmaCh4Isr()
{
	static int buffer = PING;
	
	if (buffer == PING) 		
		audioProcess(0, inBuffer, outBuffer, DIM_BUFFER/2);
	else 
		audioProcess(1, &inBuffer[DIM_BUFFER/2],  &outBuffer[DIM_BUFFER/2], DIM_BUFFER/2);
	
	buffer = (buffer == PING? PONG: PING);				
		 
}


// Interrupt Setup

void myIRQ_setVecs (unsigned int baseAddr)
{
	unsigned int *PMST = (unsigned int*)0x1D;
	unsigned int *IMR  = (unsigned int*)0;
	unsigned int *IFR  = (unsigned int*)1;

	// Set Interrupt Vectors Base Adress
	baseAddr &= 0xFF80;
	*PMST &= 0x007F;
	*PMST |= baseAddr;
	
	// Disable all interrupts
	*IMR = 0;
	*IFR = 0xFFFF;
}

int getDipSwStatus(void)
{
	static ioport unsigned int port0001;		//  DIP SWITCH I/O Port
	
	return( (port0001 & 0x60) >> 5);				// Dip Switch 7,8 Status
	
}


void clear_buffer(int *Buf, int n)
{ 
	int i;
	for (i=0;i<n;i++)
		*Buf++ = 0;
}		
				

void delay(int cnt)
{
	long i;
	
	for(i=0;i<cnt*100;i++);
}

⌨️ 快捷键说明

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