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
new file mode 100644
index 00000000..9670aa7b
--- /dev/null
+++ b/CHANGELOG.rst
@@ -0,0 +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
+
+
diff --git a/module_dfu/README b/module_dfu/README.rst
similarity index 59%
rename from module_dfu/README
rename to module_dfu/README.rst
index 1a762260..a59b5807 100644
--- a/module_dfu/README
+++ b/module_dfu/README.rst
@@ -1,3 +1,11 @@
+module_dfu
+==========
+
+: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_dfu/src/dfu.xc b/module_dfu/src/dfu.xc
index 4a6cfdbf..28f0e88c 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"
@@ -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;
}
@@ -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
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..39b57728
--- /dev/null
+++ b/module_queue/src/queue.h
@@ -0,0 +1,65 @@
+#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 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;
+}
+
+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..c78f2b0f
--- /dev/null
+++ b/module_queue/src/queue.xc
@@ -0,0 +1,13 @@
+#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 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);
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/audio.xc b/module_usb_audio/audio.xc
index c6a3821f..72b8674f 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;
@@ -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
@@ -711,7 +734,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/devicedefines.h b/module_usb_audio/devicedefines.h
index 351b52e5..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
@@ -226,42 +227,95 @@
/* 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
-/* Device release number in BCD: 0xJJMNi */
+/* Device release number in BCD: 0xJJMN */
+#define BCD_DEVICE_J 6
+#define BCD_DEVICE_M 3
+#define BCD_DEVICE_N 2
+
#ifndef BCD_DEVICE
-#define BCD_DEVICE (0x0620)
+#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)
+#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 */
#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
diff --git a/module_usb_audio/endpoint0/audiorequests.xc b/module_usb_audio/endpoint0/audiorequests.xc
index 57ae892a..1cd3fbf1 100644
--- a/module_usb_audio/endpoint0/audiorequests.xc
+++ b/module_usb_audio/endpoint0/audiorequests.xc
@@ -51,10 +51,10 @@ 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 */
-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
@@ -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;
@@ -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);
@@ -884,7 +883,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 +892,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;
diff --git a/module_usb_audio/endpoint0/descriptors.h b/module_usb_audio/endpoint0/descriptors.h
index 8f76168a..ee2773ca 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)
@@ -242,45 +242,33 @@ unsigned char devQualDesc_Null[] =
#define OUTPUT_ALT_LENGTH (OUTPUT_ALT_LENGTH_ADAT + OUTPUT_ALT_LENGTH_DSD)
-// Positions in strDescs_Audio2
-#define INTERNAL_CLOCK_STRING_INDEX (14)
-#define SPDIF_CLOCK_STRING_INDEX (15)
-
+// Positions in strDescs
+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[] = {
@@ -324,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[] =
@@ -698,7 +688,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 */
@@ -849,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 */
@@ -859,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) */
@@ -908,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) */
@@ -916,7 +905,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) */
@@ -967,15 +957,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 */
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) */
@@ -1038,15 +1029,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) */
@@ -1087,15 +1079,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) */
@@ -1248,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) */
@@ -1266,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) */
@@ -1394,44 +1387,8 @@ unsigned char cfgDesc_Audio2[] =
#endif
-
-
-
-
-
-
};
-
-
-/* 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
@@ -1446,10 +1403,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)
@@ -1853,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 */
@@ -1935,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 */
@@ -2011,23 +1971,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.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
diff --git a/module_usb_audio/endpoint0/endpoint0.xc b/module_usb_audio/endpoint0/endpoint0.xc
index 4e5863bd..55960487 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,43 +180,36 @@ 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
* 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
@@ -598,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;
@@ -607,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;
diff --git a/module_usb_audio/locks/lock.S b/module_usb_audio/locks/lock.S
index 5e2e10da..cb955077 100644
--- a/module_usb_audio/locks/lock.S
+++ b/module_usb_audio/locks/lock.S
@@ -5,51 +5,81 @@
#include
+.text
/////////////////////////////////////////////////////////////////////////
// void GetLockResource()
-.extern 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)
-.extern ClaimLock
-.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)
-.extern FreeLock
-.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)
-.extern FreeLockResource
-.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/main.xc b/module_usb_audio/main.xc
index 25f4bca7..e6eadbdd 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
@@ -29,11 +28,19 @@
#include "iap.h"
#endif
-#ifndef AUDIO_IO_TILE
-#define AUDIO_IO_TILE 0
+#ifdef MIXER
+#include "mixer.h"
#endif
-/* Audio I/O */
+#ifndef AUDIO_IO_TILE
+#define AUDIO_IO_TILE 0
+#endif
+
+#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,12 +104,12 @@ 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
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;
@@ -110,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 */
@@ -119,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
@@ -131,24 +138,27 @@ 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
-#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[0] : 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] : out port p_usb_rst = PORT_USB_RESET;
#else
-/* Reset port not required for SU1 due to built in Phy */
+/* 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
#define clk null
#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 */
@@ -178,6 +188,7 @@ XUD_EpType epTypeTableIn[EP_CNT_IN] = { XUD_EPTYPE_CTL | XUD_STATUS_ENABLE,
#endif
};
+
void thread_speed()
{
#ifdef FAST_MODE
@@ -203,74 +214,67 @@ 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;
+/* Core USB Audio functions - must be called on the Tile connected to the USB Phy */
+void usb_audio_core(chanend c_mix_out
#ifdef MIDI
- chan c_midi;
+, chanend c_midi
#endif
#ifdef IAP
- chan c_iap;
+, chanend c_iap
#endif
-
-#ifdef TEST_MODE_SUPPORT
-#warning Building with test mode support
- chan c_usb_test;
-#else
-#define c_usb_test null
+#ifdef MIXER
+, chanend c_mix_ctl
#endif
+)
+{
+ 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
-#ifdef SU1_ADC_ENABLE
- chan c_adc;
-#else
-#define c_adc null
+#ifndef MIXER
+#define c_mix_ctl 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 */
@@ -293,57 +297,143 @@ int main()
#ifdef CHAN_BUFF_CTRL
, c_buff_ctrl
#endif
-
- );
-
+ );
}
- on tile[AUDIO_IO_TILE]:
+ /* Endpoint 0 Core */
{
thread_speed();
-
- /* Audio I/O (pars additional S/PDIF TX thread) */
- audio(c_mix_out, null, null, c_adc);
+ Endpoint0( c_xud_out[0], c_xud_in[0], c_aud_ctl, c_mix_ctl, null, c_usb_test);
}
-
- on tile[0]:
+
+ /* Decoupling core */
{
thread_speed();
decouple(c_mix_out, null
#ifdef CHAN_BUFF_CTRL
- , c_buff_ctrl
+ , c_buff_ctrl
#endif
);
}
+ }
+}
- /* Endpoint 0 */
- on tile[0]:
+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();
- Endpoint0( c_xud_out[0], c_xud_in[0], c_aud_ctl, null, null, c_usb_test);
+#ifdef MIXER
+ audio(c_mix_out, null, null, c_adc);
+#else
+ audio(c_aud_in, null, null, c_adc);
+#endif
}
-
+
+ /* MIDI/iAP Core */
#if defined (MIDI) || defined IAP
- on tile[AUDIO_IO_TILE]:
{
thread_speed();
#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
+ }
+}
+#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;
+#else
+#define c_midi null
+#endif
+#ifdef IAP
+ chan c_iap;
+#endif
+
+#ifdef SU1_ADC_ENABLE
+ chan c_adc;
+#else
+#define c_adc null
+#endif
+
+#ifdef MIXER
+ chan c_mix_ctl;
+#endif
+
+ USER_MAIN_DECLARATIONS
+
+ par
+ {
+ on tile[XUD_TILE]: usb_audio_core(c_mix_out
+#ifdef MIDI
+ , c_midi
+#endif
+#ifdef IAP
+ , c_iap
+#endif
+#ifdef MIXER
+ , c_mix_ctl
+#endif
+);
+
+ on tile[AUDIO_IO_TILE]: usb_audio_io(c_mix_out, c_adc
+#ifdef MIDI
+ , c_midi
+#endif
+#ifdef IAP
+ , c_iap
+#endif
+#ifdef MIXER
+ , c_mix_ctl
+#endif
+
+ );
+
+ USER_MAIN_CORES
+ }
#ifdef SU1_ADC_ENABLE
xs1_su_adc_service(c_adc);
#endif
-
- }
+
return 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/mixer/mixer.xc b/module_usb_audio/mixer/mixer.xc
index cf0f8417..6b2c841c 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"
@@ -115,7 +114,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 +150,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;
@@ -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 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;
while (1)
{
-
#pragma xta endpoint "mixer1_req"
+ /* Request from audio() */
inuint(c_mixer2);
/* Request data from decouple thread */
outuint(c_host, 0);
/* Between request to decouple and respose ~ 400nS latency for interrupt to fire */
- select
+ select
{
case inuint_byref(c_mix_ctl, cmd):
{
@@ -406,7 +413,7 @@ void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2)
break;
}
default:
- /* Select default */
+ /* Select default */
break;
}
@@ -424,12 +431,10 @@ void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2)
#pragma loop unroll
for (int i=0;i 0
outuint(c_mixer2, 0);
giveSamplesToHost(c_host, samples, samples_to_host_map, multIn);
@@ -506,19 +511,20 @@ 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
}
}
}
-int mixer2_mix2_flag = (DEFAULT_FREQ > 96000);
+static int mixer2_mix2_flag = (DEFAULT_FREQ > 96000);
+#if (MAX_MIX_COUNT > 0)
#pragma unsafe arrays
-void mixer2(chanend c_mixer1, chanend c_audio)
+static void mixer2(chanend c_mixer1, chanend c_audio)
{
int mixed;
@@ -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)
{
@@ -651,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
#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);
diff --git a/module_usb_audio/usb_buffer/decouple.xc b/module_usb_audio/usb_buffer/decouple.xc
index 5f545ae4..ed042365 100644
--- a/module_usb_audio/usb_buffer/decouple.xc
+++ b/module_usb_audio/usb_buffer/decouple.xc
@@ -98,14 +98,16 @@ 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
#pragma unsafe arrays
-void handle_audio_request(chanend c_mix_out)
+void handle_audio_request(chanend c_mix_out)
{
int outSamps;
int space_left;
@@ -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)
@@ -472,7 +586,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
@@ -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 */
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
-
-
- }
-}
-
diff --git a/module_usb_audio/usb_buffer/usb_buffer.xc b/module_usb_audio/usb_buffer/usb_buffer.xc
index a8a41f79..050e6a8e 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"
@@ -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];
-int g_midi_from_host_buffer[MAX_USB_MIDI_PACKET_SIZE/4+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
#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,20 +507,15 @@ 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)
{
- /* 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;
@@ -630,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;
@@ -643,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;
}
diff --git a/module_usb_audio/warnings.xc b/module_usb_audio/warnings.xc
index cbc32c98..e85973a6 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"
#include "customdefines.h"
@@ -36,7 +40,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)
@@ -54,7 +58,7 @@
#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
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
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/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/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);
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.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 4a9c2403..f0781ba1 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;
@@ -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;
@@ -49,7 +49,9 @@ extern unsigned polltime;
timer iAPTimer;
#endif
-void usb_midi(port ?p_midi_in, port ?p_midi_out,
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
+
+void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out,
clock ?clk_midi,
chanend ?c_midi,
unsigned cable_number,
@@ -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<>= 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 && isempty(midi_to_host_fifo))
+ if (valid && queue_is_empty(midi_to_host_fifo))
{
event = byterev(event);
@@ -189,7 +193,7 @@ void usb_midi(port ?p_midi_in, port ?p_midi_out,
}
else
{
- enqueue(midi_to_host_fifo, event);
+ queue_push_word(midi_to_host_fifo, midi_to_host_fifo_arr, event);
}
}
else if (valid)
@@ -215,10 +219,10 @@ void usb_midi(port ?p_midi_in, port ?p_midi_out,
// When it has just finished sending a symbol
// Take from FIFO
- outputting_symbol = dequeue(symbol_fifo);
+ outputting_symbol = queue_pop_word(symbol_fifo, symbol_fifo_arr);
symbol = makeSymbol(outputting_symbol);
- if (space(symbol_fifo) > 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 +248,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 +263,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 +282,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 +296,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 +309,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);
}
@@ -331,11 +335,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)
{
@@ -347,7 +351,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
}
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;
+}
diff --git a/xpd.xml b/xpd.xml
index b1394ee6..fcb51d90 100644
--- a/xpd.xml
+++ b/xpd.xml
@@ -1,9 +1,26 @@
+
+
+ XMOS USB Audio Reference Designes
+ DFU
+
+
+
+ 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
USB Audio Shared Components
+ xross
XMOS
+
+
+
+
+
1.0
- False
-
+
\ No newline at end of file