aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple
diff options
context:
space:
mode:
authorManuel Odendahl <wesen@ruinwesen.com>2013-01-17 17:41:02 +0100
committerManuel Odendahl <wesen@ruinwesen.com>2013-01-17 21:17:00 +0100
commitb1389732c350b2dcc4c158a149dcdc038a4b6537 (patch)
tree66b830cc39e08ae3d612f4906bef7e3a5b82c9b6 /libmaple
parent5e6c43a884b780e6f6b4bee5ded8e8d391b3bc94 (diff)
downloadlibrambutan-b1389732c350b2dcc4c158a149dcdc038a4b6537.tar.gz
librambutan-b1389732c350b2dcc4c158a149dcdc038a4b6537.zip
Handle sending 0 byte packets.
Added a flag to see if we are currently waiting on an interrupt to acknowledge the sending of the current IN packet. Added a method usb_cdcacm_is_transmitting() to check for that flag. Signed-off-by: Manuel Odendahl <wesen@ruinwesen.com>
Diffstat (limited to 'libmaple')
-rw-r--r--libmaple/include/libmaple/usb_cdcacm.h1
-rw-r--r--libmaple/usb/stm32f1/usb_cdcacm.c21
2 files changed, 16 insertions, 6 deletions
diff --git a/libmaple/include/libmaple/usb_cdcacm.h b/libmaple/include/libmaple/usb_cdcacm.h
index 5a2779e..5fe832c 100644
--- a/libmaple/include/libmaple/usb_cdcacm.h
+++ b/libmaple/include/libmaple/usb_cdcacm.h
@@ -127,6 +127,7 @@ uint32 usb_cdcacm_peek(uint8* buf, uint32 len);
uint32 usb_cdcacm_data_available(void); /* in RX buffer */
uint16 usb_cdcacm_get_pending(void);
+uint8 usb_cdcacm_is_transmitting(void);
uint8 usb_cdcacm_get_dtr(void);
uint8 usb_cdcacm_get_rts(void);
diff --git a/libmaple/usb/stm32f1/usb_cdcacm.c b/libmaple/usb/stm32f1/usb_cdcacm.c
index cdcba9c..3f3a493 100644
--- a/libmaple/usb/stm32f1/usb_cdcacm.c
+++ b/libmaple/usb/stm32f1/usb_cdcacm.c
@@ -267,6 +267,8 @@ static volatile uint8 vcomBufferRx[USB_CDCACM_RX_EPSIZE];
static volatile uint32 rx_offset = 0;
/* Number of bytes left to transmit */
static volatile uint32 n_unsent_bytes = 0;
+/* Are we currently sending an IN packet? */
+static volatile uint8 transmitting = 0;
/* Number of unread bytes */
static volatile uint32 n_unread_bytes = 0;
@@ -407,6 +409,13 @@ uint32 usb_cdcacm_tx(const uint8* buf, uint32 len) {
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;
}
return len;
@@ -416,7 +425,11 @@ uint32 usb_cdcacm_data_available(void) {
return n_unread_bytes;
}
-uint16 usb_cdcacm_get_pending() {
+uint8 usb_cdcacm_is_transmitting(void) {
+ return transmitting;
+}
+
+uint16 usb_cdcacm_get_pending(void) {
return n_unsent_bytes;
}
@@ -497,12 +510,8 @@ int usb_cdcacm_get_n_data_bits(void) {
*/
static void vcomDataTxCb(void) {
- /* The following assumes that all of the bytes we copied during
- * the last call to usb_cdcacm_tx were sent during the IN
- * transaction (this seems to be the case). */
- /* TODO find out why this is broken:
- * n_unsent_bytes = usb_get_ep_tx_count(USB_CDCACM_TX_ENDP); */
n_unsent_bytes = 0;
+ transmitting = 0;
}
static void vcomDataRxCb(void) {