www.pudn.com > s3c2443_test_code.zip > iis.c


/*====================================================================== 
 
 Project Name : S3C2443 
 
 Copyright 2006 by Samsung Electronics, Inc. 
 All rights reserved. 
 
 Project Description : 
 This software is only for verifying functions of the S3C2443.  
 Anybody can use this code without our permission. 
 
 File Name    : iis.c 
 Description  : S3C2443 IIS module code 
 Author       : Junon Jeon 
 Dept         : AP 
 Created Date : 2006.06.02 
 Version      : 0.0 
 History 
   R0.0 (2006.06.02): Junon draft 
		- S3C2443 IIS test code is derived from S3C2413A IIS test code. 
		 
=======================================================================*/ 
 
#include "System.h" 
#include "iis.h"	 
 
 
 
#define IIS_BUFFER 0x31000000 
 
#define REC_LEN_IIS 0xfffff*4	//Max value of DMA Transfer Counter (20bit) = 0xfffff, Date Size=Word (4bytes) 
#define PLAY_IIS    0 
#define RECORD_MIC_IN  1 
#define RECORD_LINE_IN 2  
#define RECORD_PLAY_SIM 3 
  
#define L3C (1<<2)	// GPG2 = L3CLOCK 
#define L3D (1<<1)	// GPG1 = L3DATA  
#define L3M (1<<0)	// GPG0 = L3MODE 
 
// Global variables 
char which_Buf = 1; 
volatile char Rec_Done = 0; 
 
unsigned char  *Buf,*_temp; 
unsigned char *rec_buf = (unsigned char *)(IIS_BUFFER+0x28); 
unsigned char *rec_buf1 = (unsigned char *)(IIS_BUFFER + REC_LEN_IIS);  
 
unsigned int size, fs;  
unsigned int save_GPE_CON, save_GPG_CON; 
unsigned int save_GPE_DAT, save_GPG_DAT; 
 
float IIS_Codec_CLK; 
 
// Functions 
// GPIO port setting 
void IIS_Port_Init(void); 
void IIS_Port_Return(void); 
// L3 inteface function for initializing UDM1341 
void _WrL3Addr(unsigned char data); 
void _WrL3Data(unsigned char data,int halt); 
void Init1341(int); 
// IIS library 
unsigned int IIS_Select_SamplingRate(void); 
void Select_IIS_Master_CLK(void); 
void Select_PCLK(void); 
void Select_EXTCLK(void); 
void Select_EPLL(void); 
void Select_EPLL_Ref_CLK(void); 
void down_wav(void); 
 
void __irq Rx_IIS_Int(void); 
void __irq DMA1_Rec_Done(void); 
void __irq DMA2_Done(void); 
void __irq Play_Rec_Simul(void); 
 
 
void Play_Iis(void); 
void IIS_RecSound_DMA1( int mode, unsigned int rec_size); 
void IIS_RecSound_DMA1_Repeat(unsigned char *start_addr, unsigned int rec_size); 
void IIS_PlayWave_DMA2(unsigned char *start_addr, unsigned int play_size); 
void IIS_Paly_Rec_Simul(unsigned char *start_addr, unsigned int play_size); 
void IIS_RecSound_DMA1_SLV(int mode, unsigned int rec_size); 
void RecordSound_ViaLineIn_SLV(void); 
void Play_Iis_MASTER(void); 
void Data_init(void); 
void IIS_PlayWave_DMA2_MASTER(unsigned char *start_addr, unsigned int play_size); 
void RecordSound_ViaLineIn_MASTER(void); 
void IIS_RecSound_DMA1_MASTER(int mode, unsigned int rec_size); 
void Play_Iis_SLAVE(void); 
void IIS_PlayWave_DMA2_SLAVE(unsigned char *start_addr, unsigned int play_size); 
void Play_Iis_EXTCLK(void); 
void IIS_PlayWave_DMA2_EXTCLK(unsigned char *start_addr, unsigned int play_size); 
 
void * func_iis_test[][2]= 
{	 
	//IIS Function Test Item 
	//  									"123456789012345678901" 
   	(void *)Play_Iis,              			       "Play Wave            ",  
   	(void *)RecordSound_ViaMICIn_Playit,           "Record(MicIn) & Play ", 
   	(void *)RecordSound_ViaLineIn_Playit, 	       "Record(LineIn) & Play", 
    (void *)RECORD_PLAY_SIMtaneously,              "Record and Play Simultaneously. ",  
    (void *)RecordSound_ViaLineIn_MASTER,          "RECORD MASTER MODE", 
    (void *)Play_Iis_MASTER,              		   "PLAY  MASTER MODE           ",      
    (void *)RecordSound_ViaLineIn_SLV,             "RECORD SLAVE MODE", 
    (void *)Play_Iis_SLAVE,              		   "PLAY  SLAVE MODE           ",          
    (void *)Play_Iis_EXTCLK,                 "PLAY  EXT CDCLK            ", 
    0,0 
}; 
 
 
void Test_IIS(void) 
{ 
	int i; 
		 
	while(1) 
	{ 
		i=0; 
		printf("\n\n================== IIS Function Test =====================\n\n"); 
		 
		while(1) 
		{   //display menu 
			printf("%2d:%s",i,func_iis_test[i][1]); 
			i++; 
			if((int)(func_iis_test[i][0])==0) 
			{ 
				printf("\n"); 
				break; 
			} 
			if((i%1)==0) 
			printf("\n"); 
		} 
		printf("\n==========================================================\n"); 
		printf("Select #Item or Press Enter key to exit : "); 
		i = GetIntNum();  
		if(i==-1) break;		// return. 
		if(i>=0 && (i<((sizeof(func_iis_test)-1)/8)) )	// select and execute... 
			( (void (*)(void)) (func_iis_test[i][0]) )(); 
	} 
	 
} 
 
 
//============================== [ IIS Drivers ] =============================== 
 
// Setting Port related to IIS   
void IIS_Port_Init(void) 
{ 
	save_GPG_CON = rGPGCON;	// L3 
	save_GPE_CON = rGPECON;	// IIS 
   	 
   	//---------------------------------------------------------- 
	//PORT G GROUP 
	//Ports  :   GPG0       GPG1        GPG2   
	//Signal :  L3MODE     L3DATA      L3CLK 
	//Setting:  OUTPUT     OUTPUT      OUTPUT  
	//	        [1:0]      [3:2]       [5:4] 
	//Binary :  01          01           01  
	//----------------------------------------------------------     
    rGPGCON = rGPGCON & ~(0x3f) | (1<<4)|(1<<2)|(1); // 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   
	//------------------------------------------------------------------------------- 
	rGPECON = rGPECON & ~(0x3ff) | 0x2aa; // IIS function setting 
	rGPEUDP = 0xffffffff; // pull_up_down disable 
} 
 
 
void IIS_Port_Return(void) 
{ 
	rGPGCON = save_GPG_CON; 
   	rGPECON = save_GPE_CON; 
} 
 
 
// L3 interface library 
void _WrL3Addr(unsigned char data) 
{	  
 	int i,j; 
 
   	rGPGDAT  = rGPGDAT & ~(L3D | L3M | L3C) | L3C;	//L3D=L, L3M=L(in address mode), L3C=H 
 
   	for(j=0;j<4;j++);	 //tsu(L3) > 190ns 
 
   	for(i=0;i<8;i++)	//LSB first 
   	{ 
	  	if(data & 0x1)	//If data's LSB is 'H' 
	  	{ 
			rGPGDAT &= ~L3C;	//L3C=L 
			rGPGDAT |= L3D;		//L3D=H		  
			for(j=0;j<4;j++);	//tcy(L3) > 500ns 
			rGPGDAT |= L3C;		//L3C=H 
			rGPGDAT |= L3D;		//L3D=H 
			for(j=0;j<4;j++);	//tcy(L3) > 500ns 
	  	} 
	  	else		//If data's LSB is 'L' 
	  	{ 
			rGPGDAT &= ~L3C;	//L3C=L 
			rGPGDAT &= ~L3D;	//L3D=L 
			for(j=0;j<4;j++);	//tcy(L3) > 500ns 
			rGPGDAT |= L3C;	    //L3C=H 
			rGPGDAT &= ~L3D;	//L3D=L 
			for(j=0;j<4;j++);	//tcy(L3) > 500ns		 
	  	} 
	  	data >>= 1; 
   	} 
 
   	rGPGDAT  = rGPGDAT & ~(L3D | L3M | L3C) | (L3C | L3M);	 //L3M=H,L3C=H    
} 
 
 
void _WrL3Data(unsigned char data,int halt) 
{ 
 	int i,j; 
 
   	if(halt) 
   	{ 
	  	rGPGDAT  = rGPGDAT & ~(L3D | L3M | L3C) | L3C;   //L3C=H(while tstp, L3 interface halt condition)	   
	  	for(j=0;j<4;j++);		//tstp(L3) > 190ns 
   	} 
 
   	rGPGDAT  = rGPGDAT & ~(L3D | L3M | L3C) | (L3C | L3M);   //L3M=H(in data transfer mode)	   
   	for(j=0;j<4;j++);		//tsu(L3)D > 190ns 
 
   	for(i=0;i<8;i++) 
   	{ 
	  	if(data & 0x1)	//if data's LSB is 'H' 
	  	{ 
	    	rGPGDAT &= ~L3C;		//L3C=L 
	    	rGPGDAT |= L3D;			//L3D=H 
			for(j=0;j<4;j++);		//tcy(L3) > 500ns 
	    	rGPGDAT |= (L3C | L3D);	//L3C=H,L3D=H 
	    	for(j=0;j<4;j++);		//tcy(L3) > 500ns 
	  	} 
	  	else		//If data's LSB is 'L' 
	  	{ 
	    	rGPGDAT &= ~L3C;		//L3C=L 
	    	rGPGDAT &= ~L3D;		//L3D=L 
	    	for(j=0;j<4;j++);		//tcy(L3) > 500ns 
	    	rGPGDAT |= L3C;			//L3C=H 
	    	rGPGDAT &= ~L3D;		//L3D=L 
	    	for(j=0;j<4;j++);		//tcy(L3) > 500ns 
	  	} 
		data >>= 1;		//For check next bit 
   	} 
 
   	rGPGDAT  = rGPGDAT & ~(L3D | L3M | L3C) | (L3C | L3M);    //L3M=H,L3C=H 
} 
 
 
//Initialization of UDA1341 Audio Codec using L3 Interface  
void Init1341(int mode) 
{ 
    rGPGDAT = rGPGDAT & ~(L3M|L3C|L3D) |(L3M|L3C);  //Start condition : L3M=H, L3C=H 
  
  
	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	 	 
//	 	_WrL3Data(0x40,0);	 //0,1,00, 000,0 : Status 0,Reset, 512fs,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_MIC_IN) 
    { 
	  	_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_LINE_IN) 
   	{ 
	  	_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) 		       
   	}	 
   	// Record & play simultaneously 
	if(mode == RECORD_PLAY_SIM) 
	{ 
		_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 
	} 
} 
 
 
unsigned int IIS_Select_SamplingRate(void) 
{ 
	int i; 
	 
	printf("\nSelect ADC/DAC Rate\n"); 
	printf("0:11.025kHz, 1:22.05kHz, 2:44.1kHz, 3:88.2kHz\n"); 
	printf("4:8kHz, 5:16kHz, 6:32kHz, 7:48kHz, 8:64kHz, 9:96kHz\n"); 
	i = GetIntNum();	 
 
 
	switch(i) 
    { 
		case 0: 
    		return 11025; 
		case 1: 
    		return 22050; 
       	case 2: 
			return 44100; 
       	case 3: 
			return 88200; 
       	case 4: 
			return 8000; 
       	case 5: 
			return 16000; 
       	case 6: 
			return 32000; 
       	case 7: 
			return 48000; 
       	case 8: 
			return 64000; 
       	case 9: 
			return 96000; 
       	default: 
			return 44100; 
	}       
} 
 
 
// IIS source clock selection 
void Select_PCLK(void) 
{ 
	unsigned int pdf = 5; // prescaler division factor 
	 
	// SYSCON register setting 
	rPCLKCON |= (1<<9); // PCLK bus block of i2s enable 
	rSCLKCON |= (1<<9); // I2S source clock enable 
	rCLKDIV1 &= ~(0xf<<12);	// I2S clock divider for EPLL. 
	 
	// IIS clock register setting 
	rIISMOD = (rIISMOD & ~(7<<10)) | (0<<12)|(0<<10); // internal codec clock source, PCLK Master mode 
	rIISPSR = (1<<15)|(pdf);  // prescaler enable, prescaler division factor[9:0] 
		 
	//In case PCLK = 50 MHz, IIS Codec CLK = 50/(5+1) = 8.34MHz-->22KHz 
	printf("\nIIS Master CLK(PCLK) = %4.2f MHz", (float)PCLK/1000000); 
	IIS_Codec_CLK = (float)PCLK/(pdf+1); 
	printf("\nIIS Codec CLK = %4.2f MHz", IIS_Codec_CLK/1000000); 
 
} 
 
 
void Select_EXTCLK(void) 
{ 
	unsigned int pdf = 0; // prescaler division factor 
		 
	printf("\n Board To Board Test Source Board is OK? \n"); 
	 
	// SYSCON register setting 
	rPCLKCON |= (1<<9); // PCLK bus block of i2s enable 
	rSCLKCON |= (1<<9); // I2S source clock enable 
	rCLKSRC = (rCLKSRC & ~(3<<14)) | (1<<14); // I2S first source clock selection 
	rCLKDIV1 &= ~(0xf<<12);	// I2S clock divider for EPLL. 
	 
	// IIS clock register setting 
	rIISMOD = (rIISMOD & ~(7<<10)) | (1<<12)|(1<<10); // Get Codec clock froem extenal codec chip, using codeclki master mode 
	rIISPSR = (1<<15)|(pdf);  // prescaler enable, prescaler division factor[9:0] 
			 
} 
 
 
void Select_EPLL(void) 
{ 
	unsigned int pdf = 10; // prescaler division factor 
	 
	// SYSCON register setting 
	rPCLKCON |= (1<<9); // PCLK bus block of i2s enable 
	rSCLKCON |= (1<<9); // I2S source clock enable 
	rEPLLCON= (40<<16) | (1<<8) | 1;	// EPLL OUT IS 96Mhz   : (Mdiv<<16) | (Pdiv<<8) | Sdiv;	 
	rCLKSRC = (rCLKSRC & ~(3<<14)) | (0<<14); // I2S source clock selection EPLL divided clock 
	rCLKSRC = (rCLKSRC & ~(1<<6)) | (1<<6); //   ESYSCLK Soure is divided EPlL clock 
	rCLKDIV1 &= ~(0xf<<12);	// I2S clock divider for EPLL. 
			 
	Delay(100); 
	 
	rGPHCON = (rGPHCON & ~(3<<28)) | (2<<28); 
	rMISCCR = (rMISCCR & ~(7<<8))  | (1<<8); 
	printf("Check EPLL OUT!! and  Press Ant Key if You Want Go!!\n"); 
	getchar(); 
	 
	// IIS clock register setting 
	rIISMOD = (rIISMOD & ~(7<<10)) | (0<<12)|(1<<10); // internal codec clock source, EPLL Div Master mode 
	rIISPSR = (1<<15)|(pdf);  // prescaler enable, prescaler division factor[9:0] 
 
} 
 
 
void Select_EPLL_Ref_CLK(void) 
{ 
	unsigned int pdf = 1; // prescaler division factor	 
 
	rPCLKCON |= (1<<9); // PCLK bus block of i2s enable	 
	rSCLKCON |= (1<<9); // I2S source clock enable 
	rEPLLCON= (1<<24) | (40<<16) | (1<<8) | 1;	// EPLL Off , EPLL OUT IS 96Mhz   : (Mdiv<<16) | (Pdiv<<8) | Sdiv;	 
	rCLKSRC = (rCLKSRC & ~(3<<14)) | (3<<14); // I2S source clock selection EPLL reference clock 
	rCLKSRC = (rCLKSRC & ~(1<<6)) | (0<<6); //   ESYSCLK Soure is divided EPlL clock 
	rCLKDIV1 &= ~(0xf<<12);	// I2S clock divider for EPLL. 
			 
	Delay(100); 
	 
	rGPHCON = (rGPHCON & ~(3<<28)) | (2<<28); 
	rMISCCR = (rMISCCR & ~(7<<8))  | (1<<8); 
	printf("Check EPLL OUT!! and  Press Ant Key if You Want Go!!\n"); 
	getchar(); 
	 
	// IIS clock register setting 
	rIISMOD = (rIISMOD & ~(7<<10)) | (0<<12)|(1<<10); // internal codec clock source, EPLL Div Master mode 
	rIISPSR = (1<<15)|(pdf);  // prescaler enable, prescaler division factor[9:0] 
 
} 
 
 
void Select_IIS_Master_CLK(void) 
{ 
	int sel; 
	//unsigned short Sampling_Rate; 
	 
    printf("\nSelect IIS Master Clock Source\n"); 
	printf("0:PCLK[D], 1:IIS EXTCLK, 2:EPLL, 3:EPLL Ref. CLK\n"); 
	sel = GetIntNum();		 
	 
	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 Form GPIO (CDCLK input) 
		Select_EXTCLK(); 
		break; 
 
		case 2://In case of IIS Master Clock Source = divided EPLL or EPLL ref. 
		Select_EPLL(); 
		break; 
 
		case 3://In case of IIS Master Clock Source = EPLL Ref. CLK 
		Select_EPLL_Ref_CLK(); 
		break; 
		 
		default :  
		Select_PCLK();	 
		break;		 
	} 
} 
 
 
// download wave files 
void down_wav(void) 
{ 
	//Non-cacheable area = 0x31000000 ~ 0x33cf0000 
    Buf   = (unsigned char *)IIS_BUFFER; 
    _temp = Buf; 
     
    printf("Download the PCM(no ADPCM) file by DNW serial port(With header)!!\n"); 
    printf("Download address is %xh\n", Buf); 
    while(((unsigned int)_temp - (unsigned int)Buf) < 4) 
    { 
       Led_Display(0); 
       Delay(1500); 
       Led_Display(15); 
       Delay(1500); 
    } 
    printf("\ndata=%x",size); 
       
    size = *(Buf) | *(Buf + 1)<<8 | *(Buf + 2)<<16 | *(Buf + 3)<<24; 
    printf("\ndata=%x",size); 
     
    printf("\nNow, Downloading... [ File Size : %8d(      0)]",size); 
    while(((unsigned int)_temp - (unsigned int)Buf) < (size)){ 
	  printf("\b\b\b\b\b\b\b\b\b%8d)",(unsigned int)_temp - (unsigned int)Buf); 
		Delay(5000); 
    } 
    printf("\b\b\b\b\b\b\b\b\b%8d)]\n",(unsigned int)_temp - (unsigned int)Buf); 
 
    rINTSUBMSK |= BIT_SUB_RXD1; 
    rINTMSK  |= BIT_UART1; 
    size = *(Buf + 0x2c) | *(Buf + 0x2d)<<8 | *(Buf + 0x2e)<<16 | *(Buf + 0x2f)<<24; 
    size = (size>>1)<<1; 
    fs   = *(Buf + 0x1c) | *(Buf + 0x1d)<<8 | *(Buf + 0x1e)<<16 | *(Buf + 0x1f)<<24; 
 
    printf("Sample Size = %d\n",size/2); 
    printf("Sampling Frequency = %d Hz\n",fs); 
    printf("\n[ Now play the wave file .....]\n"); 
    printf("If you want to mute or no mute push the 'EIN0' key repeatedly\n"); 
} 
 
 
//=================================== [ IIS Test codes ] ================================== 
 
void __irq DMA2_Done(void) 
{ 
	rINTSUBMSK |= BIT_SUB_DMA2; 	 
	rINTMSK |= (BIT_DMA); 
	rSUBSRCPND = BIT_SUB_DMA2; 
	ClearPending(BIT_DMA);	 
 
	rIISCON	&= ~(1<<2)|(0<<0); 
    rIISCON |= (1<<2)|(1<<0); 
	 
  	printf("\nTX DMA Done ~~~"); 
 
	rINTMSK &= ~(BIT_DMA); 
	rINTSUBMSK &= ~BIT_SUB_DMA2; 	 
} 
 
 
void __irq DMA1_Rec_Done(void) 
{ 
	rINTSUBMSK |= BIT_SUB_DMA1; 	 
	rINTMSK |= (BIT_DMA); 
	rSUBSRCPND = BIT_SUB_DMA1; 
	ClearPending(BIT_DMA);	 
	 
	rIISCON	&= ~(1<<1)|(0<<0); 
	printf("Record DMA Done!\n"); 
 
	rINTMSK &= ~(BIT_DMA); 
	rINTSUBMSK &= ~BIT_SUB_DMA1; 	 
 
    Rec_Done = 1; 
}  
 
 
void __irq Play_Rec_Simul(void) 
{ 
	rINTSUBMSK |= BIT_SUB_DMA1; 	 
	rINTMSK |= (BIT_DMA); 
	rSUBSRCPND = BIT_SUB_DMA1; 
	ClearPending(BIT_DMA);	 
 
    rIISCON	&= ~(1<<0); 
	rIISCON |= 0x1; 
       
	printf("\nR~~~");	 
 
	rINTMSK &= ~(BIT_DMA); 
	rINTSUBMSK &= ~BIT_SUB_DMA1; 	 
} 
 
 
void __irq Rx_IIS_Int(void) 
{ 
    rSUBSRCPND = BIT_SUB_RXD1;          //Clear pending bit (Requested) 
    rSUBSRCPND; 
 
    ClearPending(BIT_UART1); 
 
    *_temp ++= RdURXH1();  
} 
  
 
void Play_Iis(void) 
{	 
	printf("\n just only Play it.\n"); 
         
	IIS_Port_Init();  
	Select_IIS_Master_CLK(); 
 
	 
	Init1341(PLAY_IIS); 
	IIS_PlayWave_DMA2(rec_buf, 464000); 
 
	// need to add mute function 
	 
	IIS_Port_Return(); 
} 
 
void Play_Iis_EXTCLK(void) 
{	 
	printf("\n just only Play it.\n"); 
         
	IIS_Port_Init();  
	Select_EXTCLK(); // Select External Clock 
 
	Init1341(PLAY_IIS); 
	Data_init(); 
	IIS_PlayWave_DMA2_EXTCLK(rec_buf, 464000); 
 
	IIS_Port_Return(); 
} 
 
 
 
//Record Sound via Line-In  
void RecordSound_ViaLineIn_Playit(void) 
{	 
	printf("\nRecord Sound via Line-In and Play it.\n"); 
 
	IIS_Port_Init();  
	Select_IIS_Master_CLK(); 
 
	Init1341(RECORD_LINE_IN); 
	IIS_RecSound_DMA1(RECORD_LINE_IN, 464000); 
	 
	Init1341(PLAY_IIS); 
	IIS_PlayWave_DMA2(rec_buf, 464000); 
 
	// need to add mute function 
 
	IIS_Port_Return(); 
} 
 
 
//Record Sound via MIC-In 
void RecordSound_ViaMICIn_Playit(void) 
{ 
	printf("\nRecord Sound via MIC-In and Play it.\n"); 
 
   	IIS_Port_Init();  
	Select_IIS_Master_CLK(); 
   
	Init1341(RECORD_MIC_IN); 
	IIS_RecSound_DMA1(RECORD_MIC_IN, REC_LEN_IIS); 
	 
	printf("\nPress Any Key If You Want Play WAV File\n" ); 
	getchar(); 
	 
	Init1341(PLAY_IIS); 
	IIS_PlayWave_DMA2(rec_buf, 464000); 
 
	// need to add mute function 
 
	IIS_Port_Return(); 
} 
 
 
void RECORD_PLAY_SIMtaneously(void) 
{ 
	printf("\nRecord and Play Simultaneously.\n"); 
 
	IIS_Port_Init();  
 
	Select_IIS_Master_CLK(); 
 
	Init1341(RECORD_LINE_IN); 
//	IIS_RecSound_DMA1(RECORD_LINE_IN, REC_LEN_IIS); 
	IIS_RecSound_DMA1(RECORD_LINE_IN, 464000); 
 
	printf("\n First Record OK! and then RECORD Simultaneously\n"); 
	getchar(); 
	 
	Init1341(RECORD_PLAY_SIM); 
//	IIS_Paly_Rec_Simul(rec_buf, REC_LEN_IIS); 
	IIS_Paly_Rec_Simul(rec_buf, 464000); 
	 
	Init1341(PLAY_IIS); 
	IIS_PlayWave_DMA2(rec_buf1, 464000); 
		 
	// need to add mute function 
 
	IIS_Port_Return(); 
} 
 
 
void RecordSound_ViaLineIn_SLV(void) 
{	 
	printf("\nRecord Sound via Line-In and Play it.\n"); 
 
	// slave mode setting 
	rIISMOD = ( rIISMOD & ~(3<<10) ) | (3<<10); 
 
	IIS_Port_Init();  
 
	Init1341(RECORD_LINE_IN); 
	IIS_RecSound_DMA1_SLV(RECORD_LINE_IN, 464000); 
	 
	IIS_Port_Return(); 
} 
 
 
void RecordSound_ViaLineIn_MASTER(void) 
{	 
	printf("\nRecord Sound via Line-In and Play it.\n"); 
 
 
	IIS_Port_Init();  
	Select_IIS_Master_CLK(); 
 
	Init1341(RECORD_LINE_IN); 
	IIS_RecSound_DMA1_MASTER(RECORD_LINE_IN, 464000); 
	 
	IIS_Port_Return(); 
} 
			   
 
void Play_Iis_MASTER(void) 
{	 
	printf("\n just only Play it.\n"); 
 
	IIS_Port_Init();  
	Select_IIS_Master_CLK();  
 
	Data_init(); 
	 
	Init1341(PLAY_IIS); 
	IIS_PlayWave_DMA2_MASTER(rec_buf, 464000); 
 
	IIS_Port_Return(); 
} 
 
 
void Play_Iis_SLAVE(void) 
{	 
	printf("\n just only Play it.\n"); 
 
	// Slave mode Setting 
	rIISMOD = ( rIISMOD & ~(3<<10) ) | (3<<10);  
	         
	IIS_Port_Init();  
 
	Data_init(); 
	 
	Init1341(PLAY_IIS); 
	IIS_PlayWave_DMA2_SLAVE(rec_buf, 464000); 
 
	IIS_Port_Return(); 
} 
 
 
void Data_init(void) 
{ 
	int i; 
    unsigned int *rec_buf = (unsigned int *)0x31000028;  
	 
	for(i=0;i<500000;i++) 
	{ 
		*(rec_buf+i)=i; 
	} 
		*(rec_buf+0)=0xa5a5a5a5; 
		*(rec_buf+1)=0x5a5a5a5a; 
		*(rec_buf+2)=0xffff0000; 
		*(rec_buf+3)=0xffffffff; 
		*(rec_buf+4)=0x0000ffff; 
} 
 
 
void IIS_RecSound_DMA1(int mode, unsigned int rec_size) 
{ 
	int Exit_Key, iIndex; 
	 
	unsigned int iR_LRCLK, iR_BCLK, iR_BLC; 
	 
	printf("\n Root Frequency Sample ( 0:256fs    1:512fs    2:384fs    3:768fs ) = "); 
 	iR_LRCLK = GetIntNum();  
	printf("\n Bit Frequency Sample (0:32fs    1:48fs    2:16fs    3:24fs) = "); 
 	iR_BCLK = GetIntNum();  
	printf("\n BLC (0: 16bit    1:8bit ) = "); 
	iR_BLC = GetIntNum();  
		 
 
	pISR_DMA = (unsigned)DMA1_Rec_Done; 
	 
	 
	ClearPending(BIT_DMA);	 
	rSUBSRCPND = BIT_SUB_DMA1; 
	 
	// 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;	    
	// Using PCLK, Receive Mode, Left Channel is Low, I2S Format, LRCLK 384fs, BLK 32fs, BLC 16bit. 
	rIISMOD = (0<<10)+(1<<8) + (0<<7) + (0<<5) +  (iR_LRCLK<<3) + (iR_BCLK<<1) + (iR_BLC<<0);	 
	 
	// FIFO flush 
	rIISFIC = (1<<7) + 0; // jungil	   
	rIISFIC = (0<<7) + 0; // jungil	   
 
	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"); // jungil 
	getchar(); //jungil  
 
	// DMA 1 Mask Release.  
	rINTMSK = ~(BIT_DMA); 
	rINTSUBMSK = ~(BIT_SUB_DMA1); 
 
	//IIS Rx start 
	rIISCON |= 0x1;	 // I2S start 
 
	//--- DMA1 Initialize 
	rDISRCC1 = (1<<1) + (1<<0);    
	rDISRC1  = ((unsigned int)0x55000014);     
	rDIDSTC1 = (0<<1) + (0<<0);      
	rDIDST1  = (int)rec_buf;                             
	rDCON1   = (U32)((1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(0<<22)+(2<<20)+(464000/4));	 
	rDMAREQSEL1 = (5<<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 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);	//DMA2 stop 
	rIISFIC    = 0x0;			//For FIFO flush 
 
	rINTSUBMSK |= (BIT_SUB_DMA1);	 
	rINTMSK |= (BIT_DMA); 
 
	printf("\nEnd of Record!\n");	 
    	 
} 
 
void IIS_RecSound_DMA1_Repeat(unsigned char *start_addr, unsigned int rec_size) 
{ 
	unsigned char Exit_Key; 
 
	printf("\nRecording At IISLRCK = %d Hz\n", (int) IIS_Codec_CLK/384); 
	printf("\nRecord Buffer 1 == %x", rec_buf1); 
	 
	//--- DMA1 Initialize 
	rDISRCC1 = (1<<1) + (1<<0);    
	rDISRC1  = ((unsigned int)0x55000014);     
	rDIDSTC1 = (0<<1) + (0<<0);      
	rDIDST1  = (int)rec_buf1;                             
	rDCON1   = (U32)((1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(0<<22)+(2<<20)+(464000/4));	 
	rDMAREQSEL1 = (5<<1) + (1<<0);  
	rDMASKTRIG1 = (0<<2) + (1<<1) + (0<<0);          //No-stop[2], DMA1 channel On[1], No-sw trigger[0]  
 
	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 IIS_PlayWave_DMA2(unsigned char *start_addr, unsigned int play_size) 
{ 
	unsigned char Exit_Key; 
	unsigned int iLRCLK=0, iBCLK=0, iBLC=0; 
	 
	 
	pISR_DMA = (unsigned)DMA2_Done; 
	ClearPending(BIT_DMA);	 
	rSUBSRCPND = BIT_SUB_DMA2; 
 
	printf("\n Root Frequency Sample ( 0:256fs    1:512fs    2:384fs    3:768fs ) = "); 
 	iLRCLK = GetIntNum();  
	printf("\n Bit Frequency Sample (0:32fs    1:48fs    2:16fs    3:24fs) = "); 
	iBCLK = GetIntNum();  
	printf("\n BLC (0: 16bit    1:8bit ) = "); 
	iBLC = GetIntNum();  
		 
	// 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 & ~(0xfff) | (0<<10)|(0<<8)|(0<<7)|(0<<5)|(iLRCLK<<3)|(iBCLK<<1)|(iBLC<<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)((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) 
	{ 
		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_Paly_Rec_Simul(unsigned char *start_addr, unsigned int play_size) 
{ 
	pISR_DMA= (unsigned)Play_Rec_Simul; 
	ClearPending(BIT_DMA); 
	rSUBSRCPND=(BIT_SUB_DMA1); 
 
	// this setting for TX RX Simulateously 
  	rIISCON = (0<<5) + (0<<4) +(1<<2) + (1<<1)+0;	    
  	// using pclk, TX/RX Silmulateously , left for channel,iis format ,384fs , 32fs ,16bit  	 
  	rIISMOD = rIISMOD & ~(0xfff) | (0<<10)|(2<<8)|(0<<7)|(0<<5)|(2<<3)|(0<<1)|(0<<0);  	 
	 
	// Fifo Fulsh 
  	rIISFIC = 0+(1<<15);	   
    rIISFIC = 0+(0<<15);	   
 
	printf("\n RootCLK = 384fs, BLK = 32fs, BLC = 16bit \n"); 
	printf("\nIISLRCK = %d Hz", (int) IIS_Codec_CLK/384); 
 
	rINTMSK &= ~(BIT_DMA); 
	rINTSUBMSK &= ~(BIT_SUB_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)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)+(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"); 
}