From 11ae3ae68040b2e058281a640c1041bfd11eab73 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Mon, 7 Jul 2014 12:39:39 +0100 Subject: [PATCH 01/23] Adding SPDIF in to main (note, currently has build issues) --- module_usb_audio/main.xc | 48 ++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/module_usb_audio/main.xc b/module_usb_audio/main.xc index 5559f4ad..7c5315ec 100755 --- a/module_usb_audio/main.xc +++ b/module_usb_audio/main.xc @@ -32,6 +32,11 @@ #include "mixer.h" #endif +#ifdef SPDIF_RX +#include "SpdifReceive.h" +#endif + + /* Audio I/O - Port declarations */ #if I2S_WIRES_DAC > 0 on tile[AUDIO_IO_TILE] : buffered out port:32 p_i2s_dac[I2S_WIRES_DAC] = @@ -98,11 +103,13 @@ on tile[AUDIO_IO_TILE] : buffered in port:32 p_i2s_adc[I2S_WIRES_ADC] = * This is a clash with S/PDIF Tx but simultaneous S/PDIF and MIDI not currently supported on single tile device * */ +/* TODO should include tile here */ #define CLKBLK_MIDI XS1_CLKBLK_1; #else #define CLKBLK_MIDI XS1_CLKBLK_REF; #endif #define CLKBLK_SPDIF_TX XS1_CLKBLK_1 +#define CLKBLK_SPDIF_RX XS1_CLKBLK_1 #define CLKBLK_MCLK XS1_CLKBLK_2 #define CLKBLK_I2S_BIT XS1_CLKBLK_3 #define CLKBLK_XUD XS1_CLKBLK_4 /* Note XUD for U-series uses CLKBLK_5 also (see XUD_Ports.xc) */ @@ -122,6 +129,10 @@ on tile[XUD_TILE] : in port p_for_mclk_count = PORT_MCLK_COUNT; on tile[AUDIO_IO_TILE] : buffered out port:32 p_spdif_tx = PORT_SPDIF_OUT; #endif +#ifdef SPDIF_RX +on tile[XUD_TILE] : buffered in port:4 p_spdif_rx = PORT_SPDIF_IN; /* K: coax, J: optical */ +#endif + #ifdef MIDI on tile[AUDIO_IO_TILE] : port p_midi_tx = PORT_MIDI_OUT; @@ -141,6 +152,10 @@ on tile[AUDIO_IO_TILE] : clock clk_midi = CLKBLK_MIDI; on tile[AUDIO_IO_TILE] : clock clk_mst_spd = CLKBLK_SPDIF_TX; #endif +#ifdef SPDIF_RX +on tile[XUD_TILE] : clock clk_spd_rx = CLKBLK_SPDIF_RX; +#endif + on tile[AUDIO_IO_TILE] : clock clk_audio_mclk = CLKBLK_MCLK; /* Master clock */ #if(AUDIO_IO_TILE != XUD_TILE) @@ -225,7 +240,7 @@ void xscope_user_init() #endif #ifdef SELF_POWERED -#define pwrConfig XUD_PWR_SELF +#define pwrConfig XUD_PWR_BUS #else #define pwrConfig XUD_PWR_BUS #endif @@ -341,21 +356,23 @@ void usb_audio_io(chanend c_aud_in, chanend ?c_adc , chanend c_mix_ctl #endif , chanend ?c_aud_cfg + +#ifdef SPDIF_RX +, chanend ?c_dig_rx +#endif ) { #ifdef MIXER chan c_mix_out; #endif -#if defined (SPDIF_RX) || (defined ADAT_RX) - chan c_dig_rx; -#else -#define c_dig_rx null -#endif - par { +#ifdef SPDIF_RX + +#endif + #ifdef MIXER /* Mixer cores(s) */ { @@ -410,6 +427,14 @@ int main() #define c_aud_cfg null #endif +#ifdef SPDIF_RX + chan c_dig_rx; + streaming chan c_spdif_rx; +#else +#define c_dig_rx null +#endif + + USER_MAIN_DECLARATIONS par @@ -431,6 +456,8 @@ int main() , c_mix_ctl #endif , c_aud_cfg + + , c_dig_rx ); #if defined(MIDI) && defined(IAP) && (IAP_TILE == MIDI_TILE) @@ -458,6 +485,13 @@ int main() #endif #endif +#ifdef SPDIF_RX + on tile[0]: + { + thread_speed(); + SpdifReceive(p_spdif_rx, c_spdif_rx, 1, clk_spd_rx); + } +#endif USER_MAIN_CORES } From 97987767b27ea2b263e29da1b6d8190406433d5e Mon Sep 17 00:00:00 2001 From: ed-xmos Date: Wed, 9 Jul 2014 14:55:08 +0100 Subject: [PATCH 02/23] Fix to ensure port clocking clock block is 0 to avoid lockup on DSD->PCM mode --- module_usb_audio/ports/audioports.xc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/module_usb_audio/ports/audioports.xc b/module_usb_audio/ports/audioports.xc index 28e0a77a..147da417 100644 --- a/module_usb_audio/ports/audioports.xc +++ b/module_usb_audio/ports/audioports.xc @@ -35,6 +35,18 @@ unsigned int divide) /* Note this call to stop_clock() will pause forever if the port clocking the clock-block is not low. * deliver() should return with this being the case */ + /* get the port id of the clock block source and set it to zero */ + { + unsigned clockResId; + unsigned portResId; + asm("add %0, %1, %2": "=r"(clockResId):"r"(clk_audio_bclk), "r"(0)); + portResId = getps(clockResId | (XS1_RES_PS_CLKSRC << 4) ); + if(portResId != 1) + asm("out res[%0], %1":: "r"(portResId), "r"(0)); + } + + + stop_clock(clk_audio_bclk); if(!isnull(p_lrclk)) From 4d4c7b8f39f48efbdff5156eb17639a65596479a Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Mon, 14 Jul 2014 14:51:13 +0100 Subject: [PATCH 03/23] DSD ports now only enabled once - avoids issue with stop_clock and un-driven clock. ConfigAudioPortsWrapper() also simplified. --- module_usb_audio/audio.xc | 44 ++++++++++++------- module_usb_audio/ports/audioports.c | 66 ++++------------------------ module_usb_audio/ports/audioports.h | 27 +++++------- module_usb_audio/ports/audioports.xc | 1 - 4 files changed, 47 insertions(+), 91 deletions(-) diff --git a/module_usb_audio/audio.xc b/module_usb_audio/audio.xc index 116f83bd..d9f84bb0 100755 --- a/module_usb_audio/audio.xc +++ b/module_usb_audio/audio.xc @@ -26,8 +26,8 @@ unsigned testsamples[100]; int p = 0; unsigned lastSample = 0; #if (DSD_CHANS_DAC != 0) -extern unsigned p_dsd_dac[DSD_CHANS_DAC]; -extern port p_dsd_clk; +extern buffered out port:32 p_dsd_dac[DSD_CHANS_DAC]; +extern buffered out port:32 p_dsd_clk; #endif unsigned g_adcVal = 0; @@ -832,6 +832,15 @@ void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config, chanend ?c) start_clock(clk_audio_mclk); +#if (DSD_CHANS_DAC > 0) + /* Make sure the DSD ports are on and buffered - just in case they are not shared with I2S */ + EnableBufferedPort(p_dsd_clk, 32); + for(int i = 0; i< DSD_CHANS_DAC; i++) + { + EnableBufferedPort(p_dsd_dac[i], 32); + } +#endif + #ifdef SPDIF SpdifTransmitPortConfig(p_spdif_tx, clk_mst_spd, p_mclk_in); #endif @@ -872,28 +881,31 @@ void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config, chanend ?c) divide = mClk / ( curSamFreq * numBits ); } -#if (DSD_CHANS_DAC != 0) + +#if (DSD_CHANS_DAC > 0) + if(dsdMode) + { /* Configure audio ports */ ConfigAudioPortsWrapper( #if (I2S_CHANS_DAC != 0) - p_i2s_dac, + p_dsd_dac, + DSD_CHANS_DAC, #endif #if (I2S_CHANS_ADC != 0) p_i2s_adc, + I2S_WIRES_ADC, #endif #if (I2S_CHANS_DAC != 0) || (I2S_CHANS_ADC != 0) -#ifndef CODEC_MASTER - p_lrclk, - p_bclk, -#else - p_lrclk, - p_bclk, + null, + p_dsd_clk, #endif + divide, dsdMode); + } + else #endif - divide, dsdMode); -#else - /* Configure audio ports */ - ConfigAudioPorts( + { + + ConfigAudioPortsWrapper( #if (I2S_CHANS_DAC != 0) p_i2s_dac, I2S_WIRES_DAC, @@ -911,9 +923,9 @@ void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config, chanend ?c) p_bclk, #endif #endif - divide); + divide, dsdMode); +} -#endif { unsigned curFreq = curSamFreq; diff --git a/module_usb_audio/ports/audioports.c b/module_usb_audio/ports/audioports.c index 9014fac0..c8fd8089 100644 --- a/module_usb_audio/ports/audioports.c +++ b/module_usb_audio/ports/audioports.c @@ -6,7 +6,6 @@ #include "devicedefines.h" #include "audioports.h" -#if (DSD_CHANS_DAC != 0) /* Note since DSD ports could be reused for I2S ports we do all the setup manually in C */ #if DSD_CHANS_DAC > 0 port p_dsd_dac[DSD_CHANS_DAC] = { @@ -23,23 +22,21 @@ port p_dsd_dac[DSD_CHANS_DAC] = { port p_dsd_clk = PORT_DSD_CLK; #endif -static inline void EnableBufferedPort(port p, unsigned transferWidth) +void EnableBufferedPort(port p, unsigned transferWidth) { - //set_port_use_on(p_dsd_dac[i]); asm volatile("setc res[%0], %1"::"r"(p), "r"(XS1_SETC_INUSE_ON)); asm volatile("setc res[%0], %1"::"r"(p), "r"(XS1_SETC_BUF_BUFFERS)); asm volatile("settw res[%0], %1"::"r"(p),"r"(transferWidth)); } - -/* C wrapper for ConfigAudioPorts() such that we can mess around with arrays of ports */ +/* C wrapper for ConfigAudioPorts() to handle DSD ports */ void ConfigAudioPortsWrapper( #if (I2S_CHANS_DAC != 0) - port p_i2s_dac[I2S_WIRES_DAC], + port p_dac[], int numPortsDac, #endif #if (I2S_CHANS_ADC != 0) - port p_i2s_adc[I2S_WIRES_ADC], + port p_adc[], int numPortsAdc, #endif #if (I2S_CHANS_DAC != 0) || (I2S_CHANS_ADC != 0) @@ -53,63 +50,16 @@ void ConfigAudioPortsWrapper( #endif unsigned int divide, unsigned int dsdMode) { - /* Ensure dsd clock is on in all modes since I2S mode sets it low on exit - * to avoid stop_clock() potentially pausing forever. If this is not done - * an exception will be raised with audio() attempts to set this port low - */ - /* TODO Do we really need to do this on every SF change? Once is probably enough */ - EnableBufferedPort(p_dsd_clk, 32); - - if(dsdMode) - { - /* Make sure the ports are on and buffered - just in case they are not shared with I2S */ - for(int i = 0; i< DSD_CHANS_DAC; i++) - { - EnableBufferedPort(p_dsd_dac[i], 32); - } - - ConfigAudioPorts( -#if (DSD_CHANS_DAC != 0) - p_dsd_dac, - DSD_CHANS_DAC, -#endif -#if (I2S_CHANS_ADC != 0) - p_i2s_adc, - I2S_WIRES_ADC, -#endif -#if (I2S_CHANS_DAC != 0) || (I2S_CHANS_ADC != 0) -#ifndef CODEC_MASTER - 0, /* NULL */ - p_dsd_clk, -#else - 0, /* NULL */ - p_dsd_clk, -#endif -#endif - divide); - - } - else - { ConfigAudioPorts( #if (I2S_CHANS_DAC != 0) - p_i2s_dac, - I2S_WIRES_DAC, + p_dac, + numPortsDac, #endif #if (I2S_CHANS_ADC != 0) - p_i2s_adc, - I2S_WIRES_ADC, + p_adc, + numPortsAdc, #endif -#if (I2S_CHANS_DAC != 0) || (I2S_CHANS_ADC != 0) -#ifndef CODEC_MASTER p_lrclk, p_bclk, -#else - p_lrclk, - p_bclk, -#endif -#endif divide); - } } -#endif diff --git a/module_usb_audio/ports/audioports.h b/module_usb_audio/ports/audioports.h index 3933b11b..f3c60bbe 100644 --- a/module_usb_audio/ports/audioports.h +++ b/module_usb_audio/ports/audioports.h @@ -4,9 +4,6 @@ #include #include "devicedefines.h" -void ConfigAudioPorts_dsd(unsigned int divide); - - #ifdef __XC__ void ConfigAudioPorts( #if (I2S_CHANS_DAC != 0) || (DSD_CHANS_DAC != 0) @@ -61,19 +58,19 @@ void ConfigAudioPorts( #ifdef __XC__ void ConfigAudioPortsWrapper( #if (I2S_CHANS_DAC != 0) - buffered out port:32 p_i2s_dac[I2S_WIRES_DAC], + buffered out port:32 p_i2s_dac[], int numPortsDAC, #endif #if (I2S_CHANS_ADC != 0) - buffered in port:32 p_i2s_adc[I2S_WIRES_ADC], + buffered in port:32 p_i2s_adc[], int numPortsADC, #endif #if (I2S_CHANS_DAC != 0) || (I2S_CHANS_ADC != 0) #ifndef CODEC_MASTER - buffered out port:32 p_lrclk, + buffered out port:32 ?p_lrclk, buffered out port:32 p_bclk, #else - in port p_lrclk, + in port ?p_lrclk, in port p_bclk, #endif #endif @@ -82,28 +79,26 @@ void ConfigAudioPortsWrapper( void ConfigAudioPortsWrapper( #if (I2S_CHANS_DAC != 0) - port p_i2s_dac[I2S_WIRES_DAC], + port p_i2s_dac[], int numPortsDAC, #endif #if (I2S_CHANS_ADC != 0) - port p_i2s_adc[I2S_WIRES_ADC], + port p_i2s_adc[], int numPortsADC, #endif #if (I2S_CHANS_DAC != 0) || (I2S_CHANS_ADC != 0) -#ifndef CODEC_MASTER port p_lrclk, port p_bclk, -#else - port p_lrclk, - port p_bclk, -#endif #endif unsigned int divide, unsigned int dsdMode); #endif /* __XC__*/ - - +#ifdef __XC__ +void EnableBufferedPort(buffered out port:32 p, unsigned transferWidth); +#else +void EnableBufferedPort(port p, unsigned transferWidth); +#endif #endif /* _AUDIOPORTS_H_ */ diff --git a/module_usb_audio/ports/audioports.xc b/module_usb_audio/ports/audioports.xc index 28e0a77a..66f77641 100644 --- a/module_usb_audio/ports/audioports.xc +++ b/module_usb_audio/ports/audioports.xc @@ -34,7 +34,6 @@ unsigned int divide) #ifndef CODEC_MASTER /* Note this call to stop_clock() will pause forever if the port clocking the clock-block is not low. * deliver() should return with this being the case */ - stop_clock(clk_audio_bclk); if(!isnull(p_lrclk)) From 544ef6e0648972bd0fae051db79372b73e2a1fbb Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Tue, 15 Jul 2014 12:08:39 +0100 Subject: [PATCH 04/23] Added 6.6.1 to changelog --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d8ca1e43..22ff07f2 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,7 +1,7 @@ sc_usb_audio Change Log ======================= -6.6.0 +6.6.1 ----- * see sw_usb_audio for changelog From e4e4631eab5dce4db5be20aed26e18781a71cbbb Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Tue, 15 Jul 2014 12:12:23 +0100 Subject: [PATCH 05/23] xpd: Patched version number --- module_dfu/.cproject | 18 +++--------------- module_usb_audio/devicedefines.h | 2 +- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/module_dfu/.cproject b/module_dfu/.cproject index bb778c83..da068095 100644 --- a/module_dfu/.cproject +++ b/module_dfu/.cproject @@ -156,11 +156,7 @@