forked from PAWPAW-Mirror/lib_xua
Fixed audio out buffer pointer off by 4 bytes
This commit is contained in:
@@ -579,7 +579,8 @@ void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config)
|
|||||||
{
|
{
|
||||||
|
|
||||||
#ifdef SPDIF
|
#ifdef SPDIF
|
||||||
{ //set_thread_fast_mode_on();
|
{
|
||||||
|
set_thread_fast_mode_on();
|
||||||
SpdifTransmit(p_spdif_tx, c_spdif_out);
|
SpdifTransmit(p_spdif_tx, c_spdif_out);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ unsigned g_epStatusOut[NUM_EP_OUT];
|
|||||||
unsigned g_epStatusIn[NUM_EP_IN];
|
unsigned g_epStatusIn[NUM_EP_IN];
|
||||||
|
|
||||||
/* Global variable for current USB bus speed (i.e. FS/HS) */
|
/* Global variable for current USB bus speed (i.e. FS/HS) */
|
||||||
unsigned g_curUsbSpeed = XUD_SPEED_HS;
|
unsigned g_curUsbSpeed = 0;
|
||||||
|
|
||||||
#ifdef HOST_ACTIVE_CALL
|
#ifdef HOST_ACTIVE_CALL
|
||||||
void VendorHostActive(int active);
|
void VendorHostActive(int active);
|
||||||
@@ -842,6 +842,8 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
|||||||
{
|
{
|
||||||
g_curUsbSpeed = XUD_ResetEndpoint(ep0_out, ep0_in);
|
g_curUsbSpeed = XUD_ResetEndpoint(ep0_out, ep0_in);
|
||||||
|
|
||||||
|
//printintln(g_curUsbSpeed);
|
||||||
|
|
||||||
g_config = 0;
|
g_config = 0;
|
||||||
|
|
||||||
#ifdef DFU
|
#ifdef DFU
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* \param c_clk_int Optional chanend connected to the clockGen() thread if present
|
* \param c_clk_int Optional chanend connected to the clockGen() thread if present
|
||||||
*/
|
*/
|
||||||
void decouple(chanend c_audio_out,
|
void decouple(chanend c_audio_out,
|
||||||
chanend ?c_midi,
|
// chanend ?c_midi,
|
||||||
chanend ?c_clk_int
|
chanend ?c_clk_int
|
||||||
#ifdef IAP
|
#ifdef IAP
|
||||||
, chanend ?c_iap
|
, chanend ?c_iap
|
||||||
|
|||||||
@@ -42,11 +42,13 @@
|
|||||||
*/
|
*/
|
||||||
static inline void XUD_Change_ReadyIn_Buffer(XUD_ep e, unsigned bufferPtr, int len)
|
static inline void XUD_Change_ReadyIn_Buffer(XUD_ep e, unsigned bufferPtr, int len)
|
||||||
{
|
{
|
||||||
|
|
||||||
int chan_array_ptr;
|
int chan_array_ptr;
|
||||||
int xud_chan;
|
int xud_chan;
|
||||||
int my_chan;
|
int my_chan;
|
||||||
int tail;
|
int tail;
|
||||||
|
|
||||||
|
printstr("TODO");
|
||||||
asm ("ldw %0, %1[0]":"=r"(chan_array_ptr):"r"(e));
|
asm ("ldw %0, %1[0]":"=r"(chan_array_ptr):"r"(e));
|
||||||
asm ("ldw %0, %1[2]":"=r"(my_chan):"r"(e));
|
asm ("ldw %0, %1[2]":"=r"(my_chan):"r"(e));
|
||||||
|
|
||||||
@@ -173,7 +175,8 @@ static inline void swap(xc_ptr &a, xc_ptr &b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// shared global midi buffering variables
|
// shared global midi buffering variables
|
||||||
#ifdef MIDI
|
#if 0
|
||||||
|
//#ifdef MIDI
|
||||||
unsigned g_midi_from_host_flag = 0;
|
unsigned g_midi_from_host_flag = 0;
|
||||||
unsigned g_midi_to_host_flag = 0;
|
unsigned g_midi_to_host_flag = 0;
|
||||||
int midi_to_host_usb_ep = 0;
|
int midi_to_host_usb_ep = 0;
|
||||||
@@ -193,7 +196,8 @@ int aud_from_host_usb_ep = 0;
|
|||||||
int aud_to_host_usb_ep = 0;
|
int aud_to_host_usb_ep = 0;
|
||||||
int int_usb_ep = 0;
|
int int_usb_ep = 0;
|
||||||
|
|
||||||
#ifdef MIDI
|
#if 0
|
||||||
|
//#ifdef MIDI
|
||||||
unsigned int g_midi_to_host_buffer_A[MAX_USB_MIDI_PACKET_SIZE/4+4];
|
unsigned int g_midi_to_host_buffer_A[MAX_USB_MIDI_PACKET_SIZE/4+4];
|
||||||
unsigned int g_midi_to_host_buffer_B[MAX_USB_MIDI_PACKET_SIZE/4+4];
|
unsigned int g_midi_to_host_buffer_B[MAX_USB_MIDI_PACKET_SIZE/4+4];
|
||||||
int g_midi_from_host_buffer[MAX_USB_MIDI_PACKET_SIZE/4+4];
|
int g_midi_from_host_buffer[MAX_USB_MIDI_PACKET_SIZE/4+4];
|
||||||
@@ -437,6 +441,7 @@ void handle_audio_request(chanend c_mix_out, chanend ?c_led)
|
|||||||
read_via_xc_ptr(sample, g_aud_from_host_rdptr);
|
read_via_xc_ptr(sample, g_aud_from_host_rdptr);
|
||||||
g_aud_from_host_rdptr+=4;
|
g_aud_from_host_rdptr+=4;
|
||||||
|
|
||||||
|
|
||||||
#ifndef OUT_VOLUME_IN_MIXER
|
#ifndef OUT_VOLUME_IN_MIXER
|
||||||
asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i));
|
asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i));
|
||||||
{h, l} = macs(mult, sample, 0, 0);
|
{h, l} = macs(mult, sample, 0, 0);
|
||||||
@@ -486,6 +491,14 @@ void handle_audio_request(chanend c_mix_out, chanend ?c_led)
|
|||||||
}
|
}
|
||||||
unpackState++;
|
unpackState++;
|
||||||
|
|
||||||
|
if(sample!=0)
|
||||||
|
{ //printhexln(sample);
|
||||||
|
//printintln(g_numUsbChanOut);
|
||||||
|
//printhexln(g_aud_from_host_rdptr);
|
||||||
|
//printintln(aud_data_remaining_to_device);
|
||||||
|
//while(1);
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef OUT_VOLUME_IN_MIXER
|
#ifndef OUT_VOLUME_IN_MIXER
|
||||||
asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i));
|
asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i));
|
||||||
{h, l} = macs(mult, sample, 0, 0);
|
{h, l} = macs(mult, sample, 0, 0);
|
||||||
@@ -588,6 +601,7 @@ void handle_audio_request(chanend c_mix_out, chanend ?c_led)
|
|||||||
/* Handle any tail - incase a bad driver sent us a datalength not a multiple of chan count */
|
/* Handle any tail - incase a bad driver sent us a datalength not a multiple of chan count */
|
||||||
if (aud_data_remaining_to_device)
|
if (aud_data_remaining_to_device)
|
||||||
{
|
{
|
||||||
|
printintln(aud_data_remaining_to_device);
|
||||||
/* Round up to nearest word */
|
/* Round up to nearest word */
|
||||||
aud_data_remaining_to_device +=3;
|
aud_data_remaining_to_device +=3;
|
||||||
aud_data_remaining_to_device &= (~3);
|
aud_data_remaining_to_device &= (~3);
|
||||||
@@ -610,6 +624,7 @@ void handle_audio_request(chanend c_mix_out, chanend ?c_led)
|
|||||||
{
|
{
|
||||||
read_via_xc_ptr(aud_data_remaining_to_device, g_aud_from_host_rdptr);
|
read_via_xc_ptr(aud_data_remaining_to_device, g_aud_from_host_rdptr);
|
||||||
|
|
||||||
|
|
||||||
unpackState = 0;
|
unpackState = 0;
|
||||||
|
|
||||||
g_aud_from_host_rdptr+=4;
|
g_aud_from_host_rdptr+=4;
|
||||||
@@ -665,7 +680,8 @@ unsigned char tmpBuffer[1026];
|
|||||||
|
|
||||||
#pragma unsafe arrays
|
#pragma unsafe arrays
|
||||||
void decouple(chanend c_mix_out,
|
void decouple(chanend c_mix_out,
|
||||||
chanend ?c_midi, chanend ?c_clk_int
|
//chanend ?c_midi,
|
||||||
|
chanend ?c_clk_int
|
||||||
#ifdef IAP
|
#ifdef IAP
|
||||||
, chanend ?c_iap
|
, chanend ?c_iap
|
||||||
#endif
|
#endif
|
||||||
@@ -676,21 +692,6 @@ void decouple(chanend c_mix_out,
|
|||||||
int aud_to_host_flag=0;
|
int aud_to_host_flag=0;
|
||||||
xc_ptr released_buffer;
|
xc_ptr released_buffer;
|
||||||
|
|
||||||
#ifdef MIDI
|
|
||||||
xc_ptr midi_from_host_rdptr;
|
|
||||||
xc_ptr midi_from_host_buffer;
|
|
||||||
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;
|
|
||||||
int midi_data_collected_from_device = 0;
|
|
||||||
int midi_waiting_on_send_to_host = 0;
|
|
||||||
int midi_to_host_flag = 0;
|
|
||||||
int midi_from_host_flag = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef IAP
|
#ifdef IAP
|
||||||
xc_ptr iap_from_host_rdptr;
|
xc_ptr iap_from_host_rdptr;
|
||||||
xc_ptr iap_from_host_buffer;
|
xc_ptr iap_from_host_buffer;
|
||||||
@@ -771,18 +772,19 @@ void decouple(chanend c_mix_out,
|
|||||||
|
|
||||||
#ifdef MIDI
|
#ifdef MIDI
|
||||||
//asm("ldaw %0, dp[g_midi_to_host_buffer]":"=r"(midi_to_host_buffer));
|
//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));
|
//asm("ldaw %0, dp[g_midi_from_host_buffer]":"=r"(midi_from_host_buffer));
|
||||||
|
|
||||||
// wait for usb_buffer to set up
|
// wait for usb_buffer to set up
|
||||||
while(!midi_from_host_flag) {
|
//while(!midi_from_host_flag) {
|
||||||
GET_SHARED_GLOBAL(midi_from_host_flag, g_midi_from_host_flag);
|
//GET_SHARED_GLOBAL(midi_from_host_flag, g_midi_from_host_flag);
|
||||||
}
|
// }
|
||||||
|
//#if 1
|
||||||
|
|
||||||
midi_from_host_flag = 0;
|
//midi_from_host_flag = 0;
|
||||||
SET_SHARED_GLOBAL(g_midi_from_host_flag, midi_from_host_flag);
|
//SET_SHARED_GLOBAL(g_midi_from_host_flag, midi_from_host_flag);
|
||||||
|
|
||||||
// send the current host -> device buffer out of the fifo
|
// send the current host -> device buffer out of the fifo
|
||||||
XUD_SetReady_OutPtr(midi_from_host_usb_ep, midi_from_host_buffer);
|
//XUD_SetReady_OutPtr(midi_from_host_usb_ep, midi_from_host_buffer);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef IAP
|
#ifdef IAP
|
||||||
@@ -813,7 +815,7 @@ void decouple(chanend c_mix_out,
|
|||||||
|
|
||||||
// send the current host -> device buffer out of the fifo
|
// send the current host -> device buffer out of the fifo
|
||||||
SET_SHARED_GLOBAL(g_aud_from_host_buffer, g_aud_from_host_wrptr);
|
SET_SHARED_GLOBAL(g_aud_from_host_buffer, g_aud_from_host_wrptr);
|
||||||
XUD_SetReady_OutPtr(aud_from_host_usb_ep, g_aud_from_host_wrptr);
|
XUD_SetReady_OutPtr(aud_from_host_usb_ep, g_aud_from_host_wrptr+4);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INPUT
|
#ifdef INPUT
|
||||||
@@ -849,18 +851,11 @@ void decouple(chanend c_mix_out,
|
|||||||
|
|
||||||
{
|
{
|
||||||
#ifdef HID_CONTROLS
|
#ifdef HID_CONTROLS
|
||||||
|
|
||||||
p_but :> tmp;
|
|
||||||
tmp = ~tmp;
|
|
||||||
tmp &=3;
|
|
||||||
g_hidData[0] = tmp;
|
|
||||||
|
|
||||||
Vendor_ReadHIDButtons(g_hidData);
|
Vendor_ReadHIDButtons(g_hidData);
|
||||||
|
|
||||||
asm("ldaw %0, dp[g_hidData]":"=r"(tmp));
|
|
||||||
if(g_hidFlag == 0)
|
if(g_hidFlag == 0)
|
||||||
{
|
{
|
||||||
//XUD_SetReady_In(g_ep_hid, 0, tmp, 1);
|
XUD_SetReady_In(g_ep_hid, g_hidData, 1);
|
||||||
g_hidFlag = 1;
|
g_hidFlag = 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -969,12 +964,28 @@ void decouple(chanend c_mix_out,
|
|||||||
/* Read datalength from buffer */
|
/* Read datalength from buffer */
|
||||||
read_via_xc_ptr(datalength, released_buffer);
|
read_via_xc_ptr(datalength, released_buffer);
|
||||||
|
|
||||||
|
//printintln(datalength);
|
||||||
|
|
||||||
/* Ignore bad small packets */
|
/* Ignore bad small packets */
|
||||||
if ((datalength >= (g_numUsbChanOut * slotSize)) && (released_buffer == g_aud_from_host_wrptr))
|
if ((datalength >= (g_numUsbChanOut * slotSize)) && (released_buffer == g_aud_from_host_wrptr))
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
for(int i = 0; i < (datalength+4); i++)
|
||||||
|
{
|
||||||
|
unsigned samp;
|
||||||
|
read_byte_via_xc_ptr(samp, aud_from_host_wrptr);
|
||||||
|
aud_from_host_wrptr+=1;
|
||||||
|
printint(i);
|
||||||
|
printhexln(samp);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
/* Move the write pointer of the fifo on - round up to nearest word */
|
/* Move the write pointer of the fifo on - round up to nearest word */
|
||||||
aud_from_host_wrptr = aud_from_host_wrptr + ((datalength+3)&~0x3) + 4;
|
aud_from_host_wrptr = aud_from_host_wrptr + ((datalength+3)&~0x3) + 4;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Wrap pointer */
|
/* Wrap pointer */
|
||||||
if (aud_from_host_wrptr >= aud_from_host_fifo_end)
|
if (aud_from_host_wrptr >= aud_from_host_fifo_end)
|
||||||
{
|
{
|
||||||
@@ -997,7 +1008,7 @@ void decouple(chanend c_mix_out,
|
|||||||
if (space_left <= 0 || space_left >= MAX_USB_AUD_PACKET_SIZE)
|
if (space_left <= 0 || space_left >= MAX_USB_AUD_PACKET_SIZE)
|
||||||
{
|
{
|
||||||
SET_SHARED_GLOBAL(g_aud_from_host_buffer, aud_from_host_wrptr);
|
SET_SHARED_GLOBAL(g_aud_from_host_buffer, aud_from_host_wrptr);
|
||||||
XUD_SetReady_OutPtr(aud_from_host_usb_ep, aud_from_host_wrptr);
|
XUD_SetReady_OutPtr(aud_from_host_usb_ep, aud_from_host_wrptr+4);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1024,6 +1035,7 @@ void decouple(chanend c_mix_out,
|
|||||||
/* Come out of OUT overflow state */
|
/* Come out of OUT overflow state */
|
||||||
outOverflow = 0;
|
outOverflow = 0;
|
||||||
SET_SHARED_GLOBAL(g_aud_from_host_buffer, aud_from_host_wrptr);
|
SET_SHARED_GLOBAL(g_aud_from_host_buffer, aud_from_host_wrptr);
|
||||||
|
printintln(1);
|
||||||
//XUD_SetReady(aud_from_host_usb_ep, 1);
|
//XUD_SetReady(aud_from_host_usb_ep, 1);
|
||||||
#ifdef DEBUG_LEDS
|
#ifdef DEBUG_LEDS
|
||||||
led(c_led);
|
led(c_led);
|
||||||
@@ -1115,121 +1127,6 @@ void decouple(chanend c_mix_out,
|
|||||||
}
|
}
|
||||||
#endif // INPUT
|
#endif // INPUT
|
||||||
|
|
||||||
#ifdef MIDI
|
|
||||||
/* Check if buffer() has send MIDI packet to host */
|
|
||||||
GET_SHARED_GLOBAL(midi_to_host_flag, g_midi_to_host_flag);
|
|
||||||
if (midi_to_host_flag)
|
|
||||||
{
|
|
||||||
/* The buffer has been sent to the host, so we can ack the midi thread */
|
|
||||||
SET_SHARED_GLOBAL(g_midi_to_host_flag, 0);
|
|
||||||
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(midi_to_host_usb_ep, midi_to_host_buffer_being_sent+4, midi_data_collected_from_device);
|
|
||||||
|
|
||||||
/* Mark as waiting for host to poll us */
|
|
||||||
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
|
|
||||||
{
|
|
||||||
/* Check if host has sent us MIDI OUT data */
|
|
||||||
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 */
|
|
||||||
/* Reset flag */
|
|
||||||
SET_SHARED_GLOBAL(g_midi_from_host_flag, 0);
|
|
||||||
|
|
||||||
/* Read length from buffer[0] */
|
|
||||||
read_via_xc_ptr(midi_data_remaining_to_device, midi_from_host_buffer);
|
|
||||||
|
|
||||||
//printintln(midi_data_remaining_to_device);
|
|
||||||
|
|
||||||
/* Increment read pointer - buffer[0] is length */
|
|
||||||
midi_from_host_rdptr = midi_from_host_buffer + 4;
|
|
||||||
|
|
||||||
if (midi_data_remaining_to_device)
|
|
||||||
{
|
|
||||||
read_via_xc_ptr(datum, midi_from_host_rdptr);
|
|
||||||
outuint(c_midi, datum);
|
|
||||||
//printhexln(datum);
|
|
||||||
midi_from_host_rdptr += 4;
|
|
||||||
midi_data_remaining_to_device -= 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
select
|
|
||||||
{
|
|
||||||
/* Received word from MIDI thread - Check for ACK or Data */
|
|
||||||
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
|
|
||||||
* we are okay to send another word */
|
|
||||||
if (midi_data_remaining_to_device == 0)
|
|
||||||
{
|
|
||||||
/* We have read an entire packet - Mark ready to receive another */
|
|
||||||
XUD_SetReady_OutPtr(midi_from_host_usb_ep, midi_from_host_buffer+4);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Read another word from the fifo and output it to MIDI thread */
|
|
||||||
read_via_xc_ptr(datum, midi_from_host_rdptr);
|
|
||||||
outuint(c_midi, datum);
|
|
||||||
midi_from_host_rdptr += 4;
|
|
||||||
midi_data_remaining_to_device -= 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* The midi/uart thread has sent us some data - handshake back */
|
|
||||||
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
|
|
||||||
{
|
|
||||||
// Too many events from device - drop
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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(midi_to_host_usb_ep, midi_to_host_buffer_being_sent+4, midi_data_collected_from_device);
|
|
||||||
midi_data_collected_from_device = 0;
|
|
||||||
midi_waiting_on_send_to_host = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif // MIDI
|
|
||||||
|
|
||||||
#ifdef IAP
|
#ifdef IAP
|
||||||
GET_SHARED_GLOBAL(iap_reset, g_iap_reset);
|
GET_SHARED_GLOBAL(iap_reset, g_iap_reset);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ void buffer(chanend c_aud_out,
|
|||||||
#ifdef MIDI
|
#ifdef MIDI
|
||||||
chanend c_midi_from_host,
|
chanend c_midi_from_host,
|
||||||
chanend c_midi_to_host,
|
chanend c_midi_to_host,
|
||||||
|
chanend c_midi,
|
||||||
#endif
|
#endif
|
||||||
#ifdef IAP
|
#ifdef IAP
|
||||||
#error IAP
|
#error IAP
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
#include "xud.h"
|
#include "xud.h"
|
||||||
#include "testct_byref.h"
|
#include "testct_byref.h"
|
||||||
|
|
||||||
|
int pktCount = 0;
|
||||||
|
|
||||||
XUD_ep XUD_Init_Ep(chanend c_ep);
|
XUD_ep XUD_Init_Ep(chanend c_ep);
|
||||||
//
|
//
|
||||||
//static inline void XUD_SetNotReady(XUD_ep e)
|
//static inline void XUD_SetNotReady(XUD_ep e)
|
||||||
@@ -55,6 +57,13 @@ static inline void swap(xc_ptr &a, xc_ptr &b)
|
|||||||
}
|
}
|
||||||
#endif
|
#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];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
unsigned char fb_clocks[16];
|
unsigned char fb_clocks[16];
|
||||||
|
|
||||||
//#define FB_TOLERANCE_TEST
|
//#define FB_TOLERANCE_TEST
|
||||||
@@ -73,6 +82,7 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
|
|||||||
#ifdef MIDI
|
#ifdef MIDI
|
||||||
chanend c_midi_from_host,
|
chanend c_midi_from_host,
|
||||||
chanend c_midi_to_host,
|
chanend c_midi_to_host,
|
||||||
|
chanend c_midi,
|
||||||
#endif
|
#endif
|
||||||
#ifdef IAP
|
#ifdef IAP
|
||||||
chanend c_iap_from_host,
|
chanend c_iap_from_host,
|
||||||
@@ -132,6 +142,19 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
|
|||||||
xc_ptr midi_from_host_buffer = 0;
|
xc_ptr midi_from_host_buffer = 0;
|
||||||
xc_ptr midi_to_host_buffer = 0;
|
xc_ptr midi_to_host_buffer = 0;
|
||||||
xc_ptr midi_to_host_waiting_buffer = 0;
|
xc_ptr midi_to_host_waiting_buffer = 0;
|
||||||
|
|
||||||
|
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;
|
||||||
|
int midi_data_collected_from_device = 0;
|
||||||
|
int midi_waiting_on_send_to_host = 0;
|
||||||
|
int midi_to_host_flag = 0;
|
||||||
|
int midi_from_host_flag = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
xc_ptr p_inZeroBuff = array_to_xc_ptr(inZeroBuff);
|
xc_ptr p_inZeroBuff = array_to_xc_ptr(inZeroBuff);
|
||||||
@@ -163,7 +186,10 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
|
|||||||
int frameTime;
|
int frameTime;
|
||||||
|
|
||||||
while(usb_speed == 0)
|
while(usb_speed == 0)
|
||||||
|
{
|
||||||
GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed);
|
GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed);
|
||||||
|
//printintln(usb_speed);
|
||||||
|
}
|
||||||
|
|
||||||
GetADCCounts(DEFAULT_FREQ, min, mid, max);
|
GetADCCounts(DEFAULT_FREQ, min, mid, max);
|
||||||
asm("stw %0, dp[g_speed]"::"r"(mid << 16));
|
asm("stw %0, dp[g_speed]"::"r"(mid << 16));
|
||||||
@@ -189,10 +215,12 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
|
|||||||
|
|
||||||
// pass the midi->XUD chanends to decouple so that thread can
|
// pass the midi->XUD chanends to decouple so that thread can
|
||||||
// initialize comm with XUD
|
// initialize comm with XUD
|
||||||
asm("stw %0, dp[midi_to_host_usb_ep]"::"r"(ep_midi_to_host));
|
//asm("stw %0, dp[midi_to_host_usb_ep]"::"r"(ep_midi_to_host));
|
||||||
asm("stw %0, dp[midi_from_host_usb_ep]"::"r"(ep_midi_from_host));
|
//asm("stw %0, dp[midi_from_host_usb_ep]"::"r"(ep_midi_from_host));
|
||||||
swap(midi_to_host_buffer, midi_to_host_waiting_buffer);
|
swap(midi_to_host_buffer, midi_to_host_waiting_buffer);
|
||||||
SET_SHARED_GLOBAL(g_midi_from_host_flag, 1);
|
//SET_SHARED_GLOBAL(g_midi_from_host_flag, 1);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef IAP
|
#ifdef IAP
|
||||||
@@ -230,9 +258,7 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
|
|||||||
|
|
||||||
if (usb_speed == XUD_SPEED_HS)
|
if (usb_speed == XUD_SPEED_HS)
|
||||||
{
|
{
|
||||||
|
|
||||||
XUD_SetReady_In(ep_aud_fb, fb_clocks, 4);
|
XUD_SetReady_In(ep_aud_fb, fb_clocks, 4);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -241,6 +267,10 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef MIDI
|
||||||
|
XUD_SetReady_OutPtr(ep_midi_from_host, midi_from_host_buffer);
|
||||||
|
#endif
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -439,10 +469,6 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
|
|||||||
/* DEVICE -> HOST */
|
/* DEVICE -> HOST */
|
||||||
case XUD_SetData_Select(c_aud_in, ep_aud_in, tmp):
|
case XUD_SetData_Select(c_aud_in, ep_aud_in, tmp):
|
||||||
{
|
{
|
||||||
//XUD_SetData_Inline(ep_aud_in, c_aud_in);
|
|
||||||
|
|
||||||
//XUD_SetNotReady(ep_aud_in);
|
|
||||||
|
|
||||||
/* Inform stream that buffer sent */
|
/* Inform stream that buffer sent */
|
||||||
SET_SHARED_GLOBAL(g_aud_to_host_flag, bufferIn+1);
|
SET_SHARED_GLOBAL(g_aud_to_host_flag, bufferIn+1);
|
||||||
}
|
}
|
||||||
@@ -476,41 +502,84 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
|
|||||||
|
|
||||||
/* Audio HOST -> DEVICE */
|
/* Audio HOST -> DEVICE */
|
||||||
case XUD_GetData_Select(c_aud_out, ep_aud_out, tmp):
|
case XUD_GetData_Select(c_aud_out, ep_aud_out, tmp):
|
||||||
|
{
|
||||||
|
unsigned samp;
|
||||||
asm("#h->d aud data");
|
asm("#h->d aud data");
|
||||||
|
|
||||||
|
pktCount++;
|
||||||
|
|
||||||
|
if(pktCount ==3)
|
||||||
|
{
|
||||||
|
// asm("ecallf %0"::"r"(0));
|
||||||
|
}
|
||||||
|
|
||||||
GET_SHARED_GLOBAL(aud_from_host_buffer, g_aud_from_host_buffer);
|
GET_SHARED_GLOBAL(aud_from_host_buffer, g_aud_from_host_buffer);
|
||||||
|
|
||||||
|
//printintln(tmp);
|
||||||
|
#if 0
|
||||||
|
for(int i = 0; i < (tmp); i++)
|
||||||
|
{
|
||||||
|
read_byte_via_xc_ptr(samp, aud_from_host_buffer);
|
||||||
|
aud_from_host_buffer+=1;
|
||||||
|
printint(i);
|
||||||
|
printhexln(samp);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
write_via_xc_ptr(aud_from_host_buffer, tmp);
|
write_via_xc_ptr(aud_from_host_buffer, tmp);
|
||||||
/* Sync with audio thread */
|
/* Sync with audio thread */
|
||||||
SET_SHARED_GLOBAL(g_aud_from_host_flag, 1);
|
SET_SHARED_GLOBAL(g_aud_from_host_flag, 1);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef MIDI
|
#ifdef MIDI
|
||||||
case XUD_GetData_Select(c_midi_from_host, ep_midi_from_host, tmp):
|
case XUD_GetData_Select(c_midi_from_host, ep_midi_from_host, tmp):
|
||||||
asm("#midi h->d");
|
asm("#midi h->d");
|
||||||
|
|
||||||
/* Get buffer data from host - MIDI OUT from host always into a single buffer */
|
/* 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 */
|
/* Write datalength (tmp) into buffer[0], data stored in buffer[4] onwards */
|
||||||
write_via_xc_ptr(midi_from_host_buffer, tmp);
|
midi_data_remaining_to_device = tmp;
|
||||||
|
|
||||||
/* release the buffer */
|
/* Increment read pointer - buffer[0] is length */
|
||||||
SET_SHARED_GLOBAL(g_midi_from_host_flag, 1);
|
midi_from_host_rdptr = midi_from_host_buffer + 4;
|
||||||
|
|
||||||
|
if (midi_data_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;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* MIDI IN to host */
|
/* MIDI IN to host */
|
||||||
case XUD_SetData_Select(c_midi_to_host, ep_midi_to_host, tmp):
|
case XUD_SetData_Select(c_midi_to_host, ep_midi_to_host, tmp):
|
||||||
asm("#midi d->h");
|
asm("#midi d->h");
|
||||||
|
|
||||||
// Ack the decouple thread to say it has been sent to host
|
|
||||||
SET_SHARED_GLOBAL(g_midi_to_host_flag, 1);
|
|
||||||
|
|
||||||
swap(midi_to_host_buffer, midi_to_host_waiting_buffer);
|
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);
|
||||||
|
|
||||||
|
/* Mark as waiting for host to poll us */
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -623,15 +692,73 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
|
|||||||
|
|
||||||
#ifdef HID_CONTROLS
|
#ifdef HID_CONTROLS
|
||||||
/* HID Report Data */
|
/* HID Report Data */
|
||||||
case inuint_byref(c_hid, tmp):
|
case XUD_SetData_Select(c_hid, ep_hid, tmp):
|
||||||
{
|
{
|
||||||
//XUD_SetData_Inline(ep_hid, c_hid);
|
|
||||||
|
|
||||||
asm("stw %0, dp[g_hidFlag]" :: "r" (0) );
|
asm("stw %0, dp[g_hidFlag]" :: "r" (0) );
|
||||||
|
|
||||||
//XUD_SetNotReady(ep_hid);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MIDI
|
||||||
|
//select
|
||||||
|
// {
|
||||||
|
/* Received word from MIDI thread - Check for ACK or Data */
|
||||||
|
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
|
||||||
|
* we are okay to send another word */
|
||||||
|
if (midi_data_remaining_to_device == 0)
|
||||||
|
{
|
||||||
|
/* We have read an entire packet - Mark ready to receive another */
|
||||||
|
XUD_SetReady_OutPtr(ep_midi_from_host, midi_from_host_buffer+4);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Read another word from the fifo and output it to MIDI thread */
|
||||||
|
read_via_xc_ptr(datum, midi_from_host_rdptr);
|
||||||
|
outuint(c_midi, datum);
|
||||||
|
midi_from_host_rdptr += 4;
|
||||||
|
midi_data_remaining_to_device -= 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* The midi/uart thread has sent us some data - handshake back */
|
||||||
|
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
|
||||||
|
{
|
||||||
|
// Too many events from device - drop
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
midi_data_collected_from_device = 0;
|
||||||
|
midi_waiting_on_send_to_host = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// default:
|
||||||
|
// break;
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user