📄 firlab.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(inp_buffer,"audio_buffer");
int inp_buffer[0x200];
/* Create specific data section for buffer (symbol, section_name) */
#pragma DATA_SECTION(out_buffer,"outt_buffer");
int out_buffer[0x200];
/* Create specific data section for coeffiecients */
#pragma DATA_SECTION(coeffs,"coefficients");
/* Low Pass Filter fs=16000 fc=4000Hz*/
int coeffs[16]={ -2, -30,127,372,-891, -1925, 4228, 14507,14507,4228,-1925,-891,372,127, -30,-2};
/* 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,"delayb");
int delaybuff[16]={0};
/* 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=2;
/* These are the items that BIOS will set when we use it */
BSCR = 0x8806;
XPC = 0;
PMST = 0xA0;
brd_set_cpu_freq(100);
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); //切换LED指示灯0的显示状态
delay(1000);
brd_led_toggle(BRD_LED1); //切换LED指示灯1的显示状态
delay(1000);
brd_led_toggle(BRD_LED2); //切换LED指示灯2的显示状态
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 */
/* Clear IFR */
INTR_CLR_FLAG(DMAC2);
/* Reset all DMA channels */
dma_reset_all();
/* Initialize DMA channel 2 */
dmsefc = ((DSYNC_REVT1 <<12));//DMA与McBSP1接收事件同步
dmmcr = ((AUTOINIT_ENABLE << 15) | (DINM_ENABLE << 14) | (IMOD_HALFBLOCK <<13) | (CTMOD_DEC <<12) | (INDEXMODE_NOMOD << 8) | (SPACE_DATA << 6) | (INDEXMODE_INC << 2) | (SPACE_DATA));
//设置传输控制模式寄存器DMMCR
//15bit AUTOINIT_ENABLE=1 使能自动初始化
//14bit DINM_ENABLE=1 根据IMOD位产生中断
//13bit IMOD_HALFBLOCK=1 帧和块结束时都产生中断
//12bit CTMOD_DEC=0 减量计数模式(多帧模式)
//10-8bit INDEXMODE_NOMOD=000 源地址模式No modify
//7-6bit SPACE_DATA=01 源地址空间为数据空间
//4-2bit INDEXMODE_INC=01 目的地址模式, 传输之后加1
//1-0bit SPACE_DATA=01 目的地址空间为数据空间
dmctr = 0xFF;//单元记数,期望传输数据减
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -