diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d8ca1e43..e7dae4d2 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,7 +1,7 @@ sc_usb_audio Change Log ======================= -6.6.0 +6.7.0 ----- * see sw_usb_audio for changelog diff --git a/README.rst b/README.rst index 5996e8c0..707f6941 100644 --- a/README.rst +++ b/README.rst @@ -1,7 +1,7 @@ USB Audio Shared ................ -:Latest release: 6.6.0rc2 +:Latest release: 6.7.0alpha0 :Maintainer: xross :Description: USB Audio Shared Components. For use in the XMOS USB Audio Refererence Designs. diff --git a/module_usb_audio/audio.xc b/module_usb_audio/audio.xc index 116f83bd..755ce13e 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; @@ -461,9 +461,8 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, unsigned divide, unsi #endif } -#if 0 - /* TODO - requires clock gen */ #if defined(SPDIF_RX) || defined(ADAT_RX) + /* Sync with clockgen */ inuint(c_dig_rx); #endif #ifdef SPDIF_RX @@ -485,7 +484,6 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, unsigned divide, unsi #if defined(SPDIF_RX) || defined(ADAT_RX) /* Request digital data (with prefill) */ outuint(c_dig_rx, 0); -#endif #endif tmp = 0; @@ -832,6 +830,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 +879,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 +921,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/clocking.h b/module_usb_audio/clocking.h index d5524128..b1b85f57 100644 --- a/module_usb_audio/clocking.h +++ b/module_usb_audio/clocking.h @@ -13,6 +13,6 @@ * \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); +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); #endif diff --git a/module_usb_audio/clocking/clockgen.xc b/module_usb_audio/clocking/clockgen.xc index 41234b48..d2b430eb 100644 --- a/module_usb_audio/clocking/clockgen.xc +++ b/module_usb_audio/clocking/clockgen.xc @@ -200,7 +200,7 @@ extern int samples_to_host_inputs_buff[NUM_USB_CHAN_IN]; /* Audio transmi int VendorAudCoreReqs(unsigned cmd, chanend c); #pragma unsafe arrays -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) { timer t_local; unsigned timeNextEdge, timeLastEdge, timeNextClockDetection; @@ -256,7 +256,6 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan g_digData[i] = 0; } - /* Init clock unit state */ #ifdef SPDIF_RX clockFreq[CLOCK_SPDIF_INDEX] = 0; diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index ffc4b6f8..59234be4 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -386,7 +386,7 @@ * @brief Device firmware version number in Binary Coded Decimal format: 0xJJMN where JJ: major, M: minor, N: sub-minor version number. */ #ifndef BCD_DEVICE_M -#define BCD_DEVICE_M 6 +#define BCD_DEVICE_M 7 #endif /** diff --git a/module_usb_audio/endpoint0/descriptors.h b/module_usb_audio/endpoint0/descriptors.h index e989c8ae..ab8648dd 100644 --- a/module_usb_audio/endpoint0/descriptors.h +++ b/module_usb_audio/endpoint0/descriptors.h @@ -529,7 +529,7 @@ StringDescTable_t g_strTable = #endif /*** INPUT CHANNEL STRINGS ***/ - + #if (NUM_USB_CHAN_IN > 0) #if defined(SPDIF_RX) && (SPDIF_RX_INDEX == 0) #if defined(SPDIF_RX) && (SPDIF_RX_INDEX < I2S_CHANS_ADC) @@ -849,8 +849,8 @@ StringDescTable_t g_strTable = #if (NUM_USB_CHAN_IN > 18) #error NUM_USB_CHAN_IN > 18 -#endif - +#endif + .iAPInterfaceStr = "iAP Interface", }; @@ -1119,6 +1119,9 @@ typedef struct #endif USB_Descriptor_Audio_OutputTerminal_t Audio_In_OutputTerminal; #endif +#if defined (SPDIF_RX) || defined (ADAT_RX) + USB_Descriptor_Endpoint_t Audio_Int_Endpoint; +#endif } __attribute__((packed)) USB_CfgDesc_Audio2_CS_Control_Int; typedef struct @@ -1576,6 +1579,19 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .iTerminal = offsetof(StringDescTable_t, usbOutputTermStr_Audio2)/sizeof(char *) }, #endif + +#if defined(SPDIF_RX) || defined(ADAT_RX) + /* Standard AS Interrupt Endpoint Descriptor (4.8.2.1): */ + .Audio_Int_Endpoint = + { + .bLength = sizeof(USB_Descriptor_Endpoint_t), + .bDescriptorType = USB_DESCTYPE_ENDPOINT, + .bEndpointAddress = ENDPOINT_ADDRESS_IN_INTERRUPT, /* (D7: 0:out, 1:in) */ + .bmAttributes = 0x03, /* (bitmap) */ + .wMaxPacketSize = 6, + .bInterval = 8, + }, +#endif }, /* End of .Audio_CS_Control_Int */ #if (NUM_USB_CHAN_OUT > 0) diff --git a/module_usb_audio/main.xc b/module_usb_audio/main.xc index 6ef44601..4e271583 100755 --- a/module_usb_audio/main.xc +++ b/module_usb_audio/main.xc @@ -32,6 +32,12 @@ #include "mixer.h" #endif +#ifdef SPDIF_RX +#include "SpdifReceive.h" +#include "clocking.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 +104,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,13 +130,18 @@ 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 */ +on tile[AUDIO_IO_TILE] : out port p_pll_clk = PORT_PLL_REF; +#endif + #ifdef MIDI on tile[AUDIO_IO_TILE] : port p_midi_tx = PORT_MIDI_OUT; #if(MIDI_RX_PORT_WIDTH == 4) -on tile[AUDIO_IO_TILE] : buffered in port:4 p_midi_rx = PORT_MIDI_IN; +on tile[AUDIO_IO_TILE] : buffered in port:4 p_midi_rx = PORT_MIDI_IN; #elif(MIDI_RX_PORT_WIDTH == 1) -on tile[AUDIO_IO_TILE] : buffered in port:1 p_midi_rx = PORT_MIDI_IN; +on tile[AUDIO_IO_TILE] : buffered in port:1 p_midi_rx = PORT_MIDI_IN; #endif #endif @@ -141,6 +154,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) @@ -235,6 +252,8 @@ void usb_audio_core(chanend c_mix_out #ifdef MIXER , chanend c_mix_ctl #endif +, chanend ?c_clk_int +, chanend ?c_clk_ctl ) { chan c_sof; @@ -299,6 +318,7 @@ void usb_audio_core(chanend c_mix_out #if defined(SPDIF_RX) || defined(ADAT_RX) /* Audio Interrupt - only used for interrupts on external clock change */ c_xud_in[ENDPOINT_NUMBER_IN_INTERRUPT], + c_clk_int, #endif c_sof, c_aud_ctl, p_for_mclk_count #ifdef HID_CONTROLS @@ -314,13 +334,13 @@ void usb_audio_core(chanend c_mix_out /* Endpoint 0 Core */ { thread_speed(); - Endpoint0( c_xud_out[0], c_xud_in[0], c_aud_ctl, c_mix_ctl, null); + Endpoint0( c_xud_out[0], c_xud_in[0], c_aud_ctl, c_mix_ctl, c_clk_ctl); } /* Decoupling core */ { thread_speed(); - decouple(c_mix_out, null + decouple(c_mix_out #ifdef CHAN_BUFF_CTRL , c_buff_ctrl #endif @@ -330,26 +350,24 @@ void usb_audio_core(chanend c_mix_out } } -void usb_audio_io(chanend c_aud_in, chanend ?c_adc +void usb_audio_io(chanend c_aud_in, chanend ?c_adc, #ifdef MIXER -, chanend c_mix_ctl +chanend c_mix_ctl, #endif -, chanend ?c_aud_cfg +chanend ?c_aud_cfg, +streaming chanend ?c_spdif_rx, +chanend ?c_clk_ctl, +chanend ?c_clk_int ) { #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 MIXER /* Mixer cores(s) */ { @@ -366,6 +384,15 @@ void usb_audio_io(chanend c_aud_in, chanend ?c_adc audio(c_aud_in, c_dig_rx, c_aud_cfg, c_adc); #endif } + +#ifdef SPDIF_RX + { + thread_speed(); + + clockGen(c_spdif_rx, null, p_pll_clk, c_dig_rx, c_clk_ctl, c_clk_int); + + } +#endif //: } } @@ -402,6 +429,17 @@ int main() chan c_aud_cfg; #else #define c_aud_cfg null +#endif + +#ifdef SPDIF_RX + streaming chan c_spdif_rx; + chan c_clk_ctl; + chan c_clk_int; +#else +#define c_dig_rx null +#define c_clk_int null +#define c_clk_ctl null +#define c_spdif_rx null #endif USER_MAIN_DECLARATIONS @@ -418,13 +456,14 @@ int main() #ifdef MIXER , c_mix_ctl #endif + , c_clk_int, c_clk_ctl ); on tile[AUDIO_IO_TILE]: usb_audio_io(c_mix_out, c_adc #ifdef MIXER , c_mix_ctl #endif - , c_aud_cfg + ,c_aud_cfg, c_spdif_rx, c_clk_ctl, c_clk_int ); #if defined(MIDI) && defined(IAP) && (IAP_TILE == MIDI_TILE) @@ -452,6 +491,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 } diff --git a/module_usb_audio/ports/audioports.c b/module_usb_audio/ports/audioports.c index 9014fac0..7daf4df6 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..09e59b35 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)) diff --git a/module_usb_audio/usb_buffer/decouple.h b/module_usb_audio/usb_buffer/decouple.h index 31e1dca7..1e75e3b4 100644 --- a/module_usb_audio/usb_buffer/decouple.h +++ b/module_usb_audio/usb_buffer/decouple.h @@ -6,12 +6,10 @@ * Audio I/O driver. * * \param c_audio_out Channel connected to the audio() or mixer() threads - * \param c_clk_int Optional chanend connected to the clockGen() thread if present */ -void decouple(chanend c_audio_out, - chanend ?c_clk_int +void decouple(chanend c_audio_out #ifdef CHAN_BUFF_CTRL - , chanend c_buff_ctrl + , chanend c_buff_ctrl #endif ); diff --git a/module_usb_audio/usb_buffer/decouple.xc b/module_usb_audio/usb_buffer/decouple.xc index 4ecfd97e..5a44a290 100644 --- a/module_usb_audio/usb_buffer/decouple.xc +++ b/module_usb_audio/usb_buffer/decouple.xc @@ -61,7 +61,6 @@ void GetADCCounts(unsigned samFreq, int &min, int &mid, int &max); /* Globals for EP types */ XUD_ep aud_from_host_usb_ep = 0; XUD_ep aud_to_host_usb_ep = 0; -XUD_ep int_usb_ep = 0; /* Shared global audio buffering variables */ unsigned g_aud_from_host_buffer; @@ -569,43 +568,6 @@ __builtin_unreachable(); } } - -unsigned g_intFlag = 0; - -extern unsigned char g_intData[8]; - -static void check_for_interrupt(chanend ?c_clk_int) { - unsigned tmp; - - select - { - /* Clocking thread wants to produce an interrupt... */ - case inuint_byref(c_clk_int, tmp): - chkct(c_clk_int, XS1_CT_END); - - /* Check if we have interrupt pending */ - /* TODO This means we can loose interrupts */ - if(!g_intFlag) - { - int x; - - g_intFlag = 1; - - g_intData[5] = tmp; - - /* Make request to send to XUD endpoint - response handled in usb_buffer */ - //XUD_SetReady(int_usb_ep, 0); - - //asm("ldaw %0, dp[g_intData]":"=r"(x)); - //XUD_SetReady_In(int_usb_ep, g_intData, 6); - } - - break; - default: - break; - } -} - /* Mark Endpoint (IN) ready with an appropriately sized zero buffer */ static inline void SetupZerosSendBuffer(XUD_ep aud_to_host_usb_ep, unsigned sampFreq, unsigned slotSize) { @@ -636,10 +598,9 @@ static inline void SetupZerosSendBuffer(XUD_ep aud_to_host_usb_ep, unsigned samp unsigned char tmpBuffer[1026]; #pragma unsafe arrays -void decouple(chanend c_mix_out, - chanend ?c_clk_int +void decouple(chanend c_mix_out #ifdef CHAN_BUFF_CTRL - , chanend c_buf_ctrl + , chanend c_buf_ctrl #endif ) { @@ -680,14 +641,6 @@ void decouple(chanend c_mix_out, t = array_to_xc_ptr(inZeroBuff); g_aud_to_host_zeros = t; - /* Init interrupt report */ - g_intData[0] = 0; // Class-specific, caused by interface - g_intData[1] = 1; // attribute: CUR - g_intData[2] = 0; // CN/ MCN - g_intData[3] = 0; // CS - g_intData[4] = 0; // interface - g_intData[5] = 0; // ID of entity causing interrupt - this will get modified - /* Init vol mult tables */ #ifndef OUT_VOLUME_IN_MIXER for (int i = 0; i < NUM_USB_CHAN_OUT + 1; i++) @@ -748,12 +701,6 @@ void decouple(chanend c_mix_out, inuchar(c_buf_ctrl); } #endif - - if (!isnull(c_clk_int)) - { - check_for_interrupt(c_clk_int); - } - { asm("#decouple-default"); diff --git a/module_usb_audio/usb_buffer/usb_buffer.h b/module_usb_audio/usb_buffer/usb_buffer.h index f68600d6..158eb507 100644 --- a/module_usb_audio/usb_buffer/usb_buffer.h +++ b/module_usb_audio/usb_buffer/usb_buffer.h @@ -12,6 +12,7 @@ * \param c_midi_from_host MIDI OUT endpoint channel connected to the XUD * \param c_midi_to_host MIDI IN endpoint channel connected to the XUD * \param c_int Audio clocking interrupt endpoint channel connected to the XUD + * \param c_clk_int Optional chanend connected to the clockGen() thread if present * \param c_sof Start of frame channel connected to the XUD * \param c_aud_ctl Audio control channel connected to Endpoint0() * \param p_off_mclk A port that is clocked of the MCLK input (not the MCLK input itself) @@ -33,7 +34,8 @@ void buffer(chanend c_aud_out, chanend c_iap, #endif #if defined(SPDIF_RX) || defined(ADAT_RX) - chanend? c_int, + chanend ?c_int, + chanend ?c_clk_int, #endif chanend c_sof, chanend c_aud_ctl, diff --git a/module_usb_audio/usb_buffer/usb_buffer.xc b/module_usb_audio/usb_buffer/usb_buffer.xc index d12151a9..b98e5cf7 100644 --- a/module_usb_audio/usb_buffer/usb_buffer.xc +++ b/module_usb_audio/usb_buffer/usb_buffer.xc @@ -38,8 +38,23 @@ extern unsigned int g_curSamFreqMultiplier; unsigned g_speed; unsigned g_freqChange = 0; -/* Interrupt EP data */ -unsigned char g_intData[8]; +#if defined (SPDIF_RX) || defined (ADAT_RX) +/* When digital Rx enabled we enable an interrupt EP to inform host about changes in clock validity */ +/* Interrupt EP report data */ +unsigned char g_intData[8] = +{ + 0, // Class-specific, caused by interface + 1, // attribute: CUR + 0, // CN/ MCN + 0, // CS + 0, // interface + 0, // ID of entity causing interrupt - this will get modified; + 0, // Spare + 0, // Spare +}; + +unsigned g_intFlag = 0; +#endif #if defined (MIDI) || defined(IAP) static inline void swap(xc_ptr &a, xc_ptr &b) @@ -91,7 +106,8 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud chanend c_iap, #endif #if defined(SPDIF_RX) || defined(ADAT_RX) - chanend ?c_int, + chanend ?c_ep_int, + chanend ?c_clk_int, #endif chanend c_sof, chanend c_aud_ctl, @@ -119,7 +135,7 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud #endif #endif #if defined(SPDIF_RX) || defined(ADAT_RX) - XUD_ep ep_int = XUD_InitEp(c_int); + XUD_ep ep_int = XUD_InitEp(c_ep_int); #endif #ifdef HID_CONTROLS @@ -172,9 +188,6 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud int iap_draining_chan = 0; #endif -#if defined(SPDIF_RX) || defined(ADAT_RX) - asm("stw %0, dp[int_usb_ep]"::"r"(ep_int)); -#endif /* Store EP's to globals so that decouple() can access them */ asm("stw %0, dp[aud_from_host_usb_ep]"::"r"(ep_aud_out)); asm("stw %0, dp[aud_to_host_usb_ep]"::"r"(ep_aud_in)); @@ -216,11 +229,27 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud select { #if defined(SPDIF_RX) || defined(ADAT_RX) - /* Interrupt EP, send back interrupt data. Note, request made from decouple */ - case XUD_SetData_Select(c_int, ep_int, result): + /* Clocking thread wants to produce an interrupt... */ + case inuint_byref(c_clk_int, u_tmp): + chkct(c_clk_int, XS1_CT_END); + + /* Check if we have interrupt pending. + * Note, this his means we can loose interrupts... */ + if(!g_intFlag) + { + g_intFlag = 1; + + /* Append Unit ID onto packet */ + g_intData[5] = u_tmp; + + XUD_SetReady_In(ep_int, g_intData, 6); + } + break; + + /* Interrupt EP data sent, clear flag */ + case XUD_SetData_Select(c_ep_int, ep_int, result): { - int sent_ok = 0; - asm("stw %0, dp[g_intFlag]" :: "r" (0) ); + g_intFlag = 0; break; } #endif diff --git a/xpd.xml b/xpd.xml index 5d86c895..1a5dea56 100644 --- a/xpd.xml +++ b/xpd.xml @@ -5,7 +5,7 @@ XMOS USB Audio Reference Designes DFU - + module_xassert UAC2 @@ -20,7 +20,7 @@ - module_queue + module_queue module_xassert MIDI @@ -67,7 +67,10 @@ - + + + + XM-004720-SM XMOS