This commit is contained in:
Ross Owen
2015-03-17 11:50:02 +00:00
14 changed files with 238 additions and 74 deletions

View File

@@ -75,6 +75,7 @@ unsigned dsdMode = DSD_MODE_OFF;
/* Master clock input */
extern port p_mclk_in;
extern in port p_mclk_in2;
#ifdef SPDIF
extern buffered out port:32 p_spdif_tx;
@@ -172,7 +173,7 @@ static inline void TransferAdatTxSamples(chanend c_adat_out, const unsigned samp
unsafe
{
unsigned * unsafe samplesFromHostAdat = &samplesFromHost[ADAT_TX_INDEX];
/* Note, when smux == 1 this loop just does a straight 1:1 copy */
//if(smux != 1)
{
@@ -181,31 +182,31 @@ static inline void TransferAdatTxSamples(chanend c_adat_out, const unsigned samp
{
adatSamples[adatSampleIndex] = samplesFromHostAdat[i];
adatSampleIndex += smux;
}
}
}
}
adatCounter++;
if(adatCounter == smux)
{
#ifdef ADAT_TX_USE_SHARED_BUFF
unsafe
{
/* Wait for ADAT core to be done with buffer */
{
/* Wait for ADAT core to be done with buffer */
/* Note, we are "running ahead" of the ADAT core */
inuint(c_adat_out);
/* Send buffer pointer over to ADAT core */
volatile unsigned * unsafe samplePtr = &adatSamples;
outuint(c_adat_out, (unsigned) samplePtr);
outuint(c_adat_out, (unsigned) samplePtr);
}
#else
#else
#pragma loop unroll
for (int i = 0; i < 8; i++)
{
outuint(c_adat_out, samplesFromHost[ADAT_TX_INDEX + i]);
outuint(c_adat_out, samplesFromHost[ADAT_TX_INDEX + i]);
}
#endif
adatCounter = 0;
@@ -368,11 +369,10 @@ static inline void InitPorts(unsigned divide)
p_lrclk @ tmp <: 0x7FFFFFFF;
#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));
asm("setpt res[%0], %1"::"r"(p_i2s_adc[i]),"r"(tmp+31));
}
#endif
}
@@ -411,8 +411,8 @@ static inline void InitPorts(unsigned divide)
p_lrclk when pinseq(1) :> void @ tmp;
#else
p_lrclk when pinseq(0) :> void @ tmp;
#endif
#endif
tmp += (I2S_CHANS_PER_FRAME * 32) - 32 + 1 ;
/* E.g. 2 * 32 - 32 + 1 = 33 for stereo */
/* E..g 8 * 32 - 32 + 1 = 225 for 8 chan TDM */
@@ -439,10 +439,10 @@ static inline void InitPorts(unsigned divide)
/* I2S delivery thread */
#pragma unsafe arrays
unsigned static deliver(chanend c_out, chanend ?c_spd_out,
unsigned static deliver(chanend c_out, chanend ?c_spd_out,
#ifdef ADAT_TX
chanend c_adat_out,
unsigned adatSmuxMode,
unsigned adatSmuxMode,
#endif
unsigned divide, unsigned curSamFreq,
#if(defined(SPDIF_RX) || defined(ADAT_RX))
@@ -495,17 +495,17 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out,
unsigned command = DoSampleTransfer(c_out, readBuffNo, underflowWord);
#ifdef ADAT_TX
unsafe{
unsafe{
//TransferAdatTxSamples(c_adat_out, samplesOut, adatSmuxMode, 0);
volatile unsigned * unsafe samplePtr = &samplesOut[ADAT_TX_INDEX];
outuint(c_adat_out, (unsigned) samplePtr);
outuint(c_adat_out, (unsigned) samplePtr);
}
#endif
#endif
if(command)
{
return command;
}
InitPorts(divide);
/* TODO In master mode, the i/o loop assumes L/RCLK = 32bit clocks. We should check this every interation
@@ -650,14 +650,14 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out,
/* Clock out the LR Clock, the DAC data and Clock in the next sample into ADC */
doI2SClocks(divide);
#endif
#if (I2S_CHANS_ADC != 0)
/* Input previous L sample into L in buffer */
index = 0;
/* First input (i.e. frameCoint == 0) we read last ADC channel of previous frame.. */
/* First input (i.e. frameCount == 0) we read last ADC channel of previous frame.. */
unsigned buffIndex = frameCount ? !readBuffNo : readBuffNo;
#pragma loop unroll
@@ -675,10 +675,10 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out,
samplesIn_0[((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i] = bitrev(sample); // channels 1, 3, 5.. on each line.
}
#endif
#ifdef ADAT_TX
#ifdef ADAT_TX
TransferAdatTxSamples(c_adat_out, samplesOut, adatSmuxMode, 1);
#endif
#endif
if(frameCount == 0)
{
@@ -741,7 +741,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out,
#ifndef CODEC_MASTER
doI2SClocks(divide);
#endif
#if (I2S_CHANS_ADC != 0)
index = 0;
/* Channels 0, 2, 4.. on each line */
@@ -843,6 +843,33 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out,
return 0;
}
#ifdef SPDIF
void SpdifTxWrapper(chanend c_spdif_tx)
{
unsigned portId;
#if SPDIF_TX_TILE == AUDIO_IO_TILE
SpdifTransmitPortConfig(p_spdif_tx, clk_mst_spd, p_mclk_in);
#error
#else
//configure_clock_src(clk, p_mclk);
// TODO could share clock block here..
asm("ldw %0, dp[p_mclk_in2]":"=r"(portId));
asm("setclk res[%0], %1"::"r"(clk_mst_spd), "r"(portId));
configure_out_port_no_ready(p_spdif_tx, clk_mst_spd, 0);
set_clock_fall_delay(clk_mst_spd, 7);
start_clock(clk_mst_spd);
#endif
while(1)
{
SpdifTransmit(p_spdif_tx, c_spdif_tx);
}
}
#endif
/* This function is a dummy version of the deliver thread that does not
connect to the codec ports. It is used during DFU reset. */
unsigned static dummy_deliver(chanend c_out)
@@ -896,17 +923,21 @@ unsigned static dummy_deliver(chanend c_out)
#define SAMPLES_PER_PRINT 1
void audio(chanend c_mix_out,
#if SPDIF
chanend c_spdif_out,
#endif
#if (defined(ADAT_RX) || defined(SPDIF_RX))
chanend c_dig_rx,
#endif
chanend ?c_config, chanend ?c)
{
#ifdef SPDIF
chan c_spdif_out;
#endif
//#ifdef SPDIF
// chan c_spdif_out;
//endif
#ifdef ADAT_TX
chan c_adat_out;
unsigned adatSmuxMode = 0;
unsigned adatMultiple = 0;
#endif
unsigned curSamFreq = DEFAULT_FREQ;
@@ -963,17 +994,20 @@ chanend ?c_config, chanend ?c)
EnableBufferedPort(p_dsd_dac[i], 32);
}
#endif
/* Configure ADAT/SPDIF tx ports */
#ifdef SPDIF
SpdifTransmitPortConfig(p_spdif_tx, clk_mst_spd, p_mclk_in);
#endif
#ifdef ADAT_TX
/* Share SPDIF clk blk */
configure_clock_src(clk_mst_spd, p_mclk_in);
configure_out_port_no_ready(p_adat_tx, clk_mst_spd, 0);
set_clock_fall_delay(clk_mst_spd, 7);
#ifndef SPDIF
start_clock(clk_mst_spd);
#endif
#endif
/* Configure ADAT/SPDIF tx ports */
#ifdef SPDIF
//SpdifTransmitPortConfig(p_spdif_tx, clk_mst_spd, p_mclk_in);
#endif
/* Perform required CODEC/ADC/DAC initialisation */
AudioHwInit(c_config);
@@ -984,17 +1018,19 @@ chanend ?c_config, chanend ?c)
if ((MCLK_441 % curSamFreq) == 0)
{
mClk = MCLK_441;
#ifdef ADAT_TX
#ifdef ADAT_TX
/* Calculate ADAT SMUX mode (1, 2, 4) */
adatSmuxMode = curSamFreq / 44100;
adatSmuxMode = curSamFreq / 44100;
adatMultiple = mClk / 44100;
#endif
}
else if ((MCLK_48 % curSamFreq) == 0)
{
mClk = MCLK_48;
#ifdef ADAT_TX
#ifdef ADAT_TX
/* Calculate ADAT SMUX mode (1, 2, 4) */
adatSmuxMode = curSamFreq / 48000;
adatSmuxMode = curSamFreq / 48000;
adatMultiple = mClk / 48000;
#endif
}
@@ -1114,7 +1150,8 @@ chanend ?c_config, chanend ?c)
par
{
#ifdef SPDIF
#if 0
//#ifdef SPDIF
{
set_thread_fast_mode_on();
SpdifTransmit(p_spdif_tx, c_spdif_out);
@@ -1144,7 +1181,7 @@ chanend ?c_config, chanend ?c)
// adatSmuxMode = 1 for FS = 44K1 or 48K0
// = 2 for FS = 88K2 or 96K0
// = 4 for FS = 176K4 or 192K0
outuint(c_adat_out, mClk/curSamFreq);
outuint(c_adat_out, adatMultiple);
outuint(c_adat_out, adatSmuxMode);
#endif
command = deliver(c_mix_out,
@@ -1155,7 +1192,7 @@ chanend ?c_config, chanend ?c)
#endif
#ifdef ADAT_TX
c_adat_out,
adatSmuxMode,
adatSmuxMode,
#endif
divide, curSamFreq,
#if defined (ADAT_RX) || defined (SPDIF_RX)