From 62e0de03b5513cd0a7890fa6dc635ac4a7f5642c Mon Sep 17 00:00:00 2001 From: Steve Evans Date: Tue, 26 Jul 2022 03:01:29 +0100 Subject: [PATCH] Backup inuntended change impacting F7 --- src/main/vcp_hal/usbd_cdc_interface.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/vcp_hal/usbd_cdc_interface.c b/src/main/vcp_hal/usbd_cdc_interface.c index f1577643b1..b44576f8a1 100644 --- a/src/main/vcp_hal/usbd_cdc_interface.c +++ b/src/main/vcp_hal/usbd_cdc_interface.c @@ -409,11 +409,17 @@ uint32_t CDC_Receive_BytesAvailable(void) uint32_t CDC_Send_FreeBytes(void) { - // return the bytes free in the circular buffer + /* + return the bytes free in the circular buffer + + 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. + */ uint32_t freeBytes; ATOMIC_BLOCK(NVIC_BUILD_PRIORITY(6, 0)) { - freeBytes = APP_RX_DATA_SIZE - rxAvailable; + freeBytes = ((UserTxBufPtrOut - UserTxBufPtrIn) + (-((int)(UserTxBufPtrOut <= UserTxBufPtrIn)) & APP_TX_DATA_SIZE)) - 1; } return freeBytes;