BUG 11356: Keep iAP messages together by sending length before data

This commit is contained in:
Russell Gallop
2011-09-21 11:21:58 +01:00
parent c0a701b926
commit c12e0bfce5

View File

@@ -675,6 +675,8 @@ void decouple(chanend c_mix_out,
int iap_waiting_on_send_to_host = 0; int iap_waiting_on_send_to_host = 0;
int iap_to_host_flag = 0; int iap_to_host_flag = 0;
int iap_from_host_flag = 0; int iap_from_host_flag = 0;
int iap_expecting_length = 1;
int iap_expecting_data_length = 0;
#endif #endif
int t = array_to_xc_ptr(outAudioBuff); int t = array_to_xc_ptr(outAudioBuff);
@@ -1168,6 +1170,7 @@ void decouple(chanend c_mix_out,
if (iap_reset) { if (iap_reset) {
iap_send_reset(c_iap); // What if this happen in the middle of a send/ack? iap_send_reset(c_iap); // What if this happen in the middle of a send/ack?
iap_reset = 0; iap_reset = 0;
iap_expecting_length = 1;
SET_SHARED_GLOBAL(g_iap_reset, iap_reset); // Reset has been signalled SET_SHARED_GLOBAL(g_iap_reset, iap_reset); // Reset has been signalled
} }
// Need to handle sending ZLP on iap_to_host_usb_ep_int to signal iOS device to collect from bulk endpoint. // Need to handle sending ZLP on iap_to_host_usb_ep_int to signal iOS device to collect from bulk endpoint.
@@ -1256,32 +1259,38 @@ void decouple(chanend c_mix_out,
{ {
/* The iap/uart thread has sent us some data - handshake back */ /* The iap/uart thread has sent us some data - handshake back */
iap_send_ack(c_iap); iap_send_ack(c_iap);
if (iap_data_collected_from_device < IAP_USB_BUFFER_TO_HOST_SIZE) if (iap_expecting_length) {
{ iap_expecting_data_length = datum_iap;
/* There is room in the collecting buffer for the data */ iap_expecting_length = 0;
xc_ptr p = (iap_to_host_buffer_being_collected + 4) + iap_data_collected_from_device; } else {
// Add data to the buffer if (iap_data_collected_from_device < IAP_USB_BUFFER_TO_HOST_SIZE)
write_byte_via_xc_ptr(p, datum_iap); {
iap_data_collected_from_device += 1; /* There is room in the collecting buffer for the data */
} xc_ptr p = (iap_to_host_buffer_being_collected + 4) + iap_data_collected_from_device;
else // Add data to the buffer
{ write_byte_via_xc_ptr(p, datum_iap);
// Too many events from device - drop iap_data_collected_from_device += 1;
} }
else
{
// Too many events from device - drop
}
// If we are not sending data to the host then initiate it // If we are not sending data to the host then initiate it (ONLY IF GOT WHOLE MESSAGE)
if (!iap_waiting_on_send_to_host) if (!iap_waiting_on_send_to_host && (iap_data_collected_from_device == iap_expecting_data_length))
{ {
// Set first element of buffer to length i.e. iap_to_host_buffer_being_collected[0] = iap_data_collected_from_device; // Set first element of buffer to length i.e. iap_to_host_buffer_being_collected[0] = iap_data_collected_from_device;
write_via_xc_ptr(iap_to_host_buffer_being_collected, iap_data_collected_from_device); write_via_xc_ptr(iap_to_host_buffer_being_collected, iap_data_collected_from_device);
swap(iap_to_host_buffer_being_collected, iap_to_host_buffer_being_sent); swap(iap_to_host_buffer_being_collected, iap_to_host_buffer_being_sent);
// Signal other side to swap // Signal other side to swap
XUD_SetReady_In(iap_to_host_int_usb_ep, 0, zero_buffer, 0); XUD_SetReady_In(iap_to_host_int_usb_ep, 0, zero_buffer, 0);
XUD_SetReady_In(iap_to_host_usb_ep, 0, iap_to_host_buffer_being_sent+4, iap_data_collected_from_device); XUD_SetReady_In(iap_to_host_usb_ep, 0, iap_to_host_buffer_being_sent+4, iap_data_collected_from_device);
iap_data_collected_from_device = 0; iap_data_collected_from_device = 0;
iap_waiting_on_send_to_host = 1; iap_waiting_on_send_to_host = 1;
iap_expecting_length = 1;
}
} }
} }
break; break;