aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2013-01-17 18:08:39 -0500
committerMarti Bolivar <mbolivar@leaflabs.com>2013-01-17 18:08:39 -0500
commitafb4199070e464c317b86741e107692120e05097 (patch)
treec57eda4542c0bb85f9354e877c0f159dd34fce6f /libmaple
parent419a6796c2d444762e2ae5b7ae8b846690add839 (diff)
downloadlibrambutan-afb4199070e464c317b86741e107692120e05097.tar.gz
librambutan-afb4199070e464c317b86741e107692120e05097.zip
usb_cdcacm.c: Fixups for usb_cdcacm_tx().
- Check if we're transmitting (instead of how many bytes are left untransmitted) before bailing, in case we're transmitting a zero-length packet. - Set transmitting=1 before setting the endpoint valid to avoid races with the USB interrupt. - Eliminate some duplicated code. Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Diffstat (limited to 'libmaple')
-rw-r--r--libmaple/usb/stm32f1/usb_cdcacm.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/libmaple/usb/stm32f1/usb_cdcacm.c b/libmaple/usb/stm32f1/usb_cdcacm.c
index 3f3a493..ecb9397 100644
--- a/libmaple/usb/stm32f1/usb_cdcacm.c
+++ b/libmaple/usb/stm32f1/usb_cdcacm.c
@@ -394,7 +394,7 @@ void usb_cdcacm_putc(char ch) {
* buffer, and returns the number of bytes copied. */
uint32 usb_cdcacm_tx(const uint8* buf, uint32 len) {
/* Last transmission hasn't finished, so abort. */
- if (n_unsent_bytes) {
+ if (usb_cdcacm_is_transmitting()) {
return 0;
}
@@ -406,17 +406,14 @@ uint32 usb_cdcacm_tx(const uint8* buf, uint32 len) {
/* Queue bytes for sending. */
if (len) {
usb_copy_to_pma(buf, len, USB_CDCACM_TX_ADDR);
- usb_set_ep_tx_count(USB_CDCACM_TX_ENDP, len);
- n_unsent_bytes = len;
- usb_set_ep_tx_stat(USB_CDCACM_TX_ENDP, USB_EP_STAT_TX_VALID);
- transmitting = 1;
- } else {
- usb_set_ep_tx_count(USB_CDCACM_TX_ENDP, 0);
- usb_set_ep_tx_stat(USB_CDCACM_TX_ENDP, USB_EP_STAT_TX_VALID);
- // actually block here waiting for interrupt, even though we sent 0 bytes
- n_unsent_bytes = 0;
- transmitting = 1;
}
+ // We still need to wait for the interrupt, even if we're sending
+ // zero bytes. (Sending zero-size packets is useful for flushing
+ // host-side buffers.)
+ usb_set_ep_tx_count(USB_CDCACM_TX_ENDP, len);
+ n_unsent_bytes = len;
+ transmitting = 1;
+ usb_set_ep_tx_stat(USB_CDCACM_TX_ENDP, USB_EP_STAT_TX_VALID);
return len;
}