5509DMA乒乓缓冲从音频读入并播放。中断无法进入,无声音

[复制链接]
1643|17
 楼主| Katze 发表于 2016-11-9 21:12 | 显示全部楼层 |阅读模式
现正在用TI 5509用DMA乒乓缓冲的方式从音频口读入数据并播放数据。程序中可能有小错误。以至于无声音。并且调试时中断无法进入。还请各位大神帮忙看一下程序。不胜感激,谢谢~~~~
  1. #include <csl.h>
  2. #include <csl_i2c.h>
  3. #include <stdio.h>
  4. #include <csl_pll.h>
  5. #include <csl_mcbsp.h>
  6. #include <csl_dma.h>
  7. #include <csl_irq.h>

  8. //---------Global constants---------
  9. #define N       128

  10. #define CODEC_ADDR 0x1A     //AIC23在I2C总线上的从地址0011010
  11. #pragma DATA_SECTION(aic23data,"dmaMem")
  12. int aic23data ;
  13. int pingrcv[N], pongrcv[N], pingxmt[N], pongxmt[N],Leftchannel_Buffer[N],Rightchannel_Buffer[N];
  14. int xfreebuf,rfreebuf,xpongbuf,rpongbuf,xpingbuf,rpingbuf;
  15. int xmtEventId,rcvEventId;
  16. Uint16 i,temp;
  17. Uint16 i2c_status;
  18. I2C_Config testI2C;
  19. MCBSP_Handle hMcbsp;
  20. DMA_Handle hDmaRcv, hDmaXmt;
  21. int RecvComplete;
  22. Uint16 dmaXmtIsr_count=0;            //计数进入传送中断的次数
  23. Uint16 dmaRcvIsr_count=0;            //计数进入接收中断的次数
  24. Uint16 sin=0;                        //计数进入signal函数的次数

  25. interrupt void dmaXmtIsr(void);
  26. interrupt void dmaRcvIsr(void);
  27. extern void VECSTART(void);            

  28. /*锁相环的设置*/
  29. PLL_Config  myConfig      = {
  30.   0,    //IAI: the PLL locks using the same process that was underway
  31.                 //before the idle mode was entered
  32.   1,    //IOB: If the PLL indicates a break in the phase lock,
  33.                 //it switches to its bypass mode and restarts the PLL phase-locking
  34.                 //sequence
  35.   24,    //PLL multiply value; multiply 24 times
  36.   1             //Divide by 2 PLL divide value; it can be either PLL divide value
  37.                 //(when PLL is enabled), or Bypass-mode divide value
  38.                 //(PLL in bypass mode, if PLL multiply value is set to 1)
  39. };


  40. /*******************************************************************************************/
  41. /**********************************MCBSP设置************************************************/



  42. MCBSP_Config Mcbsptest;
  43. /*McBSP set,we use mcbsp1 to send and recieve the data between DSP and AIC23*/
  44. MCBSP_Config Mcbsp1Config= {

  45.   MCBSP_SPCR1_RMK(

  46.    // MCBSP_SPCR1_DLB_OFF,                   /* DLB    = 0,禁止自闭环方式 */
  47.         MCBSP_SPCR1_DLB_ON,                    /* DLB    = 1 */
  48.     //MCBSP_SPCR1_RJUST_LZF,                 /* RJUST  = 2 left justify the data and zero fill LSBS */
  49.     MCBSP_SPCR1_RJUST_RZF,                 /* RJUST  = 0 */
  50.     MCBSP_SPCR1_CLKSTP_DISABLE,            /* CLKSTP = 0 Clock stop mode disable */
  51.     //MCBSP_SPCR1_DXENA_ON,                  /* DXENA  = 1 DX delay enabler on */
  52.     MCBSP_SPCR1_DXENA_NA,                  /* DXENA  = 0 */
  53.     MCBSP_SPCR1_ABIS_DISABLE,              /* ABIS   = 0 reserved always write 0*/
  54.     MCBSP_SPCR1_RINTM_RRDY,                /* RINTM  = 0 sends a receive INT request to CPU when the RRDY bit
  55.                                             change from 0 to 1, indicating that receive data is ready to be read*/

  56.     0,                                     /* RSYNCER = 0 receive frame-sync error bit, no error*/

  57.     MCBSP_SPCR1_RRST_DISABLE               /* RRST   = 0 reset the receiver*/

  58.        ),

  59.     MCBSP_SPCR2_RMK(

  60.     MCBSP_SPCR2_FREE_NO,                   /* FREE   = 0 free run bit, The McBSP transmit and receive clocks are affected as determined by the SOFT bit*/
  61.     MCBSP_SPCR2_SOFT_NO,                   /* SOFT   = 0 Soft stop bit, Hard stop*/
  62.     MCBSP_SPCR2_FRST_FSG,                  /* FRST   = 0 Frame-sync logic reset bit*/
  63.     MCBSP_SPCR2_GRST_CLKG,                 /* GRST   = 0 Sample rate generator reset bit */
  64.     MCBSP_SPCR2_XINTM_XRDY,                /* XINTM  = 0 transmit interrupt mode bits XRDY bit changes from 0 to1 */
  65.     0,                                     /* XSYNCERR = N/A transmit frame-sync error bit, no error*/           
  66.     MCBSP_SPCR2_XRST_DISABLE               /* XRST   = 0 transmit ready bit, not ready*/

  67.        //注意:开始一定要设置为disable,否则不能设置它的寄存器,全部为默认值,导致不能正常接收,
  68.        //在程序调用C库函数mcbspstart时会在设为1,McBSP便退出reset状态开始工作

  69.    ),

  70.     /*单数据相,接受数据长度为16位,每相2个数据*/

  71.   MCBSP_RCR1_RMK(

  72.     //MCBSP_RCR1_RFRLEN1_OF(1),               /* RFRLEN1 = 1 Receive frame length 1 bits(1 to 128 words),Frame length=(RFRLEN1+1)words*/
  73.     MCBSP_RCR1_RFRLEN1_OF(0),                /* RFRLEN1 = 0 */
  74.     MCBSP_RCR1_RWDLEN1_16BIT               /* RWDLEN1 = 2 Receive word length 1 bits, 16bit*/

  75.   ),

  76. MCBSP_RCR2_RMK(   

  77.     MCBSP_RCR2_RPHASE_SINGLE,              /* RPHASE  = 0 Receive phase number bit, single-phase frame*/
  78.     MCBSP_RCR2_RFRLEN2_OF(0),              /* RFRLEN2 = 0 */
  79.     MCBSP_RCR2_RWDLEN2_8BIT,               /* RWDLEN2 = 0 */
  80.     MCBSP_RCR2_RCOMPAND_MSB,               /* RCOMPAND = 0 receive companding mode bits, 0, no companding,MSB received first*/
  81.     MCBSP_RCR2_RFIG_YES,                   /* RFIG    = 0 Receive frame-sync ignore bit, 1, frame-sync detect */
  82.     //MCBSP_RCR2_RDATDLY_1BIT                /* RDATDLY = 1 Receive data delay bits, 1-bit data delay*/
  83.     MCBSP_RCR2_RDATDLY_0BIT                /* RDATDLY = 0 */

  84.     ),

  85.    MCBSP_XCR1_RMK(   

  86.     //MCBSP_XCR1_XFRLEN1_OF(1),              /* XFRLEN1 = 1 Transmit frame length 1(1 to 128 words),Frame length=(XFRLEN1+1)words */
  87.         MCBSP_XCR1_XFRLEN1_OF(0),              /* XFRLEN1 = 0 */
  88.     MCBSP_XCR1_XWDLEN1_16BIT               /* XWDLEN1 = 2 Transmit word length 1.16bit*/
  89.    ),  

  90. MCBSP_XCR2_RMK(  

  91.     MCBSP_XCR2_XPHASE_SINGLE,              /* XPHASE  = 0 Transmit phase number bit, single-phase frame*/
  92.     MCBSP_XCR2_XFRLEN2_OF(0),              /* XFRLEN2 = 0 */
  93.     MCBSP_XCR2_XWDLEN2_8BIT,               /* XWDLEN2 = 0 */
  94.     MCBSP_XCR2_XCOMPAND_MSB,               /* XCOMPAND = 0 Transmit companding mode bits, 0, no companding,MSB received first*/
  95.     MCBSP_XCR2_XFIG_YES,                   /* XFIG    = 0 Transmit frame-sync ignore bit, 1, frame-sync detect */
  96.     //MCBSP_XCR2_XDATDLY_1BIT                /* XDATDLY = 1 Transmit data delay bits, 1-bit data delay*/
  97.     MCBSP_XCR2_XDATDLY_0BIT                /* XDATDLY = 0 */

  98.   ),  

  99. //MCBSP_SRGR1_DEFAULT,                      /*(0x0001u)FWID=0,CLKGDV=1 */
  100. MCBSP_SRGR1_RMK(
  101.    MCBSP_SRGR1_FWID_OF(1),                /* FWID    = 1 */
  102.    MCBSP_SRGR1_CLKGDV_OF(1)               /* CLKGDV  = 1 */
  103. ),   
  104. //MCBSP_SRGR2_DEFAULT,                      /*(0x2000u)CLKSM=1,Sample rate generator input clock mode bit */
  105. MCBSP_SRGR2_RMK(  
  106.     MCBSP_SRGR2_GSYNC_FREE,                /* FREE    = 0 */
  107.     MCBSP_SRGR2_CLKSP_RISING,              /* CLKSP   = 0 */
  108.     MCBSP_SRGR2_CLKSM_INTERNAL,            /* CLKSM   = 1 */
  109.     MCBSP_SRGR2_FSGM_DXR2XSR,              /* FSGM    = 0 */
  110.     MCBSP_SRGR2_FPER_OF(15)                /* FPER    = 0 */
  111. ),   
  112. MCBSP_MCR1_DEFAULT,
  113. MCBSP_MCR2_DEFAULT,

  114. MCBSP_PCR_RMK(

  115.    MCBSP_PCR_IDLEEN_RESET,                 /* IDLEEN   = 0 The McBSP remains active when the PERIPH domain is idled */
  116.    MCBSP_PCR_XIOEN_SP,                     /* XIOEN    = 0 Transmit I/O enable bit, CLKX,FSX,DX,CLKS pins are serial port pins*/
  117.    MCBSP_PCR_RIOEN_SP,                     /* RIOEN    = 0 Receive I/O enable bit, CLKR,FSR,DR,CLKS pins are serial port pins*/
  118.    //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*/
  119.    MCBSP_PCR_FSXM_INTERNAL,                /* FSXM     = 1   */
  120.    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*/

  121.    0,                                      /* DXSTAT = N/A   */

  122.    //MCBSP_PCR_CLKXM_INPUT,                  /* CLKXM    = 0 Transmit clock mode bit*/
  123.    MCBSP_PCR_CLKXM_OUTPUT,                 /* CLKXM    = 1   */
  124.    MCBSP_PCR_CLKRM_INPUT,                  /* CLKRM    = 0 Receive clock mode bit*/
  125.    MCBSP_PCR_SCLKME_NO,                    /* SCLKME   = 0 Sample rate generator input clock mode bit,used with CLKSM to select the input clock*/
  126.    MCBSP_PCR_FSXP_ACTIVEHIGH,              /* FSXP     = 0 Transmit frame-sync polarity bit, 0,transmit frame-sync pulses are active high*/
  127.    MCBSP_PCR_FSRP_ACTIVEHIGH,              /* FSRP     = 1 Receive frame-sync polarity bit, 0,receive frame-sync pulses are active high*/
  128.    //MCBSP_PCR_CLKXP_FALLING,                /* CLKXP    = 1 Transmit clock polarity bit,1,transmit data is driven on the rising edge of CLKX */
  129.    MCBSP_PCR_CLKXP_RISING,                 /* CLKXP    = 0   */
  130.    //MCBSP_PCR_CLKRP_RISING                  /* CLKRP    = 1 Receive clock polarity bit*/
  131.    MCBSP_PCR_CLKRP_FALLING                 /* CLKRP    = 0   */
  132. ),

  133. MCBSP_RCERA_DEFAULT,
  134. MCBSP_RCERB_DEFAULT,
  135. MCBSP_RCERC_DEFAULT,
  136. MCBSP_RCERD_DEFAULT,
  137. MCBSP_RCERE_DEFAULT,
  138. MCBSP_RCERF_DEFAULT,
  139. MCBSP_RCERG_DEFAULT,
  140. MCBSP_RCERH_DEFAULT,
  141. MCBSP_XCERA_DEFAULT,
  142. MCBSP_XCERB_DEFAULT,
  143. MCBSP_XCERC_DEFAULT,
  144. MCBSP_XCERD_DEFAULT,
  145. MCBSP_XCERE_DEFAULT,
  146. MCBSP_XCERF_DEFAULT,
  147. MCBSP_XCERG_DEFAULT,
  148. MCBSP_XCERH_DEFAULT

  149. };   

 楼主| Katze 发表于 2016-11-9 21:12 | 显示全部楼层
  1. /*******************************************************************************************/
  2. /************************************DMA设置************************************************/



  3. /* Create DMA Receive Side Configuration */

  4. DMA_Config  dmaRcvConfig = {

  5.   DMA_DMACSDP_RMK(

  6.     DMA_DMACSDP_DSTBEN_NOBURST,    //Destination burst :-不使用突发
  7.     DMA_DMACSDP_DSTPACK_OFF,       //Destination packing :-目标口禁止打包
  8.     DMA_DMACSDP_DST_DARAM,         //Destination selection :-接收的目标口是DARAM
  9.     DMA_DMACSDP_SRCBEN_NOBURST,    //Source burst :-源突发禁止
  10.     DMA_DMACSDP_SRCPACK_OFF,       //Source packing :-源口禁止打包
  11.     DMA_DMACSDP_SRC_PERIPH,        //Source selection :-外设mcbsp
  12.     DMA_DMACSDP_DATATYPE_16BIT     //Data type :-设置数据类型16bit字长

  13.   ),                                /* DMACSDP 源与目标参数寄存器 */

  14.   DMA_DMACCR_RMK(

  15.     DMA_DMACCR_DSTAMODE_POSTINC,    //Destination address mode :-自动执行后增量(由于本程序中数据类型是16bit,所以+2)
  16.     DMA_DMACCR_SRCAMODE_CONST,      //Source address mode :-源地址为恒定地址
  17.     DMA_DMACCR_ENDPROG_ON,          //End of programmation bit :-

  18.     //DMA_DMACCR_REPEAT_ON,           //Repeat condition :-不管编程配置结束位,结束传输自动初始化开始

  19.     DMA_DMACCR_REPEAT_OFF,
  20.     DMA_DMACCR_AUTOINIT_ON,         //Auto initialization bit :-
  21.         //DMA_DMACCR_AUTOINIT_OFF,
  22.     DMA_DMACCR_EN_STOP,             //Channel enable :-设置时先关闭通道
  23.     DMA_DMACCR_PRIO_LOW,            //Channel priority :-设置为低优先级
  24.     DMA_DMACCR_FS_ELEMENT,          //Frame/Element Sync :-单元事件同步
  25.         //DMA_DMACCR_FS_DISABLE,
  26.     DMA_DMACCR_SYNC_REVT1           //Synchronization control :-McBSP1 Receive Event(REVT1)

  27.   ),                                       /* DMACCR 通道控制寄存器  */

  28.   DMA_DMACICR_RMK(

  29.     DMA_DMACICR_BLOCKIE_ON,       //Whole block interrupt enable :-块传输完成后中断使能
  30.     //DMA_DMACICR_BLOCKIE_OFF,
  31.     DMA_DMACICR_LASTIE_OFF,       //Last frame interrupt enable :-
  32.     DMA_DMACICR_FRAMEIE_OFF,      //Whole frame interrupt enable :-
  33.         //DMA_DMACICR_FRAMEIE_ON,
  34.     DMA_DMACICR_FIRSTHALFIE_OFF,  //Half frame interrupt enable :-
  35.     DMA_DMACICR_DROPIE_OFF,       //Sync. event drop interrupt enable :-
  36.     DMA_DMACICR_TIMEOUTIE_OFF     //Time out interrupt enable :-

  37.   ),                                       /* DMACICR 中断控制寄存器 */

  38.     (DMA_AdrPtr)(MCBSP_ADDR(DRR11)),       /* DMACSSAL 源地址低位 */
  39.     0,                                     /* DMACSSAU 源地址高位*/
  40.     (DMA_AdrPtr)&pingrcv,                  /* DMACDSAL 目的地址低位*/
  41.     0,                                     /* DMACDSAU 目的地址高位*/
  42.     2,                                     /* DMACEN   1 帧内数据长度 16*2 两个数据一个帧*/
  43.     N/2,                                   /* DMACFN  帧数大小 */
  44.     0,                                     /* DMACFI  */
  45.     0                                      /* DMACEI  */

  46.   };

  47. /* Create DMA Transmit Side Configuration */

  48. DMA_Config  dmaXmtConfig = {

  49.   DMA_DMACSDP_RMK(

  50.     DMA_DMACSDP_DSTBEN_NOBURST,    //Destination burst :-不使用突发
  51.     DMA_DMACSDP_DSTPACK_OFF,       //Destination packing :-目标口禁止打包
  52.     DMA_DMACSDP_DST_PERIPH,        //Destination selection :-接收的目标口是外设mcbsp
  53.     DMA_DMACSDP_SRCBEN_NOBURST,    //Source burst :-源突发禁止
  54.     DMA_DMACSDP_SRCPACK_OFF,       //Source packing :-源口禁止打包
  55.     DMA_DMACSDP_SRC_DARAM,         //Source selection :源口为DARAM
  56.     DMA_DMACSDP_DATATYPE_16BIT     //Data type :-设置数据类型16bit字长

  57.   ),                                       /* DMACSDP  源与目标参数寄存器 */

  58.   DMA_DMACCR_RMK(

  59.     DMA_DMACCR_DSTAMODE_CONST,    //Destination address mode :-目标口地址为恒定地址
  60.     DMA_DMACCR_SRCAMODE_POSTINC,  //Source address mode :-自动执行后增量(由于本程序中数据类型是16bit,所以+2)
  61.     DMA_DMACCR_ENDPROG_ON,        //End of programmation bit :-

  62.     //DMA_DMACCR_REPEAT_ON,         //Repeat condition :-不管编程配置结束位,结束传输自动初始化开始

  63.     DMA_DMACCR_REPEAT_OFF,
  64.     DMA_DMACCR_AUTOINIT_ON,       //Auto initialization bit :-
  65.     //DMA_DMACCR_AUTOINIT_OFF,
  66.     DMA_DMACCR_EN_STOP,           //Channel enable :-设置时先关闭通道
  67.     DMA_DMACCR_PRIO_LOW,          //Channel priority :-设置为低优先级
  68.     DMA_DMACCR_FS_ELEMENT,        //Frame/Element Sync :-单元事件同步
  69.         //DMA_DMACCR_FS_DISABLE,
  70.     DMA_DMACCR_SYNC_XEVT1         //Synchronization control :-McBSP1 Transmit Event(XEVT1)
  71.   ),                                       /* DMACCR 通道控制寄存器   */

  72.   DMA_DMACICR_RMK(

  73.     DMA_DMACICR_BLOCKIE_ON,       //Whole block interrupt enable :-块传输完成后中断使能
  74.     //DMA_DMACICR_BLOCKIE_OFF,
  75.     DMA_DMACICR_LASTIE_OFF,       //Last frame interrupt enable :-
  76.     DMA_DMACICR_FRAMEIE_OFF,       //Whole frame interrupt enable :-
  77.     //DMA_DMACICR_FRAMEIE_ON,
  78.     DMA_DMACICR_FIRSTHALFIE_OFF,  //Half frame interrupt enable :-
  79.     DMA_DMACICR_DROPIE_OFF,       //Sync. event drop interrupt enable :-
  80.     DMA_DMACICR_TIMEOUTIE_OFF     //Time out interrupt enable :-

  81.   ),                                       /* DMACICR 中断控制寄存器 */

  82.     (DMA_AdrPtr)&pingxmt[0],               /* DMACSSAL 源地址低位*/
  83.     0,                                     /* DMACSSAU 源地址高位 */
  84.     (DMA_AdrPtr)(MCBSP_ADDR(DXR11)),       /* DMACDSAL 目的地址低位*/
  85.     0,                                     /* DMACDSAU 目的地址高位*/
  86.     2,                                     /* DMACEN   1 帧内数据长度 16*2 两个数据一个帧*/
  87.     N/2,                                   /* DMACFN  帧数大小  */
  88.     0,                                     /* DMACFI   */
  89.     0                                      /* DMACEI   */

  90. };

 楼主| Katze 发表于 2016-11-9 21:14 | 显示全部楼层
  1. /*******************************************************************************************/
  2. /***********************************I2C的设置和AIC的设置************************************/



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


  14. /*数字音频接口格式设置
  15. AIC23为主模式,数据为DSP模式,数据长度16位*/   
  16. Uint16 digital_audio_inteface_format[2]={0x0e,0x53};
  17. /*AIC23的波特率设置,采样率为44.1K*/
  18. Uint16 sample_rate_control[2] = {0x10,0x23};
  19. /*AIC23寄存器复位*/
  20. Uint16 reset[2] ={0x1e,0x00};
  21. /*AIC23节电方式设置,所有部分均所与工作状态*/
  22. Uint16 power_down_control[2] ={0x0c,0x00};

  23. /*AIC23模拟音频的控制
  24. DAC使能,ADC输入选择为mic*/
  25. Uint16 analog_aduio_path_control[2] ={0x08,0x15};
  26. //Uint16 analog_aduio_path_control[2] ={0x08,0x14};//MIC IN 无增益
  27. //Uint16 analog_aduio_path_control[2] ={0x08,0x10};//Line IN

  28. /*AIC23数字音频通路的控制*/
  29. Uint16 digital_audio_path_control[2] ={0x0a,0x05};
  30. /*AIC23数字接口的使能*/
  31. Uint16 digital_interface_activation[2] ={0x12,0x01};
  32. /*AIC23左通路音频调节*/
  33. Uint16 left_line_input_volume_control[2] ={0x00,0x17};
  34. /*AIC23右通路音频调节*/
  35. Uint16 right_line_input_volume_control[2] ={0x02,0x17};
  36. /*AIC23耳机左通路音频调节*/
  37. Uint16 left_headphone_volume_control[2] ={0x05,0xFF};
  38. /*AIC23耳机右通路音频调节*/
  39. Uint16 right_headphone_volume_control[2] = {0x07,0xFF};



  40. /*******************************************************************************************/
  41. /*******************************************************************************************/



  42. void delay(Uint32 k)
  43. {
  44.    while(k--);
  45. }



  46. /*******************************************************************************************/
  47. /*******************************************************************************************/



  48. void CODEC(void)
  49. {

  50.         /*I2C is undet reset*/
  51.         I2C_RSET(I2CMDR,0);
  52.         /*设置预分频寄存器,I2C的mode clock is 10MHz*/
  53.         delay(100);
  54.         I2C_RSET(I2CSAR,0x001A);
  55.         I2C_RSET(I2CMDR,0x0620);       
  56.     I2C_setup(&I2Cinit);
  57.           /*设置I2C的Mater clock*/
  58.         I2C_RSET(I2CCLKL,100);
  59.         I2C_RSET(I2CCLKH,100);
  60.     I2C_getConfig(&testI2C);


  61.     /*reset AIC23*/
  62.     i2c_status = I2C_write( reset,          //pointer to data array
  63.                                     2,                                //length of data to be transmitted
  64.                                     1,                                //master or slaver
  65.                                     CODEC_ADDR,            //slave address to transmit to
  66.                                     1,                                //transfer mode of operation
  67.                                     30000                        //time out for bus busy
  68.                                         );
  69.         delay(1000);
  70.     /*设置AIC23各部分均工作*/
  71.     i2c_status = I2C_write( power_down_control,//pointer to data array
  72.                                     2,                                //length of data to be transmitted
  73.                                     1,                                //master or slaver
  74.                                     CODEC_ADDR,            //slave address to transmit to
  75.                                     1,                                //transfer mode of operation
  76.                                     30000                        //time out for bus busy
  77.                                         );            
  78.         /*设置AIC23的数字接口*/
  79.         i2c_status = I2C_write( digital_audio_inteface_format,//pointer to data array
  80.                                     2,                                //length of data to be transmitted
  81.                                     1,                                //master or slaver
  82.                                     CODEC_ADDR,            //slave address to transmit to
  83.                                     1,                                //transfer mode of operation
  84.                                     30000                        //time out for bus busy
  85.                                            );
  86.          /*设置AIC23模拟通路*/
  87.         i2c_status = I2C_write( analog_aduio_path_control,//pointer to data array
  88.                                     2,                                //length of data to be transmitted
  89.                                     1,                                //master or slaver
  90.                                     CODEC_ADDR,            //slave address to transmit to
  91.                                     1,                                //transfer mode of operation
  92.                                     30000                        //time out for bus busy
  93.                                         );
  94.         /*设置数字通路*/
  95.         i2c_status = I2C_write( digital_audio_path_control,//pointer to data array
  96.                                     2,                                //length of data to be transmitted
  97.                                     1,                                //master or slaver
  98.                                     CODEC_ADDR,            //slave address to transmit to
  99.                                     1,                                //transfer mode of operation
  100.                                     30000                        //time out for bus busy
  101.                                           );           
  102.         /*设置AIC23的采样率*/
  103.         i2c_status = I2C_write( sample_rate_control,//pointer to data array
  104.                                     2,                                //length of data to be transmitted
  105.                                     1,                                //master or slaver
  106.                                     CODEC_ADDR,            //slave address to transmit to
  107.                                     1,                                //transfer mode of operation
  108.                                     30000                        //time out for bus busy
  109.                                     );
  110.         /*设置耳机音量*/
  111.         i2c_status = I2C_write( left_headphone_volume_control,//pointer to data array
  112.                                     2,                                //length of data to be transmitted
  113.                                     1,                                //master or slaver
  114.                                     CODEC_ADDR,            //slave address to transmit to
  115.                                     1,                                //transfer mode of operation
  116.                                     30000                        //time out for bus busy
  117.                                     );
  118.         i2c_status = I2C_write( right_headphone_volume_control,//pointer to data array
  119.                                     2,                                //length of data to be transmitted
  120.                                     1,                                //master or slaver
  121.                                     CODEC_ADDR,            //slave address to transmit to
  122.                                     1,                                //transfer mode of operation
  123.                                     30000                        //time out for bus busy
  124.                                     );  
  125.         /*设置Line输入的音量*/
  126.         i2c_status = I2C_write( left_line_input_volume_control,//pointer to data array
  127.                                     2,                                //length of data to be transmitted
  128.                                     1,                                //master or slaver
  129.                                     CODEC_ADDR,            //slave address to transmit to
  130.                                     1,                                //transfer mode of operation
  131.                                     30000                        //time out for bus busy
  132.                                     );
  133.         i2c_status = I2C_write( right_line_input_volume_control,//pointer to data array
  134.                                     2,                                //length of data to be transmitted
  135.                                     1,                                //master or slaver
  136.                                     CODEC_ADDR,            //slave address to transmit to
  137.                                     1,                                //transfer mode of operation
  138.                                     30000                        //time out for bus busy
  139.                                     );
  140.         /*启动AIC23*/
  141.         i2c_status = I2C_write( digital_interface_activation,//pointer to data array
  142.                        2,                                //length of data to be transmitted
  143.                        1,                                //master or slaver
  144.                        CODEC_ADDR,            //slave address to transmit to
  145.                        1,                                //transfer mode of operation
  146.                        30000                        //time out for bus busy
  147.                        );
  148. }
 楼主| Katze 发表于 2016-11-9 21:14 | 显示全部楼层
  1. /*******************************************************************************************/
  2. /********************DMA地址、MCBSP打开、中断向量、打开DMA**********************************/


  3. void AIC23_DataTransfer_Init()
  4. {

  5.     Uint16 i;
  6.     Uint16 srcAddrHi, srcAddrLo;
  7.     Uint16 dstAddrHi, dstAddrLo;

  8.     for(i=0;i<N;i++)

  9.        {

  10.            pingrcv[i] = 0;
  11.            pongrcv[i] = 0;
  12.            pingxmt[i] = 0;
  13.            pongxmt[i] = 0;

  14.        }



  15.     /* By default, the TMS320C55xx compiler assigns all data symbols word */

  16.     /* addresses. The DMA however, expects all addresses to be byte       */

  17.     /* addresses. Therefore, we must shift the address by 2 in order to   */

  18.     /* change the word address to a byte address for the DMA transfer.    */

  19.     srcAddrHi = (Uint16)(((Uint32)(MCBSP_ADDR(DRR11))) >> 15) & 0xFFFFu;
  20.     srcAddrLo = (Uint16)(((Uint32)(MCBSP_ADDR(DRR11))) << 1) & 0xFFFFu;
  21.     dstAddrHi = (Uint16)(((Uint32)(&pingrcv)) >> 15) & 0xFFFFu;
  22.     dstAddrLo = (Uint16)(((Uint32)(&pingrcv)) << 1) & 0xFFFFu;



  23.     dmaRcvConfig.dmacssal = (DMA_AdrPtr)srcAddrLo;
  24.     dmaRcvConfig.dmacssau = srcAddrHi;
  25.     dmaRcvConfig.dmacdsal = (DMA_AdrPtr)dstAddrLo;
  26.     dmaRcvConfig.dmacdsau = dstAddrHi;



  27.     srcAddrHi = (Uint16)(((Uint32)(&pingxmt[0])) >> 15) & 0xFFFFu;
  28.     srcAddrLo = (Uint16)(((Uint32)(&pingxmt[0])) << 1) & 0xFFFFu;
  29.     dstAddrHi = (Uint16)(((Uint32)(MCBSP_ADDR(DXR11))) >> 15) & 0xFFFFu;
  30.     dstAddrLo = (Uint16)(((Uint32)(MCBSP_ADDR(DXR11))) << 1) & 0xFFFFu;



  31.     dmaXmtConfig.dmacssal = (DMA_AdrPtr)srcAddrLo;
  32.     dmaXmtConfig.dmacssau = srcAddrHi;
  33.     dmaXmtConfig.dmacdsal = (DMA_AdrPtr)dstAddrLo;
  34.     dmaXmtConfig.dmacdsau = dstAddrHi;



  35.     /* Open MCBSP Port 1 and set registers to their power on defaults */

  36.     hMcbsp = MCBSP_open(MCBSP_PORT1, MCBSP_OPEN_RESET);



  37.     /* Open DMA channels 4 & 5 and set regs to power on defaults */

  38.     hDmaRcv = DMA_open(DMA_CHA4,DMA_OPEN_RESET);
  39.     hDmaXmt = DMA_open(DMA_CHA5,DMA_OPEN_RESET);



  40.     /* Get interrupt event associated with DMA receive and transmit */

  41.     xmtEventId = DMA_getEventId(hDmaXmt);
  42.     rcvEventId = DMA_getEventId(hDmaRcv);

  43.    

  44.     /* Temporarily disable interrupts and clear any pending */

  45.     /* interrupts for MCBSP transmit */

  46.     //old_intm = IRQ_globalDisable();

  47.    

  48.     /* Clear any pending interrupts for DMA channels */

  49.     IRQ_clear(xmtEventId);
  50.     IRQ_clear(rcvEventId);



  51.     /* Enable DMA interrupt in IER register */

  52.     IRQ_enable(xmtEventId);
  53.     IRQ_enable(rcvEventId);



  54.     /* Set Start Of Interrupt Vector Table */

  55.     IRQ_setVecs(0x10000);

  56.    

  57.     /* Place DMA interrupt service addresses at associate vector */

  58.     IRQ_plug(xmtEventId,&dmaXmtIsr);
  59.     IRQ_plug(rcvEventId,&dmaRcvIsr);



  60.     /* Write values from configuration structure to MCBSP control regs */

  61.     MCBSP_config(hMcbsp, &Mcbsp1Config);

  62.    

  63.     /* Write values from configuration structure to DMA control regs */

  64.     DMA_config(hDmaRcv,&dmaRcvConfig);
  65.     DMA_config(hDmaXmt,&dmaXmtConfig);



  66.        xfreebuf = xpongbuf;
  67.        rfreebuf = rpongbuf;

  68. /* Enable all maskable interrupts */

  69.     IRQ_globalEnable();

  70.    

  71.     /* Start Sample Rate Generator and Enable Frame Sync */

  72.     MCBSP_start(hMcbsp,

  73.                 MCBSP_SRGR_START | MCBSP_SRGR_FRAMESYNC,

  74.                 0x300u);

  75.                

  76.     /* Enable DMA */

  77.     DMA_start(hDmaRcv);
  78.     DMA_start(hDmaXmt);

  79.    

  80.     /* Take MCBSP transmit and receive out of reset */

  81.     MCBSP_start(hMcbsp,

  82.                 MCBSP_XMIT_START | MCBSP_RCV_START,

  83.                 0u);

  84.        while(DMA_FGETH(hDmaRcv, DMACCR, ENDPROG));

  85.     dstAddrHi = (Uint16)(((Uint32)(&pongrcv)) >> 15) & 0xFFFFu;
  86.     dstAddrLo = (Uint16)(((Uint32)(&pongrcv)) << 1) & 0xFFFFu;
  87.     dmaRcvConfig.dmacdsal = (DMA_AdrPtr)dstAddrLo;
  88.     dmaRcvConfig.dmacdsau = dstAddrHi;

  89.       

  90.     srcAddrHi = (Uint16)(((Uint32)(&pongxmt[0])) >> 15) & 0xFFFFu;
  91.     srcAddrLo = (Uint16)(((Uint32)(&pongxmt[0])) << 1) & 0xFFFFu;
  92.     dmaXmtConfig.dmacssal = (DMA_AdrPtr)srcAddrLo;
  93.     dmaXmtConfig.dmacssau = srcAddrHi;

  94.    

  95.        DMA_FSETH(hDmaRcv, DMACCR, ENDPROG,1);

  96.        DMA_FSETH(hDmaXmt, DMACCR, ENDPROG,1);

  97. }
 楼主| Katze 发表于 2016-11-9 21:15 | 显示全部楼层
  1. /*******************************************************************************************/
  2. /*******************************************************************************************/



  3. interrupt void dmaRcvIsr(void)
  4. {

  5.        static int * ptr;
  6.        unsigned int ptraddrhi, ptraddrlow;

  7.        DMA_FSETH(hDmaRcv,DMACSR,BLOCK,0);
  8.        RecvComplete=0;      
  9.            dmaRcvIsr_count++;
  10.        if(rfreebuf == rpingbuf)
  11.        {
  12.          rfreebuf = rpongbuf;
  13.          ptr = pongrcv;
  14.        }

  15.        else
  16.        {
  17.          rfreebuf = rpingbuf;
  18.          ptr = pingrcv;
  19.        }

  20.        while(DMA_FGETH(hDmaRcv, DMACCR, ENDPROG));

  21.        //修改DMA地址
  22.        ptraddrhi = (unsigned int)(((unsigned long)(ptr)) >> 15) & 0xFFFFu;

  23.        //因为DMA都使用字节地址,所以必须左移一位

  24.        ptraddrlow= (unsigned int)(((unsigned long)(ptr)) << 1) & 0xFFFFu;

  25.        //dmaRcvConfig.dmacdsal = (DMA_AdrPtr)ptraddrlow;
  26.        //dmaRcvConfig.dmacdsau = ptraddrhi;
  27.        DMA_RSETH(hDmaRcv, DMACSSAU, ptraddrhi);
  28.        DMA_RSETH(hDmaRcv, DMACSSAL, ptraddrlow);
  29.        DMA_FSETH(hDmaRcv, DMACCR, ENDPROG,1);
  30. }



  31. /*******************************************************************************************/
  32. /*******************************************************************************************/



  33. interrupt void dmaXmtIsr(void)
  34. {
  35.        static int * ptr;
  36.        unsigned int ptraddrhi, ptraddrlow;

  37.        DMA_FSETH(hDmaXmt,DMACSR,BLOCK,0);
  38.        RecvComplete=1;               //!!!!!!!!!
  39.        dmaXmtIsr_count++;                //!!!!!!!!!!!
  40.        if(xfreebuf == xpingbuf)
  41.        {
  42.               xfreebuf = xpongbuf;
  43.               ptr = pongxmt;
  44.        }

  45.        else
  46.        {
  47.               xfreebuf = xpingbuf;
  48.               ptr = pingxmt;
  49.        }

  50.        while(DMA_FGETH(hDmaXmt, DMACCR, ENDPROG));

  51.        //修改DMA地址

  52.         ptraddrhi = (unsigned int)(((unsigned long)(ptr)) >> 15) & 0xFFFFu;

  53.        //因为DMA都使用字节地址,所以必须左移一位

  54.         ptraddrlow= (unsigned int)(((unsigned long)(ptr)) << 1) & 0xFFFFu;

  55.        //dmaXmtConfig.dmacssal = (DMA_AdrPtr)ptraddrlow;//这个地方改了一下,请注意
  56.        //dmaXmtConfig.dmacssau = ptraddrhi;

  57.        DMA_RSETH(hDmaXmt, DMACSSAU, ptraddrhi);
  58.        DMA_RSETH(hDmaXmt, DMACSSAL, ptraddrlow);
  59.        DMA_FSETH(hDmaXmt, DMACCR, ENDPROG,1);
  60. }



  61. /*******************************************************************************************/
  62. /*******************************************************************************************/


  63. void Signal_Process()
  64. {      Uint16 i,j=0;
  65.        sin++;
  66.        if(rfreebuf == rpongbuf)//(PingPong == PING)
  67.        {
  68.            for(i=0;i<N;i=i+2)
  69.               {

  70.                 Leftchannel_Buffer[j] = pongrcv[i];
  71.                 Rightchannel_Buffer[j] = pongrcv[i+1];
  72.                 j++;
  73.               }
  74.        }

  75.        else
  76.        {
  77.            for(i=0;i<N;i=i+2)

  78.               {
  79.                  Leftchannel_Buffer[j] = pingrcv[i];
  80.                  Rightchannel_Buffer[j] = pingrcv[i+1];
  81.                  j++;
  82.               }
  83.    }

  84.        j = 0;
  85.        if(xfreebuf == xpongbuf)

  86.        {
  87.               for(i=0;i<N;i=i+2)

  88.               {
  89.                 pongxmt[i] = Leftchannel_Buffer[j];
  90.                 pongxmt[i+1] = Rightchannel_Buffer[j];
  91.                 j++;
  92.               }
  93.        }

  94.        else
  95.        {
  96.               for(i=0;i<N;i=i+2)
  97.               {
  98.                 pingxmt[i] = Leftchannel_Buffer[j];
  99.                 pingxmt[i+1] = Rightchannel_Buffer[j];
  100.                 j++;
  101.               }
  102.        }
  103. }



  104. /*******************************************************************************************/
  105. /*******************************************************************************************/



  106. void main()
  107. {
  108. /* Initialize CSL library - This is REQUIRED !!! */
  109.      /*初始化CSL库*/   
  110.       CSL_init();
  111.      /*设置系统的运行速度为140MHz*/       
  112.       IRQ_setVecs((Uint32)(&VECSTART));
  113.       PLL_config(&myConfig);
  114.       AIC23_DataTransfer_Init();
  115.       CODEC();
  116.       while(1)
  117.          {
  118.       if (RecvComplete==1)
  119.           {
  120.           Signal_Process();
  121.       }
  122.          }

  123. }



  124. /*************************************end***************************************************/
  125. /*******************************************************************************************/
zhangmangui 发表于 2016-11-9 22:07 | 显示全部楼层
这么长   一时半会看不出啊
zhangmangui 发表于 2016-11-9 22:08 | 显示全部楼层
边采集边回放  能实现吗  
或者先存储一段  然后直接放出 看看
i1mcu 发表于 2016-11-10 21:25 | 显示全部楼层
用的AIC32这个芯片吗?
i1mcu 发表于 2016-11-10 21:27 | 显示全部楼层

5509的音频复读哪有这么复杂。
 楼主| Katze 发表于 2016-11-15 10:33 | 显示全部楼层
i1mcu 发表于 2016-11-10 21:25
用的AIC32这个芯片吗?

是的。
 楼主| Katze 发表于 2016-11-15 10:33 | 显示全部楼层
i1mcu 发表于 2016-11-10 21:27
5509的音频复读哪有这么复杂。

是没有这么复杂,现在是想利用DMA的乒乓缓冲来释放CPU的时间。
pklong 发表于 2016-11-16 23:00 | 显示全部楼层
这个还需要乒乓缓冲?
 楼主| Katze 发表于 2016-11-17 10:12 | 显示全部楼层
pklong 发表于 2016-11-16 23:00
这个还需要乒乓缓冲?

现在是想利用DMA的乒乓缓冲来释放CPU的时间。例程的CPU询问方式,无法满足要求。
soodesyt 发表于 2016-11-18 17:23 | 显示全部楼层
直接读取音频芯片不可以吗
soodesyt 发表于 2016-11-18 17:25 | 显示全部楼层
5509不必使用DMA就能读取。
 楼主| Katze 发表于 2016-11-24 16:53 | 显示全部楼层
soodesyt 发表于 2016-11-18 17:23
直接读取音频芯片不可以吗

不可以。现在是想利用DMA的乒乓缓冲来释放CPU的时间。例程的CPU询问方式,无法满足要求。
 楼主| Katze 发表于 2016-11-24 16:54 | 显示全部楼层
soodesyt 发表于 2016-11-18 17:25
5509不必使用DMA就能读取。

例程的CPU询问方式可以读取音频并播放,但完全不能满足我的要求。现在是想利用DMA的乒乓缓冲来释放CPU的时间。例程的CPU询问方式,无法满足要求。
buda 发表于 2019-11-25 20:57 | 显示全部楼层
您好,请问您这个问题当时解决了吗?我现在也需要用pingpong输入音频信号,不知道您现在对于这么久的程序是否还有印象。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3

主题

39

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部