diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2018-10-02 21:38:58 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2018-10-02 21:38:58 -0400 |
commit | efd9e7a6dfbeedb4dd913d27c7ed7cc0a83d1a20 (patch) | |
tree | b14e50b83dba3617d9cdf68b6c75af3fa5afbf94 /src | |
parent | fe98dd35852f03162fbfe6a3e29ca7815c4ccf19 (diff) | |
download | kutter-efd9e7a6dfbeedb4dd913d27c7ed7cc0a83d1a20.tar.gz kutter-efd9e7a6dfbeedb4dd913d27c7ed7cc0a83d1a20.tar.xz kutter-efd9e7a6dfbeedb4dd913d27c7ed7cc0a83d1a20.zip |
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 <kevin@koconnor.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/generic/usb_cdc.c | 21 |
1 files 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); |