From bb0dec49238d104927137b1dabb163bc7d4a6828 Mon Sep 17 00:00:00 2001 From: xross Date: Tue, 28 Jun 2022 10:39:01 +0100 Subject: [PATCH] - Renamed i_sync to i_pll_ref. - Always used i_pll_ref interface from clockgen rather than direct port access --- lib_xua/api/xua_buffer.h | 4 +- lib_xua/src/core/buffer/ep/ep_buffer.xc | 8 ++-- lib_xua/src/core/clocking/clockgen.xc | 55 +++++++------------------ lib_xua/src/core/clocking/clocking.h | 16 +++---- lib_xua/src/core/main.xc | 34 +++++++-------- 5 files changed, 41 insertions(+), 76 deletions(-) diff --git a/lib_xua/api/xua_buffer.h b/lib_xua/api/xua_buffer.h index 7be34578..75a90545 100644 --- a/lib_xua/api/xua_buffer.h +++ b/lib_xua/api/xua_buffer.h @@ -51,7 +51,7 @@ void XUA_Buffer( #endif , chanend c_aud #if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) - , client interface sync_if i_sync + , client interface pll_ref_if i_pll_ref #endif ); @@ -81,7 +81,7 @@ void XUA_Buffer_Ep(chanend c_aud_out, , chanend c_buff_ctrl #endif #if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) - , client interface sync_if i_sync + , client interface pll_ref_if i_pll_ref #endif ); diff --git a/lib_xua/src/core/buffer/ep/ep_buffer.xc b/lib_xua/src/core/buffer/ep/ep_buffer.xc index e75b527f..d5d4db32 100644 --- a/lib_xua/src/core/buffer/ep/ep_buffer.xc +++ b/lib_xua/src/core/buffer/ep/ep_buffer.xc @@ -115,7 +115,7 @@ void XUA_Buffer( #endif , chanend c_aud #if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) - , client interface sync_if i_sync + , client interface pll_ref_if i_pll_ref #endif ) { @@ -150,7 +150,7 @@ void XUA_Buffer( , c_buff_ctrl #endif #if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) - , i_sync + , i_pll_ref #endif ); @@ -200,7 +200,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out, , chanend c_buff_ctrl #endif #if XUA_SYNCMODE == XUA_SYNCMODE_SYNC - , client interface sync_if i_sync + , client interface pll_ref_if i_pll_ref #endif ) { @@ -529,7 +529,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out, if (sofCount == framesPerSec) { /* Port is accessed via interface to allow flexibilty with location */ - i_sync.toggle(); + i_pll_ref.toggle(); sofCount = 0; } #else diff --git a/lib_xua/src/core/clocking/clockgen.xc b/lib_xua/src/core/clocking/clockgen.xc index b06a5250..cf3137c7 100644 --- a/lib_xua/src/core/clocking/clockgen.xc +++ b/lib_xua/src/core/clocking/clockgen.xc @@ -39,8 +39,8 @@ static int clockValid[NUM_CLOCKS]; /* Store current val static int clockInt[NUM_CLOCKS]; /* Interupt flag for clocks */ static int clockId[NUM_CLOCKS]; -[[combinable]] -void PllRefPinTask(server interface sync_if i_sync, out port p_pll_ref) +[[distributable]] +void PllRefPinTask(server interface pll_ref_if i_pll_ref, out port p_pll_ref) { static unsigned pinVal= 0; static unsigned short pinTime = 0; @@ -49,18 +49,18 @@ void PllRefPinTask(server interface sync_if i_sync, out port p_pll_ref) { select { - case i_sync.toggle(): + case i_pll_ref.toggle(): pinVal = ~pinVal; p_pll_ref <: pinVal; break; - case i_sync.init(): + case i_pll_ref.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): + case i_pll_ref.toggle_timed(int relative): if (!relative) { @@ -241,10 +241,11 @@ 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) +//#if (AUDIO_IO_TILE == PLL_REF_TILE) +#if 0 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) +void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interface pll_ref_if i_pll_ref, chanend c_dig_rx, chanend c_clk_ctl, chanend c_clk_int) #endif { timer t_local; @@ -355,16 +356,9 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa 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 - + i_pll_ref.init(); + while(1) { select @@ -486,15 +480,8 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa /* 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 + i_pll_ref.toggle_timed(0); /* Record time of edge */ timeLastEdge = timeNextEdge; @@ -623,16 +610,8 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa /* 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 + i_pll_ref.toggle_timed(1); /* Reset counters */ spdifCounters.receivedSamples = 0; @@ -737,15 +716,9 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa /* 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 + i_pll_ref.toggle_timed(1); + /* Reset counters */ adatCounters.receivedSamples = 0; diff --git a/lib_xua/src/core/clocking/clocking.h b/lib_xua/src/core/clocking/clocking.h index d892160d..bde1eb34 100644 --- a/lib_xua/src/core/clocking/clocking.h +++ b/lib_xua/src/core/clocking/clocking.h @@ -4,33 +4,27 @@ #ifndef _CLOCKING_H_ #define _CLOCKING_H_ - - -interface sync_if +interface pll_ref_if { void toggle(); void init(); void toggle_timed(int relative); }; -[[combinable]] -void PllRefPinTask(server interface sync_if i_sync, out port p_sync); +[[distributable]] +void PllRefPinTask(server interface pll_ref_if i_pll_ref, out port p_sync); /** Clock generation and digital audio I/O handling. * * \param c_spdif_rx channel connected to S/PDIF receive thread * \param c_adat_rx channel connect to ADAT receive thread - * \param p port to output clock signal to drive external frequency synthesizer + * \param i_pll_ref interface to taslk that outputs clock signal to drive external frequency synthesizer * \param c_audio channel connected to the audio() thread * \param c_clk_ctl channel connected to Endpoint0() for configuration of the * clock * \param c_clk_int channel connected to the decouple() thread for clock interrupts */ -#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 +void clockGen(streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interface pll_ref_if i_pll_ref, chanend c_audio, chanend c_clk_ctl, chanend c_clk_int); #endif diff --git a/lib_xua/src/core/main.xc b/lib_xua/src/core/main.xc index a3aa94cf..54138154 100755 --- a/lib_xua/src/core/main.xc +++ b/lib_xua/src/core/main.xc @@ -289,7 +289,7 @@ void usb_audio_core(chanend c_mix_out , chanend ?c_clk_ctl , client interface i_dfu ?dfuInterface #if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) - , client interface sync_if i_sync + , client interface pll_ref_if i_pll_ref #endif VENDOR_REQUESTS_PARAMS_DEC_ ) @@ -373,7 +373,7 @@ VENDOR_REQUESTS_PARAMS_DEC_ #endif , c_mix_out #if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) - , i_sync + , i_pll_ref #endif ); //: @@ -432,8 +432,8 @@ 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 +#if (XUA_SPDIF_RX_EN || ADAT_RX) + , client interface pll_ref_if i_pll_ref #endif ) { @@ -506,13 +506,11 @@ 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 */ + /* ClockGen must currently run on same tile as AudioHub due to shared memory buffer + * However, due to the use of an interface the pll reference signal port can be on another tile + */ 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 + clockGen(c_spdif_rx, c_adat_rx, i_pll_ref, c_dig_rx, c_clk_ctl, c_clk_int); } #endif @@ -590,8 +588,8 @@ int main() #endif #endif -#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) || (XUA_SPDIF_RX_EN && (AUDIO_IO_TILE != PLL_REF_TILE)) - interface sync_if i_sync; +#if ((XUA_SYNCMODE == XUA_SYNCMODE_SYNC) || XUA_SPDIF_RX_EN || ADAT_RX) + interface pll_ref_if i_pll_ref; #endif USER_MAIN_DECLARATIONS @@ -600,8 +598,8 @@ int main() { USER_MAIN_CORES -#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); +#if ((XUA_SYNCMODE == XUA_SYNCMODE_SYNC) || XUA_SPDIF_RX_EN || ADAT_RX) + on tile[PLL_REF_TILE]: PllRefPinTask(i_pll_ref, p_pll_ref); #endif on tile[XUD_TILE]: par @@ -629,7 +627,7 @@ int main() #endif , c_clk_int, c_clk_ctl, dfuInterface #if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) - , i_sync + , i_pll_ref #endif VENDOR_REQUESTS_PARAMS_ @@ -656,8 +654,8 @@ int main() #endif , c_pdm_pcm #endif -#if (XUA_SPDIF_RX_EN && (AUDIO_IO_TILE != PLL_REF_TILE)) - , i_sync +#if (XUA_SPDIF_RX_EN || ADAT_RX) + , i_pll_ref #endif ); } @@ -720,7 +718,7 @@ int main() #if XUA_USB_EN #if (XUD_TILE != 0 ) && (AUDIO_IO_TILE != 0) && (XUA_DFU_EN == 1) /* Run flash code on its own - hope it gets combined */ -//#warning Running DFU flash code on its own + //#warning Running DFU flash code on its own on stdcore[0]: DFUHandler(dfuInterface, null); #endif #endif