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

📄 iis_test.c

📁 S3C2410学习的基础资料 大部分实验源码及工程
💻 C
字号:
/*********************************************************************************************
* File:	iis.c
* Author:		
* Desc:	IIS sound circuit code
* History:	
*********************************************************************************************/

/*------------------------------------------------------------------------------------------*/
/*	 								include files						 				    */
/*------------------------------------------------------------------------------------------*/
#include "2410lib.h"
#include "iis_test.h"
#include "def.h"
#include "2410addr.h"

/*------------------------------------------------------------------------------------------*/
/*	 								constant define						 				    */
/*------------------------------------------------------------------------------------------*/
#define PLAY 		0
#define RECORD 		1
#define REC_LEN		0xf0000
#ifdef BOARDTEST_EXH
#undef BOARDTEST
#endif	

/*------------------------------------------------------------------------------------------*/
/*	 								extern variables						 			    */
/*------------------------------------------------------------------------------------------*/
extern const UINT8 g_ucWave[155760];

/*------------------------------------------------------------------------------------------*/
/*	 								global variables						 			    */
/*------------------------------------------------------------------------------------------*/
int   f_nDMADone;

/*********************************************************************************************
* name:		iis_test
* func:		Test IIS circuit
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void iis_test(void)
{
	UINT8	ucInput;
	int nSoundLen=155956;//语音文件的长度
	UINT32 g_nKeyPress;
	Uart_Printf("\n IIS test beginning \n");
    //IIS模块初始化
    iis_init();							// initialize IIS

    Uart_Printf(" Menu(press digital to select):\n");
    Uart_Printf(" 1: play wave file \n");
    Uart_Printf(" 2: record and play\n");
    
	g_nKeyPress = 1;					// only for board test to select and exit
	while((ucInput != '1') & (ucInput != '2'))
	{
   		ucInput = Uart_GetKey();
   		if(g_nKeyPress!=1)				// SB1202/SB1203 to exit board test
   		{
   			ucInput='1';				// any select "Play wav"
   			break;
   		}
	};
	
	Uart_Printf(" %c\n",ucInput);
	if(ucInput == 0x31)
	{
#ifndef BOARDTEST
		memcpy((void *)0x30200000, g_ucWave, nSoundLen);	
#endif
		iis_play_wave(1,(UINT8 *)0x30200000,nSoundLen);//		nSoundLen = 155956; 
	}
	if(ucInput == 0x32)
		iis_record();

	Uart_Printf(" end.\n");
    iis_close();						// close IIS
}

/*********************************************************************************************
* name:		iis_init
* func:		Initialize IIS circuit
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void iis_init(void)
{
	//----------------------------------------------------------
	//   PORT B GROUP
	//Ports  :   GPB4    GPB3   GPB2  
	//Signal :  L3CLOCK L3DATA L3MODE
	//Setting:   OUTPUT OUTPUT OUTPUT 
	//           [9:8]   [7:6}  [5:4]
	//Binary :     01  ,   01    01 
	//----------------------------------------------------------    
    rGPBUP  = rGPBUP  & ~(0x7<<2) | (0x7<<2);	//The pull up function is disabled GPB[4:2] 1 1100    
    rGPBCON = rGPBCON & ~((1<<9)|(1<<7)|(1<<5)) | (1<<8)|(1<<6)|(1<<4); //GPB[4:2]=Output(L3CLOCK):Output(L3DATA):Output(L3MODE)

	//----------------------------------------------------------
	//   PORT E GROUP
	//Ports  :  GPE4    GPE3   GPE2  GPE1    GPE0 
	//Signal : I2SSDO  I2SSDI CDCLK I2SSCLK I2SLRCK 
	//Binary :   10  ,   10     10 ,  10      10    
	//----------------------------------------------------------
    rGPEUP  = rGPEUP | 0x1f;    //The pull up function is disabled GPE[4:0] 1 1111
    rGPECON = rGPECON & ~((1<<8)|(1<<6)|(1<<4)|(1<<2)|(1<<0)) | (1<<9)|(1<<7)|(1<<5)|(1<<3)|(1<<1);
    //GPE[4:0]=I2SSDO:I2SSDI:CDCLK:I2SSCLK:I2SLRCK
	
	f_nDMADone = 0;
	//初始化UDA1341
	init_1341(PLAY);							// initialize philips UDA1341 chip
}

/*********************************************************************************************
* name:		iis_close
* func:		Close IIS circuit
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void iis_close()
{
    rIISCON  = 0x0;								// IIS stop
    rIISFCON = 0x0;							// For FIFO flush
	rINTMSK |= BIT_DMA2;						// Mask interrupt
}

/*********************************************************************************************
* name:		iis_play_wave
* func:		play wave data
* para:		nTimes 	--	input, play times
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void iis_play_wave(int nTimes,UINT8 *pWavFile, int nSoundLen)
{
	int	i;	

	ClearPending(BIT_DMA2);						
	rINTMOD = 0x0;
	
	// initialize philips UDA1341 chip
	init_1341(PLAY);	

    // set BDMA interrupt
	pISR_DMA2 = (unsigned)dma2_done;
	rINTMSK  &= ~(BIT_DMA2);
    
 	for(i=nTimes; i!=0; i--)
	{
		// initialize variables
		f_nDMADone = 0;
		
		//DMA2 Initialize
		rDISRCC2 = (0<<1) + (0<<0);             //AHB, Increment
		rDISRC2  = ((UINT32)(pWavFile));                    
		rDIDSTC2 = (1<<1) + (1<<0);             //APB, Fixed
		rDIDST2  = ((UINT32)IISFIFO);           //IISFIFO
		rDCON2   = (1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(0<<24)+(1<<23)+(0<<22)+(1<<20)+nSoundLen/2;
		//Handshake, sync PCLK, TC int, single tx, single service, I2SSDO, I2S request, 
		//Auto-reload, half-word, size/2
		rDMASKTRIG2 = (0<<2)+(1<<1)+0;    		//No-stop, DMA2 channel on, No-sw trigger 

		//IIS Initialize
		//Master,Tx,L-ch=low,iis,16bit ch.,CDCLK=384fs,IISCLK=32fs
		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;            		//Prescaler_A/B=3 
	
		//Tx DMA enable,Rx DMA disable,Tx not idle,Rx idle,prescaler enable,stop
		rIISFCON = (1<<15) + (1<<13);       	//Tx DMA,Tx FIFO --> start piling....
	
	    rIISCON |= 0x1;             			// enable IIS   
	    while( f_nDMADone == 0);      			// DMA end
	    
	    rINTMSK |= BIT_DMA2;	    
	    rIISCON = 0x0;    						// IIS stop
	}
}

/*********************************************************************************************
* name:		iis_record
* func:		record and play wave file
* para:		nTimes 	--	input, play times
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void iis_record(void)
{

	UINT8 * pRecBuf,ucInput;
	int nSoundLen;
    int i;
    
	// enable interrupt
	ClearPending(BIT_DMA2);						
	rINTMOD=0x0;

	//----------------------------------------------------------------//
	//						record									  //
	//----------------------------------------------------------------//
    Uart_Printf(" Start recording....\n");  
	
    pRecBuf = (unsigned char *)0x30200000; 		// for download
    for(i= (UINT32)pRecBuf; i<((UINT32)pRecBuf+REC_LEN+0x20000); i+=4)
    {
    	*((volatile unsigned int*)i)=0x0;    
	}

    init_1341(RECORD);

    // set BDMA interrupt
	f_nDMADone = 0;
    pISR_DMA2 = (unsigned)dma2_done;
    rINTMSK  &= ~(BIT_DMA2);

	//--- DMA2 Initialize
	rDISRCC2 = (1<<1) + (1<<0);                 //APB, Fix  
	rDISRC2  = ((UINT32)IISFIFO);              //IISFIFO
	rDIDSTC2 = (0<<1) + (0<<0);                 //AHB, Increment
	rDIDST2  = ((int)pRecBuf);                  
	//Handshake, sync APB, TC int, single tx, single service, I2SSDI, I2S Rx request, 
	//Off-reload, half-word, 0x50000 half word.
	rDCON2   = (1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(1<<24)+(1<<23)+(1<<22)+(1<<20)+REC_LEN/2;
	//No-stop, DMA2 channel on, No-sw trigger
	rDMASKTRIG2 = (0<<2) + (1<<1) + 0;    
	
	//IIS Initialize
	//Master,Rx,L-ch=low,IIS,16bit ch,CDCLK=384fs,IISCLK=32fs
	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; 	
	//Tx DMA disable,Rx DMA enable,Tx idle,Rx not idle,prescaler enable,stop
	rIISFCON = (1<<14) + (1<<12);   			//Rx DMA,Rx FIFO --> start piling....
	rIISCON |= 0x1;             				// enable IIS   
    Uart_Printf(" Press any key to end recording\n");  

    while(f_nDMADone == 0)
    {
    	if(Uart_GetKey())	break;
	}    
    rINTMSK |= BIT_DMA2;
    rIISCON = 0x0;								// IIS stop
    Delay(10);

    Uart_Printf(" End of record!!!\n");
    Uart_Printf(" Press any key to play record data!!!\n");
    while(!Uart_GetKey());

	//----------------------------------------------------------------//
	//						play									  //
	//----------------------------------------------------------------//
	iis_play_wave(1,pRecBuf, REC_LEN);
    	    
    rINTMSK |= BIT_DMA2;
    rIISCON = 0x0;    							// IIS stop
    Uart_Printf(" Play end!!!\n");
}

/*********************************************************************************************
* name:		bdma0_done
* func:		BDMA0 interrupt handler
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void __irq dma2_done(void)
{
	ClearPending(BIT_DMA2);						// clear pending bit
    f_nDMADone = 1;
}


⌨️ 快捷键说明

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