mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-13 03:20:00 +03:00
Fix CDC_Send_FreeBytes
This commit is contained in:
parent
4339e4ffd6
commit
b6e2790f15
1 changed files with 6 additions and 12 deletions
|
@ -44,7 +44,7 @@ __IO uint32_t bDeviceState = UNCONNECTED; /* USB device status */
|
|||
|
||||
/* This is the buffer for data received from the MCU to APP (i.e. MCU TX, APP RX) */
|
||||
extern uint8_t APP_Rx_Buffer[];
|
||||
extern uint32_t APP_Rx_ptr_out;
|
||||
extern volatile uint32_t APP_Rx_ptr_out;
|
||||
/* Increment this buffer position or roll it back to
|
||||
start address when writing received data
|
||||
in the buffer APP_Rx_Buffer. */
|
||||
|
@ -190,12 +190,8 @@ uint32_t CDC_Send_FreeBytes(void)
|
|||
{
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
return ((APP_Rx_ptr_out - APP_Rx_ptr_in) + (-((int)(APP_Rx_ptr_out <= APP_Rx_ptr_in)) & APP_RX_DATA_SIZE)) - 1;
|
||||
return (APP_Rx_ptr_out > APP_Rx_ptr_in ? APP_Rx_ptr_out - APP_Rx_ptr_in : APP_RX_DATA_SIZE + APP_Rx_ptr_out - APP_Rx_ptr_in);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -212,15 +208,13 @@ static uint16_t VCP_DataTx(const uint8_t* Buf, uint32_t Len)
|
|||
could just check for: USB_CDC_ZLP, but better to be safe
|
||||
and wait for any existing transmission to complete.
|
||||
*/
|
||||
while (USB_Tx_State != 0);
|
||||
|
||||
for (uint32_t i = 0; i < Len; i++) {
|
||||
APP_Rx_Buffer[APP_Rx_ptr_in] = Buf[i];
|
||||
APP_Rx_ptr_in = (APP_Rx_ptr_in + 1) % APP_RX_DATA_SIZE;
|
||||
|
||||
while (CDC_Send_FreeBytes() == 0) {
|
||||
while ((APP_Rx_ptr_in + 1) % APP_RX_DATA_SIZE == APP_Rx_ptr_out || APP_Rx_ptr_out == APP_RX_DATA_SIZE || USB_Tx_State != 0) {
|
||||
delay(1);
|
||||
}
|
||||
|
||||
APP_Rx_Buffer[APP_Rx_ptr_in] = Buf[i];
|
||||
APP_Rx_ptr_in = (APP_Rx_ptr_in + 1) % APP_RX_DATA_SIZE;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue