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

📄 iis.c

📁 s3c2410开发板的测试代码,包括lcd
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
*********************************************************
* Copyright (c)
* All rights reserved.				            
*
* 文件名称:Uart0.c
* 文件标识:
* 摘    要:S3C2410 IIS (UDA1341) Record & Play Test Program
*             (DMA2, Double Buffer, Record, Play)
* 当前版本:1.0
* 作    者:刘征
* 完成日期:2005.4.3
*
* 取代版本:
* 作    者:
* 完成日期:
*********************************************************
*/

/*
*********************************************************
*   					 头文件
*********************************************************
*/
#include "2410addr.h"
#include "2410lib.h"
#include "def.h"
#include "iis.h"
#include "wave.h"
#include "wave1.h"

/*
*********************************************************
*  				    函数原型
*********************************************************
*/
void ChangeDMA2(void);
void IIS_PortSetting(void);
void _WrL3Addr(U8 data);
void _WrL3Data(U8 data,int halt);
void __irq DMA2_Done(void);
void __irq DMA2_Rec_Done(void);
void __irq RxInt(void);
void __irq Muting(void);

/*
*********************************************************
*  					  常量
*********************************************************
*/
#define L3C (1<<4)              //GPB4 = L3CLOCK
#define L3D (1<<3)              //GPB3 = L3DATA
#define L3M (1<<2)              //GPB2 = L3MODE

#define PLAY    0
#define RECORD  1
//#define REC_LEN 0x50000         //327,680 Bytes
#define REC_LEN 0x100000         //1,048,576 Bytes

#define DataCount   0x10000     //IIS Master/Slave Data Rx/Tx Count
#define DataDisplay 0x100       //IIS Master Data Display Count

#define PollMode    0           //1: Polling Mode
#define DMA2Mode    1           //1: DMA2 Mode

/*
*********************************************************
*  					  变量
*********************************************************
*/
unsigned char  *_temp;
unsigned short *rec_buf;

volatile unsigned int size = 0;
volatile unsigned int   fs = 0;
volatile char    which_Buf = 1;
volatile char     Rec_Done = 0;
volatile char         mute = 1;

//------------------------------------------------------------------------------
//      S3c2410 IIS Configuration
// GPB4 = L3CLOCK, GPB3 = L3DATA, GPB2 = L3MODE
// GPE4 = I2SSDO,  GPE3 = I2SSDI, GPE2 = CDCLK, GPE1 = I2SSCLK, GPE0 = I2SLRCK  
//------------------------------------------------------------------------------

/*
*********************************************************
* 函数介绍:本函数是iis play 测试程序。				
* 输入参数:无
* 输出参数:无
* 返回值  :无
*********************************************************
*/
void Test_Iis(void)
{
    unsigned int save_B, save_E, save_PB, save_PE;
    volatile unsigned char key = 0;

    Uart_TxEmpty(0);
    
    ChangeClockDivider(1,1);        //1:2:4
    ChangeMPllValue(0x96,0x5,0x1);  //FCLK=135.428571MHz (PCLK=33.857142MHz)

    Uart_Init(33857142,115200);    
    
    Uart_Printf("[ IIS test (Play) using UDA1341 CODEC ]\n");
    
    save_B  = rGPBCON;       
    save_E  = rGPECON;       
    save_PB = rGPBUP;
    save_PE = rGPEUP;

    IIS_PortSetting();//set i/o port 

    //中断函数入口
    pISR_DMA2  = (unsigned)DMA2_Done;
    pISR_EINT0 = (unsigned)Muting;
    //外部中断0,串口0,DMA2  
    rINTMSK    = ~(BIT_EINT0 | BIT_DMA2);
    _temp = wave;
    
    while(1)
    {
    	Uart_Printf("You select play wave file :\n");
    	Uart_Printf("'1'--wave file1,  '2'--wave file2\n");
    	Uart_Printf("You put another key ---quit!\n");
    	key = Uart_Getch();
    	if(key == '1')
    	{
    		_temp = wave;//play wave file 1
    	}
    	else if(key == '2')
    	{
    		_temp = wave1;//play wave file 2
    	}
    	else 
    	{
    		key = 0; //quit
    		goto STOP;
    	}
	    
	    if(key == '1' || key == '2')
	    { 
		    //根据WAVE文件的格式得到文件大小
		    size = *(_temp + 0x28) | *(_temp + 0x29)<<8 | *(_temp + 0x2a)<<16 | *(_temp + 0x2b)<<24;
		    size = (size>>1)<<1;
		    
		    //根据WAVE文件的格式得到采样率
		    fs   = *(_temp + 0x18) | *(_temp + 0x19)<<8;
		
		    Uart_Printf("Sample Size = 0x%x\n",size/2);
		    Uart_Printf("Sampling Frequency = %d Hz\n",fs);
		    Uart_Printf("\n[ Now play the wave file .....]\n");
		    Uart_Printf("If you want to mute or no mute push the 'EIN0' key repeatedly\n");
		    
		    //initialize UDA1341
		    Init1341(PLAY);
		    //DMA2 Initialize
		    //0x31000030~(Remove header)    
		    rDISRC2  = (int)(_temp + 0x30);  
		    rDISRCC2 = (0<<1) + (0<<0);                 //The source is in the system bus(AHB), Increment      
		    rDIDST2  = ((U32)IISFIFO);                  //IISFIFO    
		    rDIDSTC2 = (1<<1) + (1<<0);                 //The destination is in the peripheral bus(APB), Fixed  
		    rDCON2   = (1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(0<<24)+(1<<23)+(0<<22)+(1<<20)+(size/4);
		      //1010 0000 1001 xxxx xxxx xxxx xxxx xxxx
		      //Handshake[31], Sync PCLK[30], CURR_TC Interrupt Request[29], Single Tx[28], Single service[27], 
		      //I2SSDO[26:24], DMA source selected[23],Auto-reload[22], Half-word[21:20], size/2[19:0]
		      
		    rDMASKTRIG2 = (0<<2) + (1<<1) + (0<<0);          //No-stop[2], DMA2 channel On[1], No-sw trigger[0] 
		
		      //IIS Initialize
		    if(fs==44100)               //11.2896MHz(256fs)
		        rIISPSR = (2<<5) + 2;   //Prescaler A,B=2 <- FCLK 135.4752MHz(1:2:4)     
		    else                        //fs=22050, 5.6448MHz(256fs)
		        rIISPSR = (5<<5) + 5;   //Prescaler A,B=5 <- FCLK 135.4752MHz(1:2:4)  
		        
		    rIISCON = (1<<5) + (1<<2) + (1<<1);         //Tx DMA enable[5], Rx idle[2], Prescaler enable[1]
		      //Master mode[8],Tx mode[7:6],Low for Left Channel[5],IIS format[4],16bit ch.[3],CDCLK 256fs[2],IISCLK 32fs[1:0]
		    rIISMOD = (0<<8) + (2<<6) + (0<<5) + (0<<4) + (1<<3) + (0<<2) + (1<<0);
		    
		    rIISFCON = (1<<15) + (1<<13);        //Tx DMA,Tx FIFO --> start piling....
		
		    Uart_Printf("\nPress 'q'or'Q' to exit!!!\n");
		    
		      //IIS Tx Start
		    rIISCON |= 0x1;             //IIS Interface start
		    while(!(key =Uart_Getch()))
		    {
			    if((rDSTAT2 & 0xfffff) < (size/6))
			    {
			    	ChangeDMA2();
			    }
			}
			//IIS Tx Stop
		    Delay(10);                   //For end of H/W Tx
		    rIISCON      = 0x0;          //IIS Interface stop
		    rDMASKTRIG2  = (1<<2);       //DMA2 stop
		    rIISFCON     = 0x0;          //For FIFO flush		
		    size = 0;
		    if(key == 'q' || key == 'Q')
		    {
		    	key = 0;
		    	goto STOP;
		    }
		    key = 0;
		}
    }
STOP:

    rGPBCON = save_B;
    rGPECON = save_E;
    rGPBUP  = save_PB;
    rGPEUP  = save_PE;

    rINTMSK = (BIT_DMA2 | BIT_EINT0);//关DMA2中断及外部中断0

    ChangeMPllValue(0xa1,0x3,0x1);    // FCLK=202.8MHz
    Uart_Init(0,115200);
    mute = 1;
}

/*
*********************************************************
* 函数介绍:本函数是iis record 测试程序。				
* 输入参数:无
* 输出参数:无
* 返回值  :无
*********************************************************
*/
void Record_Iis(void)
{
    unsigned int save_B, save_E, save_PB, save_PE;

    Uart_TxEmpty(0);

    ChangeClockDivider(1,1);        //1:2:4
    ChangeMPllValue(0x96,0x5,0x1);  //FCLK=135428571Hz, PCLK=3.385714MHz

    Uart_Init(33857142,115200);
    
    Uart_Printf("[ Record test using UDA1341 ]\n");
    
    save_B  = rGPBCON;       
    save_E  = rGPECON;       
    save_PB = rGPBUP;
    save_PE = rGPEUP;

    IIS_PortSetting();//I/O set 
        
      //Record Buf initialize, Non-cacheable area = 0x31000000 ~ 0x33feffff
    rec_buf = (unsigned short *)0x31000000;

    pISR_DMA2  = (unsigned)DMA2_Rec_Done;
    pISR_EINT0 = (unsigned)Muting;

    rINTMSK = ~(BIT_DMA2);

    Init1341(RECORD);

      //--- DMA2 Initialize
    rDISRCC2 = (1<<1) + (1<<0);                         //APB, Fix  
    rDISRC2  = ((U32)IISFIFO);                          //IISFIFO
    rDIDSTC2 = (0<<1) + (0<<0);                         //PHB, Increment
    rDIDST2  = (int)rec_buf;                            //0x31000000 ~
    rDCON2   = (1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(1<<24)+(1<<23)+(1<<22)+(1<<20)+REC_LEN;
      //Handshake, sync PCLK, TC int, single tx, single service, I2SSDI, I2S Rx request, 
      //Off-reload, half-word, 0x50000 half word.
    rDMASKTRIG2 = (0<<2) + (1<<1) + 0;    //No-stop, DMA2 channel on, No-sw trigger

      //IIS Initialize
      //Master,Rx,L-ch=low,IIS,16bit ch,CDCLK=256fs,IISCLK=32fs
    rIISMOD = (0<<8) + (1<<6) + (0<<5) + (0<<4) + (1<<3) + (0<<2) + (1<<0);
    rIISPSR = (2<<5) + 2; //Prescaler_A/B=2 <- FCLK 135.4752MHz(1:2:4),11.2896MHz(256fs),44.1KHz
    rIISCON = (0<<5) + (1<<4) + (1<<3) + (0<<2) + (1<<1);
      //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....

    Uart_Printf("Press any key to start record!!!\n");
    Uart_Getch();
    Uart_Printf("Recording...\n");

      //Rx start
    rIISCON |= 0x1;

    while(!Rec_Done);

    rINTMSK  = BIT_DMA2;
    Rec_Done = 0;

      //IIS Stop
    Delay(10);                          //For end of H/W Rx
    rIISCON     = 0x0;                  //IIS stop
    rDMASKTRIG2 = (1<<2);               //DMA2 stop
    rIISFCON    = 0x0;                  //For FIFO flush
    
    Uart_Printf("End of Record!!!\n");
    Uart_Printf("Press any key to play recorded data\n");
    Uart_Printf("If you want to mute or no mute push the 'EIN0' key repeatedly\n");
    Uart_Getch();//得到输入值

    size = REC_LEN * 2;
    Uart_Printf("Size = %d\n",size);
    
    //播放录入的音频数据
    Init1341(PLAY);

    pISR_DMA2 = (unsigned)DMA2_Done;
    rINTMSK   = ~(BIT_DMA2 | BIT_EINT0);

      //DMA2 Initialize
    rDISRCC2 = (0<<1) + (0<<0);                         //AHB, Increment
    rDISRC2  = (int)rec_buf;                            //0x31000000
    rDIDSTC2 = (1<<1) + (1<<0);                         //APB, Fixed
    rDIDST2  = ((U32)IISFIFO);                          //IISFIFO
    rDCON2   = (1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(0<<24)+(1<<23)+(0<<22)+(1<<20)+(size/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=256fs,IISCLK=32fs

⌨️ 快捷键说明

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