📄 iis.c
字号:
void __irq DMA2_Done(void)
{
rINTSUBMSK |= BIT_SUB_DMA2;
rINTMSK |= (BIT_DMA);
rSUBSRCPND = BIT_SUB_DMA2;
ClearPending(BIT_DMA);
rIISCON &= ~(1<<2)|(0<<0);
rIISCON |= (1<<2)|(1<<0);
printf("\nTX DMA Done ~~~");
rINTMSK &= ~(BIT_DMA);
rINTSUBMSK &= ~BIT_SUB_DMA2;
}
void __irq DMA1_Rec_Done(void)
{
rINTSUBMSK |= BIT_SUB_DMA1;
rINTMSK |= (BIT_DMA);
rSUBSRCPND = BIT_SUB_DMA1;
ClearPending(BIT_DMA);
rIISCON &= ~(1<<1)|(0<<0);
printf("Record DMA Done!\n");
rINTMSK &= ~(BIT_DMA);
rINTSUBMSK &= ~BIT_SUB_DMA1;
Rec_Done = 1;
}
void __irq Play_Rec_Simul(void)
{
rINTSUBMSK |= BIT_SUB_DMA1;
rINTMSK |= (BIT_DMA);
rSUBSRCPND = BIT_SUB_DMA1;
ClearPending(BIT_DMA);
rIISCON &= ~(1<<0);
rIISCON |= 0x1;
printf("\nR~~~");
rINTMSK &= ~(BIT_DMA);
rINTSUBMSK &= ~BIT_SUB_DMA1;
}
void __irq Rx_IIS_Int(void)
{
rSUBSRCPND = BIT_SUB_RXD1; //Clear pending bit (Requested)
rSUBSRCPND;
ClearPending(BIT_UART1);
*_temp ++= RdURXH1();
}
void Play_Iis(void)
{
printf("\n just only Play it.\n");
IIS_Port_Init();
Select_IIS_Master_CLK();
Init1341(PLAY_IIS);
IIS_PlayWave_DMA2(rec_buf, 464000);
// need to add mute function
IIS_Port_Return();
}
void Play_Iis_EXTCLK(void)
{
printf("\n just only Play it.\n");
IIS_Port_Init();
Select_EXTCLK(); // Select External Clock
Init1341(PLAY_IIS);
Data_init();
IIS_PlayWave_DMA2_EXTCLK(rec_buf, 464000);
IIS_Port_Return();
}
//Record Sound via Line-In
void RecordSound_ViaLineIn_Playit(void)
{
printf("\nRecord Sound via Line-In and Play it.\n");
IIS_Port_Init();
Select_IIS_Master_CLK();
Init1341(RECORD_LINE_IN);
IIS_RecSound_DMA1(RECORD_LINE_IN, 464000);
Init1341(PLAY_IIS);
IIS_PlayWave_DMA2(rec_buf, 464000);
// need to add mute function
IIS_Port_Return();
}
//Record Sound via MIC-In
void RecordSound_ViaMICIn_Playit(void)
{
printf("\nRecord Sound via MIC-In and Play it.\n");
IIS_Port_Init();
Select_IIS_Master_CLK();
Init1341(RECORD_MIC_IN);
IIS_RecSound_DMA1(RECORD_MIC_IN, REC_LEN_IIS);
printf("\nPress Any Key If You Want Play WAV File\n" );
getchar();
Init1341(PLAY_IIS);
IIS_PlayWave_DMA2(rec_buf, 464000);
// need to add mute function
IIS_Port_Return();
}
void RECORD_PLAY_SIMtaneously(void)
{
printf("\nRecord and Play Simultaneously.\n");
IIS_Port_Init();
Select_IIS_Master_CLK();
Init1341(RECORD_LINE_IN);
// IIS_RecSound_DMA1(RECORD_LINE_IN, REC_LEN_IIS);
IIS_RecSound_DMA1(RECORD_LINE_IN, 464000);
printf("\n First Record OK! and then RECORD Simultaneously\n");
getchar();
Init1341(RECORD_PLAY_SIM);
// IIS_Paly_Rec_Simul(rec_buf, REC_LEN_IIS);
IIS_Paly_Rec_Simul(rec_buf, 464000);
Init1341(PLAY_IIS);
IIS_PlayWave_DMA2(rec_buf1, 464000);
// need to add mute function
IIS_Port_Return();
}
void RecordSound_ViaLineIn_SLV(void)
{
printf("\nRecord Sound via Line-In and Play it.\n");
// slave mode setting
rIISMOD = ( rIISMOD & ~(3<<10) ) | (3<<10);
IIS_Port_Init();
Init1341(RECORD_LINE_IN);
IIS_RecSound_DMA1_SLV(RECORD_LINE_IN, 464000);
IIS_Port_Return();
}
void RecordSound_ViaLineIn_MASTER(void)
{
printf("\nRecord Sound via Line-In and Play it.\n");
IIS_Port_Init();
Select_IIS_Master_CLK();
Init1341(RECORD_LINE_IN);
IIS_RecSound_DMA1_MASTER(RECORD_LINE_IN, 464000);
IIS_Port_Return();
}
void Play_Iis_MASTER(void)
{
printf("\n just only Play it.\n");
IIS_Port_Init();
Select_IIS_Master_CLK();
Data_init();
Init1341(PLAY_IIS);
IIS_PlayWave_DMA2_MASTER(rec_buf, 464000);
IIS_Port_Return();
}
void Play_Iis_SLAVE(void)
{
printf("\n just only Play it.\n");
// Slave mode Setting
rIISMOD = ( rIISMOD & ~(3<<10) ) | (3<<10);
IIS_Port_Init();
Data_init();
Init1341(PLAY_IIS);
IIS_PlayWave_DMA2_SLAVE(rec_buf, 464000);
IIS_Port_Return();
}
void Data_init(void)
{
int i;
unsigned int *rec_buf = (unsigned int *)0x31000028;
for(i=0;i<500000;i++)
{
*(rec_buf+i)=i;
}
*(rec_buf+0)=0xa5a5a5a5;
*(rec_buf+1)=0x5a5a5a5a;
*(rec_buf+2)=0xffff0000;
*(rec_buf+3)=0xffffffff;
*(rec_buf+4)=0x0000ffff;
}
void IIS_RecSound_DMA1(int mode, unsigned int rec_size)
{
int Exit_Key, iIndex;
unsigned int iR_LRCLK, iR_BCLK, iR_BLC;
printf("\n Root Frequency Sample ( 0:256fs 1:512fs 2:384fs 3:768fs ) = ");
iR_LRCLK = GetIntNum();
printf("\n Bit Frequency Sample (0:32fs 1:48fs 2:16fs 3:24fs) = ");
iR_BCLK = GetIntNum();
printf("\n BLC (0: 16bit 1:8bit ) = ");
iR_BLC = GetIntNum();
pISR_DMA = (unsigned)DMA1_Rec_Done;
ClearPending(BIT_DMA);
rSUBSRCPND = BIT_SUB_DMA1;
// No Pause Rx DMA Operatin, Tx disable, Rx enable, Tx DMA disable, Rx DMA enable, I2S disalbe.
rIISCON = (0<<5) + (1<<4) + (0<<3) +(0<<2) + (1<<1) + 0;
// Using PCLK, Receive Mode, Left Channel is Low, I2S Format, LRCLK 384fs, BLK 32fs, BLC 16bit.
rIISMOD = (0<<10)+(1<<8) + (0<<7) + (0<<5) + (iR_LRCLK<<3) + (iR_BCLK<<1) + (iR_BLC<<0);
// FIFO flush
rIISFIC = (1<<7) + 0; // jungil
rIISFIC = (0<<7) + 0; // jungil
printf("\nIISLRCK = %d Hz", (int) IIS_Codec_CLK/384);
// Reg_Buf Memory init
for(iIndex=0;iIndex<500000;iIndex+=1)
{
*((unsigned int*)(0x31000028)+iIndex)=0x0;
}
printf("\n Check 0x31000028 Memory Init and Press Ant Key! \n");
getchar();
printf("\n Press any key to start record!\n"); // jungil
getchar(); //jungil
// DMA 1 Mask Release.
rINTMSK = ~(BIT_DMA);
rINTSUBMSK = ~(BIT_SUB_DMA1);
//IIS Rx start
rIISCON |= 0x1; // I2S start
//--- DMA1 Initialize
rDISRCC1 = (1<<1) + (1<<0);
rDISRC1 = ((unsigned int)0x55000014);
rDIDSTC1 = (0<<1) + (0<<0);
rDIDST1 = (int)rec_buf;
rDCON1 = (U32)((1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(0<<22)+(2<<20)+(464000/4));
rDMAREQSEL1 = (5<<1) + (1<<0);
rDMASKTRIG1 = (0<<2) + (1<<1) + (0<<0); //No-stop[2], DMA1 channel On[1], No-sw trigger[0]
if(mode ==1)
printf("\n\nAre you ready to record sound via MIC-In on SMDK2443?");
if(mode ==2)
printf("\n\nAre you ready to record sound via Line-In on SMDK2443?");
printf("\n Recording............If you want stop, Press 'x' or 'X' key \n");
while(!getchar())
{
Exit_Key=getchar();
if( (Exit_Key == 'x') | (Exit_Key == 'X'))
{
Rec_Done=1;
break;
}
}
Rec_Done = 0;
//IIS Rx stop
Delay(10); //For end of H/W Rx
rIISCON = 0x0; //IIS stop
rDMASKTRIG1 = (1<<2); //DMA2 stop
rIISFIC = 0x0; //For FIFO flush
rINTSUBMSK |= (BIT_SUB_DMA1);
rINTMSK |= (BIT_DMA);
printf("\nEnd of Record!\n");
}
void IIS_RecSound_DMA1_Repeat(unsigned char *start_addr, unsigned int rec_size)
{
unsigned char Exit_Key;
printf("\nRecording At IISLRCK = %d Hz\n", (int) IIS_Codec_CLK/384);
printf("\nRecord Buffer 1 == %x", rec_buf1);
//--- DMA1 Initialize
rDISRCC1 = (1<<1) + (1<<0);
rDISRC1 = ((unsigned int)0x55000014);
rDIDSTC1 = (0<<1) + (0<<0);
rDIDST1 = (int)rec_buf1;
rDCON1 = (U32)((1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(0<<22)+(2<<20)+(464000/4));
rDMAREQSEL1 = (5<<1) + (1<<0);
rDMASKTRIG1 = (0<<2) + (1<<1) + (0<<0); //No-stop[2], DMA1 channel On[1], No-sw trigger[0]
while(!Uart_GetKey())
{
Exit_Key=getchar();
if( (Exit_Key == 'x') | (Exit_Key == 'X'))
{
Rec_Done=1;
break;
}
}
//IIS Rx stop
Delay(10); //For end of H/W Rx
rIISCON = 0x0; //IIS stop
rDMASKTRIG1 = (1<<2); //DMA1 stop
rIISFIC = 0x0; //For FIFO flush
printf("\n\nEnd of Record!");
}
void IIS_PlayWave_DMA2(unsigned char *start_addr, unsigned int play_size)
{
unsigned char Exit_Key;
unsigned int iLRCLK=0, iBCLK=0, iBLC=0;
pISR_DMA = (unsigned)DMA2_Done;
ClearPending(BIT_DMA);
rSUBSRCPND = BIT_SUB_DMA2;
printf("\n Root Frequency Sample ( 0:256fs 1:512fs 2:384fs 3:768fs ) = ");
iLRCLK = GetIntNum();
printf("\n Bit Frequency Sample (0:32fs 1:48fs 2:16fs 3:24fs) = ");
iBCLK = GetIntNum();
printf("\n BLC (0: 16bit 1:8bit ) = ");
iBLC = GetIntNum();
// this setting for only TX
rIISCON = (0<<5) + (0<<4) +(1<<2) + (0<<1)+0;
// using pclk, tx only , left for channel,iis format ,384fs , 32fs ,16bit
rIISMOD = rIISMOD & ~(0xfff) | (0<<10)|(0<<8)|(0<<7)|(0<<5)|(iLRCLK<<3)|(iBCLK<<1)|(iBLC<<0);
rIISFIC = 0+(1<<15);
rIISFIC = 0+(0<<15);
printf("\nIISLRCK = %d Hz", (int) IIS_Codec_CLK/384);
rINTMSK = ~(BIT_DMA);
rINTSUBMSK = ~(BIT_SUB_DMA2);
printf("\nConnect head-phone plug into speaker-out socket on SMDK2443 and Press any key.\n");
getchar();
printf("If you want to exit, Press the 'x' key.\n");
printf("Now Play...\n");
printf("If you want to disable IIS tx(PAUSE), Press '0' key\n");
printf("If you want to enable IIS tx, Press '1' key\n");
printf("If you want to stop DMA channel(STOP), Press '2' key\n");
printf("If you want to start DMA channel, Press '3' key\n");
//DMA2 Register Setting
rDISRC2 = (int)(start_addr);
rDISRCC2 = (0<<1) + (0<<0);
rDIDST2 = ((unsigned int)0x55000010);
rDIDSTC2 = (1<<1) + (1<<0);
// 31: ACK 30: sync pclk 29:curr_tc int setting 28:unit transfer 27:single service 22: reload 20:half word
rDCON2 = (U32)((U32)(1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(0<<22)+(2<<20)+(play_size/4));
// 5:1= 4th bit is the tx iis 0:set = hw zero = sw
rDMAREQSEL2 = (4<<1)|(1);
rDMASKTRIG2 = (0<<2) + (1<<1) + (0<<0); //No-stop, DMA2 channel On, and No-sw trigger
//IIS Tx Start
rIISCON |= 0x1; //IIS Interface start
while(1)
{
Exit_Key=getchar();
if(Exit_Key == '0'){
rIISCON |= (1<<4);
printf("\nPAUSE...\n");
}
if(Exit_Key == '1'){
rIISCON &= ~(1<<3);
}
if(Exit_Key == '2'){
rDMASKTRIG2 |= (1<<2);
rIISFIC &= ~(1<<13); //* tx fifo disable
while((rIISFIC & 0x0FC0)!=0); //* wait until tx fifo gets empty
printf("\nSTOP...\n");
}
if(Exit_Key == '3'){
rIISFIC |= (1<<13); //* tx fifo enable
rDISRC2 = (int)(start_addr);
rDMASKTRIG2 &= ~(1<<2);
rDMASKTRIG2 |= (1<<1);
}
if( (Exit_Key == 'x') | (Exit_Key == 'X'))
break;
printf("STAT2: 0x%x CURR_TC: 0x%x DCDST2: 0x%x\n", rDSTAT2&0x300000, rDSTAT2&0xfffff, rDCDST2);
}
//IIS Tx Stop
Delay(10); //For end of H/W Tx
rIISCON &= ~(1<<0); //IIS Interface stop
rDMASKTRIG2 = (1<<2); //DMA2 stop
rIISFIC = 0x0; //For FIFO flush
rINTSUBMSK |= (BIT_SUB_DMA2);
rINTMSK |= (BIT_DMA);
printf("\nEnd of Play!\n");
}
void IIS_Paly_Rec_Simul(unsigned char *start_addr, unsigned int play_size)
{
pISR_DMA= (unsigned)Play_Rec_Simul;
ClearPending(BIT_DMA);
rSUBSRCPND=(BIT_SUB_DMA1);
// this setting for TX RX Simulateously
rIISCON = (0<<5) + (0<<4) +(1<<2) + (1<<1)+0;
// using pclk, TX/RX Silmulateously , left for channel,iis format ,384fs , 32fs ,16bit
rIISMOD = rIISMOD & ~(0xfff) | (0<<10)|(2<<8)|(0<<7)|(0<<5)|(2<<3)|(0<<1)|(0<<0);
// Fifo Fulsh
rIISFIC = 0+(1<<15);
rIISFIC = 0+(0<<15);
printf("\n RootCLK = 384fs, BLK = 32fs, BLC = 16bit \n");
printf("\nIISLRCK = %d Hz", (int) IIS_Codec_CLK/384);
rINTMSK &= ~(BIT_DMA);
rINTSUBMSK &= ~(BIT_SUB_DMA1);
printf("\nConnect head-phone plug into speaker-out socket on SMDK2460 and Press any key.\n");
getchar();
printf("If you want to exit, Press the 'x' key.\n");
printf("Now Play...\n");
//DMA2 Register Setting
rDISRC2 = (int)(start_addr);
rDISRCC2 = (0<<1) + (0<<0);
rDIDST2 = ((unsigned int)0x55000010);
rDIDSTC2 = (1<<1) + (1<<0);
// 31: ACK 30: sync pclk 29:curr_tc int setting 28:unit transfer 27:single service 22: reload 20:half word
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -