summaryrefslogtreecommitdiff
path: root/src/class/cdc/cdc_device.c
diff options
context:
space:
mode:
authorReinhard Panhuber <[email protected]>2021-04-03 09:50:08 +0200
committerReinhard Panhuber <[email protected]>2021-04-03 09:50:08 +0200
commita1efd416491fd2deecea46cd466e31b4a02b9734 (patch)
treedfda074b32926050da8460d79b36c34e2e696d42 /src/class/cdc/cdc_device.c
parent9b2ddd9cc6401b80350179d26e842557f9b60aaf (diff)
parentab4d30fd6bca02c73eb9b4ff82db0b2b0f403344 (diff)
Merge remote-tracking branch 'upstream/master' into edpt_ISO_xfer
Diffstat (limited to 'src/class/cdc/cdc_device.c')
-rw-r--r--src/class/cdc/cdc_device.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c
index 18919c486..0a7691916 100644
--- a/src/class/cdc/cdc_device.c
+++ b/src/class/cdc/cdc_device.c
@@ -95,7 +95,8 @@ static void _prep_out_transaction (cdcd_interface_t* p_cdc)
// fifo can be changed before endpoint is claimed
available = tu_fifo_remaining(&p_cdc->rx_ff);
- if ( available >= sizeof(p_cdc->epout_buf) ) {
+ if ( available >= sizeof(p_cdc->epout_buf) )
+ {
usbd_edpt_xfer(rhport, p_cdc->ep_out, p_cdc->epout_buf, sizeof(p_cdc->epout_buf));
}else
{
@@ -432,25 +433,27 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
// Received new data
if ( ep_addr == p_cdc->ep_out )
{
- // TODO search for wanted char first for better performance
- for(uint32_t i=0; i<xferred_bytes; i++)
+ tu_fifo_write_n(&p_cdc->rx_ff, &p_cdc->epout_buf, xferred_bytes);
+
+ // Check for wanted char and invoke callback if needed
+ if ( tud_cdc_rx_wanted_cb && (((signed char) p_cdc->wanted_char) != -1) )
{
- tu_fifo_write(&p_cdc->rx_ff, &p_cdc->epout_buf[i]);
-
- // Check for wanted char and invoke callback if needed
- if ( tud_cdc_rx_wanted_cb && ( ((signed char) p_cdc->wanted_char) != -1 ) && ( p_cdc->wanted_char == p_cdc->epout_buf[i] ) )
+ for ( uint32_t i = 0; i < xferred_bytes; i++ )
{
- tud_cdc_rx_wanted_cb(itf, p_cdc->wanted_char);
+ if ( (p_cdc->wanted_char == p_cdc->epout_buf[i]) && !tu_fifo_empty(&p_cdc->rx_ff) )
+ {
+ tud_cdc_rx_wanted_cb(itf, p_cdc->wanted_char);
+ }
}
}
-
+
// invoke receive callback (if there is still data)
- if (tud_cdc_rx_cb && tu_fifo_count(&p_cdc->rx_ff) ) tud_cdc_rx_cb(itf);
-
+ if (tud_cdc_rx_cb && !tu_fifo_empty(&p_cdc->rx_ff) ) tud_cdc_rx_cb(itf);
+
// prepare for OUT transaction
_prep_out_transaction(p_cdc);
}
-
+
// Data sent to host, we continue to fetch from tx fifo to send.
// Note: This will cause incorrect baudrate set in line coding.
// Though maybe the baudrate is not really important !!!