From 85bbc96e61763e53f357974f590d88947f23853d Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Mon, 4 Nov 2013 09:11:23 +0000 Subject: [PATCH 01/72] i2c ports not currently in a struct --- module_usb_audio/main.xc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/main.xc b/module_usb_audio/main.xc index 17a78074..52ecd1d7 100755 --- a/module_usb_audio/main.xc +++ b/module_usb_audio/main.xc @@ -324,7 +324,7 @@ int main() #ifdef MIDI usb_midi(p_midi_rx, p_midi_tx, clk_midi, c_midi, 0, null, null, null, null); #else - iAP(c_iap, null, i2cPorts.scl, i2cPorts.sda); + iAP(c_iap, null, null, null); #endif } #endif From 6082e098090a4a55c268001c8e87fc7b93260f72 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Mon, 18 Nov 2013 18:34:09 +0000 Subject: [PATCH 02/72] BCD_DEVICE 6v2->6v3 --- module_usb_audio/devicedefines.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index b4db8a22..e2d5d312 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -246,8 +246,8 @@ /* Device release number in BCD: 0xJJMNi */ #ifndef BCD_DEVICE -#define BCD_DEVICE (0x0620) -#warning BCD_DEVICE not defined. Using 0x0620 +#define BCD_DEVICE (0x0630) +#warning BCD_DEVICE not defined. Using 0x0630 #endif /* Addition interfaces based on defines */ From 7a6e9acf96a3ae493ad7bd99491bef465b83f596 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Wed, 27 Nov 2013 11:07:07 +0000 Subject: [PATCH 03/72] Update for tools13 compatibility - per core timers not yet allocated while constructor is running --- module_usb_audio/powersave/archU_powerSaving.xc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module_usb_audio/powersave/archU_powerSaving.xc b/module_usb_audio/powersave/archU_powerSaving.xc index 068c1717..4f42f66c 100644 --- a/module_usb_audio/powersave/archU_powerSaving.xc +++ b/module_usb_audio/powersave/archU_powerSaving.xc @@ -5,6 +5,7 @@ #include #include #include +#include #ifndef VOLTAGE_REDUCTION_mV #define VOLTAGE_REDUCTION_mV 20 @@ -25,7 +26,7 @@ void archU_powerSaving() // Reduce the VDDCORE voltage level for (unsigned count=0; count < (VOLTAGE_REDUCTION_mV/10); count++) { - timer t; + hwtimer_t t; int time; writeval[0] = (ARCH_U_VOLTAGE_FIRST_STEP - count); From 49a94c16d360d92e37d522f332b1b4947c3bd44d Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Wed, 27 Nov 2013 16:38:56 +0000 Subject: [PATCH 04/72] Use the version number from xpd --- module_usb_audio/devicedefines.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index c3d693ee..d6e8c88d 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -236,7 +236,7 @@ /* Device release number in BCD: 0xJJMNi */ #ifndef BCD_DEVICE -#define BCD_DEVICE (0x0630) +#define BCD_DEVICE ((XMOS_USB_AUD_APP_MAJOR_VERSION << 8) | ((XMOS_USB_AUD_APP_MINOR_VERSION&0xF) << 4) | (XMOS_USB_AUD_APP_POINT_VERSION&0xF)) #endif /* Addition interfaces based on defines */ From e40bdb2c60c7594fc55952539bfde4881a608395 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Wed, 27 Nov 2013 18:43:48 +0000 Subject: [PATCH 05/72] Revert "Use the version number from xpd" This reverts commit 49a94c16d360d92e37d522f332b1b4947c3bd44d. --- module_usb_audio/devicedefines.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index d6e8c88d..c3d693ee 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -236,7 +236,7 @@ /* Device release number in BCD: 0xJJMNi */ #ifndef BCD_DEVICE -#define BCD_DEVICE ((XMOS_USB_AUD_APP_MAJOR_VERSION << 8) | ((XMOS_USB_AUD_APP_MINOR_VERSION&0xF) << 4) | (XMOS_USB_AUD_APP_POINT_VERSION&0xF)) +#define BCD_DEVICE (0x0630) #endif /* Addition interfaces based on defines */ From 8d49bd66feaab5aa192f16dec19a6179ebe6f359 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Thu, 28 Nov 2013 11:46:58 +0000 Subject: [PATCH 06/72] Revert "Revert "Use the version number from xpd"" This reverts commit e40bdb2c60c7594fc55952539bfde4881a608395. --- module_usb_audio/devicedefines.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index c3d693ee..d6e8c88d 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -236,7 +236,7 @@ /* Device release number in BCD: 0xJJMNi */ #ifndef BCD_DEVICE -#define BCD_DEVICE (0x0630) +#define BCD_DEVICE ((XMOS_USB_AUD_APP_MAJOR_VERSION << 8) | ((XMOS_USB_AUD_APP_MINOR_VERSION&0xF) << 4) | (XMOS_USB_AUD_APP_POINT_VERSION&0xF)) #endif /* Addition interfaces based on defines */ From d8b6a2d53a968a72d161e976967a9f4f55b63013 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Thu, 28 Nov 2013 13:14:43 +0000 Subject: [PATCH 07/72] Corrected include name (failed to build on Linux) --- module_usb_audio/main.xc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/main.xc b/module_usb_audio/main.xc index 81ae44de..8236d847 100755 --- a/module_usb_audio/main.xc +++ b/module_usb_audio/main.xc @@ -26,7 +26,7 @@ #include "audio.h" #ifdef IAP -#include "iap.h" +#include "iAP.h" #endif #ifndef AUDIO_IO_TILE From edca022c5098d5b4606e525e4e1d77c7c344ee00 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Fri, 29 Nov 2013 12:33:41 +0000 Subject: [PATCH 08/72] Added use of XUD_TILE def --- module_usb_audio/main.xc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/module_usb_audio/main.xc b/module_usb_audio/main.xc index 8236d847..df008c10 100755 --- a/module_usb_audio/main.xc +++ b/module_usb_audio/main.xc @@ -3,7 +3,6 @@ * @brief Top level for XMOS USB 2.0 Audio 2.0 Reference Designs. * @author Ross Owen, XMOS Semiconductor Ltd */ - #include #include #include @@ -30,10 +29,14 @@ #endif #ifndef AUDIO_IO_TILE -#define AUDIO_IO_TILE 0 +#define AUDIO_IO_TILE 0 #endif -/* Audio I/O */ +#ifndef XUD_TILE +#define XUD_TILE 0 +#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] = {PORT_I2S_DAC0, @@ -97,7 +100,7 @@ on tile[AUDIO_IO_TILE] : buffered in port:32 p_i2s_adc[I2S_WIRES_ADC] = on tile[AUDIO_IO_TILE] : buffered out port:32 p_lrclk = PORT_I2S_LRCLK; on tile[AUDIO_IO_TILE] : buffered out port:32 p_bclk = PORT_I2S_BCLK; #else -on tile[AUDIO_IO_TILE] : in port p_lrclk = PORT_I2S_LRCLK; +on tile[AUDIO_IO_TILE] : in port p_lrclk = PORT_I2S_LRCLK; on tile[AUDIO_IO_TILE] : in port p_bclk = PORT_I2S_BCLK; #endif @@ -134,10 +137,10 @@ on tile[AUDIO_IO_TILE] : clock clk_mst_spd = XS1_CLKBLK_1; #ifdef ARCH_L #ifdef PORT_USB_RESET /* This define is checked since it could be on a shift reg or similar */ -on tile[0] : out port p_usb_rst = PORT_USB_RESET; +on tile[XUD_TILE] : out port p_usb_rst = PORT_USB_RESET; #endif /* L Series also needs a clock for this port */ -on tile[0] : clock clk = XS1_CLKBLK_4; +on tile[XUD_TILE] : clock clk = XS1_CLKBLK_4; #else /* Reset port not required for SU1 due to built in Phy */ #define p_usb_rst null @@ -145,10 +148,11 @@ on tile[0] : clock clk = XS1_CLKBLK_4; #endif #ifdef IAP -on tile [AUDIO_IO_TILE] : port p_i2c_sda = PORT_I2C_SDA; -on tile [AUDIO_IO_TILE] : port p_i2c_scl = PORT_I2C_SCL; +on tile [AUDIO_IO_TILE] : port p_i2c_sda = PORT_I2C_SDA; +on tile [AUDIO_IO_TILE] : port p_i2c_scl = PORT_I2C_SCL; #endif + /* Endpoint type tables for XUD */ XUD_EpType epTypeTableOut[EP_CNT_OUT] = { XUD_EPTYPE_CTL | XUD_STATUS_ENABLE, XUD_EPTYPE_ISO, /* Audio */ From 3d92d4b79f1facc26be1ae1af260b03e5cc585ef Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Fri, 29 Nov 2013 12:36:14 +0000 Subject: [PATCH 09/72] Main() now makes calls to two funcions (with their own pars). Also added USER_MAIN_DECLARIONS and USER_MAIN_CORES --- module_usb_audio/main.xc | 184 +++++++++++++++++++++------------------ 1 file changed, 99 insertions(+), 85 deletions(-) diff --git a/module_usb_audio/main.xc b/module_usb_audio/main.xc index df008c10..49236184 100755 --- a/module_usb_audio/main.xc +++ b/module_usb_audio/main.xc @@ -182,6 +182,7 @@ XUD_EpType epTypeTableIn[EP_CNT_IN] = { XUD_EPTYPE_CTL | XUD_STATUS_ENABLE, #endif }; + void thread_speed() { #ifdef FAST_MODE @@ -207,74 +208,52 @@ void xscope_user_init() #define pwrConfig XUD_PWR_BUS #endif - -int main() -{ - chan c_sof; - chan c_xud_out[EP_CNT_OUT]; /* Endpoint channels for XUD */ - chan c_xud_in[EP_CNT_IN]; - chan c_aud_ctl; - chan c_mix_out; -#ifdef MIDI - chan c_midi; -#endif -#ifdef IAP - chan c_iap; -#endif - -#ifdef TEST_MODE_SUPPORT -#warning Building with test mode support - chan c_usb_test; -#else -#define c_usb_test null -#endif - -#ifdef SU1_ADC_ENABLE - chan c_adc; -#else -#define c_adc null -#endif - -#ifdef CHAN_BUFF_CTRL -#warning Using channel to control buffering - this may reduce performance but improve power consumption - chan c_buff_ctrl; -#endif - - - +/* Core USB Audio functions - must be called on the Tile connected to the USB Phy */ +void usb_audio_core(chanend c_mix_out) +{ + chan c_sof; + chan c_xud_out[EP_CNT_OUT]; /* Endpoint channels for XUD */ + chan c_xud_in[EP_CNT_IN]; + chan c_aud_ctl; +#ifdef TEST_MODE_SUPPORT +#warning Building with test mode support + chan c_usb_test; +#else +#define c_usb_test null +#endif +#ifdef CHAN_BUFF_CTRL +#warning Using channel to control buffering - this may reduce performance but improve power consumption + chan c_buff_ctrl; +#endif par - { - - /* USB Interface */ + { + /* USB Interface Core */ #if (AUDIO_CLASS==2) - on tile[0]: XUD_Manager(c_xud_out, EP_CNT_OUT, c_xud_in, EP_CNT_IN, - c_sof, epTypeTableOut, epTypeTableIn, p_usb_rst, - clk, 1, XUD_SPEED_HS, c_usb_test, pwrConfig); -#else - on tile[0]:XUD_Manager(c_xud_out, EP_CNT_OUT, c_xud_in, EP_CNT_IN, - c_sof, epTypeTableOut, epTypeTableIn, p_usb_rst, - clk, 1, XUD_SPEED_FS, c_usb_test, pwrConfig); -#endif - - on tile[0]: + XUD_Manager(c_xud_out, EP_CNT_OUT, c_xud_in, EP_CNT_IN, + c_sof, epTypeTableOut, epTypeTableIn, p_usb_rst, + clk, 1, XUD_SPEED_HS, c_usb_test, pwrConfig); +#else + XUD_Manager(c_xud_out, EP_CNT_OUT, c_xud_in, EP_CNT_IN, + c_sof, epTypeTableOut, epTypeTableIn, p_usb_rst, + clk, 1, XUD_SPEED_FS, c_usb_test, pwrConfig); +#endif + + /* USB Packet buffering Core */ { + unsigned x; thread_speed(); /* Attach mclk count port to mclk clock-block (for feedback) */ //set_port_clock(p_for_mclk_count, clk_audio_mclk); - { - unsigned x; #if(AUDIO_IO_TILE != 0) - set_clock_src(clk_audio_mclk2, p_mclk_in2); - set_port_clock(p_for_mclk_count, clk_audio_mclk2); - start_clock(clk_audio_mclk2); + set_clock_src(clk_audio_mclk2, p_mclk_in2); + set_port_clock(p_for_mclk_count, clk_audio_mclk2); + start_clock(clk_audio_mclk2); #else - /* Uses same clock-block as I2S */ - asm("ldw %0, dp[clk_audio_mclk]":"=r"(x)); - asm("setclk res[%0], %1"::"r"(p_for_mclk_count), "r"(x)); + /* Uses same clock-block as I2S */ + asm("ldw %0, dp[clk_audio_mclk]":"=r"(x)); + asm("setclk res[%0], %1"::"r"(p_for_mclk_count), "r"(x)); #endif - } - buffer(c_xud_out[EP_NUM_OUT_AUD],/* Audio Out*/ c_xud_in[EP_NUM_IN_AUD], /* Audio In */ c_xud_in[EP_NUM_IN_FB], /* Audio FB */ @@ -297,38 +276,39 @@ int main() #ifdef CHAN_BUFF_CTRL , c_buff_ctrl #endif - - ); - - } - - on tile[AUDIO_IO_TILE]: - { - thread_speed(); - - /* Audio I/O (pars additional S/PDIF TX thread) */ - audio(c_mix_out, null, null, c_adc); - } - - on tile[0]: - { - thread_speed(); - decouple(c_mix_out, null -#ifdef CHAN_BUFF_CTRL - , c_buff_ctrl -#endif ); } - /* Endpoint 0 */ - on tile[0]: + /* Endpoint 0 Core */ { thread_speed(); Endpoint0( c_xud_out[0], c_xud_in[0], c_aud_ctl, null, null, c_usb_test); } + + /* Decoupling core */ + { + thread_speed(); + decouple(c_mix_out, null +#ifdef CHAN_BUFF_CTRL + , c_buff_ctrl +#endif + ); + } + } +} +void usb_audio_io(chanend c_mix_out, chanend ?c_adc) +{ + par + { + /* Audio I/O Core (pars additional S/PDIF TX Core) */ + { + thread_speed(); + audio(c_mix_out, null, null, c_adc); + } + + /* MIDI/iAP Core */ #if defined (MIDI) || defined IAP - on tile[AUDIO_IO_TILE]: { thread_speed(); #ifdef MIDI @@ -339,15 +319,49 @@ int main() } #endif + } +} +#ifndef USER_MAIN_DECLARATIONS +#define USER_MAIN_DECLARATIONS +#endif + +#ifndef USER_MAIN_CORES +#define USER_MAIN_CORES +#endif + +/* Main for USB Audio Applications */ +int main() +{ + chan c_mix_out; +#ifdef MIDI + chan c_midi; +#endif +#ifdef IAP + chan c_iap; +#endif + +#ifdef SU1_ADC_ENABLE + chan c_adc; +#else +#define c_adc null +#endif + + USER_MAIN_DECLARATIONS + + par + { + on tile[XUD_TILE]: usb_audio_core(c_mix_out); + + on tile[AUDIO_IO_TILE]: usb_audio_io(c_mix_out, c_adc); + + USER_MAIN_CORES + } #ifdef SU1_ADC_ENABLE xs1_su_adc_service(c_adc); #endif - - } + return 0; } - - From d252fa029c7752fffb26d01d18391603ca06ecae Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Fri, 29 Nov 2013 13:59:44 +0000 Subject: [PATCH 10/72] Fixed MIDI build issues --- module_usb_audio/main.xc | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/module_usb_audio/main.xc b/module_usb_audio/main.xc index 49236184..e8ba0489 100755 --- a/module_usb_audio/main.xc +++ b/module_usb_audio/main.xc @@ -209,7 +209,11 @@ void xscope_user_init() #endif /* Core USB Audio functions - must be called on the Tile connected to the USB Phy */ -void usb_audio_core(chanend c_mix_out) +void usb_audio_core(chanend c_mix_out +#ifdef MIDI +, chanend c_midi +#endif +) { chan c_sof; chan c_xud_out[EP_CNT_OUT]; /* Endpoint channels for XUD */ @@ -297,7 +301,11 @@ void usb_audio_core(chanend c_mix_out) } } -void usb_audio_io(chanend c_mix_out, chanend ?c_adc) +void usb_audio_io(chanend c_mix_out, chanend ?c_adc +#ifdef MIDI +, chanend c_midi +#endif +) { par { @@ -336,6 +344,8 @@ int main() chan c_mix_out; #ifdef MIDI chan c_midi; +#else +#define c_midi null #endif #ifdef IAP chan c_iap; @@ -351,9 +361,17 @@ int main() par { - on tile[XUD_TILE]: usb_audio_core(c_mix_out); + on tile[XUD_TILE]: usb_audio_core(c_mix_out +#ifdef MIDI + , c_midi +#endif +); - on tile[AUDIO_IO_TILE]: usb_audio_io(c_mix_out, c_adc); + on tile[AUDIO_IO_TILE]: usb_audio_io(c_mix_out, c_adc +#ifdef MIDI + , c_midi +#endif + ); USER_MAIN_CORES } From 1ec376c5917024b784c3aa71da8db1e78a25104f Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Fri, 29 Nov 2013 16:45:06 +0000 Subject: [PATCH 11/72] Adding BCD_DEVICE --- module_usb_audio/devicedefines.h | 6 ++++-- xpd.xml | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index 48397e2e..568e05ec 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -242,9 +242,11 @@ #define PID_AUDIO_2 (0x0002) #endif -/* Device release number in BCD: 0xJJMNi */ +/* Device release number in BCD: 0xJJMN */ #ifndef BCD_DEVICE -#define BCD_DEVICE ((XMOS_USB_AUD_APP_MAJOR_VERSION << 8) | ((XMOS_USB_AUD_APP_MINOR_VERSION&0xF) << 4) | (XMOS_USB_AUD_APP_POINT_VERSION&0xF)) +#define BCD_DEVICE (0x0630) + +//((XMOS_USB_AUD_APP_MAJOR_VERSION << 8) | ((XMOS_USB_AUD_APP_MINOR_VERSION&0xF) << 4) | (XMOS_USB_AUD_APP_POINT_VERSION&0xF)) #endif /* Addition interfaces based on defines */ diff --git a/xpd.xml b/xpd.xml index b1394ee6..bf987c6d 100644 --- a/xpd.xml +++ b/xpd.xml @@ -4,6 +4,11 @@ git://git/apps/sc_usb_audio USB Audio Shared Components XMOS + + + + + 1.0 False From 14737affac0cbe7ea2e6a9098c1c1dec332fbb37 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Fri, 29 Nov 2013 16:47:55 +0000 Subject: [PATCH 12/72] Added changelog --- CHANGELOG | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 CHANGELOG diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 00000000..8ae83f0e --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,9 @@ +sc_usb_audio +============ + +1.0.0 +----- + + * Initial release + + From 0042a125d3d04ed41559242ff79b115e5486d204 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Fri, 29 Nov 2013 16:48:29 +0000 Subject: [PATCH 13/72] Added changelog --- CHANGELOG | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 8ae83f0e..b0afae19 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,7 +3,6 @@ sc_usb_audio 1.0.0 ----- - * Initial release From 594507602196964946373cd844f388ff2a648615 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Fri, 29 Nov 2013 16:48:51 +0000 Subject: [PATCH 14/72] Added changelog --- CHANGELOG => CHANGELOG.rst | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename CHANGELOG => CHANGELOG.rst (100%) diff --git a/CHANGELOG b/CHANGELOG.rst similarity index 100% rename from CHANGELOG rename to CHANGELOG.rst From 919666222cdd349d589fd77e02b201e9a8a460b5 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Fri, 29 Nov 2013 16:51:38 +0000 Subject: [PATCH 15/72] Added changelog --- CHANGELOG.rst | 4 ++-- xpd.xml | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b0afae19..8d4a27ea 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,8 +1,8 @@ sc_usb_audio ============ -1.0.0 +6.3.0 ----- - * Initial release + * see sw_usb_audio for changelog diff --git a/xpd.xml b/xpd.xml index bf987c6d..34e9f6e9 100644 --- a/xpd.xml +++ b/xpd.xml @@ -1,6 +1,8 @@ + USB Audio Shared Components. For use in the XMOS USB Audio Refererence Designs. + False git://git/apps/sc_usb_audio USB Audio Shared Components XMOS @@ -10,5 +12,4 @@ 1.0 - False - + \ No newline at end of file From c8672b24ab261ec6800cbe0fe8ec18fd1f12aa48 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Fri, 29 Nov 2013 16:52:17 +0000 Subject: [PATCH 16/72] Reverted BCD_DEVICE to test xpd --- module_usb_audio/devicedefines.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index 568e05ec..626cd5ba 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -242,11 +242,13 @@ #define PID_AUDIO_2 (0x0002) #endif +#define BCD_DEVICE_J 6 +#define BCD_DEVICE_M 2 +#define BCD_DEVICE_N 0 + /* Device release number in BCD: 0xJJMN */ #ifndef BCD_DEVICE -#define BCD_DEVICE (0x0630) - -//((XMOS_USB_AUD_APP_MAJOR_VERSION << 8) | ((XMOS_USB_AUD_APP_MINOR_VERSION&0xF) << 4) | (XMOS_USB_AUD_APP_POINT_VERSION&0xF)) +#define BCD_DEVICE ((BCD_DEVICE_J << 8) | ((BCD_DEVICE&0xF) << 4) | (XMOS_USB_AUD_APP_POINT_VERSION&0xF)) #endif /* Addition interfaces based on defines */ From a86789d590a3bc59b72ead8384e1dc91817fbd34 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Fri, 29 Nov 2013 17:06:47 +0000 Subject: [PATCH 17/72] Updates by XPD --- .cproject | 172 ------------------------------- .project | 73 ------------- CHANGELOG.rst | 5 +- module_dfu/README.rst | 9 ++ module_usb_audio/README.rst | 9 ++ module_usb_audio_adat/README.rst | 9 ++ module_usb_midi/README.rst | 9 ++ xpd.xml | 1 + 8 files changed, 40 insertions(+), 247 deletions(-) delete mode 100644 .cproject delete mode 100644 .project create mode 100644 module_dfu/README.rst create mode 100644 module_usb_audio/README.rst create mode 100644 module_usb_audio_adat/README.rst create mode 100644 module_usb_midi/README.rst diff --git a/.cproject b/.cproject deleted file mode 100644 index 3ddfeef5..00000000 --- a/.cproject +++ /dev/null @@ -1,172 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -xmake --f .makefile -all -true -false -true - - -xmake --f Makefile -app_uart_test.all -true -true -true - - - - - - - - - diff --git a/.project b/.project deleted file mode 100644 index 43b408ff..00000000 --- a/.project +++ /dev/null @@ -1,73 +0,0 @@ - - - sc_usb_audio - - - - - - org.eclipse.cdt.managedbuilder.core.genmakebuilder - clean,full,incremental, - - - ?name? - - - - org.eclipse.cdt.make.core.append_environment - true - - - org.eclipse.cdt.make.core.buildArguments - -f Makefile - - - org.eclipse.cdt.make.core.buildCommand - xmake - - - org.eclipse.cdt.make.core.buildLocation - ${workspace_loc:/sc_usb_audio} - - - org.eclipse.cdt.make.core.cleanBuildTarget - clean - - - org.eclipse.cdt.make.core.contents - org.eclipse.cdt.make.core.activeConfigSettings - - - org.eclipse.cdt.make.core.enableAutoBuild - false - - - org.eclipse.cdt.make.core.enableCleanBuild - true - - - org.eclipse.cdt.make.core.enableFullBuild - true - - - org.eclipse.cdt.make.core.stopOnError - true - - - org.eclipse.cdt.make.core.useDefaultBuildCmd - false - - - - - org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder - - - - - - org.eclipse.cdt.managedbuilder.core.ScannerConfigNature - org.eclipse.cdt.managedbuilder.core.managedBuildNature - org.eclipse.cdt.core.cnature - - diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8d4a27ea..f83500fb 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,5 +1,6 @@ -sc_usb_audio -============ +sc_usb_audio Change Log +======================= + 6.3.0 ----- diff --git a/module_dfu/README.rst b/module_dfu/README.rst new file mode 100644 index 00000000..3e0884f9 --- /dev/null +++ b/module_dfu/README.rst @@ -0,0 +1,9 @@ + +================ + +:scope: +:description: +:keywords: +:boards: + + diff --git a/module_usb_audio/README.rst b/module_usb_audio/README.rst new file mode 100644 index 00000000..3e0884f9 --- /dev/null +++ b/module_usb_audio/README.rst @@ -0,0 +1,9 @@ + +================ + +:scope: +:description: +:keywords: +:boards: + + diff --git a/module_usb_audio_adat/README.rst b/module_usb_audio_adat/README.rst new file mode 100644 index 00000000..3e0884f9 --- /dev/null +++ b/module_usb_audio_adat/README.rst @@ -0,0 +1,9 @@ + +================ + +:scope: +:description: +:keywords: +:boards: + + diff --git a/module_usb_midi/README.rst b/module_usb_midi/README.rst new file mode 100644 index 00000000..3e0884f9 --- /dev/null +++ b/module_usb_midi/README.rst @@ -0,0 +1,9 @@ + +================ + +:scope: +:description: +:keywords: +:boards: + + diff --git a/xpd.xml b/xpd.xml index 34e9f6e9..d0cc6776 100644 --- a/xpd.xml +++ b/xpd.xml @@ -5,6 +5,7 @@ False git://git/apps/sc_usb_audio USB Audio Shared Components + xross XMOS From d36edf7218b6ad0cfbd0b9db31dcad6facdd0cf1 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Fri, 29 Nov 2013 17:19:34 +0000 Subject: [PATCH 18/72] module dfu readme updates --- module_dfu/README | 3 --- module_dfu/README.rst | 16 +++++++++------- module_usb_audio/devicedefines.h | 4 ++-- 3 files changed, 11 insertions(+), 12 deletions(-) delete mode 100644 module_dfu/README diff --git a/module_dfu/README b/module_dfu/README deleted file mode 100644 index 1a762260..00000000 --- a/module_dfu/README +++ /dev/null @@ -1,3 +0,0 @@ -Code providing firmware upgrade over USB. - -./host provides an example of a host application for DFU. This is written and tested for OSX. LibUSB is used to aid cross-platform porting. diff --git a/module_dfu/README.rst b/module_dfu/README.rst index 3e0884f9..a59b5807 100644 --- a/module_dfu/README.rst +++ b/module_dfu/README.rst @@ -1,9 +1,11 @@ - -================ +module_dfu +========== -:scope: -:description: -:keywords: -:boards: +:scope: General Use +:description: module_dfu +:keywords: DFU +:boards: XMOS USB Audio Reference Designes - +Code providing firmware upgrade over USB. + +./host provides an example of a host application for DFU. This is written and tested for OSX. LibUSB is used to aid cross-platform porting. diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index 626cd5ba..78d27336 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -243,12 +243,12 @@ #endif #define BCD_DEVICE_J 6 -#define BCD_DEVICE_M 2 +#define BCD_DEVICE_M 3 #define BCD_DEVICE_N 0 /* Device release number in BCD: 0xJJMN */ #ifndef BCD_DEVICE -#define BCD_DEVICE ((BCD_DEVICE_J << 8) | ((BCD_DEVICE&0xF) << 4) | (XMOS_USB_AUD_APP_POINT_VERSION&0xF)) +#define BCD_DEVICE ((BCD_DEVICE_J << 8) | ((BCD_DEVICE_M & 0xF) << 4) | (BCD_DEVICE_N & 0xF)) #endif /* Addition interfaces based on defines */ From b05d73e825eab080cc8efed82708e96d2b84efb7 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Wed, 4 Dec 2013 17:07:25 +0000 Subject: [PATCH 19/72] Fixed IAP build issue --- module_usb_audio/main.xc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/module_usb_audio/main.xc b/module_usb_audio/main.xc index e8ba0489..bf11106f 100755 --- a/module_usb_audio/main.xc +++ b/module_usb_audio/main.xc @@ -213,6 +213,9 @@ void usb_audio_core(chanend c_mix_out #ifdef MIDI , chanend c_midi #endif +#ifdef IAP +, chanend c_iap +#endif ) { chan c_sof; @@ -305,6 +308,9 @@ void usb_audio_io(chanend c_mix_out, chanend ?c_adc #ifdef MIDI , chanend c_midi #endif +#ifdef IAP +, chanend c_iap +#endif ) { par @@ -365,11 +371,17 @@ int main() #ifdef MIDI , c_midi #endif +#ifdef IAP + , c_iap +#endif ); on tile[AUDIO_IO_TILE]: usb_audio_io(c_mix_out, c_adc #ifdef MIDI , c_midi +#endif +#ifdef IAP + , c_iap #endif ); From 656edd6df9987ff1e8633a0e105afcb89272c9ee Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 4 Dec 2013 18:09:21 +0000 Subject: [PATCH 20/72] customdefines.h included in warnings.xc so warnings actually work --- module_usb_audio/devicedefines.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index 9436866c..8231dcef 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -226,24 +226,24 @@ /* Product string for Audio Class 2.0 mode */ #ifndef PRODUCT_STR_A2 -#define PRODUCT_STR_A2 "xCORE USB Audio 2.0" +#define PRODUCT_STR_A2 "xCORE USB Audio 2.0" #endif /* Product string for Audio Class 1.0 mode */ #ifndef PRODUCT_STR_A1 -#define PRODUCT_STR_A1 "xCORE USB Audio 1.0" +#define PRODUCT_STR_A1 "xCORE USB Audio 1.0" #endif /* USB Product ID (PID) for Audio Class 1.0 mode */ #if (AUDIO_CLASS==1) || defined(AUDIO_CLASS_FALLBACK) #ifndef PID_AUDIO_1 -#define PID_AUDIO_1 (0x0003) +#define PID_AUDIO_1 (0x0003) #endif #endif /* USB Product ID (PID) for Audio Class 2.0 mode */ #ifndef PID_AUDIO_2 -#define PID_AUDIO_2 (0x0002) +#define PID_AUDIO_2 (0x0002) #endif #define BCD_DEVICE_J 6 @@ -255,17 +255,21 @@ #define BCD_DEVICE ((BCD_DEVICE_J << 8) | ((BCD_DEVICE_M & 0xF) << 4) | (BCD_DEVICE_N & 0xF)) #endif +#if defined(IAP) && !defined(ACCESSORY_FIRMWARE_VERSION) +#define ACCESSORY_FIRMWARE_VERSION BCD_DEVICE +#endif + /* Addition interfaces based on defines */ #if defined(DFU) && DFU != 0 -#define DFU_INTERFACES (1) /* DFU interface count */ +#define DFU_INTERFACES (1) /* DFU interface count */ #else -#define DFU_INTERFACES (0) +#define DFU_INTERFACES (0) #endif #ifdef INPUT -#define INPUT_INTERFACES (1) +#define INPUT_INTERFACES (1) #else -#define INPUT_INTERFACES (0) +#define INPUT_INTERFACES (0) #endif #if defined(OUTPUT) && OUTPUT != 0 From b5bfaa17a404e0718af44636cc8146b9cdf9ef9f Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 4 Dec 2013 18:16:13 +0000 Subject: [PATCH 21/72] warnings.xc tidy --- module_usb_audio/warnings.xc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/module_usb_audio/warnings.xc b/module_usb_audio/warnings.xc index 6617ab42..59acf5cf 100644 --- a/module_usb_audio/warnings.xc +++ b/module_usb_audio/warnings.xc @@ -1,5 +1,9 @@ -/* Warnings relating to defines have been moved to this XC file to avoid multiple warnings being issued from the devicedefines.h header file */ +/* +Warnings relating to configuration defines located in this XC source file rather than the devicedefines.h header file in order to avoid multiple warnings being issued when the devicedefines.h header file is included in multiple files. +*/ + +#include "customdefines.h" #ifndef DEFAULT_FREQ #warning DEFAULT_FREQ not defined. Using MIN_FREQ @@ -34,7 +38,7 @@ #endif #ifndef BCD_DEVICE -#warning BCD_DEVICE not defined. Using 0x0620 +#warning BCD_DEVICE not defined. Using XMOS release version number #endif #if (AUDIO_CLASS==1) || defined(AUDIO_CLASS_FALLBACK) @@ -52,6 +56,6 @@ #endif #ifndef AUDIO_CLASS_FALLBACK -#warning AUDIO_CLASS_FALLBACK not defined, using 0 +#warning AUDIO_CLASS_FALLBACK not defined, using 0 (i.e. disabled) #endif From 39207ac7f41e8806dae6c04611c52b0795c5cb2c Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Wed, 4 Dec 2013 18:24:05 +0000 Subject: [PATCH 22/72] Fixed iAP firmware version format --- module_usb_audio/devicedefines.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index 8231dcef..fd10ba89 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -256,7 +256,7 @@ #endif #if defined(IAP) && !defined(ACCESSORY_FIRMWARE_VERSION) -#define ACCESSORY_FIRMWARE_VERSION BCD_DEVICE +#define ACCESSORY_FIRMWARE_VERSION {BCD_DEVICE_J, BCD_DEVICE_M, BCD_DEVICE_N} #endif /* Addition interfaces based on defines */ From a3480befd621d24a26d68c8f762b0d9aa3158331 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Wed, 4 Dec 2013 18:39:39 +0000 Subject: [PATCH 23/72] Whitespace only --- module_usb_audio/devicedefines.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index fd10ba89..f07f4ad9 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -256,7 +256,7 @@ #endif #if defined(IAP) && !defined(ACCESSORY_FIRMWARE_VERSION) -#define ACCESSORY_FIRMWARE_VERSION {BCD_DEVICE_J, BCD_DEVICE_M, BCD_DEVICE_N} +#define ACCESSORY_FIRMWARE_VERSION {BCD_DEVICE_J, BCD_DEVICE_M, BCD_DEVICE_N} #endif /* Addition interfaces based on defines */ From a90878a94b192131df98862b7bd6be520e0be1dc Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Thu, 5 Dec 2013 11:16:20 +0000 Subject: [PATCH 24/72] Removed uppercase letters from file names from module_iap --- module_usb_audio/main.xc | 2 +- module_usb_audio/usb_buffer/usb_buffer.xc | 2 +- module_usb_midi/src/usb_midi.xc | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/module_usb_audio/main.xc b/module_usb_audio/main.xc index bf11106f..c54d1d55 100755 --- a/module_usb_audio/main.xc +++ b/module_usb_audio/main.xc @@ -25,7 +25,7 @@ #include "audio.h" #ifdef IAP -#include "iAP.h" +#include "iap.h" #endif #ifndef AUDIO_IO_TILE diff --git a/module_usb_audio/usb_buffer/usb_buffer.xc b/module_usb_audio/usb_buffer/usb_buffer.xc index a8a41f79..2f6cc64f 100644 --- a/module_usb_audio/usb_buffer/usb_buffer.xc +++ b/module_usb_audio/usb_buffer/usb_buffer.xc @@ -8,7 +8,7 @@ #include "usb_midi.h" #endif #ifdef IAP -#include "iAP.h" +#include "iap.h" #endif #include "xc_ptr.h" #include "commands.h" diff --git a/module_usb_midi/src/usb_midi.xc b/module_usb_midi/src/usb_midi.xc index 4a9c2403..e4b1550a 100644 --- a/module_usb_midi/src/usb_midi.xc +++ b/module_usb_midi/src/usb_midi.xc @@ -7,8 +7,8 @@ #include "midioutparse.h" #include "queue.h" #ifdef IAP -#include "iAP.h" -#include "iapuser.h" +#include "iap.h" +#include "iap_user.h" #endif //#define MIDI_LOOPBACK 1 int icount = 0; From d3398ef523b4245d8e501a24239c786c7c560d9b Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Thu, 5 Dec 2013 12:22:30 +0000 Subject: [PATCH 25/72] Added iap_conf.h include to avoid ACCESSORY_FIRMWARE_VERSION redefinition risk --- module_usb_audio/devicedefines.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index f07f4ad9..9a4a8c31 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -8,6 +8,10 @@ #include "customdefines.h" +#ifdef __iap_conf_h_exists__ +#include "iap_conf.h" +#endif + /* Tidy up historical INPUT/OUTPUT defines. INPUT/OUTPUT now enabled based on channel count defines */ #if !defined(NUM_USB_CHAN_IN) #error NUM_USB_CHAN_IN must be defined! From 2b3f9ea5caac86eeccf4c5fc95b11d6d00e36303 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Fri, 6 Dec 2013 14:48:47 +0000 Subject: [PATCH 26/72] iap_conf.h no longer included in devicedefines.h --- module_usb_audio/devicedefines.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index 9a4a8c31..f07f4ad9 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -8,10 +8,6 @@ #include "customdefines.h" -#ifdef __iap_conf_h_exists__ -#include "iap_conf.h" -#endif - /* Tidy up historical INPUT/OUTPUT defines. INPUT/OUTPUT now enabled based on channel count defines */ #if !defined(NUM_USB_CHAN_IN) #error NUM_USB_CHAN_IN must be defined! From 5ecc36096f26772d335a5edae1f5155a4ba25f5d Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Fri, 6 Dec 2013 16:26:11 +0000 Subject: [PATCH 27/72] Improved iAP case function name --- module_usb_midi/src/usb_midi.xc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module_usb_midi/src/usb_midi.xc b/module_usb_midi/src/usb_midi.xc index e4b1550a..44ee1af8 100644 --- a/module_usb_midi/src/usb_midi.xc +++ b/module_usb_midi/src/usb_midi.xc @@ -331,11 +331,11 @@ void usb_midi(port ?p_midi_in, port ?p_midi_out, /* Check for special case where MIDI ports are shared with i2c ports */ if(isnull(c_i2c) && isnull(p_scl) && isnull(p_sda)) { - handle_iap_case(is_ack, is_reset, datum, c_iap, c_i2c, p_midi_out, p_midi_in); + iap_handle_ack_or_reset_or_data(is_ack, is_reset, datum, c_iap, c_i2c, p_midi_out, p_midi_in); } else { - handle_iap_case(is_ack, is_reset, datum, c_iap, c_i2c, p_scl, p_sda); + iap_handle_ack_or_reset_or_data(is_ack, is_reset, datum, c_iap, c_i2c, p_scl, p_sda); } if (!authenticating) { From 9c531dbafe459d43f6c93b35a46b6db8ef04f2cc Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Fri, 6 Dec 2013 16:28:36 +0000 Subject: [PATCH 28/72] Improved iAP case function name --- module_usb_midi/src/usb_midi.xc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_midi/src/usb_midi.xc b/module_usb_midi/src/usb_midi.xc index 44ee1af8..f037ecd0 100644 --- a/module_usb_midi/src/usb_midi.xc +++ b/module_usb_midi/src/usb_midi.xc @@ -347,7 +347,7 @@ void usb_midi(port ?p_midi_in, port ?p_midi_out, /* Slow timer looking for IDevice plug/unplug event */ case iAPTimer when timerafter(polltime) :> void: printintln(polltime); - handle_poll_dev_det(iAPTimer); + iap_handle_poll_dev_det(iAPTimer); break; #endif } From 042d8f1969e10f17a654d5ec3fe9e81e94a49855 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Mon, 9 Dec 2013 15:46:04 +0000 Subject: [PATCH 29/72] Re-instated mixer core on main() --- module_usb_audio/main.xc | 44 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/module_usb_audio/main.xc b/module_usb_audio/main.xc index c54d1d55..c685c0de 100755 --- a/module_usb_audio/main.xc +++ b/module_usb_audio/main.xc @@ -28,6 +28,10 @@ #include "iap.h" #endif +#ifdef MIXER +#include "mixer.h" +#endif + #ifndef AUDIO_IO_TILE #define AUDIO_IO_TILE 0 #endif @@ -216,6 +220,9 @@ void usb_audio_core(chanend c_mix_out #ifdef IAP , chanend c_iap #endif +#ifdef MIXER +, chanend c_mix_ctl +#endif ) { chan c_sof; @@ -232,6 +239,11 @@ void usb_audio_core(chanend c_mix_out #warning Using channel to control buffering - this may reduce performance but improve power consumption chan c_buff_ctrl; #endif + +#ifndef MIXER +#define c_mix_ctl null +#endif + par { /* USB Interface Core */ @@ -289,7 +301,7 @@ 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, null, null, c_usb_test); + Endpoint0( c_xud_out[0], c_xud_in[0], c_aud_ctl, c_mix_ctl, null, c_usb_test); } /* Decoupling core */ @@ -304,21 +316,38 @@ void usb_audio_core(chanend c_mix_out } } -void usb_audio_io(chanend c_mix_out, chanend ?c_adc +void usb_audio_io(chanend c_aud_in, chanend ?c_adc #ifdef MIDI , chanend c_midi #endif #ifdef IAP , chanend c_iap #endif +#ifdef MIXER +, chanend c_mix_ctl +#endif ) { + chan c_mix_out; + par { + +#ifdef MIXER + /* Mixer cores(s) */ + { + thread_speed(); + mixer(c_aud_in, c_mix_out, c_mix_ctl); + } +#endif /* Audio I/O Core (pars additional S/PDIF TX Core) */ { thread_speed(); +#ifdef MIXER audio(c_mix_out, null, null, c_adc); +#else + audio(c_aud_in, null, null, c_adc); +#endif } /* MIDI/iAP Core */ @@ -363,6 +392,10 @@ int main() #define c_adc null #endif +#ifdef MIXER + chan c_mix_ctl; +#endif + USER_MAIN_DECLARATIONS par @@ -374,6 +407,9 @@ int main() #ifdef IAP , c_iap #endif +#ifdef MIXER + , c_mix_ctl +#endif ); on tile[AUDIO_IO_TILE]: usb_audio_io(c_mix_out, c_adc @@ -383,6 +419,10 @@ int main() #ifdef IAP , c_iap #endif +#ifdef MIXER + , c_mix_ctl +#endif + ); USER_MAIN_CORES From 51e9415a57d3d830231f72154bb0274440ea4d85 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Mon, 9 Dec 2013 15:47:59 +0000 Subject: [PATCH 30/72] Mixer communications updated for new underflow protocol --- module_usb_audio/mixer/mixer.xc | 35 ++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/module_usb_audio/mixer/mixer.xc b/module_usb_audio/mixer/mixer.xc index cf0f8417..b8910309 100644 --- a/module_usb_audio/mixer/mixer.xc +++ b/module_usb_audio/mixer/mixer.xc @@ -1,7 +1,6 @@ #include -#include #include "mixer.h" #include "devicedefines.h" #include "xc_ptr.h" @@ -184,8 +183,10 @@ void giveSamplesToHost(chanend c, xc_ptr samples, xc_ptr ptr, xc_ptr multIn) } #pragma unsafe arrays -static void getSamplesFromHost(chanend c, xc_ptr samples, int base) +static void getSamplesFromHost(chanend c, xc_ptr samples, int base, unsigned underflow) { + if(!underflow) + { #pragma loop unroll for (int i=0;i 0 outuint(c_mixer2, 0); giveSamplesToHost(c_host, samples, samples_to_host_map, multIn); @@ -506,10 +511,10 @@ void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2) } #else /* IF MAX_MIX_COUNT > 0 */ /* No mixes, this thread runs on its own doing just volume */ - giveSamplesToDevice(c_mixer2, samples, samples_to_device_map, multOut); + giveSamplesToDevice(c_mixer2, samples, samples_to_device_map, multOut, underflow); getSamplesFromDevice(c_mixer2, samples, NUM_USB_CHAN_OUT); giveSamplesToHost(c_host, samples, samples_to_host_map, multIn); - getSamplesFromHost(c_host, samples, 0); + getSamplesFromHost(c_host, samples, 0, underflow); #endif } } @@ -517,6 +522,7 @@ void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2) int mixer2_mix2_flag = (DEFAULT_FREQ > 96000); +#if (MAX_MIX_COUNT > 0) #pragma unsafe arrays void mixer2(chanend c_mixer1, chanend c_audio) { @@ -622,6 +628,7 @@ void mixer2(chanend c_mixer1, chanend c_audio) } } } +#endif void mixer(chanend c_mix_in, chanend c_mix_out, chanend c_mix_ctl) { From 5c7366eec2f0a82427cec873edfe12c4253a7ef8 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Mon, 9 Dec 2013 15:48:25 +0000 Subject: [PATCH 31/72] Mixer descriptors now only enabled if MAX_MIX_COUNT > 0 --- module_usb_audio/endpoint0/descriptors.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module_usb_audio/endpoint0/descriptors.h b/module_usb_audio/endpoint0/descriptors.h index 8f76168a..ef8a0b6e 100644 --- a/module_usb_audio/endpoint0/descriptors.h +++ b/module_usb_audio/endpoint0/descriptors.h @@ -191,7 +191,7 @@ unsigned char devQualDesc_Null[] = #define LEN_XU_IN (0) #endif -#ifdef MIXER +#if defined (MIXER) && (MAX_MIX_COUNT > 0) #define LEN_XU_MIX (17) #define MIX_BMCONTROLS_LEN_TMP ((MAX_MIX_COUNT * MIX_INPUTS) / 8) @@ -698,7 +698,7 @@ unsigned char cfgDesc_Audio2[] = -#ifdef MIXER +#if defined (MIXER) && (MAX_MIX_COUNT > 0) /* Extension Unit Descriptor (4.7.2.12) */ LEN_XU_MIX, /* 0 bLength (15 + p, when p is number of sources) */ CS_INTERFACE, /* 1 bDescriptorType */ From 1ce3c74ebc3d39a222e406d0db79a1f3e56e7c43 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Mon, 9 Dec 2013 15:49:50 +0000 Subject: [PATCH 32/72] Deliver to/from mixer comms fixed up for new underflow protocol --- module_usb_audio/audio.xc | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/module_usb_audio/audio.xc b/module_usb_audio/audio.xc index c6a3821f..e1e9a94c 100755 --- a/module_usb_audio/audio.xc +++ b/module_usb_audio/audio.xc @@ -209,8 +209,8 @@ static inline void doI2SClocks(unsigned divide) } else { -#ifndef MIXER // Interfaces straight to decouple() underflow = inuint(c_out); +#ifndef MIXER // Interfaces straight to decouple() #if NUM_USB_CHAN_IN > 0 #pragma loop unroll @@ -238,7 +238,18 @@ static inline void doI2SClocks(unsigned divide) } } #endif -#else +#else /* ifndef MIXER */ + + if(underflow) + { + #pragma loop unroll + for(int i = 0; i < NUM_USB_CHAN_OUT; i++) + { + samplesOut[i] = underflowWord; + } + } + else + { #pragma loop unroll for(int i = 0; i < NUM_USB_CHAN_OUT; i++) { @@ -248,6 +259,7 @@ static inline void doI2SClocks(unsigned divide) #endif samplesOut[i] = tmp; } + } #pragma loop unroll for(int i = 0; i < NUM_USB_CHAN_IN; i++) @@ -387,8 +399,8 @@ static inline void doI2SClocks(unsigned divide) } else { -#ifndef MIXER // Interfaces straight to decouple() underflow = inuint(c_out); +#ifndef MIXER // Interfaces straight to decouple() #if NUM_USB_CHAN_IN > 0 #pragma loop unroll for(int i = 0; i < NUM_USB_CHAN_IN; i++) @@ -416,14 +428,25 @@ static inline void doI2SClocks(unsigned divide) } #endif #else /* ifndef MIXER */ -#pragma loop unroll - for(int i = 0; i < NUM_USB_CHAN_OUT; i++) + + if(underflow) + { + for(int i = 0; i < NUM_USB_CHAN_OUT; i++) + { + samplesOut[i] = underflowWord; + } + } + else { - int tmp = inuint(c_out); +#pragma loop unroll + for(int i = 0; i < NUM_USB_CHAN_OUT; i++) + { + int tmp = inuint(c_out); #if defined(OUT_VOLUME_IN_MIXER) && defined(OUT_VOLUME_AFTER_MIX) - tmp<<=3; + tmp<<=3; #endif - samplesOut[i] = tmp; + samplesOut[i] = tmp; + } } #pragma loop unroll From c0129c683a676f8b147fe0420441daf34c0fa985 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Mon, 9 Dec 2013 15:58:35 +0000 Subject: [PATCH 33/72] Mixer related L2 app build issues patched up --- module_usb_audio/endpoint0/audiorequests.xc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/module_usb_audio/endpoint0/audiorequests.xc b/module_usb_audio/endpoint0/audiorequests.xc index 57ae892a..eb2c3f70 100644 --- a/module_usb_audio/endpoint0/audiorequests.xc +++ b/module_usb_audio/endpoint0/audiorequests.xc @@ -583,10 +583,10 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c break; /* FU_USBIN */ -#ifdef MIXER +#if defined(MIXER) && (MAX_MIX_COUNT > 0) case ID_XU_OUT: { - if(sp.bmRequestType.Direction == BM_REQTYPE_DIRECTION_H2D) /* Direction: Host-to-device */ + if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) /* Direction: Host-to-device */ { unsigned volume = 0; int c = sp.wValue & 0xff; @@ -624,7 +624,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c break; case ID_XU_IN: - if(sp.bmRequestType.Direction == BM_REQTYPE_DIRECTION_H2D) /* Direction: Host-to-device */ + if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) /* Direction: Host-to-device */ { unsigned volume = 0; int c = sp.wValue & 0xff; @@ -660,10 +660,10 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c case ID_XU_MIXSEL: { int cs = sp.wValue >> 8; /* Control Selector */ - int cn = sp.wValue & 0xff; /* Channel number */ + int cn = sp.wValue & 0xff; /* Channel number */ /* Check for Get or Set */ - if(sp.bmRequestType.Direction == BM_REQTYPE_DIRECTION_OUT) + if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_OUT) { /* Direction: Host-to-device */ /* Host-to-device */ datalength = XUD_GetBuffer(ep0_out, buffer); @@ -720,7 +720,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c case ID_MIXER_1: - if(sp.bmRequestType.Direction == BM_REQTYPE_DIRECTION_OUT) /* Direction: Host-to-device */ + if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_OUT) /* Direction: Host-to-device */ { unsigned volume = 0; @@ -884,7 +884,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c break; /* case: RANGE */ } -#ifdef MIXER +#if defined (MIXER) && (MAX_MIX_COUNT > 0) case MEM: /* Memory Requests (5.2.7.1) */ unitID = sp.wIndex >> 8; @@ -893,7 +893,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c { case ID_MIXER_1: - if(sp.bmRequestType.Direction == BM_REQTYPE_DIRECTION_IN) + if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_IN) { int length = 0; From bfca1da4097a8dcfc567de3c5bedfef3546a4582 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Mon, 9 Dec 2013 16:03:28 +0000 Subject: [PATCH 34/72] Quick patch to fix TX channel strings --- module_usb_audio/endpoint0/descriptors.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/endpoint0/descriptors.h b/module_usb_audio/endpoint0/descriptors.h index ef8a0b6e..a88031d4 100644 --- a/module_usb_audio/endpoint0/descriptors.h +++ b/module_usb_audio/endpoint0/descriptors.h @@ -1429,7 +1429,7 @@ unsigned char cfgDesc_Audio2[] = #define DFU_NUM_STRS 0 #endif -#define STR_INDEX_OUT_CHAN (10 + SPDIF_RX_NUM_STRS + ADAT_RX_NUM_STRS + MIDI_NUM_STRS + DFU_NUM_STRS) +#define STR_INDEX_OUT_CHAN (15 + SPDIF_RX_NUM_STRS + ADAT_RX_NUM_STRS + MIDI_NUM_STRS + DFU_NUM_STRS) #define STR_INDEX_IN_CHAN (STR_INDEX_OUT_CHAN + NUM_USB_CHAN_OUT) #define APPEND_VENDOR_STR(x) VENDOR_STR" "#x From 93590833cf3a9ed478be4a04e6df9d401f1a95aa Mon Sep 17 00:00:00 2001 From: Richard Osborne Date: Thu, 28 Nov 2013 14:12:51 +0000 Subject: [PATCH 35/72] Add resource usage symbols / elimination blocks to assembly files. See bug 10909 and bug 15022. --- module_usb_audio/locks/lock.S | 68 ++++++++++++----- module_usb_audio/mixer/fastmix.S | 15 +++- module_usb_audio/write_sswitch_reg_blind.S | 88 +++++++++++----------- 3 files changed, 109 insertions(+), 62 deletions(-) diff --git a/module_usb_audio/locks/lock.S b/module_usb_audio/locks/lock.S index 5d5ddb49..cb955077 100644 --- a/module_usb_audio/locks/lock.S +++ b/module_usb_audio/locks/lock.S @@ -5,47 +5,81 @@ #include +.text ///////////////////////////////////////////////////////////////////////// // void GetLockResource() -.globl GetLockResource.nstackwords -.linkset GetLockResource.nstackwords, 0 .globl GetLockResource -.text +.type GetLockResource, @function +.cc_top GetLockResource.function +.align 2 GetLockResource: getr r0, XS1_RES_TYPE_LOCK retsp 0 - +.size GetLockResource, .-GetLockResource +.cc_bottom GetLockResource.function +.globl GetLockResource.nstackwords +.globl GetLockResource.maxcores +.globl GetLockResource.maxchanends +.globl GetLockResource.maxtimers +.set GetLockResource.nstackwords, 0 +.set GetLockResource.maxcores, 1 +.set GetLockResource.maxchanends, 0 +.set GetLockResource.maxtimers, 0 ///////////////////////////////////////////////////////////////////////// // void ClaimLock(lock l) -.globl ClaimLock.nstackwords -.linkset ClaimLock.nstackwords, 0 .globl ClaimLock -.text +.type ClaimLock, @function +.cc_top ClaimLock.function +.align 2 ClaimLock: in r0, res[r0] retsp 0 - +.size ClaimLock, .-ClaimLock +.cc_bottom ClaimLock.function +.globl ClaimLock.nstackwords +.globl ClaimLock.maxcores +.globl ClaimLock.maxchanends +.globl ClaimLock.maxtimers +.set ClaimLock.nstackwords, 0 +.set ClaimLock.maxcores, 1 +.set ClaimLock.maxchanends, 0 +.set ClaimLock.maxtimers, 0 ///////////////////////////////////////////////////////////////////////// // void FreeLock(lock l) -.globl FreeLock.nstackwords -.linkset FreeLock.nstackwords, 0 .globl FreeLock -.text +.cc_top FreeLock.function +.align 2 FreeLock: out res[r0], r0 retsp 0 - +.size FreeLock, .-FreeLock +.cc_bottom FreeLock.function +.globl FreeLock.nstackwords +.globl FreeLock.maxcores +.globl FreeLock.maxchanends +.globl FreeLock.maxtimers +.set FreeLock.nstackwords, 0 +.set FreeLock.maxcores, 1 +.set FreeLock.maxchanends, 0 +.set FreeLock.maxtimers, 0 ///////////////////////////////////////////////////////////////////////// // void FreeLockResource(lock l) -.globl FreeLockResource.nstackwords -.linkset FreeLockResource.nstackwords, 0 .globl FreeLockResource -.text +.cc_top FreeLockResource.function +.align 2 FreeLockResource: freer res[r0] retsp 0 - - +.size FreeLockResource, .-FreeLockResource +.cc_bottom FreeLockResource.function +.globl FreeLockResource.nstackwords +.globl FreeLockResource.maxcores +.globl FreeLockResource.maxchanends +.globl FreeLockResource.maxtimers +.set FreeLockResource.nstackwords, 0 +.set FreeLockResource.maxcores, 1 +.set FreeLockResource.maxchanends, 0 +.set FreeLockResource.maxtimers, 0 diff --git a/module_usb_audio/mixer/fastmix.S b/module_usb_audio/mixer/fastmix.S index 16e3c703..af8ca56f 100644 --- a/module_usb_audio/mixer/fastmix.S +++ b/module_usb_audio/mixer/fastmix.S @@ -9,6 +9,7 @@ .cc_top doMix##i.function,doMix##i; \ .align 4 ;\ .globl doMix##i ;\ +.type doMix##i, @function ;\ .globl doMix##i##.nstackwords ;\ .globl doMix##i##.maxthreads ; \ .globl doMix##i##.maxtimers ; \ @@ -42,6 +43,7 @@ doMix##i##: ;\ retsp 0x0;\ \ \ +.size doMix##i, .-doMix##i; \ .cc_bottom doMix##i##.function; #define N MIX_INPUTS @@ -124,9 +126,10 @@ DOMIX_BOT(7) #undef BODY #define N MAX_MIX_COUNT .cc_top setPtr.function,setPtr; - .align 4 ; -.globl setPtr.nstackwords; +.align 4 ; .globl setPtr; +.type setPtr, @function +.globl setPtr.nstackwords; .globl setPtr.maxthreads; .globl setPtr.maxtimers; .globl setPtr.maxchanends; @@ -151,14 +154,20 @@ setPtr_go: add r1, r1, r2; st8 r1, r11[r0]; retsp 0; +.size setPtr, .-setPtr .cc_bottom setPtr.function .section .cp.const4, "acM", @progbits, 4 -.LC0: +.cc_top .LC0.data .align 4 +.LC0: .int 0x7fffff00 +.cc_bottom .LC0.data +.cc_top .LC1.data + .align 4 .LC1: .int 0x80000000 +.cc_bottom .LC1.data #undef N #undef BODY diff --git a/module_usb_audio/write_sswitch_reg_blind.S b/module_usb_audio/write_sswitch_reg_blind.S index 35861075..5aede664 100644 --- a/module_usb_audio/write_sswitch_reg_blind.S +++ b/module_usb_audio/write_sswitch_reg_blind.S @@ -1,59 +1,63 @@ - #include "xs1_kernel.h" #include "xs1_user.h" - - .global write_sswitch_reg_blind, "f{si}(ui,ui,ui)" -.global write_sswitch_reg_blind.nstackwords -.linkset write_sswitch_reg_blind.nstackwords, 0 -//.type read_sswitch_reg, @function +.type write_sswitch_reg_blind, @function // r0 - coreid // r1 - reg // r2 - data .cc_top write_sswitch_reg_blind.function, write_sswitch_reg_blind .align 2 write_sswitch_reg_blind: - // Check range of coreid + // Check range of coreid shr r3, r0, XS1_CHAN_ID_PROCESSOR_SIZE + XS1_CHAN_ID_NODE_SIZE - bt r3, write_switch_reg_fail + bt r3, write_switch_reg_fail - // Check range of reg - shr r3, r1, 16 - bt r3, write_switch_reg_fail + // Check range of reg + shr r3, r1, 16 + bt r3, write_switch_reg_fail - // Allocate channel end - getr r3, XS1_RES_TYPE_CHANEND + // Allocate channel end + getr r3, XS1_RES_TYPE_CHANEND - // Set destination - ldc r11, XS1_RES_TYPE_CONFIG | (XS1_CT_SSCTRL << XS1_CHAN_ID_CHANNUM_SHIFT) + // Set destination + ldc r11, XS1_RES_TYPE_CONFIG | (XS1_CT_SSCTRL << XS1_CHAN_ID_CHANNUM_SHIFT) - // r0 - l - // r1 - reg - // r2 - data - // r3 - chanend - // r11 - low half of dest - write_switch_reg: - shl r0, r0, XS1_CHAN_ID_PROCESSOR_SHIFT - or r0, r0, r11 - setd res[r3], r0 + // r0 - l + // r1 - reg + // r2 - data + // r3 - chanend + // r11 - low half of dest + write_switch_reg: + shl r0, r0, XS1_CHAN_ID_PROCESSOR_SHIFT + or r0, r0, r11 + setd res[r3], r0 - // Send packet - ldc r11, XS1_CT_WRITEC // Too big for outct immediate - outct res[r3], r11 - mkmsk r0, 32 - shl r0, r0, 8 - shr r11, r1, 8 - or r0, r0, r11 - out res[r3], r0 // (0xffffff00) | (reg >> 8) - outt res[r3], r1 // reg & 0xff - out res[r3], r2 - outct res[r3], XS1_CT_END + // Send packet + ldc r11, XS1_CT_WRITEC // Too big for outct immediate + outct res[r3], r11 + mkmsk r0, 32 + shl r0, r0, 8 + shr r11, r1, 8 + or r0, r0, r11 + out res[r3], r0 // (0xffffff00) | (reg >> 8) + outt res[r3], r1 // reg & 0xff + out res[r3], r2 + outct res[r3], XS1_CT_END - // Receive response - freer res[r3] - retsp 0 - write_switch_reg_fail: - ldc r0, 0 - retsp 0 - .cc_bottom write_sswitch_reg_blind.function + // Receive response + freer res[r3] + retsp 0 + write_switch_reg_fail: + ldc r0, 0 + retsp 0 +.size write_sswitch_reg_blind, .-write_sswitch_reg_blind +.cc_bottom write_sswitch_reg_blind.function +.global write_sswitch_reg_blind.nstackwords +.global write_sswitch_reg_blind.maxchanends +.global write_sswitch_reg_blind.maxtimers +.global write_sswitch_reg_blind.maxcores +.set write_sswitch_reg_blind.nstackwords, 0 +.set write_sswitch_reg_blind.maxchanends, 1 +.set write_sswitch_reg_blind.maxtimers, 0 +.set write_sswitch_reg_blind.maxcores, 0 From f19653b759eb16616603cbd721bca92822ea032a Mon Sep 17 00:00:00 2001 From: Richard Osborne Date: Thu, 28 Nov 2013 13:49:51 +0000 Subject: [PATCH 36/72] Remove pointless .extern directives. These have no effect and are ignored by the assembler. --- module_usb_audio/locks/lock.S | 4 ---- 1 file changed, 4 deletions(-) diff --git a/module_usb_audio/locks/lock.S b/module_usb_audio/locks/lock.S index 5e2e10da..5d5ddb49 100644 --- a/module_usb_audio/locks/lock.S +++ b/module_usb_audio/locks/lock.S @@ -7,7 +7,6 @@ ///////////////////////////////////////////////////////////////////////// // void GetLockResource() -.extern GetLockResource .globl GetLockResource.nstackwords .linkset GetLockResource.nstackwords, 0 .globl GetLockResource @@ -19,7 +18,6 @@ GetLockResource: ///////////////////////////////////////////////////////////////////////// // void ClaimLock(lock l) -.extern ClaimLock .globl ClaimLock.nstackwords .linkset ClaimLock.nstackwords, 0 .globl ClaimLock @@ -31,7 +29,6 @@ ClaimLock: ///////////////////////////////////////////////////////////////////////// // void FreeLock(lock l) -.extern FreeLock .globl FreeLock.nstackwords .linkset FreeLock.nstackwords, 0 .globl FreeLock @@ -43,7 +40,6 @@ FreeLock: ///////////////////////////////////////////////////////////////////////// // void FreeLockResource(lock l) -.extern FreeLockResource .globl FreeLockResource.nstackwords .linkset FreeLockResource.nstackwords, 0 .globl FreeLockResource From a695e58524b1615a8bfd487bed1e555b2cbea362 Mon Sep 17 00:00:00 2001 From: Richard Osborne Date: Fri, 29 Nov 2013 18:36:35 +0000 Subject: [PATCH 37/72] Add a new module implementing a queue data structure. Since the functions are simple make them inline functions. This provides a small code size saving. --- module_queue/module_build_info | 14 ++++ module_queue/module_description | 1 + module_queue/src/queue.h | 54 ++++++++++++++ module_queue/src/queue.xc | 11 +++ module_usb_midi/module_build_info | 1 + module_usb_midi/src/queue.c | 84 ---------------------- module_usb_midi/src/queue.h | 25 ------- module_usb_midi/src/usb_midi.xc | 36 +++++----- tests/app_queue_test/Makefile | 32 +++++++++ tests/app_queue_test/src/app_queue_test.xc | 32 +++++++++ 10 files changed, 164 insertions(+), 126 deletions(-) create mode 100644 module_queue/module_build_info create mode 100644 module_queue/module_description create mode 100644 module_queue/src/queue.h create mode 100644 module_queue/src/queue.xc delete mode 100644 module_usb_midi/src/queue.c delete mode 100644 module_usb_midi/src/queue.h create mode 100644 tests/app_queue_test/Makefile create mode 100644 tests/app_queue_test/src/app_queue_test.xc diff --git a/module_queue/module_build_info b/module_queue/module_build_info new file mode 100644 index 00000000..84cb704f --- /dev/null +++ b/module_queue/module_build_info @@ -0,0 +1,14 @@ +# You can set flags specifically for your module by using the MODULE_XCC_FLAGS +# variable. So the following +# +# MODULE_XCC_FLAGS = $(XCC_FLAGS) -O3 +# +# specifies that everything in the modules should have the application +# build flags with -O3 appended (so the files will build at +# optimization level -O3). +# +# You can also set MODULE_XCC_C_FLAGS, MODULE_XCC_XC_FLAGS etc.. + +MODULE_XCC_XC_FLAGS = $(XCC_XC_FLAGS) + +DEPENDENT_MODULES = module_xassert diff --git a/module_queue/module_description b/module_queue/module_description new file mode 100644 index 00000000..00a6de45 --- /dev/null +++ b/module_queue/module_description @@ -0,0 +1 @@ +One line module description. diff --git a/module_queue/src/queue.h b/module_queue/src/queue.h new file mode 100644 index 00000000..23e4cea5 --- /dev/null +++ b/module_queue/src/queue.h @@ -0,0 +1,54 @@ +#ifndef QUEUE_H_ +#define QUEUE_H_ + +#include + +typedef struct queue_t { + /// Read index. + unsigned rdptr; + /// Write index. + unsigned wrptr; + unsigned size; + unsigned mask; +} queue_t; + +inline int is_power_of_2(unsigned x) { + return x != 0 && (x & (x - 1)) == 0; +} + +inline void queue_init(queue_t &q, unsigned size) { + assert(is_power_of_2(size)); + q.rdptr = 0; + q.wrptr = 0; + q.size = size; + q.mask = size - 1; // Assumes power of two. +} + +inline int queue_is_empty(const queue_t &q) { + return q.wrptr == q.rdptr; +} + +inline int queue_is_full(const queue_t &q) { + return q.wrptr - q.rdptr == q.size; +} + +inline void queue_push_word(queue_t &q, unsigned array[], unsigned data) +{ + assert(!queue_is_full(q)); + array[q.wrptr++ & q.mask] = data; +} + +inline unsigned queue_pop_word(queue_t &q, unsigned array[]) { + assert(!queue_is_empty(q)); + return array[q.rdptr++ & q.mask]; +} + +inline unsigned queue_items(const queue_t &q) { + return q.wrptr - q.rdptr; +} + +inline unsigned queue_space(const queue_t &q) { + return q.size - queue_items(q); +} + +#endif /* QUEUE_H_ */ diff --git a/module_queue/src/queue.xc b/module_queue/src/queue.xc new file mode 100644 index 00000000..58c78248 --- /dev/null +++ b/module_queue/src/queue.xc @@ -0,0 +1,11 @@ +#include "queue.h" + +// Force external definitions of inline functions. +extern inline int is_power_of_2(unsigned x); +extern inline void queue_init(queue_t &q, unsigned size); +extern inline int queue_is_empty(const queue_t &q); +extern inline int queue_is_full(const queue_t &q); +extern inline void queue_push_word(queue_t &q, unsigned array[], unsigned data); +extern inline unsigned queue_pop_word(queue_t &q, unsigned array[]); +extern inline unsigned queue_space(const queue_t &q); +extern inline unsigned queue_items(const queue_t &q); diff --git a/module_usb_midi/module_build_info b/module_usb_midi/module_build_info index cb931043..bb4cb582 100644 --- a/module_usb_midi/module_build_info +++ b/module_usb_midi/module_build_info @@ -9,3 +9,4 @@ # # You can also set MODULE_XCC_C_FLAGS, MODULE_XCC_XC_FLAGS etc.. +DEPENDENT_MODULES = module_queue diff --git a/module_usb_midi/src/queue.c b/module_usb_midi/src/queue.c deleted file mode 100644 index 1852b466..00000000 --- a/module_usb_midi/src/queue.c +++ /dev/null @@ -1,84 +0,0 @@ -#include -#include "queue.h" - -// Queue implementation -// Offers no protection against adding when full or dequeueing when empty. -// Uses read and write counts for pointers to distinguish full and empty cases. -// Works from c and xc -// Must allocate the memory outside of this and pass it in to init_queue so can statically allocate -// Must work for different element sizes - -// This presumes that the xc compiler will not re-use the mem passed to init_queue -void init_queue(queue *q, unsigned char arr[], int size, int element_size) { - q->rdptr = 0; - q->wrptr = 0; - q->data = (uintptr_t)arr; - q->size = size; // in items, presume that size is power of two - q->element_size = element_size; // The size of each element in bytes - q->mask = size - 1; -} - -extern inline void enqueue(queue *q, unsigned value) { - switch (q->element_size) { - case 4: - ((unsigned *)q->data)[q->wrptr & q->mask] = value; - break; - case 1: - ((unsigned char *)q->data)[q->wrptr & q->mask] = (unsigned char)value; - break; - default: - break; - } - q->wrptr++; -} - -extern inline unsigned dequeue(queue *q) { - unsigned retval; - switch (q->element_size) { - case 4: - retval = ((unsigned *)q->data)[q->rdptr & q->mask]; - break; - case 1: - retval = ((unsigned char *)q->data)[q->rdptr & q->mask]; - break; - default: - break; - } - q->rdptr++; - return retval; -} - -extern inline int isempty(queue *q) { - return (q->rdptr == q->wrptr); -} - -extern inline int isfull(queue *q) { - return ((q->wrptr - q->rdptr) == q->size); -} - -extern inline int items(queue *q) { - int items = q->wrptr - q->rdptr; - return items; -} - -// How to calculate size? Could make it a function call or leave it as a variable within the struct -extern inline int space(queue *q) { - return q->size - items(q); -} - -void dump(queue *q) { - for (int i = q->rdptr; i != q->wrptr; i++) { - switch (q->element_size) { - case 4: - printf("a[%d] = %d\n", i & q->mask, ((unsigned *)q->data)[i & q->mask]); - break; - case 1: - printf("a[%d] = %d\n", i & q->mask, ((unsigned char *)q->data)[i & q->mask]); - break; - default: - break; - } - } -} - - diff --git a/module_usb_midi/src/queue.h b/module_usb_midi/src/queue.h deleted file mode 100644 index 1e04c8d0..00000000 --- a/module_usb_midi/src/queue.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef QUEUE_H -#define QUEUE_H - -#include -#include - -typedef struct queue { - uintptr_t data; - int rdptr; // Using absolute indices which count reads and writes so this needs to be considered when accessing. - int wrptr; - int size; - int element_size; - int mask; -} queue; - -void init_queue(REFERENCE_PARAM(queue, q), unsigned char arr[], int size, int element_size); -void enqueue(REFERENCE_PARAM(queue, q), unsigned value); -unsigned dequeue(REFERENCE_PARAM(queue, q)); -int isempty(REFERENCE_PARAM(queue, q)); -int isfull(REFERENCE_PARAM(queue, q)); -int items(REFERENCE_PARAM(queue, q)); -int space(REFERENCE_PARAM(queue, q)); -void dump(REFERENCE_PARAM(queue, q)); - -#endif // QUEUE_H diff --git a/module_usb_midi/src/usb_midi.xc b/module_usb_midi/src/usb_midi.xc index f037ecd0..cdd6239d 100644 --- a/module_usb_midi/src/usb_midi.xc +++ b/module_usb_midi/src/usb_midi.xc @@ -49,6 +49,8 @@ extern unsigned polltime; timer iAPTimer; #endif +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) + void usb_midi(port ?p_midi_in, port ?p_midi_out, clock ?clk_midi, chanend ?c_midi, @@ -71,23 +73,23 @@ void usb_midi(port ?p_midi_in, port ?p_midi_out, timer t2; // One place buffer for data going out to host - queue midi_to_host_fifo; - unsigned char midi_to_host_fifo_arr[4]; // Used for 32bit USB MIDI events + queue_t midi_to_host_fifo; + unsigned midi_to_host_fifo_arr[1]; // Used for 32bit USB MIDI events unsigned outputting_symbol, outputted_symbol; struct midi_in_parse_state mips; // the symbol fifo (to go out of uart) - queue symbol_fifo; - unsigned char symbol_fifo_arr[USB_MIDI_DEVICE_OUT_FIFO_SIZE * 4]; // Used for 32bit USB MIDI events + queue_t symbol_fifo; + unsigned symbol_fifo_arr[USB_MIDI_DEVICE_OUT_FIFO_SIZE]; // Used for 32bit USB MIDI events unsigned rxPT, txPT; int midi_from_host_overflow = 0; //configure_clock_rate(clk_midi, 100, 1); - init_queue(symbol_fifo, symbol_fifo_arr, USB_MIDI_DEVICE_OUT_FIFO_SIZE, 4); - init_queue(midi_to_host_fifo, midi_to_host_fifo_arr, 1, 4); + queue_init(symbol_fifo, ARRAY_SIZE(symbol_fifo_arr)); + queue_init(midi_to_host_fifo, ARRAY_SIZE(midi_to_host_fifo_arr)); configure_out_port(p_midi_out, clk_midi, 1< 3 && midi_from_host_overflow) + if (queue_space(symbol_fifo) > 3 && midi_from_host_overflow) { midi_from_host_overflow = 0; midi_send_ack(c_midi); @@ -244,7 +246,7 @@ void usb_midi(port ?p_midi_in, port ?p_midi_out, // Finished sending byte uout_count++; outputted_symbol = outputting_symbol; - if (isempty(symbol_fifo)) + if (queue_is_empty(symbol_fifo)) { // FIFO empty isTX = 0; } @@ -259,10 +261,10 @@ void usb_midi(port ?p_midi_in, port ?p_midi_out, { // have we got more data to send //printstr("ack\n"); - if (!isempty(midi_to_host_fifo)) + if (!queue_is_empty(midi_to_host_fifo)) { //printstr("uart->decouple\n"); - outuint(c_midi, dequeue(midi_to_host_fifo)); + outuint(c_midi, queue_pop_word(midi_to_host_fifo, midi_to_host_fifo_arr)); th_count++; } else @@ -278,7 +280,7 @@ void usb_midi(port ?p_midi_in, port ?p_midi_out, int event = byterev(datum); mr_count++; #ifdef MIDI_LOOPBACK - if (isempty(midi_to_host_fifo)) + if (queue_is_empty(midi_to_host_fifo)) { // data to send to host if (!waiting_for_ack) @@ -292,7 +294,7 @@ void usb_midi(port ?p_midi_in, port ?p_midi_out, else { event = byterev(event); - enqueue(midi_to_host_fifo, event); + queue_push_word(midi_to_host_fifo, midi_to_host_fifo_arr, event); } midi_send_ack(c_midi); } @@ -305,10 +307,10 @@ void usb_midi(port ?p_midi_in, port ?p_midi_out, for (int i = 0; i != size; i++) { // add symbol to fifo - enqueue(symbol_fifo, midi[i]); + queue_push_word(symbol_fifo, symbol_fifo_arr, midi[i]); } - if (space(symbol_fifo) > 3) + if (queue_space(symbol_fifo) > 3) { midi_send_ack(c_midi); } diff --git a/tests/app_queue_test/Makefile b/tests/app_queue_test/Makefile new file mode 100644 index 00000000..a9c74106 --- /dev/null +++ b/tests/app_queue_test/Makefile @@ -0,0 +1,32 @@ +# The TARGET variable determines what target system the application is +# compiled for. It either refers to an XN file in the source directories +# or a valid argument for the --target option when compiling +TARGET = XP-SKC-SU1 + +# The APP_NAME variable determines the name of the final .xe file. It should +# not include the .xe postfix. If left blank the name will default to +# the project name +APP_NAME = app_queue_test + +# The USED_MODULES variable lists other module used by the application. +USED_MODULES = module_queue + +# The flags passed to xcc when building the application +# You can also set the following to override flags for a particular language: +# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS +# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to +# xcc for the final link (mapping) stage. +XCC_FLAGS = -O0 -g + +# The VERBOSE variable, if set to 1, enables verbose output from the make system. +VERBOSE = 0 + +# This change to the module path is so that this application can be in the +# tests sub-directory in it's git repo +ifeq ($(notdir $(abspath ..)),tests) +PATHSEP = $(if $(findstring Windows, $(OS))$(findstring WINDOWS,$(OS)),;,:) +XMOS_MODULE_PATH := $(XMOS_MODULE_PATH)$(PATHSEP)../../.. +endif + +XMOS_MAKE_PATH ?= ../.. +-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common diff --git a/tests/app_queue_test/src/app_queue_test.xc b/tests/app_queue_test/src/app_queue_test.xc new file mode 100644 index 00000000..b4acd7f4 --- /dev/null +++ b/tests/app_queue_test/src/app_queue_test.xc @@ -0,0 +1,32 @@ +#include "queue.h" +#include + +#define VERIFY(x) do { if (!(x)) _Exit(1); } while(0) + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) + +int main() +{ + queue_t q; + unsigned array[4]; + const unsigned size = ARRAY_SIZE(array); + queue_init(q, size); + VERIFY(queue_is_empty(q)); + VERIFY(!queue_is_full(q)); + VERIFY(queue_items(q) == 0); + VERIFY(queue_space(q) == size); + queue_push_word(q, array, 1); + VERIFY(!queue_is_empty(q)); + VERIFY(queue_items(q) == 1); + VERIFY(queue_space(q) == size - 1); + for (unsigned i = 1; i < size; i++) { + queue_push_word(q, array, i + 1); + } + VERIFY(queue_is_full(q)); + VERIFY(queue_items(q) == size); + VERIFY(queue_space(q) == 0); + for (unsigned i = 0; i < size; i++) { + VERIFY(queue_pop_word(q, array) == i + 1); + } + return 0; +} From 4b22faaf690dd5c5a687b93f0ccaba21c0b19d39 Mon Sep 17 00:00:00 2001 From: Richard Osborne Date: Mon, 25 Nov 2013 17:42:11 +0000 Subject: [PATCH 38/72] Remove checked in file generated from a merge conflict. --- module_usb_audio/usb_buffer/decouple.xc.orig | 1169 ------------------ 1 file changed, 1169 deletions(-) delete mode 100644 module_usb_audio/usb_buffer/decouple.xc.orig diff --git a/module_usb_audio/usb_buffer/decouple.xc.orig b/module_usb_audio/usb_buffer/decouple.xc.orig deleted file mode 100644 index 98ad583c..00000000 --- a/module_usb_audio/usb_buffer/decouple.xc.orig +++ /dev/null @@ -1,1169 +0,0 @@ -#include -#include -#include -#define ecallf(e) asm("ecallf %0" :: "r"(e)); -#include "xc_ptr.h" -#define NO_INLINE_MIDI_SELECT_HANDLER 1 -#include "usb_midi.h" -#include "devicedefines.h" -#include "testct_byref.h" -#include "interrupt.h" -#include "clockcmds.h" -#include "xud.h" -#include "usb.h" - - -#define MAX(x,y) ((x)>(y) ? (x) : (y)) -#define MAX_CLASS_ONE_FREQ 96000 -#define MAX_CLASS_ONE_CHAN 2 - -#define CLASS_TWO_PACKET_SIZE ((((MAX_FREQ+7999)/8000))+3) -#define CLASS_ONE_PACKET_SIZE ((((MAX_CLASS_ONE_FREQ+999)/1000))+3) - -#define BUFF_SIZE_OUT MAX(4 * CLASS_TWO_PACKET_SIZE * NUM_USB_CHAN_OUT, 4 * CLASS_ONE_PACKET_SIZE * MAX_CLASS_ONE_CHAN) -#define BUFF_SIZE_IN MAX(4 * CLASS_TWO_PACKET_SIZE * NUM_USB_CHAN_IN, 4 * CLASS_ONE_PACKET_SIZE * MAX_CLASS_ONE_CHAN) -#define MAX_USB_AUD_PACKET_SIZE 1028 -//#define OUT_BUFFER_PREFILL (2*4*BUFF_SIZE_OUT/3) -#define OUT_BUFFER_PREFILL MAX(CLASS_ONE_PACKET_SIZE*3+4,CLASS_TWO_PACKET_SIZE*4+4)*2 -#define IN_BUFFER_PREFILL MAX(CLASS_ONE_PACKET_SIZE*3+4,CLASS_TWO_PACKET_SIZE*4+4)*2 - - -//#pragma xta command "config threads stdcore[1] 6" -//#pragma xta command "add exclusion out_underflow" -//#pragma xta command "add exclusion freq_change" -//#pragma xta command "add exclusion print_err" -//#pragma xta command "add exclusion out_soverflow" -//#pragma xta command "analyse path mixer_request mixer_request" -//#pragma xta command "set required - 5200 ns" /* 192kHz */ - -/* Volume and mute tables */ -#ifndef OUT_VOLUME_IN_MIXER -unsigned int multOut[NUM_USB_CHAN_OUT + 1]; -#endif -#ifndef IN_VOLUME_IN_MIXER -unsigned int multIn[NUM_USB_CHAN_IN + 1]; -#endif - -/* Number of channels to/from the USB bus */ -unsigned g_numUsbChanOut = NUM_USB_CHAN_OUT; -unsigned g_numUsbChanIn = NUM_USB_CHAN_IN; - -#define MAX_DEVICE_AUD_PACKET_SIZE_CLASS_TWO ((MAX_FREQ/8000+1)*NUM_USB_CHAN_IN*4) -#define MAX_DEVICE_AUD_PACKET_SIZE_CLASS_ONE (((MAX_CLASS_ONE_FREQ/1000+1)*MAX_CLASS_ONE_CHAN*3)+4) - -#define MAX_DEVICE_AUD_PACKET_SIZE (MAX(MAX_DEVICE_AUD_PACKET_SIZE_CLASS_ONE, MAX_DEVICE_AUD_PACKET_SIZE_CLASS_TWO)) - -/* Circular audio buffers */ -unsigned outAudioBuff[BUFF_SIZE_OUT + (MAX_USB_AUD_PACKET_SIZE>>2) + 4]; -unsigned audioBuffIn[BUFF_SIZE_IN + (MAX_DEVICE_AUD_PACKET_SIZE>>2) + 4]; - -unsigned inZeroBuff[(MAX_DEVICE_AUD_PACKET_SIZE>>2)+4]; - -unsigned ledVal = 1; -unsigned dir = 0; - -void led(chanend ?c_led) -{ - if(dir == 0) - ledVal <<= 1; - else - ledVal >>= 1; - - if(ledVal == 0b10000000 || ledVal == 1) - dir = !dir; - - if (!isnull(c_led)) { - c_led <: ledVal; - } -} - -/* Returns the max and min packet sizes to send back to host for a given sample frequency - * See page 13 of USB Audio Device Class Definitions for Audio Data Formats Spec (v2.0) - * - * Audio samples per frame = INT(sampFreq/frametime); Variation allowed is + 1; - * - * For HS frame time = 8 * 1000 - * - * so n = INT(SampFreq/8000) | INT (SampFreq/8000) + 1 - * - * In the case where INT(SampFreq/8000) == SampFreq/8000) n may vary between - * - * INT(SamFreq/8000) - 1 | INT(SampFreq/8000) | INT (SampFreq/8000) + 1 - * - * Note: Assumes HS (i.e. 8 frames per 1ms) - * - * Examples: - * 44100: min: 5 max: 6 - * 48000: min: 5 max: 7 - * 96000: min: 11 max: 13 - * 88200: min: 11 max: 12 - * 176400: min: 22 max: 23 - * 192000: min: 23 max: 25 - * - * Note: This function uses the multiple return value feature of XC - */ - -void GetADCCounts(unsigned samFreq, int &min, int &mid, int &max); - -static inline void swap(xc_ptr &a, xc_ptr &b) -{ - xc_ptr tmp; - tmp = a; - a = b; - b = tmp; - return; -} - -// shared global midi buffering variables -unsigned g_midi_from_host_flag = 0; -unsigned g_midi_to_host_flag = 0; -int midi_to_host_usb_ep = 0; -int midi_from_host_usb_ep = 0; -int aud_from_host_usb_ep = 0; -int aud_to_host_usb_ep = 0; -int int_usb_ep = 0; - -int g_midi_to_host_buffer[8]; -int g_midi_from_host_buffer[MAX_USB_PACKET_SIZE+4]; - -// shared global aud buffering variables - -unsigned g_aud_from_host_buffer; -unsigned g_aud_to_host_buffer; -unsigned g_aud_to_host_flag = 0; -int buffer_aud_ctl_chan = 0; -unsigned g_aud_from_host_flag = 0; -unsigned g_aud_from_host_info; -unsigned g_freqChange_flag = 0; -unsigned g_freqChange_sampFreq; -int speedRem = 0; - - -xc_ptr aud_from_host_fifo_start; -xc_ptr aud_from_host_fifo_end; -xc_ptr g_aud_from_host_wrptr; -xc_ptr g_aud_from_host_rdptr; - - -xc_ptr aud_to_host_fifo_start; -xc_ptr aud_to_host_fifo_end; -xc_ptr g_aud_to_host_wrptr; -xc_ptr g_aud_to_host_dptr; -xc_ptr g_aud_to_host_rdptr; -xc_ptr g_aud_to_host_zeros; -int sampsToWrite = 0; -int totalSampsToWrite = 0; - - -int aud_data_remaining_to_device = 0; - - -/* Over/under flow flags */ -unsigned outUnderflow = 1; -unsigned outOverflow = 0; -unsigned inUnderflow = 1; -unsigned inOverflow = 0; - - -int aud_req_in_count = 0; -int aud_req_out_count = 0; - -unsigned unpackState = 0; -unsigned unpackData = 0; - -unsigned packState = 0; -unsigned packData = 0; - - -#pragma select handler -#pragma unsafe arrays -void handle_audio_request(chanend c_mix_out, chanend ?c_led) -{ - int outSamps; - int space_left; - int usb_speed; - - asm("ldw %0, dp[g_curUsbSpeed]" : "=r" (usb_speed) :); - - (void) inuint(c_mix_out); - outuint(c_mix_out, 0); - - /* If in overflow condition, throw samples away */ - if(inOverflow || sampsToWrite == 0) - { -#pragma loop unroll - for(int i = 0; i < NUM_USB_CHAN_IN; i++) - { - (void) inuint(c_mix_out); - } - - /* Calculate how much space left in buffer */ - space_left = g_aud_to_host_rdptr - g_aud_to_host_wrptr; - if (space_left <= 0) - space_left += BUFF_SIZE_IN*4; - - if (space_left > (BUFF_SIZE_IN*4/2)) - { - inOverflow = 0; - } - } - else - { - /* Not in overflow, store samples from mixer into sample buffer */ - if (usb_speed == XUD_SPEED_HS) - { - unsigned ptr = g_aud_to_host_dptr; - - for(int i = 0; i < g_numUsbChanIn; i++) - { - int sample = inuint(c_mix_out); -#if !defined(IN_VOLUME_IN_MIXER) - int mult; - int h; - unsigned l; - asm("ldw %0, %1[%2]":"=r"(mult):"r"(multIn),"r"(i)); - {h, l} = macs(mult, sample, 0, 0); - sample = h << 3; -#elif defined(IN_VOLUME_IN_MIXER) && defined(IN_VOLUME_AFTER_MIX) - sample = sample << 3; -#endif - write_via_xc_ptr(ptr, sample); - ptr+=4; - } - - g_aud_to_host_dptr = ptr; - } - else - { - for(int i = 0; i < g_numUsbChanIn; i++) - { - int sample = inuint(c_mix_out); -#ifndef IN_VOLUME_IN_MIXER - int mult; - int h; - unsigned l; - asm("ldw %0, %1[%2]":"=r"(mult):"r"(multIn),"r"(i)); - {h, l} = macs(mult, sample, 0, 0); - sample = h << 3; -#endif - switch (packState&0x3) - { - case 0: - packData = sample; - break; - case 1: - packData = packData >> 8 | ((sample & 0xff00)<<16); - write_via_xc_ptr(g_aud_to_host_dptr, packData); - g_aud_to_host_dptr+=4; - write_via_xc_ptr(g_aud_to_host_dptr, sample>>16); - packData = sample; - break; - case 2: - packData = (packData>>16) | ((sample & 0xffff00) << 8); - write_via_xc_ptr(g_aud_to_host_dptr, packData); - g_aud_to_host_dptr+=4; - packData = sample; - break; - case 3: - packData = (packData >> 24) | (sample & 0xffffff00); - write_via_xc_ptr(g_aud_to_host_dptr, packData); - g_aud_to_host_dptr+=4; - break; - } - packState++; - } - - } - - /* Input any remaining channels */ - for(int i = 0; i < NUM_USB_CHAN_IN - g_numUsbChanIn; i++) - { - inuint(c_mix_out); - } - - sampsToWrite--; - } - - if(outUnderflow) - { -#pragma xta endpoint "out_underflow" - /* We're still pre-buffering, send out 0 samps */ - for(int i = 0; i < NUM_USB_CHAN_OUT; i++) - { - outuint(c_mix_out, 0); - } - - /* Calc how many samples left in buffer */ - outSamps = g_aud_from_host_wrptr - g_aud_from_host_rdptr; - if (outSamps < 0) - { - outSamps += BUFF_SIZE_OUT*4; - } - - /* If we have a decent number of samples, come out of underflow cond */ - if (outSamps >= (OUT_BUFFER_PREFILL)) - { - outUnderflow = 0; - } - } - else - { - - if (usb_speed == XUD_SPEED_HS) - { - /* Buffering not underflow condition send out some samples...*/ - for(int i = 0; i < g_numUsbChanOut; i++) - { -#pragma xta endpoint "mixer_request" - int sample; - int mult; - int h; - unsigned l; - - read_via_xc_ptr(sample, g_aud_from_host_rdptr); - g_aud_from_host_rdptr+=4; - -#ifndef OUT_VOLUME_IN_MIXER - asm("ldw %0, %1[%2]":"=r"(mult):"r"(multOut),"r"(i)); - {h, l} = macs(mult, sample, 0, 0); - h <<= 3; - outuint(c_mix_out, h); -#else - outuint(c_mix_out, sample); - -#endif - } - } - else - { - - /* Buffering not underflow condition send out some samples...*/ - for(int i = 0; i < g_numUsbChanOut; i++) - { -#pragma xta endpoint "mixer_request" - int sample; - int mult; - int h; - unsigned l; - - switch (unpackState&0x3) - { - case 0: - read_via_xc_ptr(unpackData, g_aud_from_host_rdptr); - g_aud_from_host_rdptr+=4; - sample = unpackData << 8; - break; - case 1: - sample = (unpackData >> 16); - read_via_xc_ptr(unpackData, g_aud_from_host_rdptr); - g_aud_from_host_rdptr+=4; - sample = sample | (unpackData << 16); - break; - case 2: - sample = (unpackData >> 8); - read_via_xc_ptr(unpackData, g_aud_from_host_rdptr); - g_aud_from_host_rdptr+=4; - sample = sample | (unpackData<< 24); - break; - case 3: - sample = unpackData & 0xffffff00; - break; - } - unpackState++; - -#ifndef OUT_VOLUME_IN_MIXER - asm("ldw %0, %1[%2]":"=r"(mult):"r"(multOut),"r"(i)); - {h, l} = macs(mult, sample, 0, 0); - h <<= 3; - outuint(c_mix_out, h); -#else - outuint(c_mix_out, sample); - -#endif - } - } - - /* Output remaining channels. Past this point we always operate on MAX chan count */ - for(int i = 0; i < NUM_USB_CHAN_OUT - g_numUsbChanOut; i++) - { - outuint(c_mix_out, 0); - } - - - - if(usb_speed == XUD_SPEED_HS) - { - /* 4 bytes per sample */ - aud_data_remaining_to_device -= (g_numUsbChanOut*4); - } - else { - /* 3 bytes per sample */ - aud_data_remaining_to_device -= (g_numUsbChanOut*3); - } - - - - } - - if (!inOverflow) - { - if (sampsToWrite == 0) - { - int speed; - - if (totalSampsToWrite) - { - if (usb_speed == XUD_SPEED_HS) - { - g_aud_to_host_wrptr += 4+totalSampsToWrite*4*g_numUsbChanIn; - } - else - { - unsigned int datasize = totalSampsToWrite*3*g_numUsbChanIn; - datasize = (datasize+3) & (~0x3); // round up to nearest word - g_aud_to_host_wrptr += 4+datasize; - } - if (g_aud_to_host_wrptr >= aud_to_host_fifo_end) - { - g_aud_to_host_wrptr = aud_to_host_fifo_start; - } - } - - /* Get feedback val */ - /* TODO, this should be syncronised ideally */ - asm("ldw %0, dp[g_speed]" : "=r" (speed) :); - - /* Calc packet size to send back based on our fb */ - speedRem += speed; - totalSampsToWrite = speedRem >> 16; - speedRem &= 0xffff; - - if (usb_speed == XUD_SPEED_HS) - { - if (totalSampsToWrite < 0 || totalSampsToWrite*4*g_numUsbChanIn > (MAX_DEVICE_AUD_PACKET_SIZE_CLASS_TWO)) - { - totalSampsToWrite = 0; - } - } - else - { - if (totalSampsToWrite < 0 || totalSampsToWrite*3*g_numUsbChanIn > (MAX_DEVICE_AUD_PACKET_SIZE_CLASS_ONE)) - { - totalSampsToWrite = 0; - } - } - - /* Calc slots left in fifo */ - space_left = g_aud_to_host_rdptr - g_aud_to_host_wrptr; - - /* mod and special case */ - if (space_left <= 0 && g_aud_to_host_rdptr == aud_to_host_fifo_start) - { - space_left = aud_to_host_fifo_end - g_aud_to_host_wrptr; - } - - if ((space_left <= 0) || (space_left > totalSampsToWrite*g_numUsbChanIn*4+4)) - { - // packet ok - if (totalSampsToWrite) - { - if (usb_speed == XUD_SPEED_HS) - { - write_via_xc_ptr(g_aud_to_host_wrptr, totalSampsToWrite*4*g_numUsbChanIn); - } - else - { - write_via_xc_ptr(g_aud_to_host_wrptr, totalSampsToWrite*3*g_numUsbChanIn); - packState = 0; - } - g_aud_to_host_dptr = g_aud_to_host_wrptr + 4; - } - } - else - { - inOverflow = 1; - totalSampsToWrite = 0; - } - sampsToWrite = totalSampsToWrite; - } - } - - if (!outUnderflow && (aud_data_remaining_to_device<3)) - { - /* Wrap read pointer */ - if (g_aud_from_host_rdptr >= aud_from_host_fifo_end) - g_aud_from_host_rdptr = aud_from_host_fifo_start; - - outUnderflow = (g_aud_from_host_rdptr == g_aud_from_host_wrptr); - - if (!outUnderflow) - { - read_via_xc_ptr(aud_data_remaining_to_device, g_aud_from_host_rdptr); - //ecallf(aud_data_remaining_to_device <= 432); - - unpackState = 0; - //aud_data_remaining_to_device >>= 2; - /* if (aud_data_remaining_to_device % g_numUsbChanOut != 0) { - asm("ecallf %0"::"r"(0)); - }*/ - g_aud_from_host_rdptr+=4; - } -#ifdef DEBUG_LEDS - else - { - led(c_led); - } -#endif - } - -} - - -unsigned g_intFlag = 0; - -extern unsigned char g_intData[8]; - -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, 0,x,6); - } - - break; - default: - break; - } -} - - -#pragma unsafe arrays -void decouple(chanend c_mix_out, - chanend ?c_midi, chanend ?c_clk_int) -{ - unsigned sampFreq = DEFAULT_FREQ; - int aud_from_host_flag=0; - int aud_to_host_flag=0; - xc_ptr released_buffer; - -#ifdef MIDI - xc_ptr midi_from_host_rdptr = midi_from_host_fifo_start; - - xc_ptr midi_from_host_buffer = array_to_xc_ptr(g_midi_from_host_buffer); - xc_ptr midi_to_host_buffer = array_to_xc_ptr(g_midi_to_host_buffer); - int is_ack; - unsigned int datum; - int midi_data_remaining_to_device = 0; - int midi_to_host_flag = 0; - int midi_from_host_flag = 0; -#endif - int t = array_to_xc_ptr(outAudioBuff); - - - aud_from_host_fifo_start = t; - aud_from_host_fifo_end = aud_from_host_fifo_start + BUFF_SIZE_OUT*4; - g_aud_from_host_wrptr = aud_from_host_fifo_start; - g_aud_from_host_rdptr = aud_from_host_fifo_start; - - t = array_to_xc_ptr(audioBuffIn); - - aud_to_host_fifo_start = t; - aud_to_host_fifo_end = aud_to_host_fifo_start + BUFF_SIZE_IN*4; - g_aud_to_host_wrptr = aud_to_host_fifo_start; - g_aud_to_host_rdptr = aud_to_host_fifo_start; - - 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++) - { - asm("stw %0, %1[%2]"::"r"(MAX_VOL),"r"(multOut),"r"(i)); - } -#endif - -#ifndef IN_VOLUME_IN_MIXER - for (int i = 0; i < NUM_USB_CHAN_IN + 1; i++) - { - asm("stw %0, %1[%2]"::"r"(MAX_VOL),"r"(mulIn),"r"(i)); - } -#endif - - - { int c=0; - while(!c) { - asm("ldw %0, dp[buffer_aud_ctl_chan]":"=r"(c)); - } - } - - - set_interrupt_handler(handle_audio_request, 200, 1, c_mix_out, 0); - -#ifdef MIDI - asm("ldaw %0, dp[g_midi_to_host_buffer]":"=r"(midi_to_host_buffer)); - asm("ldaw %0, dp[g_midi_from_host_buffer]":"=r"(midi_from_host_buffer)); - - // wait for usb_buffer to set up - while(!midi_from_host_flag) { - GET_SHARED_GLOBAL(midi_from_host_flag, g_midi_from_host_flag); - } - - midi_from_host_flag = 0; - SET_SHARED_GLOBAL(g_midi_from_host_flag, midi_from_host_flag); - - // send the current host -> device buffer out of the fifo - XUD_SetReady(midi_from_host_usb_ep, 1); -#endif - -#ifdef OUTPUT - // wait for usb_buffer to set up - while(!aud_from_host_flag) { - GET_SHARED_GLOBAL(aud_from_host_flag, g_aud_from_host_flag); - } - - aud_from_host_flag = 0; - SET_SHARED_GLOBAL(g_aud_from_host_flag, aud_from_host_flag); - - // send the current host -> device buffer out of the fifo - SET_SHARED_GLOBAL(g_aud_from_host_buffer, g_aud_from_host_wrptr); - XUD_SetReady(aud_from_host_usb_ep, 1); -#endif - -#ifdef INPUT - // wait for usb_buffer to set up - while(!aud_to_host_flag) { - GET_SHARED_GLOBAL(aud_to_host_flag, g_aud_to_host_flag); - } - - aud_to_host_flag = 0; - SET_SHARED_GLOBAL(g_aud_to_host_flag, aud_to_host_flag); - - // send the current host -> device buffer out of the fifo - SET_SHARED_GLOBAL(g_aud_to_host_buffer, g_aud_to_host_zeros); - { - xc_ptr p; - int len; - - GET_SHARED_GLOBAL(p, g_aud_to_host_buffer); - read_via_xc_ptr(len, p); - - XUD_SetReady_In(aud_to_host_usb_ep, PIDn_DATA0, g_aud_to_host_buffer, len); - - } -#endif - - while(1) - { - if (!isnull(c_clk_int)) - { - check_for_interrupt(c_clk_int); - } - - asm("#decouple-default"); - - /* Check for freq change or other update */ - { - int tmp; - GET_SHARED_GLOBAL(tmp, g_freqChange_flag); - if (tmp == SET_SAMPLE_FREQ) - { - SET_SHARED_GLOBAL(g_freqChange_flag, 0); - GET_SHARED_GLOBAL(sampFreq, g_freqChange_sampFreq); - - /* Pass on to mixer */ - DISABLE_INTERRUPTS(); - inuint(c_mix_out); - outct(c_mix_out, 9); - outuint(c_mix_out, sampFreq); - - inOverflow = 0; - inUnderflow = 1; - SET_SHARED_GLOBAL(g_aud_to_host_rdptr, - aud_to_host_fifo_start); - SET_SHARED_GLOBAL(g_aud_to_host_wrptr, - aud_to_host_fifo_start); - SET_SHARED_GLOBAL(sampsToWrite, 0); - SET_SHARED_GLOBAL(totalSampsToWrite, 0); - SET_SHARED_GLOBAL(g_aud_to_host_buffer, - g_aud_to_host_zeros); - - /* Wait for handshake back and pass back up */ - - chkct(c_mix_out, XS1_CT_END); - - - SET_SHARED_GLOBAL(g_freqChange, 0); - asm("outct res[%0],%1"::"r"(buffer_aud_ctl_chan),"r"(XS1_CT_END)); - - ENABLE_INTERRUPTS(); - - speedRem = 0; - continue; - } - else if(tmp == SET_CHAN_COUNT_IN) - { - - DISABLE_INTERRUPTS(); - SET_SHARED_GLOBAL(g_freqChange_flag, 0); - GET_SHARED_GLOBAL(g_numUsbChanIn, g_freqChange_sampFreq); /* Misuse of g_freqChange_sampFreq */ - - inOverflow = 0; - inUnderflow = 1; - SET_SHARED_GLOBAL(g_aud_to_host_rdptr, - aud_to_host_fifo_start); - SET_SHARED_GLOBAL(g_aud_to_host_wrptr, - aud_to_host_fifo_start); - SET_SHARED_GLOBAL(sampsToWrite, 0); - SET_SHARED_GLOBAL(totalSampsToWrite, 0); - SET_SHARED_GLOBAL(g_aud_to_host_buffer, - g_aud_to_host_zeros); - - - // g_buffSizeIn = (BUFF_MULT * g_numUsbChanIn); - // inWr = 0; // Reseting wr/rd prob not required since we will underflow and reset - // inRd = (g_buffSizeIn + (int) inWr - (g_numUsbChanIn * 25)) % g_buffSizeIn; - // sampsToWrite = 0; - - SET_SHARED_GLOBAL(g_freqChange, 0); - ENABLE_INTERRUPTS(); - } - } - -#ifdef OUTPUT - GET_SHARED_GLOBAL(aud_from_host_flag, g_aud_from_host_flag); - if (aud_from_host_flag) - { - // the buffer thread has filled up a buffer - int datalength; - int space_left; - int aud_from_host_wrptr; - int aud_from_host_rdptr; - GET_SHARED_GLOBAL(aud_from_host_wrptr, g_aud_from_host_wrptr); - GET_SHARED_GLOBAL(aud_from_host_rdptr, g_aud_from_host_rdptr); - - SET_SHARED_GLOBAL(g_aud_from_host_flag, 0); - GET_SHARED_GLOBAL(released_buffer, g_aud_from_host_buffer); - - read_via_xc_ptr(datalength, released_buffer); - - if (datalength) { - // move the write pointer of the fifo on - - aud_from_host_wrptr = - aud_from_host_wrptr + ((datalength+3)&~0x3) + 4; - if (aud_from_host_wrptr >= aud_from_host_fifo_end) - aud_from_host_wrptr = aud_from_host_fifo_start; - - SET_SHARED_GLOBAL(g_aud_from_host_wrptr, aud_from_host_wrptr); - } - - // if we have enough space left then send a new buffer pointer - // back to the buffer thread - space_left = aud_from_host_rdptr - aud_from_host_wrptr; - - - if (space_left <= 0 || space_left >= MAX_USB_AUD_PACKET_SIZE) { - SET_SHARED_GLOBAL(g_aud_from_host_buffer, aud_from_host_wrptr); - XUD_SetReady(aud_from_host_usb_ep, 1); - } - else { - outOverflow = 1; -#ifdef DEBUG_LEDS - led(c_led); -#endif - // overflow - } - continue; - } - else if (outOverflow) { - int space_left; - int aud_from_host_wrptr; - int aud_from_host_rdptr; - GET_SHARED_GLOBAL(aud_from_host_wrptr, g_aud_from_host_wrptr); - GET_SHARED_GLOBAL(aud_from_host_rdptr, g_aud_from_host_rdptr); - space_left = aud_from_host_rdptr - aud_from_host_wrptr; - if (space_left <= 0) - space_left += BUFF_SIZE_OUT*4; - if (space_left >= (BUFF_SIZE_OUT*4/2)) { - outOverflow = 0; - SET_SHARED_GLOBAL(g_aud_from_host_buffer, - aud_from_host_wrptr); - XUD_SetReady(aud_from_host_usb_ep, 1); -#ifdef DEBUG_LEDS - led(c_led); -#endif - } - } -#endif - - -#ifdef INPUT - { int tmp; - GET_SHARED_GLOBAL(tmp, g_aud_to_host_flag); - //case inuint_byref(c_buf_in, tmp): - if (tmp) { - /* Signals that the IN endpoint has sent data - from the passed buffer */ - SET_SHARED_GLOBAL(g_aud_to_host_flag, 0); - - if (inUnderflow) { - int aud_to_host_wrptr; - int aud_to_host_rdptr; - int fill_level; - GET_SHARED_GLOBAL(aud_to_host_wrptr, g_aud_to_host_wrptr); - GET_SHARED_GLOBAL(aud_to_host_rdptr, g_aud_to_host_rdptr); - - // check if we have come out of underflow. - - fill_level = aud_to_host_wrptr - aud_to_host_rdptr; - - if (fill_level < 0) - fill_level += BUFF_SIZE_IN*4; - - if (fill_level >= IN_BUFFER_PREFILL) { - inUnderflow = 0; - SET_SHARED_GLOBAL(g_aud_to_host_buffer, aud_to_host_rdptr); - } - else { - SET_SHARED_GLOBAL(g_aud_to_host_buffer, - g_aud_to_host_zeros); - } - - } else { - int datalength; - int aud_to_host_wrptr; - int aud_to_host_rdptr; - GET_SHARED_GLOBAL(aud_to_host_wrptr, g_aud_to_host_wrptr); - GET_SHARED_GLOBAL(aud_to_host_rdptr, g_aud_to_host_rdptr); - - read_via_xc_ptr(datalength, aud_to_host_rdptr); - aud_to_host_rdptr = - aud_to_host_rdptr + ((datalength+3)&~0x3) + 4; - if (aud_to_host_rdptr >= aud_to_host_fifo_end) - aud_to_host_rdptr = aud_to_host_fifo_start; - - SET_SHARED_GLOBAL(g_aud_to_host_rdptr, aud_to_host_rdptr); - - if (aud_to_host_rdptr != aud_to_host_wrptr) { - SET_SHARED_GLOBAL(g_aud_to_host_buffer, - aud_to_host_rdptr); - } - else { - inUnderflow = 1; - SET_SHARED_GLOBAL(g_aud_to_host_buffer, - g_aud_to_host_zeros); - - } - } - - { - int p, len; - - GET_SHARED_GLOBAL(p, g_aud_to_host_buffer); - - asm("ldw %0, %1[0]":"=r"(len):"r"(p)); - - XUD_SetReady_In(aud_to_host_usb_ep, PIDn_DATA0, p+4, len); - } - continue; - } - } -#endif // INPUT - -#ifdef MIDI -<<<<<<< HEAD - GET_SHARED_GLOBAL(midi_to_host_flag, g_midi_to_host_flag); - if (midi_to_host_flag) - { - // An ack from the buffer thread means that the buffer has been - // sent to the host, so we can ack the midi thread - SET_SHARED_GLOBAL(g_midi_to_host_flag, 0); - midi_send_ack(c_midi); - continue; - } - else - { - GET_SHARED_GLOBAL(midi_from_host_flag, g_midi_from_host_flag); - if (midi_from_host_flag) - { - // the buffer thread has filled up a buffer - int datalength; - int space_left; - - SET_SHARED_GLOBAL(g_midi_from_host_flag, 0); - - read_via_xc_ptr(midi_data_remaining_to_device, - midi_from_host_buffer); - midi_from_host_rdptr = midi_from_host_buffer + 4; - - if (midi_remaining_to_device) { - read_via_xc_ptr(datum, midi_from_host_rdptr); - outuint(c_midi, datum); - midi_from_host_rdptr += 4; - midi_data_remaining_to_device -= 4; - } - } - } - - - select - { - case midi_get_ack_or_data(c_midi, is_ack, datum): - if (is_ack) { - // an ack from the midi/uart thread means it has accepted - // some data we sent it - if (midi_data_remaining_to_device == 0) { - // we have read an entire packet - XUD_SetReady(midi_from_host_usb_ep, 1); - } - else { - read_via_xc_ptr(datum, midi_from_host_rdptr); - outuint(c_midi, datum); - midi_data_remaining_to_device -= 4; - } - } - else { - // set up a single event packet - write_via_xc_ptr(midi_to_host_buffer, datum); - XUD_SetReady_In(midi_to_host_usb_ep, 0, - midi_to_host_buffer, 4); - - } - break; - default: - break; - } - } - -======= - GET_SHARED_GLOBAL(midi_to_host_flag, g_midi_to_host_flag); - if (midi_to_host_flag) - { - // An ack from the buffer thread means that the buffer has been - // sent to the host - SET_SHARED_GLOBAL(g_midi_to_host_flag, 0); - - if (midi_data_collected_from_device != 0) - { - // printstr("agg"); - // we have some more data to send - // printstr("decouple->buffer: "); - // printintln(midi_data_collected_from_device); - - // set the amount of data to send - write_via_xc_ptr(midi_to_host_buffer_being_collected, midi_data_collected_from_device); - - // swap the collecting and sending buffer - swap(midi_to_host_buffer_being_collected, midi_to_host_buffer_being_sent); - - -#if 1 - { - int len; - - asm("ldw %0, %1[0]":"=r"(len):"r"(midi_to_host_buffer_being_sent)); - - XUD_SetReady_In(midi_to_host_usb_ep, 0, midi_to_host_buffer_being_sent+4, len); - } -#else - // signal other side to swap - XUD_SetReady(midi_to_host_usb_ep, 0); -#endif - - // midi_send_ack(c_midi_buf); - midi_waiting_on_send_to_host = 1; - - // reset the collected data count - midi_data_collected_from_device = 0; - } - else - { - - midi_waiting_on_send_to_host = 0; - } - continue; - } - else - { - GET_SHARED_GLOBAL(midi_from_host_flag, g_midi_from_host_flag); - if (midi_from_host_flag) - { - // the buffer thread has filled up a buffer - int datalength; - int space_left; - - SET_SHARED_GLOBAL(g_midi_from_host_flag, 0); - GET_SHARED_GLOBAL(released_buffer, g_midi_from_host_buffer); - - read_via_xc_ptr(datalength, released_buffer); - - if (datalength) { - // move the write pointer of the fifo on - midi_from_host_wrptr = midi_from_host_wrptr + datalength + 4; - if (midi_from_host_wrptr >= midi_from_host_fifo_end) - midi_from_host_wrptr = midi_from_host_fifo_start; - } - - // if we have enough space left then send a new buffer pointer - // back to the buffer thread - space_left = midi_from_host_rdptr - midi_from_host_wrptr; - - if (space_left < 0 || space_left >= MAX_USB_MIDI_PACKET_SIZE) { - SET_SHARED_GLOBAL(g_midi_from_host_buffer, midi_from_host_wrptr); - XUD_SetReady(midi_from_host_usb_ep, 1); - } - else { - // overflow - - midi_from_device_overflow = 1; - // SET_SHARED_GLOBAL(g_midi_from_host_buffer, - // null_midi_from_host_buffer); - // asm("out res[%1], %0"::"r"(1),"r"(midi_from_host_usb_chan)); - //printstrln("decouple h->d overflow"); - } - - if (datalength) { - // if weare not currently sending data to the midi-uart thread - // intiate sending it some - if (midi_data_remaining_to_device == 0) { - read_via_xc_ptr(midi_data_remaining_to_device, - midi_from_host_rdptr); - midi_from_host_rdptr += 4; - read_via_xc_ptr(datum, midi_from_host_rdptr); - outuint(c_midi, datum); - } - } - - continue; - } - } - - {int cont = 0; - select - { - case midi_get_ack_or_data(c_midi, is_ack, datum): - if (is_ack) - { - // An ack from the midi/uart thread means it has accepted some data we - // sent it - - // update the read pointer of the fifo - midi_from_host_rdptr += 4; - midi_data_remaining_to_device -= 4; - - if (midi_data_remaining_to_device == 0) - { - // We have read an entire packet - if (midi_from_host_rdptr >= midi_from_host_fifo_end) - midi_from_host_rdptr = midi_from_host_fifo_start; - - if (midi_from_host_rdptr != midi_from_host_wrptr) - { - // There is another packet to send - read_via_xc_ptr(midi_data_remaining_to_device, midi_from_host_rdptr); - midi_from_host_rdptr += 4; - } - } - - if (midi_from_device_overflow) - { - int space_left = midi_from_host_rdptr - midi_from_host_wrptr; - - if (space_left < 0 || space_left >= MAX_USB_MIDI_PACKET_SIZE) - { - midi_from_device_overflow = 0; - SET_SHARED_GLOBAL(g_midi_from_host_buffer, midi_from_host_wrptr); - XUD_SetReady(midi_from_host_usb_ep, 1); - } - } - - if (midi_data_remaining_to_device) - { - /* There is more data to send to the midi/uart thread */ - read_via_xc_ptr(datum, midi_from_host_rdptr); - outuint(c_midi, datum); - } - } - else /* if(is_ack) */ - { - // the midi/uart thread has sent us some data - midi_send_ack(c_midi); - if (midi_data_collected_from_device < MIDI_USB_BUFFER_TO_HOST_SIZE) - { - // there is room in the collecting buffer for the data - xc_ptr p = (midi_to_host_buffer_being_collected + 4) - + midi_data_collected_from_device; - - // add data to the buffer - write_via_xc_ptr(p, datum); - midi_data_collected_from_device += 4; - } - else - { - //printstrln("decouple d->h overflow"); - // too many events from device - drop it - } - - // if we are not sending data to the host then initiate it - if (!midi_waiting_on_send_to_host) - { - // printstr("decouple->buffer: "); - // printintln(midi_data_collected_from_device); - write_via_xc_ptr(midi_to_host_buffer_being_collected, - midi_data_collected_from_device); - midi_data_collected_from_device = 0; - swap(midi_to_host_buffer_being_collected, - midi_to_host_buffer_being_sent); - // signal other side to swap - { - int len; - asm("ldw %0, %1[0]":"=r"(len):"r"(midi_to_host_buffer_being_sent)); - XUD_SetReady_In(midi_to_host_usb_ep, 0, midi_to_host_buffer_being_sent+4, len); - } - // midi_send_ack(c_midi_buf); - midi_waiting_on_send_to_host = 1; - } - } - cont = 1; - break; - default: - break; - } - if (cont) - continue; - } ->>>>>>> master -#endif // MIDI - - - } -} - From 577b5f500d37896095d9ee14610bb712f11f25d0 Mon Sep 17 00:00:00 2001 From: Richard Osborne Date: Fri, 29 Nov 2013 18:41:23 +0000 Subject: [PATCH 39/72] Make functions static where possible, no intended functionality change. This saves 208 bytes. --- module_dfu/src/dfu.xc | 8 ++++---- module_usb_audio/audio.xc | 4 ++-- module_usb_audio/clocking/clockgen.xc | 6 +++--- module_usb_audio/endpoint0/audiorequests.xc | 14 +++++++------- module_usb_audio/mixer/mixer.xc | 16 ++++++++-------- module_usb_audio/usb_buffer/decouple.xc | 4 ++-- module_usb_midi/src/midiinparse.xc | 2 +- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/module_dfu/src/dfu.xc b/module_dfu/src/dfu.xc index 4a6cfdbf..bbeec696 100644 --- a/module_dfu/src/dfu.xc +++ b/module_dfu/src/dfu.xc @@ -357,7 +357,7 @@ int DFUReportResetState(chanend ?c_user_cmd) return inDFU; } -int XMOS_DFU_RevertFactory(chanend ?c_user_cmd) +static int XMOS_DFU_RevertFactory(chanend ?c_user_cmd) { unsigned s = 0; @@ -371,7 +371,7 @@ int XMOS_DFU_RevertFactory(chanend ?c_user_cmd) return 0; } -int XMOS_DFU_SelectImage(unsigned int index, chanend ?c_user_cmd) +static int XMOS_DFU_SelectImage(unsigned int index, chanend ?c_user_cmd) { // Select the image index for firmware update // Currently not used or implemented @@ -379,12 +379,12 @@ int XMOS_DFU_SelectImage(unsigned int index, chanend ?c_user_cmd) } -int XMOS_DFU_SaveState() +static int XMOS_DFU_SaveState() { return 0; } -int XMOS_DFU_LoadState() +static int XMOS_DFU_LoadState() { return 0; } diff --git a/module_usb_audio/audio.xc b/module_usb_audio/audio.xc index c6a3821f..d95cd6f2 100755 --- a/module_usb_audio/audio.xc +++ b/module_usb_audio/audio.xc @@ -142,7 +142,7 @@ static inline void doI2SClocks(unsigned divide) /* I2S delivery thread */ #pragma unsafe arrays -{unsigned, unsigned} deliver(chanend c_out, chanend ?c_spd_out, unsigned divide, unsigned curSamFreq, chanend ?c_dig_rx, chanend ?c_adc) +{unsigned, unsigned} static deliver(chanend c_out, chanend ?c_spd_out, unsigned divide, unsigned curSamFreq, chanend ?c_dig_rx, chanend ?c_adc) { unsigned sample; unsigned underflow = 0; @@ -711,7 +711,7 @@ static inline void doI2SClocks(unsigned divide) /* This function is a dummy version of the deliver thread that does not connect to the codec ports. It is used during DFU reset. */ -{unsigned,unsigned} dummy_deliver(chanend c_out) +{unsigned,unsigned} static dummy_deliver(chanend c_out) { while (1) { diff --git a/module_usb_audio/clocking/clockgen.xc b/module_usb_audio/clocking/clockgen.xc index 3da5ea1c..c0269298 100644 --- a/module_usb_audio/clocking/clockgen.xc +++ b/module_usb_audio/clocking/clockgen.xc @@ -38,13 +38,13 @@ static int clockValid[NUM_CLOCKS]; /* Store current val static int clockInt[NUM_CLOCKS]; /* Interupt flag for clocks */ static int clockId[NUM_CLOCKS]; -int abs(int x) +static int abs(int x) { if (x < 0) return -x; return x; } -int channelContainsControlToken(chanend x) +static int channelContainsControlToken(chanend x) { unsigned char tmpc; @@ -58,7 +58,7 @@ int channelContainsControlToken(chanend x) } -void outInterrupt(chanend c_interruptControl, int value) +static void outInterrupt(chanend c_interruptControl, int value) { /* Non-blocking check for control token */ //if (channelContainsControlToken(c_interruptControl)) diff --git a/module_usb_audio/endpoint0/audiorequests.xc b/module_usb_audio/endpoint0/audiorequests.xc index 57ae892a..22f42c32 100644 --- a/module_usb_audio/endpoint0/audiorequests.xc +++ b/module_usb_audio/endpoint0/audiorequests.xc @@ -54,7 +54,7 @@ unsigned int g_curSamFreq48000Family = DEFAULT_FREQ % 48000 == 0; unsigned int g_curSamFreqMultiplier = DEFAULT_FREQ / 48000; /* Store an int into a char array: Note this allows non-word aligned access unlike reinerpret cast */ -void storeInt(unsigned char buffer[], int index, int val) +static void storeInt(unsigned char buffer[], int index, int val) { buffer[index+3] = val>>24; buffer[index+2] = val>>16; @@ -63,13 +63,13 @@ void storeInt(unsigned char buffer[], int index, int val) } /* Store an short into a char array: Note this allows non-word aligned access unlike reinerpret cast */ -void storeShort(unsigned char buffer[], int index, short val) +static void storeShort(unsigned char buffer[], int index, short val) { buffer[index+1] = val>>8; buffer[index] = val; } -void storeFreq(unsigned char buffer[], int &i, int freq) +static void storeFreq(unsigned char buffer[], int &i, int freq) { storeInt(buffer, i, freq); i+=4; @@ -81,7 +81,7 @@ void storeFreq(unsigned char buffer[], int &i, int freq) } -unsigned longMul(unsigned a, unsigned b, int prec) +static unsigned longMul(unsigned a, unsigned b, int prec) { unsigned x,y; unsigned ret; @@ -94,12 +94,12 @@ unsigned longMul(unsigned a, unsigned b, int prec) return ret; } -void setG_curSamFreqMultiplier(int x) { +static void setG_curSamFreqMultiplier(int x) { asm(" stw %0, dp[g_curSamFreqMultiplier]" :: "r"(x)); } /* Update master volume i.e. i.e update weights for all channels */ -void updateMasterVol( int unitID, chanend ?c_mix_ctl) +static void updateMasterVol( int unitID, chanend ?c_mix_ctl) { int x; #ifndef OUT_VOLUME_IN_MIXER @@ -168,7 +168,7 @@ void updateMasterVol( int unitID, chanend ?c_mix_ctl) } } -void updateVol(int unitID, int channel, chanend ?c_mix_ctl) +static void updateVol(int unitID, int channel, chanend ?c_mix_ctl) { int x; #ifndef OUT_VOLUME_IN_MIXER diff --git a/module_usb_audio/mixer/mixer.xc b/module_usb_audio/mixer/mixer.xc index cf0f8417..1ba91b39 100644 --- a/module_usb_audio/mixer/mixer.xc +++ b/module_usb_audio/mixer/mixer.xc @@ -115,7 +115,7 @@ int doMix8(xc_ptr samples, xc_ptr mult); /* DO NOT inline, causes 10.4.2 tools to add extra loads in loop */ /* At 18 x 12dB we could get 64 x bigger */ #pragma unsafe arrays -int doMix(xc_ptr samples, xc_ptr ptr, xc_ptr mult) +static int doMix(xc_ptr samples, xc_ptr ptr, xc_ptr mult) { int h=0; int l=0; @@ -151,7 +151,7 @@ int doMix(xc_ptr samples, xc_ptr ptr, xc_ptr mult) #endif #pragma unsafe arrays -void giveSamplesToHost(chanend c, xc_ptr samples, xc_ptr ptr, xc_ptr multIn) +static void giveSamplesToHost(chanend c, xc_ptr samples, xc_ptr ptr, xc_ptr multIn) { #if defined(IN_VOLUME_IN_MIXER) && defined(IN_VOLUME_AFTER_MIX) int mult; @@ -220,7 +220,7 @@ static void getSamplesFromHost(chanend c, xc_ptr samples, int base) } #pragma unsafe arrays -void giveSamplesToDevice(chanend c, xc_ptr samples, xc_ptr ptr, xc_ptr multOut) +static void giveSamplesToDevice(chanend c, xc_ptr samples, xc_ptr ptr, xc_ptr multOut) { #pragma loop unroll for (int i=0;i 96000); +static int mixer1_mix2_flag = (DEFAULT_FREQ > 96000); #pragma unsafe arrays -void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2) +static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2) { int mixed; unsigned cmd; @@ -515,10 +515,10 @@ void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2) } } -int mixer2_mix2_flag = (DEFAULT_FREQ > 96000); +static int mixer2_mix2_flag = (DEFAULT_FREQ > 96000); #pragma unsafe arrays -void mixer2(chanend c_mixer1, chanend c_audio) +static void mixer2(chanend c_mixer1, chanend c_audio) { int mixed; diff --git a/module_usb_audio/usb_buffer/decouple.xc b/module_usb_audio/usb_buffer/decouple.xc index 5f545ae4..9ebf6d2f 100644 --- a/module_usb_audio/usb_buffer/decouple.xc +++ b/module_usb_audio/usb_buffer/decouple.xc @@ -105,7 +105,7 @@ int slotSize = 3; /* 3 bytes per sample for Audio Class 1.0 */ #pragma select handler #pragma unsafe arrays -void handle_audio_request(chanend c_mix_out) +void handle_audio_request(chanend c_mix_out) { int outSamps; int space_left; @@ -472,7 +472,7 @@ unsigned g_intFlag = 0; extern unsigned char g_intData[8]; -void check_for_interrupt(chanend ?c_clk_int) { +static void check_for_interrupt(chanend ?c_clk_int) { unsigned tmp; select diff --git a/module_usb_midi/src/midiinparse.xc b/module_usb_midi/src/midiinparse.xc index ed651e2a..dd7dcf1f 100644 --- a/module_usb_midi/src/midiinparse.xc +++ b/module_usb_midi/src/midiinparse.xc @@ -42,7 +42,7 @@ void reset_midi_state(struct midi_in_parse_state &mips) { * @brief Construct USB MIDI event * */ -unsigned makeEvent(unsigned cable_number, unsigned codeIndexNumber, unsigned midi0, unsigned midi1, unsigned midi2) { +static unsigned makeEvent(unsigned cable_number, unsigned codeIndexNumber, unsigned midi0, unsigned midi1, unsigned midi2) { unsigned event = (cable_number << 28); event |= (codeIndexNumber << 24); event |= (midi0 << 16); From 2c3604311951264f8456463ca8268dd8f3f900c8 Mon Sep 17 00:00:00 2001 From: Richard Osborne Date: Tue, 3 Dec 2013 18:10:40 +0000 Subject: [PATCH 40/72] Assign unique string indexes using a enum instead of #defines. --- module_usb_audio/endpoint0/descriptors.h | 44 +++++++++--------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/module_usb_audio/endpoint0/descriptors.h b/module_usb_audio/endpoint0/descriptors.h index 8d494be6..46abddea 100644 --- a/module_usb_audio/endpoint0/descriptors.h +++ b/module_usb_audio/endpoint0/descriptors.h @@ -243,44 +243,32 @@ unsigned char devQualDesc_Null[] = // Positions in strDescs_Audio2 -#define INTERNAL_CLOCK_STRING_INDEX (14) -#define SPDIF_CLOCK_STRING_INDEX (15) - +enum { + INTERNAL_CLOCK_STRING_INDEX = 14, #ifdef SPDIF_RX -#define ADAT_CLOCK_STRING_INDEX (SPDIF_CLOCK_STRING_INDEX + 1) -#else -#define ADAT_CLOCK_STRING_INDEX (SPDIF_CLOCK_STRING_INDEX) + SPDIF_CLOCK_STRING_INDEX, #endif - #ifdef ADAT_RX -#define DFU_STRING_INDEX (ADAT_CLOCK_STRING_INDEX + 1) -#else -#define DFU_STRING_INDEX (ADAT_CLOCK_STRING_INDEX) + ADAT_CLOCK_STRING_INDEX, #endif - #ifdef DFU -#define MIDI_OUT_STRING_INDEX (DFU_STRING_INDEX + 1) -#else -#define MIDI_OUT_STRING_INDEX (DFU_STRING_INDEX) + DFU_STRING_INDEX, #endif - -#define MIDI_IN_STRING_INDEX (MIDI_OUT_STRING_INDEX + 1) - #ifdef MIDI -#define OUTPUT_INTERFACE_STRING_INDEX (MIDI_OUT_STRING_INDEX + 2) -#else -#define OUTPUT_INTERFACE_STRING_INDEX (MIDI_OUT_STRING_INDEX) + MIDI_OUT_STRING_INDEX, + MIDI_IN_STRING_INDEX, #endif - -#define INPUT_INTERFACE_STRING_INDEX (OUTPUT_INTERFACE_STRING_INDEX + NUM_USB_CHAN_OUT) - -#define MIXER_STRING_INDEX (INPUT_INTERFACE_STRING_INDEX + NUM_USB_CHAN_IN) - + OUTPUT_INTERFACE_STRING_INDEX, + OUTPUT_INTERFACE_LAST_STRING_INDEX = OUTPUT_INTERFACE_STRING_INDEX + NUM_USB_CHAN_OUT - 1, + INPUT_INTERFACE_STRING_INDEX, + INPUT_INTERFACE_LAST_STRING_INDEX = INPUT_INTERFACE_STRING_INDEX + NUM_USB_CHAN_IN - 1, #ifdef MIXER -#define IAP_INTERFACE_STRING_INDEX (MIXER_STRING_INDEX + MAX_MIX_COUNT) -#else -#define IAP_INTERFACE_STRING_INDEX (MIXER_STRING_INDEX) + MIXER_STRING_INDEX, #endif +#ifdef IAP + IAP_INTERFACE_STRING_INDEX, +#endif +}; #ifdef HID_CONTROLS unsigned char hidReportDescriptor[] = { From 47d56e71385330144dd8e1aa59a1db3800e1973c Mon Sep 17 00:00:00 2001 From: Richard Osborne Date: Tue, 3 Dec 2013 18:10:56 +0000 Subject: [PATCH 41/72] Update comment. --- module_usb_audio/endpoint0/descriptors.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/endpoint0/descriptors.h b/module_usb_audio/endpoint0/descriptors.h index 46abddea..a98a8fe3 100644 --- a/module_usb_audio/endpoint0/descriptors.h +++ b/module_usb_audio/endpoint0/descriptors.h @@ -242,7 +242,7 @@ unsigned char devQualDesc_Null[] = #define OUTPUT_ALT_LENGTH (OUTPUT_ALT_LENGTH_ADAT + OUTPUT_ALT_LENGTH_DSD) -// Positions in strDescs_Audio2 +// Positions in strDescs enum { INTERNAL_CLOCK_STRING_INDEX = 14, #ifdef SPDIF_RX From c337eccf0add0c96f6f6aa4374c7852b35b0237a Mon Sep 17 00:00:00 2001 From: Richard Osborne Date: Wed, 4 Dec 2013 11:46:18 +0000 Subject: [PATCH 42/72] Remove duplicate constants for string indicies. It looks like STR_INDEX_OUT_CHAN STR_INDEX_IN_CHAN weren't calculated correctly, and we already have existing constants for the index of the input / output strings. --- module_usb_audio/endpoint0/descriptors.h | 30 ------------------ module_usb_audio/endpoint0/endpoint0.xc | 40 ++++++++++++------------ 2 files changed, 20 insertions(+), 50 deletions(-) diff --git a/module_usb_audio/endpoint0/descriptors.h b/module_usb_audio/endpoint0/descriptors.h index a98a8fe3..3e6911e9 100644 --- a/module_usb_audio/endpoint0/descriptors.h +++ b/module_usb_audio/endpoint0/descriptors.h @@ -1390,36 +1390,6 @@ unsigned char cfgDesc_Audio2[] = }; - - -/* String table */ -#ifdef SPDIF_RX -#define SPDIF_RX_NUM_STRS 1 -#else -#define SPDIF_RX_NUM_STRS 0 -#endif - -#ifdef ADAT_RX -#define ADAT_RX_NUM_STRS 1 -#else -#define ADAT_RX_NUM_STRS 0 -#endif - -#ifdef MIDI -#define MIDI_NUM_STRS 2 -#else -#define MIDI_NUM_STRS 0 -#endif - -#ifdef DFU -#define DFU_NUM_STRS 1 -#else -#define DFU_NUM_STRS 0 -#endif - -#define STR_INDEX_OUT_CHAN (10 + SPDIF_RX_NUM_STRS + ADAT_RX_NUM_STRS + MIDI_NUM_STRS + DFU_NUM_STRS) -#define STR_INDEX_IN_CHAN (STR_INDEX_OUT_CHAN + NUM_USB_CHAN_OUT) - #define APPEND_VENDOR_STR(x) VENDOR_STR" "#x #define APPEND_PRODUCT_STR_A2(x) PRODUCT_STR_A2 " "#x diff --git a/module_usb_audio/endpoint0/endpoint0.xc b/module_usb_audio/endpoint0/endpoint0.xc index ef389052..b69e66a0 100755 --- a/module_usb_audio/endpoint0/endpoint0.xc +++ b/module_usb_audio/endpoint0/endpoint0.xc @@ -198,33 +198,33 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, /* Build up channel string table - By default all channels are marked as analogue * TODO We really want to do this an build time... */ #if defined(SPDIF_RX) && (SPDIF_RX_INDEX != 0) - safestrcpy(strDescs[SPDIF_RX_INDEX + STR_INDEX_IN_CHAN], "S/PDIF 1"); - safestrcpy(strDescs[SPDIF_RX_INDEX + STR_INDEX_IN_CHAN + 1], "S/PDIF 2"); + safestrcpy(strDescs[SPDIF_RX_INDEX + INPUT_INTERFACE_STRING_INDEX], "S/PDIF 1"); + safestrcpy(strDescs[SPDIF_RX_INDEX + INPUT_INTERFACE_STRING_INDEX + 1], "S/PDIF 2"); #endif #if defined(ADAT_RX) && (ADAT_RX_INDEX != 0) - safestrcpy(strDescs[ADAT_RX_INDEX + STR_INDEX_IN_CHAN], "ADAT 1"); - safestrcpy(strDescs[ADAT_RX_INDEX + STR_INDEX_IN_CHAN + 1], "ADAT 2"); - safestrcpy(strDescs[ADAT_RX_INDEX + STR_INDEX_IN_CHAN + 2], "ADAT 3"); - safestrcpy(strDescs[ADAT_RX_INDEX + STR_INDEX_IN_CHAN + 3], "ADAT 4"); - safestrcpy(strDescs[ADAT_RX_INDEX + STR_INDEX_IN_CHAN + 4], "ADAT 5"); - safestrcpy(strDescs[ADAT_RX_INDEX + STR_INDEX_IN_CHAN + 5], "ADAT 6"); - safestrcpy(strDescs[ADAT_RX_INDEX + STR_INDEX_IN_CHAN + 6], "ADAT 7"); - safestrcpy(strDescs[ADAT_RX_INDEX + STR_INDEX_IN_CHAN + 7], "ADAT 8"); + safestrcpy(strDescs[ADAT_RX_INDEX + INPUT_INTERFACE_STRING_INDEX], "ADAT 1"); + safestrcpy(strDescs[ADAT_RX_INDEX + INPUT_INTERFACE_STRING_INDEX + 1], "ADAT 2"); + safestrcpy(strDescs[ADAT_RX_INDEX + INPUT_INTERFACE_STRING_INDEX + 2], "ADAT 3"); + safestrcpy(strDescs[ADAT_RX_INDEX + INPUT_INTERFACE_STRING_INDEX + 3], "ADAT 4"); + safestrcpy(strDescs[ADAT_RX_INDEX + INPUT_INTERFACE_STRING_INDEX + 4], "ADAT 5"); + safestrcpy(strDescs[ADAT_RX_INDEX + INPUT_INTERFACE_STRING_INDEX + 5], "ADAT 6"); + safestrcpy(strDescs[ADAT_RX_INDEX + INPUT_INTERFACE_STRING_INDEX + 6], "ADAT 7"); + safestrcpy(strDescs[ADAT_RX_INDEX + INPUT_INTERFACE_STRING_INDEX + 7], "ADAT 8"); #endif #if defined(SPDIF) && (SPDIF_TX_INDEX != 0) /* "Analogue naming gets priority */ - safestrcpy(strDescs[SPDIF_TX_INDEX + STR_INDEX_OUT_CHAN], "S/PDIF 1"); - safestrcpy(strDescs[SPDIF_TX_INDEX + STR_INDEX_OUT_CHAN + 1], "S/PDIF 2"); + safestrcpy(strDescs[SPDIF_TX_INDEX + OUTPUT_INTERFACE_STRING_INDEX], "S/PDIF 1"); + safestrcpy(strDescs[SPDIF_TX_INDEX + OUTPUT_INTERFACE_STRING_INDEX + 1], "S/PDIF 2"); #endif #if defined(ADAT_TX) && (ADAT_TX_INDEX != 0) - safestrcpy(strDescs[ADAT_TX_INDEX + STR_INDEX_OUT_CHAN], "ADAT 1"); - safestrcpy(strDescs[ADAT_TX_INDEX + STR_INDEX_OUT_CHAN + 1], "ADAT 2"); - safestrcpy(strDescs[ADAT_TX_INDEX + STR_INDEX_OUT_CHAN + 2], "ADAT 3"); - safestrcpy(strDescs[ADAT_TX_INDEX + STR_INDEX_OUT_CHAN + 3], "ADAT 4"); - safestrcpy(strDescs[ADAT_TX_INDEX + STR_INDEX_OUT_CHAN + 4], "ADAT 5"); - safestrcpy(strDescs[ADAT_TX_INDEX + STR_INDEX_OUT_CHAN + 5], "ADAT 6"); - safestrcpy(strDescs[ADAT_TX_INDEX + STR_INDEX_OUT_CHAN + 6], "ADAT 7"); - safestrcpy(strDescs[ADAT_TX_INDEX + STR_INDEX_OUT_CHAN + 7], "ADAT 8"); + safestrcpy(strDescs[ADAT_TX_INDEX + OUTPUT_INTERFACE_STRING_INDEX], "ADAT 1"); + safestrcpy(strDescs[ADAT_TX_INDEX + OUTPUT_INTERFACE_STRING_INDEX + 1], "ADAT 2"); + safestrcpy(strDescs[ADAT_TX_INDEX + OUTPUT_INTERFACE_STRING_INDEX + 2], "ADAT 3"); + safestrcpy(strDescs[ADAT_TX_INDEX + OUTPUT_INTERFACE_STRING_INDEX + 3], "ADAT 4"); + safestrcpy(strDescs[ADAT_TX_INDEX + OUTPUT_INTERFACE_STRING_INDEX + 4], "ADAT 5"); + safestrcpy(strDescs[ADAT_TX_INDEX + OUTPUT_INTERFACE_STRING_INDEX + 5], "ADAT 6"); + safestrcpy(strDescs[ADAT_TX_INDEX + OUTPUT_INTERFACE_STRING_INDEX + 6], "ADAT 7"); + safestrcpy(strDescs[ADAT_TX_INDEX + OUTPUT_INTERFACE_STRING_INDEX + 7], "ADAT 8"); #endif #ifdef VENDOR_AUDIO_REQS From 09bafcfb3a97e8a32940381c78d21b32691bae0c Mon Sep 17 00:00:00 2001 From: Richard Osborne Date: Mon, 2 Dec 2013 16:40:57 +0000 Subject: [PATCH 43/72] Base the buffer size on the MIDI_USB_BUFFER_TO_HOST_SIZE. The buffer task never writes more than this amount of data to the buffer so there is no point in a bigger buffer. --- module_usb_audio/usb_buffer/usb_buffer.xc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module_usb_audio/usb_buffer/usb_buffer.xc b/module_usb_audio/usb_buffer/usb_buffer.xc index 9e63528d..050e6a8e 100644 --- a/module_usb_audio/usb_buffer/usb_buffer.xc +++ b/module_usb_audio/usb_buffer/usb_buffer.xc @@ -54,8 +54,8 @@ static inline void swap(xc_ptr &a, xc_ptr &b) #endif #ifdef MIDI -static unsigned int g_midi_to_host_buffer_A[MAX_USB_MIDI_PACKET_SIZE/4]; -static unsigned int g_midi_to_host_buffer_B[MAX_USB_MIDI_PACKET_SIZE/4]; +static unsigned int g_midi_to_host_buffer_A[MIDI_USB_BUFFER_TO_HOST_SIZE/4]; +static unsigned int g_midi_to_host_buffer_B[MIDI_USB_BUFFER_TO_HOST_SIZE/4]; static unsigned int g_midi_from_host_buffer[MAX_USB_MIDI_PACKET_SIZE/4]; #endif From 4b6b98af107819db53cb3470b9807620be1d12b5 Mon Sep 17 00:00:00 2001 From: Richard Osborne Date: Wed, 4 Dec 2013 16:24:22 +0000 Subject: [PATCH 44/72] Remove unnecessary runtime initialization. --- module_usb_audio/endpoint0/descriptors.h | 7 +++++-- module_usb_audio/endpoint0/endpoint0.xc | 15 --------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/module_usb_audio/endpoint0/descriptors.h b/module_usb_audio/endpoint0/descriptors.h index 3e6911e9..61f8aa95 100644 --- a/module_usb_audio/endpoint0/descriptors.h +++ b/module_usb_audio/endpoint0/descriptors.h @@ -1404,10 +1404,13 @@ unsigned char cfgDesc_Audio2[] = #endif #endif + +#define STR_USENG 0x0409 + static unsigned char strDescs[][40] = { - "Langids", // 0 LangIDs place holder - APPEND_VENDOR_STR(), // 1 iManufacturer (at MANUFACTURER_STRING_INDEX) + { STR_USENG & 0xff, STR_USENG >> 8, '\0'}, // 0 LangID + APPEND_VENDOR_STR(), // 1 iManufacturer (at MANUFACTURER_STRING_INDEX) "",//SERIAL_STR, // 2 iSerialNumber (at SERIAL_STR_INDEX) diff --git a/module_usb_audio/endpoint0/endpoint0.xc b/module_usb_audio/endpoint0/endpoint0.xc index b69e66a0..5bdd6205 100755 --- a/module_usb_audio/endpoint0/endpoint0.xc +++ b/module_usb_audio/endpoint0/endpoint0.xc @@ -100,24 +100,11 @@ unsigned g_curUsbSpeed = 0; extern unsigned g_iap_reset; #endif - -#define STR_USENG 0x0409 - -#define DESC_STR_LANGIDS \ -{ \ - STR_USENG & 0xff, /* 2 wLangID[0] */ \ - STR_USENG>>8, /* 3 wLangID[0] */ \ - '\0' \ -} - #ifdef NATIVE_DSD /* We remember if we are in DSD mode to avoid Configuring the DAC too often - thus avoiding pops and clicks */ unsigned g_dsdMode = 0; #endif -/* String descriptors */ -static unsigned char strDesc_langIDs[] = DESC_STR_LANGIDS; - void VendorAudioRequestsInit(chanend c_audioControl, chanend ?c_mix_ctl, chanend ?c_clk_ctl); /* Endpoint 0 function. Handles all requests to the device */ @@ -193,8 +180,6 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, } #endif - safememcpy(strDescs[0], strDesc_langIDs, sizeof(strDesc_langIDs)); - /* Build up channel string table - By default all channels are marked as analogue * TODO We really want to do this an build time... */ #if defined(SPDIF_RX) && (SPDIF_RX_INDEX != 0) From a2a151b510be13c72a2ea0515c4eaead7dee43da Mon Sep 17 00:00:00 2001 From: Richard Osborne Date: Fri, 29 Nov 2013 18:52:21 +0000 Subject: [PATCH 45/72] Reduce the amount of output buffering. It looks their was a typo here - the code calculates the maximum audio packet size and uses it for the input buffer but not the output buffer. Now the amount of input buffering matches the amount of output buffering. --- module_usb_audio/usb_buffer/decouple.xc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/usb_buffer/decouple.xc b/module_usb_audio/usb_buffer/decouple.xc index 9ebf6d2f..a10feeb2 100644 --- a/module_usb_audio/usb_buffer/decouple.xc +++ b/module_usb_audio/usb_buffer/decouple.xc @@ -42,7 +42,7 @@ unsigned g_numUsbChanIn = NUM_USB_CHAN_IN; #define MAX_DEVICE_AUD_PACKET_SIZE (MAX(MAX_DEVICE_AUD_PACKET_SIZE_CLASS_ONE, MAX_DEVICE_AUD_PACKET_SIZE_CLASS_TWO)) /* Circular audio buffers */ -unsigned outAudioBuff[BUFF_SIZE_OUT + (MAX_USB_AUD_PACKET_SIZE>>2) + 4]; +unsigned outAudioBuff[BUFF_SIZE_OUT + (MAX_DEVICE_AUD_PACKET_SIZE>>2) + 4]; unsigned audioBuffIn[BUFF_SIZE_IN + (MAX_DEVICE_AUD_PACKET_SIZE>>2) + 4]; unsigned inZeroBuff[(MAX_DEVICE_AUD_PACKET_SIZE>>2)+4]; From 82e07458911e4115981508e0538f682c146544ca Mon Sep 17 00:00:00 2001 From: Richard Osborne Date: Mon, 2 Dec 2013 15:34:13 +0000 Subject: [PATCH 46/72] Remove local buffer pointers which are set but never used. --- module_usb_audio/usb_buffer/usb_buffer.xc | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/module_usb_audio/usb_buffer/usb_buffer.xc b/module_usb_audio/usb_buffer/usb_buffer.xc index 2f6cc64f..117ef82c 100644 --- a/module_usb_audio/usb_buffer/usb_buffer.xc +++ b/module_usb_audio/usb_buffer/usb_buffer.xc @@ -56,7 +56,7 @@ static inline void swap(xc_ptr &a, xc_ptr &b) #ifdef MIDI unsigned int g_midi_to_host_buffer_A[MAX_USB_MIDI_PACKET_SIZE/4+4]; unsigned int g_midi_to_host_buffer_B[MAX_USB_MIDI_PACKET_SIZE/4+4]; -int g_midi_from_host_buffer[MAX_USB_MIDI_PACKET_SIZE/4+4]; +unsigned int g_midi_from_host_buffer[MAX_USB_MIDI_PACKET_SIZE/4+4]; #endif #ifdef IAP @@ -145,15 +145,12 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud xc_ptr aud_from_host_buffer = 0; #ifdef MIDI - xc_ptr midi_from_host_buffer = 0; - xc_ptr midi_to_host_buffer = 0; - xc_ptr midi_to_host_waiting_buffer = 0; + xc_ptr midi_from_host_buffer = array_to_xc_ptr(g_midi_from_host_buffer); xc_ptr midi_from_host_rdptr; xc_ptr midi_to_host_buffer_being_sent = array_to_xc_ptr(g_midi_to_host_buffer_A); xc_ptr midi_to_host_buffer_being_collected = array_to_xc_ptr(g_midi_to_host_buffer_B); - int is_ack; unsigned int datum; int midi_data_remaining_to_device = 0; @@ -214,16 +211,7 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud expected_fb = ((DEFAULT_FREQ * 0x2000) / 1000); #endif - } - -#ifdef MIDI - // get the two buffers to use for midi device->host - asm("ldaw %0, dp[g_midi_to_host_buffer_A]":"=r"(midi_to_host_buffer)); - asm("ldaw %0, dp[g_midi_to_host_buffer_B]":"=r"(midi_to_host_waiting_buffer)); - asm("ldaw %0, dp[g_midi_from_host_buffer]":"=r"(midi_from_host_buffer)); - - swap(midi_to_host_buffer, midi_to_host_waiting_buffer); -#endif + } #ifdef OUTPUT SET_SHARED_GLOBAL(g_aud_from_host_flag, 1); @@ -519,8 +507,6 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud /* MIDI IN to host */ case XUD_SetData_Select(c_midi_to_host, ep_midi_to_host, tmp): asm("#midi d->h"); - - swap(midi_to_host_buffer, midi_to_host_waiting_buffer); /* The buffer has been sent to the host, so we can ack the midi thread */ if (midi_data_collected_from_device != 0) From e56b271e0c969a6ad958d2cc8b3068359df5473d Mon Sep 17 00:00:00 2001 From: Richard Osborne Date: Mon, 2 Dec 2013 15:36:32 +0000 Subject: [PATCH 47/72] Make MIDI buffer globals static. --- module_usb_audio/usb_buffer/usb_buffer.xc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module_usb_audio/usb_buffer/usb_buffer.xc b/module_usb_audio/usb_buffer/usb_buffer.xc index 117ef82c..897b0fe4 100644 --- a/module_usb_audio/usb_buffer/usb_buffer.xc +++ b/module_usb_audio/usb_buffer/usb_buffer.xc @@ -54,9 +54,9 @@ static inline void swap(xc_ptr &a, xc_ptr &b) #endif #ifdef MIDI -unsigned int g_midi_to_host_buffer_A[MAX_USB_MIDI_PACKET_SIZE/4+4]; -unsigned int g_midi_to_host_buffer_B[MAX_USB_MIDI_PACKET_SIZE/4+4]; -unsigned int g_midi_from_host_buffer[MAX_USB_MIDI_PACKET_SIZE/4+4]; +static unsigned int g_midi_to_host_buffer_A[MAX_USB_MIDI_PACKET_SIZE/4+4]; +static unsigned int g_midi_to_host_buffer_B[MAX_USB_MIDI_PACKET_SIZE/4+4]; +static unsigned int g_midi_from_host_buffer[MAX_USB_MIDI_PACKET_SIZE/4+4]; #endif #ifdef IAP From 662ac7df58af07f3dc1a34a04933b903e5ab5fdd Mon Sep 17 00:00:00 2001 From: Richard Osborne Date: Mon, 2 Dec 2013 16:39:41 +0000 Subject: [PATCH 48/72] Don't store length of the buffer in the buffer itself. This is pointless as nothing ever reads it. --- module_usb_audio/usb_buffer/usb_buffer.xc | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/module_usb_audio/usb_buffer/usb_buffer.xc b/module_usb_audio/usb_buffer/usb_buffer.xc index 897b0fe4..9e63528d 100644 --- a/module_usb_audio/usb_buffer/usb_buffer.xc +++ b/module_usb_audio/usb_buffer/usb_buffer.xc @@ -54,9 +54,9 @@ static inline void swap(xc_ptr &a, xc_ptr &b) #endif #ifdef MIDI -static unsigned int g_midi_to_host_buffer_A[MAX_USB_MIDI_PACKET_SIZE/4+4]; -static unsigned int g_midi_to_host_buffer_B[MAX_USB_MIDI_PACKET_SIZE/4+4]; -static unsigned int g_midi_from_host_buffer[MAX_USB_MIDI_PACKET_SIZE/4+4]; +static unsigned int g_midi_to_host_buffer_A[MAX_USB_MIDI_PACKET_SIZE/4]; +static unsigned int g_midi_to_host_buffer_B[MAX_USB_MIDI_PACKET_SIZE/4]; +static unsigned int g_midi_from_host_buffer[MAX_USB_MIDI_PACKET_SIZE/4]; #endif #ifdef IAP @@ -511,14 +511,11 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud /* The buffer has been sent to the host, so we can ack the midi thread */ if (midi_data_collected_from_device != 0) { - /* We have some more data to send set the amount of data to send */ - write_via_xc_ptr(midi_to_host_buffer_being_collected, midi_data_collected_from_device); - /* Swap the collecting and sending buffer */ swap(midi_to_host_buffer_being_collected, midi_to_host_buffer_being_sent); /* Request to send packet */ - XUD_SetReady_InPtr(ep_midi_to_host, midi_to_host_buffer_being_sent+4, midi_data_collected_from_device); + XUD_SetReady_InPtr(ep_midi_to_host, midi_to_host_buffer_being_sent, midi_data_collected_from_device); /* Mark as waiting for host to poll us */ midi_waiting_on_send_to_host = 1; @@ -616,7 +613,7 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud if (midi_data_collected_from_device < MIDI_USB_BUFFER_TO_HOST_SIZE) { /* There is room in the collecting buffer for the data */ - xc_ptr p = (midi_to_host_buffer_being_collected + 4) + midi_data_collected_from_device; + xc_ptr p = midi_to_host_buffer_being_collected + midi_data_collected_from_device; // Add data to the buffer write_via_xc_ptr(p, datum); midi_data_collected_from_device += 4; @@ -629,12 +626,10 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud // If we are not sending data to the host then initiate it if (!midi_waiting_on_send_to_host) { - write_via_xc_ptr(midi_to_host_buffer_being_collected, midi_data_collected_from_device); - swap(midi_to_host_buffer_being_collected, midi_to_host_buffer_being_sent); // Signal other side to swap - XUD_SetReady_InPtr(ep_midi_to_host, midi_to_host_buffer_being_sent+4, midi_data_collected_from_device); + XUD_SetReady_InPtr(ep_midi_to_host, midi_to_host_buffer_being_sent, midi_data_collected_from_device); midi_data_collected_from_device = 0; midi_waiting_on_send_to_host = 1; } From b2816ac3aa4163a8b91c6079a89c9a5418292602 Mon Sep 17 00:00:00 2001 From: Richard Osborne Date: Tue, 3 Dec 2013 17:46:58 +0000 Subject: [PATCH 49/72] Remove commented out code. --- module_usb_audio/endpoint0/descriptors.h | 19 ------------------- module_usb_audio/endpoint0/endpoint0.xc | 5 ----- 2 files changed, 24 deletions(-) diff --git a/module_usb_audio/endpoint0/descriptors.h b/module_usb_audio/endpoint0/descriptors.h index 8f76168a..8d494be6 100644 --- a/module_usb_audio/endpoint0/descriptors.h +++ b/module_usb_audio/endpoint0/descriptors.h @@ -2011,23 +2011,4 @@ unsigned char cfgDesc_Audio1[] = }; #endif - -#define APPEND_VENDOR_STR(x) VENDOR_STR#x -#if 0 -static unsigned char strDescs_Audio1[][40] = -{ - "Langids", /* String 0 (LangIDs) place holder */ - APPEND_VENDOR_STR(), // 1 iManufacturer - APPEND_VENDOR_STR(USB Audio 1.0), // 2 iProduct and iInterface for control interface - "",//SERIAL_STR, // 3 iSerialNumber - - APPEND_VENDOR_STR(USB 1.0 Audio Out), // 4 iInterface for Streaming interaces - APPEND_VENDOR_STR(USB 1.0 Audio In), // 5 - - APPEND_VENDOR_STR(Audio 1.0 Output), // 6 "USB Input Terminal" (User sees as output from host) - APPEND_VENDOR_STR(Audio 1.0 Input), // 7 "USB Output Terminal" (User sees as input to host) - - APPEND_VENDOR_STR(DFU) // 8 iInterface for DFU interface -}; -#endif #endif diff --git a/module_usb_audio/endpoint0/endpoint0.xc b/module_usb_audio/endpoint0/endpoint0.xc index 4e5863bd..ef389052 100755 --- a/module_usb_audio/endpoint0/endpoint0.xc +++ b/module_usb_audio/endpoint0/endpoint0.xc @@ -193,11 +193,6 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, } #endif - /* Copy langIDs string desc into string[0] */ - /* TODO: Macro? */ -#if defined(AUDIO_CLASS_FALLBACK) || (AUDIO_CLASS == 1) - //safememcpy(strDescs_Audio1[0], strDesc_langIDs, sizeof(strDesc_langIDs)); -#endif safememcpy(strDescs[0], strDesc_langIDs, sizeof(strDesc_langIDs)); /* Build up channel string table - By default all channels are marked as analogue From e7ade114d656bef6ab214c5859db29eaf5f78e04 Mon Sep 17 00:00:00 2001 From: Richard Osborne Date: Mon, 9 Dec 2013 18:21:50 +0000 Subject: [PATCH 50/72] Add functions for working with queues of bytes. This is used by the IAP code. --- module_queue/src/queue.h | 11 +++++++++++ module_queue/src/queue.xc | 2 ++ 2 files changed, 13 insertions(+) diff --git a/module_queue/src/queue.h b/module_queue/src/queue.h index 23e4cea5..39b57728 100644 --- a/module_queue/src/queue.h +++ b/module_queue/src/queue.h @@ -43,6 +43,17 @@ inline unsigned queue_pop_word(queue_t &q, unsigned array[]) { return array[q.rdptr++ & q.mask]; } +inline void queue_push_byte(queue_t &q, unsigned char array[], unsigned data) +{ + assert(!queue_is_full(q)); + array[q.wrptr++ & q.mask] = data; +} + +inline unsigned queue_pop_byte(queue_t &q, unsigned char array[]) { + assert(!queue_is_empty(q)); + return array[q.rdptr++ & q.mask]; +} + inline unsigned queue_items(const queue_t &q) { return q.wrptr - q.rdptr; } diff --git a/module_queue/src/queue.xc b/module_queue/src/queue.xc index 58c78248..c78f2b0f 100644 --- a/module_queue/src/queue.xc +++ b/module_queue/src/queue.xc @@ -7,5 +7,7 @@ extern inline int queue_is_empty(const queue_t &q); extern inline int queue_is_full(const queue_t &q); extern inline void queue_push_word(queue_t &q, unsigned array[], unsigned data); extern inline unsigned queue_pop_word(queue_t &q, unsigned array[]); +extern inline void queue_push_byte(queue_t &q, unsigned char array[], unsigned data); +extern inline unsigned queue_pop_byte(queue_t &q, unsigned char array[]); extern inline unsigned queue_space(const queue_t &q); extern inline unsigned queue_items(const queue_t &q); From dbf9d350c3143c39e4c7971573a7e3d334750b41 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 11 Dec 2013 18:18:50 +0000 Subject: [PATCH 51/72] Fixed G-based DFU build (From when XUD API was diffent on L vs G --- module_dfu/src/dfu.xc | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/module_dfu/src/dfu.xc b/module_dfu/src/dfu.xc index 4a6cfdbf..7ec7ff62 100644 --- a/module_dfu/src/dfu.xc +++ b/module_dfu/src/dfu.xc @@ -3,11 +3,11 @@ #include "devicedefines.h" #include "xud.h" -#ifdef ARCH_G -#include "XUD_USB_Defines.h" -#else +//#ifdef ARCH_G +//#include "XUD_USB_Defines.h" +//#else #include "usb.h" -#endif +//#endif #include "dfu_types.h" #include "flash_interface.h" @@ -400,11 +400,7 @@ int DFUDeviceRequests(XUD_ep ep0_out, XUD_ep &?ep0_in, USB_SetupPacket_t &sp, ch { // Host to device if (sp.wLength) -#ifdef ARCH_G - data_buffer_len = XUD_GetBuffer_(ep0_out, 0, (data_buffer, unsigned char[])); -#else data_buffer_len = XUD_GetBuffer(ep0_out, (data_buffer, unsigned char[])); -#endif } // Map Standard DFU commands onto device level firmware upgrade mechanism From a00d3c329b86a6d08fd0552069a3bb85112b7da9 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 11 Dec 2013 18:19:15 +0000 Subject: [PATCH 52/72] Fixed up tile defines in main.xc Some were hardcoded to 0 --- module_usb_audio/main.xc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/module_usb_audio/main.xc b/module_usb_audio/main.xc index c685c0de..036a4cca 100755 --- a/module_usb_audio/main.xc +++ b/module_usb_audio/main.xc @@ -109,7 +109,7 @@ on tile[AUDIO_IO_TILE] : in port p_bclk = PORT_I2S_BCLK; #endif on tile[AUDIO_IO_TILE] : port p_mclk_in = PORT_MCLK_IN; -on tile[0] : in port p_for_mclk_count = PORT_MCLK_COUNT; +on tile[XUD_TILE] : in port p_for_mclk_count = PORT_MCLK_COUNT; #ifdef SPDIF on tile[AUDIO_IO_TILE] : buffered out port:32 p_spdif_tx = PORT_SPDIF_OUT; @@ -126,9 +126,9 @@ on tile[AUDIO_IO_TILE] : clock clk_midi = XS1_CLKBLK_REF; #endif on tile[AUDIO_IO_TILE] : clock clk_audio_mclk = XS1_CLKBLK_2; /* Master clock */ -#if(AUDIO_IO_TILE != 0) -on tile[0] : clock clk_audio_mclk2 = XS1_CLKBLK_2; /* Master clock */ -on tile[0] : in port p_mclk_in2 = PORT_MCLK_IN2; +#if(AUDIO_IO_TILE != XUD_TILE) +on tile[XUD_TILE] : clock clk_audio_mclk2 = XS1_CLKBLK_2; /* Master clock */ +on tile[XUD_TILE] : in port p_mclk_in2 = PORT_MCLK_IN2; #endif @@ -138,7 +138,7 @@ on tile[AUDIO_IO_TILE] : clock clk_mst_spd = XS1_CLKBLK_1; #endif /* L Series needs a port to use for USB reset */ -#ifdef ARCH_L +#if defined(ARCH_L) || defined(ARCH_G) #ifdef PORT_USB_RESET /* This define is checked since it could be on a shift reg or similar */ on tile[XUD_TILE] : out port p_usb_rst = PORT_USB_RESET; From 22afdb295c30ba80fd583383462efc60178a6326 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 12 Dec 2013 10:27:33 +0000 Subject: [PATCH 53/72] Mixer: device chan map inline asm tidy --- module_usb_audio/mixer/mixer.xc | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/module_usb_audio/mixer/mixer.xc b/module_usb_audio/mixer/mixer.xc index b8910309..4fe9726e 100644 --- a/module_usb_audio/mixer/mixer.xc +++ b/module_usb_audio/mixer/mixer.xc @@ -658,11 +658,8 @@ void mixer(chanend c_mix_in, chanend c_mix_out, chanend c_mix_ctl) int num_mixes = DEFAULT_FREQ > 96000 ? 2 : MAX_MIX_COUNT; for (int i=0;i Date: Thu, 12 Dec 2013 12:03:42 +0000 Subject: [PATCH 54/72] Revert "Reduce the amount of output buffering." Not safe if channel count differs between input and output This reverts commit a2a151b510be13c72a2ea0515c4eaead7dee43da. --- module_usb_audio/usb_buffer/decouple.xc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/usb_buffer/decouple.xc b/module_usb_audio/usb_buffer/decouple.xc index a10feeb2..9ebf6d2f 100644 --- a/module_usb_audio/usb_buffer/decouple.xc +++ b/module_usb_audio/usb_buffer/decouple.xc @@ -42,7 +42,7 @@ unsigned g_numUsbChanIn = NUM_USB_CHAN_IN; #define MAX_DEVICE_AUD_PACKET_SIZE (MAX(MAX_DEVICE_AUD_PACKET_SIZE_CLASS_ONE, MAX_DEVICE_AUD_PACKET_SIZE_CLASS_TWO)) /* Circular audio buffers */ -unsigned outAudioBuff[BUFF_SIZE_OUT + (MAX_DEVICE_AUD_PACKET_SIZE>>2) + 4]; +unsigned outAudioBuff[BUFF_SIZE_OUT + (MAX_USB_AUD_PACKET_SIZE>>2) + 4]; unsigned audioBuffIn[BUFF_SIZE_IN + (MAX_DEVICE_AUD_PACKET_SIZE>>2) + 4]; unsigned inZeroBuff[(MAX_DEVICE_AUD_PACKET_SIZE>>2)+4]; From f3aefe39659c0e752cc5a3154d8235e12d66716f Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Fri, 13 Dec 2013 17:55:31 +0000 Subject: [PATCH 55/72] Release updates and XPD for 6.3.1 release --- CHANGELOG.rst | 7 ++++++- xpd.xml | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f83500fb..9670aa7b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,9 +1,14 @@ sc_usb_audio Change Log ======================= +6.3.1 +----- + + * see sw_usb_audio for changelog 6.3.0 ----- - * see sw_usb_audio for changelog + + * see sw_usb_audio for changelog diff --git a/xpd.xml b/xpd.xml index d0cc6776..a7b254f6 100644 --- a/xpd.xml +++ b/xpd.xml @@ -1,6 +1,11 @@ + + d0531d7c68ab67334582c324828e36d617baf8b3 + git://github.com/xcore/sc_util + 1.0.3rc0 + USB Audio Shared Components. For use in the XMOS USB Audio Refererence Designs. False git://git/apps/sc_usb_audio From 728fb4f2cf6bdce96e850419e382dd7a771cef54 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Fri, 13 Dec 2013 17:57:37 +0000 Subject: [PATCH 56/72] Manual BCDDEVICE define change. 6.3.0 -> 6.3.1 --- module_queue/README.rst | 9 +++++++++ module_usb_audio/devicedefines.h | 2 +- xpd.xml | 7 ++++++- 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 module_queue/README.rst diff --git a/module_queue/README.rst b/module_queue/README.rst new file mode 100644 index 00000000..3e0884f9 --- /dev/null +++ b/module_queue/README.rst @@ -0,0 +1,9 @@ + +================ + +:scope: +:description: +:keywords: +:boards: + + diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index f07f4ad9..36d1382c 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -248,7 +248,7 @@ #define BCD_DEVICE_J 6 #define BCD_DEVICE_M 3 -#define BCD_DEVICE_N 0 +#define BCD_DEVICE_N 1 /* Device release number in BCD: 0xJJMN */ #ifndef BCD_DEVICE diff --git a/xpd.xml b/xpd.xml index a7b254f6..fcb51d90 100644 --- a/xpd.xml +++ b/xpd.xml @@ -1,6 +1,11 @@ - + + + XMOS USB Audio Reference Designes + DFU + + d0531d7c68ab67334582c324828e36d617baf8b3 git://github.com/xcore/sc_util From dd945224d30b65ab3401491705c2b8647ca34a90 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Fri, 13 Dec 2013 17:58:39 +0000 Subject: [PATCH 57/72] Removed module_queue readme --- module_queue/README.rst | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 module_queue/README.rst diff --git a/module_queue/README.rst b/module_queue/README.rst deleted file mode 100644 index 3e0884f9..00000000 --- a/module_queue/README.rst +++ /dev/null @@ -1,9 +0,0 @@ - -================ - -:scope: -:description: -:keywords: -:boards: - - From 96b4360e4e6a97a2ff745366d9d0a1da4b75d507 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Mon, 16 Dec 2013 16:45:29 +0000 Subject: [PATCH 58/72] Added comment about IAP ver no module_usb_audio/devicedefines.h --- module_usb_audio/devicedefines.h | 1 + 1 file changed, 1 insertion(+) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index 36d1382c..0bc9619b 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -255,6 +255,7 @@ #define BCD_DEVICE ((BCD_DEVICE_J << 8) | ((BCD_DEVICE_M & 0xF) << 4) | (BCD_DEVICE_N & 0xF)) #endif +/* By default base the iAP version number on USB BCD_DEVICE */ #if defined(IAP) && !defined(ACCESSORY_FIRMWARE_VERSION) #define ACCESSORY_FIRMWARE_VERSION {BCD_DEVICE_J, BCD_DEVICE_M, BCD_DEVICE_N} #endif From 73d8aa1413c517815ce6fdb0d33a78ea1192ea67 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 18 Dec 2013 11:47:25 +0000 Subject: [PATCH 59/72] Removed reference to EP0_THREAD_COMBINED_WITH_SPI and assocaited params --- module_usb_audio/endpoint0/endpoint0.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/module_usb_audio/endpoint0/endpoint0.h b/module_usb_audio/endpoint0/endpoint0.h index 59314dcb..da30bf93 100644 --- a/module_usb_audio/endpoint0/endpoint0.h +++ b/module_usb_audio/endpoint0/endpoint0.h @@ -16,10 +16,6 @@ * \param c_usb_test Optional chanend to be connected to XUD if test modes required. */ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioCtrl, - chanend ?c_mix_ctl,chanend ?c_clk_ctl, chanend ?c_usb_test -#ifdef EP0_THREAD_COMBINED_WITH_SPI - , chanend c_spi, chanend c_spi_ss -#endif -); + chanend ?c_mix_ctl,chanend ?c_clk_ctl, chanend ?c_usb_test); #endif From 0e25b24657f323d9bb79bf9645a2e37114d94f26 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Wed, 18 Dec 2013 23:24:05 +0000 Subject: [PATCH 60/72] Updated MFi firmware version defines (to allow iAP1 and iAP2 to construct version info in required format) --- module_usb_audio/devicedefines.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index 0bc9619b..8a0e8e53 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -256,8 +256,16 @@ #endif /* By default base the iAP version number on USB BCD_DEVICE */ -#if defined(IAP) && !defined(ACCESSORY_FIRMWARE_VERSION) -#define ACCESSORY_FIRMWARE_VERSION {BCD_DEVICE_J, BCD_DEVICE_M, BCD_DEVICE_N} +#if defined(IAP) +#ifndef ACCESSORY_FIRMWARE_MAJOR +#define ACCESSORY_FIRMWARE_MAJOR BCD_DEVICE_J +#endif +#ifndef ACCESSORY_FIRMWARE_MINOR +#define ACCESSORY_FIRMWARE_MINOR BCD_DEVICE_M +#endif +#ifndef ACCESSORY_FIRMWARE_POINT +#define ACCESSORY_FIRMWARE_POINT BCD_DEVICE_N +#endif #endif /* Addition interfaces based on defines */ From 7fe8f1bbcef78b888845dcce83ace3c2c8283165 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 19 Dec 2013 11:54:23 +0000 Subject: [PATCH 61/72] Added use of SAMPLE_SUBSLOT_SIZE_ defines and general use of global slotSizevar. Added unpack/pack of 2 byte slot size. Added unreachable builtins to slotsize switch and default case. --- module_usb_audio/usb_buffer/decouple.xc | 398 +++++++++++++++--------- 1 file changed, 256 insertions(+), 142 deletions(-) diff --git a/module_usb_audio/usb_buffer/decouple.xc b/module_usb_audio/usb_buffer/decouple.xc index 9ebf6d2f..ed042365 100644 --- a/module_usb_audio/usb_buffer/decouple.xc +++ b/module_usb_audio/usb_buffer/decouple.xc @@ -98,9 +98,11 @@ unsigned packState = 0; unsigned packData = 0; #if (AUDIO_CLASS==2) -int slotSize = 4; /* 4 bytes per ssample for Audio Class 2.0 */ +int g_slotSize = SAMPLE_SUBSLOT_SIZE_HS; /* 4 bytes per ssample for Audio Class 2.0 */ +int g_maxPacketSize = MAX_DEVICE_AUD_PACKET_SIZE_CLASS_TWO; #else -int slotSize = 3; /* 3 bytes per sample for Audio Class 1.0 */ +int g_slotSize = SAMPLE_SUBSLOT_SIZE_FS; /* 3 bytes per sample for Audio Class 1.0 */ +int g_maxPacketSize = MAX_DEVICE_AUD_PACKET_SIZE_CLASS_ONE; #endif #pragma select handler @@ -123,11 +125,13 @@ void handle_audio_request(chanend c_mix_out) #if defined(AUDIO_CLASS_FALLBACK) || defined (FULL_SPEED_AUDIO_2) if (usb_speed == XUD_SPEED_HS) { - slotSize = 4; /* 4 bytes per sample */ + g_slotSize = SAMPLE_SUBSLOT_SIZE_HS; /* Typically 4 bytes per sample for HS */ + g_maxPacketSize = MAX_DEVICE_AUD_PACKET_SIZE_CLASS_TWO; } else { - slotSize = 3; /* 3 bytes per sample */ + g_slotSize = SAMPLE_SUBSLOT_SIZE_FS; /* Typically 3 bytes per sample for FS */ + g_maxPacketSize = MAX_DEVICE_AUD_PACKET_SIZE_CLASS_ONE; } #endif @@ -156,77 +160,130 @@ void handle_audio_request(chanend c_mix_out) } else { - /* Not in overflow, store samples from mixer into sample buffer */ - if (usb_speed == XUD_SPEED_HS) - { - unsigned ptr = g_aud_to_host_dptr; - for(int i = 0; i < g_numUsbChanIn; i++) + /* Not in overflow, store samples from mixer into sample buffer */ + switch(g_slotSize) + { + case 4: { - /* Receive sample */ - int sample = inuint(c_mix_out); -#if !defined(IN_VOLUME_IN_MIXER) - /* Apply volume */ - int mult; - int h; - unsigned l; - asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multIn),"r"(i)); - {h, l} = macs(mult, sample, 0, 0); - sample = h << 3; - sample |= (l >> 29) & 0x7; // Note, this step is not required if we assume sample depth is 24 (rather than 32) -#elif defined(IN_VOLUME_IN_MIXER) && defined(IN_VOLUME_AFTER_MIX) - sample = sample << 3; +#if (SAMPLE_SUBSLOT_SIZE_HS != 4) && (SAMPLE_SUBSLOT_SIZE_FS != 4) +__builtin_unreachable(); #endif - /* Write into fifo */ - write_via_xc_ptr(ptr, sample); - ptr+=4; + unsigned ptr = g_aud_to_host_dptr; + + for(int i = 0; i < g_numUsbChanIn; i++) + { + /* Receive sample */ + int sample = inuint(c_mix_out); +#if !defined(IN_VOLUME_IN_MIXER) + /* Apply volume */ + int mult; + int h; + unsigned l; + asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multIn),"r"(i)); + {h, l} = macs(mult, sample, 0, 0); + sample = h << 3; + sample |= (l >> 29) & 0x7; // Note, this step is not required if we assume sample depth is 24 (rather than 32) +#elif defined(IN_VOLUME_IN_MIXER) && defined(IN_VOLUME_AFTER_MIX) + sample = sample << 3; +#endif + /* Write into fifo */ + write_via_xc_ptr(ptr, sample); + ptr+=4; + } + + /* Update global pointer */ + g_aud_to_host_dptr = ptr; + break; } - /* Update global pointer */ - g_aud_to_host_dptr = ptr; - } - else - { - for(int i = 0; i < g_numUsbChanIn; i++) - { - /* Receive sample */ - int sample = inuint(c_mix_out); -#ifndef IN_VOLUME_IN_MIXER - /* Apply volume */ - int mult; - int h; - unsigned l; - asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multIn),"r"(i)); - {h, l} = macs(mult, sample, 0, 0); - sample = h << 3; + case 3: +#if (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 3) +__builtin_unreachable(); #endif - /* Pack 3 byte samples */ - switch (packState&0x3) + for(int i = 0; i < g_numUsbChanIn; i++) { - case 0: - packData = sample; - break; - case 1: - packData = packData >> 8 | ((sample & 0xff00)<<16); - write_via_xc_ptr(g_aud_to_host_dptr, packData); - g_aud_to_host_dptr+=4; - write_via_xc_ptr(g_aud_to_host_dptr, sample>>16); - packData = sample; - break; - case 2: - packData = (packData>>16) | ((sample & 0xffff00) << 8); - write_via_xc_ptr(g_aud_to_host_dptr, packData); - g_aud_to_host_dptr+=4; - packData = sample; - break; - case 3: - packData = (packData >> 24) | (sample & 0xffffff00); - write_via_xc_ptr(g_aud_to_host_dptr, packData); - g_aud_to_host_dptr+=4; - break; + /* Receive sample */ + int sample = inuint(c_mix_out); +#ifndef IN_VOLUME_IN_MIXER + /* Apply volume */ + int mult; + int h; + unsigned l; + asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multIn),"r"(i)); + {h, l} = macs(mult, sample, 0, 0); + sample = h << 3; +#endif + /* Pack 3 byte samples */ + switch (packState&0x3) + { + case 0: + packData = sample; + break; + case 1: + packData = (packData >> 8) | ((sample & 0xff00)<<16); + write_via_xc_ptr(g_aud_to_host_dptr, packData); + g_aud_to_host_dptr+=4; + write_via_xc_ptr(g_aud_to_host_dptr, sample>>16); + packData = sample; + break; + case 2: + packData = (packData>>16) | ((sample & 0xffff00) << 8); + write_via_xc_ptr(g_aud_to_host_dptr, packData); + g_aud_to_host_dptr+=4; + packData = sample; + break; + case 3: + packData = (packData >> 24) | (sample & 0xffffff00); + write_via_xc_ptr(g_aud_to_host_dptr, packData); + g_aud_to_host_dptr+=4; + break; + } + packState++; } - packState++; - } + break; + + case 2: + +#if (SAMPLE_SUBSLOT_SIZE_HS != 2) && (SAMPLE_SUBSLOT_SIZE_FS != 2) +__builtin_unreachable(); +#endif + for(int i = 0; i < g_numUsbChanIn; i++) + { + /* Receive sample */ + int sample = inuint(c_mix_out); +#if !defined(IN_VOLUME_IN_MIXER) + /* Apply volume */ + int mult; + int h; + unsigned l; + asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multIn),"r"(i)); + {h, l} = macs(mult, sample, 0, 0); + sample = h << 3; +#if (SAMPLE_BIT_RESOLUTION_HS > 24) || (SAMPLE_BIT_RESOLUTION_FS > 24) + sample |= (l >> 29) & 0x7; // Note, this step is not required if we assume sample depth is 24 (rather than 32) +#endif +#elif defined(IN_VOLUME_IN_MIXER) && defined(IN_VOLUME_AFTER_MIX) + sample = sample << 3; +#endif + /* Write into fifo */ + switch (packState&0x1) + { + case 0: + packData = sample; + break; + case 1: + packData = (packData>>16) | (sample & 0xffff0000); + write_via_xc_ptr(g_aud_to_host_dptr, packData); + g_aud_to_host_dptr+=4; + break; + } + } + break; + + default: + __builtin_unreachable(); + break; } /* Input any remaining channels - past this thread we always operate on max channel count */ @@ -273,79 +330,132 @@ void handle_audio_request(chanend c_mix_out) } else { - if (usb_speed == XUD_SPEED_HS) + switch(g_slotSize) { - /* Buffering not underflow condition send out some samples...*/ - for(int i = 0; i < g_numUsbChanOut; i++) - { + case 4: +#if (SAMPLE_SUBSLOT_SIZE_HS != 4) && (SAMPLE_SUBSLOT_SIZE_FS != 4) +__builtin_unreachable(); +#endif + /* Buffering not underflow condition send out some samples...*/ + for(int i = 0; i < g_numUsbChanOut; i++) + { #pragma xta endpoint "mixer_request" - int sample; - int mult; - int h; - unsigned l; + int sample; + int mult; + int h; + unsigned l; - read_via_xc_ptr(sample, g_aud_from_host_rdptr); - g_aud_from_host_rdptr+=4; + read_via_xc_ptr(sample, g_aud_from_host_rdptr); + g_aud_from_host_rdptr+=4; #ifndef OUT_VOLUME_IN_MIXER - asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i)); - {h, l} = macs(mult, sample, 0, 0); - h <<= 3; - h |= (l >>29)& 0x7; // Note this step is not required if we assume sample depth is 24bit (rather than 32bit) - outuint(c_mix_out, h); -#else - outuint(c_mix_out, sample); + asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i)); + {h, l} = macs(mult, sample, 0, 0); + h <<= 3; +#if (SAMPLE_BIT_RESOLUTION_HS > 24) || (SAMPLE_BIT_RESOLUTION_FS > 24) + h |= (l >>29)& 0x7; // Note this step is not required if we assume sample depth is 24bit (rather than 32bit) #endif - } - } - else - { - /* Buffering not underflow condition send out some samples...*/ - for(int i = 0; i < g_numUsbChanOut; i++) - { -#pragma xta endpoint "mixer_request" - int sample; - int mult; - int h; - unsigned l; + outuint(c_mix_out, h); +#else + outuint(c_mix_out, sample); +#endif + } - /* Unpack 3 byte samples */ - switch (unpackState&0x3) + break; + + case 3: +#if (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 3) +__builtin_unreachable(); +#endif + /* Buffering not underflow condition send out some samples...*/ + for(int i = 0; i < g_numUsbChanOut; i++) { - case 0: - read_via_xc_ptr(unpackData, g_aud_from_host_rdptr); - g_aud_from_host_rdptr+=4; - sample = unpackData << 8; - break; - case 1: - sample = (unpackData >> 16); - read_via_xc_ptr(unpackData, g_aud_from_host_rdptr); - g_aud_from_host_rdptr+=4; - sample = sample | (unpackData << 16); - break; - case 2: - sample = (unpackData >> 8); - read_via_xc_ptr(unpackData, g_aud_from_host_rdptr); - g_aud_from_host_rdptr+=4; - sample = sample | (unpackData<< 24); - break; - case 3: - sample = unpackData & 0xffffff00; - break; - } - unpackState++; +#pragma xta endpoint "mixer_request" + int sample; + int mult; + int h; + unsigned l; + + /* Unpack 3 byte samples */ + switch (unpackState&0x3) + { + case 0: + read_via_xc_ptr(unpackData, g_aud_from_host_rdptr); + g_aud_from_host_rdptr+=4; + sample = unpackData << 8; + break; + case 1: + sample = (unpackData >> 16); + read_via_xc_ptr(unpackData, g_aud_from_host_rdptr); + g_aud_from_host_rdptr+=4; + sample = sample | (unpackData << 16); + break; + case 2: + sample = (unpackData >> 8); + read_via_xc_ptr(unpackData, g_aud_from_host_rdptr); + g_aud_from_host_rdptr+=4; + sample = sample | (unpackData<< 24); + break; + case 3: + sample = unpackData & 0xffffff00; + break; + } + unpackState++; #ifndef OUT_VOLUME_IN_MIXER - asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i)); - {h, l} = macs(mult, sample, 0, 0); - h <<= 3; - outuint(c_mix_out, h); + asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i)); + {h, l} = macs(mult, sample, 0, 0); + h <<= 3; + outuint(c_mix_out, h); #else - outuint(c_mix_out, sample); + outuint(c_mix_out, sample); #endif - } - } + } + break; + + case 2: +#if (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 3) +__builtin_unreachable(); +#endif +/* Buffering not underflow condition send out some samples...*/ + for(int i = 0; i < g_numUsbChanOut; i++) + { +#pragma xta endpoint "mixer_request" + int sample; + int mult; + int h; + unsigned l; + + switch (unpackState&0x1) + { + case 0: + read_via_xc_ptr(unpackData, g_aud_from_host_rdptr); + sample = unpackData << 16; + break; + case 1: + g_aud_from_host_rdptr+=4; + sample = unpackData & 0xffff0000; + break; + } + unpackState++; + +#ifndef OUT_VOLUME_IN_MIXER + asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i)); + {h, l} = macs(mult, sample, 0, 0); + h <<= 3; + outuint(c_mix_out, h); +#else + outuint(c_mix_out, sample); +#endif + } + break; + + default: + __builtin_unreachable(); + break; + + } /* switch(g_slotsize) */ /* Output remaining channels. Past this point we always operate on MAX chan count */ for(int i = 0; i < NUM_USB_CHAN_OUT - g_numUsbChanOut; i++) @@ -354,7 +464,7 @@ void handle_audio_request(chanend c_mix_out) } /* 3/4 bytes per sample */ - aud_data_remaining_to_device -= (g_numUsbChanOut*slotSize); + aud_data_remaining_to_device -= (g_numUsbChanOut*g_slotSize); } if (!inOverflow) @@ -365,16 +475,13 @@ void handle_audio_request(chanend c_mix_out) if (totalSampsToWrite) { - if (usb_speed == XUD_SPEED_HS) - { - g_aud_to_host_wrptr += 4+totalSampsToWrite*4*g_numUsbChanIn; - } - else - { - unsigned int datasize = totalSampsToWrite*3*NUM_USB_CHAN_IN_A1; - datasize = (datasize+3) & (~0x3); // round up to nearest word - g_aud_to_host_wrptr += 4+datasize; - } + unsigned datasize = totalSampsToWrite * g_slotSize * g_numUsbChanIn; + + /* Round up to nearest word - note, not needed for slotsize == 4! */ + datasize = (datasize+3) & (~0x3); + + g_aud_to_host_wrptr += 4+datasize; + if (g_aud_to_host_wrptr >= aud_to_host_fifo_end) { g_aud_to_host_wrptr = aud_to_host_fifo_start; @@ -389,6 +496,7 @@ void handle_audio_request(chanend c_mix_out) totalSampsToWrite = speedRem >> 16; speedRem &= 0xffff; +#if 0 if (usb_speed == XUD_SPEED_HS) { if (totalSampsToWrite < 0 || totalSampsToWrite*4*g_numUsbChanIn > (MAX_DEVICE_AUD_PACKET_SIZE_CLASS_TWO)) @@ -403,6 +511,12 @@ void handle_audio_request(chanend c_mix_out) totalSampsToWrite = 0; } } +#else + if (totalSampsToWrite < 0 || totalSampsToWrite * g_slotSize * g_numUsbChanIn > g_maxPacketSize) + { + totalSampsToWrite = 0; + } +#endif /* Calc slots left in fifo */ space_left = g_aud_to_host_rdptr - g_aud_to_host_wrptr; @@ -413,12 +527,12 @@ void handle_audio_request(chanend c_mix_out) space_left = aud_to_host_fifo_end - g_aud_to_host_wrptr; } - if ((space_left <= 0) || (space_left > totalSampsToWrite*g_numUsbChanIn*4+4)) + if ((space_left <= 0) || (space_left > totalSampsToWrite*g_numUsbChanIn * 4 + 4)) { /* Packet okay, write to fifo */ if (totalSampsToWrite) { - write_via_xc_ptr(g_aud_to_host_wrptr, totalSampsToWrite*slotSize*g_numUsbChanIn); + write_via_xc_ptr(g_aud_to_host_wrptr, totalSampsToWrite*g_slotSize*g_numUsbChanIn); packState = 0; g_aud_to_host_dptr = g_aud_to_host_wrptr + 4; } @@ -432,7 +546,7 @@ void handle_audio_request(chanend c_mix_out) } } - if (!outUnderflow && (aud_data_remaining_to_device<(slotSize*g_numUsbChanOut))) + if (!outUnderflow && (aud_data_remaining_to_device<(g_slotSize*g_numUsbChanOut))) { /* Handle any tail - incase a bad driver sent us a datalength not a multiple of chan count */ if (aud_data_remaining_to_device) @@ -831,7 +945,7 @@ void decouple(chanend c_mix_out, read_via_xc_ptr(datalength, released_buffer); /* Ignore bad small packets */ - if ((datalength >= (g_numUsbChanOut * slotSize)) && (released_buffer == aud_from_host_wrptr)) + if ((datalength >= (g_numUsbChanOut * g_slotSize)) && (released_buffer == aud_from_host_wrptr)) { /* Move the write pointer of the fifo on - round up to nearest word */ From 855ba6b83f6165a60f750c9ccb8ba54b0e9aa74d Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 19 Dec 2013 11:55:34 +0000 Subject: [PATCH 62/72] Fixed up null USB reset port but not null USB clock. This is for case when UserReset is used to reset USB phy (L1 iOS board has USB phy rst on shiftreg --- module_usb_audio/main.xc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/module_usb_audio/main.xc b/module_usb_audio/main.xc index 036a4cca..93966acb 100755 --- a/module_usb_audio/main.xc +++ b/module_usb_audio/main.xc @@ -138,16 +138,18 @@ on tile[AUDIO_IO_TILE] : clock clk_mst_spd = XS1_CLKBLK_1; #endif /* L Series needs a port to use for USB reset */ -#if defined(ARCH_L) || defined(ARCH_G) -#ifdef PORT_USB_RESET +#if (defined(ARCH_L) || defined(ARCH_G)) && defined(PORT_USB_RESET) /* This define is checked since it could be on a shift reg or similar */ on tile[XUD_TILE] : out port p_usb_rst = PORT_USB_RESET; +#else +/* Reset port not required for U series due to built in Phy */ +#define p_usb_rst null #endif + +#if defined (ARCH_L) || defined(ARCH_G) /* L Series also needs a clock for this port */ on tile[XUD_TILE] : clock clk = XS1_CLKBLK_4; #else -/* Reset port not required for SU1 due to built in Phy */ -#define p_usb_rst null #define clk null #endif From d690ad9dfcfd34308576eb26068330c3de781cb4 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 19 Dec 2013 12:00:16 +0000 Subject: [PATCH 63/72] Endpoint 0 now patches Audio 2 descriptors between FS and HS using SAMPLE_SUBSLOT_SIZE_ and SAMPLE_BIT_RESOLTION_ defines. --- module_usb_audio/endpoint0/endpoint0.xc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/module_usb_audio/endpoint0/endpoint0.xc b/module_usb_audio/endpoint0/endpoint0.xc index 5bdd6205..55960487 100755 --- a/module_usb_audio/endpoint0/endpoint0.xc +++ b/module_usb_audio/endpoint0/endpoint0.xc @@ -578,7 +578,10 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, if(g_curUsbSpeed == XUD_SPEED_HS) { /* Mod bSlotSize */ - cfgDesc_Audio2[STREAMING_ALT1_OFFSET+4] = 4; + cfgDesc_Audio2[STREAMING_ALT1_OFFSET+4] = SAMPLE_SUBSLOT_SIZE_HS; + + /* Mod bBitResolution */ + cfgDesc_Audio2[STREAMING_ALT1_OFFSET+5] = SAMPLE_BIT_RESOLUTION_HS; /* wMaxPacketSize */ cfgDesc_Audio2[STREAMING_ALT1_OFFSET+10] = MAX_PACKET_SIZE_OUT_HS&0xff; @@ -587,7 +590,10 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, else { /* Mod bSlotSize */ - cfgDesc_Audio2[STREAMING_ALT1_OFFSET+4] = 3; + cfgDesc_Audio2[STREAMING_ALT1_OFFSET+4] = SAMPLE_SUBSLOT_SIZE_FS; + + /* Mod bBitResolution */ + cfgDesc_Audio2[STREAMING_ALT1_OFFSET+5] = SAMPLE_BIT_RESOLUTION_FS; /* wMaxPacketSize */ cfgDesc_Audio2[STREAMING_ALT1_OFFSET+10] = MAX_PACKET_SIZE_OUT_FS&0xff; From 8bf5bc7ea825667fef5fc285d0099fc00da42cb7 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 19 Dec 2013 12:01:15 +0000 Subject: [PATCH 64/72] Added default values and checks for SAMPLE_BIT_RESOLUTION_ and SAMPLE_SUBSLOT_SIZE_ defines --- module_usb_audio/devicedefines.h | 38 +++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index 0bc9619b..4026e32c 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -246,15 +246,51 @@ #define PID_AUDIO_2 (0x0002) #endif +/* Device release number in BCD: 0xJJMN */ #define BCD_DEVICE_J 6 #define BCD_DEVICE_M 3 #define BCD_DEVICE_N 1 -/* Device release number in BCD: 0xJJMN */ #ifndef BCD_DEVICE #define BCD_DEVICE ((BCD_DEVICE_J << 8) | ((BCD_DEVICE_M & 0xF) << 4) | (BCD_DEVICE_N & 0xF)) #endif +/* Sample Sub-slot size (bytes) for High Speed. Default is 4 bytes */ +#ifndef SAMPLE_SUBSLOT_SIZE_HS +#define SAMPLE_SUBSLOT_SIZE_HS 4 +#endif + +#if (SAMPLE_SUBSLOT_SIZE_HS != 2) && (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_HS != 4) +#error Only SAMPLE_SUBSLOT_SIZE_HS 2, 3 or 4 supported #SAMPLE_SUBSLOT_SIZE_HS +#endif + +/* Sample Sub-slot size (bytes) for Full Speed. Default is 3 bytes */ +#ifndef SAMPLE_SUBSLOT_SIZE_FS +#define SAMPLE_SUBSLOT_SIZE_FS 3 +#endif + +#if (SAMPLE_SUBSLOT_SIZE_FS != 2) && (SAMPLE_SUBSLOT_SIZE_FS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 4) +#error Only SAMPLE_SUBSLOT_SIZE_FS 2, 3 or 4 supported +#endif + +/* Sample bit resolution for High Speed. Default 24bit*/ +#ifndef SAMPLE_BIT_RESOLUTION_HS +#define SAMPLE_BIT_RESOLUTION_HS 24 +#endif + +#if (SAMPLE_BIT_RESOLUTION_HS/8) > SAMPLE_SUBSLOT_SIZE_HS +#error SAMPLE_BIT_RESOLUTION_HS is too big for SAMPLE_SUBSLOT_SIZE_HS +#endif + +/* Sample bit resolution for Full Speed. Default 24bit*/ +#ifndef SAMPLE_BIT_RESOLUTION_FS +#define SAMPLE_BIT_RESOLUTION_FS 24 +#endif + +#if (SAMPLE_BIT_RESOLUTION_FS/8) > SAMPLE_SUBSLOT_SIZE_FS +#error SAMPLE_BIT_RESOLUTION_FS is too big for SAMPLE_SUBSLOT_SIZE_FS +#endif + /* By default base the iAP version number on USB BCD_DEVICE */ #if defined(IAP) && !defined(ACCESSORY_FIRMWARE_VERSION) #define ACCESSORY_FIRMWARE_VERSION {BCD_DEVICE_J, BCD_DEVICE_M, BCD_DEVICE_N} From aa029aa68524206440a48b8c0a7cc7e7c0507e46 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 19 Dec 2013 12:06:40 +0000 Subject: [PATCH 65/72] Fixed usage of MAX_PACKET_SIZE_defines (Input was hardcoded to 1024 bytes) --- module_usb_audio/endpoint0/descriptors.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/module_usb_audio/endpoint0/descriptors.h b/module_usb_audio/endpoint0/descriptors.h index 94158d33..1430cecf 100644 --- a/module_usb_audio/endpoint0/descriptors.h +++ b/module_usb_audio/endpoint0/descriptors.h @@ -312,7 +312,9 @@ unsigned char hidReportDescriptor[] = { * Multiply by number of channels and bytes 25 * 2 * 4 = 200 bytes */ #define MAX_PACKET_SIZE_OUT_HS ((((MAX_FREQ+7999)/8000)+1) * NUM_USB_CHAN_OUT * 4) -#define MAX_PACKET_SIZE_OUT_FS ((((MAX_FREQ_A1+999)/1000)+1) * NUM_USB_CHAN_OUT_FS * 3) // Samples per channel +#define MAX_PACKET_SIZE_OUT_FS ((((MAX_FREQ_A1+999)/1000)+1) * NUM_USB_CHAN_OUT_FS * 3) // Samples per channel +#define MAX_PACKET_SIZE_IN_HS ((((MAX_FREQ+7999)/8000)+1) * NUM_USB_CHAN_IN * 4) +#define MAX_PACKET_SIZE_IN_FS ((((MAX_FREQ_A1+999)/1000)+1) * NUM_USB_CHAN_IN_FS * 3) // Samples per channel /* Configuration Descriptor for Audio 2.0 (HS) operation */ unsigned char cfgDesc_Audio2[] = @@ -904,7 +906,8 @@ unsigned char cfgDesc_Audio2[] = USB_ENDPOINT, /* 1 bDescriptorType: ENDPOINT */ 0x01, /* 2 bEndpointAddress (D7: 0:out, 1:in) */ 0x05, /* 3 bmAttributes (bitmap) */ - 0,4, /* 4 wMaxPacketSize */ + MAX_PACKET_SIZE_OUT_HS&0xff, /* 4 wMaxPacketSize */ + (MAX_PACKET_SIZE_OUT_HS&0xff00)>>8, /* 5 wMaxPacketSize */ 1, /* 6 bInterval */ /* Class-Specific AS Isochronous Audio Data Endpoint Descriptor (4.10.1.2) */ @@ -963,7 +966,8 @@ unsigned char cfgDesc_Audio2[] = USB_ENDPOINT, /* 1 bDescriptorType: ENDPOINT */ 0x01, /* 2 bEndpointAddress (D7: 0:out, 1:in) */ 0x05, /* 3 bmAttributes (bitmap) */ - 0,4, /* 4 wMaxPacketSize */ + MAX_PACKET_SIZE_OUT_HS&0xff, /* 4 wMaxPacketSize */ + (MAX_PACKET_SIZE_OUT_HS&0xff00)>>8, /* 5 wMaxPacketSize */ 1, /* 6 bInterval */ /* Class-Specific AS Isochronous Audio Data Endpoint Descriptor (4.10.1.2) */ @@ -1026,15 +1030,16 @@ unsigned char cfgDesc_Audio2[] = CS_INTERFACE, /* 1 bDescriptorType: 0x24 */ FORMAT_TYPE, /* 2 bDescriptorSubtype: FORMAT_TYPE */ FORMAT_TYPE_I, /* 3 bFormatType: FORMAT_TYPE_1 */ - 0x04, /* 4 bSubslotSize (Number of bytes per subslot) */ - 24, /* 5 bBitResolution (Number of bits used per subslot) */ + SAMPLE_SUBSLOT_SIZE_HS, /* 4 bSubslotSize (Number of bytes per subslot) */ + SAMPLE_BIT_RESOLUTION_HS, /* 5 bBitResolution (Number of bits used per subslot) */ /* Standard AS Isochronous Audio Data Endpoint Descriptor (4.10.1.1) */ 0x07, /* 0 bLength: 7 */ USB_ENDPOINT, /* 1 bDescriptorType: ENDPOINT */ 0x82, /* 2 bEndpointAddress (D7: 0:out, 1:in) */ 5, /* 3 bmAttributes (bitmap) */ - 0,4, /* 4 wMaxPacketSize */ + MAX_PACKET_SIZE_IN_HS&0xff, /* 4 wMaxPacketSize */ + (MAX_PACKET_SIZE_IN_HS&0xff00)>>8, /* 5 wMaxPacketSize */ 1, /* 6 bInterval */ /* Class-Specific AS Isochronous Audio Data Endpoint Descriptor (4.10.1.2) */ @@ -1083,7 +1088,8 @@ unsigned char cfgDesc_Audio2[] = USB_ENDPOINT, /* 1 bDescriptorType: ENDPOINT */ 0x82, /* 2 bEndpointAddress (D7: 0:out, 1:in) */ 5, /* 3 bmAttributes (bitmap) */ - 0,4, /* 4 wMaxPacketSize */ + MAX_PACKET_SIZE_IN_HS&0xff, /* 4 wMaxPacketSize */ + (MAX_PACKET_SIZE_IN_HS&0xff00)>>8, /* 5 wMaxPacketSize */ 1, /* 6 bInterval */ /* Class-Specific AS Isochronous Audio Data Endpoint Descriptor (4.10.1.2) */ From 3dd9ddcf47f30b054e3cc189d62ff1f092eccbc9 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 19 Dec 2013 12:07:34 +0000 Subject: [PATCH 66/72] Descriptors now use SAMPLE_SUBSLOT_SIZE_ and SAMPLE_BIT_RESOLUTION_ defines --- module_usb_audio/endpoint0/descriptors.h | 25 ++++++++++++------------ 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/module_usb_audio/endpoint0/descriptors.h b/module_usb_audio/endpoint0/descriptors.h index 1430cecf..be90d14c 100644 --- a/module_usb_audio/endpoint0/descriptors.h +++ b/module_usb_audio/endpoint0/descriptors.h @@ -839,8 +839,8 @@ unsigned char cfgDesc_Audio2[] = CS_INTERFACE, /* 1 bDescriptorType: 0x24 */ FORMAT_TYPE, /* 2 bDescriptorSubtype: FORMAT_TYPE */ FORMAT_TYPE_I, /* 3 bFormatType: FORMAT_TYPE_1 */ - 0x04, /* 4 bSubslotSize (Number of bytes per subslot) */ - 24, /* 5 bBitResolution (Number of bits used per subslot) */ + SAMPLE_SUBSLOT_SIZE_HS, /* 4 bSubslotSize (Number of bytes per subslot) */ + SAMPLE_BIT_RESOLUTION_HS, /* 5 bBitResolution (Number of bits used per subslot) */ /* Standard AS Isochronous Audio Data Endpoint Descriptor (4.10.1.1) */ 0x07, /* 0 bLength: 7 */ @@ -849,7 +849,6 @@ unsigned char cfgDesc_Audio2[] = 0x05, /* 3 bmAttributes (bitmap) */ MAX_PACKET_SIZE_OUT_HS&0xff, /* 4 wMaxPacketSize */ (MAX_PACKET_SIZE_OUT_HS&0xff00)>>8, /* 5 wMaxPacketSize */ - //0, 4, // 1024 1, /* 6 bInterval */ /* Class-Specific AS Isochronous Audio Data Endpoint Descriptor (4.10.1.2) */ @@ -898,7 +897,7 @@ unsigned char cfgDesc_Audio2[] = CS_INTERFACE, /* 1 bDescriptorType: 0x24 */ FORMAT_TYPE, /* 2 bDescriptorSubtype: FORMAT_TYPE */ FORMAT_TYPE_I, /* 3 bFormatType: FORMAT_TYPE_1 */ - 0x04, /* 4 bSubslotSize (Number of bytes per subslot) */ + SAMPLE_SUBSLOT_SIZE_HS, /* 4 bSubslotSize (Number of bytes per subslot) */ 32, /* 5 bBitResolution (Number of bits used per subslot) */ /* Standard AS Isochronous Audio Data Endpoint Descriptor (4.10.1.1) */ @@ -958,8 +957,8 @@ unsigned char cfgDesc_Audio2[] = CS_INTERFACE, /* 1 bDescriptorType: 0x24 */ FORMAT_TYPE, /* 2 bDescriptorSubtype: FORMAT_TYPE */ FORMAT_TYPE_I, /* 3 bFormatType: FORMAT_TYPE_1 */ - 0x04, /* 4 bSubslotSize (Number of bytes per subslot) */ - 24, /* 5 bBitResolution (Number of bits used per subslot) */ + SAMPLE_SUBSLOT_SIZE_HS, /* 4 bSubslotSize (Number of bytes per subslot) */ + SAMPLE_BIT_RESOLUTION_HS, /* 5 bBitResolution (Number of bits used per subslot) */ /* Standard AS Isochronous Audio Data Endpoint Descriptor (4.10.1.1) */ 0x07, /* 0 bLength: 7 */ @@ -1080,8 +1079,8 @@ unsigned char cfgDesc_Audio2[] = CS_INTERFACE, /* 1 bDescriptorType: 0x24 */ FORMAT_TYPE, /* 2 bDescriptorSubtype: FORMAT_TYPE */ FORMAT_TYPE_I, /* 3 bFormatType: FORMAT_TYPE_1 */ - 0x04, /* 4 bSubslotSize (Number of bytes per subslot) */ - 24, /* 5 bBitResolution (Number of bits used per subslot) */ + SAMPLE_SUBSLOT_SIZE_HS, /* 4 bSubslotSize (Number of bytes per subslot) */ + SAMPLE_BIT_RESOLUTION_HS, /* 5 bBitResolution (Number of bits used per subslot) */ /* Standard AS Isochronous Audio Data Endpoint Descriptor (4.10.1.1) */ 0x07, /* 0 bLength: 7 */ @@ -1814,8 +1813,8 @@ unsigned char cfgDesc_Audio1[] = 0x02, /* Subtype - FORMAT_TYPE */ 0x01, /* Format type - FORMAT_TYPE_1 */ NUM_USB_CHAN_OUT_FS, /* nrChannels */ - 0x03, /* subFrameSize - 4 bytes per slot */ - 24, /* bitResolution - 24bit */ + SAMPLE_SUBSLOT_SIZE_FS, /* subFrameSize */ + SAMPLE_BIT_RESOLUTION_FS, /* bitResolution */ 0x04, /* SamFreqType - 4 sample freq */ 0x44, 0xAC, 0x00, /* sampleFreq - 44.1Khz */ 0x80, 0xBB, 0x00, /* sampleFreq - 48KHz */ @@ -1896,9 +1895,9 @@ unsigned char cfgDesc_Audio1[] = CS_INTERFACE, 0x02, /* Subtype - FORMAT_TYPE */ 0x01, /* Format type - FORMAT_TYPE_1 */ - NUM_USB_CHAN_IN_FS, /* bNrChannels - 2 */ - 0x03, /* subFrameSize - 4 bytes per slot */ - 24, /* bitResolution - 24bit */ + NUM_USB_CHAN_IN_FS, /* bNrChannels - Typically 2 */ + SAMPLE_SUBSLOT_SIZE_FS, /* subFrameSize - Typically 4 bytes per slot */ + SAMPLE_BIT_RESOLUTION_FS, /* bitResolution - Typically 24bit */ 0x04, /* SamFreqType - 4 sample freq */ 0x44, 0xAC, 0x00, /* sampleFreq - 44.1Khz */ 0x80, 0xBB, 0x00, /* sampleFreq - 48KHz */ From 70f5047e2290f0876a3a053624118935eab4156e Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Fri, 20 Dec 2013 15:51:11 +0000 Subject: [PATCH 67/72] Manual BCDDEVICE change 6.3.1 -> 6.3.2 --- module_usb_audio/devicedefines.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index 7c804f24..d79e2563 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -249,7 +249,7 @@ /* Device release number in BCD: 0xJJMN */ #define BCD_DEVICE_J 6 #define BCD_DEVICE_M 3 -#define BCD_DEVICE_N 1 +#define BCD_DEVICE_N 2 #ifndef BCD_DEVICE #define BCD_DEVICE ((BCD_DEVICE_J << 8) | ((BCD_DEVICE_M & 0xF) << 4) | (BCD_DEVICE_N & 0xF)) From 6e0f1d5a135979d5523d1faf9a8ab6a5e6d6ef81 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 9 Jan 2014 15:14:11 +0000 Subject: [PATCH 68/72] Fixed issue where the next 44.1 based freq above MAX_FREQ was reported in GetRange(SamplingFrequency) when MAX_FREQ=MIN_FREQ (BUG #15127) --- module_usb_audio/endpoint0/audiorequests.xc | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/module_usb_audio/endpoint0/audiorequests.xc b/module_usb_audio/endpoint0/audiorequests.xc index 596def14..2d4cc817 100644 --- a/module_usb_audio/endpoint0/audiorequests.xc +++ b/module_usb_audio/endpoint0/audiorequests.xc @@ -807,25 +807,24 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c while(1) { - if((currentFreq48 <= maxFreq)) + if((currentFreq44 <= maxFreq) && (currentFreq44 >= MIN_FREQ)) { - /* Note i passed byref here */ storeFreq(buffer, i, currentFreq44); num_freqs++; currentFreq44*=2; - + } + + if((currentFreq48 <= maxFreq)) + { + /* Note i passed byref here */ storeFreq(buffer, i, currentFreq48); num_freqs++; currentFreq48*=2; } - else if((currentFreq44 <= maxFreq)) - { - storeFreq(buffer, i, currentFreq44); - num_freqs++; - currentFreq44*=2; - } else + { break; + } } storeShort(buffer, 0, num_freqs); From 507afd4f60f3efbb90d8165e020c164e1dedf460 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Sat, 11 Jan 2014 16:29:34 +0000 Subject: [PATCH 69/72] Comment only (MIDI descriptor packet sizes) --- module_usb_audio/endpoint0/descriptors.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module_usb_audio/endpoint0/descriptors.h b/module_usb_audio/endpoint0/descriptors.h index be90d14c..ee2773ca 100644 --- a/module_usb_audio/endpoint0/descriptors.h +++ b/module_usb_audio/endpoint0/descriptors.h @@ -1241,7 +1241,7 @@ unsigned char cfgDesc_Audio2[] = 0x05, /* 1 bDescriptorType : ENDPOINT descriptor. (field size 1 bytes) */ EP_ADR_OUT_MIDI, /* 2 bEndpointAddress : OUT Endpoint 3. (field size 1 bytes) */ 0x02, /* 3 bmAttributes : Bulk, not shared. (field size 1 bytes) */ - 0x00, /* 4 wMaxPacketSize : 64 bytes per packet. (field size 2 bytes) - has to be 0x200 for compliance*/ + 0x00, /* 4 wMaxPacketSize : 512 bytes per packet. (field size 2 bytes) - has to be 0x200 for compliance*/ 0x02, /* 5 wMaxPacketSize */ 0x00, /* 6 bInterval : Ignored for Bulk. Set to zero. (field size 1 bytes) */ 0x00, /* 7 bRefresh : Unused. (field size 1 bytes) */ @@ -1259,7 +1259,7 @@ unsigned char cfgDesc_Audio2[] = 0x05, /* 1 bDescriptorType : ENDPOINT descriptor. (field size 1 bytes) */ EP_ADR_IN_MIDI, /* 2 bEndpointAddress : IN Endpoint 3. (field size 1 bytes) */ 0x02, /* 3 bmAttributes : Bulk, not shared. (field size 1 bytes) */ - 0x00, /* 4 wMaxPacketSize : 64 bytes per packet. (field size 2 bytes) - has to be 0x200 for compliance*/ + 0x00, /* 4 wMaxPacketSize : 512 bytes per packet. (field size 2 bytes) - has to be 0x200 for compliance*/ 0x02, /* 5 wMaxPacketSize */ 0x00, /* 6 bInterval : Ignored for Bulk. Set to zero. (field size 1 bytes) */ 0x00, /* 7 bRefresh : Unused. (field size 1 bytes) */ From 3570f551e1078b1401da58c3581b8628043565bb Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Sat, 11 Jan 2014 16:33:29 +0000 Subject: [PATCH 70/72] MIDI Rx port now buffered. Means that Start-bit detect select case doesn't get started on receipt of large MIDI packet. --- module_usb_audio/main.xc | 2 +- module_usb_midi/src/usb_midi.h | 2 +- module_usb_midi/src/usb_midi.xc | 18 ++++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/module_usb_audio/main.xc b/module_usb_audio/main.xc index 93966acb..e6eadbdd 100755 --- a/module_usb_audio/main.xc +++ b/module_usb_audio/main.xc @@ -117,7 +117,7 @@ on tile[AUDIO_IO_TILE] : buffered out port:32 p_spdif_tx = PORT_SPDIF_OUT; #ifdef MIDI on tile[AUDIO_IO_TILE] : port p_midi_tx = PORT_MIDI_OUT; -on tile[AUDIO_IO_TILE] : port p_midi_rx = PORT_MIDI_IN; +on tile[AUDIO_IO_TILE] : buffered port:1 p_midi_rx = PORT_MIDI_IN; #endif /* Clock blocks */ diff --git a/module_usb_midi/src/usb_midi.h b/module_usb_midi/src/usb_midi.h index 3ab9b821..ca9a490f 100644 --- a/module_usb_midi/src/usb_midi.h +++ b/module_usb_midi/src/usb_midi.h @@ -15,7 +15,7 @@ * \param cable_number the cable number of the MIDI implementation. * This should be set to 0. **/ -void usb_midi(port ?p_midi_in, port ?p_midi_out, +void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out, clock ?clk_midi, chanend ?c_midi, unsigned cable_number, diff --git a/module_usb_midi/src/usb_midi.xc b/module_usb_midi/src/usb_midi.xc index cdd6239d..f0781ba1 100644 --- a/module_usb_midi/src/usb_midi.xc +++ b/module_usb_midi/src/usb_midi.xc @@ -22,7 +22,7 @@ static unsigned makeSymbol(unsigned data) #define RATE 31250 #ifndef MIDI_SHIFT_TX -#define MIDI_SHIFT_TX 7 +#define MIDI_SHIFT_TX 0 #endif static unsigned bit_time = XS1_TIMER_MHZ * 1000000 / (unsigned) RATE; @@ -51,7 +51,7 @@ timer iAPTimer; #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) -void usb_midi(port ?p_midi_in, port ?p_midi_out, +void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out, clock ?clk_midi, chanend ?c_midi, unsigned cable_number, @@ -169,12 +169,14 @@ void usb_midi(port ?p_midi_in, port ?p_midi_out, unsigned event = 0; uin_count++; rxByte >>= 24; - // if (rxByte != outputted_symbol) { - // // Loopback check - // printhexln(rxByte); - // printhexln(outputted_symbol); - // } - +#if 0 + // Loopback check + if ((rxByte != outputted_symbol)) + { + printhexln(rxByte); + printhexln(outputted_symbol); + } +#endif {valid, event} = midi_in_parse(mips, cable_number, rxByte); if (valid && queue_is_empty(midi_to_host_fifo)) { From 44f46ee0eba1e5bc3232daa64ea6b4ab1042e77a Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Sat, 11 Jan 2014 17:44:05 +0000 Subject: [PATCH 71/72] Comment only. --- module_usb_audio/devicedefines.h | 1 + 1 file changed, 1 insertion(+) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index d79e2563..7d12bfd2 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -56,6 +56,7 @@ #if ((MCLK_48 % MIN_FREQ) == 0) #define MIN_FREQ_48 MIN_FREQ +/* * 2 required since we want the next 44.1 based freq above MIN_FREQ */ #define MIN_FREQ_44 (((44100*512)/((48000 * 512)/MIN_FREQ))*2) #endif From beff2feaf1abd057660cc7bcd7f343fc0934b257 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Sat, 11 Jan 2014 17:45:35 +0000 Subject: [PATCH 72/72] initial value for g_curSampFreqMultiplier now fixed (#15141). Causes issue if no SF rate change from host and the DEFAULT_FREQ is used. --- module_usb_audio/endpoint0/audiorequests.xc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/endpoint0/audiorequests.xc b/module_usb_audio/endpoint0/audiorequests.xc index 2d4cc817..1cd3fbf1 100644 --- a/module_usb_audio/endpoint0/audiorequests.xc +++ b/module_usb_audio/endpoint0/audiorequests.xc @@ -51,7 +51,7 @@ extern unsigned char mixSel[MIX_INPUTS]; /* Global var for current frequency, set to default freq */ unsigned int g_curSamFreq = DEFAULT_FREQ; unsigned int g_curSamFreq48000Family = DEFAULT_FREQ % 48000 == 0; -unsigned int g_curSamFreqMultiplier = DEFAULT_FREQ / 48000; +unsigned int g_curSamFreqMultiplier = DEFAULT_FREQ / (DEFAULT_MCLK_FREQ / 512); /* Store an int into a char array: Note this allows non-word aligned access unlike reinerpret cast */ static void storeInt(unsigned char buffer[], int index, int val)