forked from mfulz_github/qmk_firmware
Fixed CDC and USBtoSerial demos freezing where buffers were full while still transmitting or receiving (thanks to Peter Hand).
This commit is contained in:
parent
11bb2f2172
commit
6380d057f8
|
@ -300,15 +300,23 @@ TASK(CDC_Task)
|
||||||
/* Write the String to the Endpoint */
|
/* Write the String to the Endpoint */
|
||||||
Endpoint_Write_Stream_LE(ReportString, strlen(ReportString));
|
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 */
|
/* Finalize the stream transfer to send the last packet */
|
||||||
Endpoint_ClearIN();
|
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 */
|
/* Wait until the endpoint is ready for another packet */
|
||||||
while (!(Endpoint_IsINReady()));
|
while (!(Endpoint_IsINReady()));
|
||||||
|
|
||||||
/* Send an empty packet to ensure that the host does not buffer data sent to it */
|
/* Send an empty packet to ensure that the host does not buffer data sent to it */
|
||||||
Endpoint_ClearIN();
|
Endpoint_ClearIN();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Select the Serial Rx Endpoint */
|
/* Select the Serial Rx Endpoint */
|
||||||
Endpoint_SelectEndpoint(CDC_RX_EPNUM);
|
Endpoint_SelectEndpoint(CDC_RX_EPNUM);
|
||||||
|
|
|
@ -246,19 +246,20 @@ TASK(CDC_Task)
|
||||||
|
|
||||||
if (Endpoint_IsOUTReceived())
|
if (Endpoint_IsOUTReceived())
|
||||||
{
|
{
|
||||||
/* Read the received data endpoint into the transmission buffer */
|
/* Read the bytes in from the endpoint into the buffer while space is available */
|
||||||
while (Endpoint_BytesInEndpoint())
|
while (Endpoint_BytesInEndpoint() && (BUFF_STATICSIZE - Rx_Buffer.Elements))
|
||||||
{
|
{
|
||||||
/* Wait until the buffer has space for a new character */
|
|
||||||
while (!((BUFF_STATICSIZE - Rx_Buffer.Elements)));
|
|
||||||
|
|
||||||
/* Store each character from the endpoint */
|
/* Store each character from the endpoint */
|
||||||
Buffer_StoreElement(&Rx_Buffer, Endpoint_Read_Byte());
|
Buffer_StoreElement(&Rx_Buffer, Endpoint_Read_Byte());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check to see if all bytes in the current packet have been read */
|
||||||
|
if (!(Endpoint_BytesInEndpoint()))
|
||||||
|
{
|
||||||
/* Clear the endpoint buffer */
|
/* Clear the endpoint buffer */
|
||||||
Endpoint_ClearOUT();
|
Endpoint_ClearOUT();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Check if Rx buffer contains data */
|
/* Check if Rx buffer contains data */
|
||||||
if (Rx_Buffer.Elements)
|
if (Rx_Buffer.Elements)
|
||||||
|
@ -280,13 +281,23 @@ TASK(CDC_Task)
|
||||||
/* Wait until Serial Tx Endpoint Ready for Read/Write */
|
/* Wait until Serial Tx Endpoint Ready for Read/Write */
|
||||||
while (!(Endpoint_IsReadWriteAllowed()));
|
while (!(Endpoint_IsReadWriteAllowed()));
|
||||||
|
|
||||||
/* Write the transmission buffer contents to the received data endpoint */
|
/* Write the bytes from the buffer to the endpoint while space is available */
|
||||||
while (Tx_Buffer.Elements && (Endpoint_BytesInEndpoint() < CDC_TXRX_EPSIZE))
|
while (Tx_Buffer.Elements && (Endpoint_BytesInEndpoint() < CDC_TXRX_EPSIZE))
|
||||||
|
{
|
||||||
|
/* Write each byte retreived from the buffer to the endpoint */
|
||||||
Endpoint_Write_Byte(Buffer_GetElement(&Tx_Buffer));
|
Endpoint_Write_Byte(Buffer_GetElement(&Tx_Buffer));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remember if the packet to send completely fills the endpoint */
|
||||||
|
bool IsFull = (Endpoint_BytesInEndpoint() == CDC_TXRX_EPSIZE);
|
||||||
|
|
||||||
/* Send the data */
|
/* Send the data */
|
||||||
Endpoint_ClearIN();
|
Endpoint_ClearIN();
|
||||||
|
|
||||||
|
/* If no more data to send and 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 && !(Tx_Buffer.Elements))
|
||||||
|
{
|
||||||
/* Wait until Serial Tx Endpoint Ready for Read/Write */
|
/* Wait until Serial Tx Endpoint Ready for Read/Write */
|
||||||
while (!(Endpoint_IsReadWriteAllowed()));
|
while (!(Endpoint_IsReadWriteAllowed()));
|
||||||
|
|
||||||
|
@ -294,6 +305,7 @@ TASK(CDC_Task)
|
||||||
Endpoint_ClearIN();
|
Endpoint_ClearIN();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ISR to handle the USART transmit complete interrupt, fired each time the USART has sent a character. This reloads the USART
|
/** ISR to handle the USART transmit complete interrupt, fired each time the USART has sent a character. This reloads the USART
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
* - Removed old endpoint and pipe aliased read/write/discard routines which did not have an explicit endian specifier for clarity
|
* - Removed old endpoint and pipe aliased read/write/discard routines which did not have an explicit endian specifier for clarity
|
||||||
* - Removed the ButtLoadTag.h header file, as no one used for its intended purpose anyway
|
* - Removed the ButtLoadTag.h header file, as no one used for its intended purpose anyway
|
||||||
* - Renamed the main Drivers/AT90USBXXX directory to Drivers/Peripheral, renamed the Serial_Stream driver to SerialStream
|
* - Renamed the main Drivers/AT90USBXXX directory to Drivers/Peripheral, renamed the Serial_Stream driver to SerialStream
|
||||||
|
* - Fixed CDC and USBtoSerial demos freezing where buffers were full while still transmitting or receiving (thanks to Peter Hand)
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* \section Sec_ChangeLog090401 Version 090401
|
* \section Sec_ChangeLog090401 Version 090401
|
||||||
|
|
Loading…
Reference in New Issue