/* Define a DMA_Handle object to be used with DMA_open function */ DMA_Handle hDmaRcv, hDmaXmt;
/* Define a MCBSP_Handle object to be used with MCBSP_open function */ MCBSP_Handle hMcbsp;
volatile Uint16 transferComplete = FALSE; Uint16 err = 0; Uint16 old_intm;
Uint16 xmtEventId, rcvEventId;
//---------Function prototypes---------
/* Reference the start of the interrupt vector table */ /* This symbol is defined in file vectors.s55 */ extern void VECSTART(void);
/* Protoype for interrupt functions */ interrupt void dmaXmtIsr(void); interrupt void dmaRcvIsr(void); void taskFxn(void); /*
* copyData() - 实现DMA中实时信号FIR滤波.
*/
void copyData(Int16 *inbuf, Int16 *outbuf, Int16 length) { Int16 i = 0;
for (i = 0; i < length/2; i++) { inp_left[0] = inbuf[2*i]+SINE_TABLE[i]; inp_right[0] = inbuf[2*i+1]+SINE_TABLE[i];
// 对输入数据inbuf进行FIR滤波,结果存放在outbuf中 fir(inp_left, h, out_left, dbptr, NX, NH); outbuf[2*i] = out_left[0]; fir(inp_right, h, out_right, dbptrx, NX, NH); outbuf[2*i+1] = out_right[0]; } }
/* ------------------------------- Threads ------------------------------ */
30
/*
* processBuffer() - Process audio data once it has been received. */
void processBuffer(void) {
Uint32 addr;
static Int16 pingPong = PING; while(DMA_FGETH (hDmaRcv, DMACCR, ENDPROG)){ ; } /* 修改DMA接收通道的目的地址 */
// Determine which ping-pong state we're in if (pingPong == PING) {
// Configure the receive channel for pong input data addr = ((Uint32)gBufferRcvPong) << 1;
DMA_RSETH(hDmaRcv, DMACDSAL, addr & 0xffff);
DMA_RSETH(hDmaRcv, DMACDSAU, (addr >> 16) & 0xffff); // Set new state to PONG pingPong = PONG; } else {
// Configure the receive channel for ping input data addr = ((Uint32)gBufferRcvPing) << 1;
DMA_RSETH(hDmaRcv, DMACDSAL, addr & 0xffff);
DMA_RSETH(hDmaRcv, DMACDSAU, (addr >> 16) & 0xffff);
// Set new state to PING pingPong = PING; } DMA_FSETH (hDmaRcv, DMACCR, ENDPROG, 1); DMA_FSETH (hDmaXmt, DMACCR, ENDPROG, 1); /* 修改DMA发送通道的源地址 */
if (pingPong == PONG)
31
{ //Insert your application program here
copyData(gBufferRcvPing, gBufferXmtPing, BUFFSIZE);
// Configure the transmit channel for ping output data addr = ((Uint32)gBufferXmtPing) << 1;
DMA_RSETH(hDmaXmt, DMACSSAL, addr & 0xffff);
DMA_RSETH(hDmaXmt, DMACSSAU, (addr >> 16) & 0xffff);
} else { //Insert your application program here
copyData(gBufferRcvPong, gBufferXmtPong, BUFFSIZE);
// Configure the transmit channel for pong output data addr = ((Uint32)gBufferXmtPong) << 1;
DMA_RSETH(hDmaXmt, DMACSSAL, addr & 0xffff);
DMA_RSETH(hDmaXmt, DMACSSAU, (addr >> 16) & 0xffff); } /* 启动DMA传输 */ // Start the DMA
DMA_start(hDmaRcv); DMA_start(hDmaXmt); }
//---------main routine--------- void main(void) {
Uint16 i; Int16 j = 0;
/* Initialize CSL library - This is REQUIRED !!! */ CSL_init();
// The main frequency of system is 240MHz
// 该频率是为了设置IIC模块的需要设置的,为了使用I2C_setup函数 PLL_setFreq(1, 0xC, 0, 1, 3, 3, 0);
//EMIF初始化 Emif_Config();
32
// Open McBSP port 1 and get a McBSP type handle hMcbsp = MCBSP_open(MCBSP_PORT1,MCBSP_OPEN_RESET);
// Config McBSP port 1 by use previously defined structure MCBSP_config(hMcbsp, &Mcbsp1Config);
//I2C初始化
I2C_cofig();
//CODEC寄存器初始化
inti_AIC();
/* Set IVPH/IVPD to start of interrupt vector table */ IRQ_setVecs((Uint32)(&VECSTART)); for (j=0; j for (j=0; j dbptr = &db[0]; dbptrx = &dbx[0]; for (i = 0; i <= BUFFSIZE - 1; i++) { gBufferXmtPing[i] = 0; gBufferXmtPong[i] = 0; } /* Call function to effect transfer */ taskFxn(); } void taskFxn(void) { Uint16 srcAddrHi, srcAddrLo; Uint16 dstAddrHi, dstAddrLo; /* By default, the TMS320C55xx compiler assigns all data symbols word */ /* addresses. The DMA however, expects all addresses to be byte */ /* addresses. Therefore, we must shift the address by 2 in order to */ /* change the word address to a byte address for the DMA transfer. */ 33 /* DMA接收通道的源地址和目的地址 */ srcAddrHi = (Uint16)(((Uint32)(MCBSP_ADDR(DRR11))) >> 15) & 0xFFFFu; srcAddrLo = (Uint16)(((Uint32)(MCBSP_ADDR(DRR11))) << 1) & 0xFFFFu; dstAddrHi = (Uint16)(((Uint32)(&gBufferRcvPing)) >> 15) & 0xFFFFu; dstAddrLo = (Uint16)(((Uint32)(&gBufferRcvPing)) << 1) & 0xFFFFu; dmaRcvConfig.dmacssal = (DMA_AdrPtr)srcAddrLo; dmaRcvConfig.dmacssau = srcAddrHi; dmaRcvConfig.dmacdsal = (DMA_AdrPtr)dstAddrLo; dmaRcvConfig.dmacdsau = dstAddrHi; /* DMA发送通道的源地址和目的地址 */ srcAddrHi = (Uint16)(((Uint32)(&gBufferXmtPing)) >> 15) & 0xFFFFu; srcAddrLo = (Uint16)(((Uint32)(&gBufferXmtPing)) << 1) & 0xFFFFu; dstAddrHi = (Uint16)(((Uint32)(MCBSP_ADDR(DXR11))) >> 15) & 0xFFFFu; dstAddrLo = (Uint16)(((Uint32)(MCBSP_ADDR(DXR11))) << 1) & 0xFFFFu; dmaXmtConfig.dmacssal = (DMA_AdrPtr)srcAddrLo; dmaXmtConfig.dmacssau = srcAddrHi; dmaXmtConfig.dmacdsal = (DMA_AdrPtr)dstAddrLo; dmaXmtConfig.dmacdsau = dstAddrHi; /* Open MCBSP Port 1 and set registers to their power on defaults */ // hMcbsp = MCBSP_open(MCBSP_PORT1, MCBSP_OPEN_RESET); /* 配置DMA通道及其中断 */ /* Open DMA channels 4 & 5 and set regs to power on defaults */ hDmaRcv = DMA_open(DMA_CHA4,DMA_OPEN_RESET); hDmaXmt = DMA_open(DMA_CHA5,DMA_OPEN_RESET); /* Get interrupt event associated with DMA receive and transmit */ xmtEventId = DMA_getEventId(hDmaXmt); rcvEventId = DMA_getEventId(hDmaRcv); /* Temporarily disable interrupts and clear any pending */ /* interrupts for MCBSP transmit */ old_intm = IRQ_globalDisable(); /* Clear any pending interrupts for DMA channels */ IRQ_clear(xmtEventId); 34