TI中文支持网
TI专业的中文技术问题搜集分享网站

DSP5509A使用DMA乒乓缓存从McBSP0读取AIC23的数据进入不了中断

/******************************************************************************/
/* this program is that the codec is controled by the I2C and Mcbsp*/
/*----------------------------------------------------------------------------*/

#include <csl.h>
#include <csl_i2c.h>
#include <stdio.h>
#include <csl_pll.h>
#include <csl_mcbsp.h>
#include <csl_irq.h>
#include <math.h>
#include <function.h>
#include <csl_dma.h>

#define State_Signal_Process 1

/* Define transmit and receive buffers */
int pingrcv[FRAME_LENGTH];
int pongrcv[FRAME_LENGTH];
int pingxmt[FRAME_LENGTH];
int pongxmt[FRAME_LENGTH];
int Leftchannel_Buffer[FRAME_LENGTH];
int Rightchannel_Buffer[FRAME_LENGTH];

int xfreebuf;
int rfreebuf;

int State_Work=0;

//volatile Uint16 transferComplete = FALSE;
Uint16 old_intm;

Uint16 rcvEventId;
Uint16 xmtEventId;

//---------Function prototypes---------
/* Reference start of interrupt vector table */
/* This symbol is defined in file, vectors.s55 */
extern void VECSTART(void);

void delay(Uint32 k);

void I2C_Set_Init();
void McBSP_Set_Init();
void DMA_DataTransfer_Init();
void Signal_Process();

/* Protoype for interrupt functions */
interrupt void dmaXmtIsr(void);
interrupt void dmaRcvIsr(void);


/*锁相环的设置*/
PLL_Config  myConfig= {0,//IAI: the PLL locks using the same process that was underway//before the idle mode was entered1,//IOB: If the PLL indicates a break in the phase lock,//it switches to its bypass mode and restarts the PLL phase-locking//sequence12,//PLL multiply value; multiply 24 times1//Divide by 2 PLL divide value; it can be either PLL divide value//(when PLL is enabled), or Bypass-mode divide value//(PLL in bypass mode, if PLL multiply value is set to 1)
};

/*McBSP set,we use mcbsp1 to send and recieve the data between DSP and AIC23*/
MCBSP_Config Mcbsp1Config= {
	MCBSP_SPCR1_RMK(MCBSP_SPCR1_DLB_OFF,/* DLB= 0,禁止自闭环方式 */MCBSP_SPCR1_RJUST_LZF,/* RJUST  = 2 left justify the data and zero fill LSBS */MCBSP_SPCR1_CLKSTP_DISABLE,/* CLKSTP = 0 Clock stop mode disable */MCBSP_SPCR1_DXENA_ON,/* DXENA  = 1 DX delay enabler on */MCBSP_SPCR1_ABIS_DISABLE,/* ABIS= 0 reserved always write 0*/MCBSP_SPCR1_RINTM_RRDY,/* RINTM  = 0 sends a receive INT request to CPU when the RRDY bitchange from 0 to 1, indicating that receive data is ready to be read*/0,/* RSYNCER = 0 receive frame-sync error bit, no error*/MCBSP_SPCR1_RRST_DISABLE/* RRST= 0 reset the receiver*/),MCBSP_SPCR2_RMK(MCBSP_SPCR2_FREE_NO,/* FREE= 0 free run bit, The McBSP transmit and receive clocks are affected as determined by the SOFT bit*/MCBSP_SPCR2_SOFT_NO,/* SOFT= 0 Soft stop bit, Hard stop*/MCBSP_SPCR2_FRST_FSG,/* FRST= 0 Frame-sync logic reset bit*/MCBSP_SPCR2_GRST_CLKG,/* GRST= 0 Sample rate generator reset bit */MCBSP_SPCR2_XINTM_XRDY,/* XINTM  = 0 transmit interrupt mode bits XRDY bit changes from 0 to1 */0,/* XSYNCERR = N/A transmit frame-sync error bit, no error*/MCBSP_SPCR2_XRST_DISABLE/* XRST= 0 transmit ready bit, not ready*///注意:开始一定要设置为disable,否则不能设置它的寄存器,全部为默认值,导致不能正常接收,//在程序调用C库函数mcbspstart时会在设为1,McBSP便退出reset状态开始工作),/*单数据相,接受数据长度为16位,每相2个数据*/MCBSP_RCR1_RMK(MCBSP_RCR1_RFRLEN1_OF(1),/* RFRLEN1 = 1 Receive frame length 1 bits(1 to 128 words),Frame length=(RFRLEN1+1)words*/MCBSP_RCR1_RWDLEN1_16BIT/* RWDLEN1 = 2 Receive word length 1 bits, 16bit*/),
 MCBSP_RCR2_RMK(MCBSP_RCR2_RPHASE_SINGLE,/* RPHASE  = 0 Receive phase number bit, single-phase frame*/MCBSP_RCR2_RFRLEN2_OF(0),/* RFRLEN2 = 0 */MCBSP_RCR2_RWDLEN2_8BIT,/* RWDLEN2 = 0 */MCBSP_RCR2_RCOMPAND_MSB,/* RCOMPAND = 0 receive companding mode bits, 0, no companding,MSB received first*/MCBSP_RCR2_RFIG_YES,/* RFIG= 0 Receive frame-sync ignore bit, 1, frame-sync detect */MCBSP_RCR2_RDATDLY_1BIT/* RDATDLY = 1 Receive data delay bits, 1-bit data delay*/),MCBSP_XCR1_RMK(MCBSP_XCR1_XFRLEN1_OF(1),/* XFRLEN1 = 1 Transmit frame length 1(1 to 128 words),Frame length=(XFRLEN1+1)words */MCBSP_XCR1_XWDLEN1_16BIT/* XWDLEN1 = 2 Transmit word length 1.16bit*/),
 MCBSP_XCR2_RMK(MCBSP_XCR2_XPHASE_SINGLE,/* XPHASE  = 0 Transmit phase number bit, single-phase frame*/MCBSP_XCR2_XFRLEN2_OF(0),/* XFRLEN2 = 0 */MCBSP_XCR2_XWDLEN2_8BIT,/* XWDLEN2 = 0 */MCBSP_XCR2_XCOMPAND_MSB,/* XCOMPAND = 0 Transmit companding mode bits, 0, no companding,MSB received first*/MCBSP_XCR2_XFIG_YES,/* XFIG= 0 Transmit frame-sync ignore bit, 1, frame-sync detect */MCBSP_XCR2_XDATDLY_1BIT/* XDATDLY = 1 Transmit data delay bits, 1-bit data delay*/),
 MCBSP_SRGR1_DEFAULT,/*(0x0001u)FWID=0,CLKGDV=1 */
 MCBSP_SRGR2_DEFAULT,/*(0x2000u)CLKSM=1,Sample rate generator input clock mode bit */
 MCBSP_MCR1_DEFAULT,
 MCBSP_MCR2_DEFAULT,
 MCBSP_PCR_RMK(MCBSP_PCR_IDLEEN_RESET,/* IDLEEN= 0 The McBSP remains active when the PERIPH domain is idled */MCBSP_PCR_XIOEN_SP,/* XIOEN= 0 Transmit I/O enable bit, CLKX,FSX,DX,CLKS pins are serial port pins*/MCBSP_PCR_RIOEN_SP,/* RIOEN= 0 Receive I/O enable bit, CLKR,FSR,DR,CLKS pins are serial port pins*/MCBSP_PCR_FSXM_EXTERNAL,/* FSXM= 0 Transmit frame-sync mode bit,0:transmit fram-sync is supplied by an external source via the FSX pin*/MCBSP_PCR_FSRM_EXTERNAL,/* FSRM= 0 Receive frame-sync mode bit,0:transmit fram-sync is supplied by an external source via the FSR pin*/0,/* DXSTAT = N/A*/MCBSP_PCR_CLKXM_INPUT,/* CLKXM= 0 Transmit clock mode bit*/MCBSP_PCR_CLKRM_INPUT,/* CLKRM= 0 Receive clock mode bit*/MCBSP_PCR_SCLKME_NO,/* SCLKME= 0 Sample rate generator input clock mode bit,used with CLKSM to select the input clock*/MCBSP_PCR_FSXP_ACTIVEHIGH,/* FSXP= 0 Transmit frame-sync polarity bit, 0,transmit frame-sync pulses are active high*/MCBSP_PCR_FSRP_ACTIVEHIGH,/* FSRP= 1 Receive frame-sync polarity bit, 0,receive frame-sync pulses are active high*/MCBSP_PCR_CLKXP_FALLING,/* CLKXP= 1 Transmit clock polarity bit,1,transmit data is driven on the rising edge of CLKX */MCBSP_PCR_CLKRP_RISING/* CLKRP= 1 Receive clock polarity bit*/
 ),
 MCBSP_RCERA_DEFAULT,
 MCBSP_RCERB_DEFAULT,
 MCBSP_RCERC_DEFAULT,
 MCBSP_RCERD_DEFAULT,
 MCBSP_RCERE_DEFAULT,
 MCBSP_RCERF_DEFAULT,
 MCBSP_RCERG_DEFAULT,
 MCBSP_RCERH_DEFAULT,
 MCBSP_XCERA_DEFAULT,
 MCBSP_XCERB_DEFAULT,
 MCBSP_XCERC_DEFAULT,
 MCBSP_XCERD_DEFAULT,
 MCBSP_XCERE_DEFAULT,
 MCBSP_XCERF_DEFAULT,
 MCBSP_XCERG_DEFAULT,
 MCBSP_XCERH_DEFAULT
};

DMA_Config dmaRcvConfig = {
		DMA_DMACSDP_RMK(
				DMA_DMACSDP_DSTBEN_NOBURST,/* DSTBEN = 0 */
				DMA_DMACSDP_DSTPACK_OFF,/* DSTPACK = 0 */
				DMA_DMACSDP_DST_DARAM,/* DST = 1 */
				DMA_DMACSDP_SRCBEN_NOBURST,/* SRCBEN = 0 */
				DMA_DMACSDP_SRCPACK_OFF,/* SRCPACK = 0 */
				DMA_DMACSDP_SRC_PERIPH,/* SRC = 3 */
				DMA_DMACSDP_DATATYPE_16BIT/* DATATYPE = 1 */
		),/* DMACSDP源和目标参数寄存器 */
		DMA_DMACCR_RMK(
				DMA_DMACCR_DSTAMODE_POSTINC,/* DSTAMODE = 1 */
				DMA_DMACCR_SRCAMODE_CONST,/* SRCAMODE = 0  */
				DMA_DMACCR_ENDPROG_ON,/* ENDPROG = 1 */
				DMA_DMACCR_REPEAT_OFF,/* REPEAT = 0*/
				DMA_DMACCR_AUTOINIT_OFF,/* AUTOINIT = 1 */
				DMA_DMACCR_EN_STOP,/* EN = 0 */
				DMA_DMACCR_PRIO_HI,/* PRIO = 1 */
				DMA_DMACCR_FS_DISABLE,/* FS = 1*/
				DMA_DMACCR_SYNC_REVT0/* SYNC = 5 DMA_DMACCR_SYNC_NONE*/
		),/* DMACCR 通道控制寄存器 */
		DMA_DMACICR_RMK(
				DMA_DMACICR_BLOCKIE_OFF,/* BLOCKIE = 0 */
				DMA_DMACICR_LASTIE_OFF,/* LASTIE = 0 */
				DMA_DMACICR_FRAMEIE_ON,/* FRAMEIE = 1 */
				DMA_DMACICR_FIRSTHALFIE_OFF,/* FIRSTHALFIE = 0 */
				DMA_DMACICR_DROPIE_OFF,/* DROPIE = 0 */
				DMA_DMACICR_TIMEOUTIE_OFF/* TIMEOUTIE = 0 */
		), /* DMACICR 中断控制寄存器*/
		(DMA_AdrPtr)(MCBSP_ADDR(DRR10)), /* DMACSSAL 源起始地址低位寄存器*/
		0, /* DMACSSAU 源起始地址高位寄存器*/
		(DMA_AdrPtr)&pingrcv, /* DMACDSAL  目标起始地址低位寄存器*/
		0, /* DMACDSAU 目标起始地址高位寄存器*/
		FRAME_LENGTH, /* DMACEN 要素个数寄存器,装入每帧的要素数*/
		1, /* DMACFN 帧数寄存器,装入每块的帧数*/
		0, /* DMACFI 帧索引寄存器*/
		0 /* DMACEI 要素索引寄存器*/
};

DMA_Config  dmaXmtConfig = {DMA_DMACSDP_RMK(
	DMA_DMACSDP_DSTBEN_NOBURST,//Destination burst :-不使用突发DMA_DMACSDP_DSTPACK_OFF,//Destination packing :-目标口禁止打包DMA_DMACSDP_DST_PERIPH,//Destination selection :-接收的目标口是外设mcbspDMA_DMACSDP_SRCBEN_NOBURST,//Source burst :-源突发禁止DMA_DMACSDP_SRCPACK_OFF,//Source packing :-源口禁止打包DMA_DMACSDP_SRC_DARAM,//Source selection :源口为DARAMDMA_DMACSDP_DATATYPE_16BIT//Data type :-设置数据类型16bit字长),/* DMACSDP  源与目标参数寄存器 */DMA_DMACCR_RMK(DMA_DMACCR_DSTAMODE_CONST,//Destination address mode :-目标口地址为恒定地址DMA_DMACCR_SRCAMODE_POSTINC,  //Source address mode :-自动执行后增量(由于本程序中数据类型是16bit,所以+2)DMA_DMACCR_ENDPROG_ON,//End of programmation bit :-DMA_DMACCR_REPEAT_OFF,
	DMA_DMACCR_AUTOINIT_OFF,//Auto initialization bit :-DMA_DMACCR_EN_STOP,//Channel enable :-设置时先关闭通道
	DMA_DMACCR_PRIO_HI,//Channel priority :-设置为低优先级
	DMA_DMACCR_FS_DISABLE,//Frame/Element Sync :-单元事件同步DMA_DMACCR_SYNC_XEVT0//Synchronization control :-McBSP1 Transmit Event(XEVT1)),/* DMACCR 通道控制寄存器*/DMA_DMACICR_RMK(
	DMA_DMACICR_BLOCKIE_OFF,//Whole block interrupt enable :-块传输完成后中断使能DMA_DMACICR_LASTIE_OFF,//Last frame interrupt enable :-
	DMA_DMACICR_FRAMEIE_ON,//Whole frame interrupt enable :-DMA_DMACICR_FIRSTHALFIE_OFF,  //Half frame interrupt enable :-DMA_DMACICR_DROPIE_OFF,//Sync. event drop interrupt enable :-DMA_DMACICR_TIMEOUTIE_OFF//Time out interrupt enable :-),/* DMACICR 中断控制寄存器 */(DMA_AdrPtr)&pingxmt[0],/* DMACSSAL 源地址低位*/0,/* DMACSSAU 源地址高位 */(DMA_AdrPtr)(MCBSP_ADDR(DXR10)),/* DMACDSAL 目的地址低位*/0,/* DMACDSAU 目的地址高位*/
	FRAME_LENGTH,/* DMACEN1 帧内数据长度 16*2 两个数据一个帧*/
	1,/* DMACFN  帧数大小  */0,/* DMACFI*/0/* DMACEI*/
};

/* This next struct shows how to use the I2C API */
/* Create and initialize an I2C initialization structure */
I2C_Setup I2Cinit = {0,/* 7 bit address mode */0,/* own address - don't care if master */84,/* clkout value (Mhz)  */50,/* a number between 10 and 400*/0,/* number of bits/byte to be received or transmitted (8)*/0,/* DLB mode on*/1/* FREE mode of operation on*/
};

/*数字音频接口格式设置
AIC23为主模式,数据为DSP模式,数据长度16位*/
Uint16 digital_audio_inteface_format[2]={0x0e,0x53};
/*AIC23的波特率设置,采样率为44.1K*/
Uint16 sample_rate_control[2] = {0x10,0x20};
/*AIC23寄存器复位*/
Uint16 reset[2] ={0x1e,0x00};
/*AIC23节电方式设置,所有部分均所与工作状态*/
Uint16 power_down_control[2] ={0x0c,0x01};
/*AIC23模拟音频的控制
DAC使能,ADC输入选择为MIC*/
Uint16 analog_aduio_path_control[2] ={0x08,0x15};
/*AIC23数字音频通路的控制*/
Uint16 digital_audio_path_control[2] ={0x0a,0x05};
/*AIC23数字接口的激活*/
Uint16 digital_interface_activation[2] ={0x12,0x01};
/*AIC23左通路音频调节*/
Uint16 left_line_input_volume_control[2] ={0x00,0x00};
/*AIC23右通路音频调节*/
Uint16 right_line_input_volume_control[2] ={0x02,0x00};
/*AIC23耳机左通路音频调节*/
Uint16 left_headphone_volume_control[2] ={0x05,0x79};
/*AIC23耳机右通路音频调节*/
Uint16 right_headphone_volume_control[2] = {0x07,0x79};

/*定义McBSP的句柄*/
MCBSP_Handle hMcbsp;
MCBSP_Config Mcbsptest;

I2C_Config testI2C;

/*定义DMA的句柄*/
DMA_Handle hDmaRcv;
DMA_Handle hDmaXmt;

void main(void)
{/* Initialize CSL library - This is REQUIRED !!! *//*初始化CSL库*/CSL_init();

	/*设置系统的运行速度为140MHz*/PLL_config(&myConfig);/*初始化I2C */
	I2C_Set_Init();

	/*初始化McBSP */
	McBSP_Set_Init();

	/*初始化DMA */
	DMA_DataTransfer_Init();

	while(TRUE){
		if(State_Work==State_Signal_Process){
			Signal_Process();
			State_Work=0;
		}
	}
}

void delay(Uint32 k){while(k--);
}

void I2C_Set_Init(){/* Initialize I2C, using parameters in init structure *//*初始化I2C的格式*/
//	I2C_config(&Config);
//	I2C_start();

//	I2C_getConfig(&Config1);
	/*I2C is undet reset*/
	I2C_RSET(I2CMDR,0);

	/*设置预分频寄存器,I2C的mode clock is 10MHz*/
	delay(100);
	I2C_RSET(I2CSAR,0x001A);

	I2C_RSET(I2CMDR,0x0620);I2C_setup(&I2Cinit);	/*设置I2C的Mater clock*/
	I2C_RSET(I2CCLKL,100);

	I2C_RSET(I2CCLKH,100);I2C_getConfig(&testI2C);/*reset AIC23*/i2c_status = I2C_write( reset,//pointer to data array2,				//length of data to be transmitted1,				//master or slaver--masterCODEC_ADDR,//slave address to transmit to1,				//transfer mode of operation30000			//time out for bus busy);
	delay(1000);/*设置AIC23各部分均工作*/i2c_status = I2C_write( power_down_control,//pointer to data array2,				//length of data to be transmitted1,				//master or slaverCODEC_ADDR,//slave address to transmit to1,				//transfer mode of operation30000			//time out for bus busy);

	/*设置AIC23的数字接口*/
	i2c_status = I2C_write( digital_audio_inteface_format,//pointer to data array2,				//length of data to be transmitted1,				//master or slaverCODEC_ADDR,//slave address to transmit to1,				//transfer mode of operation30000			//time out for bus busy	);/*设置AIC23模拟通路*/
	i2c_status = I2C_write( analog_aduio_path_control,//pointer to data array2,				//length of data to be transmitted1,				//master or slaverCODEC_ADDR,//slave address to transmit to1,				//transfer mode of operation30000			//time out for bus busy);

	/*设置数字通路*/
	i2c_status = I2C_write( digital_audio_path_control,//pointer to data array2,				//length of data to be transmitted1,				//master or slaverCODEC_ADDR,//slave address to transmit to1,				//transfer mode of operation30000			//time out for bus busy	);

	/*设置AIC23的采样率*/
	i2c_status = I2C_write( sample_rate_control,//pointer to data array2,				//length of data to be transmitted1,				//master or slaverCODEC_ADDR,//slave address to transmit to1,				//transfer mode of operation30000			//time out for bus busy);

	/*设置耳机音量*/
	i2c_status = I2C_write( left_headphone_volume_control,//pointer to data array2,				//length of data to be transmitted1,				//master or slaverCODEC_ADDR,//slave address to transmit to1,				//transfer mode of operation30000			//time out for bus busy);

	i2c_status = I2C_write( right_headphone_volume_control,//pointer to data array2,				//length of data to be transmitted1,				//master or slaverCODEC_ADDR,//slave address to transmit to1,				//transfer mode of operation30000			//time out for bus busy);

	/*设置Line输入的音量*/
	i2c_status = I2C_write( left_line_input_volume_control,//pointer to data array2,				//length of data to be transmitted1,				//master or slaverCODEC_ADDR,//slave address to transmit to1,				//transfer mode of operation30000			//time out for bus busy);

	i2c_status = I2C_write( right_line_input_volume_control,//pointer to data array2,				//length of data to be transmitted1,				//master or slaverCODEC_ADDR,//slave address to transmit to1,				//transfer mode of operation30000			//time out for bus busy);

	/*启动AIC23*/
	i2c_status = I2C_write( digital_interface_activation,//pointer to data array2,				//length of data to be transmitted1,				//master or slaverCODEC_ADDR,//slave address to transmit to1,				//transfer mode of operation30000			//time out for bus busy);

}


void McBSP_Set_Init(){

	/* Open MCBSP Port 1 and set registers to their power on defaults */
	hMcbsp = MCBSP_open(MCBSP_PORT0,MCBSP_OPEN_RESET);

	/* Write values from configuration structure to MCBSP control regs */
	MCBSP_config(hMcbsp,&Mcbsp1Config);

	/* Start Sample Rate Generator and Enable Frame Sync */
	MCBSP_start(hMcbsp,MCBSP_SRGR_START | MCBSP_SRGR_FRAMESYNC,0x300u);

	/* Take MCBSP transmit and receive out of reset */
	MCBSP_start(hMcbsp,MCBSP_XMIT_START | MCBSP_RCV_START,0u);

//	MCBSP_start(hMcbsp,
//MCBSP_RCV_START | MCBSP_XMIT_START,
//0);

	MCBSP_getConfig(hMcbsp,&Mcbsptest);

}

void DMA_DataTransfer_Init()
{
	Uint16 srcAddrHi, srcAddrLo;
	Uint16 dstAddrHi, dstAddrLo;

	int i;
	//乒乓数组初始化
	for(i=0;i<FRAME_LENGTH;i++){
		pingrcv[i] = 0;
		pongrcv[i] = 0;
		pingxmt[i] = 0;
		pongxmt[i] = 0;
	}

	xfreebuf = xpongbuf;
	rfreebuf = rpongbuf;

	/* Set IVPD/IPVH to start of interrupt vector table */
	IRQ_setVecs((Uint32)(&VECSTART));

	/* 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.
	* MCBSP_ADDR()函数用来取址,DRR11是数据接收寄存器,即DMA寄存器从此接收数据
	* 表示DMA从MCBSP传数据到pingrcv*/srcAddrHi = (Uint16)(((Uint32)(MCBSP_ADDR(DRR10))) >> 15) & 0xFFFFu;srcAddrLo = (Uint16)(((Uint32)(MCBSP_ADDR(DRR10))) << 1) & 0xFFFFu;dstAddrHi = (Uint16)(((Uint32)(&pingrcv)) >> 15) & 0xFFFFu;dstAddrLo = (Uint16)(((Uint32)(&pingrcv)) << 1) & 0xFFFFu;dmaRcvConfig.dmacssal = (DMA_AdrPtr)srcAddrLo;dmaRcvConfig.dmacssau = srcAddrHi;dmaRcvConfig.dmacdsal = (DMA_AdrPtr)dstAddrLo;dmaRcvConfig.dmacdsau = dstAddrHi;

	/* 表示DMA从pingxmt传数据到MCBSP*/srcAddrHi = (Uint16)(((Uint32)(&pingxmt[0])) >> 15) & 0xFFFFu;srcAddrLo = (Uint16)(((Uint32)(&pingxmt[0])) << 1) & 0xFFFFu;dstAddrHi = (Uint16)(((Uint32)(MCBSP_ADDR(DXR10))) >> 15) & 0xFFFFu;dstAddrLo = (Uint16)(((Uint32)(MCBSP_ADDR(DXR10))) << 1) & 0xFFFFu;dmaXmtConfig.dmacssal = (DMA_AdrPtr)srcAddrLo;dmaXmtConfig.dmacssau = srcAddrHi;dmaXmtConfig.dmacdsal = (DMA_AdrPtr)dstAddrLo;dmaXmtConfig.dmacdsau = dstAddrHi;

	/* 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);
	IRQ_clear(rcvEventId);

	/* Enable DMA interrupt in IER register */
	IRQ_enable(xmtEventId);
	IRQ_enable(rcvEventId);

	/* Set Interrupt Vector Start Location */
	IRQ_setVecs(0x10000);

	/* Place DMA interrupt service addresses at associate vector
	* 连接两个中断函数*/
	IRQ_plug(xmtEventId,&dmaXmtIsr);
	IRQ_plug(rcvEventId,&dmaRcvIsr);

	/* Write values from configuration structure to DMA control regs */
	DMA_config(hDmaRcv,&dmaRcvConfig);
	DMA_config(hDmaXmt,&dmaXmtConfig);

	/* Enable all maskable interrupts */
	IRQ_globalEnable();

	/* Enable DMA */
	DMA_start(hDmaRcv);
	DMA_start(hDmaXmt);

	/* 获取DMAD的MACCR寄存器ENDPROG字段值,为1表示编程结束。
	*  */
	while(DMA_FGETH(hDmaRcv, DMACCR, ENDPROG));

	/* 表示DMA从pongxmt传数据到pongrcv*/dstAddrHi = (Uint16)(((Uint32)(&pongrcv)) >> 15) & 0xFFFFu;dstAddrLo = (Uint16)(((Uint32)(&pongrcv)) << 1) & 0xFFFFu;dmaRcvConfig.dmacdsal = (DMA_AdrPtr)dstAddrLo;dmaRcvConfig.dmacdsau = dstAddrHi;srcAddrHi = (Uint16)(((Uint32)(&pongxmt[0])) >> 15) & 0xFFFFu;srcAddrLo = (Uint16)(((Uint32)(&pongxmt[0])) << 1) & 0xFFFFu;dmaXmtConfig.dmacssal = (DMA_AdrPtr)srcAddrLo;dmaXmtConfig.dmacssau = srcAddrHi;

	/* 赋值DMAD的MACCR寄存器ENDPROG字段,为1表示编程结束。
	*  */DMA_FSETH(hDmaRcv, DMACCR, ENDPROG,1);DMA_FSETH(hDmaXmt, DMACCR, ENDPROG,1);
}

/*播放声音的中断*/
interrupt void dmaXmtIsr(void) {
	printf("……进入中断dmaXmtIsr……\n");static int * ptr;unsigned int ptraddrhi, ptraddrlow;/* 赋值DMAD的DMACSR寄存器BLOCK字段,为0表示整块时间没有发生,为1表示整块已经传输完毕,一个中断请求已经发送给CPU。*  */DMA_FSETH(hDmaXmt,DMACSR,FRAME,0);if(xfreebuf == xpingbuf){xfreebuf = xpongbuf;ptr = pongxmt;}else{xfreebuf = xpingbuf;ptr = pingxmt;}/* 获取DMAD的MACCR寄存器ENDPROG字段值,为1表示编程结束。*  */while(DMA_FGETH(hDmaXmt, DMACCR, ENDPROG));//修改DMA地址ptraddrhi = (unsigned int)(((unsigned long)(ptr)) >> 15) & 0xFFFFu;//因为DMA都使用字节地址,所以必须左移一位ptraddrlow= (unsigned int)(((unsigned long)(ptr)) << 1) & 0xFFFFu;DMA_RSETH(hDmaXmt, DMACSSAU, ptraddrhi);DMA_RSETH(hDmaXmt, DMACSSAL, ptraddrlow);DMA_FSETH(hDmaXmt, DMACCR, ENDPROG,1);
}

/*接受声音的中断*/
interrupt void dmaRcvIsr(void) {
	printf("……进入中断dmaRcvIsr……\n");
	static int * ptr;unsigned int ptraddrhi, ptraddrlow;DMA_FSETH(hDmaRcv,DMACSR,FRAME,0);if(rfreebuf == rpingbuf){	rfreebuf = rpongbuf;ptr = pongrcv;}else{	rfreebuf = rpingbuf;ptr = pingrcv;}while(DMA_FGETH(hDmaRcv, DMACCR, ENDPROG));//修改DMA地址ptraddrhi = (unsigned int)(((unsigned long)(ptr)) >> 15) & 0xFFFFu;//因为DMA都使用字节地址,所以必须左移一位ptraddrlow= (unsigned int)(((unsigned long)(ptr)) << 1) & 0xFFFFu;DMA_RSETH(hDmaRcv, DMACSSAU, ptraddrhi);DMA_RSETH(hDmaRcv, DMACSSAL, ptraddrlow);DMA_FSETH(hDmaRcv, DMACCR, ENDPROG,1);State_Work = State_Signal_Process;
}

void Signal_Process()
{
	printf("……进入处理函数  Signal_Process……\n");Uint16 i,j=0;if(rfreebuf == rpongbuf){									//(PingPong == PING)for(i=0;i<FRAME_LENGTH;i=i+2){Leftchannel_Buffer[j] = pongrcv[i];Rightchannel_Buffer[j] = pongrcv[i+1];j++;}}else{for(i=0;i<FRAME_LENGTH;i=i+2){Leftchannel_Buffer[j] = pingrcv[i];Rightchannel_Buffer[j] = pingrcv[i+1];j++;}}j = 0;if(xfreebuf == xpongbuf){for(i=0;i<FRAME_LENGTH;i=i+2){pongxmt[i] = Leftchannel_Buffer[j];pongxmt[i+1] = Rightchannel_Buffer[j];j++;}}else{for(i=0;i<FRAME_LENGTH;i=i+2){pingxmt[i] = Leftchannel_Buffer[j];pingxmt[i+1] = Rightchannel_Buffer[j];j++;}}
}

/******************************************************************************/
/* End of main.c*/
/******************************************************************************/
user5155731:

问题描述:

本人使用的是TMS320VC5509A,I2C给AIC23写入配置,McBSP来读取AIC23的数据。经测试,用MCBSP_read16()和MCBSP_write16()函数是可以正常读取、写入的。但是如果加上DMA就不行了,始终进不去中断。

求大神解答。

Shine:

回复 user5155731:

请问中断标志位置起来了吗?

user5155731:

回复 Shine:

请原谅我是新手。

中断标志位怎么看有没有立起来呢?也就是说DMACSR的状态寄存器怎么查看呢?

谢谢!

user5321810:

你现在跑出来了吗?我现在也在使用5509a的板子做声音处理回放,主要是dma和aic23,但是总感觉mic口没用,如果可以的话想和你交流一下。介意给一个联系方式吗?

赞(0)
未经允许不得转载:TI中文支持网 » DSP5509A使用DMA乒乓缓存从McBSP0读取AIC23的数据进入不了中断
分享到: 更多 (0)