forked from PAWPAW-Mirror/lib_xua
Merge branch 'ANDROID'
This commit is contained in:
@@ -4,24 +4,28 @@
|
||||
#include "interrupt.h"
|
||||
#include "commands.h"
|
||||
#include "xud.h"
|
||||
#include "usb.h"
|
||||
|
||||
#ifdef NATIVE_DSD
|
||||
#include "usbaudio20.h" /* Defines from the USB Audio 2.0 Specifications */
|
||||
#endif
|
||||
|
||||
#ifdef HID_CONTROLS
|
||||
#include "user_hid.h"
|
||||
#endif
|
||||
#define MAX(x,y) ((x)>(y) ? (x) : (y))
|
||||
|
||||
#define CLASS_TWO_PACKET_SIZE ((((MAX_FREQ+7999)/8000))+3) // Samples per channel
|
||||
#define CLASS_ONE_PACKET_SIZE ((((MAX_FREQ_FS+999)/1000))+3) // Samples per channel
|
||||
#define HS_PACKET_SIZE ((((MAX_FREQ+7999)/8000))+3) // Samples per channel
|
||||
#define FS_PACKET_SIZE ((((MAX_FREQ_FS+999)/1000))+3) // Samples per channel
|
||||
|
||||
/* TODO user SLOTSIZE to potentially save memory */
|
||||
#define BUFF_SIZE_OUT MAX(4 * CLASS_TWO_PACKET_SIZE * NUM_USB_CHAN_OUT, 4 * CLASS_ONE_PACKET_SIZE * NUM_USB_CHAN_OUT_FS)
|
||||
#define BUFF_SIZE_IN MAX(4 * CLASS_TWO_PACKET_SIZE * NUM_USB_CHAN_IN, 4 * CLASS_ONE_PACKET_SIZE * NUM_USB_CHAN_IN_FS)
|
||||
/* TODO use SLOTSIZE to potentially save memory */
|
||||
#define BUFF_SIZE_OUT MAX(4 * HS_PACKET_SIZE * NUM_USB_CHAN_OUT, 4 * FS_PACKET_SIZE * NUM_USB_CHAN_OUT_FS)
|
||||
#define BUFF_SIZE_IN MAX(4 * HS_PACKET_SIZE * NUM_USB_CHAN_IN, 4 * FS_PACKET_SIZE * NUM_USB_CHAN_IN_FS)
|
||||
|
||||
/* Maximum USB buffer size (1024 bytes + 1 word to store length) */
|
||||
#define MAX_USB_AUD_PACKET_SIZE 1028
|
||||
|
||||
#define OUT_BUFFER_PREFILL (MAX(NUM_USB_CHAN_OUT_FS*CLASS_ONE_PACKET_SIZE*3+4,NUM_USB_CHAN_OUT*CLASS_TWO_PACKET_SIZE*4+4)*1)
|
||||
#define IN_BUFFER_PREFILL (MAX(CLASS_ONE_PACKET_SIZE*3+4,CLASS_TWO_PACKET_SIZE*4+4)*2)
|
||||
#define OUT_BUFFER_PREFILL (MAX(NUM_USB_CHAN_OUT_FS*FS_PACKET_SIZE*3+4,NUM_USB_CHAN_OUT*HS_PACKET_SIZE*4+4)*1)
|
||||
#define IN_BUFFER_PREFILL (MAX(FS_PACKET_SIZE*2+4, HS_PACKET_SIZE*4+4)*2)
|
||||
|
||||
/* Volume and mute tables */
|
||||
#ifndef OUT_VOLUME_IN_MIXER
|
||||
@@ -37,10 +41,14 @@ static xc_ptr p_multIn;
|
||||
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_FREQ_FS/1000+1)*NUM_USB_CHAN_IN_FS*3)+4)
|
||||
/* Note we could improve on this, for one subslot is set to 4 */
|
||||
#define MAX_DEVICE_AUD_PACKET_SIZE_MULT_HS ((MAX_FREQ/8000+1)*4)
|
||||
#define MAX_DEVICE_AUD_PACKET_SIZE_MULT_FS ((MAX_FREQ_FS/1000+1)*4)
|
||||
|
||||
#define MAX_DEVICE_AUD_PACKET_SIZE (MAX(MAX_DEVICE_AUD_PACKET_SIZE_CLASS_ONE, MAX_DEVICE_AUD_PACKET_SIZE_CLASS_TWO))
|
||||
#define MAX_DEVICE_AUD_PACKET_SIZE_HS ((MAX_FREQ/8000+1)*NUM_USB_CHAN_IN*4)
|
||||
#define MAX_DEVICE_AUD_PACKET_SIZE_FS ((MAX_FREQ_FS/1000+1)*NUM_USB_CHAN_IN_FS*4)
|
||||
|
||||
#define MAX_DEVICE_AUD_PACKET_SIZE (MAX(MAX_DEVICE_AUD_PACKET_SIZE_FS, MAX_DEVICE_AUD_PACKET_SIZE_HS))
|
||||
|
||||
/* Circular audio buffers */
|
||||
unsigned outAudioBuff[BUFF_SIZE_OUT + (MAX_USB_AUD_PACKET_SIZE>>2) + 4];
|
||||
@@ -64,6 +72,11 @@ unsigned g_aud_from_host_flag = 0;
|
||||
unsigned g_aud_from_host_info;
|
||||
unsigned g_freqChange_flag = 0;
|
||||
unsigned g_freqChange_sampFreq;
|
||||
|
||||
unsigned g_formatChange_SubSlot;
|
||||
unsigned g_formatChange_DataFormat;
|
||||
unsigned g_formatChange_NumChans;
|
||||
|
||||
int speedRem = 0;
|
||||
|
||||
xc_ptr aud_from_host_fifo_start;
|
||||
@@ -96,12 +109,15 @@ unsigned unpackData = 0;
|
||||
unsigned packState = 0;
|
||||
unsigned packData = 0;
|
||||
|
||||
/* Default to something sensible but the following are setup at stream start: */
|
||||
unsigned g_curSubSlot_out = HS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES;
|
||||
unsigned g_curSubSlot_in = HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES;
|
||||
|
||||
/* Init to something sensible, but expect to be re-set before stream start */
|
||||
#if (AUDIO_CLASS==2)
|
||||
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;
|
||||
int g_maxPacketSize = MAX_DEVICE_AUD_PACKET_SIZE_HS;
|
||||
#else
|
||||
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;
|
||||
int g_maxPacketSize = MAX_DEVICE_AUD_PACKET_SIZE_FS;
|
||||
#endif
|
||||
|
||||
#pragma select handler
|
||||
@@ -118,23 +134,6 @@ void handle_audio_request(chanend c_mix_out)
|
||||
/* Reply with underflow */
|
||||
outuint(c_mix_out, outUnderflow);
|
||||
|
||||
GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed);
|
||||
|
||||
/* slotSize different for Audio Class 1.0/2.0. */
|
||||
/* TODO It is quite wasteful to run this check every interrupt. Perhaps on stream start is good enough */
|
||||
#if defined(AUDIO_CLASS_FALLBACK) || defined (FULL_SPEED_AUDIO_2)
|
||||
if (usb_speed == XUD_SPEED_HS)
|
||||
{
|
||||
g_slotSize = SAMPLE_SUBSLOT_SIZE_HS; /* Typically 4 bytes per sample for HS */
|
||||
g_maxPacketSize = MAX_DEVICE_AUD_PACKET_SIZE_CLASS_TWO;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_slotSize = SAMPLE_SUBSLOT_SIZE_FS; /* Typically 3 bytes per sample for FS */
|
||||
g_maxPacketSize = MAX_DEVICE_AUD_PACKET_SIZE_CLASS_ONE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* If in overflow condition then receive samples and throw away */
|
||||
if(inOverflow || sampsToWrite == 0)
|
||||
{
|
||||
@@ -160,14 +159,13 @@ void handle_audio_request(chanend c_mix_out)
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Not in overflow, store samples from mixer into sample buffer */
|
||||
switch(g_slotSize)
|
||||
switch(g_curSubSlot_in)
|
||||
{
|
||||
case 4:
|
||||
{
|
||||
#if (SAMPLE_SUBSLOT_SIZE_HS != 4) && (SAMPLE_SUBSLOT_SIZE_FS != 4)
|
||||
__builtin_unreachable();
|
||||
#if (STREAM_FORMAT_INPUT_SUBSLOT_4_USED == 1)
|
||||
//__builtin_unreachable();
|
||||
#endif
|
||||
unsigned ptr = g_aud_to_host_dptr;
|
||||
|
||||
@@ -183,6 +181,7 @@ __builtin_unreachable();
|
||||
asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multIn),"r"(i));
|
||||
{h, l} = macs(mult, sample, 0, 0);
|
||||
sample = h << 3;
|
||||
#warning FIXME
|
||||
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;
|
||||
@@ -198,8 +197,8 @@ __builtin_unreachable();
|
||||
}
|
||||
|
||||
case 3:
|
||||
#if (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 3)
|
||||
__builtin_unreachable();
|
||||
#if (STREAM_FORMAT_INPUT_SUBSLOT_3_USED == 1)
|
||||
//__builtin_unreachable();
|
||||
#endif
|
||||
for(int i = 0; i < g_numUsbChanIn; i++)
|
||||
{
|
||||
@@ -244,9 +243,8 @@ __builtin_unreachable();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
#if (SAMPLE_SUBSLOT_SIZE_HS != 2) && (SAMPLE_SUBSLOT_SIZE_FS != 2)
|
||||
__builtin_unreachable();
|
||||
#if (STREAM_FORMAT_INPUT_SUBSLOT_2_USED == 1)
|
||||
//__builtin_unreachable();
|
||||
#endif
|
||||
for(int i = 0; i < g_numUsbChanIn; i++)
|
||||
{
|
||||
@@ -260,24 +258,13 @@ __builtin_unreachable();
|
||||
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
|
||||
|
||||
/* Note, in 2 byte sub slot - ignore lower bits of macs */
|
||||
#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;
|
||||
}
|
||||
write_short_via_xc_ptr(g_aud_to_host_dptr, sample>>16);
|
||||
g_aud_to_host_dptr+=2;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -330,11 +317,41 @@ __builtin_unreachable();
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(g_slotSize)
|
||||
switch(g_curSubSlot_out)
|
||||
{
|
||||
|
||||
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;
|
||||
|
||||
read_short_via_xc_ptr(sample, g_aud_from_host_rdptr);
|
||||
g_aud_from_host_rdptr+=2;
|
||||
sample <<= 16;
|
||||
|
||||
#ifndef OUT_VOLUME_IN_MIXER
|
||||
asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i));
|
||||
{h, l} = macs(mult, sample, 0, 0);
|
||||
/* Note, in 2 byte subslot mode - ignore lower result of macs */
|
||||
h <<= 3;
|
||||
outuint(c_mix_out, h);
|
||||
#else
|
||||
outuint(c_mix_out, sample);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:
|
||||
#if (SAMPLE_SUBSLOT_SIZE_HS != 4) && (SAMPLE_SUBSLOT_SIZE_FS != 4)
|
||||
__builtin_unreachable();
|
||||
//__builtin_unreachable();
|
||||
#endif
|
||||
/* Buffering not underflow condition send out some samples...*/
|
||||
for(int i = 0; i < g_numUsbChanOut; i++)
|
||||
@@ -352,10 +369,11 @@ __builtin_unreachable();
|
||||
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) || defined(NATIVE_DSD)
|
||||
//#if (SAMPLE_BIT_RESOLUTION_HS > 24) || (SAMPLE_BIT_RESOLUTION_FS > 24) || defined(NATIVE_DSD)
|
||||
#warning FIXME
|
||||
h |= (l >>29)& 0x7; // Note: This step is not required if we assume sample depth is 24bit (rather than 32bit)
|
||||
// Note: We need all 32bits for Native DSD
|
||||
#endif
|
||||
//#endif
|
||||
outuint(c_mix_out, h);
|
||||
#else
|
||||
outuint(c_mix_out, sample);
|
||||
@@ -366,7 +384,7 @@ __builtin_unreachable();
|
||||
|
||||
case 3:
|
||||
#if (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 3)
|
||||
__builtin_unreachable();
|
||||
//__builtin_unreachable();
|
||||
#endif
|
||||
/* Buffering not underflow condition send out some samples...*/
|
||||
for(int i = 0; i < g_numUsbChanOut; i++)
|
||||
@@ -415,48 +433,12 @@ __builtin_unreachable();
|
||||
}
|
||||
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();
|
||||
//__builtin_unreachable();
|
||||
break;
|
||||
|
||||
} /* switch(g_slotsize) */
|
||||
} /* switch(g_curSubSlot_out) */
|
||||
|
||||
/* 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++)
|
||||
@@ -465,7 +447,7 @@ __builtin_unreachable();
|
||||
}
|
||||
|
||||
/* 3/4 bytes per sample */
|
||||
aud_data_remaining_to_device -= (g_numUsbChanOut*g_slotSize);
|
||||
aud_data_remaining_to_device -= (g_numUsbChanOut * g_curSubSlot_out);
|
||||
}
|
||||
|
||||
if (!inOverflow)
|
||||
@@ -476,7 +458,7 @@ __builtin_unreachable();
|
||||
|
||||
if (totalSampsToWrite)
|
||||
{
|
||||
unsigned datasize = totalSampsToWrite * g_slotSize * g_numUsbChanIn;
|
||||
unsigned datasize = totalSampsToWrite * g_curSubSlot_in * g_numUsbChanIn;
|
||||
|
||||
/* Round up to nearest word - note, not needed for slotsize == 4! */
|
||||
datasize = (datasize+3) & (~0x3);
|
||||
@@ -513,7 +495,7 @@ __builtin_unreachable();
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (totalSampsToWrite < 0 || totalSampsToWrite * g_slotSize * g_numUsbChanIn > g_maxPacketSize)
|
||||
if (totalSampsToWrite < 0 || totalSampsToWrite * g_curSubSlot_in * g_numUsbChanIn > g_maxPacketSize)
|
||||
{
|
||||
totalSampsToWrite = 0;
|
||||
}
|
||||
@@ -528,12 +510,12 @@ __builtin_unreachable();
|
||||
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 * g_curSubSlot_in + 4))
|
||||
{
|
||||
/* Packet okay, write to fifo */
|
||||
if (totalSampsToWrite)
|
||||
{
|
||||
write_via_xc_ptr(g_aud_to_host_wrptr, totalSampsToWrite*g_slotSize*g_numUsbChanIn);
|
||||
write_via_xc_ptr(g_aud_to_host_wrptr, totalSampsToWrite * g_curSubSlot_in * g_numUsbChanIn);
|
||||
packState = 0;
|
||||
g_aud_to_host_dptr = g_aud_to_host_wrptr + 4;
|
||||
}
|
||||
@@ -547,7 +529,7 @@ __builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
if (!outUnderflow && (aud_data_remaining_to_device<(g_slotSize*g_numUsbChanOut)))
|
||||
if (!outUnderflow && (aud_data_remaining_to_device<(g_curSubSlot_out * 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)
|
||||
@@ -620,18 +602,20 @@ static void check_for_interrupt(chanend ?c_clk_int) {
|
||||
}
|
||||
|
||||
/* Mark Endpoint (IN) ready with an appropriately sized zero buffer */
|
||||
static inline void SetupZerosSendBuffer(XUD_ep aud_to_host_usb_ep, unsigned sampFreq)
|
||||
static inline void SetupZerosSendBuffer(XUD_ep aud_to_host_usb_ep, unsigned sampFreq, unsigned slotSize)
|
||||
{
|
||||
int min, mid, max, usb_speed, p;
|
||||
GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed);
|
||||
GetADCCounts(sampFreq, min, mid, max);
|
||||
|
||||
// TODO, don't need to use speed.
|
||||
if (usb_speed == XUD_SPEED_HS)
|
||||
{
|
||||
mid*=NUM_USB_CHAN_IN*SAMPLE_SUBSLOT_SIZE_HS;
|
||||
mid *= NUM_USB_CHAN_IN * slotSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
mid*=NUM_USB_CHAN_IN_FS*SAMPLE_SUBSLOT_SIZE_FS;
|
||||
mid *= NUM_USB_CHAN_IN_FS * slotSize;
|
||||
}
|
||||
|
||||
asm("stw %0, %1[0]"::"r"(mid),"r"(g_aud_to_host_zeros));
|
||||
@@ -793,7 +777,7 @@ void decouple(chanend c_mix_out,
|
||||
SET_SHARED_GLOBAL(g_aud_to_host_buffer,g_aud_to_host_zeros);
|
||||
|
||||
/* Update size of zeros buffer */
|
||||
SetupZerosSendBuffer(aud_to_host_usb_ep, sampFreq);
|
||||
SetupZerosSendBuffer(aud_to_host_usb_ep, sampFreq, g_curSubSlot_in);
|
||||
|
||||
/* Reset OUT buffer state */
|
||||
outUnderflow = 1;
|
||||
@@ -819,13 +803,18 @@ void decouple(chanend c_mix_out,
|
||||
speedRem = 0;
|
||||
continue;
|
||||
}
|
||||
else if(tmp == SET_CHAN_COUNT_IN)
|
||||
else if(tmp == SET_STREAM_FORMAT_IN)
|
||||
{
|
||||
unsigned dataFormat, usbSpeed;
|
||||
|
||||
/* Change in IN channel count */
|
||||
DISABLE_INTERRUPTS();
|
||||
SET_SHARED_GLOBAL(g_freqChange_flag, 0);
|
||||
GET_SHARED_GLOBAL(g_numUsbChanIn, g_freqChange_sampFreq); /* Misuse of g_freqChange_sampFreq */
|
||||
|
||||
|
||||
GET_SHARED_GLOBAL(g_numUsbChanIn, g_formatChange_NumChans);
|
||||
GET_SHARED_GLOBAL(g_curSubSlot_in, g_formatChange_SubSlot);
|
||||
GET_SHARED_GLOBAL(dataFormat, g_formatChange_DataFormat); /* Not currently used for input stream */
|
||||
|
||||
/* Reset IN buffer state */
|
||||
inOverflow = 0;
|
||||
inUnderflow = 1;
|
||||
@@ -838,22 +827,41 @@ void decouple(chanend c_mix_out,
|
||||
SET_SHARED_GLOBAL(g_aud_to_host_buffer, g_aud_to_host_zeros);
|
||||
|
||||
/* Update size of zeros buffer */
|
||||
SetupZerosSendBuffer(aud_to_host_usb_ep, sampFreq);
|
||||
SetupZerosSendBuffer(aud_to_host_usb_ep, sampFreq, g_curSubSlot_in);
|
||||
|
||||
GET_SHARED_GLOBAL(usbSpeed, g_curUsbSpeed);
|
||||
if (usbSpeed == XUD_SPEED_HS)
|
||||
{
|
||||
g_maxPacketSize = (MAX_DEVICE_AUD_PACKET_SIZE_MULT_HS * g_numUsbChanIn);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_maxPacketSize = (MAX_DEVICE_AUD_PACKET_SIZE_MULT_FS * g_numUsbChanIn);
|
||||
}
|
||||
|
||||
SET_SHARED_GLOBAL(g_freqChange, 0);
|
||||
asm("outct res[%0],%1"::"r"(buffer_aud_ctl_chan),"r"(XS1_CT_END));
|
||||
|
||||
ENABLE_INTERRUPTS();
|
||||
}
|
||||
else if(tmp == SET_CHAN_COUNT_OUT)
|
||||
else if(tmp == SET_STREAM_FORMAT_OUT)
|
||||
{
|
||||
unsigned dataFormat;
|
||||
unsigned dsdMode = DSD_MODE_OFF;
|
||||
|
||||
/* Change in OUT channel count - note we expect this on every stream start event */
|
||||
DISABLE_INTERRUPTS();
|
||||
SET_SHARED_GLOBAL(g_freqChange_flag, 0);
|
||||
GET_SHARED_GLOBAL(g_numUsbChanOut, g_freqChange_sampFreq); /* Misuse of g_freqChange_sampFreq */
|
||||
GET_SHARED_GLOBAL(g_numUsbChanOut, g_formatChange_NumChans);
|
||||
GET_SHARED_GLOBAL(g_curSubSlot_out, g_formatChange_SubSlot);
|
||||
GET_SHARED_GLOBAL(dataFormat, g_formatChange_DataFormat);
|
||||
|
||||
/* Reset OUT buffer state */
|
||||
SET_SHARED_GLOBAL(g_aud_from_host_rdptr, aud_from_host_fifo_start);
|
||||
SET_SHARED_GLOBAL(g_aud_from_host_wrptr, aud_from_host_fifo_start);
|
||||
|
||||
unpackState = 0;
|
||||
|
||||
outUnderflow = 1;
|
||||
if(outOverflow)
|
||||
{
|
||||
@@ -861,11 +869,29 @@ void decouple(chanend c_mix_out,
|
||||
XUD_SetReady_OutPtr(aud_from_host_usb_ep, aud_from_host_fifo_start+4);
|
||||
outOverflow = 0;
|
||||
}
|
||||
|
||||
#ifdef NATIVE_DSD
|
||||
/* TODO only send when there is a change */
|
||||
if(dataFormat == UAC_FORMAT_TYPEI_RAW_DATA)
|
||||
{
|
||||
dsdMode = DSD_MODE_NATIVE;
|
||||
}
|
||||
|
||||
/* Wait for the audio code to request samples and respond with command */
|
||||
inuint(c_mix_out);
|
||||
outct(c_mix_out, SET_DSD_MODE);
|
||||
outuint(c_mix_out, dsdMode);
|
||||
|
||||
/* Wait for handshake back */
|
||||
chkct(c_mix_out, XS1_CT_END);
|
||||
#endif
|
||||
asm("outct res[%0],%1"::"r"(buffer_aud_ctl_chan),"r"(XS1_CT_END));
|
||||
|
||||
SET_SHARED_GLOBAL(g_freqChange, 0);
|
||||
ENABLE_INTERRUPTS();
|
||||
}
|
||||
#ifdef NATIVE_DSD
|
||||
#if 0
|
||||
//#ifdef NATIVE_DSD
|
||||
else if(tmp == SET_DSD_MODE)
|
||||
{
|
||||
unsigned dsdMode;
|
||||
@@ -922,7 +948,7 @@ void decouple(chanend c_mix_out,
|
||||
read_via_xc_ptr(datalength, released_buffer);
|
||||
|
||||
/* Ignore bad small packets */
|
||||
if ((datalength >= (g_numUsbChanOut * g_slotSize)) && (released_buffer == aud_from_host_wrptr))
|
||||
if ((datalength >= (g_numUsbChanOut * g_curSubSlot_out)) && (released_buffer == aud_from_host_wrptr))
|
||||
{
|
||||
|
||||
/* Move the write pointer of the fifo on - round up to nearest word */
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include <xs1.h>
|
||||
#include <print.h>
|
||||
|
||||
#include "usb.h"
|
||||
#include "devicedefines.h"
|
||||
#ifdef MIDI
|
||||
#include "usb_midi.h"
|
||||
@@ -241,10 +240,11 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
|
||||
else
|
||||
{
|
||||
unsigned cmd = inuint(c_aud_ctl);
|
||||
sampleFreq = inuint(c_aud_ctl);
|
||||
|
||||
if(cmd == SET_SAMPLE_FREQ)
|
||||
{
|
||||
sampleFreq = inuint(c_aud_ctl);
|
||||
|
||||
/* Don't update things for DFU command.. */
|
||||
if(sampleFreq != AUDIO_STOP_FOR_DFU)
|
||||
{
|
||||
@@ -262,9 +262,31 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
|
||||
/* Ideally we want to wait for handshake (and pass back up) here. But we cannot keep this
|
||||
* core locked, it must stay responsive to packets (MIDI etc) and SOFs. So, set a flag and check for
|
||||
* handshake elsewhere */
|
||||
SET_SHARED_GLOBAL(g_freqChange_sampFreq, sampleFreq);
|
||||
}
|
||||
else if (cmd == SET_CHAN_COUNT_OUT)
|
||||
else if(cmd == SET_STREAM_FORMAT_IN)
|
||||
{
|
||||
unsigned formatChange_SubSlot, formatChange_NumChans, formatChange_DataFormat;
|
||||
|
||||
formatChange_DataFormat = inuint(c_aud_ctl);
|
||||
formatChange_NumChans = inuint(c_aud_ctl);
|
||||
formatChange_SubSlot = inuint(c_aud_ctl);
|
||||
|
||||
SET_SHARED_GLOBAL(g_formatChange_NumChans, formatChange_NumChans);
|
||||
SET_SHARED_GLOBAL(g_formatChange_SubSlot, formatChange_SubSlot);
|
||||
SET_SHARED_GLOBAL(g_formatChange_DataFormat, formatChange_DataFormat);
|
||||
}
|
||||
else if (cmd == SET_STREAM_FORMAT_OUT)
|
||||
{
|
||||
unsigned formatChange_SubSlot, formatChange_NumChans, formatChange_DataFormat;
|
||||
formatChange_DataFormat = inuint(c_aud_ctl);
|
||||
formatChange_NumChans = inuint(c_aud_ctl);
|
||||
formatChange_SubSlot = inuint(c_aud_ctl);
|
||||
|
||||
SET_SHARED_GLOBAL(g_formatChange_NumChans, formatChange_NumChans);
|
||||
SET_SHARED_GLOBAL(g_formatChange_SubSlot, formatChange_SubSlot);
|
||||
SET_SHARED_GLOBAL(g_formatChange_DataFormat, formatChange_DataFormat);
|
||||
|
||||
/* Host is starting up the output stream. Setup (or potentially resize) feedback packet based on bus-speed
|
||||
* This is only really important on inital start up (when bus-speed
|
||||
was unknown) and when changing bus-speeds */
|
||||
@@ -284,8 +306,7 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
|
||||
/* Pass on sample freq change to decouple() via global flag (saves a chanend) */
|
||||
/* Note: freqChange flags now used to communicate other commands also */
|
||||
SET_SHARED_GLOBAL0(g_freqChange, cmd); /* Set command */
|
||||
SET_SHARED_GLOBAL(g_freqChange_sampFreq, sampleFreq); /* Set flag */
|
||||
SET_SHARED_GLOBAL(g_freqChange_flag, cmd);
|
||||
SET_SHARED_GLOBAL(g_freqChange_flag, cmd); /* Set Flag */
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -422,11 +443,10 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
|
||||
#ifdef MIDI
|
||||
case XUD_GetData_Select(c_midi_from_host, ep_midi_from_host, length, result):
|
||||
asm("#midi h->d");
|
||||
|
||||
|
||||
if((result == XUD_RES_OKAY) && (length > 0))
|
||||
{
|
||||
/* Get buffer data from host - MIDI OUT from host always into a single buffer */
|
||||
/* Write datalength (tmp) into buffer[0], data stored in buffer[4] onwards */
|
||||
midi_data_remaining_to_device = length;
|
||||
|
||||
midi_from_host_rdptr = midi_from_host_buffer;
|
||||
|
||||
@@ -14,19 +14,25 @@ inline xc_ptr array_to_xc_ptr(const unsigned a[])
|
||||
return x;
|
||||
}
|
||||
|
||||
#define write_via_xc_ptr(p,x) asm volatile("stw %0, %1[0]"::"r"(x),"r"(p))
|
||||
#define write_via_xc_ptr(p,x) asm volatile("stw %0, %1[0]"::"r"(x),"r"(p))
|
||||
|
||||
#define write_via_xc_ptr_indexed(p,i,x) asm volatile("stw %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
|
||||
#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
|
||||
#define write_via_xc_ptr_indexed(p,i,x) asm volatile("stw %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
|
||||
#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
|
||||
#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
|
||||
#define write_short_via_xc_ptr_indexed(p,i,x) asm volatile("st16 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
|
||||
// No immediate st8 format
|
||||
#define write_byte_via_xc_ptr(p,x) write_byte_via_xc_ptr_indexed(p, 0, x)
|
||||
#define write_byte_via_xc_ptr(p,x) write_byte_via_xc_ptr_indexed(p, 0, x)
|
||||
#define write_short_via_xc_ptr(p,x) write_short_via_xc_ptr_indexed(p, 0, x)
|
||||
|
||||
#define read_via_xc_ptr(x,p) asm("ldw %0, %1[0]":"=r"(x):"r"(p));
|
||||
#define read_via_xc_ptr(x,p) asm("ldw %0, %1[0]":"=r"(x):"r"(p));
|
||||
|
||||
#define read_via_xc_ptr_indexed(x,p,i) asm("ldw %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
|
||||
#define read_byte_via_xc_ptr_indexed(x,p,i) asm("ld8u %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
|
||||
#define read_short_via_xc_ptr_indexed(x,p,i) asm("ld16s %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
|
||||
|
||||
#define read_via_xc_ptr_indexed(x,p,i) asm("ldw %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
|
||||
#define read_byte_via_xc_ptr_indexed(x,p,i) asm("ld8u %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
|
||||
// No immediate ld8u format
|
||||
#define read_byte_via_xc_ptr(x,p) read_byte_via_xc_ptr_indexed(x, p, 0)
|
||||
#define read_byte_via_xc_ptr(x,p) read_byte_via_xc_ptr_indexed(x, p, 0)
|
||||
#define read_short_via_xc_ptr(x,p) read_short_via_xc_ptr_indexed(x, p, 0)
|
||||
|
||||
#define GET_SHARED_GLOBAL(x, g) asm volatile("ldw %0, dp[" #g "]":"=r"(x)::"memory")
|
||||
#define SET_SHARED_GLOBAL(g, v) asm volatile("stw %0, dp[" #g "]"::"r"(v):"memory")
|
||||
|
||||
Reference in New Issue
Block a user