aboutsummaryrefslogtreecommitdiffstats
path: root/src/generic/usb_cdc.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2018-10-02 21:38:58 -0400
committerKevin O'Connor <kevin@koconnor.net>2018-10-02 21:38:58 -0400
commitefd9e7a6dfbeedb4dd913d27c7ed7cc0a83d1a20 (patch)
treeb14e50b83dba3617d9cdf68b6c75af3fa5afbf94 /src/generic/usb_cdc.c
parentfe98dd35852f03162fbfe6a3e29ca7815c4ccf19 (diff)
downloadkutter-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/generic/usb_cdc.c')
-rw-r--r--src/generic/usb_cdc.c21
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);