This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TLV320AIC23B: recording has periodicity noise

Part Number: TLV320AIC23B

Dear expert,

  I use AIC23B to play and record audio, aic23b works as Slave, MCU as Master, I2S mode. MCU provide LRCIN and BCLK. play sound is good, but recording sound is very not clear with periodicity noise.

the AIC23B init code is DSP2833x_Audio_App download from TI. I enable side tone when recording, the sound is clear. it's ADC issue i think, how can i do it?

thanks!

TI_AIC23.c
// TI File $Revision:  $
// Checkin $Date:  $
//###########################################################################
//
// FILE:	AIC23.c
//
// TITLE:	TLV320AIC23B Driver Functions
//
// DESCRIPTION: 
//
// This file includes functions for initializing the AIC23 codec. You may
// modify/add to these functions to suit your application if desired.
//
//###########################################################################
// $TI Release:   $
// $Release Date:   $
//###########################################################################
/*************************************************
0000000 Left line input channel volume control
0000001 Right line input channel volume control
0000010 Left channel headphone volume control
0000011 Right channel headphone volume control
0000100 Analog audio path control
0000101 Digital audio path control
0000110 Power down control
0000111 Digital audio interface format
0001000 Sample rate control
0001001 Digital interface activation
0001111 Reset register
***************************************************/
/*
*   DMA1 CHANNEL4 FOR IIS2 RX  
*/

//#define DEBUG
#include "TI_AIC23.h"
#include "sys.h"
#include "delay.h" 
#include "spi_soft.h"
#include "usart.h"
#include "includes.h"
#include "prj_config.h"


extern int16_t dmamem[AD_MEM_SIZE];
extern int8_t decodemem[2*AD_MEM_SIZE]; 
extern u32 bytesToPlay;
extern OS_EVENT *pcm_mailbox;
extern u16 gui_get_vol(void);
/* Useful Definitions */
#define MIC 1      // 0 = line input, 1 = microphone input
#define MICDIS 0
#define I2S_SEL 1  // 0 = normal DSP McBSP dig. interface, 1 = I2S interface

// Sample Rates:
#define SRUSB44_1    0x0022 // 44.1 kHz USB, BOSR set
#define SRUSB8       0x000c // 8.0 kHz USB, BOSR not set
#define SRUSB8021    0x002e // 8.0 kHz USB, BOSR not set
#define SRUSB48      0x0000 // 8.0 kHz USB, BOSR not set

#define SR48         0x0000 // 48 kHz USB/normal, BOSR clear
#define SR44_1       0x0020 // 44.1 kHz normal - 11.2896 MHz MCLK, BOSR clear
#define SR8          0x000C // 48 kHz USB/normal, BOSR clear


// Volume Control:
#define LIV         0x0017 // Left line input volume control
                           // 11111=12 dB down to 00000= -34.5 dB
						   // at 1.5 dB per step
						   // Default = 10111 = 0dB
#define RIV         0x0017 // Right line input volume control
                           // 11111=12 dB down to 00000= -34.5 dB
						   // at 1.5 dB per step
						   // Default = 10111 = 0dB
#define LHV         0x007F // Left Channel Headphone Volume Control
                           // 1111111 = 6 dB, 79 steps between +6 and -73 dB (mute)
						   // 0110000 = -73 dB (mute)
						   // Currently set at 1101001 = -16 dB
#define RHV         0x007F // Right Channel Headphone Volume Control
                           // 1111111 = 6 dB, 79 steps between +6 and -73 dB (mute)
						   // 0110000 = -73 dB (mute)
						   // Currently set at 1101001 = -16 dB


Uint16 softpowerdown (void) {          // Power down control 
    return (POWDCTL|(AIC23OUT|AIC23DAC|AIC23ADC|  // Power down: In/Out/DAC/ADC/Mic 
                       AIC23MIC|AIC23LINE));       // Leave AIC23 device, osc, clks on
}
Uint16 fullpowerup (void) {            // Power up all modules
    return (POWDCTL|0x0000);   
}    
Uint16 nomicpowerup (void) {           // Power up all modules except microphone
    return (POWDCTL|AIC23MIC);  
}
Uint16 micpowerup (void) {           // Power up all modules except microphone
    return (POWDCTL|AIC23LINE|AIC23DAC|AIC23OUT);
}
Uint16 linput_volctl (Uint16 volume) { // Left Line Input Volume Control 
    return (LRS|LLINVCTL|volume);
}

Uint16 rinput_volctl (Uint16 volume) { // Right Line Input Volume Control 
    return (RLS|RLINVCTL|volume);
}

Uint16 linput_volmute (void) { // Left Line Input Volume Control 
    return (LRS|LLINVCTL|LIM);
}

Uint16 rinput_volmute (void) { // Right Line Input Volume Control 
    return (RLS|RLINVCTL|RIM);
}

Uint16 lhp_volctl (Uint16 volume) {    // Left Headphone Volume Control
    return (LRS|LHVCTL|LZC|volume);
}

Uint16 rhp_volctl (Uint16 volume) {    // Right Headphone Volume Control
    return (RLS|RHVCTL|RZC|volume);
}

Uint16 nomicaaudpath (void) {          // Analog audio path control
    return 	(AAUDCTL|DACBIT|MICMUTE);     // Turn on DAC, mute mic
}

Uint16 aaudpath (void){
    return (AAUDCTL|DACBIT|MICINSEL|MICBOOST); // Turn on DAC, mic
}

Uint16 nodacaudpath (void){
    return (AAUDCTL|MICINSEL|MICBOOST|DB_0_ST|BYPASS); // Turn on DAC, mic
}

Uint16 digaudiopath (void) {           // Digital audio path control
    return (DAUDCTL|DEEMP48|ADCHP);           // DAC mute, de-emph, ADC HP filter all disabled 
}

Uint16 digaudiopathrecord (void) {           // Digital audio path control
    return (DAUDCTL|DEEMP48|DACM);           // DAC mute, de-emph, ADC HP filter all disabled 
}

Uint16 DSPdigaudinterface (void) {     // Digital audio interface format
    return (DAUDINTF|(AIC23MS|         // AIC23 master mode, DSP mode,32-bit data,
            FORDSP|IWL32B|LRP));         // LRP=1
}

Uint16 I2Sdigaudinterface (void) {     // Digital audio interface format
    return (DAUDINTF|( 0 |         // AIC23 slave mode, I2S mode,16-bit data,
            FORI2S|IWL16B|LRPZRO));         // LRP=0 right channel high
}

Uint16 MSBFLAdigaudinterface (void) {     // Digital audio interface format
    return (DAUDINTF|( 0 |         // AIC23 slave mode, I2S mode,16-bit data,
            FORDSP|IWL16B|LRP));         // LRP=0 right channel high
}

Uint16 USBsampleratecontrol (Uint16 ratecontrol)  {
    return (SMPLRCTL|(USBCLK|ratecontrol)); // USB clock - 48 kHz sample rate in USB mode
}

Uint16 CLKsampleratecontrol (Uint16 ratecontrol)  {
    return (SMPLRCTL|ratecontrol);      // external clock - 48 kHz sample rate in external clock (12.288 MHz) mode
}

Uint16 digact (void) {                 // Digital Interface Activation       
    return (DIGINTFACT|ACT);           // Activate
} 

Uint16 reset (void) {                  // Reset AIC23
    return (RESETREG|RES);
}

Uint16 digaudinterface (void) {     // Digital audio interface format
    return (DAUDINTF|( 0|         // AIC23 master mode, DSP mode,32-bit data,
            FORMSBFLA|IWL16B|LRPZRO));         // LRP=1
}

Uint16 I2Sdigaudinterface_master (void) {     // Digital audio interface format
    return (DAUDINTF|( AIC23MS |         // AIC23 slave mode, I2S mode,16-bit data,
            FORI2S|IWL16B|LRPZRO));         // LRP=0 right channel high
}

Uint16 USBsampleratecontroldivid2 (Uint16 ratecontrol)  {
    return (SMPLRCTL|(AIC23CLKIND|USBCLK|ratecontrol)); // USB clock - 48 kHz sample rate in USB mode
}

Uint16 CLKsampleratecontroldivid2 (Uint16 ratecontrol)  {
    return (SMPLRCTL|(AIC23CLKIND|ratecontrol));      // external clock - 48 kHz sample rate in external clock (12.288 MHz) mode
}

Uint16 MICpoweron (void) {            // Power up all modules
    return (POWDCTL|0x0009);   
}    

void SetUSBsamplerate(Uint16 rate)
{
	Uint16 command;
	command=USBsampleratecontrol(rate);
	mcbsp_xmit (command);
}

void Setnormalsampleratedivid2(Uint16 rate)
{
	Uint16 command;
	command=CLKsampleratecontroldivid2(rate);
	mcbsp_xmit (command);
}

void Setnormalsamplerate(Uint16 rate)
{
	Uint16 command;
	command=CLKsampleratecontrol(rate);
	mcbsp_xmit (command);
}

void SetI2Sdigaudinterface_master(void)
{
	Uint16 command;
	command=I2Sdigaudinterface_master();
	mcbsp_xmit(command);
}

void SetLeftAligdigaudinterface(void)
{
	Uint16 command;
	command=digaudinterface();
	mcbsp_xmit(command);
}

void SetSoftpowerdown(void)
{
	Uint16 command;
	command=softpowerdown();
	mcbsp_xmit (command);
}

void SetMICpoweron(void)
{
	Uint16 command;
	command=MICpoweron();
	mcbsp_xmit (command);
}

/*44.1/2==22050 used play wav file*/
void SetCLKindivid2(void)
{
	Uint16 command;
	command=USBsampleratecontroldivid2(SRUSB44_1);
	mcbsp_xmit (command);
}

void SetVolume(u8 volume)
{
	Uint16 command;
	switch (volume)
		{
		case 0:
			command = lhp_volctl(0x30);
			mcbsp_xmit(command);
			command = rhp_volctl(0x30);
			mcbsp_xmit(command);
			debug_printf("0000");
			break;
		case 25:
			command = lhp_volctl(0x68);
			mcbsp_xmit(command);
			command = rhp_volctl(0x68);
			mcbsp_xmit(command);
			debug_printf("1111");
			break;
		case 50:
			command = lhp_volctl(0x70);
			mcbsp_xmit(command);
			command = rhp_volctl(0x70);
			mcbsp_xmit(command);
			debug_printf("2222");
			break;
		case 75:
			command = lhp_volctl(0x78);
			mcbsp_xmit(command);
			command = rhp_volctl(0x78);
			mcbsp_xmit(command);
			debug_printf("3333");
			break;
		case 100:
			command = lhp_volctl(0x7f);
			mcbsp_xmit(command);
			command = rhp_volctl(0x7f);
			mcbsp_xmit(command);
			debug_printf("4444");
			break;
		default:
		break;
		}
}

void aic23_init(int mic, int i2s_mode)
{
    Uint16 command;
    command = reset();
	mcbsp_xmit (command);
    command = softpowerdown();       // Power down everything except device and clocks
	mcbsp_xmit (command);
    command = linput_volctl(LIV);    // Unmute left line input and maintain default volume
	mcbsp_xmit (command);
	command = rinput_volctl(RIV);    // Unmute right line input and maintain default volume
	mcbsp_xmit (command);
#if 0
	command = lhp_volctl(LHV);       // Left headphone volume control
	mcbsp_xmit (command);
	command = rhp_volctl(RHV);       // Right headphone volume control
	mcbsp_xmit (command);
#else
	SetVolume(gui_get_vol());
#endif
    if (mic == 1) {
        command = aaudpath();
    } else {
   	    command = nomicaaudpath();      // Turn on DAC, mute mic
    }
	mcbsp_xmit (command);
	command = digaudiopath();       // Disable DAC mute
	mcbsp_xmit (command);

	if (i2s_mode == 1) {
	    command = I2Sdigaudinterface(); // AIC23 master mode, I2S mode,32-bit data, LRP=1 to match with XDATADLY=1
 	    mcbsp_xmit (command);
	    command = CLKsampleratecontrol (SR48); // 12.288 MHz external MCLK -  48 kHz sample rate (12.288 MHz/64/4 = 48 kHz)
	    //command = USBsampleratecontrol (SRUSB8); //12MHZ, USB BOSR=0 8KFs
	    mcbsp_xmit (command);
	} else {
 	    command = DSPdigaudinterface(); // AIC23 master mode, DSP mode,32-bit data, LRP=0 to match with XDATADLY=0
	    mcbsp_xmit (command);
	    command = USBsampleratecontrol (SR48); // 12 MHz USB clock -  48 kHz sample rate in USB mode
	    mcbsp_xmit (command);
    }
	command = digact();             // Activate digital interface
	mcbsp_xmit (command);
    if (mic == 1) {
        command = fullpowerup();
	} else {
   	    command = nomicpowerup();      // Turn everything on except Mic.
    }
    mcbsp_xmit (command);
}


void aic23_init_record(int mic, int i2s_mode)
{
    Uint16 command;
    command = reset();
	mcbsp_xmit (command);
    //command = softpowerdown();       // Power down everything except device and clocks
    command = micpowerup();
	mcbsp_xmit (command);
    command = linput_volmute();    // Unmute left line input and maintain default volume
	mcbsp_xmit (command);
	command = rinput_volmute();    // Unmute right line input and maintain default volume
	mcbsp_xmit (command);
#if 0
	command = lhp_volctl(LHV);       // Left headphone volume control
	mcbsp_xmit (command);
	command = rhp_volctl(RHV);       // Right headphone volume control
	mcbsp_xmit (command);
#else
	SetVolume(gui_get_vol());
#endif
    if (mic == 1) {
		command= (AAUDCTL|MICBOOST|MICMUTE);
		mcbsp_xmit (command);
		delay_ms(10);
		command= (AAUDCTL|MICINSEL|MICBOOST|MICMUTE);//DAC off
    } else {
   	    command = nomicaaudpath();      // Turn on DAC, mute mic
    }
	mcbsp_xmit (command);
	command = digaudiopathrecord();       // DAC mute,ADCHP
	mcbsp_xmit (command);

	if (i2s_mode == 1) {
	    command = I2Sdigaudinterface(); // AIC23 master mode, I2S mode,32-bit data, LRP=1 to match with XDATADLY=1
	    //command = MSBFLAdigaudinterface();
 	    mcbsp_xmit (command);
	    command = CLKsampleratecontrol(SR48); // 12.288 MHz external MCLK -  48 kHz sample rate (12.288 MHz/64/4 = 48 kHz)
	    //command = USBsampleratecontrol (SRUSB8); //12MHZ, USB BOSR=0 8KFs
	    mcbsp_xmit (command);
	} else {
 	    command = DSPdigaudinterface(); // AIC23 master mode, DSP mode,32-bit data, LRP=0 to match with XDATADLY=0
	    mcbsp_xmit (command);
	    command = USBsampleratecontrol (SR48); // 12 MHz USB clock -  48 kHz sample rate in USB mode
	    mcbsp_xmit (command);
    }
	command = digact();             // Activate digital interface
	mcbsp_xmit (command);

}

static void NVIC_Configuration_DMA1_4(void)
{
	NVIC_InitTypeDef NVIC_InitStructure;   // Configure one bit for preemption priority
	NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel4_IRQn;//need changed with ITConfig enable together	   
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;   
	NVIC_Init(&NVIC_InitStructure);
	DMA_ITConfig(DMA1_Channel4, DMA_IT_TC|DMA_IT_HT, ENABLE);
}

/*
*   DMA1 CHANNEL5 FOR IIS2 TX  
*/
static void NVIC_Configuration_DMA1_5(void)
{
	NVIC_InitTypeDef NVIC_InitStructure;   // Configure one bit for preemption priority
	NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel5_IRQn;//need changed with ITConfig enable together	   
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;   
	NVIC_Init(&NVIC_InitStructure);
	DMA_ITConfig(DMA1_Channel5, DMA_IT_TC|DMA_IT_HT, ENABLE);
}

//extern void adpcm_codec(uint8_t * adpcm, int16_t * pcm, int encode);
//定时器初始化

void TIM3_Configuration(void)
{ 
 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; 
 TIM_OCInitTypeDef TIM_OCInitStructure; 
 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); 
 TIM_TimeBaseStructure.TIM_Period = 5;//设置一次TIM2比较的频率24/3000=8K
 TIM_TimeBaseStructure.TIM_Prescaler = 0;//系统主频72M,这里分频1,72M  72M/6 = 12M
 TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; 
 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
 TIM_TimeBaseInit(TIM3, & TIM_TimeBaseStructure);
 
 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;//下面详细说明 
 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;//TIM_OutputState_Disable; 
 TIM_OCInitStructure.TIM_Pulse = 3; 
 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;//如果是PWM1要为Low,PWM2则为High 
 TIM_OC1Init(TIM3, & TIM_OCInitStructure);//OC1->TIM1_CC1 
 TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable); 
 //TIM_ARRPreloadConfig(TIM3,ENABLE); 
 //TIM_InternalClockConfig(TIM8); 
 //TIM_UpdateDisableConfig(TIM8, DISABLE);
 //TIM_SelectOutputTrigger(TIM1, TIM_TRGOSource_OC1);
 //TIM_CCxCmd(TIM8, TIM_Channel_1, TIM_CCx_Enable); 
 TIM_CtrlPWMOutputs(TIM3, ENABLE);
 TIM_Cmd(TIM3, ENABLE);
	
}


//extern void adpcm_codec(uint8_t * adpcm, int16_t * pcm, int encode);
//定时器初始化

void TIM3_Record_Configuration(void)
{ 
 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; 
 TIM_OCInitTypeDef TIM_OCInitStructure; 
 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); 
 TIM_TimeBaseStructure.TIM_Period = 5;//设置一次TIM2比较的频率72M/=4M,4M/250fs = 8K
 TIM_TimeBaseStructure.TIM_Prescaler = 0;//系统主频72M
 TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; 
 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
 TIM_TimeBaseInit(TIM3, & TIM_TimeBaseStructure);
 
 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;//下面详细说明 
 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;//TIM_OutputState_Disable; 
 TIM_OCInitStructure.TIM_Pulse = 3; 
 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;//如果是PWM1要为Low,PWM2则为High 
 TIM_OC1Init(TIM3, & TIM_OCInitStructure);//OC1->TIM1_CC1 
 TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable); 
 //TIM_ARRPreloadConfig(TIM3,ENABLE); 
 //TIM_InternalClockConfig(TIM8); 
 //TIM_UpdateDisableConfig(TIM8, DISABLE);
 //TIM_SelectOutputTrigger(TIM1, TIM_TRGOSource_OC1);
 //TIM_CCxCmd(TIM8, TIM_Channel_1, TIM_CCx_Enable); 
 TIM_CtrlPWMOutputs(TIM3, ENABLE);
 TIM_Cmd(TIM3, ENABLE);
	
}

void TIM3_control(FunctionalState onoff)
{
	TIM_CtrlPWMOutputs(TIM3, onoff);
	TIM_Cmd(TIM3, onoff);
}

void AIC23_IIS2_PlayPCM(u32 same_rate)
{
	I2S_InitTypeDef I2S_InitStructure;
	//TIM3_control(DISABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, DISABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
	I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx;
	I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips;
	I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
	I2S_InitStructure.I2S_AudioFreq = same_rate; 
	I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
	I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
	I2S_Init(SPI2, &I2S_InitStructure);
	//SPI_I2S_DMACmd(SPI2, SPI_I2S_DMAReq_Rx, DISABLE);
	SPI_I2S_DMACmd(SPI2, SPI_I2S_DMAReq_Tx, ENABLE);
}


void AIC23_IIS2_RecordPCM(u32 same_rate)
{
	I2S_InitTypeDef I2S_InitStructure;
	//TIM3_control(DISABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, DISABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
	I2S_InitStructure.I2S_Mode = I2S_Mode_MasterRx;
	I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips;
	I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
	I2S_InitStructure.I2S_AudioFreq = same_rate; 
	I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
	I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
	I2S_Init(SPI2, &I2S_InitStructure);
	//SPI_I2S_DMACmd(SPI2, SPI_I2S_DMAReq_Tx, DISABLE);
	SPI_I2S_DMACmd(SPI2, SPI_I2S_DMAReq_Rx, ENABLE);
}

void Play_DMA_Config(u32 cmar, u16 dmasize)
{  
	DMA_InitTypeDef 		   DMA_InitStructure;
	
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
	 
	DMA_StructInit( &DMA_InitStructure);	  
	DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;//memory to peripherals
	DMA_InitStructure.DMA_BufferSize = dmasize;
	DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
	DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
	DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
	DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
	DMA_InitStructure.DMA_Priority = DMA_Priority_High;
	DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
	DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
	DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&SPI2->DR;
	DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)cmar;
	DMA_Init(DMA1_Channel5, &DMA_InitStructure);
	NVIC_Configuration_DMA1_5();
	DMA_Cmd(DMA1_Channel4, DISABLE);
	DMA_Cmd(DMA1_Channel5, ENABLE);

}


//DMA初始化配置
void Record_DMA_Config(u32 cmar, u16 dmasize)
{
	DMA_InitTypeDef DMA_InitStructure; // 注:ADC为12位模数转换器,只有ADCConvertedValue的低12位有效
	
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);//使能DMA时钟
	DMA_DeInit(DMA1_Channel4);//开启DMA1的第一通道 
	DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&SPI2->DR;//DMA对应的外设基地址
	DMA_InitStructure.DMA_MemoryBaseAddr = cmar; //内存存储基地址
	DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //DMA的转换模式为SRC模式,由外设搬移到内存
	DMA_InitStructure.DMA_BufferSize = dmasize;//DMA缓存大小,1个
	DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //接收一次数据后,设备地址禁止后移
	DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //关闭接收一次数据后,目标内存地址后移
	DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//定义外设数据宽度为16位
	DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //DMA搬移数据尺寸,HalfWord就是为16位
	DMA_InitStructure.DMA_Mode =DMA_Mode_Circular;//循环转换模式
	DMA_InitStructure.DMA_Priority = DMA_Priority_High;//DMA优先级高
	DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;//M2M模式禁用
	DMA_Init(DMA1_Channel4, &DMA_InitStructure);
	NVIC_Configuration_DMA1_4();
	DMA_Cmd(DMA1_Channel5, DISABLE);
	DMA_Cmd(DMA1_Channel4, ENABLE);
}

/*
*  mic record
*/
void DMA1_Channel4_IRQHandler(void)
{

   OSIntEnter();
   if(DMA_GetITStatus(DMA1_IT_TC4)!=RESET){
         DMA_ClearITPendingBit(DMA1_IT_TC4);
		 OSMboxPost(pcm_mailbox, "E");
		 //spx_full_frame();
   }
   if(DMA_GetITStatus(DMA1_IT_HT4)!=RESET){
         DMA_ClearITPendingBit(DMA1_IT_HT4);
		 OSMboxPost(pcm_mailbox, "e");
		 //spx_half_frame();
   }   
   OSIntExit();
}

/*
*  PCM play dma
*/
void DMA1_Channel5_IRQHandler(void)
{

   OSIntEnter();
   if(DMA_GetITStatus(DMA1_IT_TC5)!=RESET){
         DMA_ClearITPendingBit(DMA1_IT_TC5);
		 if(bytesToPlay)
		   OSMboxPost(pcm_mailbox, "d");
		 else
		   OSMboxPost(pcm_mailbox, "o");
   }
   if(DMA_GetITStatus(DMA1_IT_HT5)!=RESET){
         DMA_ClearITPendingBit(DMA1_IT_HT5);
		 if(bytesToPlay)
		   OSMboxPost(pcm_mailbox, "h");
		 else
		   OSMboxPost(pcm_mailbox, "o");
   }   
   OSIntExit();
}

void aic23_pcm_play_Start(u32 same_rate)
{
	debug_printf("aic23_pcm_play_Start\n");

	Play_DMA_Config((u32)decodemem, AD_MEM_SIZE);
	aic23_init(MICDIS, I2S_SEL);
	AIC23_IIS2_PlayPCM(same_rate);
	I2S_Cmd(SPI2, ENABLE);

	SPK_PA_ON();
}

void aic23_pcm_play_Stop(void)
{
	debug_printf("aic23_pcm_play_Stop\n");	
	SPK_PA_OFF();
	SetSoftpowerdown();
	I2S_Cmd(SPI2, DISABLE);
}

void aic23_pcm_record_Start(void)
{
	Uint16 command;
	//TIM3_Record_Configuration();
	Record_DMA_Config((u32)dmamem, AD_MEM_SIZE);
	aic23_init(MIC, I2S_SEL);
	//aic23_init_record(MIC, I2S_SEL);
	//SetMICpoweron();
	AIC23_IIS2_RecordPCM(8000);
	delay_ms(20);
	I2S_Cmd(SPI2, ENABLE);
	delay_ms(20);
	command = nodacaudpath();
    mcbsp_xmit (command);	
	debug_printf("aic23_pcm_record_Start");
}

void aic23_pcm_record_Stop(void)
{
	SetSoftpowerdown();
	I2S_Cmd(SPI2, DISABLE);
	debug_printf("aic23_pcm_record_Stop");
}

//SPI IIS DMA used for audio codec
void aic23_hw_init(void)
{
	AIC23_GPIO_INIT();
	//TIM3_Configuration();
	delay_ms(10);
	//Play_DMA_Config((u32)decodemem, AD_MEM_SIZE);
}


void aic23_test(void)
{
	aic23_hw_init();
	//aic23_init(MICDIS, I2S_SEL);
}

TI_AIC23.h