diff --git a/flight/Bootloaders/CopterControl/main.c b/flight/Bootloaders/CopterControl/main.c index aa375a49c..c1def4a46 100644 --- a/flight/Bootloaders/CopterControl/main.c +++ b/flight/Bootloaders/CopterControl/main.c @@ -198,10 +198,8 @@ uint32_t LedPWM(uint32_t pwm_period, uint32_t pwm_sweep_steps, uint32_t count) { } uint8_t processRX() { - while (PIOS_COM_ReceiveBufferUsed(PIOS_COM_TELEM_USB) >= 63) { - if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB, mReceive_Buffer, 63, 0) == 63) { - processComand(mReceive_Buffer); - } + if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB, mReceive_Buffer, 63, 0) == 63) { + processComand(mReceive_Buffer); } return TRUE; } diff --git a/flight/Bootloaders/OpenPilot/main.c b/flight/Bootloaders/OpenPilot/main.c index 8e15952ea..48056cff6 100644 --- a/flight/Bootloaders/OpenPilot/main.c +++ b/flight/Bootloaders/OpenPilot/main.c @@ -249,10 +249,8 @@ uint32_t LedPWM(uint32_t pwm_period, uint32_t pwm_sweep_steps, uint32_t count) { uint8_t processRX() { if (ProgPort == Usb) { - while (PIOS_COM_ReceiveBufferUsed(PIOS_COM_TELEM_USB) >= 63) { - if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB, mReceive_Buffer, 63, 0) == 63) { - processComand(mReceive_Buffer); - } + if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB, mReceive_Buffer, 63, 0) == 63) { + processComand(mReceive_Buffer); } } else if (ProgPort == Serial) { @@ -277,15 +275,12 @@ void SSP_CallBack(uint8_t *buf, uint16_t len) { fifoBuf_putData(&ssp_buffer, buf, len); } int16_t SSP_SerialRead(void) { - if (PIOS_COM_ReceiveBufferUsed(PIOS_COM_TELEM_RF) > 0) { - uint8_t byte; - if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_RF, &byte, 1, 0) == 1) { - return byte; - } else { - return -1; - } - } else + uint8_t byte; + if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_RF, &byte, 1, 0) == 1) { + return byte; + } else { return -1; + } } void SSP_SerialWrite(uint8_t value) { PIOS_COM_SendChar(PIOS_COM_TELEM_RF, value); diff --git a/flight/Bootloaders/PipXtreme/main.c b/flight/Bootloaders/PipXtreme/main.c index 3f1c4bd54..f09881d42 100644 --- a/flight/Bootloaders/PipXtreme/main.c +++ b/flight/Bootloaders/PipXtreme/main.c @@ -204,10 +204,8 @@ uint32_t LedPWM(uint32_t pwm_period, uint32_t pwm_sweep_steps, uint32_t count) { } uint8_t processRX() { - while (PIOS_COM_ReceiveBufferUsed(PIOS_COM_TELEM_USB) >= 63) { - if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB, mReceive_Buffer, 63, 0) == 63) { - processComand(mReceive_Buffer); - } + if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB, mReceive_Buffer, 63, 0) == 63) { + processComand(mReceive_Buffer); } return TRUE; } diff --git a/flight/PiOS/Common/pios_com.c b/flight/PiOS/Common/pios_com.c index e5440d065..992167bad 100644 --- a/flight/PiOS/Common/pios_com.c +++ b/flight/PiOS/Common/pios_com.c @@ -511,24 +511,6 @@ uint16_t PIOS_COM_ReceiveBuffer(uint32_t com_id, uint8_t * buf, uint16_t buf_len return (bytes_from_fifo); } -/** -* Get the number of bytes waiting in the buffer -* \param[in] port COM port -* \return Number of bytes used in buffer -*/ -int32_t PIOS_COM_ReceiveBufferUsed(uint32_t com_id) -{ - struct pios_com_dev * com_dev = (struct pios_com_dev *)com_id; - - if (!PIOS_COM_validate(com_dev)) { - /* Undefined COM port for this board (see pios_board.c) */ - PIOS_Assert(0); - } - - PIOS_Assert(com_dev->has_rx); - return (fifoBuf_getUsed(&com_dev->rx)); -} - #endif /** diff --git a/flight/PiOS/inc/pios_com.h b/flight/PiOS/inc/pios_com.h index cbee33735..1bda392f6 100644 --- a/flight/PiOS/inc/pios_com.h +++ b/flight/PiOS/inc/pios_com.h @@ -55,7 +55,6 @@ extern int32_t PIOS_COM_SendString(uint32_t com_id, const char *str); extern int32_t PIOS_COM_SendFormattedStringNonBlocking(uint32_t com_id, const char *format, ...); extern int32_t PIOS_COM_SendFormattedString(uint32_t com_id, const char *format, ...); extern uint16_t PIOS_COM_ReceiveBuffer(uint32_t com_id, uint8_t * buf, uint16_t buf_len, uint32_t timeout_ms); -extern int32_t PIOS_COM_ReceiveBufferUsed(uint32_t com_id); #endif /* PIOS_COM_H */ diff --git a/flight/PipXtreme/api_config.c b/flight/PipXtreme/api_config.c index 10587a6ee..5aa9fc6c0 100644 --- a/flight/PipXtreme/api_config.c +++ b/flight/PipXtreme/api_config.c @@ -792,13 +792,8 @@ void apiconfig_process(void) else if (apiconfig_usb_comms) { // we're using the USB for comms - keep the USART rx buffer empty - int32_t bytes = PIOS_COM_ReceiveBufferUsed(PIOS_COM_SERIAL); - while (bytes > 0) - { - uint8_t c; - PIOS_COM_ReceiveBuffer(PIOS_COM_SERIAL, &c, 1, 0); - bytes--; - } + uint8_t c; + while (PIOS_COM_ReceiveBuffer(PIOS_COM_SERIAL, &c, 1, 0) > 0); } apiconfig_previous_com_port = apiconfig_comm_port; // remember the current comm-port we are using @@ -808,20 +803,9 @@ void apiconfig_process(void) // fetch the data received via the comm-port // get the number of data bytes received down the comm-port - int32_t com_num = PIOS_COM_ReceiveBufferUsed(apiconfig_comm_port); + uint16_t buf_avail = sizeof(apiconfig_rx_buffer) - apiconfig_rx_buffer_wr; - // limit number of bytes we will get to how much space we have in our RX buffer - if (com_num > sizeof(apiconfig_rx_buffer) - apiconfig_rx_buffer_wr) - com_num = sizeof(apiconfig_rx_buffer) - apiconfig_rx_buffer_wr; - - - while (com_num > 0) - { // fetch a byte from the comm-port RX buffer and save it into our RX buffer - uint8_t c; - PIOS_COM_ReceiveBuffer(apiconfig_comm_port, &c, 1, 0); - apiconfig_rx_buffer[apiconfig_rx_buffer_wr++] = c; - com_num--; - } + PIOS_COM_ReceiveBuffer(apiconfig_comm_port, &(apiconfig_rx_buffer[apiconfig_rx_buffer_wr]), buf_avail, 0); apiconfig_processTx(); apiconfig_processRx(); diff --git a/flight/PipXtreme/transparent_comms.c b/flight/PipXtreme/transparent_comms.c index 20d78290b..dc5e0384a 100644 --- a/flight/PipXtreme/transparent_comms.c +++ b/flight/PipXtreme/transparent_comms.c @@ -89,13 +89,8 @@ void trans_process(void) else if (usb_comms) { // we're using the USB for comms - keep the USART rx buffer empty - int32_t bytes = PIOS_COM_ReceiveBufferUsed(PIOS_COM_SERIAL); - while (bytes > 0) - { - uint8_t c; - PIOS_COM_ReceiveBuffer(PIOS_COM_SERIAL, &c, 1, 0); - bytes--; - } + uint8_t c; + while (PIOS_COM_ReceiveBuffer(PIOS_COM_SERIAL, &c, 1, 0) > 0); } trans_previous_com_port = comm_port; // remember the current comm-port we are using @@ -112,9 +107,6 @@ void trans_process(void) // free space size in the RF packet handler tx buffer uint16_t ph_num = ph_putData_free(connection_index); - // get the number of data bytes received down the comm-port - int32_t com_num = PIOS_COM_ReceiveBufferUsed(comm_port); - // set the USART RTS handshaking line if (!usb_comms) { @@ -127,16 +119,12 @@ void trans_process(void) SERIAL_RTS_SET; // release the USART RTS line // limit number of bytes we will get to the size of the temp buffer - if (com_num > sizeof(trans_temp_buffer1)) - com_num = sizeof(trans_temp_buffer1); - - // limit number of bytes we will get to the size of the free space in the RF packet handler TX buffer - if (com_num > ph_num) - com_num = ph_num; + if (ph_num > sizeof(trans_temp_buffer1)) + ph_num = sizeof(trans_temp_buffer1); // copy data received down the comm-port into our temp buffer register uint16_t bytes_saved = 0; - bytes_saved = PIOS_COM_ReceiveBuffer(comm_port, trans_temp_buffer1, com_num, 0); + bytes_saved = PIOS_COM_ReceiveBuffer(comm_port, trans_temp_buffer1, ph_num, 0); // put the received comm-port data bytes into the RF packet handler TX buffer if (bytes_saved > 0) @@ -147,12 +135,8 @@ void trans_process(void) } else { // empty the comm-ports rx buffer - int32_t com_num = PIOS_COM_ReceiveBufferUsed(comm_port); - while (com_num > 0) { - uint8_t c; - PIOS_COM_ReceiveBuffer(comm_port, &c, 1, 0); - com_num--; - } + uint8_t c; + while (PIOS_COM_ReceiveBuffer(comm_port, &c, 1, 0) > 0); } // ********************