📄 iis.c
字号:
if(bplay) /* 放音 */
{
rBDISRC0=(1<<30)+(1<<28)+(int)(Buf); /*Half word,inc,Buf */
rBDIDES0=(1<<30)+(3<<28)+((int)IISFIF); /*M2IO,fix,IISFIF */
rBDICNT0=(1<<30)+(1<<26)+(3<<22)+(0<<21)+(1<<20)+size;
rBDCON0 = 0x0<<2;
}
else /* 录音 */
{
rBDISRC0=(1<<30)+(3<<28)+((int)IISFIF);
rBDIDES0=(2<<30)+(1<<28)+((int)(Buf));
rBDICNT0=(1<<30)+(1<<26)+(3<<22)+(0<<21)+(0<<20)+size;
rBDCON0 = 0x0<<2;
}
}
/*****************************************************************************
// Function name : iis_init
// Description : IIS 初始化
// Return type : void
// Argument : bplay, 1=放音,0=录音
*****************************************************************************/
void iis_init(int bplay)
{
if(bplay)
{
rIISCON=0x22; /*Tx DMA enable,Rx idle,prescaler enable */
rIISMOD=0x89; /*Tx,Lch=low,iis,16bit ch,codeclk=256fs,lrck=32fs */
rIISPSR=0x33; /*Prescaler_A/B enable, value=3 */
rIISFCON=0xa00; /*Tx/Rx DMA,Tx/Rx FIFO --> start piling.... */
}
else
{
rIISCON=0x12; /*Rx DMA enable,Rx idle,prescaler enable */
rIISMOD=0x49; /*Rx,L-ch=low,iis,16bit ch.,codeclk=256fs,lrck=32fs */
rIISPSR=0x33; /*Prescaler_A/B enable, value=3 */
rIISFCON=0x500; /*Tx/Rx DMA,Tx/Rx FIFO --> start piling.... */
}
}
/*****************************************************************************
// Function name : iis_play
// Description : 放音,采用DMA方式播放音频文件,播放完毕后将引发BDMA0中断
// Return type : void
// Argument : unsigned char *Buf : 纯音频数据,不包含其它信息
// Argument : int size : 数据长度
*****************************************************************************/
void iis_play(unsigned char *Buf, int size)
{
Uart_Printf("[IIS test]\n");
Uart_Printf("IIS test should be configured 16bit data bus\n");
/* 端口配置 */
rPCONE = 0x2556b; /*配置CODECLK */
rPCONG = 0x57ff; /*配置1341三线接口 */
rPUPG |= 0xE0; /*上拉1341三线接口 */
intcount = 0;
/* 准备中断向量 */
pISR_BDMA0=(unsigned)BDMA0_Done;
rI_ISPC=BIT_BDMA0; /*clear pending bit */
rINTMSK=~(BIT_GLOBAL|BIT_BDMA0);
Uart_Printf("sample size=0x%x\n",size/2);
Uart_Printf("\n[]Now play the wave file\n");
uda1341_init(); /*UDA1341初始化 */
dma_init(Buf, size, 1); /*设置DMA */
iis_init(1); /*IIS初始化 */
rIISCON |=0x1; /*启动IIS */
while(!intcount); /*等待处理完成 */
/* 关闭IIS */
rIISCON=0x0; /*IIS stop */
rBDICNT0=0x0; /*BDMA stop */
Cache_Flush();
rNCACHBE0=0xb0000000;
size=0;
rINTMSK=BIT_GLOBAL;
ChangePllValue(PLL_M,PLL_P,PLL_S);
Uart_Init(0,BAUD);
}
/*****************************************************************************
// Function name : iis_play_wav
// Description : 播放WAV声音格式文件,WAV文件位于ADDR_TST_WAV_FILE起始处
// Return type : void
// Argument :
*****************************************************************************/
void iis_play_wav()
{
unsigned char * Buf;
int size;
/* 获取数据长度 */
Buf = (unsigned char *)ADDR_TST_WAV_FILE;
size=*(Buf+0x28) | *(Buf+0x29)<<8 | *(Buf+0x2a)<<16 | *(Buf+0x2b)<<24;
size=(size>>1)<<1;
/* 内存空间申请 */
Buf=(unsigned char *)malloc(size);
rNCACHBE0= ((int)Buf>>12) + ( (((int)Buf>>12) +0x100)<<16 );
Uart_Printf("rNCACHBE0=0x%x\n",rNCACHBE0);
/* 拷贝数据到缓冲区 */
memcpy(Buf, (unsigned char *)(ADDR_TST_WAV_FILE + 0x2c), size);
iis_play(Buf, size);
while(1);
}
/*****************************************************************************
// Function name : iis_record
// Description : 录音,采用DMA方式播放音频文件,播放完毕后将引发BDMA0中断
// Return type : void
// Argument : unsigned char *Buf : 录音数据缓冲区
// Argument : int size : 录音数据长度
*****************************************************************************/
void iis_record(unsigned char *Buf, int size)
{
Uart_Printf("[IIS test]\n");
Uart_Printf("IIS test should be configured 16bit data bus\n");
/* 配置端口 */
rPCONE = 0x2556b; /*配置CODECLK */
rPCONG = 0x57ff; /*配置1341三线接口 */
rPUPG |= 0xE0; /*上拉1341三线接口 */
/* 设置非cache区 */
Uart_Printf("Record 0x%x bytes at 0x%x\n", SIZE_REC_WAV, Buf);
rNCACHBE0= ((int)Buf>>12) + ( (((int)Buf>>12) +0x100)<<16 );
Uart_Printf("rNCACHBE0=0x%x\n",rNCACHBE0);
pISR_BDMA0=(unsigned)TR_Done; /* 准备中断向量 */
rINTMSK=~(BIT_GLOBAL|BIT_BDMA0);
rI_ISPC=BIT_BDMA0;
Uart_Printf("sample size=0x%x\n",size/2);
Uart_Printf("Recording...\n");
uda1341_init(); /* UDA1341初始化 */
dma_init(Buf, size, 0); /* 设置DMA */
iis_init(0); /* IIS初始化 */
Rx_Done = 0;
rBDICNT0 |= (1<<20);
rIISCON |=0x1; /* 启动IIS */
while(!Rx_Done); /* 等待处理完成 */
rIISCON=0x0; /*IIS stop */
rBDICNT0=0x0; /*BDMA stop */
Uart_Printf("\rRecord OK\n");
Cache_Flush();
rNCACHBE0=0xb0000000;
size=0;
rINTMSK=BIT_GLOBAL;
ChangePllValue(PLL_M,PLL_P,PLL_S);
Uart_Init(0,BAUD);
}
/*****************************************************************************
// Function name : iis_record_to_ram
// Description : 录制声音数据到SDRAM中
// Return type : void
// Argument :
*****************************************************************************/
void iis_record_to_ram()
{
unsigned char * Buf;
int size;
/* 录音缓冲区 */
Buf=(unsigned char *)ADDR_REC_WAV; /*申请TESTSIZE字节的内存空间 */
memset(Buf, 0x55, SIZE_REC_WAV);
size=SIZE_REC_WAV; /* 大小 */
size=(size>>1)<<1;
iis_record(Buf, size); /* 录音 */
while(1) iis_play(Buf, size); /* 播放 */
}
/*****************************************************************************
// Function name : HaltUndef
// Description : undefine abort hooker
// Return type : void
// Argument : void
*****************************************************************************/
void HaltUndef(void)
{
Uart_Printf("Undefined instruction exception!!!\n");
while(1);
}
/*****************************************************************************
// Function name : HaltSwi
// Description : swi hooker
// Return type : void
// Argument : void
*****************************************************************************/
void HaltSwi(void)
{
Uart_Printf("SWI exception!!!\n");
while(1);
}
/*****************************************************************************
// Function name : HaltPabort
// Description : pabort hooker
// Return type : void
// Argument : void
*****************************************************************************/
void HaltPabort(void)
{
Uart_Printf("Pabort exception!!!\n");
while(1);
}
/*****************************************************************************
// Function name : HaltDabort
// Description : data abort hooker
// Return type : void
// Argument : void
*****************************************************************************/
void HaltDabort(void)
{
Uart_Printf("Dabort exception!!!\n");
while(1);
}
/*****************************************************************************
// Function name : Isr_Init
// Description : isr init
// Return type : void
// Argument : void
*****************************************************************************/
void Isr_Init(void)
{
pISR_UNDEF=(unsigned)HaltUndef;
pISR_SWI =(unsigned)HaltSwi;
pISR_PABORT=(unsigned)HaltPabort;
pISR_DABORT=(unsigned)HaltDabort;
rINTCON=0x5; /*Non-vect,IRQ enable,FIQ disable */
rINTMOD=0x0; /* All=IRQ mode */
init_interrupt_handler((unsigned int)IsrIRQ);
install_isr_handler(HandleBDMA0, (void*)BDMA0_Done);
}
/*****************************************************************************
// Function name : Main
// Description : C entry function of demo
// Return type : void
// Argument : void
******************************************************************************/
void Main()
{
Isr_Init(); /* 中断初始化 */
Delay(10);
Uart_Init(MCLK,BAUD); /* 串口初始化 */
Uart_Select(0);
iis_play_wav();
iis_record_to_ram();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -