- /* Read bytes from the USART receive buffer into the USB IN endpoint */
- while (USARTtoUSB_Buffer.Count)
- CDC_Device_SendByte(&VirtualSerial_CDC_Interface, RingBuffer_Remove(&USARTtoUSB_Buffer));
-
- /* Load bytes from the USART transmit buffer into the USART */
- while (USBtoUSART_Buffer.Count)
+ /* 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 */
+ while (BufferCount--)
+ CDC_Device_SendByte(&VirtualSerial_CDC_Interface, RingBuffer_Remove(&USARTtoUSB_Buffer));
+ }
+
+ /* Load the next byte from the USART transmit buffer into the USART */
+ if (!(RingBuffer_IsEmpty(&USBtoUSART_Buffer)))