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>
This commit is contained in:
Kevin O'Connor 2018-10-02 21:38:58 -04:00
parent fe98dd3585
commit efd9e7a6df
1 changed files with 12 additions and 9 deletions

View File

@ -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);