forked from PAWPAW-Mirror/lib_xua
Fixed operation when N_BITS_I2S define and small tidies
This commit is contained in:
@@ -12,7 +12,7 @@ extern buffered out port:32 p_dsd_clk;
|
|||||||
extern unsigned dsdMode;
|
extern unsigned dsdMode;
|
||||||
|
|
||||||
#if !CODEC_MASTER
|
#if !CODEC_MASTER
|
||||||
void InitPorts_master(unsigned divide, buffered _XUA_CLK_DIR port:32 p_lrclk, buffered _XUA_CLK_DIR port:32 p_bclk, buffered out port:32 (&?p_i2s_dac)[I2S_WIRES_DAC], buffered in port:32 (&?p_i2s_adc)[I2S_WIRES_ADC])
|
void InitPorts_master(buffered _XUA_CLK_DIR port:32 p_lrclk, buffered _XUA_CLK_DIR port:32 p_bclk, buffered out port:32 (&?p_i2s_dac)[I2S_WIRES_DAC], buffered in port:32 (&?p_i2s_adc)[I2S_WIRES_ADC])
|
||||||
{
|
{
|
||||||
#if (DSD_CHANS_DAC > 0)
|
#if (DSD_CHANS_DAC > 0)
|
||||||
if(dsdMode == DSD_MODE_OFF)
|
if(dsdMode == DSD_MODE_OFF)
|
||||||
@@ -92,7 +92,7 @@ void InitPorts_master(unsigned divide, buffered _XUA_CLK_DIR port:32 p_lrclk, bu
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
void InitPorts_slave(unsigned divide, buffered _XUA_CLK_DIR port:32 p_lrclk, buffered _XUA_CLK_DIR port:32 p_bclk, buffered out port:32 (&?p_i2s_dac)[I2S_WIRES_DAC], buffered in port:32 (&?p_i2s_adc)[I2S_WIRES_ADC])
|
void InitPorts_slave(buffered _XUA_CLK_DIR port:32 p_lrclk, buffered _XUA_CLK_DIR port:32 p_bclk, buffered out port:32 (&?p_i2s_dac)[I2S_WIRES_DAC], buffered in port:32 (&?p_i2s_adc)[I2S_WIRES_ADC])
|
||||||
{
|
{
|
||||||
#if (I2S_CHANS_ADC != 0 || I2S_CHANS_DAC != 0)
|
#if (I2S_CHANS_ADC != 0 || I2S_CHANS_DAC != 0)
|
||||||
unsigned tmp;
|
unsigned tmp;
|
||||||
|
|||||||
@@ -52,19 +52,6 @@ unsigned samplesOut[MAX(NUM_USB_CHAN_OUT, I2S_CHANS_DAC)];
|
|||||||
|
|
||||||
unsigned samplesIn[2][MAX(NUM_USB_CHAN_IN, IN_CHAN_COUNT)];
|
unsigned samplesIn[2][MAX(NUM_USB_CHAN_IN, IN_CHAN_COUNT)];
|
||||||
|
|
||||||
#ifdef XTA_TIMING_AUDIO
|
|
||||||
#pragma xta command "add exclusion received_command"
|
|
||||||
#pragma xta command "analyse path i2s_output_l i2s_output_r"
|
|
||||||
#pragma xta command "set required - 2000 ns"
|
|
||||||
|
|
||||||
#pragma xta command "add exclusion received_command"
|
|
||||||
#pragma xta command "add exclusion received_underflow"
|
|
||||||
#pragma xta command "add exclusion divide_1"
|
|
||||||
#pragma xta command "add exclusion deliver_return"
|
|
||||||
#pragma xta command "analyse path i2s_output_r i2s_output_l"
|
|
||||||
#pragma xta command "set required - 2000 ns"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (XUA_ADAT_TX_EN)
|
#if (XUA_ADAT_TX_EN)
|
||||||
extern buffered out port:32 p_adat_tx;
|
extern buffered out port:32 p_adat_tx;
|
||||||
#endif
|
#endif
|
||||||
@@ -78,7 +65,7 @@ void InitPorts_slave
|
|||||||
#else
|
#else
|
||||||
void InitPorts_master
|
void InitPorts_master
|
||||||
#endif
|
#endif
|
||||||
(unsigned divide, buffered _XUA_CLK_DIR port:32 p_lrclk, buffered _XUA_CLK_DIR port:32 p_bclk, buffered out port:32 (&?p_i2s_dac)[I2S_WIRES_DAC],
|
(buffered _XUA_CLK_DIR port:32 p_lrclk, buffered _XUA_CLK_DIR port:32 p_bclk, buffered out port:32 (&?p_i2s_dac)[I2S_WIRES_DAC],
|
||||||
buffered in port:32 (&?p_i2s_adc)[I2S_WIRES_ADC]);
|
buffered in port:32 (&?p_i2s_adc)[I2S_WIRES_ADC]);
|
||||||
|
|
||||||
|
|
||||||
@@ -160,18 +147,21 @@ static inline int HandleSampleClock(int frameCount, buffered _XUA_CLK_DIR port:3
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(frameCount == 0)
|
if(frameCount == 0)
|
||||||
|
{
|
||||||
#ifdef N_BITS_I2S
|
#ifdef N_BITS_I2S
|
||||||
partout(p_lrclk, N_BITS_I2S, 0x80000000 >> (32 - N_BITS_I2S));
|
partout(p_lrclk, N_BITS_I2S, 0x80000000 >> (32 - N_BITS_I2S));
|
||||||
#else
|
#else
|
||||||
p_lrclk <: 0x80000000;
|
p_lrclk <: 0x80000000;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
#ifdef N_BITS_I2S
|
#ifdef N_BITS_I2S
|
||||||
partout(p_lrclk, N_BITS_I2S, 0x7fffffff >> (32 - N_BITS_I2S));
|
partout(p_lrclk, N_BITS_I2S, 0x7fffffff >> (32 - N_BITS_I2S));
|
||||||
#else
|
#else
|
||||||
p_lrclk <: 0x7fffffff;
|
p_lrclk <: 0x7fffffff;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -290,9 +280,9 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
|
|||||||
if ((I2S_CHANS_DAC > 0 || I2S_CHANS_ADC > 0))
|
if ((I2S_CHANS_DAC > 0 || I2S_CHANS_ADC > 0))
|
||||||
{
|
{
|
||||||
#if CODEC_MASTER
|
#if CODEC_MASTER
|
||||||
InitPorts_slave(divide, p_lrclk, p_bclk, p_i2s_dac, p_i2s_adc);
|
InitPorts_slave(p_lrclk, p_bclk, p_i2s_dac, p_i2s_adc);
|
||||||
#else
|
#else
|
||||||
InitPorts_master(divide, p_lrclk, p_bclk, p_i2s_dac, p_i2s_adc);
|
InitPorts_master(p_lrclk, p_bclk, p_i2s_dac, p_i2s_adc);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,13 +316,16 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
|
|||||||
// p_i2s_adc[index++] :> sample;
|
// p_i2s_adc[index++] :> sample;
|
||||||
// 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]));
|
||||||
#ifdef N_BITS_I2S
|
#ifdef N_BITS_I2S
|
||||||
set_port_shift_count(p_i2s_adc[i], N_BITS_I2S);
|
set_port_shift_count(p_i2s_adc[index], N_BITS_I2S);
|
||||||
sample = bitrev(sample) << (32 - N_BITS_I2S);
|
sample = bitrev(sample) << (32 - N_BITS_I2S);
|
||||||
#else
|
#else
|
||||||
sample = bitrev(sample);
|
sample = bitrev(sample);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
index++;
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
#if (AUD_TO_USB_RATIO > 1)
|
#if (AUD_TO_USB_RATIO > 1)
|
||||||
@@ -385,7 +378,7 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
|
|||||||
src_ff3v_fir_coefs[2-audioToUsbRatioCounter]);
|
src_ff3v_fir_coefs[2-audioToUsbRatioCounter]);
|
||||||
}
|
}
|
||||||
#endif /* (AUD_TO_USB_RATIO > 1) */
|
#endif /* (AUD_TO_USB_RATIO > 1) */
|
||||||
#ifdef N_BITS_I2SN
|
#ifdef N_BITS_I2S
|
||||||
partout(p_i2s_dac[index++], N_BITS_I2S, bitrev(samplesOut[frameCount +i]));
|
partout(p_i2s_dac[index++], N_BITS_I2S, bitrev(samplesOut[frameCount +i]));
|
||||||
#else
|
#else
|
||||||
p_i2s_dac[index++] <: bitrev(samplesOut[frameCount +i]);
|
p_i2s_dac[index++] <: bitrev(samplesOut[frameCount +i]);
|
||||||
@@ -463,14 +456,16 @@ unsigned static AudioHub_MainLoop(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]));
|
||||||
#ifdef N_BITS_I2S
|
#ifdef N_BITS_I2S
|
||||||
set_port_shift_count(p_i2s_adc[i], N_BITS_I2S);
|
set_port_shift_count(p_i2s_adc[index], N_BITS_I2S);
|
||||||
sample = bitrev(sample) << (32 - N_BITS_I2S);
|
sample = bitrev(sample) << (32 - N_BITS_I2S);
|
||||||
#else
|
#else
|
||||||
sample = bitrev(sample);
|
sample = bitrev(sample);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
index++;
|
||||||
|
|
||||||
int chanIndex = ((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i; // channels 1, 3, 5.. on each line.
|
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)
|
#if (AUD_TO_USB_RATIO > 1 && !I2S_DOWNSAMPLE_MONO_IN)
|
||||||
if ((AUD_TO_USB_RATIO - 1) == audioToUsbRatioCounter)
|
if ((AUD_TO_USB_RATIO - 1) == audioToUsbRatioCounter)
|
||||||
@@ -502,7 +497,6 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
index = 0;
|
index = 0;
|
||||||
#pragma xta endpoint "i2s_output_r"
|
|
||||||
#if (I2S_CHANS_DAC != 0)
|
#if (I2S_CHANS_DAC != 0)
|
||||||
/* Output "odd" channel to DAC (i.e. right) */
|
/* Output "odd" channel to DAC (i.e. right) */
|
||||||
#pragma loop unroll
|
#pragma loop unroll
|
||||||
@@ -580,7 +574,6 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#pragma xta endpoint "deliver_return"
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user