From efd9e7a6dfbeedb4dd913d27c7ed7cc0a83d1a20 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 2 Oct 2018 21:38:58 -0400 Subject: [PATCH] usb_cdc: Try to read new data before processing data blocks Call usb_read_bulk_out() before calling command_find_and_dispatch() as this optimizes the common case where each usb packet contains a single new message block. Signed-off-by: Kevin O'Connor --- src/generic/usb_cdc.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/generic/usb_cdc.c b/src/generic/usb_cdc.c index 96bd01c6..7f6b2f34 100644 --- a/src/generic/usb_cdc.c +++ b/src/generic/usb_cdc.c @@ -92,8 +92,19 @@ usb_bulk_out_task(void) { if (!sched_check_wake(&usb_bulk_out_wake)) return; - // Process any existing message blocks + // Read data uint_fast8_t rpos = receive_pos, pop_count; + if (rpos + USB_CDC_EP_BULK_OUT_SIZE <= sizeof(receive_buf)) { + int_fast8_t ret = usb_read_bulk_out( + &receive_buf[rpos], USB_CDC_EP_BULK_OUT_SIZE); + if (ret > 0) { + rpos += ret; + usb_notify_bulk_out(); + } + } else { + usb_notify_bulk_out(); + } + // Process a message block int_fast8_t ret = command_find_and_dispatch(receive_buf, rpos, &pop_count); if (ret) { // Move buffer @@ -104,14 +115,6 @@ usb_bulk_out_task(void) } rpos = needcopy; } - // Read more data - if (rpos + USB_CDC_EP_BULK_OUT_SIZE <= sizeof(receive_buf)) { - ret = usb_read_bulk_out(&receive_buf[rpos], USB_CDC_EP_BULK_OUT_SIZE); - if (ret > 0) { - rpos += ret; - usb_notify_bulk_out(); - } - } receive_pos = rpos; } DECL_TASK(usb_bulk_out_task);