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

📄 firlab.c

📁 适用与c5402的DSP编程
💻 C
字号:
/*****************************************************************************/
/* firlab.c																 */
/* 																		     */
/* Digital Fir Filter example										 */
/*																			 */
/*****************************************************************************/

#include <type.h>
#include <board.h>
#include <codec.h>
#include <mcbsp54.h>

#include <tms320.h>
#include <dsplib.h>

/*****************************************************************************/
/* Function Prototypes														 */
/*****************************************************************************/

/* This delay routine does not conflict with DSP/BIOS.  It is used in this  */
/* example rather than brd_delay_msec which causes DSP/BIOS conflicts just  */
/* because of this.  If you are not using DSP/BIOS, you can change the code */
/* to use brd_delay_msec.                                                   */

void delay(s16 period);


/*****************************************************************************/
/* Global Variables                                                          */
/*****************************************************************************/

HANDLE hHandset;
s16 data;

/* Create specific data section for coeffiecients */
#pragma DATA_SECTION(coeffs,"coefficients");
/* Low  Pass Filter */ 
short coeffs[16]={
      157,    708,    150,      0,      0,    753,   6537,  11505,  11505,
     6537,    753,      0,      0,    150,    708,    157
};
/* High Pass Filter */ 
/* int coeffs[16]={-120,5245,-3421,2451,-11216,40,-24657,29610,29610,-24657,40,-11216,2451,-3421,5245,-120};  */
/* Band Pass Filter */ 
/* int coeffs[16]={921,-2494,137,-3654,-2485,-2063,-9015,16165,16165,-9015,-2063,-2485,-3654,137,-2494,921};  */
/* Band Stop Filter */
/* int coeffs[16]={491,165,-2159,772,-6697,10044,648,12297,12297,648,10044,-6697,772,-2159,165,491}; */ 
/* All  Pass Filter */
/* int coeffs[16] ={32767,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};  */

/* Create specific data section for delay buffer  */
#pragma DATA_SECTION(delaybuff,"delay");
short delaybuff[16]={0};

/* delayptr holds the address of the start of the delay buffer */
     
short *delayptr = &(delaybuff[0]); 

short inp_buffer[1];
short out_buffer[1];

short *inp_ptr=inp_buffer;
short *out_ptr=out_buffer;


/*****************************************************************************/
/* main																		 */
/*****************************************************************************/

void main()
{
    s16 cnt=2;

    if (brd_init(100))
        return;

	/* blink the leds a couple times */
	while ( cnt-- )
	{
		brd_led_toggle(BRD_LED0);
		/* brd_delay_msec(1000); */
		delay(1000);
		brd_led_toggle(BRD_LED1);
		/* brd_delay_msec(1000); */
		delay(1000);
		brd_led_toggle(BRD_LED2);
		/* brd_delay_msec(1000); */
		delay(1000);
	}


    /* Open Handset Codec */
    hHandset = codec_open(HANDSET_CODEC);               /* Acquire handle to codec */

    /* Set codec parameters */
    codec_dac_mode(hHandset, CODEC_DAC_15BIT);          /* DAC in 15-bit mode */
    codec_adc_mode(hHandset, CODEC_ADC_15BIT);          /* ADC in 15-bit mode */
    codec_ain_gain(hHandset, CODEC_AIN_6dB);            /* 6dB gain on analog input to ADC */
    codec_aout_gain(hHandset, CODEC_AOUT_MINUS_6dB);    /* -6dB gain on analog output from DAC */
    codec_sample_rate(hHandset,SR_16000);               /* 16KHz sampling rate */


    /* Polling and digital loopback */
    while (1)
    {
       /* Wait for sample from handset */
       while (!MCBSP_RRDY(HANDSET_CODEC)) {};

       /* Read sample from and write back to handset codec */
       inp_buffer[0] = *(volatile u16*)DRR1_ADDR(HANDSET_CODEC);
       
 		/*数据处理开始*/
 		
 		//fir计算
 		fir(inp_ptr,coeffs,out_ptr,&delayptr,16,1);
 		
 		data=out_buffer[0]&0xfffe;
 		
		/*数据处理结束*/

	
       *(volatile u16*)DXR1_ADDR(HANDSET_CODEC) =data ;
    }

}


void delay(s16 period)
{
    int i, j;
    
    for(i=0; i<period; i++)
    {
        for(j=0; j<period>>1; j++);
    }
}

⌨️ 快捷键说明

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