diff options
author | Dean Camera <dean@fourwalledcubicle.com> | 2009-04-17 04:10:30 +0000 |
---|---|---|
committer | Dean Camera <dean@fourwalledcubicle.com> | 2009-04-17 04:10:30 +0000 |
commit | 6380d057f8911f5d09bdffff4220aa9602df49e2 (patch) | |
tree | 12456118c9c91c9521abfe3475d9d025d56aa38b /Demos/Device/CDC/CDC.c | |
parent | 11bb2f21720c2af4b29732ca128963869e5c512c (diff) | |
download | lufa-6380d057f8911f5d09bdffff4220aa9602df49e2.tar.gz lufa-6380d057f8911f5d09bdffff4220aa9602df49e2.tar.bz2 lufa-6380d057f8911f5d09bdffff4220aa9602df49e2.zip |
Fixed CDC and USBtoSerial demos freezing where buffers were full while still transmitting or receiving (thanks to Peter Hand).
Diffstat (limited to 'Demos/Device/CDC/CDC.c')
-rw-r--r-- | Demos/Device/CDC/CDC.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/Demos/Device/CDC/CDC.c b/Demos/Device/CDC/CDC.c index 3dc624057..29bc00373 100644 --- a/Demos/Device/CDC/CDC.c +++ b/Demos/Device/CDC/CDC.c @@ -300,14 +300,22 @@ TASK(CDC_Task) /* Write the String to the Endpoint */
Endpoint_Write_Stream_LE(ReportString, strlen(ReportString));
+ /* Remember if the packet to send completely fills the endpoint */
+ bool IsFull = (Endpoint_BytesInEndpoint() == CDC_TXRX_EPSIZE);
+
/* Finalize the stream transfer to send the last packet */
Endpoint_ClearIN();
- /* Wait until the endpoint is ready for another packet */
- while (!(Endpoint_IsINReady()));
-
- /* Send an empty packet to ensure that the host does not buffer data sent to it */
- Endpoint_ClearIN();
+ /* If the last packet filled the endpoint, send an empty packet to release the buffer on
+ * the receiver (otherwise all data will be cached until a non-full packet is received) */
+ if (IsFull)
+ {
+ /* Wait until the endpoint is ready for another packet */
+ while (!(Endpoint_IsINReady()));
+
+ /* Send an empty packet to ensure that the host does not buffer data sent to it */
+ Endpoint_ClearIN();
+ }
}
/* Select the Serial Rx Endpoint */
|