📄 main.c
字号:
#include "option.h"
#include "def.h"
#include "44b.h"
#include "44blib.h"
#define L3D (0x200)
#define L3M (0x10)
#define L3C (0x20)
#define TESTSIZE 700000 //1000//100
#define PLAY 0
#define RECORD 1
#define REC_LEN 0xF0000
void _WrL3Addr(U8 data);
void _WrL3Data(U8 data,int halt);
volatile unsigned int size=0;
volatile unsigned int leng,ssize;
volatile char Rec_Done=0;
volatile char mute=1;
void Init1341(char);
void __irq BDMA0_PLAY(void);
void __irq BDMA0_Done(void);
void __irq RxInt(void);
void __irq BDMA0_Rec_Done(void);
void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);
void HaltDabort(void);
unsigned char *Buf,*_temp;
unsigned char *rec_buf;
void Main(void)
{
unsigned int i=0, j=0;
rSYSCFG=SYSCFG_8KB;
#if (PLLON==1)
ChangePllValue(PLL_M,PLL_P,PLL_S);
#endif
Isr_Init();
Port_Init();
Uart_Init(0,115200);
Uart_Select(0);
Delay(1000); //calibrate Delay()
ChangePllValue(0x49,0x7,0x1); //MCLK=45.1584MHz <-- 5.6448MHz*8
Uart_Init(45000000,115200);
/////////////// my changed ///////////////////
rPCONF=(rPCONF&0xff)|(4<<10)|(4<<13)|(4<<16)|(4<<19);
/////////////// changed end ///////////////////
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;
Uart_Printf(" test program is end \n");
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; //PB4:L3M, PB5: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(0x00,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(0x45,0); //010,001,01 : DATA0, MS=0dB, 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();
}
//////////////////////////////////////////////////////////////////////////////////////////
void Isr_Init(void)
{
U32 i;
pISR_UNDEF=(unsigned)HaltUndef;
pISR_SWI =(unsigned)HaltSwi;
pISR_PABORT=(unsigned)HaltPabort;
pISR_DABORT=(unsigned)HaltDabort;
for(i=_RAM_STARTADDRESS;i<(_RAM_STARTADDRESS+0x20);i+=4)
{
*((volatile unsigned *)i)=0xEA000000+0x1FFE;
}
rINTCON=0x5; // Non-vectored,IRQ enable,FIQ disable
rINTMOD=0x0; // All=IRQ mode
rINTMSK|=BIT_GLOBAL|BIT_EINT3; // All interrupt is masked.
}
void HaltUndef(void)
{
Uart_Printf("Undefined instruction exception!!!\n");
while(1);
}
void HaltSwi(void)
{
Uart_Printf("SWI exception!!!\n");
while(1);
}
void HaltPabort(void)
{
Uart_Printf("Pabort exception!!!\n");
while(1);
}
void HaltDabort(void)
{
Uart_Printf("Dabort exception!!!\n");
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -