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

📄 appmain.c

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

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

/* Preprocessor includes, definitions */

#include "dsk5402_filtercfg.h"

#include <csl.h>
#include <csl_irq.h>

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

// #include <dsplib.h>


//******* DMA BUFFERS ABU MODE *****************************************								

#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}
	 }; 

char	*str[5] = {"All pass", "Low pass", "High pass", "Band Pass", "Band stop"};

//******* 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()
{
        
    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
    IRQ_clear(IRQ_EVT_DMAC4);
    IRQ_enable(IRQ_EVT_DMAC4);
    
	
	LOG_printf(&trace, "*** DSKC5402 FIR started ***");
	LOG_printf(&trace, "Use the Dip Switch 7-8 to change the filter type\n");
	                                    
    // Fall into DSP/BIOS Idle loop              

}



/*
 *  ======== C54XX_DMA_MCBSP_isr ========
 */
Void DmaCh4Isr()
{
	SWI_post(&audio);	// Post Audio SWI for the audio processing
}

/*
 *  ======== audioProcess ========
 */
Void audioProcess(Void)
{

	static int buffer = PING;
	
	if (buffer == PING) 		
		firProcess(0, inBuffer, outBuffer, DIM_BUFFER/2);
	else 
		firProcess(1, &inBuffer[DIM_BUFFER/2],  &outBuffer[DIM_BUFFER/2], DIM_BUFFER/2);
	
	buffer = (buffer == PING? PONG: PING);				
		 
}

/*
 *  ======== firProcess ========
 */

Void firProcess(int type, int *inp, int *out, int dim)
{
	int i;		
	static int oldFilterType = 99;
					
	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);
	
	if (filterType != oldFilterType)
		LOG_printf(&trace, "filter type is %s ", str[filterType]);
	oldFilterType= filterType; 

	// FIR filter from the C54x DSP library
    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;
 	
} 


/*
 *  ======== Blink ========
 */

Void Blink(Void)				// Periodic function that blinks the leds
{
	static ioport unsigned int port0000;		//  LEDS I/O Port
	static int led = 4;
	
	port0000 &=0xFFF8;
	port0000 |= (led | filterType) ;
	
	led = (led == 4 ? 0 : 4);
		
}

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


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

⌨️ 快捷键说明

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