8ch i2s slave passing

This commit is contained in:
Ed Clarke
2017-12-27 16:10:00 +00:00
parent 573b7f3b0c
commit 308e63a97d

View File

@@ -995,7 +995,6 @@ unsigned static deliver_slave(chanend ?c_out, chanend ?c_spd_out
#endif #endif
) )
{ {
/* Since DAC and ADC buffered ports off by one sample we buffer previous ADC frame */ /* Since DAC and ADC buffered ports off by one sample we buffer previous ADC frame */
unsigned readBuffNo = 0; unsigned readBuffNo = 0;
unsigned index; unsigned index;
@@ -1006,9 +1005,7 @@ unsigned static deliver_slave(chanend ?c_out, chanend ?c_spd_out
#endif #endif
int firstIteration = 1; int firstIteration = 1;
unsigned underflowWord = 0; unsigned underflowWord = 0;
unsigned frameCount = 0; unsigned frameCount = 0;
#ifdef ADAT_TX #ifdef ADAT_TX
adatCounter = 0; adatCounter = 0;
@@ -1078,6 +1075,7 @@ unsigned static deliver_slave(chanend ?c_out, chanend ?c_spd_out
* Check this every iteration and resync if we get a bclk glitch. * Check this every iteration and resync if we get a bclk glitch.
*/ */
int syncError = 0; int syncError = 0;
unsigned lrval;
if (!firstIteration) if (!firstIteration)
{ {
@@ -1110,13 +1108,16 @@ unsigned static deliver_slave(chanend ?c_out, chanend ?c_spd_out
// Manual IN instruction since compiler generates an extra setc per IN (bug #15256) // Manual IN instruction since compiler generates an extra setc per IN (bug #15256)
unsigned sample; unsigned sample;
asm volatile("in %0, res[%1]" : "=r"(sample) : "r"(p_i2s_adc[index++])); asm volatile("in %0, res[%1]" : "=r"(sample) : "r"(p_i2s_adc[index++]));
unsigned lrval;
if (i == 0){
p_lrclk :> lrval; p_lrclk :> lrval;
#ifdef I2S_MODE_TDM #ifdef I2S_MODE_TDM
syncError += (lrval != 0x00000000); //We do not check this part of the frame because TDM frame sync falling egde timing
//is not defined. We only care about rising edge which is checked in first half of frame
#else #else
syncError += (lrval != 0x80000000); syncError += (lrval != 0x80000000);
#endif // I2S_MODE_TDM #endif // I2S_MODE_TDM
}
sample = bitrev(sample); sample = bitrev(sample);
int chanIndex = ((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i; // channels 0, 2, 4.. on each line. int chanIndex = ((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i; // channels 0, 2, 4.. on each line.
@@ -1143,7 +1144,15 @@ unsigned static deliver_slave(chanend ?c_out, chanend ?c_spd_out
samplesIn[buffIndex][chanIndex] = sample; samplesIn[buffIndex][chanIndex] = sample;
#endif /* (AUD_TO_USB_RATIO > 1) */ #endif /* (AUD_TO_USB_RATIO > 1) */
} }
#endif #else //(I2S_CHANS_ADC != 0) //If no ADC channels then just check lrclk for sync
p_lrclk :> lrval;
#ifdef I2S_MODE_TDM
//We do not check this part of the frame because TDM frame sync falling egde timing
//is not defined. We only care about rising edge which is checked in first half of frame
#else
syncError += (lrval != 0x80000000);
#endif // I2S_MODE_TDM
#endif //(I2S_CHANS_ADC != 0)
#pragma xta endpoint "i2s_output_l" #pragma xta endpoint "i2s_output_l"
@@ -1240,7 +1249,7 @@ unsigned static deliver_slave(chanend ?c_out, chanend ?c_spd_out
/* Manual IN instruction since compiler generates an extra setc per IN (bug #15256) */ /* Manual IN instruction since compiler generates an extra setc per IN (bug #15256) */
unsigned sample; unsigned sample;
asm volatile("in %0, res[%1]" : "=r"(sample) : "r"(p_i2s_adc[index++])); asm volatile("in %0, res[%1]" : "=r"(sample) : "r"(p_i2s_adc[index++]));
unsigned lrval; if (i == 0) {
p_lrclk :> lrval; p_lrclk :> lrval;
#ifdef I2S_MODE_TDM #ifdef I2S_MODE_TDM
if (frameCount == (I2S_CHANS_PER_FRAME-2)) if (frameCount == (I2S_CHANS_PER_FRAME-2))
@@ -1254,6 +1263,7 @@ unsigned static deliver_slave(chanend ?c_out, chanend ?c_spd_out
#else #else
syncError += (lrval != 0x7FFFFFFF); syncError += (lrval != 0x7FFFFFFF);
#endif // I2S_MODE_TDM #endif // I2S_MODE_TDM
}
sample = bitrev(sample); sample = bitrev(sample);
int chanIndex = ((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i; // channels 1, 3, 5.. on each line. int chanIndex = ((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i; // channels 1, 3, 5.. on each line.
@@ -1280,7 +1290,21 @@ unsigned static deliver_slave(chanend ?c_out, chanend ?c_spd_out
samplesIn[buffIndex][chanIndex] = sample; samplesIn[buffIndex][chanIndex] = sample;
#endif /* (AUD_TO_USB_RATIO > 1) && !I2S_DOWNSAMPLE_MONO_IN */ #endif /* (AUD_TO_USB_RATIO > 1) && !I2S_DOWNSAMPLE_MONO_IN */
} }
#endif #else //(I2S_CHANS_ADC != 0) //No ADC so just do lrclk sync check only
p_lrclk :> lrval;
#ifdef I2S_MODE_TDM
if (frameCount == (I2S_CHANS_PER_FRAME-2))
{
syncError += (lrval != 0x80000000);
}
else
{
syncError += (lrval != 0x00000000);
}
#else
syncError += (lrval != 0x7FFFFFFF);
#endif //I2S_MODE_TDM
#endif //(I2S_CHANS_ADC != 0)
index = 0; index = 0;
#pragma xta endpoint "i2s_output_r" #pragma xta endpoint "i2s_output_r"