aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple
diff options
context:
space:
mode:
authorAJM <poslathian@poslathian.(none)>2010-06-11 13:03:09 -0400
committerAJM <poslathian@poslathian.(none)>2010-06-11 13:03:09 -0400
commitcb1a6fbc210a3c6a68b1b1cecf39e0cb9cffa1aa (patch)
tree1a752d05fc10d9dd164fb352a1dafe7f0a371d7a /libmaple
parent57662f99c49ae5eb58ff5cba58f7f90812a721f5 (diff)
downloadlibrambutan-cb1a6fbc210a3c6a68b1b1cecf39e0cb9cffa1aa.tar.gz
librambutan-cb1a6fbc210a3c6a68b1b1cecf39e0cb9cffa1aa.zip
added getDTR and getRTS to usb.h, subtly modded how sendBytes checks for connection
flip flopped back and forth on how much work should be done here. For now its like 5 lines of changes
Diffstat (limited to 'libmaple')
-rw-r--r--libmaple/usb/usb.c30
-rw-r--r--libmaple/usb/usb.h2
2 files changed, 26 insertions, 6 deletions
diff --git a/libmaple/usb/usb.c b/libmaple/usb/usb.c
index 7cca37f..8dbf9c9 100644
--- a/libmaple/usb/usb.c
+++ b/libmaple/usb/usb.c
@@ -339,29 +339,39 @@ void usbWaitReset(void) {
systemHardReset();
}
+
+/* todo, change this function to behave like below */
/* copies data out of sendBuf into the packet memory for
usb, but waits until any previous usb transmissions have
completed before doing this. It returns without waiting
for its data to be sent. most efficient when 64 bytes are copied
at a time. users responsible for not overflowing sendbuf
with len! if > 64 bytes are being sent, then the function
- will block at every 64 byte packet
+ will simply send the first 64 and return. It is the USERS JOB
+ to implement any blocking. return -1 implies connection failure,
+ return 0 implies buffer filled, return < len implies another
+ transaction is needed to complete the send.
*/
+
+/* current behavior:
+ sendBytes will block until bytes are actually sent over the pipe.
+ broken pipes could stall this function. DTR and RTS are used to check
+ for a valid connection.
+ */
int16 usbSendBytes(uint8* sendBuf, uint16 len) {
- if (((line_dtr_rts & CONTROL_LINE_RTS) == 0) || bDeviceState != CONFIGURED) {
+ if (bDeviceState != CONFIGURED || (!usbGetDTR() && !usbGetRTS())) {
return -1; /* indicates to caller to stop trying, were not connected */
}
- /* This may be the correct behavior but it's undocumented
+ /*
if (countTx >= VCOM_TX_EPSIZE) {
return 0; // indicates to caller that the buffer is full
}
- */
+ */
- /* Block for any pending writes */
while (countTx)
- ;
+ ;
uint16 sent = len;
@@ -435,3 +445,11 @@ void usbSendHello(void) {
uint8 recv[64];
usbReceiveBytes(&recv[0],1);
}
+
+uint8 usbGetDTR() {
+ return ((line_dtr_rts & CONTROL_LINE_DTR) != 0);
+}
+
+uint8 usbGetRTS() {
+ return ((line_dtr_rts & CONTROL_LINE_RTS) != 0);
+}
diff --git a/libmaple/usb/usb.h b/libmaple/usb/usb.h
index ac8dc40..6451f7e 100644
--- a/libmaple/usb/usb.h
+++ b/libmaple/usb/usb.h
@@ -54,6 +54,8 @@ typedef enum
int16 usbSendBytes(uint8* sendBuf,uint16 len);
uint8 usbBytesAvailable(void);
uint8 usbReceiveBytes(uint8* recvBuf, uint8 len);
+ uint8 usbGetDTR(void);
+ uint8 usbGetRTS(void);
void usbSendHello(void);