?? post_common.c
字號:
//
// Connect DAC1 to SPORT1, using data output A
// Connect DAC2 to SPORT1, using data output B
// Connect DAC3 to SPORT2, using data output A
// Connect DAC4 to SPORT2, using data output B
//
// Connect the clock and frame sync inputs to SPORT1 and SPORT2
// should come from the ADC on DAI pins 7 and 8, respectively
//
// Connect the ADC BCLK and LRCLK back out to the DAC on DAI
// pins 13 and 14, respectively.
//
// All six DAC connections are always outputs from the SHARC
// so tie the pin buffer enable inputs all high.
//
//------------------------------------------------------------------------
// Connect the pin buffers to the SPORT data lines and ADC BCLK & LRCLK
SRU(SPORT2_DB_O,DAI_PB09_I);
SRU(SPORT2_DA_O,DAI_PB10_I);
SRU(SPORT1_DB_O,DAI_PB11_I);
SRU(SPORT1_DA_O,DAI_PB12_I);
//------------------------------------------------------------------------
// Connect the clock and frame sync input from the ADC directly
// to the output pins driving the DACs.
SRU(DAI_PB07_O,DAI_PB13_I);
SRU(DAI_PB08_O,DAI_PB14_I);
//SRU(DAI_PB17_O,DAI_PB06_I); // comment out for external pll
//------------------------------------------------------------------------
// Connect the SPORT clocks and frame syncs to the clock and
// frame sync from the SPDIF receiver
SRU(DAI_PB07_O,SPORT1_CLK_I);
SRU(DAI_PB07_O,SPORT2_CLK_I);
SRU(DAI_PB08_O,SPORT1_FS_I);
SRU(DAI_PB08_O,SPORT2_FS_I);
//------------------------------------------------------------------------
// Tie the pin buffer enable inputs HIGH to make DAI pins 9-14 outputs.
SRU(HIGH,PBEN06_I);
SRU(HIGH,PBEN09_I);
SRU(HIGH,PBEN10_I);
SRU(HIGH,PBEN11_I);
SRU(HIGH,PBEN12_I);
SRU(HIGH,PBEN13_I);
SRU(HIGH,PBEN14_I);
}
void Config_SRU_UART(void)
{
// connect the pin buffer output signal to the UART0 receive
SRU2(DPI_PB10_O,UART0_RX_I);
SRU2(LOW,DPI_PB10_I);
SRU2(LOW,DPI_PBEN10_I)
// UART transmit signal is connected to DPI pin 9
SRU2(UART0_TX_O,DPI_PB09_I);
SRU2(HIGH,DPI_PBEN09_I);
}
void Config_SRU_AT25F2048(void)
{
SRU(SPI_CLK_O,DPI_PB03_I);
SRU(HIGH,DPI_PBEN03_I);
// for the flag pins to act as chip select
SRU(FLAG4_O, DPI_PB05_I);
SRU(HIGH, DPI_PBEN05_I);
}
void Config_SRU_INTS(void)
{
//Pin Assignments in SRU_PIN3 (Group D)
SRU(LOW,DAI_PB19_I);//assign pin buffer 19 low so it is an input
SRU(LOW,DAI_PB20_I); //assign pin buffer 20 low so it is an input
//Route MISCA singnals in SRU_EXT_MISCA (Group E)
SRU(DAI_PB19_O,MISCA1_I);//route so that DAI pin buffer 19 connects to MISCA1
SRU(DAI_PB20_O,MISCA2_I);//route so that DAI pin buffer 20 connects to MISCA2
//Pin Buffer Disable in SRU_PINEN0 (Group F)
SRU(LOW,PBEN19_I);//assign pin 19 low so it is an input
SRU(LOW,PBEN20_I);//assign pin 20 low so it is an input
}
void Config_SRU_LEDS(void)
{
//Setting the SRU and route so that Flag pins connects to DPI pin buffers.
//Use Flags 4 to 15 only. Flags 0 to 3 are reserved
SRU(FLAG4_O,DPI_PB06_I); //DPI => We can use flags.
SRU(FLAG5_O,DPI_PB07_I); //DPI => We can use flags.
SRU(FLAG6_O,DPI_PB08_I); //DPI => We can use flags.
SRU(FLAG7_O,DPI_PB13_I); //DPI => We can use flags.
SRU(FLAG8_O,DPI_PB14_I); //DPI => We can use flags.
SRU(LOW,DAI_PB15_I); //DAI => We can't use flags. Value has to be set low or high.
SRU(LOW,DAI_PB16_I); //DAI => We can't use flags. Value has to be set low or high.
//Enabling the Buffer using the following sequence: High -> Output, Low -> Input
SRU(HIGH,DPI_PBEN06_I);
SRU(HIGH,DPI_PBEN07_I);
SRU(HIGH,DPI_PBEN08_I);
SRU(HIGH,DPI_PBEN13_I);
SRU(HIGH,DPI_PBEN14_I);
SRU(HIGH,PBEN15_I); //default format to enable the buffer using DAI
SRU(HIGH,PBEN16_I);
}
void Config_SRU_SPDIF(void)
{
// Disable the pull-up resistors on all 20 pins
*pDAI_PIN_PULLUP = 0x000FFFFF;
//------------------------------------------------------------------------
// Connect the SPDIF Receiver
SRU(DAI_PB18_O, DIR_I);
//------------------------------------------------------------------------
// Connect the SPDIF Receiver outputs.
SRU(DIR_DAT_O, SPORT0_DA_I);
SRU(DIR_FS_O, SPORT0_FS_I);
SRU(DIR_CLK_O, SPORT0_CLK_I);
//------------------------------------------------------------------------
// Connect the SPDIF Transmitter Inputs
SRU(SPORT3_DA_O, DIT_DAT_I);
SRU(DIR_FS_O, DIT_FS_I);
SRU(DIR_CLK_O, DIT_CLK_I);
SRU(DIR_CLK_O, SPORT3_CLK_I);
SRU(DIR_FS_O, SPORT3_FS_I );
SRU(DIR_TDMCLK_O, DIT_HFCLK_I); // also used in external pll code
//SRU(DIR_TDMCLK_O,DAI_PB03_I);
//SRU(DAI_PB02_O,DIT_HFCLK_I);
//SRU(HIGH,PBEN03_I);
//SRU(LOW,PBEN02_I);
//------------------------------------------------------------------------
// Connect the SPDIF Transmitter Output.
SRU(DIT_O, DAI_PB01_I);
//------------------------------------------------------------------------
// Tie the pin buffer inputs LOW for DAI pin 18. Even though
// these pins are inputs to the SHARC, tying unused pin buffer inputs
// LOW is "good coding style" to eliminate the possibility of
// termination artifacts internal to the IC. Note that signal
// integrity is degraded only with a few specific SRU combinations.
// In practice, this occurs VERY rarely, and these connections are
// typically unnecessary.
SRU(LOW, DAI_PB18_I);
//------------------------------------------------------------------------
// Tie the pin buffer enable inputs LOW for DAI pin 18 so
// that they are always input pins.
SRU(LOW, PBEN18_I);
//-----------------------------------------------------------------------------
//------------------------------------------------------------------------
// Tie the pin buffer enable inputs HIGH to make DAI pin 1 an output.
SRU(HIGH,PBEN01_I);
}
volatile bool g_bLeftRight = 1;
volatile int g_iSampleIndex = 1;
volatile int g_iSampleCount = 0;
volatile float g_fSineWaveOut[MAX_SAMPLES];
volatile float g_fSineWaveIn_Left[MAX_SAMPLES];
volatile float g_fSineWaveIn_Right[MAX_SAMPLES];
int Test_Channel(float* pfRealIn, const int iMaxSamples, const int iSampleRate, const float fExpFreq, const float fFreqTol, const float fExpAmp, const float fAmpTol)
{
const float fMaxFreq = (fExpFreq + (fExpFreq * fFreqTol));
const float fMinFreq = (fExpFreq - (fExpFreq * fFreqTol));
complex_float cfFFTOut[(MAX_SAMPLES/2)];
float fTempFreq = 0;
int nSampleNumber = 0;
int nHighestFreqIndex = 0;
float fSampledFrequency = 0;
float fSlope = 0.0;
int iSlopeY1 = 0;
// Real input array fills from a converter or other source
rfft256( pfRealIn, (complex_float*)cfFFTOut);
// Arrays are filled with FFT data
// scan the output array for the highest real value
fTempFreq = abs(cfFFTOut[0].re);
for (nSampleNumber=1; nSampleNumber < (iMaxSamples / 2); nSampleNumber++)
{
if( abs(cfFFTOut[nSampleNumber].re) > fTempFreq )
{
fTempFreq = abs(cfFFTOut[nSampleNumber].re);
nHighestFreqIndex = nSampleNumber;
}
}
// multiply the index of the array of the highest value with the sample rate value
fSampledFrequency = nHighestFreqIndex * (iSampleRate / iMaxSamples);
// make sure frequency is within acceptable ranges
if( (fSampledFrequency < fMaxFreq) && (fSampledFrequency > fMinFreq) )
{
// for now, take the point before, and after the max value
// average them, then find the distance between them
// the slope is given by b = (y2 - y1) / (x2 - x1) or b = y2-y1
if( 0 == nSampleNumber )
{ // roll around to the end of the array
iSlopeY1 = iMaxSamples;
}
else if( iMaxSamples == nSampleNumber )
{
iSlopeY1 = 0;
}
else
{
iSlopeY1 = nSampleNumber - 1;
}
fSlope = (cfFFTOut[nHighestFreqIndex].re - cfFFTOut[iSlopeY1].re);
fSlope = abs(fSlope);
if( fSlope < fExpAmp )
{
return 0;
}
//fDB = 10 * log10( fSNR );
return 1;
}
//asm("nop;"); // asm("emuidle;"); //
return 0; // test failed
}
void CreateSinTable(const float fAmp, const float fFreq, const float fSampleRate)
{
int n;
for(n = 0; n < MAX_SAMPLES; n++)
{
g_fSineWaveOut[n] = (float)(fAmp * sin( (2.0 * PI * fFreq * ( ((float)(n+1)) / fSampleRate))) );
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -