Merge branch '6V3_DEV'

This commit is contained in:
Ross Owen
2014-01-13 16:28:04 +00:00
38 changed files with 1068 additions and 2131 deletions

View File

@@ -0,0 +1,9 @@
<Add title here>
================
:scope: <Put one of Roadmap, Example, Early Development or General Use>
:description: <Add one line here>
:keywords: <Add comma separated list of keywords>
:boards: <Add comma separated list of supported boards>
<Add description of software block>

View File

@@ -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)
{

View File

@@ -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))

View File

@@ -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

View File

@@ -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;

View File

@@ -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

View File

@@ -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

View File

@@ -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;

View File

@@ -5,51 +5,81 @@
#include <xs1_user.h>
.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

View File

@@ -3,7 +3,6 @@
* @brief Top level for XMOS USB 2.0 Audio 2.0 Reference Designs.
* @author Ross Owen, XMOS Semiconductor Ltd
*/
#include <syscall.h>
#include <platform.h>
#include <xs1.h>
@@ -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;
}

View File

@@ -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

View File

@@ -1,7 +1,6 @@
#include <xs1.h>
#include <print.h>
#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<NUM_USB_CHAN_OUT;i++)
{
@@ -216,12 +217,17 @@ static void getSamplesFromHost(chanend c, xc_ptr samples, int base)
#else
write_via_xc_ptr_indexed(samples,base+i,sample);
#endif
}
} }
}
#pragma unsafe arrays
void giveSamplesToDevice(chanend c, xc_ptr samples, xc_ptr ptr, xc_ptr multOut)
static void giveSamplesToDevice(chanend c, xc_ptr samples, xc_ptr ptr, xc_ptr multOut, unsigned underflow)
{
outuint(c, underflow);
if(!underflow)
{
#pragma loop unroll
for (int i=0;i<NUM_USB_CHAN_OUT;i++)
{
@@ -245,10 +251,11 @@ void giveSamplesToDevice(chanend c, xc_ptr samples, xc_ptr ptr, xc_ptr multOut)
outuint(c, sample);
#endif
}
}
}
#pragma unsafe arrays
void getSamplesFromDevice(chanend c, xc_ptr samples, int base)
static void getSamplesFromDevice(chanend c, xc_ptr samples, int base)
{
#if defined(IN_VOLUME_IN_MIXER) && !defined(IN_VOLUME_AFTER_MIX)
int mult;
@@ -281,25 +288,25 @@ void getSamplesFromDevice(chanend c, xc_ptr samples, int base)
}
}
int mixer1_mix2_flag = (DEFAULT_FREQ > 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<MAX_MIX_COUNT;i++)
{
write_via_xc_ptr_indexed(samples,
(NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + i),
0);
write_via_xc_ptr_indexed(samples, (NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + i), 0);
}
/* Inform mixer 2 about freq change */
/* Inform mixer2 (or audio())about freq change */
outct(c_mixer2, XS1_CT_END);
outuint(c_mixer2, sampFreq);
@@ -439,7 +444,7 @@ void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2)
}
else
{
inuint(c_host);
unsigned underflow = inuint(c_host);
#if MAX_MIX_COUNT > 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<NUM_USB_CHAN_OUT;i++)
{
asm("stw %0, %1[%2]"::
"r"(i),
"r"(samples_to_device_map),
"r"(i));
//samples_to_device_map_array[i] = i;
asm("stw %0, %1[%2]":: "r"(i), "r"(samples_to_device_map), "r"(i));
}
}

View File

@@ -5,6 +5,7 @@
#include <xs1_l_registers.h>
#include <xs1_su_registers.h>
#include <platform.h>
#include <hwtimer.h>
#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);

View File

@@ -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 */

File diff suppressed because it is too large Load Diff

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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