📄 iis_test.c
字号:
//9-2. pcm + 16bit + 6ch
bool I2S_ChannelTestWave(void)
{
int i;
printf("Channel test by wave file\n");
printf("2CH. 1. 16bit, 2. 24bit, 3. 8bit \n");
if(g_I2S_Port == I2S_PORT0)
{
printf("6CH. 4. 16bit, 5. 24bit, 6. 8bit \n");
printf("4CH. 7. 16bit, 8. 24bit, 9. 8bit \n");
}
i = GetIntNum();
if(i==1) return I2S_ChannelCummTest(1, g_I2S_Port, 2, 16);//wave
else if(i==2) return I2S_ChannelCummTest(1, g_I2S_Port, 2, 24);//wave
else if(i==3) return I2S_ChannelCummTest(1, g_I2S_Port, 2, 8);//wave
if(g_I2S_Port != I2S_PORT0) return 0;
if(i==4) return I2S_ChannelCummTest(1, g_I2S_Port, 6, 16);//wave
else if(i==5) return I2S_ChannelCummTest(1, g_I2S_Port, 6, 24);//wave
else if(i==6) return I2S_ChannelCummTest(1, g_I2S_Port, 6, 8);//wave
else if(i==7) return I2S_ChannelCummTest(1, g_I2S_Port, 4, 16);//wave
else if(i==8) return I2S_ChannelCummTest(1, g_I2S_Port, 4, 24);//wave
else if(i==9) return I2S_ChannelCummTest(1, g_I2S_Port, 4, 8);//wave
else return 0;
}
// master : i2s0
// slave : wm8580
// PCLK(XTAL), 12Mhz,
// codec clock 16.934Mhz 44000Hz, 384fs,DMA, tx, 2ch
//10. I2S data format
bool I2S_DataformatTest(void)
{
bool bret;
int failnum;
printf("\ncodec 2ch 16bit sound out i2s format test(test pattern) to press any key\n");
getchar();
bret=I2S_ChannelTest(0, g_I2S_Port, I2S_FORMAT_I2S, 2, 16, 0, 1);//pattern
//int testsource, int port, int totch, int bit, int maskingch, bool testsourceredownload
if(!bret) failnum++;
printf("\ncodec 2ch 16bit sound out msb test(test pattern) to press any key\n");
getchar();
bret=I2S_ChannelTest(0, g_I2S_Port, I2S_FORMAT_MSB, 2, 16, 0, 0);//pattern
//int testsource, int port, int totch, int bit, int maskingch, bool testsourceredownload
if(!bret) failnum++;
printf("\ncodec 2ch 16bit sound out lsb test(test pattern) to press any key\n");
getchar();
bret=I2S_ChannelTest(0, g_I2S_Port, I2S_FORMAT_LSB, 2, 16, 0, 0);//pattern
//int testsource, int port, int totch, int bit, int maskingch, bool testsourceredownload
if(!bret) failnum++;
printf("\ncodec 2ch 16bit sound out i2s format test(wave) to press any key\n");
getchar();
bret=I2S_ChannelTest(1, g_I2S_Port, I2S_FORMAT_I2S, 2, 16, 0, 1);//wave
//int testsource, int port, int totch, int bit, int maskingch, bool testsourceredownload
if(!bret) failnum++;
printf("\ncodec 2ch 16bit sound out msb test(test pattern) to press any key\n");
getchar();
bret=I2S_ChannelTest(1, g_I2S_Port, I2S_FORMAT_MSB, 2, 16, 0, 0);//wave
//int testsource, int port, int totch, int bit, int maskingch, bool testsourceredownload
if(!bret) failnum++;
printf("\ncodec 2ch 16bit sound out lsb test(test pattern) to press any key\n");
getchar();
bret=I2S_ChannelTest(1, g_I2S_Port, I2S_FORMAT_LSB, 2, 16, 0, 0);//wave
//int testsource, int port, int totch, int bit, int maskingch, bool testsourceredownload
if(!bret) failnum++;
if(failnum>0) return 0;
else return 1;
}
bool I2S0_MasterClockSelectionTestEXT(void)
{
int failnum;
bool bret=0;
printf("please set om[0] hardware pin to 1, and EXTclk is installed with 12Mhz\n");
printf("if not, please turn off board, set, then restart this test\n");
AUTO_DownloadData(PCM_TESTPLAYINGDATA_BASE);//download to 0x31000000
//internal master
bret=I2S_ClockSelectionTestSub(I2S_PORT0, I2S_MASTER, CLK_PCLK_XTAL_12, PCLK_12__16_910, WM_8450,
PCM_TESTPLAYINGDATA_BASE, 500000);
if(!bret) failnum++;
return bret;
}
//with default setting check all with clock source selection playing are ok
// Master : i2s0
// slave : codec
//
//default setting :
// codec clock 16.934Mhz
// 44000Hz
// 384fs
// 16bit(32fs)
// DMA
// tx
// i2s format
// 2ch
bool I2S0_MasterClockSelectionTest(void)
{
int failnum;
bool bret=0;
//internal master
bret=I2S_ClockSelectionTestSub(I2S_PORT0, I2S_MASTER, CLK_PCLK_XTAL_12, PCLK_12__8_455, WM_8450,
PCM_TESTPLAYINGDATA_BASE, 500000);
if(!bret) failnum++;
bret=I2S_ClockSelectionTestSub(I2S_PORT0, I2S_MASTER, CLK_PCLK_XTAL_12, PCLK_12__16_910, WM_8450,
PCM_TESTPLAYINGDATA_BASE, 500000);
if(!bret) failnum++;
/*
bret=I2S_ClockSelectionTestSub(IIS_PORT0, MASTER, CLK_PCLK_EXTCLK, PCLK_33_8688, WM_8450);
if(!bret) failnum++;
bret=I2S_ClockSelectionTestSub(IIS_PORT0, MASTER, CLK_EPLL_DIV_XTAL, EPLL_DIV_33_8688, WM_8450);
if(!bret) failnum++;
bret=I2S_ClockSelectionTestSub(IIS_PORT0, MASTER, CLK_EPLL_DIV_EXTCLK, EPLL_DIV_33_8688, WM_8450);
if(!bret) failnum++;
bret=I2S_ClockSelectionTestSub(IIS_PORT0, MASTER, CLK_EPLL_REF10_XTAL, EPLL_REF_12, WM_8450);
if(!bret) failnum++;
bret=I2S_ClockSelectionTestSub(IIS_PORT0, MASTER, CLK_EPLL_REF10_EXTCLK, EPLL_REF_12, WM_8450);
if(!bret) failnum++;
bret=I2S_ClockSelectionTestSub(IIS_PORT0, MASTER, CLK_EPLL_REF11_XTAL, EPLL_REF_12, WM_8450);
if(!bret) failnum++;
bret=I2S_ClockSelectionTestSub(IIS_PORT0, MASTER, CLK_EPLL_REF11_EXTCLK, EPLL_REF_12, WM_8450);
if(!bret) failnum++;
//external master
bret=I2S_ClockSelectionTestSub(IIS_PORT0, MASTER, CLK_EXT_CODEC_CLK, EXT_CODEC_CLK_16_9344, WM_8450);
if(!bret) failnum++;
*/
return bret;
}
//I2S0+I2S1 test
////////////////////////////////////////////////////
// Test common function
////////////////////////////////////////////////////
//with default setting check all with clock source selection playing are ok
// master : i2s0
// slave : wm8580
// PCLK(XTAL), 12Mhz,
// codec clock 16.934Mhz 44000Hz, 384fs,DMA, tx, i2s format,
//pcm
//port, totch, bit are input variable
//test pattern / or test pcm is located in 0x32200000
//testsource 0: pattern 1:32bit 2ch 44000Hz pcmfile
bool I2S_ChannelCummTest(int testsource, int port, int totch, int bit)
{
int failnum;
bool bret=0;
unsigned int destsize;
unsigned int orgsize;
//channel 1 only sounds,
printf("\ncodec ch 1 sound out(Front left) test to press any key\n");
getchar();
bret = I2S_ChannelTest(testsource, port, I2S_FORMAT_I2S, totch, bit, 0x3f & ~(0x1<<0), 1);
//int testsource, int port, int totch, int bit, int maskingch, bool testsourceredownload
if(!bret) failnum++;
//channel 2 only sounds,
printf("\ncodec ch 2 sound out(Front right) test to press any key\n");
getchar();
bret = I2S_ChannelTest(testsource, port, I2S_FORMAT_I2S, totch, bit, 0x3f & ~(0x1<<1), 0);
//int testsource, int port, int totch, int bit, int maskingch, bool testsourceredownload
if(!bret) failnum++;
//2 channel sounds,
printf("\ncodec 2channels sound out test to press any key\n");
getchar();
bret = I2S_ChannelTest(testsource, port, I2S_FORMAT_I2S, totch, bit, 0x3f & ~(0x3<<0), 0);
//int testsource, int port, int totch, int bit, int maskingch, bool testsourceredownload
if(!bret) failnum++;
//all channel mask for SNR measuring
printf("\nall channel mask for SNR measuring\n");
getchar();
bret = I2S_ChannelTest(testsource, port, I2S_FORMAT_I2S, totch, bit, 0x3f, 0);
//int testsource, int port, int totch, int bit, int maskingch, bool testsourceredownload
if(!bret) failnum++;
if(totch<3)
{
if(failnum>0) return 0;
else return 1;
}
//channel 3 only sounds,
printf("\ncodec ch 3 sound out(Center left) test to press any key\n");
getchar();
bret = I2S_ChannelTest(testsource, port, I2S_FORMAT_I2S, totch, bit, 0x3f & ~(0x1<<2), 0);
//int testsource, int port, int totch, int bit, int maskingch, bool testsourceredownload
if(!bret) failnum++;
//channel 4 only sounds,
printf("\ncodec ch 4 sound out(Center right) test to press any key\n");
getchar();
bret = I2S_ChannelTest(testsource, port, I2S_FORMAT_I2S, totch, bit, 0x3f & ~(0x1<<3), 0);
//int testsource, int port, int totch, int bit, int maskingch, bool testsourceredownload
if(!bret) failnum++;
//4channel sounds,
printf("\ncodec 4channels sound out test to press any key\n");
getchar();
bret = I2S_ChannelTest(testsource, port, I2S_FORMAT_I2S, totch, bit, 0x3f & ~(0xf<<0), 0);
//int testsource, int port, int totch, int bit, int maskingch, bool testsourceredownload
if(!bret) failnum++;
if(totch<5)
{
if(failnum>0) return 0;
else return 1;
}
//channel 5 only sounds,
printf("\ncodec ch 5 sound out(read left) test to press any key\n");
getchar();
bret = I2S_ChannelTest(testsource, port, I2S_FORMAT_I2S, totch, bit, 0x3f & ~(0x1<<4), 0);
//int testsource, int port, int totch, int bit, int maskingch, bool testsourceredownload
if(!bret) failnum++;
//channel 6 only sounds,
printf("\ncodec ch 6 sound out(rear right) test to press any key\n");
getchar();
bret = I2S_ChannelTest(testsource, port, I2S_FORMAT_I2S, totch, bit, 0x3f & ~(0x1<<5), 0);
//int testsource, int port, int totch, int bit, int maskingch, bool testsourceredownload
if(!bret) failnum++;
//6channel sounds,
printf("\ncodec 6ch sound out test to press any key\n");
getchar();
bret = I2S_ChannelTest(testsource, port, I2S_FORMAT_I2S, totch, bit, 0, 0);
//int testsource, int port, int totch, int bit, int maskingch, bool testsourceredownload
if(!bret) failnum++;
return bret;
}
//default setting :
// codec clock 16.934Mhz
// 44000Hz
// 384fs
// 16bit
// DMA
// tx
// i2s format
// 2ch
//before starting playing pcm data should be inserted at 0x31000000
//by
//DownloadData();
//PCM_DATA_2chpattern_making( 0x31000000, 500000/5000,5000, 16);
//destaddr, unit repeat datasize, repeat num, bitperch
bool I2S_ClockSelectionTestSub( int Port, int Opmode,
int CodecClk, int ClkSpeed,
int CodecChip,
unsigned int sourceaddr, unsigned int sourcesize)
{
bool ret;
/*
I2S_InitGpio(ePort);
I2S_InitGpioIF(ePort, eCodecChip);
I2S_SelectCodecClock( ePort, eCodecClk, eClkSpeed);//with assert
I2S_SelectMasterSlave(ePort, eOpmode);//with assert
I2S_DataDN(0x32000000);//dn 1ch source
//I2S_DataConvert(0x32000000, rec_buff, 16bit, 0x2);//s, d, bit, ch configuration 0x3f mean 6ch
I2S_InitCodec(eCodecChip, Opmode,
tx, i2sformat, 384fs, 16bit);
I2S_PLAY( ePort,
rec_buff, 464000,
tx, i2sformat, 384fs, 16bit
);//port, source, setting,
*/
//I2S_DEINIT();
//I2S_DeinitCodec();
//I2S_DeinitCodecClock();
//I2S_DeinitGpioIF();
//I2S_DeinitGpio();
IIS_Port_Init(Port);
if(CodecClk == CLK_PCLK_XTAL_12)
{
I2S_PCLK_speed_change(16910, 12000);//fout, fin
switch(ClkSpeed)
{
//pdf = 5; // prescaler division factor(SMDK) 50/(5+1)=8.34Mhz
//pdf = 1; // prescaler division factor(FPGA) 16.91/(1+1)=8.455Mhz
//pdf = 0; // prescaler division factor(FPGA) 16.91/(0+1)=16.91Mhz (Default)
case 16910:
Select_PCLK(0);
break;
case 8455:
Select_PCLK(1);
break;
}
}
else
if(CodecClk == CLK_PCLK_EXTCLK_12)
{
I2S_PCLK_speed_change(16910, 12000);
switch(ClkSpeed)
{
//pdf = 1; // prescaler division factor(FPGA) 16.91/(1+1)=8.455Mhz
//pdf = 0; // prescaler division factor(FPGA) 16.91/(0+1)=16.91Mhz (Default)
case 16910:
Select_PCLK(0);
break;
case 8455:
Select_PCLK(1);
break;
}
}
else
if(CodecClk == CLK_PCLK_EXTCLK_169344)
{
I2S_PCLK_speed_change(16910, 16934);//nor update is needed
switch(ClkSpeed)
{
//pdf = 1; // prescaler division factor(FPGA) 16.91/(1+1)=8.455Mhz
//pdf = 0; // prescaler division factor(FPGA) 16.91/(0+1)=16.91Mhz (Default)
case 16910:
Select_PCLK(0);
break;
case 8455:
Select_PCLK(1);
break;
}
}
else
return 0;
//before starting playing pcm data should be inserted at 0x31000000
//2450
ret=I2SCODEC_InitWm8580(I2S_MASTER,
I2S_MODE_TX, I2S_FORMAT_I2S, 0, 16);
//int OpMode,
//int txr, int dataformat, int CodecClkFs, int BitperCh)
if(!ret) return 0;
if(sourceaddr>0 && sourcesize>0)
{
I2S_Setting(Port, I2S_MASTER, 0, 0, 384, 32, 2, 16,I2S_DMA);
//Port, MasterSlave, int trx, int i2sformat, int rootfs, int ch, int bit);
//IIS_PlayWave_DMA2(0x31000000, 464000);
IIS_PlayWave_DMA(Port, (unsigned char *)sourceaddr, sourcesize, 16);//0x31000000, 500000);
}
// need to add mute function
IIS_Port_Return(Port);
return 1;
}
//end of code
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -