Add active polling on UART buffer and bigger USB buffers

This commit is contained in:
Raphael Coeffic
2021-11-21 11:18:35 +01:00
committed by Raphael Coeffic
parent 1fe4876786
commit aa7b0143bd
4 changed files with 52 additions and 36 deletions
@@ -151,6 +151,21 @@ uint16_t usbWraps = 0;
uint16_t charsWritten = 0;
uint16_t usbTxErrors = 0;
// return the bytes free in the circular buffer
uint32_t usbSerialFreeSpace()
{
// functionally equivalent to:
//
// (APP_Rx_ptr_out > APP_Rx_ptr_in ? APP_Rx_ptr_out - APP_Rx_ptr_in :
// APP_RX_DATA_SIZE - APP_Rx_ptr_in + APP_Rx_ptr_in)
//
// but without the impact of the condition check.
return ((APP_Rx_ptr_out - APP_Rx_ptr_in) +
(-((int)(APP_Rx_ptr_out <= APP_Rx_ptr_in)) & APP_RX_DATA_SIZE)) -
1;
}
void usbSerialPutc(uint8_t c)
{
/*
@@ -172,14 +187,6 @@ void usbSerialPutc(uint8_t c)
txDataLen -= APP_RX_DATA_SIZE;
}
// buffer is too full, skip this write
if (txDataLen > (APP_RX_DATA_SIZE - CDC_DATA_MAX_PACKET_SIZE)) {
usbTxErrors++;
return;
}
++charsWritten;
/*
APP_Rx_Buffer and associated variables must be modified
atomically, because they are used from the interrupt