|
程序仍在调试中
#include "2440addr.h" #include "music.h"#define L3MODE 1<<2 #define L3DATA 1<<3 #define L3CLOCK 1<<4 #define U32 unsigned int #define U8 unsigned char int cmd,command, stop , temp; U8 iis_buffer[646256];void __irq UART0_ISR(void){ char ch; rSRCPND |= (0x1<<28); rINTPND |= (0x1<<28); rSUBSRCPND |= 0x1<<0; if(rUTRSTAT0 & 0x1){ ch = rURXH0; while(!(rUTRSTAT0&0x4)); rUTXH0 = ch;command = ch;switch(command){case 0xaa:cmd = 0x01;break;case 0xbb:stop = 1;break;case 0xcc:cmd = 0x02;break;} } } void WriteL3(U8 data, U32 mode){ //mode = 0,地址模式;mode = 1,数据传输模式 int i, k; if(mode == 0){ rGPBDAT = rGPBDAT & ~(L3MODE|L3DATA|L3CLOCK )|L3CLOCK; } else{ rGPBDAT = rGPBDAT & ~(L3MODE|L3DATA|L3CLOCK)|(L3CLOCK|L3MODE); } for(k = 0; k < 5; k++) ; for(i = 0; i < 8; i++){ if(data & 0x1){ rGPBDAT &= ~L3CLOCK; rGPBDAT |= L3DATA; for(k = 0; k < 5; k++) ; rGPBDAT |= L3CLOCK; rGPBDAT |= L3DATA; for(k = 0; k < 5; k++) ; } else{ rGPBDAT &= ~L3CLOCK; rGPBDAT &= ~L3DATA; for(k = 0; k < 5; k++) ; rGPBDAT |= L3CLOCK; rGPBDAT &= ~L3DATA; for(k = 0; k < 5; k++) ; } data >>= 1; } rGPBDAT = rGPBDAT & ~(L3MODE|L3DATA|L3CLOCK)|(L3CLOCK|L3MODE); } void play(U8 buffer[], U32 length){ int i, fifo; //UDA1341 //STATUS模式 rGPBDAT = rGPBDAT & ~(L3MODE|L3DATA|L3CLOCK)|(L3CLOCK|L3MODE); WriteL3(0x14+2,0); //复位 WriteL3(0x60,1); WriteL3(0x14+2,0); //00010000 系统时钟频率384fs WriteL3(0x10,1); WriteL3(0x14+2,0); //11000001 输出增益,ADC关,DAC开 WriteL3(0xc1,1); //IIS //DMA禁止,在接受空闲状态,不产生IISLRCK信号,IIS预分频使能 rIISCON = (0<<5)|(0<<4)|(0<<3)|(1<<2)|(1<<1); //主设备时钟PCLK,主设备模式,发送模式,串行数据16位,主时钟是384fs,串行位时钟32fs rIISMOD = (0<<9)|(0<<8)|(2<<6)|(0<<5)|(0<<4)|(1<<3)|(1<<2)|(1<<0); //预分频都是N=3 rIISPSR = (3<<5)|3; //发送FIFO正常,发送FIFO使能 rIISFCON = (0<<15)|(1<<13); //IIS start rIISCON |= 0x1; for(fifo = 0; fifo <= length; fifo += 64){ while(rIISCON &(1<<7)); for(i = 0; i < 32; i++) rIISFIFO = (iis_buffer[i*2+fifo]) + (iis_buffer[i*2+1+fifo]<<8); } //IIS close rIISCON = 0x0; } void record(){int i, fifo; rGPBDAT = rGPBDAT & ~(L3MODE|L3DATA|L3CLOCK)|(L3CLOCK|L3MODE); WriteL3(0x14+2,0); //复位 WriteL3(0x60,1);WriteL3(0x14+2,0); //00010000 系统时钟频率384fs WriteL3(0x10,1); WriteL3(0x14+2,0); //10100010 输入增益,ADC开,DAC关 WriteL3(0xa2,1);WriteL3(0x14+0,0); WriteL3(0x7b,1); //01,1110,11 BB 18dB~24dB Treble 6dBWriteL3(0xc0,1);WriteL3(0xe0,1); //000,00000 MA 0dBWriteL3(0xc1,1);WriteL3(0xe0,1); //001,00000 MB 0dBWriteL3(0xc4,1);WriteL3(0xf0,1); //100,1,00,00 AGC使能 WriteL3(0xc2,1);WriteL3(0xf9,1); //010,110,11 MIC 26dB input 1 * MA + input 2 * MB //IIS //DMA禁止,在接受空闲状态,不产生IISLRCK信号,IIS预分频使能 rIISCON = (0<<5)|(0<<4)|(1<<3)|(0<<2)|(1<<1); //主设备时钟PCLK,主设备模式,接收模式,串行数据16位,主时钟是384fs,串行位时钟32fs rIISMOD = (0<<9)|(0<<8)|(1<<6)|(0<<5)|(0<<4)|(1<<3)|(1<<2)|(1<<0); //预分频都是N=3 rIISPSR = (3<<5)|3; //发送FIFO正常,发送FIFO使能 rIISFCON = (0<<14)|(1<<12); //IIS start rIISCON |= 0x1; for(fifo = 0; stop == 0; fifo += 64){ while(!(rIISCON &(1<<6))); for(i = 0; i < 32; i++){temp = rIISFIFO;iis_buffer[i*2+fifo] = temp & 0xff;iis_buffer[i*2+1+fifo] = temp & 0xff00; } } //IIS close rIISCON = 0x0; }int Main(){ cmd = 0; stop = 0; rULCON0 = 0x3; rUCON0 = (1<<11)|(1<<2)|(1<<0); rUBRDIV0 = 36; rSRCPND = 0x1<<28; rINTPND = 0x1<<28; rSUBSRCPND = 0x1<<0; rINTMSK &= ~(0x1<<28); rINTSUBMSK &= ~(0x1<<0); pISR_UART0 = (U32)UART0_ISR;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) rGPBDAT = 0x1ec; 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 rMPLLCON = (150<<12)|(5<<4)|(0<<0); while(1){ while(!cmd);switch(cmd){ case 0x01: record();break; case 0x02: play(iis_buffer,sizeof(iis_buffer));break; }cmd = 0;stop = 0; }return 0; } |
|
|