diff --git a/lib_xua/src/core/clocking/clockgen.xc b/lib_xua/src/core/clocking/clockgen.xc index c2264738..b06a5250 100644 --- a/lib_xua/src/core/clocking/clockgen.xc +++ b/lib_xua/src/core/clocking/clockgen.xc @@ -40,10 +40,10 @@ static int clockInt[NUM_CLOCKS]; /* Interupt flag for static int clockId[NUM_CLOCKS]; [[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; - p_sync <: pinVal; + static unsigned short pinTime = 0; while(1) { @@ -51,7 +51,30 @@ void PllRefPinTask(server interface sync_if i_sync, out port p_sync) { case i_sync.toggle(): 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; } } @@ -218,12 +241,19 @@ extern int samples_to_host_inputs_buff[NUM_USB_CHAN_IN]; int VendorAudCoreReqs(unsigned cmd, chanend c); #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) +#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; unsigned timeNextEdge, timeLastEdge, timeNextClockDetection; + +#if (AUDIO_IO_TILE == PLL_REF_TILE) unsigned pinVal = 0; unsigned short pinTime; +#endif unsigned clkMode = CLOCK_INTERNAL; /* Current clocking mode in operation */ 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); #endif +#if (AUDIO_IO_TILE == PLL_REF_TILE) /* Initial ref clock output and get timestamp */ p <: pinVal @ pinTime; pinTime += (unsigned short)(LOCAL_CLOCK_INCREMENT - (LOCAL_CLOCK_INCREMENT/2)); p @ pinTime <: pinVal; +#else + /* TODO ideally always use interface */ + i_sync.init(); +#endif 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 */ case t_local when timerafter(timeNextEdge) :> void: - +#if (AUDIO_IO_TILE == PLL_REF_TILE) /* Setup next local clock edge */ pinTime += (short) LOCAL_CLOCK_INCREMENT; pinVal = !pinVal; p @ pinTime <: pinVal; +#else + /* TODO ideally always use interface */ + i_sync.toggle_timed(0); +#endif /* Record time of edge */ 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 */ timeNextEdge = spdifReceivedTime + LOCAL_CLOCK_INCREMENT + LOCAL_CLOCK_MARGIN; +#if (AUDIO_IO_TILE == PLL_REF_TILE) /* Toggle edge */ p <: pinVal @ pinTime; pinTime += (short) LOCAL_CLOCK_INCREMENT; pinVal = !pinVal; p @ pinTime <: pinVal; +#else + i_sync.toggle_timed(1); + +#endif /* Reset counters */ 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 */ timeNextEdge = adatReceivedTime + LOCAL_CLOCK_INCREMENT + LOCAL_CLOCK_MARGIN; +#if (AUDIO_IO_TILE == PLL_REF_TILE) /* Toggle edge */ p <: pinVal @ pinTime; pinTime += LOCAL_CLOCK_INCREMENT; pinVal = !pinVal; p @ pinTime <: pinVal; - +#else + i_sync.toggle_timed(1); +#endif /* Reset counters */ adatCounters.receivedSamples = 0; diff --git a/lib_xua/src/core/clocking/clocking.h b/lib_xua/src/core/clocking/clocking.h index a388f16a..d892160d 100644 --- a/lib_xua/src/core/clocking/clocking.h +++ b/lib_xua/src/core/clocking/clocking.h @@ -4,6 +4,18 @@ #ifndef _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. * * \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 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); - -interface sync_if -{ - void toggle(); -}; - -[[combinable]] -void PllRefPinTask(server interface sync_if i_sync, out port p_sync); +#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); +#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); +#endif #endif diff --git a/lib_xua/src/core/main.xc b/lib_xua/src/core/main.xc index d6264a60..a3aa94cf 100755 --- a/lib_xua/src/core/main.xc +++ b/lib_xua/src/core/main.xc @@ -432,6 +432,9 @@ void usb_audio_io(chanend ?c_aud_in, #endif , chanend c_pdm_pcm #endif +#if (XUA_SPDIF_RX_EN && (AUDIO_IO_TILE != PLL_REF_TILE)) + , client interface sync_if i_sync +#endif ) { #ifdef MIXER @@ -503,9 +506,13 @@ void usb_audio_io(chanend ?c_aud_in, #if (XUA_SPDIF_RX_EN || ADAT_RX) { + /* ClockGen must currently run on same tile as AudioHub due to shared memory buffer */ 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); +#else + clockGen(c_spdif_rx, c_adat_rx, i_sync, c_dig_rx, c_clk_ctl, c_clk_int); +#endif } #endif @@ -583,7 +590,7 @@ int main() #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; #endif @@ -593,9 +600,8 @@ int main() { 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); - #endif on tile[XUD_TILE]: par @@ -649,6 +655,9 @@ int main() , c_ds_output #endif , c_pdm_pcm +#endif +#if (XUA_SPDIF_RX_EN && (AUDIO_IO_TILE != PLL_REF_TILE)) + , i_sync #endif ); }