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

📄 iis.c

📁 三星2413芯片的测试代码,对进行驱动开发很有帮助.
💻 C
📖 第 1 页 / 共 4 页
字号:
}

void IIS_PlayWave_DMA2_SLAVE_SlaveTest(unsigned char *start_addr, unsigned int play_size)
{
	unsigned char Exit_Key;
	
	pISR_DMA2 = (unsigned)DMA2_Done;
	ClearPending(BIT_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 = (2<<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_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");
	
	//DMA2 Register Setting 
	rDISRC2  = (int)(start_addr); 
	rDISRCC2 = (0<<1) + (0<<0); 		  
	rDIDST2  = ((unsigned int)0x55000010);			
	rDIDSTC2 = (0<<2)+ (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)+(262144);
	// 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();
    	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);	
	rINTMSK |= (BIT_DMA2);
 	
	printf("\nEnd of Play!\n");
}

void IIS_RecSound_DMA1_SLAVE(int mode, unsigned int rec_size)
{
	int Exit_Key;
	int iIndex, iFault=0, iGood=0, iLoop=0; 
	
	pISR_DMA2 = (unsigned)DMA1_Rec_Done;
	ClearPending(BIT_DMA2);	

	rIISCON = (0<<5) + (1<<4) + (0<<3) +(0<<2) + (1<<1) + 0;	   
  	// using pclk, rx only , left for channel,iis format ,384fs , 32fs ,16bit  	
 	rIISMOD = (2<<10)+(1<<8) + (0<<7)+ (0<<5) + (2<<3)+ (0<<1) + (0<<0);
  	// using pclk, rx only , left for channel,iis format ,384fs , 48fs ,16bit  	
// 	rIISMOD = (IMS<<10)+(1<<8) + (0<<7)+ (0<<5) + (2<<3)+ (1<<1) + (0<<0);
  	// using pclk, rx only , left for channel,iis format ,768fs , 32fs ,16bit  	
// 	rIISMOD = (IMS<<10)+(1<<8) + (0<<7)+ (0<<5) + (3<<3)+ (0<<1) + (0<<0);
  	// using pclk, rx only , left for channel,iis format ,768fs , 48fs ,16bit  	
// 	rIISMOD = (IMS<<10)+(1<<8) + (0<<7)+ (0<<5) + (3<<3)+ (1<<1) + (0<<0);
  	// using pclk, rx only , left for channel,iis format ,384fs , 32fs ,8bit  	
// 	rIISMOD = (IMS<<10)+(1<<8) + (0<<7)+ (0<<5) + (2<<3)+ (0<<1) + (1<<0);
  	// using pclk, rx only , left for channel,iis format ,384fs , 48fs ,8bit  	
// 	rIISMOD = (IMS<<10)+(1<<8) + (0<<7)+ (0<<5) + (2<<3)+ (1<<1) + (1<<0);
  	// using pclk, rx only , left for channel,iis format ,768fs , 32fs ,8bit  	
// 	rIISMOD = (IMS<<10)+(1<<8) + (0<<7)+ (0<<5) + (3<<3)+ (0<<1) + (1<<0);
  	// using pclk, rx only , left for channel,iis format ,768fs , 48fs ,8bit  	
// 	rIISMOD = (IMS<<10)+(1<<8) + (0<<7)+ (0<<5) + (3<<3)+ (1<<1) + (1<<0);

	rIISFIC = rIISFIC | (1<<7);
	rIISFIC = rIISFIC & (0<<7);

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

	for(iIndex=0;iIndex<500000;iIndex+=1)
	{
		*((unsigned int*)(0x31000028)+iIndex)=0x0;
	}
	printf("\n Check 0x31000028 Memory Init \n");
	getchar();

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


	//--- DMA1 Initialize
	rDISRCC2 = (1<<1) + (1<<0);   
	rDISRC2  = ((unsigned int)0x55000014);    
	rDIDSTC2 = (0<<1) + (0<<0);     
	rDIDST2  = (int)rec_buf;                            
//	rDCON2   = (1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(1<<22)+(2<<20)+(5);
	rDCON2   = (1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(0<<22)+(2<<20)+(262144);
	rDMAREQSEL2 = (5<<1) + (1<<0); 
	rDMASKTRIG2 = (0<<2) + (1<<1) + (0<<0);          //No-stop[2], DMA1 channel On[1], No-sw trigger[0] 


	rIISCON |= 0x1;
	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("Recording...\n");

	//IIS Rx start

	while(!Uart_GetKey())
	{
		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
	rDMASKTRIG2 = (1<<2);	//DMA1 stop
	rIISFIC    = 0x0;			//For FIFO flush

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

	printf("\nEnd of Record!\n");	
	
  	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_MASTER(int mode, unsigned int rec_size)
{
	int Exit_Key;
	int iIndex, iFault=0, iGood=0, iLoop=0; 
	
	pISR_DMA2 = (unsigned)DMA1_Rec_Done;
	ClearPending(BIT_DMA2);	

	rIISCON = (0<<5) + (1<<4) + (0<<3) +(0<<2) + (1<<1) + 0;	   
  	// using pclk, rx only , left for channel,iis format ,384fs , 32fs ,16bit  	
 	rIISMOD = (0<<10)+(1<<8) + (0<<7)+ (0<<5) + (2<<3)+ (0<<1) + (0<<0);

	rIISFIC = rIISFIC | (1<<7);
	rIISFIC = rIISFIC & (0<<7);

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

	for(iIndex=0;iIndex<500000;iIndex+=1)
	{
		*((unsigned int*)(0x31000028)+iIndex)=0x0;
	}
	printf("\n Check 0x31000028 Memory Init \n");
	getchar();

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


	//--- DMA1 Initialize
	rDISRCC2 = (1<<1) + (1<<0);   
	rDISRC2  = ((unsigned int)0x55000014);    
	rDIDSTC2 = (0<<1) + (0<<0);     
	rDIDST2  = (int)rec_buf;                            
//	rDCON2   = (1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(1<<22)+(2<<20)+(5);
	rDCON2   = (1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(0<<22)+(2<<20)+(262144);
	rDMAREQSEL2 = (5<<1) + (1<<0); 
	rDMASKTRIG2 = (0<<2) + (1<<1) + (0<<0);          //No-stop[2], DMA1 channel On[1], No-sw trigger[0] 


	rIISCON |= 0x1;
	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("Recording...\n");

	//IIS Rx start

	while(!Uart_GetKey())
	{
		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
	rDMASKTRIG2 = (1<<2);	//DMA1 stop
	rIISFIC    = 0x0;			//For FIFO flush

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

	printf("\nEnd of Record!\n");	
	
  	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 );
}


// ------------------------------- Sub Function ---------------------------------------

void IIS_Port_Init(void)
{
	save_GPE_CON = rGPECON;	 
	save_GPB_CON = rGPBCON;	 
   	
   	//----------------------------------------------------------
	//PORT B GROUP
	//Ports  :   GPB2         GPB4           GPB3  
	//Signal :  L3MODE     L3CLOCK    L3DATA
	//Setting:  OUTPUT     OUTPUT      OUTPUT 
	//	          [11:10]      [13:12]      [15:14]
	//Binary :  01             01              01 
	//----------------------------------------------------------    
    rGPBCON = rGPBCON & ~(0x3<<4) & ~(0x3<<6) & ~(0x3<<8); 
   	rGPBCON |= (0x1<<4) |(0x1<<6) |(0x1<<8); // output setting
   
   	//-------------------------------------------------------------------------------
	//PORT E GROUP
	//Ports  :     GPE4    		 GPE3             GPE2           GPE1            GPE0 
	//Signal :    I2S DO           I2S DI         CDCLK        I2S CLK        I2S LRCLK
	//Binary :   10,                10,             10,              10,              10,            10    
	//-------------------------------------------------------------------------------
	rGPECON = rGPECON & ~(0x3ff) | 0x2aa;   
	rGPEDN = 0xffff; // pull_down disable

}

void IIS_Port_Return(void)
{
	rGPBCON = save_GPB_CON;
   	rGPECON = save_GPE_CON;

}

void Init1341(int mode)
{
 	
	//----------------------------------------------------------
	//PORT B GROUP
	//Ports  :   GPB3  		GPB4  		GPB2
	//Signal :   L3DATA      L3CLOCK 	L3MODE 
	//Setting:  OUTPUT      OUTPUT 		OUTPUT
	//	          [7:6]		[9:8] 		[5:4] 
	//Binary :     01 	      01	      01
	//---------------------------------------------------------- 
    rGPBDAT &= ~(L3M|L3C|L3D) |(L3M|L3C);  //Start condition : L3M=H, L3C=H
	rGPBCON &= ~(0x3<<4) & ~(0x3<<6) & ~(0x3<<8);  
   	rGPBCON |= (0x1<<4) |(0x1<<6) |(0x1<<8); 
 
	if(mode == PLAY_IIS)
    {	//L3 Interface
	    _WrL3Addr(0x14 + 2);     //STATUS (000101xx+10)
	 	_WrL3Data(0x50,0);	 //0,1,01, 000,0 : Status 0,Reset, 384fs,IIS-bus,no DC-filtering
//		_WrL3Data(0x60,0);	 //0,1,10, 000,0 : Status 0,Reset, 256fs,IIS-bus,no DC-filtering

		_WrL3Addr(0x14 + 2);     //STATUS (000101xx+10)
	    _WrL3Data(0x81,0);	 //bit[7:0] => 1,0,0,0, 0,0,01 
    }
	//Record Sound via MIC-In
    if(mode == RECORD_MICIn)
    {
	  	_WrL3Addr(0x14 + 2);    //STATUS (000101xx+10)
		_WrL3Data(0xa2,0);	//bit[7:0] => 1,0,1,0,0,0,10
		
		_WrL3Addr(0x14 + 0);    //DATA0 (000101xx+00)
       	_WrL3Data(0xc2, 0);	//1100 0,010  : Extended addr(3bits), 010 
        _WrL3Data(0xf2, 0);	//111,100,10 : DATA0, MIC Amplifier Gain 21dB, input channel 2 select (input channel 1 off)              
    }
    //Record Sound via Line-In
   	if(mode == RECORD_LineIn)
   	{
	  	_WrL3Addr(0x14 + 2);    //STATUS (000101xx+10)
		_WrL3Data(0xa2,0);	//bit[7:0] => 1,0,1,0, 0,0,10 Gain of ADC 6dB, ADC(on) DAC(off)
		
		_WrL3Addr(0x14 + 0);    //DATA0 (000101xx+00)
       	_WrL3Data(0xc2, 0);	//1100 0,010  : Extended addr(3bits), 010 
      	_WrL3Data(0xf1, 0);	//111,100,01 : DATA0, MIC Amplifier Gain 15dB, input channel 1 select (input channel 2 off) 		      
   	}	
    if(mode == RECORD_PLAY_Simul)
	{
		_WrL3Addr(0x14 + 2);     //STATUS (000101xx+10)
   		_WrL3Data(0xa3,0);       // 1,0,1,0,0,0,11 : OGS=0,IGS=1,ADC_NI,DAC_NI,sngl speed,AonDon

   		_WrL3Addr(0x14 + 0);     //DATA0 (000101xx+00)
   		_WrL3Data(0xc2,0);       //11000,010  : DATA0, Extended addr(010) 
   		_WrL3Data(0xff,0);       //010,011,01 : DATA0, MS=9dB, Ch1=on Ch2=on
	}
    
}

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
}

void Select_IIS_Master_CLK(void)
{
	int sel;
	unsigned short Sampling_Rate;
	
	//printf("\nIIS Master Clock Source => MPLLin\n");
    printf("\nSelect IIS Master Clock Source\n");
	printf(" 1:I2SSYSCLK(MPLL Out), 2:EPLL(Not Use), 3:I2SSYSCLK(EREFCLK) CLK   = ");
	sel = GetIntNum();		
	printf("/n");
	
	switch(sel)
	{
		case 0://In case of IIS Master Clock Source = PCLK
		Select_PCLK();
		break;
		
		case 1://In case of IIS Master Clock Source = EXTCLK
		Select_EXTCLK();
		break;

		case 2://In case of IIS Master Clock Source = EPLL
		Select_PCLK();
		break;

		case 3://In case of IIS Master Clock Source = UPLL Ref. CLK
		Select_UPLL_Ref_CLK();
		break;
		
		default : 
		Select_PCLK();	

⌨️ 快捷键说明

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