diff --git a/.gitignore b/.gitignore index a10bd6ad0..979a2930d 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ _build* **/.vscode/** **.egg-info *.pdf +*tests/logs/* # waf build files .lock-waf_* diff --git a/lib_xua/api/xua_buffer.h b/lib_xua/api/xua_buffer.h index 302e3f679..265846cc8 100644 --- a/lib_xua/api/xua_buffer.h +++ b/lib_xua/api/xua_buffer.h @@ -1,4 +1,4 @@ -// Copyright 2011-2021 XMOS LIMITED. +// Copyright 2011-2022 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef __XUA_BUFFER_H__ #define __XUA_BUFFER_H__ @@ -6,6 +6,7 @@ #if __XC__ #include "xua.h" +#include "clocking.h" /** USB Audio Buffering Core. * @@ -38,20 +39,6 @@ void XUA_Buffer( chanend c_midi_to_host, chanend c_midi, #endif -#ifdef IAP - chanend c_iap_from_host, - chanend c_iap_to_host, -#ifdef IAP_INT_EP - chanend c_iap_to_host_int, -#endif - chanend c_iap, -#ifdef IAP_EA_NATIVE_TRANS - chanend c_iap_ea_native_out, - chanend c_iap_ea_native_in, - chanend c_iap_ea_native_ctrl, - chanend c_iap_ea_native_data, -#endif -#endif #if (SPDIF_RX) || (ADAT_RX) chanend ?c_int, chanend ?c_clk_int, @@ -59,10 +46,13 @@ void XUA_Buffer( chanend c_sof, chanend c_aud_ctl, in port p_off_mclk -#if( 0 < HID_CONTROLS ) +#if (HID_CONTROLS ) , chanend c_hid #endif , chanend c_aud +#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) + , client interface sync_if i_sync +#endif ); void XUA_Buffer_Ep(chanend c_aud_out, @@ -77,20 +67,6 @@ void XUA_Buffer_Ep(chanend c_aud_out, chanend c_midi_to_host, chanend c_midi, #endif -#ifdef IAP - chanend c_iap_from_host, - chanend c_iap_to_host, -#ifdef IAP_INT_EP - chanend c_iap_to_host_int, -#endif - chanend c_iap, -#ifdef IAP_EA_NATIVE_TRANS - chanend c_iap_ea_native_out, - chanend c_iap_ea_native_in, - chanend c_iap_ea_native_ctrl, - chanend c_iap_ea_native_data, -#endif -#endif #if (SPDIF_RX) || (ADAT_RX) chanend ?c_int, chanend ?c_clk_int, @@ -98,11 +74,14 @@ void XUA_Buffer_Ep(chanend c_aud_out, chanend c_sof, chanend c_aud_ctl, in port p_off_mclk -#if( 0 < HID_CONTROLS ) +#if (HID_CONTROLS) , chanend c_hid #endif #ifdef CHAN_BUFF_CTRL , chanend c_buff_ctrl +#endif +#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) + , client interface sync_if i_sync #endif ); @@ -116,7 +95,5 @@ void XUA_Buffer_Decouple(chanend c_audio_out , chanend c_buff_ctrl #endif ); - #endif - #endif diff --git a/lib_xua/api/xua_conf_default.h b/lib_xua/api/xua_conf_default.h index 0c9ccce8b..e553fba9a 100644 --- a/lib_xua/api/xua_conf_default.h +++ b/lib_xua/api/xua_conf_default.h @@ -11,8 +11,6 @@ #include "xua_conf.h" #endif - - /* Default tile arrangement */ /** @@ -57,6 +55,13 @@ #define PDM_TILE AUDIO_IO_TILE #endif +/** + * @brief Location (tile) of reference signal to CS2100. Default: AUDIO_IO_TILE + */ +#ifndef PLL_REF_TILE +#define PLL_REF_TILE AUDIO_IO_TILE +#endif + /** * @brief Disable USB functionalty just leaving AudioHub */ @@ -1452,3 +1457,17 @@ enum USBEndpointNumber_Out #if (CODEC_MASTER == 1) && (DSD_CHANS_DAC != 0) #error CODEC_MASTER with DSD is currently unsupported #endif + +#define XUA_SYNCMODE_ASYNC (1) // USB_ENDPOINT_SYNCTYPE_ASYNC +#define XUA_SYNCMODE_ADAPT (2) // USB_ENDPOINT_SYNCTYPE_ADAPT +#define XUA_SYNCMODE_SYNC (3) // USB_ENDPOINT_SYNCTYPE_SYNC + +#ifndef XUA_SYNCMODE +#define XUA_SYNCMODE XUA_SYNCMODE_ASYNC +#endif + +#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) + #if (SPDIF_RX || ADAT_RX) + #error "Digital input streams not supported in Sync mode" + #endif +#endif diff --git a/lib_xua/src/core/buffer/ep/ep_buffer.xc b/lib_xua/src/core/buffer/ep/ep_buffer.xc index ec2ba41d5..0a1e050c8 100644 --- a/lib_xua/src/core/buffer/ep/ep_buffer.xc +++ b/lib_xua/src/core/buffer/ep/ep_buffer.xc @@ -91,43 +91,32 @@ unsigned int fb_clocks[4]; #define FB_TOLERANCE 0x100 void XUA_Buffer( - register chanend c_aud_out, + register chanend c_aud_out, #if (NUM_USB_CHAN_IN > 0) - register chanend c_aud_in, + register chanend c_aud_in, #endif #if (NUM_USB_CHAN_IN == 0) || defined (UAC_FORCE_FEEDBACK_EP) - chanend c_aud_fb, + chanend c_aud_fb, #endif #ifdef MIDI - chanend c_midi_from_host, - chanend c_midi_to_host, - chanend c_midi, -#endif -#ifdef IAP - chanend c_iap_from_host, - chanend c_iap_to_host, -#ifdef IAP_INT_EP - chanend c_iap_to_host_int, -#endif - chanend c_iap, -#ifdef IAP_EA_NATIVE_TRANS - chanend c_iap_ea_native_out, - chanend c_iap_ea_native_in, - chanend c_iap_ea_native_ctrl, - chanend c_iap_ea_native_data, -#endif + chanend c_midi_from_host, + chanend c_midi_to_host, + chanend c_midi, #endif #if (SPDIF_RX) || (ADAT_RX) - chanend ?c_ep_int, - chanend ?c_clk_int, + chanend ?c_ep_int, + chanend ?c_clk_int, #endif - chanend c_sof, - chanend c_aud_ctl, - in port p_off_mclk -#if( 0 < HID_CONTROLS ) - , chanend c_hid + chanend c_sof, + chanend c_aud_ctl, + in port p_off_mclk +#if (HID_CONTROLS ) + , chanend c_hid +#endif + , chanend c_aud +#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) + , client interface sync_if i_sync #endif - , chanend c_aud ) { #ifdef CHAN_BUFF_CTRL @@ -148,20 +137,6 @@ void XUA_Buffer( c_midi_to_host, /* MIDI In */ // 4 c_midi, #endif -#ifdef IAP - c_iap_from_host, /* iAP Out */ - c_iap_to_host, /* iAP In */ -#ifdef IAP_INT_EP - c_iap_to_host_int, /* iAP Interrupt In */ -#endif - c_iap, -#ifdef IAP_EA_NATIVE_TRANS - c_iap_ea_native_out, - c_iap_ea_native_in, - c_EANativeTransport_ctrl, - c_ea_data, -#endif -#endif #if (SPDIF_RX) || (ADAT_RX) /* Audio Interrupt - only used for interrupts on external clock change */ c_ep_int, @@ -173,6 +148,9 @@ void XUA_Buffer( #endif #ifdef CHAN_BUFF_CTRL , c_buff_ctrl +#endif +#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) + , i_sync #endif ); @@ -204,38 +182,27 @@ void XUA_Buffer_Ep(register chanend c_aud_out, chanend c_aud_fb, #endif #ifdef MIDI - chanend c_midi_from_host, - chanend c_midi_to_host, - chanend c_midi, -#endif -#ifdef IAP - chanend c_iap_from_host, - chanend c_iap_to_host, -#ifdef IAP_INT_EP - chanend c_iap_to_host_int, -#endif - chanend c_iap, -#ifdef IAP_EA_NATIVE_TRANS - chanend c_iap_ea_native_out, - chanend c_iap_ea_native_in, - chanend c_iap_ea_native_ctrl, - chanend c_iap_ea_native_data, -#endif + chanend c_midi_from_host, + chanend c_midi_to_host, + chanend c_midi, #endif #if (SPDIF_RX) || (ADAT_RX) - chanend ?c_ep_int, - chanend ?c_clk_int, + chanend ?c_ep_int, + chanend ?c_clk_int, #endif - chanend c_sof, - chanend c_aud_ctl, - in port p_off_mclk -#if( 0 < HID_CONTROLS ) - , chanend c_hid + chanend c_sof, + chanend c_aud_ctl, + in port p_off_mclk +#if(HID_CONTROLS) + , chanend c_hid #endif #ifdef CHAN_BUFF_CTRL - , chanend c_buff_ctrl + , chanend c_buff_ctrl #endif - ) +#if XUA_SYNCMODE == XUA_SYNCMODE_SYNC + , client interface sync_if i_sync +#endif + ) { XUD_ep ep_aud_out = XUD_InitEp(c_aud_out); @@ -542,6 +509,30 @@ void XUA_Buffer_Ep(register chanend c_aud_out, /* SOF notification from XUD_Manager() */ case inuint_byref(c_sof, u_tmp): +#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) + /* This really could (should) be done in decouple. However, for a quick demo this is okay + * Decouple expects a 16:16 number in fixed point stored in the global g_speed */ + + unsigned usbSpeed; + int framesPerSec; + GET_SHARED_GLOBAL(usbSpeed, g_curUsbSpeed); + static int sofCount = 0; + static unsigned syncPinVal = 0; + + framesPerSec = (usbSpeed == XUD_SPEED_HS) ? 8000 : 1000; + float float_clocks = (float) sampleFreq/framesPerSec ; + + clocks = (unsigned) (float_clocks * (1 << 16)); + asm volatile("stw %0, dp[g_speed]"::"r"(clocks)); + + sofCount += 1000; + if (sofCount == framesPerSec) + { + /* Port is accessed via interface to allow flexibilty with location */ + i_sync.toggle(); + sofCount = 0; + } +#else /* NOTE our feedback will be wrong for a couple of SOF's after a SF change due to * lastClock being incorrect */ @@ -711,7 +702,8 @@ void XUA_Buffer_Ep(register chanend c_aud_out, #endif sofCount++; } - break; +#endif + break; #if (NUM_USB_CHAN_IN > 0) /* Sent audio packet DEVICE -> HOST */ @@ -724,7 +716,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out, #endif #if (NUM_USB_CHAN_OUT > 0) -#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) +#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) && (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) /* Feedback Pipe */ case XUD_SetData_Select(c_aud_fb, ep_aud_fb, result): { diff --git a/lib_xua/src/core/clocking/clockgen.xc b/lib_xua/src/core/clocking/clockgen.xc index 524c4dd2f..929aee5dd 100644 --- a/lib_xua/src/core/clocking/clockgen.xc +++ b/lib_xua/src/core/clocking/clockgen.xc @@ -7,6 +7,7 @@ #include "xua.h" #include "xua_commands.h" +#include "clocking.h" #if (SPDIF_RX) #include "spdif.h" @@ -38,6 +39,24 @@ 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_sync) +{ + static unsigned pinVal= 0; + p_sync <: pinVal; + + while(1) + { + select + { + case i_sync.toggle(): + pinVal = ~pinVal; + p_sync <: pinVal; + break; + } + } +} + #if (SPDIF_RX) || (ADAT_RX) static int abs(int x) diff --git a/lib_xua/src/core/clocking/clocking.h b/lib_xua/src/core/clocking/clocking.h index 10dff9eeb..a388f16aa 100644 --- a/lib_xua/src/core/clocking/clocking.h +++ b/lib_xua/src/core/clocking/clocking.h @@ -1,4 +1,4 @@ -// Copyright 2011-2021 XMOS LIMITED. +// Copyright 2011-2022 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef _CLOCKING_H_ @@ -16,5 +16,13 @@ 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); #endif diff --git a/lib_xua/src/core/endpoint0/xua_endpoint0.c b/lib_xua/src/core/endpoint0/xua_endpoint0.c index 784679721..ae74bc941 100755 --- a/lib_xua/src/core/endpoint0/xua_endpoint0.c +++ b/lib_xua/src/core/endpoint0/xua_endpoint0.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "xua.h" @@ -482,7 +483,7 @@ void XUA_Endpoint0_init(chanend c_ep0_out, chanend c_ep0_in, NULLABLE_RESOURCE(c /* Check if device has started in DFU mode */ if (DFUReportResetState(null)) { - assert((c_audioControl != NULL) && msg("DFU not supported when c_audioControl is null")); + assert(((unsigned)c_audioControl != 0) && msg("DFU not supported when c_audioControl is null")); /* Stop audio */ outuint(c_audioControl, SET_SAMPLE_FREQ); diff --git a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h index 72db76021..83f7cbb53 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h +++ b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h @@ -10,16 +10,13 @@ #define _DEVICE_DESCRIPTORS_ #include -#include "xua.h" /* Device specific define */ +#include "xua.h" /* Device specific define */ #include "descriptor_defs.h" #include "usbaudio20.h" /* Defines from the USB Audio 2.0 Specifications */ #include "usbaudiocommon.h" #include "xud_device.h" #include "xua_hid_descriptor.h" - -#ifdef IAP_EA_NATIVE_TRANS -#include "iap2.h" /* Defines iAP EA Native Transport protocol name */ -#endif +#include "xud.h" #define APPEND_VENDOR_STR(x) VENDOR_STR" "#x @@ -46,14 +43,25 @@ // The value below must match the length of XUA_DESCR_EMPTY_STRING. #define XUA_MAX_STR_LEN (32) -#define ISO_EP_ATTRIBUTES_ASYNCH 0x05 //ISO, ASYNCH, DATA EP -#define ISO_EP_ATTRIBUTES_ADAPTIVE 0x09 //ISO, ADAPTIVE, DATA EP -#define ISO_EP_IMPL_ATTRIBUTES_ASYNCH 0x25 //ISO, ASYNCH, IMPLICIT FB DATA EP -#define ISO_EP_IMPL_ATTRIBUTES_ADAPTIVE 0x29 //ISO, ADAPTIVE, IMPLICIT FB DATA EP +#define ISO_EP_ATTRIBUTES_ASYNC ((USB_ENDPOINT_TRANSTYPE_ISO << USB_ENDPOINT_TRANSTYPE_SHIFT)\ + | (USB_ENDPOINT_SYNCTYPE_ASYNC << USB_ENDPOINT_SYNCTYPE_SHIFT)\ + | (USB_ENDPOINT_USAGETYPE_DATA << USB_ENDPOINT_USAGETYPE_SHIFT)) + +#define ISO_EP_ATTRIBUTES_ADAPTIVE ((USB_ENDPOINT_TRANSTYPE_ISO << USB_ENDPOINT_TRANSTYPE_SHIFT)\ + | (USB_ENDPOINT_SYNCTYPE_ADAPT << USB_ENDPOINT_SYNCTYPE_SHIFT)\ + | (USB_ENDPOINT_USAGETYPE_DATA << USB_ENDPOINT_USAGETYPE_SHIFT)) -#if (defined(XUA_ADAPTIVE) && (XUA_ADAPTIVE == 0)) -#undef XUA_ADAPTIVE -#endif +#define ISO_EP_ATTRIBUTES_SYNC ((USB_ENDPOINT_TRANSTYPE_ISO << USB_ENDPOINT_TRANSTYPE_SHIFT)\ + | (USB_ENDPOINT_SYNCTYPE_SYNC << USB_ENDPOINT_SYNCTYPE_SHIFT)\ + | (USB_ENDPOINT_USAGETYPE_DATA << USB_ENDPOINT_USAGETYPE_SHIFT)) + +#define ISO_EP_IMPL_ATTRIBUTES_ASYNC ((USB_ENDPOINT_TRANSTYPE_ISO << USB_ENDPOINT_TRANSTYPE_SHIFT)\ + | (USB_ENDPOINT_SYNCTYPE_ASYNC << USB_ENDPOINT_SYNCTYPE_SHIFT)\ + | (USB_ENDPOINT_USAGETYPE_IMPLICIT << USB_ENDPOINT_USAGETYPE_SHIFT)) + +#define ISO_EP_IMPL_ATTRIBUTES_ADAPT ((USB_ENDPOINT_TRANSTYPE_ISO << USB_ENDPOINT_TRANSTYPE_SHIFT)\ + | (USB_ENDPOINT_SYNCTYPE_ADAPT << USB_ENDPOINT_SYNCTYPE_SHIFT)\ + | (USB_ENDPOINT_USAGETYPE_IMPLICIT << USB_ENDPOINT_USAGETYPE_SHIFT)) #if __STDC__ typedef struct @@ -707,7 +715,7 @@ typedef struct USB_Descriptor_Audio_Format_Type1_t Audio_Out_Format; USB_Descriptor_Endpoint_t Audio_Out_Endpoint; USB_Descriptor_Audio_Class_AS_Endpoint_t Audio_Out_ClassEndpoint; -#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) +#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) && (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) USB_Descriptor_Endpoint_t Audio_Out_Fb_Endpoint; #endif #if (OUTPUT_FORMAT_COUNT > 1) @@ -716,7 +724,7 @@ typedef struct USB_Descriptor_Audio_Format_Type1_t Audio_Out_Format_2; USB_Descriptor_Endpoint_t Audio_Out_Endpoint_2; USB_Descriptor_Audio_Class_AS_Endpoint_t Audio_Out_ClassEndpoint_2; -#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) +#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) && (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) USB_Descriptor_Endpoint_t Audio_Out_Fb_Endpoint_2; #endif #endif // OUTPUT_FORMAT_COUNT > 1 @@ -726,7 +734,7 @@ typedef struct USB_Descriptor_Audio_Format_Type1_t Audio_Out_Format_3; USB_Descriptor_Endpoint_t Audio_Out_Endpoint_3; USB_Descriptor_Audio_Class_AS_Endpoint_t Audio_Out_ClassEndpoint_3; -#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) +#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) && (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) USB_Descriptor_Endpoint_t Audio_Out_Fb_Endpoint_3; #endif #endif // OUTPUT_FORMAT_COUNT > 2 @@ -1424,7 +1432,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= USB_DESCTYPE_INTERFACE, /* 1 bDescriptorType: INTERFACE */ INTERFACE_NUMBER_AUDIO_OUTPUT, /* 2 bInterfaceNumber: Number of interface */ 1, /* 3 bAlternateSetting */ -#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) +#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) && (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) 2, /* 4 bNumEndpoints */ #else 1, /* 4 bNumEndpoints */ @@ -1467,14 +1475,18 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .bLength = sizeof(USB_Descriptor_Endpoint_t), .bDescriptorType = USB_DESCTYPE_ENDPOINT, .bEndpointAddress = ENDPOINT_ADDRESS_OUT_AUDIO, -#ifdef XUA_ADAPTIVE +#if (XUA_SYNCMODE == XUA_SYNCMODE_ADAPT) .bmAttributes = ISO_EP_ATTRIBUTES_ADAPTIVE, -#else +#elif (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) - .bmAttributes = ISO_EP_ATTRIBUTES_ASYNCH, /* Iso, async, data endpoint */ + .bmAttributes = ISO_EP_ATTRIBUTES_ASYNC, /* Iso, async, data endpoint */ #else - .bmAttributes = ISO_EP_IMPL_ATTRIBUTES_ASYNCH, /* Feedback data endpoint */ + .bmAttributes = ISO_EP_IMPL_ATTRIBUTES_ASYNC, /* Feedback data endpoint */ #endif +#elif (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) + .bmAttributes = ISO_EP_ATTRIBUTES_SYNC, +#else + #error "Bad XUA_SYNCMODE" #endif .wMaxPacketSize = HS_STREAM_FORMAT_OUTPUT_1_MAXPACKETSIZE, .bInterval = 1, @@ -1492,7 +1504,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= 0x0008, /* 6:7 bLockDelay */ }, -#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) +#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) && (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) .Audio_Out_Fb_Endpoint = { .bLength = 0x07, @@ -1511,7 +1523,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= USB_DESCTYPE_INTERFACE, /* 1 bDescriptorType: INTERFACE */ INTERFACE_NUMBER_AUDIO_OUTPUT, /* 2 bInterfaceNumber: Number of interface */ 2, /* 3 bAlternateSetting */ -#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) +#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) && (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) 2, /* 4 bNumEndpoints */ #else 1, /* 4 bNumEndpoints */ @@ -1553,14 +1565,18 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .bLength = sizeof(USB_Descriptor_Endpoint_t), .bDescriptorType = USB_DESCTYPE_ENDPOINT, .bEndpointAddress = ENDPOINT_ADDRESS_OUT_AUDIO, -#ifdef XUA_ADAPTIVE +#if (XUA_SYNCMODE == XUA_SYNCMODE_ADAPT) .bmAttributes = ISO_EP_ATTRIBUTES_ADAPTIVE, +#elif (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) + #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) + .bmAttributes = ISO_EP_ATTRIBUTES_ASYNC, /* Iso, Async, data endpoint */ + #else + .bmAttributes = ISO_EP_IMPL_ATTRIBUTES_ASYNC, /* Feedback data endpoint */ + #endif +#elif (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) + .bmAttributes = ISO_EP_ATTRIBUTES_SYNC, /* Iso, Sync, data endpoint */ #else - #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) - .bmAttributes = ISO_EP_ATTRIBUTES_ASYNCH, /* Iso, async, data endpoint */ - #else - .bmAttributes = ISO_EP_IMPL_ATTRIBUTES_ASYNCH, /* Feedback data endpoint */ - #endif + #error "Bad XUA_SYNCMODE" #endif .wMaxPacketSize = HS_STREAM_FORMAT_OUTPUT_2_MAXPACKETSIZE, .bInterval = 1, @@ -1578,7 +1594,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= 0x0008, /* 6:7 bLockDelay */ }, -#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) +#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) && (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) .Audio_Out_Fb_Endpoint_2 = { 0x07, /* 0 bLength: 7 */ @@ -1598,7 +1614,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= USB_DESCTYPE_INTERFACE, /* 1 bDescriptorType: INTERFACE */ INTERFACE_NUMBER_AUDIO_OUTPUT, /* 2 bInterfaceNumber: Number of interface */ 3, /* 3 bAlternateSetting */ -#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) +#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) && (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) 2, /* 4 bNumEndpoints */ #else 1, /* 4 bNumEndpoints */ @@ -1641,14 +1657,18 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .bLength = 0x07, .bDescriptorType = USB_DESCTYPE_ENDPOINT, .bEndpointAddress = ENDPOINT_ADDRESS_OUT_AUDIO, -#ifdef XUA_ADAPTIVE - .bmAttributes = ISO_EP_ATTRIBUTES_ADAPTIVE, +#if (XUA_SYNCMODE == XUA_SYNCMODE_ADAPT) + .bmAttributes = ISO_EP_ATTRIBUTES_ADAPTIVE, +#elif (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) + #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) + .bmAttributes = ISO_EP_ATTRIBUTES_ASYNC, /* Iso, Async, data endpoint */ + #else + .bmAttributes = ISO_EP_IMPL_ATTRIBUTES_ASYNC, /* Feedback data endpoint */ + #endif +#elif (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) + .bmAttributes = ISO_EP_ATTRIBUTES_SYNC, /* Iso, Sync, data endpoint */ #else - #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) - .bmAttributes = ISO_EP_ATTRIBUTES_ASYNCH, /* Iso, async, data endpoint */ - #else - .bmAttributes = ISO_EP_IMPL_ATTRIBUTES_ASYNCH, /* Feedback data endpoint */ - #endif + #error "Bad XUA_SYNCMODE" #endif .wMaxPacketSize = HS_STREAM_FORMAT_OUTPUT_3_MAXPACKETSIZE, .bInterval = 1, @@ -1666,7 +1686,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .wLockDelay = 0x0008, }, -#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) +#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) && (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) .Audio_Out_Fb_Endpoint_3 = { .bLength = 0x07, @@ -1742,14 +1762,18 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .bLength = 0x07, .bDescriptorType = USB_DESCTYPE_ENDPOINT, .bEndpointAddress = ENDPOINT_ADDRESS_IN_AUDIO, -#ifdef XUA_ADAPTIVE - .bmAttributes = ISO_EP_ATTRIBUTES_ADAPTIVE, +#if (XUA_SYNCMODE == XUA_SYNCMODE_ADAPT) + .bmAttributes = ISO_EP_ATTRIBUTES_ADAPTIVE, +#elif (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) + #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) + .bmAttributes = ISO_EP_ATTRIBUTES_ASYNC, /* Iso, Async, data endpoint */ + #else + .bmAttributes = ISO_EP_IMPL_ATTRIBUTES_ASYNC, /* Feedback data endpoint */ + #endif +#elif (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) + .bmAttributes = ISO_EP_ATTRIBUTES_SYNC, /* Iso, Sync, data endpoint */ #else - #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) - .bmAttributes = ISO_EP_ATTRIBUTES_ASYNCH, /* Iso, async, data endpoint */ - #else - .bmAttributes = ISO_EP_IMPL_ATTRIBUTES_ASYNCH, /* Feedback data endpoint */ - #endif + #error "Bad XUA_SYNCMODE" #endif .wMaxPacketSize = HS_STREAM_FORMAT_INPUT_1_MAXPACKETSIZE, .bInterval = 0x01, @@ -1814,14 +1838,18 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .bLength = 0x07, .bDescriptorType = USB_DESCTYPE_ENDPOINT, .bEndpointAddress = ENDPOINT_ADDRESS_IN_AUDIO, -#ifdef XUA_ADAPTIVE - .bmAttributes = ISO_EP_ATTRIBUTES_ADAPTIVE, +#if (XUA_SYNCMODE == XUA_SYNCMODE_ADAPT) + .bmAttributes = ISO_EP_ATTRIBUTES_ADAPTIVE, +#elif (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) + #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) + .bmAttributes = ISO_EP_ATTRIBUTES_ASYNC, /* Iso, Async, data endpoint */ + #else + .bmAttributes = ISO_EP_IMPL_ATTRIBUTES_ASYNC, /* Feedback data endpoint */ + #endif +#elif (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) + .bmAttributes = ISO_EP_ATTRIBUTES_SYNC, /* Iso, Sync, data endpoint */ #else - #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) - .bmAttributes = ISO_EP_ATTRIBUTES_ASYNCH, /* Iso, async, data endpoint */ - #else - .bmAttributes = ISO_EP_IMPL_ATTRIBUTES_ASYNCH, /* Feedback data endpoint */ - #endif + #error "Bad XUA_SYNCMODE" #endif .wMaxPacketSize = HS_STREAM_FORMAT_INPUT_2_MAXPACKETSIZE, .bInterval = 0x01, @@ -1887,14 +1915,18 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .bLength = 0x07, .bDescriptorType = USB_DESCTYPE_ENDPOINT, .bEndpointAddress = ENDPOINT_ADDRESS_IN_AUDIO, -#ifdef XUA_ADAPTIVE - .bmAttributes = ISO_EP_ATTRIBUTES_ADAPTIVE, +#if (XUA_SYNCMODE == XUA_SYNCMODE_ADAPT) + .bmAttributes = ISO_EP_ATTRIBUTES_ADAPTIVE, +#elif (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) + #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) + .bmAttributes = ISO_EP_ATTRIBUTES_ASYNC, /* Iso, Async, data endpoint */ + #else + .bmAttributes = ISO_EP_IMPL_ATTRIBUTES_ASYNC, /* Feedback data endpoint */ + #endif +#elif (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) + .bmAttributes = ISO_EP_ATTRIBUTES_SYNC, /* Iso, Sync, data endpoint */ #else - #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) - .bmAttributes = ISO_EP_ATTRIBUTES_ASYNCH, /* Iso, async, data endpoint */ - #else - .bmAttributes = ISO_EP_IMPL_ATTRIBUTES_ASYNCH, /* Feedback data endpoint */ - #endif + #error "Bad XUA_SYNCMODE" #endif .wMaxPacketSize = HS_STREAM_FORMAT_INPUT_3_MAXPACKETSIZE, .bInterval = 0x01, @@ -2325,7 +2357,7 @@ const unsigned num_freqs_a1 = MAX(3, (0 /* Note, this is different that INTERFACE_COUNT since we dont support items such as MIDI, iAP etc in UAC1 mode */ #define NUM_INTERFACES_A1 (1 + INPUT_INTERFACES_A1 + OUTPUT_INTERFACES_A1 + NUM_CONTROL_USB_INTERFACES + DFU_INTERFACES_A1 + HID_INTERFACES_A1) -#if ((NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP)) +#if ((NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP)) && (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) #define CFG_TOTAL_LENGTH_A1 (18 + AC_TOTAL_LENGTH + (INPUT_INTERFACES_A1 * (49 + num_freqs_a1 * 3)) + (OUTPUT_INTERFACES_A1 * (58 + num_freqs_a1 * 3)) + CONTROL_INTERFACE_BYTES + DFU_INTERFACE_BYTES + HID_INTERFACE_BYTES) #else #define CFG_TOTAL_LENGTH_A1 (18 + AC_TOTAL_LENGTH + (INPUT_INTERFACES_A1 * (49 + num_freqs_a1 * 3)) + (OUTPUT_INTERFACES_A1 * (49 + num_freqs_a1 * 3)) + CONTROL_INTERFACE_BYTES + DFU_INTERFACE_BYTES + HID_INTERFACE_BYTES) @@ -2557,7 +2589,7 @@ unsigned char cfgDesc_Audio1[] = 0x04, /* INTERFACE */ 0x01, /* bInterfaceNumber */ 0x01, /* bAlternateSetting */ -#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) +#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) && (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) 0x02, /* bNumEndpoints 2: audio EP and feedback EP */ #else 0x01, /* bNumEndpoints */ @@ -2640,27 +2672,31 @@ unsigned char cfgDesc_Audio1[] = 0x09, 0x05, /* ENDPOINT */ ENDPOINT_ADDRESS_OUT_AUDIO, /* endpointAddress - D7, direction (0 OUT, 1 IN). D6..4 reserved (0). D3..0 endpoint no. */ -#ifdef XUA_ADAPTIVE +#if (XUA_SYNCMODE == XUA_SYNCMODE_ADAPT) ISO_EP_ATTRIBUTES_ADAPTIVE, -#else +#elif (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) - ISO_EP_ATTRIBUTES_ASYNCH, /* Iso, async, data endpoint */ + ISO_EP_ATTRIBUTES_ASYNC, /* Iso, async, data endpoint */ #else - ISO_EP_IMPL_ATTRIBUTES_ASYNCH, /* Feedback data endpoint */ + ISO_EP_IMPL_ATTRIBUTES_ASYNC, /* Feedback data endpoint */ #endif +#elif (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) + ISO_EP_ATTRIBUTES_SYNC, /* Iso, sync, data endpoint */ +#else +#error "Unsupported XUA_SYNCMODE" #endif (FS_STREAM_FORMAT_OUTPUT_1_MAXPACKETSIZE&0xff), /* 4 wMaxPacketSize (Typically 294 bytes)*/ (FS_STREAM_FORMAT_OUTPUT_1_MAXPACKETSIZE&0xff00)>>8, /* 5 wMaxPacketSize */ 0x01, /* bInterval */ 0x00, /* bRefresh */ -#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) +#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) && (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) ENDPOINT_ADDRESS_IN_FEEDBACK, /* bSynchAdddress - address of EP used to communicate sync info */ -#else /* Bi-directional in/out device */ -#ifdef XUA_ADAPTIVE - 0, /* OUT */ -#else - ENDPOINT_ADDRESS_IN_AUDIO, -#endif +#else /* Bi-directional in/out device */ + #if (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) + ENDPOINT_ADDRESS_IN_AUDIO, + #else + 0, /* Unused */ + #endif #endif /* CS_Endpoint Descriptor ?? */ @@ -2669,13 +2705,13 @@ unsigned char cfgDesc_Audio1[] = 0x01, /* subtype - GENERAL */ 0x01, /* attributes. D[0]: sample freq ctrl. */ 0x02, /* bLockDelayUnits */ -#ifdef XUA_ADAPTIVE +#if (XUA_SYNCMODE == XUA_SYNCMODE_ADAPT) 0x08, 0x00, /* bLockDelay */ #else 0x00, 0x00, /* Not used */ #endif -#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) +#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) && (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) /* Feedback EP */ 0x09, 0x05, /* bDescriptorType: ENDPOINT */ @@ -2784,14 +2820,18 @@ unsigned char cfgDesc_Audio1[] = 0x09, 0x05, /* ENDPOINT */ ENDPOINT_ADDRESS_IN_AUDIO, /* EndpointAddress */ -#ifdef XUA_ADAPTIVE +#if (XUA_SYNCMODE == XUA_SYNCMODE_ADAPT) ISO_EP_ATTRIBUTES_ADAPTIVE, -#else +#elif (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC) #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) - ISO_EP_ATTRIBUTES_ASYNCH, /* Iso, async, data endpoint */ + ISO_EP_ATTRIBUTES_ASYNC, /* Iso, async, data endpoint */ #else - ISO_EP_IMPL_ATTRIBUTES_ASYNCH, /* Feedback data endpoint */ + ISO_EP_IMPL_ATTRIBUTES_ASYNC, /* Feedback data endpoint */ #endif +#elif (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) + ISO_EP_ATTRIBUTES_SYNC, /* Iso, sync, data endpoint */ +#else +#error "Unsupported XUA_SYNCMODE" #endif FS_STREAM_FORMAT_INPUT_1_MAXPACKETSIZE&0xff, /* 4 wMaxPacketSize (Typically 294 bytes)*/ (FS_STREAM_FORMAT_INPUT_1_MAXPACKETSIZE&0xff00)>>8, /* 5 wMaxPacketSize */ @@ -2804,13 +2844,13 @@ unsigned char cfgDesc_Audio1[] = 0x25, /* CS_ENDPOINT */ 0x01, /* Subtype - GENERAL */ 0x01, /* Attributes. D[0]: sample freq ctrl. */ -#ifdef XUA_ADAPTIVE +#if (XUA_SYNCMODE == XUA_SYNCMODE_ADAPT) 0x02, /* Lock Delay units PCM samples*/ 0x08, 0x00, /* No lock delay */ #else 0x00, /* Undefined */ 0x00, 0x00, /* Not used */ -#endif // XUA_ADAPTIVE +#endif #endif // NUM_USB_CHAN_IN > 0 #if (XUA_DFU_EN == 1) && (FORCE_UAC1_DFU == 1) diff --git a/lib_xua/src/core/main.xc b/lib_xua/src/core/main.xc index 79b70f6f3..83cc313f6 100755 --- a/lib_xua/src/core/main.xc +++ b/lib_xua/src/core/main.xc @@ -154,9 +154,9 @@ on stdcore[XUD_TILE] : buffered in port:32 p_adat_rx = PORT_ADAT_IN; on tile[XUD_TILE] : buffered in port:4 p_spdif_rx = PORT_SPDIF_IN; #endif -#if (SPDIF_RX == 1) || (ADAT_RX) +#if (SPDIF_RX) || (ADAT_RX) || (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) /* Reference to external clock multiplier */ -on tile[AUDIO_IO_TILE] : out port p_pll_clk = PORT_PLL_REF; +on tile[PLL_REF_TILE] : out port p_pll_ref = PORT_PLL_REF; #endif #ifdef MIDI @@ -280,20 +280,17 @@ void xscope_user_init() /* 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 -, chanend c_midi + , chanend c_midi #endif -#ifdef IAP -, chanend c_iap -#ifdef IAP_EA_NATIVE_TRANS -, chanend c_ea_data + #ifdef MIXER + , chanend c_mix_ctl #endif + , chanend ?c_clk_int + , chanend ?c_clk_ctl + , client interface i_dfu ?dfuInterface +#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) + , client interface sync_if i_sync #endif -#ifdef MIXER -, chanend c_mix_ctl -#endif -, chanend ?c_clk_int -, chanend ?c_clk_ctl -, client interface i_dfu ?dfuInterface VENDOR_REQUESTS_PARAMS_DEC_ ) { @@ -362,33 +359,22 @@ VENDOR_REQUESTS_PARAMS_DEC_ c_xud_in[ENDPOINT_NUMBER_IN_MIDI], /* MIDI In */ // 4 c_midi, #endif -#ifdef IAP - c_xud_out[ENDPOINT_NUMBER_OUT_IAP], /* iAP Out */ - c_xud_in[ENDPOINT_NUMBER_IN_IAP], /* iAP In */ -#ifdef IAP_INT_EP - c_xud_in[ENDPOINT_NUMBER_IN_IAP_INT], /* iAP Interrupt In */ -#endif - c_iap, -#ifdef IAP_EA_NATIVE_TRANS - c_xud_out[ENDPOINT_NUMBER_OUT_IAP_EA_NATIVE_TRANS], - c_xud_in[ENDPOINT_NUMBER_IN_IAP_EA_NATIVE_TRANS], - c_EANativeTransport_ctrl, - c_ea_data, -#endif -#endif #if (SPDIF_RX) || (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 -#if( 0 < HID_CONTROLS ) +#if (HID_CONTROLS) , c_xud_in[ENDPOINT_NUMBER_IN_HID] #endif #ifdef CHAN_BUFF_CTRL , c_buff_ctrl #endif , c_mix_out +#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) + , i_sync +#endif ); //: } @@ -519,7 +505,7 @@ void usb_audio_io(chanend ?c_aud_in, { thread_speed(); - clockGen(c_spdif_rx, c_adat_rx, p_pll_clk, c_dig_rx, c_clk_ctl, c_clk_int); + clockGen(c_spdif_rx, c_adat_rx, p_pll_ref, c_dig_rx, c_clk_ctl, c_clk_int); } #endif @@ -598,12 +584,20 @@ int main() #endif #endif +#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) + interface sync_if i_sync; +#endif + USER_MAIN_DECLARATIONS par { USER_MAIN_CORES +#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) + on tile[PLL_REF_TILE]: PllRefPinTask(i_sync, p_pll_ref); + +#endif on tile[XUD_TILE]: par { @@ -629,6 +623,9 @@ int main() , c_mix_ctl #endif , c_clk_int, c_clk_ctl, dfuInterface +#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) + , i_sync +#endif VENDOR_REQUESTS_PARAMS_ );