📄 iis.c
字号:
/* iis operation
written by ZhangBo 2008-5
*/
#include "2410lib.h"
#include "audio.h"
#define LEN 0xf0000
int intsymbol = 0;
extern const UINT8T g_ucWave[155760];
/* init iis device */
void init_iis(void)
{
/*GPB4 GPB3 GPB2 as output */
rGPBCON = rGPBCON |(1<<8)|(1<<6)|(1<<4);
/*GPB2 GPB3 GPB4 pullup function are disabled */
rGPBUP = rGPBUP | (7<<2);
/*GPE4 GPE3 GPE2 GPE1 GPE0 as follows */
/*I2SSDO I2SSDI CDCLK I2SSCLK I2SLRCLK */
rGPECON = rGPECON |(2<<8)|(2<<6)|(2<<4)|(2<<2)|2;
/* GPE0-GPE4 pull up disabled */
rGPEUP = rGPEUP | 0x1f;
intsymbol = 0;
init_1341(0); /*0 for play mode, 1 for record mode */
}
/* close iis device */
void close_iis(void)
{
rIISCON = 0x0; // IIS stop
rIISFCON = 0x0; // For FIFO flush
rINTMSK |= BIT_DMA2;
}
/* play audio */
void audio_play(UINT8T* dat,int length)
{
int i;
ClearPending(BIT_DMA2);
rINTMOD = 0x0;
init_1341(0); //play audio mode
pISR_DMA2 = (unsigned)dma_operation;
rINTMSK &= ~(BIT_DMA2);
intsymbol = 0;
rDISRCC2 = 0x0;
rDISRC2 = (INT32T)dat;
rDIDSTC2 = 0x3;
rDIDST2 = (INT32T)IISFIFO;
rDCON2 = (1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(0<<24)+(1<<23)+(0<<22)+(1<<20) + length/2;
rDMASKTRIG2 = (0<<2)+(1<<1)+0;
rIISCON = (1<<5)+(0<<4)+(0<<3)+(1<<2)+(1<<1);
rIISMOD = (0<<8)|(2<<6)|(0<<5)|(0<<4)|(1<<3)|(1<<2)|(1<<0);
rIISPSR = (2<<5)|(2<<0);
rIISFCON = (1<<15)|(1<<13);
rIISCON |= 0x1;
while(intsymbol == 0)
;
rINTMSK |= BIT_DMA2;
rIISCON = 0x0;
}
/* record audio */
void audio_record(void)
{
UINT8T* buff;
int length;
int i;
/* enable interrupt */
ClearPending(BIT_DMA2);
rINTMOD=0x0;
uart_printf("Record audio begin:\n");
buff = (unsigned char*)0x30200000;
for( i = (UINT32T)buff; i <((UINT32T)buff+LEN+0x20000); i+=4)
{
*((volatile unsigned int*)i)=0x0;
}
/* record mode */
init_1341(1);
intsymbol = 0;
pISR_DMA2 = (unsigned)dma_operation;
rINTMSK &= ~(BIT_DMA2);
rDISRCC2 = 0x2;
rDISRC2 = (INT32T)IISFIFO;
rDIDSTC2 = 0x0;
rDIDST2 = (INT32T)buff;
rDCON2 = (1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(0<<24)+(1<<23)+(1<<22)+(1<<20) + LEN/2;
rDMASKTRIG2 = (0<<2)+(1<<1)+0;
rIISCON = (0<<5)+(1<<4)+(1<<3)+(0<<2)+(1<<1);
rIISMOD = (0<<8)|(1<<6)|(0<<5)|(0<<4)|(1<<3)|(1<<2)|(1<<0);
rIISPSR = (2<<5)|(2<<0);
rIISFCON = (1<<14)|(1<<12);
rIISCON |= 0x1;
uart_printf("Press any key to end! \n");
while(intsymbol == 0)
{
if(uart_getkey())
break;
}
rINTMSK |= BIT_DMA2;
rIISCON = 0x0;
delay(20);
uart_printf(" End record!!!\n");
uart_printf(" Press any key to play record data!!!\n");
while(!uart_getkey());
/* play the audio */
audio_play(buff, LEN);
rINTMSK |= BIT_DMA2;
rIISCON = 0x0;
uart_printf(" Play end!!!\n");
}
/* dma interrupt */
void dma_operation(void)
{
ClearPending(BIT_DMA2);
intsymbol = 1;
}
void test(void)
{
uart_printf("\n IIS test begin\n");
init_iis();
uart_printf(" record and play\n");
memcpy((void *)0x30200000, g_ucWave, 155956);
audio_play((UINT8T *)0x30200000,155956);
// audio_record();
uart_printf(" end.\n");
close_iis();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -