Use i_sync for sync signal to CS2100 interface when AUDIO_IO_TILE != PLL_REF_TILE and S/PDIF Rx is enabled.

This commit is contained in:
xross
2022-06-27 19:15:56 +01:00
parent f3a149076b
commit 3e0f127b92
3 changed files with 82 additions and 18 deletions

View File

@@ -40,10 +40,10 @@ static int clockInt[NUM_CLOCKS]; /* Interupt flag for
static int clockId[NUM_CLOCKS]; static int clockId[NUM_CLOCKS];
[[combinable]] [[combinable]]
void PllRefPinTask(server interface sync_if i_sync, out port p_sync) void PllRefPinTask(server interface sync_if i_sync, out port p_pll_ref)
{ {
static unsigned pinVal= 0; static unsigned pinVal= 0;
p_sync <: pinVal; static unsigned short pinTime = 0;
while(1) while(1)
{ {
@@ -51,7 +51,30 @@ void PllRefPinTask(server interface sync_if i_sync, out port p_sync)
{ {
case i_sync.toggle(): case i_sync.toggle():
pinVal = ~pinVal; pinVal = ~pinVal;
p_sync <: pinVal; p_pll_ref <: pinVal;
break;
case i_sync.init():
p_pll_ref <: pinVal @ pinTime;
pinTime += (unsigned short)(LOCAL_CLOCK_INCREMENT - (LOCAL_CLOCK_INCREMENT/2));
p_pll_ref @ pinTime <: pinVal;
break;
case i_sync.toggle_timed(int relative):
if (!relative)
{
pinTime += (short) LOCAL_CLOCK_INCREMENT;
pinVal = !pinVal;
p_pll_ref @ pinTime <: pinVal;
}
else
{
p_pll_ref <: pinVal @ pinTime;
pinTime += (short) LOCAL_CLOCK_INCREMENT;
pinVal = !pinVal;
p_pll_ref @ pinTime <: pinVal;
}
break; break;
} }
} }
@@ -218,12 +241,19 @@ extern int samples_to_host_inputs_buff[NUM_USB_CHAN_IN];
int VendorAudCoreReqs(unsigned cmd, chanend c); int VendorAudCoreReqs(unsigned cmd, chanend c);
#pragma unsafe arrays #pragma unsafe arrays
#if (AUDIO_IO_TILE == PLL_REF_TILE)
void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, out port p, chanend c_dig_rx, chanend c_clk_ctl, chanend c_clk_int) void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, out port p, chanend c_dig_rx, chanend c_clk_ctl, chanend c_clk_int)
#else
void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interface sync_if i_sync, chanend c_dig_rx, chanend c_clk_ctl, chanend c_clk_int)
#endif
{ {
timer t_local; timer t_local;
unsigned timeNextEdge, timeLastEdge, timeNextClockDetection; unsigned timeNextEdge, timeLastEdge, timeNextClockDetection;
#if (AUDIO_IO_TILE == PLL_REF_TILE)
unsigned pinVal = 0; unsigned pinVal = 0;
unsigned short pinTime; unsigned short pinTime;
#endif
unsigned clkMode = CLOCK_INTERNAL; /* Current clocking mode in operation */ unsigned clkMode = CLOCK_INTERNAL; /* Current clocking mode in operation */
unsigned tmp; unsigned tmp;
@@ -325,10 +355,15 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, out port p, ch
outuint(c_dig_rx, 1); outuint(c_dig_rx, 1);
#endif #endif
#if (AUDIO_IO_TILE == PLL_REF_TILE)
/* Initial ref clock output and get timestamp */ /* Initial ref clock output and get timestamp */
p <: pinVal @ pinTime; p <: pinVal @ pinTime;
pinTime += (unsigned short)(LOCAL_CLOCK_INCREMENT - (LOCAL_CLOCK_INCREMENT/2)); pinTime += (unsigned short)(LOCAL_CLOCK_INCREMENT - (LOCAL_CLOCK_INCREMENT/2));
p @ pinTime <: pinVal; p @ pinTime <: pinVal;
#else
/* TODO ideally always use interface */
i_sync.init();
#endif
while(1) while(1)
{ {
@@ -451,11 +486,15 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, out port p, ch
/* Generate local clock from timer */ /* Generate local clock from timer */
case t_local when timerafter(timeNextEdge) :> void: case t_local when timerafter(timeNextEdge) :> void:
#if (AUDIO_IO_TILE == PLL_REF_TILE)
/* Setup next local clock edge */ /* Setup next local clock edge */
pinTime += (short) LOCAL_CLOCK_INCREMENT; pinTime += (short) LOCAL_CLOCK_INCREMENT;
pinVal = !pinVal; pinVal = !pinVal;
p @ pinTime <: pinVal; p @ pinTime <: pinVal;
#else
/* TODO ideally always use interface */
i_sync.toggle_timed(0);
#endif
/* Record time of edge */ /* Record time of edge */
timeLastEdge = timeNextEdge; timeLastEdge = timeNextEdge;
@@ -584,11 +623,16 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, out port p, ch
/* Setup for next edge */ /* Setup for next edge */
timeNextEdge = spdifReceivedTime + LOCAL_CLOCK_INCREMENT + LOCAL_CLOCK_MARGIN; timeNextEdge = spdifReceivedTime + LOCAL_CLOCK_INCREMENT + LOCAL_CLOCK_MARGIN;
#if (AUDIO_IO_TILE == PLL_REF_TILE)
/* Toggle edge */ /* Toggle edge */
p <: pinVal @ pinTime; p <: pinVal @ pinTime;
pinTime += (short) LOCAL_CLOCK_INCREMENT; pinTime += (short) LOCAL_CLOCK_INCREMENT;
pinVal = !pinVal; pinVal = !pinVal;
p @ pinTime <: pinVal; p @ pinTime <: pinVal;
#else
i_sync.toggle_timed(1);
#endif
/* Reset counters */ /* Reset counters */
spdifCounters.receivedSamples = 0; spdifCounters.receivedSamples = 0;
@@ -693,12 +737,15 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, out port p, ch
/* Setup for next edge */ /* Setup for next edge */
timeNextEdge = adatReceivedTime + LOCAL_CLOCK_INCREMENT + LOCAL_CLOCK_MARGIN; timeNextEdge = adatReceivedTime + LOCAL_CLOCK_INCREMENT + LOCAL_CLOCK_MARGIN;
#if (AUDIO_IO_TILE == PLL_REF_TILE)
/* Toggle edge */ /* Toggle edge */
p <: pinVal @ pinTime; p <: pinVal @ pinTime;
pinTime += LOCAL_CLOCK_INCREMENT; pinTime += LOCAL_CLOCK_INCREMENT;
pinVal = !pinVal; pinVal = !pinVal;
p @ pinTime <: pinVal; p @ pinTime <: pinVal;
#else
i_sync.toggle_timed(1);
#endif
/* Reset counters */ /* Reset counters */
adatCounters.receivedSamples = 0; adatCounters.receivedSamples = 0;

View File

@@ -4,6 +4,18 @@
#ifndef _CLOCKING_H_ #ifndef _CLOCKING_H_
#define _CLOCKING_H_ #define _CLOCKING_H_
interface sync_if
{
void toggle();
void init();
void toggle_timed(int relative);
};
[[combinable]]
void PllRefPinTask(server interface sync_if i_sync, out port p_sync);
/** Clock generation and digital audio I/O handling. /** Clock generation and digital audio I/O handling.
* *
* \param c_spdif_rx channel connected to S/PDIF receive thread * \param c_spdif_rx channel connected to S/PDIF receive thread
@@ -15,14 +27,10 @@
* \param c_clk_int channel connected to the decouple() thread for clock * \param c_clk_int channel connected to the decouple() thread for clock
interrupts interrupts
*/ */
void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, out port p, chanend c_audio, chanend c_clk_ctl, chanend c_clk_int); #if (AUDIO_IO_TILE == PLL_REF_TILE)
void clockGen(streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interface out port p_pll_ref, chanend c_audio, chanend c_clk_ctl, chanend c_clk_int);
interface sync_if #else
{ void clockGen(streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interface sync_if i_sync, chanend c_audio, chanend c_clk_ctl, chanend c_clk_int);
void toggle(); #endif
};
[[combinable]]
void PllRefPinTask(server interface sync_if i_sync, out port p_sync);
#endif #endif

View File

@@ -432,6 +432,9 @@ void usb_audio_io(chanend ?c_aud_in,
#endif #endif
, chanend c_pdm_pcm , chanend c_pdm_pcm
#endif #endif
#if (XUA_SPDIF_RX_EN && (AUDIO_IO_TILE != PLL_REF_TILE))
, client interface sync_if i_sync
#endif
) )
{ {
#ifdef MIXER #ifdef MIXER
@@ -503,9 +506,13 @@ void usb_audio_io(chanend ?c_aud_in,
#if (XUA_SPDIF_RX_EN || ADAT_RX) #if (XUA_SPDIF_RX_EN || ADAT_RX)
{ {
/* ClockGen must currently run on same tile as AudioHub due to shared memory buffer */
thread_speed(); thread_speed();
#if AUDIO_IO_TILE == PLL_REF_TILE
clockGen(c_spdif_rx, c_adat_rx, p_pll_ref, c_dig_rx, c_clk_ctl, c_clk_int); clockGen(c_spdif_rx, c_adat_rx, p_pll_ref, c_dig_rx, c_clk_ctl, c_clk_int);
#else
clockGen(c_spdif_rx, c_adat_rx, i_sync, c_dig_rx, c_clk_ctl, c_clk_int);
#endif
} }
#endif #endif
@@ -583,7 +590,7 @@ int main()
#endif #endif
#endif #endif
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) #if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) || (XUA_SPDIF_RX_EN && (AUDIO_IO_TILE != PLL_REF_TILE))
interface sync_if i_sync; interface sync_if i_sync;
#endif #endif
@@ -593,9 +600,8 @@ int main()
{ {
USER_MAIN_CORES USER_MAIN_CORES
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) #if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) || (XUA_SPDIF_RX_EN && (AUDIO_IO_TILE != PLL_REF_TILE))
on tile[PLL_REF_TILE]: PllRefPinTask(i_sync, p_pll_ref); on tile[PLL_REF_TILE]: PllRefPinTask(i_sync, p_pll_ref);
#endif #endif
on tile[XUD_TILE]: on tile[XUD_TILE]:
par par
@@ -649,6 +655,9 @@ int main()
, c_ds_output , c_ds_output
#endif #endif
, c_pdm_pcm , c_pdm_pcm
#endif
#if (XUA_SPDIF_RX_EN && (AUDIO_IO_TILE != PLL_REF_TILE))
, i_sync
#endif #endif
); );
} }