#include "global.h" int sport0a_buf[2][NUM_SAMPLES*SLOTS]; int sport0b_buf[2][NUM_SAMPLES*SLOTS]; int sport1a_buf[2][NUM_SAMPLES*SLOTS]; int sport1b_buf[2][NUM_SAMPLES*SLOTS]; int sport2a_buf[2][NUM_SAMPLES*SLOTS]; int sport2b_buf[2][NUM_SAMPLES*SLOTS]; int sport3a_buf[2][NUM_SAMPLES*SLOTS]; int sport3b_buf[2][NUM_SAMPLES*SLOTS]; int sport4a_buf[2][NUM_SAMPLES*2]; int sport5a_buf[2][NUM_SAMPLES*2]; int sport6a_buf[2][NUM_SAMPLES*SLOTS]; int sport7a_buf[2][NUM_SAMPLES*SLOTS]; //int xt[1024*1024]; //2 For ping-pong ,each TCB has four registers. int sport0a_tcb[2][4] = { {0, NUM_SAMPLES*SLOTS, 1, (int) sport0a_buf[0]}, {0, NUM_SAMPLES*SLOTS, 1, (int) sport0a_buf[1]} }; int sport0b_tcb[2][4] = { {0, NUM_SAMPLES*SLOTS, 1, (int) sport0b_buf[0]}, {0, NUM_SAMPLES*SLOTS, 1, (int) sport0b_buf[1]} }; int sport1a_tcb[2][4] = { {0, NUM_SAMPLES*SLOTS, 1, (int) sport1a_buf[0]}, {0, NUM_SAMPLES*SLOTS, 1, (int) sport1a_buf[1]} }; int sport1b_tcb[2][4] = { {0, NUM_SAMPLES*SLOTS, 1, (int) sport1b_buf[0]}, {0, NUM_SAMPLES*SLOTS, 1, (int) sport1b_buf[1]} }; int sport2a_tcb[2][4] = { {0, NUM_SAMPLES*SLOTS, 1, (int) sport2a_buf[0]}, {0, NUM_SAMPLES*SLOTS, 1, (int) sport2a_buf[1]} }; int sport2b_tcb[2][4] = { {0, NUM_SAMPLES*SLOTS, 1, (int) sport2b_buf[0]}, {0, NUM_SAMPLES*SLOTS, 1, (int) sport2b_buf[1]} }; int sport3a_tcb[2][4] = { {0, NUM_SAMPLES*SLOTS, 1, (int) sport3a_buf[0]}, {0, NUM_SAMPLES*SLOTS, 1, (int) sport3a_buf[1]} }; int sport3b_tcb[2][4] = { {0, NUM_SAMPLES*SLOTS, 1, (int) sport3b_buf[0]}, {0, NUM_SAMPLES*SLOTS, 1, (int) sport3b_buf[1]} }; int sport4a_tcb[2][4] = { {0, NUM_SAMPLES*2, 1, (int) sport4a_buf[0]}, {0, NUM_SAMPLES*2, 1, (int) sport4a_buf[1]} }; int sport5a_tcb[2][4] = { {0, NUM_SAMPLES*2, 1, (int) sport5a_buf[0]}, {0, NUM_SAMPLES*2, 1, (int) sport5a_buf[1]} }; int sport6a_tcb[2][4] = { {0, NUM_SAMPLES*SLOTS, 1, (int) sport6a_buf[0]}, {0, NUM_SAMPLES*SLOTS, 1, (int) sport6a_buf[1]} }; int sport7a_tcb[2][4] = { {0, NUM_SAMPLES*SLOTS, 1, (int) sport7a_buf[0]}, {0, NUM_SAMPLES*SLOTS, 1, (int) sport7a_buf[1]} }; /* sport 0,2 TDMÊä³ö sport 1,3 TDMÊäÈë sport 4 i2s Êä³ö sport 5, i2s ÊäÈë sport 6 tdmÊä³ö sport 7 tdmÊäÈë */ void InitSPORT(int mask,int sampleRate) { int i; int fs_div = MCLK/RATE_SAMPLES; int sclk_div = MCLK/(RATE_SAMPLES*32*SLOTS); int sclk_div_48k = MCLK/(RATE_SAMPLES*32*2); int fs_div_8k = MCLK/8000; int sclk_div_8k = MCLK/(8000*32*32); int reg; /* External clock and frame syncs generated by AD1939 */ *pDIV0 = 0x00000000; // Transmitter (SPORT0) *pDIV1 = 0x00000000; // Receiver (SPORT1) at 12.288 MHz SCLK and 48 kHz sample rate sport0a_tcb[0][0]= ((int)sport0a_tcb[1] + 3)&0x7ffff | (1<<19); sport0a_tcb[1][0]= ((int)sport0a_tcb[0] + 3)&0x7ffff | (1<<19); sport0b_tcb[0][0]= ((int)sport0b_tcb[1] + 3)&0x7ffff | (1<<19); sport0b_tcb[1][0]= ((int)sport0b_tcb[0] + 3)&0x7ffff | (1<<19); sport1a_tcb[0][0]= ((int)sport1a_tcb[1] + 3)&0x7ffff | (1<<19); sport1a_tcb[1][0]= ((int)sport1a_tcb[0] + 3)&0x7ffff | (1<<19); sport1b_tcb[0][0]= ((int)sport1b_tcb[1] + 3)&0x7ffff | (1<<19); sport1b_tcb[1][0]= ((int)sport1b_tcb[0] + 3)&0x7ffff | (1<<19); sport2a_tcb[0][0]= ((int)sport2a_tcb[1] + 3)&0x7ffff | (1<<19); sport2a_tcb[1][0]= ((int)sport2a_tcb[0] + 3)&0x7ffff | (1<<19); sport2b_tcb[0][0]= ((int)sport2b_tcb[1] + 3)&0x7ffff | (1<<19); sport2b_tcb[1][0]= ((int)sport2b_tcb[0] + 3)&0x7ffff | (1<<19); sport3a_tcb[0][0]= ((int)sport3a_tcb[1] + 3)&0x7ffff | (1<<19); sport3a_tcb[1][0]= ((int)sport3a_tcb[0] + 3)&0x7ffff | (1<<19); sport3b_tcb[0][0]= ((int)sport3b_tcb[1] + 3)&0x7ffff | (1<<19); sport3b_tcb[1][0]= ((int)sport3b_tcb[0] + 3)&0x7ffff | (1<<19); sport4a_tcb[0][0]= ((int)sport4a_tcb[1] + 3)&0x7ffff | (1<<19); sport4a_tcb[1][0]= ((int)sport4a_tcb[0] + 3)&0x7ffff | (1<<19); sport5a_tcb[0][0]= ((int)sport5a_tcb[1] + 3)&0x7ffff | (1<<19); sport5a_tcb[1][0]= ((int)sport5a_tcb[0] + 3)&0x7ffff | (1<<19); sport6a_tcb[0][0]= ((int)sport6a_tcb[1] + 3)&0x7ffff | (1<<19); sport6a_tcb[1][0]= ((int)sport6a_tcb[0] + 3)&0x7ffff | (1<<19); sport7a_tcb[0][0]= ((int)sport7a_tcb[1] + 3)&0x7ffff | (1<<19); sport7a_tcb[1][0]= ((int)sport7a_tcb[0] + 3)&0x7ffff | (1<<19); *pSPCTL0 = *pSPCTL1 = *pSPCTL2=*pSPCTL3=*pSPCTL4=*pSPCTL5=*pSPCTL6=*pSPCTL7=0; *pSPMCTL0 = *pSPMCTL1=*pSPMCTL2=*pSPMCTL3=*pSPMCTL4=*pSPMCTL5 =*pSPMCTL6=*pSPMCTL7=0; *pSPCTLN0 =*pSPCTLN1=*pSPCTLN2=*pSPCTLN3=*pSPCTLN4=*pSPCTLN5 =*pSPCTLN6 =*pSPCTLN7=0; *pCPSP0A = sport0a_tcb[0][0]; *pCPSP0B = sport0b_tcb[0][0]; *pCPSP1A = sport1a_tcb[0][0]; *pCPSP1B = sport1b_tcb[0][0]; *pCPSP2A = sport2a_tcb[0][0]; *pCPSP2B = sport2b_tcb[0][0]; *pCPSP3A = sport3a_tcb[0][0]; *pCPSP3B = sport3b_tcb[0][0]; *pCPSP4A = sport4a_tcb[0][0]; *pCPSP5A = sport5a_tcb[0][0]; *pCPSP6A = sport6a_tcb[0][0]; *pCPSP7A = sport7a_tcb[0][0]; *pSPCTL4 = (SPTRAN| OPMODE | SLEN32 | SPEN_A | SCHEN_A | SDEN_A |LFS |CKRE); //usb send *pSPCTL5 = (SLEN32 | OPMODE | SPEN_A | SCHEN_A | SDEN_A |LFS |CKRE); //usb recv //tdm reg = (SPTRAN| SLEN32 | SCHEN_A | SDEN_A | SCHEN_B | SDEN_B |FSR |CKRE); //*pSPCTLN0 = FSED; // ֡ͬ²½±ßÑØ¼ì²â //reg = (SPTRAN| OPMODE |SPEN_A| SLEN32 | SCHEN_A | SDEN_A |SPEN_B| SCHEN_B | SDEN_B); *pSPCTL0 = reg; *pSPCTL2 = reg; reg = (SPTRAN| SLEN32 | SCHEN_A | SDEN_A |FSR |CKRE); *pSPCTL6 = reg; reg = (SLEN32 | SCHEN_A | SDEN_A | SCHEN_B | SDEN_B |FSR |CKRE); //reg = (SLEN32 | OPMODE| SPEN_A| SCHEN_A | SDEN_A | SPEN_B| SCHEN_B | SDEN_B); *pSPCTL1 = reg; *pSPCTL3 = reg; reg = (SLEN32 | SCHEN_A | SDEN_A |FSR |CKRE); *pSPCTL7 = reg; *pSP0CS0 = *pSP1CS0 = *pSP2CS0 = *pSP3CS0 = *pSP6CS0 = *pSP7CS0 = 0x000000ff; *pMT0CCS0 = *pMT2CCS0 = *pMT6CCS0 = 0; //0,2 transit *pMR1CCS0 = *pMR3CCS0 = *pMR7CCS0 = 0; reg = (NCH7 | MFD1 |MCEA|MCEB); *pSPMCTL0 = *pSPMCTL1 =*pSPMCTL2 = *pSPMCTL3 = reg; reg = (NCH7 | MFD1 |MCEA); *pSPMCTL6 = *pSPMCTL7 = reg; if(1) { int n,r0 ; *pPCG_CTLA1 =0 ; *pPCG_CTLA0 =0; for (n=0; n<16; n++)asm("NOP;"); r0 = sclk_div | CLKASOURCE | FSASOURCE; *pPCG_CTLA1 = r0 ; r0 = fs_div | ENFSA | ENCLKA ; *pPCG_CTLA0 = r0; //bypass mode PCGB , get invert sclk *pPCG_CTLB1 =0 ; *pPCG_CTLB0 =0; for (n=0; n<16; n++)asm("NOP;"); *pPCG_PW1 = 2| INVFSB ; r0 = sclk_div | CLKBSOURCE | FSBSOURCE; *pPCG_CTLB1 = r0 ; r0 = ENFSB | ENCLKB ; *pPCG_CTLB0 = r0; } ////USB if(1) { int n,r0 ; *pPCG_CTLC1 =0 ; *pPCG_CTLC0 =0; for (n=0; n<16; n++)asm("NOP;"); //*pPCG_PW1 =1; //*pPCG_PW2 = STROBEA| INVFSA; r0 = sclk_div_48k| CLKCSOURCE | FSCSOURCE | ((sclk_div_48k/2)<<20); *pPCG_CTLC1 = r0 ; r0 = fs_div | ENFSC | ENCLKC ; *pPCG_CTLC0 = r0; } }