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

📄 firlab.c

📁 信号fm调制与解调的dsp实现
💻 C
字号:
/*****************************************************************************/
/* FIRlab.C  AIC,McBSP,DMA initialization for FIR lab Filter                 */ 
/*                                                                           */
/* Goal:  This code performs the following functions:                        */
/*			- toggle the three LEDs on the DSK								 */
/*			- setup AIC (CODEC) parameters									 */
/*  		- initialize DMA Channel (CH2-input)			                 */
/*			- turn on interrupts											 */
/*			- run forever (waiting for DMA interrupts to transfer data)		 */
/*																			 */
/* Author: Scott Bland     Date: 03/20/2000									 */
/*****************************************************************************/
   
/*****************************************************************************/
/* Include Files                                                             */
/*****************************************************************************/

#include <type.h>
#include <board.h>
#include <codec.h>
#include <firlab.h>
#include <string.h>

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

void delay(s16 period);
extern void DMAC2ISR();


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

HANDLE hHandset;
unsigned int dmsefc, dmmcr, dmctr, src_addr, dst_addr;
unsigned int dmpre, dmsrcp, dmdstp, dmidx0, dmidx1, dmfri0, dmfri1, dmgsa, dmgda, dmgcr, dmgfr;

/* Create specific data section for buffer (symbol, section_name) */
#pragma DATA_SECTION(buffer,"audio_buffer");
int buffer[0x1400];

/* Create specific data section for buffer (symbol, section_name) */
#pragma DATA_SECTION(out_buffer,"outt_buffer");
int out_buffer[0x500];//


/* Create specific data section for coeffiecients */
#pragma DATA_SECTION(lpfh,"coefficients");
/* Low  Pass Filter fs=16000 fc=4000Hz*/ 
   int lpfh[82]={
       -1,     -1,     -1,     -1,     -1,      1,      4,      8,     14,
       21,     29,     36,     42,     44,     41,     31,     13,    -15,
      -52,    -97,   -148,   -200,   -249,   -288,   -310,   -306,   -270,
     -195,    -76,     88,    296,    545,    827,   1132,   1447,   1757,
     2046,   2300,   2505,   2648,   2721,   2721,   2648,   2505,   2300,
     2046,   1757,   1447,   1132,    827,    545,    296,     88,    -76,
     -195,   -270,   -306,   -310,   -288,   -249,   -200,   -148,    -97,
      -52,    -15,     13,     31,     41,     44,     42,     36,     29,
       21,     14,      8,      4,      1,     -1,     -1,     -1,     -1,
       -1
};
/* 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");
int delaybuff[82]={0}; 
//int abuffer[256];
//int bbuffer[256]; 

/* declare and initialize two variables for DMAC ISRs */

int frame=0; 
int flag=0;
int temp;   
int currbuff = 0;


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

interrupt void DMAC2ISR();


/*****************************************************************************/
/* MAIN                                                                      */
/*****************************************************************************/

void main()
{   
	s16 cnt=1;
	
/* These are the items that BIOS will set when we use it */

    BSCR = 0x8806;
    XPC = 0;
    PMST = 0xA0;
    brd_set_cpu_freq(50);
    TIMER_HALT(0); 
    brd_set_wait_states(7, 7, 9);
    TIMER_RESET(0); 
    IMR=0;		//禁止所有中断
/* ----------------------------------------------------- */

		if(brd_init_bios())	  			
        return;
         


	while ( cnt-- )
	{
		brd_led_toggle(BRD_LED0);
		delay(1000);
		brd_led_toggle(BRD_LED0);
		brd_led_toggle(BRD_LED1);
		delay(1000);
		brd_led_toggle(BRD_LED1);
		brd_led_toggle(BRD_LED2);
		delay(1000);
		brd_led_toggle(BRD_LED2);
	}

/* 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 */

/* Clear IFR */
 
   INTR_CLR_FLAG(DMAC2);

/* Reset all DMA channels */ 

    dma_reset_all();


/* Initialize DMA channel 2 */

    dmsefc = ((DSYNC_REVT1 <<12));
    dmmcr = ((AUTOINIT_ENABLE << 15) | (DINM_ENABLE << 14) | (IMOD_HALFBLOCK <<13) | (CTMOD_DEC <<12) | (INDEXMODE_NOMOD << 8) | (SPACE_DATA << 6) | (INDEXMODE_INC << 2) | (SPACE_DATA));
    dmctr = 0x3FF;
    src_addr = DRR1_ADDR(HANDSET_CODEC);
    dst_addr = (unsigned int) &buffer;

    dma_init(DMA_CH2, dmsefc, dmmcr, dmctr, SPACE_DATA, src_addr, SPACE_DATA, dst_addr);

/* Set number of frames for channel 2 */
    
    DMA_FRAMECOUNT(DMA_CH2, 2);
     
/* Set up global autoinit registers for DMA CH2 Input */

    dmgsa = src_addr;
    dmgda = dst_addr;
    dmgcr = 0x3FF;
    dmgfr = 2;
    
/* Set up global priority and enable control register for Ch2 */

    dmpre = ((HIGH_PRIORITY << 10) | (INTSEL_01 << 6));
    dmsrcp = SPACE_DATA;
    dmdstp = SPACE_DATA;
    dmidx0 = 0;
    dmidx1 = 0;
    dmfri0 = 0;
    dmfri1 = 0;

    dma_global_init(dmpre, dmsrcp, dmdstp, dmidx0, dmidx1, dmfri0, dmfri1, dmgsa, dmgda, dmgcr, dmgfr);

/* Enable channel 2 */

    DMA_ENABLE(DMA_CH2);  
    
/* prime the serial port to begin input buffer stream */
    temp = *(volatile u16*)DRR1_ADDR(HANDSET_CODEC);  
     
/* Enable DMAC2 interrupt */
 
    INTR_ENABLE(DMAC2);
   
/* Enable Global Interrupts */ 

    INTR_GLOBAL_ENABLE;

/* Endless loop waiting for DMAC2 interrupt */
    
	for(;;);
}


/*****************************************************************************/
/* delay()   											 */
/*****************************************************************************/

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 + -