aboutsummaryrefslogtreecommitdiffstats
path: root/Projects
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2010-11-03 11:24:34 +0000
committerDean Camera <dean@fourwalledcubicle.com>2010-11-03 11:24:34 +0000
commit85cf2027373cfbe6f6fb257a84a59df0d74f3e1a (patch)
treedf007db035b4ccc4a558ed8eb01cee00fb3f974f /Projects
parent8f9b5ae00df6654490245d29d1fd703a90be382d (diff)
downloadlufa-85cf2027373cfbe6f6fb257a84a59df0d74f3e1a.tar.gz
lufa-85cf2027373cfbe6f6fb257a84a59df0d74f3e1a.tar.bz2
lufa-85cf2027373cfbe6f6fb257a84a59df0d74f3e1a.zip
Fixed USBtoSerial and XPLAINBridge demos discarding data from the PC if the send buffer becomes full.
Diffstat (limited to 'Projects')
-rw-r--r--Projects/USBtoSerial/USBtoSerial.c14
-rw-r--r--Projects/XPLAINBridge/XPLAINBridge.c14
2 files changed, 20 insertions, 8 deletions
diff --git a/Projects/USBtoSerial/USBtoSerial.c b/Projects/USBtoSerial/USBtoSerial.c
index 3f06acde9..c26667df9 100644
--- a/Projects/USBtoSerial/USBtoSerial.c
+++ b/Projects/USBtoSerial/USBtoSerial.c
@@ -81,15 +81,21 @@ int main(void)
for (;;)
{
- /* Read bytes from the USB OUT endpoint into the USART transmit buffer */
- int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
- if (!(ReceivedByte < 0) && !(RingBuffer_IsFull(&USBtoUSART_Buffer)))
- RingBuffer_Insert(&USBtoUSART_Buffer, ReceivedByte);
+ /* Only try to read in bytes from the CDC interface if the transmit buffer is not full */
+ if (!(RingBuffer_IsFull(&USBtoUSART_Buffer)))
+ {
+ int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
+ /* Read bytes from the USB OUT endpoint into the USART transmit buffer */
+ if (!(ReceivedByte < 0))
+ RingBuffer_Insert(&USBtoUSART_Buffer, ReceivedByte);
+ }
+
/* Check if the UART receive buffer flush timer has expired or the buffer is nearly full */
RingBuff_Count_t BufferCount = RingBuffer_GetCount(&USARTtoUSB_Buffer);
if ((TIFR0 & (1 << TOV0)) || (BufferCount > 200))
{
+ /* Clear flush timer expiry flag */
TIFR0 |= (1 << TOV0);
/* Read bytes from the USART receive buffer into the USB IN endpoint */
diff --git a/Projects/XPLAINBridge/XPLAINBridge.c b/Projects/XPLAINBridge/XPLAINBridge.c
index 8cd1b2dd2..d645ebead 100644
--- a/Projects/XPLAINBridge/XPLAINBridge.c
+++ b/Projects/XPLAINBridge/XPLAINBridge.c
@@ -119,15 +119,21 @@ void UARTBridge_Task(void)
if (USB_DeviceState != DEVICE_STATE_Configured)
return;
- /* Read bytes from the USB OUT endpoint into the UART transmit buffer */
- int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
- if (!(ReceivedByte < 0) && !(RingBuffer_IsFull(&USBtoUART_Buffer)))
- RingBuffer_Insert(&USBtoUART_Buffer, ReceivedByte);
+ /* Only try to read in bytes from the CDC interface if the transmit buffer is not full */
+ if (!(RingBuffer_IsFull(&USBtoUART_Buffer)))
+ {
+ int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
+ /* Read bytes from the USB OUT endpoint into the UART transmit buffer */
+ if (!(ReceivedByte < 0))
+ RingBuffer_Insert(&USBtoUART_Buffer, ReceivedByte);
+ }
+
/* Check if the UART receive buffer flush timer has expired or buffer is nearly full */
RingBuff_Count_t BufferCount = RingBuffer_GetCount(&UARTtoUSB_Buffer);
if ((TIFR0 & (1 << TOV0)) || (BufferCount > 200))
{
+ /* Clear flush timer expiry flag */
TIFR0 |= (1 << TOV0);
/* Read bytes from the UART receive buffer into the USB IN endpoint */