diff --git a/lib_xua/api/xua_audiohub.h b/lib_xua/api/xua_audiohub.h index bf073f99..bac07a99 100644 --- a/lib_xua/api/xua_audiohub.h +++ b/lib_xua/api/xua_audiohub.h @@ -6,7 +6,7 @@ #include "xccompat.h" -#ifndef NO_USB +#if XUA_USB_EN #include "dfu_interface.h" #endif diff --git a/lib_xua/api/xua_conf_default.h b/lib_xua/api/xua_conf_default.h index 93910c33..ae96bb2e 100644 --- a/lib_xua/api/xua_conf_default.h +++ b/lib_xua/api/xua_conf_default.h @@ -56,6 +56,13 @@ #define PDM_TILE AUDIO_IO_TILE #endif +/** + * @brief Disable USB functionalty just leaving AudioHub + */ +#ifndef XUA_USB_EN +#define XUA_USB_EN 1 +#endif + /** * @brief Number of input channels (device to host). Default: NONE (Must be defined by app) */ diff --git a/lib_xua/src/core/audiohub/dsd.h b/lib_xua/src/core/audiohub/dsd.h new file mode 100644 index 00000000..4267597d --- /dev/null +++ b/lib_xua/src/core/audiohub/dsd.h @@ -0,0 +1,95 @@ +#if (DSD_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT > 0) +/* This function performs the DSD native loop and outputs a 32b DSD stream per loop */ +static inline void DoDsdNative(unsigned samplesOut[], unsigned &dsdSample_l, unsigned &dsdSample_r, unsigned divide) +{ + /* 8 bits per chan, 1st 1-bit sample in MSB */ + dsdSample_l = samplesOut[0]; + dsdSample_r = samplesOut[1]; + dsdSample_r = bitrev(byterev(dsdSample_r)); + dsdSample_l = bitrev(byterev(dsdSample_l)); + + asm volatile("out res[%0], %1"::"r"(p_dsd_dac[0]),"r"(dsdSample_l)); + asm volatile("out res[%0], %1"::"r"(p_dsd_dac[1]),"r"(dsdSample_r)); +} + +/* This function performs the DOP loop and collects 16b of DSD per loop + and outputs a 32b word into the port buffer every other cycle. */ +static inline void DoDsdDop(int &everyOther, unsigned samplesOut[], unsigned &dsdSample_l, unsigned &dsdSample_r, unsigned divide) +{ + if(!everyOther) + { + dsdSample_l = ((samplesOut[0] & 0xffff00) << 8); + dsdSample_r = ((samplesOut[1] & 0xffff00) << 8); + everyOther = 1; + } + else + { + everyOther = 0; + dsdSample_l = dsdSample_l | ((samplesOut[0] & 0xffff00) >> 8); + dsdSample_r = dsdSample_r | ((samplesOut[1] & 0xffff00) >> 8); + + asm volatile("out res[%0], %1"::"r"(p_dsd_dac[0]),"r"(bitrev(dsdSample_l))); + asm volatile("out res[%0], %1"::"r"(p_dsd_dac[1]),"r"(bitrev(dsdSample_r))); + } +} + +/* When DSD is enabled and streaming is standard PCM, this function checks for a series of DoP markers in the upper byte. + If found it will exit deliver() with the command to restart in DoP mode. + When in DoP mode, this function will check for a single absence of the DoP marker and exit deliver() with the command + to restart in I2S mode. */ +static inline int DoDsdDopCheck(unsigned &dsdMode, int &dsdCount, unsigned curSamFreq, unsigned samplesOut[], unsigned &dsdMarker) +{ +#if (DSD_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT > 0) + /* Check for DSD - note we only move into DoP mode if valid DoP Freq */ + /* Currently we only check on channel 0 - we get all 0's on channels without data */ + if((dsdMode == DSD_MODE_OFF) && (curSamFreq > 96000)) + { + if((DSD_MASK(samplesOut[0]) == dsdMarker) && (DSD_MASK(samplesOut[1]) == dsdMarker)) + { + dsdCount++; + dsdMarker ^= DSD_MARKER_XOR; + if(dsdCount == DSD_EN_THRESH) + { + dsdMode = DSD_MODE_DOP; + dsdCount = 0; + dsdMarker = DSD_MARKER_2; + +#if (I2S_CHANS_ADC != 0) || (I2S_CHANS_DAC != 0) + // Set clocks low + p_lrclk <: 0; + p_bclk <: 0; +#endif + p_dsd_clk <: 0; + return 0; + } + } + else + { + dsdCount = 0; + dsdMarker = DSD_MARKER_2; + } + } + else if(dsdMode == DSD_MODE_DOP) + { + /* If we are running in DOP mode, check if we need to come out */ + if((DSD_MASK(samplesOut[0]) != DSD_MARKER_1) && (DSD_MASK(samplesOut[1]) != DSD_MARKER_1)) + { + if((DSD_MASK(samplesOut[0]) != DSD_MARKER_2) && (DSD_MASK(samplesOut[1]) != DSD_MARKER_2)) + { + dsdMode = DSD_MODE_OFF; + // Set clocks low +#if (I2S_CHANS_ADC != 0 || I2S_CHANS_DAC != 0) + p_lrclk <: 0; + p_bclk <: 0; +#endif + p_dsd_clk <: 0; + return 0; + } + } + } +#endif + return 1; +} +#endif + + diff --git a/lib_xua/src/core/audiohub/xua_audiohub.xc b/lib_xua/src/core/audiohub/xua_audiohub.xc index 1c67f487..169b0554 100755 --- a/lib_xua/src/core/audiohub/xua_audiohub.xc +++ b/lib_xua/src/core/audiohub/xua_audiohub.xc @@ -91,15 +91,6 @@ extern buffered out port:32 p_adat_tx; extern clock clk_mst_spd; #endif -#define MAX_DIVIDE_48 (MCLK_48/MIN_FREQ_48/64) -#define MAX_DIVIDE_44 (MCLK_44/MIN_FREQ_44/64) -#if (MAX_DIVIDE_44 > MAX_DIVIDE_48) -#define MAX_DIVIDE (MAX_DIVIDE_44) -#else -#define MAX_DIVIDE (MAX_DIVIDE_48) -#endif - - #include "init_ports.h" #ifdef ADAT_TX @@ -156,172 +147,71 @@ static inline void TransferAdatTxSamples(chanend c_adat_out, const unsigned samp } #endif -#ifndef NO_USB #pragma unsafe arrays static inline unsigned DoSampleTransfer(chanend c_out, const int readBuffNo, const unsigned underflowWord) { - outuint(c_out, underflowWord); - /* Check for sample freq change (or other command) or new samples from mixer*/ - if(testct(c_out)) + if(XUA_USB_EN) { - unsigned command = inct(c_out); -#ifndef CODEC_MASTER - if(dsdMode == DSD_MODE_OFF) + outuint(c_out, underflowWord); + + /* Check for sample freq change (or other command) or new samples from mixer*/ + if(testct(c_out)) { + unsigned command = inct(c_out); +#ifndef CODEC_MASTER + if(dsdMode == DSD_MODE_OFF) + { #if (I2S_CHANS_ADC != 0 || I2S_CHANS_DAC != 0) - /* Set clocks low */ - p_lrclk <: 0; - p_bclk <: 0; + /* Set clocks low */ + p_lrclk <: 0; + p_bclk <: 0; #endif + } + else + { +#if(DSD_CHANS_DAC != 0) + /* DSD Clock might not be shared with lrclk or bclk... */ + p_dsd_clk <: 0; +#endif + } +#endif +#if (DSD_CHANS_DAC > 0) + if(dsdMode == DSD_MODE_DOP) + dsdMode = DSD_MODE_OFF; +#endif +#pragma xta endpoint "received_command" + return command; } else { -#if(DSD_CHANS_DAC != 0) - /* DSD Clock might not be shared with lrclk or bclk... */ - p_dsd_clk <: 0; -#endif - } -#endif -#if (DSD_CHANS_DAC > 0) - if(dsdMode == DSD_MODE_DOP) - dsdMode = DSD_MODE_OFF; -#endif -#pragma xta endpoint "received_command" - return command; - } - else - { #if NUM_USB_CHAN_OUT > 0 #pragma loop unroll - for(int i = 0; i < NUM_USB_CHAN_OUT; i++) - { - int tmp = inuint(c_out); - samplesOut[i] = tmp; - } + for(int i = 0; i < NUM_USB_CHAN_OUT; i++) + { + int tmp = inuint(c_out); + samplesOut[i] = tmp; + } #else - inuint(c_out); + inuint(c_out); #endif - UserBufferManagement(samplesOut, samplesIn[readBuffNo]); + UserBufferManagement(samplesOut, samplesIn[readBuffNo]); #if NUM_USB_CHAN_IN > 0 #pragma loop unroll - for(int i = 0; i < NUM_USB_CHAN_IN; i++) - { - outuint(c_out, samplesIn[readBuffNo][i]); - } + for(int i = 0; i < NUM_USB_CHAN_IN; i++) + { + outuint(c_out, samplesIn[readBuffNo][i]); + } #endif + } } + else + UserBufferManagement(samplesOut, samplesIn[readBuffNo]); return 0; } -#else /* NO_USB */ -#pragma unsafe arrays -static inline unsigned DoSampleTransfer(chanend ?c_out, const int readBuffNo, const unsigned underflowWord) -{ - UserBufferManagement(samplesOut, samplesIn[readBuffNo]); - return 0; -} -#endif /* NO_USB */ - - -#if (DSD_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT > 0) -/* This function performs the DSD native loop and outputs a 32b DSD stream per loop */ -static inline void DoDsdNative(unsigned samplesOut[], unsigned &dsdSample_l, unsigned &dsdSample_r, unsigned divide) -{ - /* 8 bits per chan, 1st 1-bit sample in MSB */ - dsdSample_l = samplesOut[0]; - dsdSample_r = samplesOut[1]; - dsdSample_r = bitrev(byterev(dsdSample_r)); - dsdSample_l = bitrev(byterev(dsdSample_l)); - - asm volatile("out res[%0], %1"::"r"(p_dsd_dac[0]),"r"(dsdSample_l)); - asm volatile("out res[%0], %1"::"r"(p_dsd_dac[1]),"r"(dsdSample_r)); -} - -/* This function performs the DOP loop and collects 16b of DSD per loop - and outputs a 32b word into the port buffer every other cycle. */ -static inline void DoDsdDop(int &everyOther, unsigned samplesOut[], unsigned &dsdSample_l, unsigned &dsdSample_r, unsigned divide) -{ - if(!everyOther) - { - dsdSample_l = ((samplesOut[0] & 0xffff00) << 8); - dsdSample_r = ((samplesOut[1] & 0xffff00) << 8); - everyOther = 1; - } - else - { - everyOther = 0; - dsdSample_l = dsdSample_l | ((samplesOut[0] & 0xffff00) >> 8); - dsdSample_r = dsdSample_r | ((samplesOut[1] & 0xffff00) >> 8); - - asm volatile("out res[%0], %1"::"r"(p_dsd_dac[0]),"r"(bitrev(dsdSample_l))); - asm volatile("out res[%0], %1"::"r"(p_dsd_dac[1]),"r"(bitrev(dsdSample_r))); - } -} - -/* When DSD is enabled and streaming is standard PCM, this function checks for a series of DoP markers in the upper byte. - If found it will exit deliver() with the command to restart in DoP mode. - When in DoP mode, this function will check for a single absence of the DoP marker and exit deliver() with the command - to restart in I2S mode. */ -static inline int DoDsdDopCheck(unsigned &dsdMode, int &dsdCount, unsigned curSamFreq, unsigned samplesOut[], unsigned &dsdMarker) -{ -#if (DSD_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT > 0) - /* Check for DSD - note we only move into DoP mode if valid DoP Freq */ - /* Currently we only check on channel 0 - we get all 0's on channels without data */ - if((dsdMode == DSD_MODE_OFF) && (curSamFreq > 96000)) - { - if((DSD_MASK(samplesOut[0]) == dsdMarker) && (DSD_MASK(samplesOut[1]) == dsdMarker)) - { - dsdCount++; - dsdMarker ^= DSD_MARKER_XOR; - if(dsdCount == DSD_EN_THRESH) - { - dsdMode = DSD_MODE_DOP; - dsdCount = 0; - dsdMarker = DSD_MARKER_2; - -#if (I2S_CHANS_ADC != 0 || I2S_CHANS_DAC != 0) - // Set clocks low - p_lrclk <: 0; - p_bclk <: 0; -#endif - p_dsd_clk <: 0; - return 0; - } - } - else - { - dsdCount = 0; - dsdMarker = DSD_MARKER_2; - } - } - else if(dsdMode == DSD_MODE_DOP) - { - /* If we are running in DOP mode, check if we need to come out */ - if((DSD_MASK(samplesOut[0]) != DSD_MARKER_1) && (DSD_MASK(samplesOut[1]) != DSD_MARKER_1)) - { - if((DSD_MASK(samplesOut[0]) != DSD_MARKER_2) && (DSD_MASK(samplesOut[1]) != DSD_MARKER_2)) - { - dsdMode = DSD_MODE_OFF; - // Set clocks low -#if (I2S_CHANS_ADC != 0 || I2S_CHANS_DAC != 0) - p_lrclk <: 0; - p_bclk <: 0; -#endif - p_dsd_clk <: 0; - return 0; - } - } - } -#endif - return 1; -} -#endif - - - #if (CODEC_MASTER == 0) #pragma unsafe arrays @@ -1363,7 +1253,7 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk, } #endif /* Handshake back */ -#ifndef NO_USB +#if (XUA_USB_EN) outct(c_aud, XS1_CT_END); #endif } @@ -1436,7 +1326,7 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk, p_bclk ); -#ifndef NO_USB +#if (XUA_USB_EN) if(command == SET_SAMPLE_FREQ) { curSamFreq = inuint(c_aud) * AUD_TO_USB_RATIO; @@ -1482,7 +1372,7 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk, } #endif -#endif /* NO_USB */ +#endif /* XUA_USB_EN */ #if (XUA_SPDIF_TX_EN) /* Notify S/PDIF task of impending new freq... */ diff --git a/lib_xua/src/core/buffer/decouple/decouple.xc b/lib_xua/src/core/buffer/decouple/decouple.xc index 4e631dfb..f96bc061 100644 --- a/lib_xua/src/core/buffer/decouple/decouple.xc +++ b/lib_xua/src/core/buffer/decouple/decouple.xc @@ -1,5 +1,5 @@ // Copyright (c) 2011-2018, XMOS Ltd, All rights reserved -#ifndef NO_USB +#if XUA_USB_EN #include #include "xua.h" #include "xc_ptr.h" @@ -1031,4 +1031,4 @@ void XUA_Buffer_Decouple(chanend c_mix_out #endif /* NUM_USB_CHAN_IN > 0 */ } } -#endif /* NO_USB */ +#endif /* XUA_USB_EN */ diff --git a/lib_xua/src/core/buffer/decouple/get_adc_counts.c b/lib_xua/src/core/buffer/decouple/get_adc_counts.c index fb11d3ea..e4a6eaef 100644 --- a/lib_xua/src/core/buffer/decouple/get_adc_counts.c +++ b/lib_xua/src/core/buffer/decouple/get_adc_counts.c @@ -1,5 +1,5 @@ // Copyright (c) 2011-2018, XMOS Ltd, All rights reserved -#ifndef NO_USB +#if XUA_USB_EN #include "xud.h" extern XUD_BusSpeed_t g_curUsbSpeed; @@ -50,5 +50,5 @@ void GetADCCounts(unsigned samFreq, int *min, int *mid, int *max) } } -#endif /* NO_USB */ +#endif /* XUA_USB_EN */ diff --git a/lib_xua/src/core/buffer/ep/ep_buffer.xc b/lib_xua/src/core/buffer/ep/ep_buffer.xc index 3d62b794..82923d2e 100644 --- a/lib_xua/src/core/buffer/ep/ep_buffer.xc +++ b/lib_xua/src/core/buffer/ep/ep_buffer.xc @@ -1,5 +1,5 @@ // Copyright (c) 2011-2018, XMOS Ltd, All rights reserved -#ifndef NO_USB +#if XUA_USB_EN #include #include @@ -1097,4 +1097,4 @@ void XUA_Buffer_Ep(register chanend c_aud_out, } } -#endif /* NO_USB */ +#endif /* XUA_USB_EN */ diff --git a/lib_xua/src/core/endpoint0/vendorrequests.c b/lib_xua/src/core/endpoint0/vendorrequests.c index 3346ca70..d3e1132d 100644 --- a/lib_xua/src/core/endpoint0/vendorrequests.c +++ b/lib_xua/src/core/endpoint0/vendorrequests.c @@ -1,5 +1,5 @@ // Copyright (c) 2016-2018, XMOS Ltd, All rights reserved -#ifndef NO_USB +#if XUA_USB_EN #include "xud.h" #include "vendorrequests.h" @@ -32,4 +32,4 @@ void VendorRequests_Init(VENDOR_REQUESTS_PARAMS_DEC) } -#endif /* NO_USB */ +#endif /* XUA_USB_EN */ diff --git a/lib_xua/src/core/endpoint0/xua_endpoint0.c b/lib_xua/src/core/endpoint0/xua_endpoint0.c index 195c027b..443ea44d 100755 --- a/lib_xua/src/core/endpoint0/xua_endpoint0.c +++ b/lib_xua/src/core/endpoint0/xua_endpoint0.c @@ -10,7 +10,7 @@ #include "xua.h" -#ifndef NO_USB +#if XUA_USB_EN #include "xud_device.h" /* Standard descriptor requests */ #include "dfu_types.h" #include "usbaudio20.h" /* Defines from USB Audio 2.0 spec */ @@ -802,4 +802,4 @@ void XUA_Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, } } } -#endif /* NO_USB */ +#endif /* XUA_USB_EN*/ diff --git a/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc b/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc index a70d30c4..b61e4b4d 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc +++ b/lib_xua/src/core/endpoint0/xua_ep0_uacreqs.xc @@ -6,7 +6,7 @@ #include "xua.h" -#ifndef NO_USB +#if XUA_USB_EN #include #include "xud_device.h" #include "usbaudio20.h" diff --git a/lib_xua/src/core/main.xc b/lib_xua/src/core/main.xc index a06b1e67..985ed890 100755 --- a/lib_xua/src/core/main.xc +++ b/lib_xua/src/core/main.xc @@ -17,7 +17,7 @@ #include #endif -#ifndef NO_USB +#if XUA_USB_EN #include "xud_device.h" /* XMOS USB Device Layer defines and functions */ #include "xua_endpoint0.h" #endif @@ -125,7 +125,7 @@ on tile[AUDIO_IO_TILE] : buffered out port:32 p_bclk = PORT_I2S_BCLK; on tile[AUDIO_IO_TILE] : in port p_mclk_in = PORT_MCLK_IN; -#ifndef NO_USB +#if XUA_USB_EN on tile[XUD_TILE] : in port p_for_mclk_count = PORT_MCLK_COUNT; #endif @@ -197,7 +197,7 @@ on tile[XUD_TILE] : clock clk_adat_rx = CLKBLK_ADAT_RX; on tile[AUDIO_IO_TILE] : clock clk_audio_mclk = CLKBLK_MCLK; /* Master clock */ -#if(AUDIO_IO_TILE != XUD_TILE) && !defined(NO_USB) +#if(AUDIO_IO_TILE != XUD_TILE) && XUA_USB_EN /* Separate clock/port for USB feedback calculation */ on tile[XUD_TILE] : clock clk_audio_mclk_usb = CLKBLK_MCLK; /* Master clock */ on tile[XUD_TILE] : in port p_mclk_in_usb = PORT_MCLK_IN_USB; @@ -224,7 +224,7 @@ on tile [IAP_TILE] : struct r_i2c r_i2c = {PORT_I2C_SCL, PORT_I2C_SDA}; #endif #endif -#ifndef NO_USB +#if XUA_USB_EN /* Endpoint type tables for XUD */ XUD_EpType epTypeTableOut[ENDPOINT_COUNT_OUT] = { XUD_EPTYPE_CTL | XUD_STATUS_ENABLE, XUD_EPTYPE_ISO, /* Audio */ @@ -264,7 +264,7 @@ XUD_EpType epTypeTableIn[ENDPOINT_COUNT_IN] = { XUD_EPTYPE_CTL | XUD_STATUS_ENAB #endif #endif }; -#endif /* NO_USB */ +#endif /* XUA_USB_EN */ void thread_speed() { @@ -285,7 +285,7 @@ void xscope_user_init() } #endif -#ifndef NO_USB +#if XUA_USB_EN /* Core USB Audio functions - must be called on the Tile connected to the USB Phy */ void usb_audio_core(chanend c_mix_out #ifdef MIDI @@ -412,7 +412,7 @@ VENDOR_REQUESTS_PARAMS_DEC_ //: } } -#endif /* NO_USB */ +#endif /* XUA_USB_EN */ void usb_audio_io(chanend ?c_aud_in, chanend ?c_adc, #if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE) @@ -512,7 +512,7 @@ void usb_audio_io(chanend ?c_aud_in, chanend ?c_adc, /* Main for USB Audio Applications */ int main() { -#if NO_USB +#if !XUA_USB_EN #define c_mix_out null #else chan c_mix_out; @@ -592,7 +592,7 @@ int main() DFUHandler(dfuInterface, null); #endif #endif -#ifndef NO_USB +#if XUA_USB_EN usb_audio_core(c_mix_out #ifdef MIDI , c_midi @@ -610,7 +610,7 @@ int main() VENDOR_REQUESTS_PARAMS_ ); -#endif /* NO_USB */ +#endif /* XUA_USB_EN */ } on tile[AUDIO_IO_TILE]: @@ -695,7 +695,7 @@ int main() #endif -#ifndef NO_USB +#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 diff --git a/lib_xua/src/core/uac_hwresources.h b/lib_xua/src/core/uac_hwresources.h index 83eda797..2e465aba 100644 --- a/lib_xua/src/core/uac_hwresources.h +++ b/lib_xua/src/core/uac_hwresources.h @@ -3,7 +3,7 @@ #ifndef _UAC_HWRESOURCES_H_ #define _UAC_HWRESOURCES_H_ -#ifndef NO_USB +#if XUA_USB_EN #include "xud.h" /* XMOS USB Device Layer defines and functions */ #endif diff --git a/lib_xua/src/core/warnings.xc b/lib_xua/src/core/warnings.xc index 452a2165..7e071dbf 100644 --- a/lib_xua/src/core/warnings.xc +++ b/lib_xua/src/core/warnings.xc @@ -6,7 +6,7 @@ Warnings relating to configuration defines located in this XC source file rather #include "xua_conf_full.h" -#ifndef NO_USB +#if XUA_USB_EN #ifndef DEFAULT_FREQ #warning DEFAULT_FREQ not defined. Using MIN_FREQ diff --git a/lib_xua/src/core/xuduser/xuduser.c b/lib_xua/src/core/xuduser/xuduser.c index 4393530d..831acc1f 100644 --- a/lib_xua/src/core/xuduser/xuduser.c +++ b/lib_xua/src/core/xuduser/xuduser.c @@ -1,5 +1,5 @@ // Copyright (c) 2013-2018, XMOS Ltd, All rights reserved -#ifndef NO_USB +#if XUA_USB_EN #include "xua.h" #include "hostactive.h" #include "audiostream.h" @@ -23,4 +23,4 @@ void XUD_UserResume(void) UserHostActive(1); } } -#endif /* NO_USB */ +#endif /* XUA_USB_EN*/