⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iis.c

📁 三星2443芯片
💻 C
📖 第 1 页 / 共 3 页
字号:
	rDCON2   = ((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)
	{
		Delay(10000);

		IIS_RecSound_DMA1_Repeat(rec_buf1, REC_LEN_IIS);	
		if( Rec_Done==1)
			break;	
	}

	Rec_Done=0;

	//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_DMA1);
	rINTMSK |=(BIT_DMA);

	printf("\nEnd of Play!\n");

}


void IIS_PlayWave_DMA2_MASTER(unsigned char *start_addr, unsigned int play_size)
{
	unsigned char Exit_Key;
	
	pISR_DMA = (unsigned)DMA2_Done;
	ClearPending(BIT_DMA);	
	rSUBSRCPND = BIT_SUB_DMA2;

	// FIFO Flush
	rIISFIC = rIISFIC | (1<<15);
	rIISFIC = rIISFIC & (0<<15);
	
	// this setting for only TX   	
  	rIISCON = (1<<5) + (0<<4) + (1<<3) + (1<<2) + (0<<1) + (0<<0);	   
 	// 384fs , 32fs, 16BLC
 	rIISMOD = rIISMOD & ~(0x1fff) | (0<<12)|(0<<10)|(0<<8)|(0<<7)|(0<<5)|(2<<3)|(0<<1)|(0<<0);
 
	printf("\nIISLRCK = %d Hz", (int) IIS_Codec_CLK/384);

	// DMA2 MAsk Release
	rINTMSK = ~(BIT_DMA);
	rINTSUBMSK = ~(BIT_SUB_DMA2);

	printf("\nConnect head-phone plug into speaker-out socket on SMDK2411 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); 
	// 24bit APB ADDR Fix, 22bit auto Off, 20bit Word Transmit, 0:19 TC
	rDCON2   = (U32)((1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(1<<24)+(1<<22)+(2<<20)+(50)); 
	// 5:1= 4th bit is the tx iis     0:set = hw zero = sw
	rDMAREQSEL2 = (4<<1)+(1<<0);
	rDMASKTRIG2 = (0<<2) + (1<<1) + (0<<0);	    //No-stop, DMA2 channel On, and No-sw trigger 
       
	//IIS Tx Start
	rIISCON |= 0x1;		

	while(!Uart_GetKey())
	{
		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_PlayWave_DMA2_SLAVE(unsigned char *start_addr, unsigned int play_size)
{
	unsigned char Exit_Key;
	
	pISR_DMA = (unsigned)DMA2_Done;
	ClearPending(BIT_DMA);	
	rSUBSRCPND = BIT_SUB_DMA2;
	
	// FIFO Flush
	rIISFIC = rIISFIC | (1<<15);
	rIISFIC = rIISFIC & (0<<15);
        	
	// this setting for only TX   	
  	rIISCON = (1<<5) + (0<<4) + (1<<3) + (1<<2) + (0<<1) + (0<<0);	   
 	// 384fs , 32fs, 16BLC
 	rIISMOD = rIISMOD & ~(0x1fff) | (3<<10)|(0<<8)|(0<<7)|(0<<5)|(2<<3)|(0<<1)|(0<<0);
 
	printf("\nIISLRCK = %d Hz", (int) IIS_Codec_CLK/384);

	// DMA2 MAsk Release
	rINTMSK = ~(BIT_DMA);
	rINTSUBMSK = ~(BIT_SUB_DMA2);

	printf("\nConnect head-phone plug into speaker-out socket on SMDK2411 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); 
	// 24bit APB ADDR Fix, 22bit auto Off, 20bit Word Transmit, 0:19 TC
	rDCON2   = (U32)((1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(1<<24)+(1<<22)+(2<<20)+(50)); 
	// 5:1= 4th bit is the tx iis     0:set = hw zero = sw
	rDMAREQSEL2 = (4<<1)+(1<<0);
	rDMASKTRIG2 = (0<<2) + (1<<1) + (0<<0);	    //No-stop, DMA2 channel On, and No-sw trigger 
       
	//IIS Tx Start
	rIISCON |= 0x1;		

	while(!Uart_GetKey())
	{
		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_RecSound_DMA1_SLV(int mode, unsigned int rec_size)
{
	int Exit_Key;
	int iIndex, iFault=0, iGood=0, iLoop=0; 

	pISR_DMA = (unsigned)DMA1_Rec_Done;
	
	ClearPending(BIT_DMA);	
	rSUBSRCPND = BIT_SUB_DMA1;
	
	// FIFO flush
	rIISFIC = rIISFIC | (1<<7);
	rIISFIC = rIISFIC & (0<<7);	
	
	// 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;	   
	rIISMOD = rIISMOD & ~(0x1fff) | (0<<12)|(3<<10)|(1<<8) | (0<<7) | (0<<5) | (2<<3) | (0<<1) | (0<<0); //32fs
	
	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"); 
	getchar(); 

	// DMA 1 Mask Release. 
	rINTMSK = ~(BIT_DMA);
	rINTSUBMSK = ~(BIT_SUB_DMA1);



	//--- DMA1 Initialize
	rDISRCC1 = (1<<1) + (1<<0);   
	rDISRC1  = ((unsigned int)0x55000014);    
	rDIDSTC1 = (0<<1) + (0<<0);     
	rDIDST1  = (int)rec_buf;                            
	// 24bit APB ADDR fixed, 22bit Auto Off, 20bit Word transmit, 0:19 TC
	rDCON1   = (U32)((1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(1<<24)+(1<<22)+(2<<20)+(50));	// auto off test
	rDMAREQSEL1 = (5<<1) + (1<<0); 
	rDMASKTRIG1 = (0<<2) + (1<<1) + (0<<0);          //No-stop[2], DMA1 channel On[1], No-sw trigger[0] 

	//IIS Rx start	
	rIISCON |= 0x1;	 // I2S start
	

	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);	//DMA1 stop
	rIISFIC    = 0x0;			//For FIFO flush

	rINTSUBMSK |= (BIT_SUB_DMA1);	
	rINTMSK |= (BIT_DMA);

	printf("\nEnd of Record!\n");
	
	getchar();
	
 	for(iIndex = 0 ; iIndex < 1048576 ; iIndex = iIndex + 4)
  	{
  		if ( *(unsigned int *)(0x31000028+iIndex)==(iLoop))
  		{
  			iGood++;
  			iLoop++;
  		}
  		else
  		{
  			iFault++;
  			iLoop++;
  		}
  	}
  	printf("\n\n Result Bad: %d  Good: %d", iFault, iGood );
}

void IIS_RecSound_DMA1_MASTER(int mode, unsigned int rec_size)
{
	int Exit_Key;
	int iIndex, iFault=0, iGood=0, iLoop=0; 

	pISR_DMA = (unsigned)DMA1_Rec_Done;
	
	ClearPending(BIT_DMA);	
	rSUBSRCPND = BIT_SUB_DMA1;
	
	// FIFO flush
	rIISFIC = rIISFIC | (1<<7);
	rIISFIC = rIISFIC & (0<<7);

	// 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;	   
	rIISMOD = rIISMOD & ~(0x1fff) | (0<<12)|(0<<10)|(1<<8) | (0<<7) | (0<<5) | (2<<3) | (0<<1) | (0<<0); //32fs
	
	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"); 
	getchar(); 

	// DMA 1 Mask Release. 
	rINTMSK = ~(BIT_DMA);
	rINTSUBMSK = ~(BIT_SUB_DMA1);

	//--- DMA1 Initialize
	rDISRCC1 = (1<<1) + (1<<0);   
	rDISRC1  = ((unsigned int)0x55000014);    
	rDIDSTC1 = (0<<1) + (0<<0);     
	rDIDST1  = (int)rec_buf;                            
	// 24bit APB ADDR fixed, 22bit Auto Off, 20bit Word transmit, 0:19 TC
	rDCON1   = (U32)((1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(1<<24)+(1<<22)+(2<<20)+(50));	// auto off test
	rDMAREQSEL1 = (5<<1) + (1<<0); 
	rDMASKTRIG1 = (0<<2) + (1<<1) + (0<<0);          //No-stop[2], DMA1 channel On[1], No-sw trigger[0] 

	//IIS Rx start
	rIISCON |= 0x1;	 // I2S start

	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);	//DMA1 stop
	rIISFIC    = 0x0;			//For FIFO flush

	rINTSUBMSK |= (BIT_SUB_DMA1);	
	rINTMSK |= (BIT_DMA);

	printf("\nEnd of Record!\n");
	
	getchar();
	
 	for(iIndex = 0 ; iIndex < 2000000 ; iIndex = iIndex + 4)
  	{
  		if ( *(unsigned int *)(0x31000028+iIndex)==(iLoop))
  		{
  			iGood++;
  			iLoop++;
  		}
  		else
  		{
  			iFault++;
  			iLoop++;
  		}
  	}
  	printf("\n\n Result Bad: %d  Good: %d", iFault, iGood );
}

void IIS_PlayWave_DMA2_EXTCLK(unsigned char *start_addr, unsigned int play_size)
{
	unsigned char Exit_Key;
	
	
	pISR_DMA = (unsigned)DMA2_Done;
	ClearPending(BIT_DMA);	
	rSUBSRCPND = BIT_SUB_DMA2;

	// 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 & ~(0x1fff) | (1<<12)|(1<<10)|(0<<8)|(0<<7)|(0<<5)|(2<<3)|(0<<1)|(0<<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)(1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(0<<22)+(2<<20)+(U32)(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");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -