mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-03-15 07:29:15 +01:00
com: track dropped bytes on rx for usart and usb com
This commit is contained in:
parent
2040645171
commit
b858cf387e
@ -63,6 +63,8 @@ struct pios_usart_dev {
|
||||
uint32_t rx_in_context;
|
||||
pios_com_callback tx_out_cb;
|
||||
uint32_t tx_out_context;
|
||||
|
||||
uint32_t rx_dropped;
|
||||
};
|
||||
|
||||
static bool PIOS_USART_validate(struct pios_usart_dev * usart_dev)
|
||||
@ -285,7 +287,12 @@ static void PIOS_USART_generic_irq_handler(uint32_t usart_id)
|
||||
if (sr & USART_SR_RXNE) {
|
||||
uint8_t byte = dr;
|
||||
if (usart_dev->rx_in_cb) {
|
||||
(void) (usart_dev->rx_in_cb)(usart_dev->rx_in_context, &byte, 1, NULL, &rx_need_yield);
|
||||
uint16_t rc;
|
||||
rc = (usart_dev->rx_in_cb)(usart_dev->rx_in_context, &byte, 1, NULL, &rx_need_yield);
|
||||
if (rc < 1) {
|
||||
/* Lost bytes on rx */
|
||||
usart_dev->rx_dropped += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,6 +81,8 @@ struct pios_usb_com_dev {
|
||||
|
||||
uint8_t rx_packet_buffer[PIOS_USB_COM_DATA_LENGTH + 2];
|
||||
uint8_t tx_packet_buffer[PIOS_USB_COM_DATA_LENGTH + 2];
|
||||
|
||||
uint32_t rx_dropped;
|
||||
};
|
||||
|
||||
static bool PIOS_USB_COM_validate(struct pios_usb_com_dev * usb_com_dev)
|
||||
@ -479,12 +481,18 @@ static void PIOS_USB_COM_CDC_DATA_EP_OUT_Callback(void)
|
||||
|
||||
uint16_t headroom;
|
||||
bool need_yield = false;
|
||||
(usb_com_dev->rx_in_cb)(usb_com_dev->rx_in_context,
|
||||
uint16_t rc;
|
||||
rc = (usb_com_dev->rx_in_cb)(usb_com_dev->rx_in_context,
|
||||
usb_com_dev->rx_packet_buffer,
|
||||
DataLength,
|
||||
&headroom,
|
||||
&need_yield);
|
||||
|
||||
if (rc < DataLength) {
|
||||
/* Lost bytes on rx */
|
||||
usb_com_dev->rx_dropped += (DataLength - rc);
|
||||
}
|
||||
|
||||
if (headroom >= sizeof(usb_com_dev->rx_packet_buffer)) {
|
||||
/* We have room for a maximum length message */
|
||||
SetEPRxStatus(usb_com_dev->cfg->data_rx_ep, EP_RX_VALID);
|
||||
|
Loading…
x
Reference in New Issue
Block a user