📄 iis.c
字号:
/*=================================================
File Name: Iis.c
Description: S3C2440A IIS controller Function Test
Version: 0.1
History:
0.0: 2002. 03. 06, Programming Start by SOP.
0.1: 2004. 02. 04, Modified by Y. H. Lee.
- IIS Master Tx: Play Sample Wave File.
- IIS Master Rx: Record Sound using MIC and Play it.
- IIS maser clock selection is supported.
===================================================*/
#include "2440addr.h"
#include "2440lib.h"
#include "def.h"
#include "iis.h"
//lzd add
#include "WindowsXP_Wav.h" //长度为243552个字节
#define REC_LEN_IIS 0x200000
#define PLAY_IIS 0
#define RECORD_IIS 1
//#define DataCount 0x10000 //IIS Master/Slave Data Rx/Tx Count
//#define DataDisplay 0x100 //IIS Master Data Display Count
//#define PollMode 0 //Polling Mode
//#define DMA2Mode 1 //DMA2 Mode
#define L3C (1<<4) //GPB4 = L3CLOCK
#define L3D (1<<3) //GPB3 = L3DATA
#define L3M (1<<2) //GPB2 = L3MODE
char which_Buf = 1;
char Rec_Done = 0;
char mute = 1;
char IIS_MasterClk_Sel = 0;
unsigned char *rec_buf;
unsigned char *Buf,*_temp;
unsigned int size, fs;
unsigned int save_B, save_E, save_PB, save_PE;
U32 downloadAddress=0x31000000;
//extern U32 downloadFileSize;
float IIS_Codec_CLK;
void ChangeDMA2(void);
void IIS_Port_Init(void);
void IIS_Port_Return(void);
void Download_Wave_File(void);
void Select_IIS_Master_CLK(void);
void IIS_RecSound_DMA1(unsigned char *start_addr, U32 rec_size);
void IIS_PlayWave_DMA2(unsigned char *start_addr, U32 play_size);
void _WrL3Addr(U8 data);
void _WrL3Data(U8 data,int halt);
void __irq DMA1_Rec_Done(void);
void __irq DMA2_Done(void);
void __irq RxInt(void);
void __irq Muting(void);
void * func_iis_test[][2]=
{
//IIS Function Test Item
(void *)Play_Wave_Iis, "Play Wave File. ",
(void *)Record_Sound_Iis, "Record Sound via MIC and Play it. ",
0,0
};
void IIS_Test(void)
{
int i;
while(1)
{
i=0;
Uart_Printf("\n\n================== IIS Function Test ==================\n\n");
while(1)
{ //display menu
Uart_Printf("%2d:%s",i,func_iis_test[i][1]);
i++;
if((int)(func_iis_test[i][0])==0)
{
Uart_Printf("\n");
break;
}
if((i%4)==0)
Uart_Printf("\n");
}
Uart_Printf("\n=======================================================\n");
Uart_Printf("\nPress Enter key to exit : ");
i = Uart_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]) )();
}
//Uart_Printf("\n====== IIS Test program end ======\n");
}
//Play Wave File
void Play_Wave_Iis(void)
{
unsigned char *buf;
unsigned int i;
unsigned int downloadSize = 243552;
Uart_Printf("\nPlay Wave File.\n");
IIS_Port_Init();
Select_IIS_Master_CLK();
if(1)
{
downloadAddress = _NONCACHE_STARTADDRESS;
buf = (unsigned char *)downloadAddress ;
for( i = 0; i < 243552; i++ ) buf[i] = WindowsXP_Wav[i] ;
}
else
{
Download_Wave_File();
}
Init1341(PLAY_IIS);
//IIS_PlayWave_DMA2(Buf + 0x30, size);
IIS_PlayWave_DMA2(buf, downloadSize);
IIS_Port_Return();
mute = 1;
}
//Record Sound using MIC
void Record_Sound_Iis(void)
{
Uart_Printf("\nRecord Sound via MIC.\n");
IIS_Port_Init();
Select_IIS_Master_CLK();
Init1341(RECORD_IIS);
rec_buf = (unsigned char *)0x31000000;
IIS_RecSound_DMA1(rec_buf, REC_LEN_IIS);
////////////////////////////////////////////////////////////////////////
Init1341(PLAY_IIS);
IIS_PlayWave_DMA2(rec_buf, REC_LEN_IIS);
IIS_Port_Return();
mute = 1;
}
/* Sub-Routines */
//Setting Port related to IIS
void IIS_Port_Init(void)
{
save_B = rGPBCON;
save_E = rGPECON;
save_PB = rGPBUP;
save_PE = rGPEUP;
//----------------------------------------------------------
// 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 & ~(0x3f<<4) | (0x15<<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) | 0x1f; //The pull up function is disabled GPE[4:0] 1 1111
rGPECON = rGPECON & ~(0x3ff) | 0x2aa; //GPE[4:0]=I2SSDO:I2SSDI:CDCLK:I2SSCLK:I2SLRCK
rGPFUP = ((rGPFUP & ~(1<<0)) | (1<<0)); //GPF0
rGPFCON = ((rGPFCON & ~(3<<0)) | (1<<1)); //GPF0=EINT0
rEXTINT0 = ((rEXTINT0 & ~(7<<0)) | (2<<0)); //EINT0=falling edge triggered
}
void IIS_Port_Return(void)
{
rGPBCON = save_B;
rGPECON = save_E;
rGPBUP = save_PB;
rGPEUP = save_PE;
}
void Download_Wave_File(void)
{
unsigned int temp;
pISR_UART1 = (unsigned)RxInt;
rINTMSK = ~(BIT_UART1);
rINTSUBMSK = ~(BIT_SUB_RXD1);
//Non-cacheable area = 0x31000000 ~ 0x33feffff
Buf = (unsigned char *)0x31000000;
_temp = Buf;
Uart_Printf("\n\nDownload the PCM(no ADPCM) file by DNW serial port(With header)!!\n");
Uart_Printf("Download Start Address: 0x%x\n", Buf);
while(((unsigned int)_temp - (unsigned int)Buf) < 4)
{
Led_Display(0);
Delay(1500);
Led_Display(15);
Delay(1500);
}
size = *(Buf) | *(Buf + 1)<<8 | *(Buf + 2)<<16 | *(Buf + 3)<<24;
Uart_Printf("\nNow, Downloading... [ File Size : %7d 0]", size);
temp =size;
while(((unsigned int)_temp - (unsigned int)Buf) < size)
{
Uart_Printf("\b\b\b\b\b\b\b\b%7d ",(unsigned int)_temp - (unsigned int)Buf);
Delay(5000);
}
Uart_Printf("\b\b\b\b\b\b\b\b%7d ]\n",(unsigned int)_temp - (unsigned int)Buf);
rINTSUBMSK |= BIT_SUB_RXD1;
size = *(Buf + 0x2c) | *(Buf + 0x2d)<<8 | *(Buf + 0x2e)<<16 | *(Buf + 0x2f)<<24;
size = (size>>1)<<1;
//size = temp -0x30;
fs = *(Buf + 0x1c) | *(Buf + 0x1d)<<8 | *(Buf + 0x1e)<<16 | *(Buf + 0x1f)<<24;
Uart_Printf("PCM File Size = %d\n", size);
Uart_Printf("Sampling Frequency of PCM data = %d Hz\n", fs);
}
void IIS_RecSound_DMA1(unsigned char *start_addr, U32 rec_size)
{
pISR_DMA1 = (unsigned)DMA1_Rec_Done;
if (IIS_MasterClk_Sel == 0) //IIS Master Clock Source = PCLK
{
rIISCON = (1<<4) + (1<<3) + (1<<1);
//Bit[1] IIS prescaler enable
//Bit[3] Tx idle
//Bit[4] Rx DMA enable
rIISMOD = (0<<9)+(0<<8) + (1<<6) + (0<<5) + (0<<4) + (1<<3) + (1<<2) + (1<<0);
//Bit[1:0] Serial bit clock => 32fs,
//Bit[2] Master clock => 384fs,
//Bit[3] Serial data bit per channel => 16bit,
//Bit[4] Serial interface format => IIS compatible format
//Bit[5] Active level of left/right channel => Low for left channel
//Bit[7:6] Tx/Rx mode select => Rx mode
//Bit[8] Master/Slave mode => Master mode
//Bit[9] Master clock => PCLK
rIISFCON = (1<<14) + (1<<12);
//Bit[13] Rx FIFO enable
//Bit[15] Rx FIFO access mode => DMA
Uart_Printf("\nIISLRCK = %d Hz", (int) IIS_Codec_CLK/384);
}
else //IIS Master Clock Source = MPLLin
{
rIISCON = (1<<4) + (1<<3) + (1<<1);
//Bit[1] IIS prescaler enable
//Bit[3] Tx idle
//Bit[4] Rx DMA enable
rIISMOD = (0<<9)+(0<<8) + (1<<6) + (0<<5) + (0<<4) + (1<<3) + (1<<2) + (1<<0);
//Bit[1:0] Serial bit clock => 32fs,
//Bit[2] Master clock => 384fs,
//Bit[3] Serial data bit per channel => 16bit,
//Bit[4] Serial interface format => IIS compatible format
//Bit[5] Active level of left/right channel => Low for left channel
//Bit[7:6] Tx/Rx mode select => Rx mode
//Bit[8] Master/Slave mode => Master mode
//Bit[9] Master clock => PCLK
rIISFCON = (1<<14) + (1<<12);
//Bit[13] Rx FIFO enable
//Bit[15] Rx FIFO access mode => DMA
Uart_Printf("\nIISLRCK = %d Hz", (int) IIS_Codec_CLK/384);
}
rINTMSK = ~(BIT_DMA1);
//--- DMA1 Initialize
rDISRCC1 = (1<<1) + (1<<0);
rDISRC1 = ((U32)IISFIFO);
rDIDSTC1 = (0<<1) + (0<<0);
rDIDST1 = (int)start_addr;
rDCON1 = (1<<31)+(0<<30)+(1<<29)+(0<<28)+(0<<27)+(2<<24)+(1<<23)+(1<<22)+(1<<20)+(rec_size/2);
rDMASKTRIG1 = (0<<2) + (1<<1) + 0; //No-stop, DMA1 channel on, No-sw trigger
Uart_Printf("\n\nAre you ready to record voice via MIC on SMDK2440?");
Uart_Printf("\nPress any key to start record!\n");
Uart_Getch();
Uart_Printf("Recording...\n");
//IIS Rx start
rIISCON |= 0x1;
while(!Rec_Done)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -