From 84fd2532a7f23d20354ff590790b3f892cb7e7d7 Mon Sep 17 00:00:00 2001 From: AJM Date: Tue, 14 Dec 2010 01:39:20 -0500 Subject: added a usbBlockingSendByte(char ch) this new function will only return AFTER the usb interrupt has been serviced and the byte is sent. Bytes should NOT fall on the floor ever with this function. (but they still do? pyserials problem?) --- libmaple/usb/usb.c | 15 ++++++++++----- libmaple/usb/usb.h | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'libmaple/usb') diff --git a/libmaple/usb/usb.c b/libmaple/usb/usb.c index 448c4ff..4e86ed0 100644 --- a/libmaple/usb/usb.c +++ b/libmaple/usb/usb.c @@ -336,10 +336,15 @@ void usbWaitReset(void) { * * */ +void usbBlockingSendByte(char ch) { + while (countTx); + UserToPMABufferCopy(&ch,VCOM_TX_ADDR,1); + _SetEPTxCount(VCOM_TX_ENDP,1); + _SetEPTxValid(VCOM_TX_ENDP); + countTx = 1; + while (countTx); +} uint32 usbSendBytes(uint8* sendBuf, uint32 len) { - - uint16 loaded = 0; - /* any checks on connection (via dtr/rts) done upstream in wirish or by user */ /* last xmit hasnt finished, abort */ @@ -348,8 +353,8 @@ uint32 usbSendBytes(uint8* sendBuf, uint32 len) { } // We can only put VCOM_TX_EPSIZE bytes in the buffer - if(len > VCOM_TX_EPSIZE) { - len = VCOM_TX_EPSIZE; + if(len > VCOM_TX_EPSIZE/2) { + len = VCOM_TX_EPSIZE/2; } // Try to load some bytes if we can diff --git a/libmaple/usb/usb.h b/libmaple/usb/usb.h index 5bc31e1..0ed02e5 100644 --- a/libmaple/usb/usb.h +++ b/libmaple/usb/usb.h @@ -73,6 +73,7 @@ void usb_lpIRQHandler(void); void usbWaitReset(void); /* blocking functions for send/receive */ +void usbBlockingSendByte(char ch); uint32 usbSendBytes(uint8* sendBuf,uint32 len); uint32 usbBytesAvailable(void); uint32 usbReceiveBytes(uint8* recvBuf, uint32 len); -- cgit v1.2.3