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

📄 iis.c

📁 台湾EV44B0II嵌入式开发系统实验源代码例程
💻 C
字号:
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\def.h"
#include "..\inc\iis.h"

void _WrL3Addr(U8 data);
void _WrL3Data(U8 data,int halt);
void __irq BDMA0_PLAY(void);
void __irq BDMA0_Done(void);
void __irq BDMA0_Rec_Done(void);
void __irq RxInt(void);
//void __irq Muting(void);
void Init1341(char);

#define L3D (0x200)
#define L3M (0x10)
#define L3C (0x20)

#define TESTSIZE 700000//1000//100
//for test
//static short int Buf[TESTSIZE];
//for down
unsigned char *Buf,*_temp;
unsigned char *rec_buf;

#define PLAY 0
#define RECORD 1
#define REC_LEN	0xF0000

volatile unsigned int size=0;
volatile unsigned int leng,ssize;
volatile char Rec_Done=0;
volatile char mute=1;

void Test_Iis(void)
{
    U32 i;
     
    ChangePllValue(0x49,0x7,0x1);	//MCLK=45.1584MHz <-- 5.6448MHz*8
    Uart_Init(45000000,115200);
    Uart_Printf("[IIS test]\n");
    
    rPCONE=(rPCONE&0xffff)+(2<<16); //PE:CODECLK
    pISR_BDMA0=(unsigned)BDMA0_Done;

//for down
    pISR_URXD0=(unsigned)RxInt;
    
    rINTMSK=~(BIT_GLOBAL|BIT_BDMA0|BIT_URXD0);
    Buf=(unsigned char *)0xc400000;
    _temp=Buf;
    
    for(i=0XC400000;i<(0XC400000+0XF0000);i+=4)
    {
	*((volatile unsigned *)i)=0x0;
    }

    Uart_Printf("Download the PCM(no ADPCM) wave file by wkcom2(with header)!!\n");

    while(((unsigned int)_temp-(unsigned int)Buf)<4)
    {
	Led_Display(0xf);
	Delay(1500);
	Led_Display(0x0);
	Delay(1500);
    }
    size=*(Buf) | *(Buf+1)<<8 | *(Buf+2)<<16 | *(Buf+3)<<24;
    Uart_Printf("\nNow, Downloading... [FILESIZE:%7d(      0)",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);
    Uart_Printf("\b\b\b\b\b\b\b\b%7d)\n",(unsigned int)_temp-(unsigned int)Buf);

    rINTMSK |=BIT_URXD0;
    leng=0xf0000;
    size=*(Buf+0x2c) | *(Buf+0x2d)<<8 | *(Buf+0x2e)<<16 | *(Buf+0x2f)<<24;
    size=(size>>1)<<1;
    Uart_Printf("sample size=0x%x\n",size/2);
    Uart_Printf("\n[]Now play the wave file\n");

   Init1341(PLAY);
    /****** BDMA0 Initialize ******/
//for down
    rBDISRC0=(1<<30)+(1<<28)+(int)(Buf+0x30);	//Half word,inc,Buf
    rBDIDES0=(1<<30)+(3<<28)+((int)rIISFIF);	//M2IO,fix,IISFIF
    rBDICNT0=(1<<30)+(1<<26)+(3<<22)+(1<<21)+(1<<20)+size;
    rBDCON0 = 0x0<<2;
  
    /****** IIS Initialize ******/
    rIISCON=0x22;	//Tx DMA enable,Rx idle,prescaler enable
    rIISMOD=0x89;	//Master,Tx,L-ch=low,iis,16bit ch.,codeclk=256fs,lrck=32fs
    rIISPSR=0x33;	//Prescaler_A/B enable, value=3
    rIISFCON=0xa00;	//Tx/Rx DMA,Tx/Rx FIFO --> start piling....

    Uart_Printf("Push any key to exit!!!\n");
    /****** IIS Tx Start ******/
    rIISCON |=0x1;
    while(!Uart_GetKey());

    /****** IIS Tx Stop ******/
    rIISCON=0x0;    //IIS stop
    rBDICNT0=0x0;   //BDMA stop
//for down
    free(Buf);
    Cache_Flush();
    rNCACHBE0=0x0;
    size=0;


    rINTMSK|=BIT_GLOBAL;
    ChangePllValue(PLL_M,PLL_P,PLL_S);	//MCLK=40MHz
    Uart_Init(0,115200);
}
void Record_Iis(void)
{
     U32 i;
    
    ChangePllValue(0x49,0x7,0x1);	//MCLK=45.1584MHz <-- 5.6448MHz*8
    Uart_Init(45000000,115200);
    Uart_Printf("[Record test using UDA1341]\n");
 
    rPCONE=(rPCONE&0xffff)+(2<<16); //PE:CODECLK
    pISR_BDMA0=(unsigned)BDMA0_Rec_Done;
    rINTMSK=~(BIT_GLOBAL|BIT_BDMA0);
//for down
    rec_buf=(unsigned char *)0xc400000;
    Buf =rec_buf;
      for(i=0XC400000;i<(0XC400000+0XF0000);i+=4)
    {
	*((volatile unsigned *)i)=0x0;
    }

    Init1341(RECORD);
    /****** BDMA0 Initialize ******/
//for down
    rBDISRC0=(1<<30)+(3<<28)+((int)rIISFIF);	//Half word,inc,Buf
    rBDIDES0=(2<<30)+(1<<28)+((int)rec_buf);	//M2IO,fix,IISFIF
//for down
    rBDICNT0=(1<<30)+(1<<26)+(3<<22)+(1<<21)+(1<<20)+REC_LEN;
    rBDCON0 = 0x0<<2;
  
    /****** IIS Initialize ******/
    rIISCON=0x1a;	//Rx DMA enable,Rx idle,prescaler enable
    rIISMOD=0x49;	//Master,Tx,L-ch=low,iis,16bit ch.,codeclk=256fs,lrck=32fs
    rIISPSR=0x33;	//Prescaler_A/B enable, value=3
    rIISFCON=0x500;	//Tx/Rx DMA,Tx/Rx FIFO --> start piling....
    
    Uart_Printf("Press any key to start record!!!\n");
    Uart_Getch();
    Uart_Printf("Recording...\n");
    //--- Rx start
    rIISCON |=0x1;
    
    Uart_Printf("Push any key to stop record!!!\n");
    while(!Uart_GetKey());
   // while(!Rec_Done);
    rINTMSK |= BIT_BDMA0;
    Rec_Done=0;
    //--- IIS Stop
    Delay(10);		//for end of H/W Rx
    rIISCON=0x0;	//IIS stop
    rBDICNT0=0x0;   //BDMA stop
    Uart_Printf("End of Record!!!\n");
    Uart_Printf("Press any key to play recorded data\n");
    Uart_Getch();
    
    size=REC_LEN*2;
    Uart_Printf("size=%d\n",size);
    Init1341(PLAY);

     pISR_BDMA0=(unsigned)BDMA0_Done;
    rINTMSK=~(BIT_GLOBAL|BIT_BDMA0);
    
    rBDIDES0=(1<<30)+(3<<28)+((int)rIISFIF);	//M2IO,fix,IISFIF
    rBDISRC0=(1<<30)+(1<<28)+((int)rec_buf);	//Half word,inc,Buf
    rBDICNT0=(1<<30)+(1<<26)+(3<<22)+(1<<21)+(1<<20)+ REC_LEN;
    rBDCON0 = 0x0<<2;
  
    /****** IIS Initialize ******/
    rIISCON=0x26;	//Tx DMA enable,Rx idle,prescaler enable
    rIISMOD=0x89;	//Master,Tx,L-ch=low,iis,16bit ch.,codeclk=256fs,lrck=32fs
    rIISPSR=0x33;	//Prescaler_A/B enable, value=3
    rIISFCON=0xa00;	//Tx/Rx DMA,Tx/Rx FIFO --> start piling....
    Uart_Printf("Push any key to exit!!!\n");
    /****** IIS Tx Start ******/
    rIISCON |=0x1;
    while(!Uart_GetKey());
    /****** IIS Tx Stop ******/
    rIISCON=0x0;    //IIS stop
    rBDICNT0=0x0;   //BDMA stop
//for down
    free(rec_buf);
    Cache_Flush();
    rNCACHBE0=0x0;
    size=0;
  
    rINTMSK=BIT_GLOBAL;
    ChangePllValue(PLL_M,PLL_P,PLL_S);	//MCLK=40MHz
    Uart_Init(0,115200);
}

void Init1341(char mode)
{
    /****** Port Initialize ******/
    rPCONA = 0x1ff;	//PA9(out):L3D
    rPCONB = 0x7CF;	//PG6:L3M, PG7:L3C
  

    rPDATB = L3M|L3C;	//L3M=H(start condition)
    			//L3C=H(start condition)

    /****** L3 Interface ******/
    _WrL3Addr(0x14+2);	//status (000101xx+10)
#ifdef FS441KHZ
    _WrL3Data(0x60,0); //0,1,10,000,0 reset,256fs,no DCfilter,iis
#else
    _WrL3Data(0x40,0); //0,1,00,000,0 reset,512fs,no DCfilter,iis
#endif

    _WrL3Addr(0x14+2); //status (000101xx+10)
#ifdef FS441KHZ
    _WrL3Data(0x20,0); //0,0,10,000,0 no reset,256fs,no DCfilter,iis
#else
    _WrL3Data(0x00,0); //0,0,00,000,0 no reset,512fs,no DCfilter,iis
#endif
    
    _WrL3Addr(0x14+2); //status (000101xx+10)
    _WrL3Data(0x81,0);
    //1,0,0,0,0,0,11 OGS=0,IGS=0,ADC_NI,DAC_NI,sngl speed,AonDon
    _WrL3Addr(0x14+0); //DATA0 (000101xx+00)
    _WrL3Data(0x0A,0);
    
//record
    if(mode)
    {
	_WrL3Addr(0x14+2); //STATUS (000101xx+10)
	_WrL3Data(0xa2,0); //1,0,1,0,0,0,10	: OGS=0,IGS=1,ADC_NI,DAC_NI,sngl speed,AonDoff

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


void _WrL3Addr(U8 data)
{	
    U32 vPdata = 0x0;	//L3D=L	
    U32 vPdatb = 0x0;	//L3M=L(in address mode)/L3C=L
    S32 i,j;

    rPDATB = vPdatb;	//L3M=L
    rPDATB |= L3C;	//L3C=H

    for(j=0;j<4;j++);		//tsu(L3) > 190ns

    //PA9:L3D PG6:L3M PG7:L3C
    for(i=0;i<8;i++)		
    {
	if(data&0x1)//if data bit is 'H'
	{
	    rPDATB = vPdatb;	//L3C=L
	    rPDATA = L3D;	//L3D=H		    
	    for(j=0;j<4;j++);	//tcy(L3) > 500ns
	    rPDATB = L3C;	//L3C=H
	    rPDATA = L3D;	//L3D=H
	    for(j=0;j<4;j++);	//tcy(L3) > 500ns
	}
	else		//if data bit is 'L'
	{
	    rPDATB=vPdatb;	//L3C=L
	    rPDATA=vPdata;	//L3D=L
	    for(j=0;j<4;j++);	//tcy(L3) > 500ns
	    rPDATB=L3C;		//L3C=H
	    rPDATA=vPdata;	//L3D=L
	    for(j=0;j<4;j++);	//tcy(L3) > 500ns
	}
	data >>=1;
    }
    rPDATG=L3C|L3M;	//L3M=H,L3C=H
}


void _WrL3Data(U8 data,int halt)
{
    U32 vPdata = 0x0;   //L3D=L
    U32 vPdatb = 0x0;	//L3M/L3C=L
    S32 i,j;
    if(halt)
    {
        rPDATB=L3C;	    //L3C=H(while tstp, L3 interface halt condition)
        for(j=0;j<4;j++);   //tstp(L3) > 190ns
    }
    rPDATB=L3C|L3M;	    //L3M=H(in data transfer mode)	
    for(j=0;j<4;j++);	    //tsu(L3)D > 190ns

    //PA9:L3MODE PG6:L3DATA PG7:L3CLOCK
    for(i=0;i<8;i++)
    {
        if(data&0x1)	//if data bit is 'H'
        {
	    rPDATB=L3M;		//L3C=L
            rPDATA=L3D;		//L3D=H
            for(j=0;j<4;j++);	//tcy(L3) > 500ns
            rPDATB=L3C|L3M;	//L3C=H,L3D=H
	    rPDATA=L3D;
            for(j=0;j<4;j++);	//tcy(L3) > 500ns
        }
        else		//if data bit is 'L'
        {
            rPDATB=L3M;		//L3C=L
	    rPDATA=vPdata;	//L3D=L
            for(j=0;j<4;j++);	//tcy(L3) > 500ns
            rPDATB=L3C|L3M;	//L3C=H
	    rPDATA=vPdata;	//L3D=L
            for(j=0;j<4;j++);	//tcy(L3) > 500ns
        }
        data>>=1;
    }
    rPDATB=L3C|L3M;	//L3M=H,L3C=H
}


void __irq BDMA0_Done(void)
{
    rI_ISPC=BIT_BDMA0;	//clear pending bit
    WrUTXH0('&');
}

void __irq BDMA0_Rec_Done(void)
{
    rI_ISPC=BIT_BDMA0;	//clear pending bit
    WrUTXH0('#');
    
}

void __irq RxInt(void)
{
    rI_ISPC=BIT_URXD0 ;	//clear pending bits
    *_temp++=RdURXH0();
}



⌨️ 快捷键说明

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