+ /* Check if the receive buffer flush period has expired */
+ uint16_t BufferCount = RingBuffer_GetCount(&USARTtoUSB_Buffer);
+ if (!(--FlushPeriodRemaining) || (BufferCount > 200))
+ {
+ FlushPeriodRemaining = RECEIVE_BUFFER_FLUSH_MS;
+
+ /* Start RX LED indicator pulse */
+ if (BufferCount)
+ {
+ LEDs_TurnOnLEDs(LEDMASK_RX);
+ PulseMSRemaining.RxLEDPulse = TX_RX_LED_PULSE_MS;
+ }
+
+ /* Echo bytes from the target to the host via the virtual serial port */
+ while (BufferCount--)
+ {
+ /* Try to send the next byte of data to the host, abort if there is an error without dequeuing */
+ if (CDC_Device_SendByte(&VirtualSerial_CDC_Interface,
+ RingBuffer_Peek(&USARTtoUSB_Buffer)) != ENDPOINT_READYWAIT_NoError)
+ {
+ break;
+ }
+
+ /* Dequeue the already sent byte from the buffer now we have confirmed that no transmission error occurred */
+ RingBuffer_Remove(&USARTtoUSB_Buffer);
+ }
+ }