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

📄 iis.c

📁 一个基于三星S3C2413的全部驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
	rIISMOD = (0<<8) + (1<<6) + (0<<5) + (0<<4) + (1<<3) + (1<<2) + (1<<0);
	rIISFIC = (1<<14) + (1<<12);	  

	printf("\nIISLRCK = %d Hz", (int) IIS_Codec_CLK/384);

	rINTMSK = ~(BIT_DMA1);
	//rINTSUBMSK=~(BIT_DMA1);

	//--- DMA1 Initialize
	rDISRCC1 = (1<<1) + (1<<0);   
	rDISRC1  = ((unsigned int)0x31000000);    
	rDIDSTC1 = (0<<1) + (0<<0);     
	rDIDST1  = (int)rec_buf;                            
	rDCON1   = (1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(1<<22)+(2<<20)+(rec_size/4);
	rDMAREQSEL1 = (3<<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 SMDK2411/2413?");
	if(mode ==2)
		printf("\n\nAre you ready to record sound via Line-In on SMDK2411/2413?");

	printf("\nPress any key to start record!\n");
	getchar();

	printf("Recording...\n");

	//IIS Rx start
	rIISCON |= 0x1;

	while(!Rec_Done)
	{
		//printf("STAT1: 0x%x CURR_TC: 0x%x		DCDST1: 0x%x\n", rDSTAT1&0x300000, rDSTAT1&0xfffff, rDCDST1);
		printf(".");
		Delay(2000);
	}

	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

	ClearPending(BIT_DMA1);	
//	rSUBSRCPND=(BIT_SUB_DMA1);

	rINTMSK |= (BIT_DMA1);

	printf("\nEnd of Record!\n");	
    	
}

void IIS_RecSound_DMA1_Repeat(unsigned char *start_addr, unsigned int rec_size)
{
	unsigned char Exit_Key;

	printf("\nIISLRCK = %d Hz", (int) IIS_Codec_CLK/384);

	//--- DMA1 Initialize
	rDISRCC1 = (1<<1) + (1<<0);   
	rDISRC1  = ((unsigned int)0x44700010);    
	rDIDSTC1 = (0<<1) + (0<<0);     
	rDIDST1  = (int)start_addr;                            
	rDCON1   = (1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(0<<22)+(2<<20)+(rec_size/4);
	rDMAREQSEL1 = (3<<1) + (1<<0); 
	rDMASKTRIG1 = (0<<2) + (1<<1) + (0<<0);          //No-stop[2], DMA1 channel On[1], No-sw trigger[0] 
	  
	printf("\nRecording...\n");

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

	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 __irq Rx_IIS_Int(void)
{
    rSUBSRCPND = BIT_SUB_RXD1;          //Clear pending bit (Requested)
    rSUBSRCPND;

    ClearPending(BIT_UART1);

    *_temp ++= RdURXH1(); 
}

void __irq DMA1_Rec_Done(void)
{
	ClearPending(BIT_DMA1);	
	//rSUBSRCPND=(BIT_DMA1);      

    Rec_Done = 1;
} 

void IIS_PlayWave_DMA2(unsigned char *start_addr, unsigned int play_size)
{
	unsigned char Exit_Key;
	
	pISR_DMA2 = (unsigned)DMA2_Done;
	ClearPending(BIT_DMA2);	
	   	
  	rIISCON = (0<<5) + (0<<4) +(1<<2) + (0<<1)+0;	   
  	rIISMOD = (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_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); 
	// 31: ACK 	30: sync pclk  29:curr_tc int setting 28:unit transfer 27:single service 22: reload 20:half word 
	rDCON2   = (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<<0);
	//
	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(!Uart_GetKey())
	{
		Exit_Key=getchar();
		
    	//->
		//khs.050510
		//	added for I2S bug test
    	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
		
	ClearPending(BIT_DMA2);	
	//rSUBSRCPND=(BIT_SUB_DMA2);

	rINTMSK |= (BIT_DMA2);
 	
	printf("\nEnd of Play!\n");
}

void IIS_Paly_Rec_Simul(unsigned char *start_addr, unsigned int play_size)
{
	unsigned char Exit_Key;
	int i;

	pISR_DMA1= (unsigned)Play_Rec_Simul;
	ClearPending(BIT_DMA1);	

	rIISCON = (1<<5) + (1<<4) + (0<<3) + (0<<2) + (1<<1);	   
	rIISMOD = (0<<8) + (3<<6) + (0<<5) + (0<<4) + (1<<3) + (1<<2) + (1<<0);
	rIISFIC = (1<<15) + (1<<14) + (1<<13) + (1<<12);	  

	printf("\nIISLRCK = %d Hz", (int) IIS_Codec_CLK/384);

	rINTMSK = ~(BIT_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)0x44700010);			
	rDIDSTC2 = (0<<2) + (1<<1) + (1<<0);				
	rDCON2   = (1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(0<<22)+(2<<20)+(play_size/4);
	rDMAREQSEL2 = (2<<1) + (1<<0); 
	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

	ClearPending(BIT_DMA1);	
	rINTMSK |=(BIT_DMA1);

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

}


void __irq DMA2_Done(void)
{

	rINTMSK |= (BIT_DMA2);
 	
	ClearPending(BIT_DMA2);	

	rIISCON	&= ~(1<<2)|(0<<0);
	rIISCON |= (1<<2)|(1<<0);
	
  	printf("\nPuhahah~~~");

	rINTMSK = ~(BIT_DMA2);
}


void __irq Play_Rec_Simul(void)
{
	
	rINTMSK |= (BIT_DMA1);
	ClearPending(BIT_DMA1);	

    rIISCON	&= ~(1<<0);
	rIISCON |= 0x1;
      
	printf("\nR~~~");	

	rINTMSK = ~(BIT_DMA1);
}

////////////////////////////////////////////////////////////////////////////////////
void _WrL3Addr(unsigned char data)
{	 
 	int i,j;

    	rGPBDAT  = rGPBDAT & ~(L3D | L3M | L3C) | L3C;	//L3D=L, L3M=L(in address mode), L3C=H

    	for(j=0;j<4;j++);	 //tsu(L3) > 190ns

	//GPB[4:2]=L3C:L3D:L3M
    	for(i=0;i<8;i++)	//LSB first
    	{
	  	if(data & 0x1)	//If data's LSB is 'H'
	  	{
			rGPBDAT &= ~L3C;	 //L3C=L
			rGPBDAT |= L3D;		 //L3D=H		 
			for(j=0;j<4;j++);	        //tcy(L3) > 500ns
			rGPBDAT |= L3C;		 //L3C=H
			rGPBDAT |= L3D;		 //L3D=H
			for(j=0;j<4;j++);	        //tcy(L3) > 500ns
	  	}
	  	else		//If data's LSB is 'L'
	  	{
			rGPBDAT &= ~L3C;	//L3C=L
			rGPBDAT &= ~L3D;	//L3D=L
			for(j=0;j<4;j++);	       //tcy(L3) > 500ns
			rGPBDAT |= L3C;	       //L3C=H
			rGPBDAT &= ~L3D;	//L3D=L
			for(j=0;j<4;j++);	       //tcy(L3) > 500ns		
	  	}
	  	data >>= 1;
    	}

    	rGPBDAT  = rGPBDAT & ~(L3D | L3M | L3C) | (L3C | L3M);	 //L3M=H,L3C=H   
}


void _WrL3Data(unsigned char data,int halt)
{
 	int i,j;

    	if(halt)
    	{
	  	rGPBDAT  = rGPBDAT & ~(L3D | L3M | L3C) | L3C;   //L3C=H(while tstp, L3 interface halt condition)	  
	  	for(j=0;j<4;j++);		//tstp(L3) > 190ns
    	}

    	rGPBDAT  = rGPBDAT & ~(L3D | L3M | L3C) | (L3C | L3M);   //L3M=H(in data transfer mode)	  
    	for(j=0;j<4;j++);		//tsu(L3)D > 190ns

	//GPB[4:2]=L3C:L3D:L3M
    	for(i=0;i<8;i++)
    	{
	  	if(data & 0x1)	//if data's LSB is 'H'
	  	{
	     		rGPBDAT &= ~L3C;		//L3C=L
	     		rGPBDAT |= L3D;			//L3D=H

	     		for(j=0;j<4;j++);			//tcy(L3) > 500ns
	     		rGPBDAT |= (L3C | L3D);	//L3C=H,L3D=H
	     		for(j=0;j<4;j++);		 	//tcy(L3) > 500ns
	  	}
	  	else		//If data's LSB is 'L'
	  	{
	     		rGPBDAT &= ~L3C;	//L3C=L
	     		rGPBDAT &= ~L3D;	//L3D=L
	     		for(j=0;j<4;j++);		//tcy(L3) > 500ns
	     		rGPBDAT |= L3C;		//L3C=H
	     		rGPBDAT &= ~L3D;	//L3D=L
	     		for(j=0;j<4;j++);		//tcy(L3) > 500ns
	  	}
		data >>= 1;		//For check next bit
    	}

    	rGPBDAT  = rGPBDAT & ~(L3D | L3M | L3C) | (L3C | L3M);    //L3M=H,L3C=H
}





⌨️ 快捷键说明

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