forked from PAWPAW-Mirror/lib_xua
Initial guarding of variable bit I2S modifications
This commit is contained in:
@@ -39,7 +39,11 @@ void InitPorts_master(unsigned divide, buffered _XUA_CLK_DIR port:32 p_lrclk, bu
|
||||
|
||||
#pragma xta endpoint "divide_1"
|
||||
unsigned tmp;
|
||||
#ifdef N_BITS_I2S
|
||||
tmp = partout_timestamped(p_lrclk, N_BITS_I2S, 0);
|
||||
#else
|
||||
p_lrclk <: 0 @ tmp;
|
||||
#endif
|
||||
tmp += 100;
|
||||
|
||||
/* Since BCLK is free-running, setup outputs/inputs at a known point in the future */
|
||||
@@ -47,17 +51,28 @@ void InitPorts_master(unsigned divide, buffered _XUA_CLK_DIR port:32 p_lrclk, bu
|
||||
#pragma loop unroll
|
||||
for(int i = 0; i < I2S_WIRES_DAC; i++)
|
||||
{
|
||||
#ifdef N_BITS_I2S
|
||||
partout_timed(p_i2s_dac[i], N_BITS_I2S, 0, tmp);
|
||||
#else
|
||||
p_i2s_dac[i] @ tmp <: 0;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef N_BITS_I2S
|
||||
partout_timed(p_lrclk, N_BITS_I2S, 0x7FFFFFFF, tmp);
|
||||
#else
|
||||
p_lrclk @ tmp <: 0x7FFFFFFF;
|
||||
#endif
|
||||
|
||||
|
||||
#if (I2S_CHANS_ADC != 0)
|
||||
for(int i = 0; i < I2S_WIRES_ADC; i++)
|
||||
{
|
||||
asm("setpt res[%0], %1"::"r"(p_i2s_adc[i]),"r"(tmp-1));
|
||||
#ifdef N_BITS_I2S
|
||||
set_port_shift_count(p_i2s_adc[i], N_BITS_I2S);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif /* (I2S_CHANS_ADC != 0 || I2S_CHANS_DAC != 0) */
|
||||
@@ -92,7 +107,11 @@ void InitPorts_slave(unsigned divide, buffered _XUA_CLK_DIR port:32 p_lrclk, buf
|
||||
p_lrclk when pinseq(0) :> void @ tmp;
|
||||
#endif
|
||||
|
||||
#ifdef N_BITS_I2S
|
||||
tmp += (I2S_CHANS_PER_FRAME * N_BITS_I2S) - N_BITS_I2S + 1 ;
|
||||
#else
|
||||
tmp += (I2S_CHANS_PER_FRAME * 32) - 32 + 1 ;
|
||||
#endif
|
||||
/* E.g. 2 * 32 - 32 + 1 = 33 for stereo */
|
||||
/* E.g. 8 * 32 - 32 + 1 = 225 for 8 chan TDM */
|
||||
|
||||
@@ -100,7 +119,11 @@ void InitPorts_slave(unsigned divide, buffered _XUA_CLK_DIR port:32 p_lrclk, buf
|
||||
#pragma loop unroll
|
||||
for(int i = 0; i < I2S_WIRES_DAC; i++)
|
||||
{
|
||||
#ifdef N_BITS_I2S
|
||||
partout_timed(p_i2s_dac[i], N_BITS_I2S, 0, tmp-1);
|
||||
#else
|
||||
p_i2s_dac[i] @ tmp <: 0;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -109,12 +132,16 @@ void InitPorts_slave(unsigned divide, buffered _XUA_CLK_DIR port:32 p_lrclk, buf
|
||||
for(int i = 0; i < I2S_WIRES_ADC; i++)
|
||||
{
|
||||
asm("setpt res[%0], %1"::"r"(p_i2s_adc[i]),"r"(tmp-1));
|
||||
#ifdef N_BITS_I2S
|
||||
set_port_shift_count(p_i2s_adc[i], N_BITS_I2S);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
asm("setpt res[%0], %1"::"r"(p_lrclk),"r"(tmp-1));
|
||||
#ifdef N_BITS_I2S
|
||||
set_port_shift_count(p_lrclk, N_BITS_I2S);
|
||||
#endif
|
||||
#endif /* (I2S_CHANS_ADC != 0 || I2S_CHANS_DAC != 0) */
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -160,10 +160,14 @@ static inline int HandleSampleClock(int frameCount, buffered _XUA_CLK_DIR port:3
|
||||
#if CODEC_MASTER
|
||||
unsigned syncError = 0;
|
||||
unsigned lrval = 0;
|
||||
const unsigned lrval_mask = (0xffffffff << (32 - N_BITS_I2S));
|
||||
|
||||
#ifdef N_BITS_I2S
|
||||
const unsigned lrval_mask = (0xffffffff << (32 - N_BITS_I2S));
|
||||
asm volatile("in %0, res[%1]":"=r"(lrval):"r"(p_lrclk):"memory");
|
||||
set_port_shift_count(p_lrclk, N_BITS_I2S);
|
||||
#else
|
||||
p_lrclk :> lrval;
|
||||
#endif
|
||||
|
||||
if(I2S_MODE_TDM)
|
||||
{
|
||||
@@ -181,20 +185,32 @@ static inline int HandleSampleClock(int frameCount, buffered _XUA_CLK_DIR port:3
|
||||
}
|
||||
else
|
||||
{
|
||||
if(frameCount == 0)
|
||||
if(frameCount == 0)
|
||||
#ifdef N_BITS_I2S
|
||||
{
|
||||
if ((lrval & lrval_mask) != 0x80000000)
|
||||
{
|
||||
syncError = 1;
|
||||
}
|
||||
}
|
||||
#else
|
||||
{
|
||||
syncError += (lrval != 0x80000000);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
#ifdef N_BITS_I2S
|
||||
{
|
||||
if ((lrval | (~lrval_mask)) != 0x7FFFFFFF)
|
||||
{
|
||||
syncError = 1;
|
||||
}
|
||||
}
|
||||
#else
|
||||
{
|
||||
syncError += (lrval != 0x7FFFFFFF);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return syncError;
|
||||
@@ -210,9 +226,17 @@ static inline int HandleSampleClock(int frameCount, buffered _XUA_CLK_DIR port:3
|
||||
else
|
||||
{
|
||||
if(frameCount == 0)
|
||||
#ifdef N_BITS_I2S
|
||||
partout(p_lrclk, N_BITS_I2S, 0x80000000 >> (32 - N_BITS_I2S));
|
||||
#else
|
||||
p_lrclk <: 0x80000000;
|
||||
#endif
|
||||
else
|
||||
#ifdef N_BITS_I2S
|
||||
partout(p_lrclk, N_BITS_I2S, 0x7fffffff >> (32 - N_BITS_I2S));
|
||||
#else
|
||||
p_lrclk <: 0x7fffffff;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@@ -369,8 +393,12 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
|
||||
// Manual IN instruction since compiler generates an extra setc per IN (bug #15256)
|
||||
unsigned sample;
|
||||
asm volatile("in %0, res[%1]" : "=r"(sample) : "r"(p_i2s_adc[index++]));
|
||||
#ifdef N_BITS_I2S
|
||||
set_port_shift_count(p_i2s_adc[i], N_BITS_I2S);
|
||||
sample = bitrev(sample) << (32 - N_BITS_I2S);
|
||||
#else
|
||||
sample = bitrev(sample);
|
||||
#endif
|
||||
int chanIndex = ((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i; // channels 0, 2, 4.. on each line.
|
||||
|
||||
#if (AUD_TO_USB_RATIO > 1)
|
||||
@@ -423,7 +451,11 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
|
||||
src_ff3v_fir_coefs[2-audioToUsbRatioCounter]);
|
||||
}
|
||||
#endif /* (AUD_TO_USB_RATIO > 1) */
|
||||
#ifdef N_BITS_I2SN
|
||||
partout(p_i2s_dac[index++], N_BITS_I2S, bitrev(samplesOut[frameCount +i]));
|
||||
#else
|
||||
p_i2s_dac[index++] <: bitrev(samplesOut[frameCount +i]);
|
||||
#endif
|
||||
|
||||
}
|
||||
#endif // (I2S_CHANS_DAC != 0)
|
||||
@@ -499,8 +531,12 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
|
||||
/* Manual IN instruction since compiler generates an extra setc per IN (bug #15256) */
|
||||
unsigned sample;
|
||||
asm volatile("in %0, res[%1]" : "=r"(sample) : "r"(p_i2s_adc[index++]));
|
||||
#ifdef N_BITS_I2S
|
||||
set_port_shift_count(p_i2s_adc[i], N_BITS_I2S);
|
||||
sample = bitrev(sample) << (32 - N_BITS_I2S);
|
||||
#else
|
||||
sample = bitrev(sample);
|
||||
#endif
|
||||
|
||||
int chanIndex = ((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i; // channels 1, 3, 5.. on each line.
|
||||
#if (AUD_TO_USB_RATIO > 1 && !I2S_DOWNSAMPLE_MONO_IN)
|
||||
@@ -552,7 +588,11 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
|
||||
src_ff3v_fir_coefs[2-audioToUsbRatioCounter]);
|
||||
}
|
||||
#endif /* (AUD_TO_USB_RATIO > 1) */
|
||||
#ifdef N_BITS_I2S
|
||||
partout(p_i2s_dac[index++], N_BITS_I2S, bitrev(samplesOut[frameCount + i]));
|
||||
#else
|
||||
p_i2s_dac[index++] <: bitrev(samplesOut[frameCount + i]);
|
||||
#endif
|
||||
|
||||
}
|
||||
#endif // (I2S_CHANS_DAC != 0)
|
||||
@@ -775,8 +815,12 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
|
||||
#endif
|
||||
|
||||
#else
|
||||
#ifndef N_BITS_I2S
|
||||
/* I2S has 32 bits per sample. *2 as 2 channels */
|
||||
unsigned numBits = 2 * 32;
|
||||
#else
|
||||
unsigned numBits = 2 * N_BITS_I2S;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (DSD_CHANS_DAC > 0)
|
||||
|
||||
Reference in New Issue
Block a user