aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple/usb
diff options
context:
space:
mode:
authorAJM <poslathian@poslathian.(none)>2010-12-13 23:46:36 -0500
committerAJM <poslathian@poslathian.(none)>2010-12-13 23:46:36 -0500
commit125cbc814bc032ba217e8c10e0ceb43981126ce3 (patch)
tree612f65862fefb39ef8da94b865e84564bf5e503c /libmaple/usb
parentef3fcf8b3ed17540a4a931525afee8168852c48c (diff)
downloadlibrambutan-125cbc814bc032ba217e8c10e0ceb43981126ce3.tar.gz
librambutan-125cbc814bc032ba217e8c10e0ceb43981126ce3.zip
enlarged rx buffer and nak when less than 64 bytes is left in packet buf
Diffstat (limited to 'libmaple/usb')
-rw-r--r--libmaple/usb/usb.c4
-rw-r--r--libmaple/usb/usb.h4
-rw-r--r--libmaple/usb/usb_callbacks.c23
-rw-r--r--libmaple/usb/usb_callbacks.h10
-rw-r--r--libmaple/usb/usb_config.h1
5 files changed, 22 insertions, 20 deletions
diff --git a/libmaple/usb/usb.c b/libmaple/usb/usb.c
index 2b99132..396579f 100644
--- a/libmaple/usb/usb.c
+++ b/libmaple/usb/usb.c
@@ -336,7 +336,7 @@ void usbWaitReset(void) {
*
*
*/
-uint32 usbSendBytes(uint8* sendBuf, uint16 len) {
+uint32 usbSendBytes(uint8* sendBuf, uint32 len) {
uint16 loaded = 0;
@@ -380,7 +380,7 @@ uint32 usbBytesAvailable(void) {
usb packet buffer) into recvBuf and deq's the fifo.
will only copy the minimum of len or the available
bytes. returns the number of bytes copied */
-uint32 usbReceiveBytes(uint8* recvBuf, uint8 len) {
+uint32 usbReceiveBytes(uint8* recvBuf, uint32 len) {
if (len > VCOM_RX_EPSIZE - maxNewBytes) {
len = VCOM_RX_EPSIZE - maxNewBytes;
}
diff --git a/libmaple/usb/usb.h b/libmaple/usb/usb.h
index 84390cb..5bc31e1 100644
--- a/libmaple/usb/usb.h
+++ b/libmaple/usb/usb.h
@@ -73,9 +73,9 @@ void usb_lpIRQHandler(void);
void usbWaitReset(void);
/* blocking functions for send/receive */
-uint32 usbSendBytes(uint8* sendBuf,uint16 len);
+uint32 usbSendBytes(uint8* sendBuf,uint32 len);
uint32 usbBytesAvailable(void);
-uint32 usbReceiveBytes(uint8* recvBuf, uint8 len);
+uint32 usbReceiveBytes(uint8* recvBuf, uint32 len);
uint8 usbGetDTR(void);
uint8 usbGetRTS(void);
uint8 usbIsConnected(void);
diff --git a/libmaple/usb/usb_callbacks.c b/libmaple/usb/usb_callbacks.c
index c30d650..d04f610 100644
--- a/libmaple/usb/usb_callbacks.c
+++ b/libmaple/usb/usb_callbacks.c
@@ -32,11 +32,11 @@ USB_Line_Coding line_coding = {
datatype: 0x08
};
-uint8 vcomBufferRx[VCOM_RX_EPSIZE];
-volatile uint8 countTx = 0;
-volatile uint8 recvBufIn = 0;
-volatile uint8 recvBufOut = 0;
-volatile uint8 maxNewBytes = VCOM_RX_EPSIZE;
+uint8 vcomBufferRx[VCOM_RX_BUFLEN];
+volatile uint32 countTx = 0;
+volatile uint32 recvBufIn = 0;
+volatile uint32 recvBufOut = 0;
+volatile uint32 maxNewBytes = VCOM_RX_BUFLEN;
RESET_STATE reset_state = DTR_UNSET;
uint8 line_dtr_rts = 0;
@@ -61,6 +61,7 @@ void vcomDataRxCb(void) {
/* setEPRxCount on the previous cycle should garuntee
we havnt received more bytes than we can fit */
uint8 newBytes = GetEPRxCount(VCOM_RX_ENDP);
+ SetEPRxStatus(VCOM_RX_ENDP,EP_RX_NAK);
/* assert (newBytes <= maxNewBytes); */
/* todo, not checking very carefully for edge cases. USUALLY,
@@ -116,26 +117,26 @@ void vcomDataRxCb(void) {
- if (recvBufIn + newBytes < VCOM_RX_EPSIZE) {
+ if (recvBufIn + newBytes < VCOM_RX_BUFLEN) {
PMAToUserBufferCopy(&vcomBufferRx[recvBufIn],VCOM_RX_ADDR,newBytes);
recvBufIn += newBytes;
} else {
/* we have to copy the data in two chunks because we roll over
the edge of the circular buffer */
- uint8 tailBytes = VCOM_RX_EPSIZE - recvBufIn;
+ uint8 tailBytes = VCOM_RX_BUFLEN - recvBufIn;
uint8 remaining = newBytes - tailBytes;
PMAToUserBufferCopy(&vcomBufferRx[recvBufIn],VCOM_RX_ADDR,tailBytes);
PMAToUserBufferCopy(&vcomBufferRx[0], VCOM_RX_ADDR,remaining);
- recvBufIn = (recvBufIn + newBytes ) % VCOM_RX_EPSIZE;
+ recvBufIn = (recvBufIn + newBytes ) % VCOM_RX_BUFLEN;
}
maxNewBytes -= newBytes;
- if (maxNewBytes > VCOM_RX_EPSIZE) {
- SetEPRxCount(VCOM_RX_ENDP,0);
- SetEPRxStatus(VCOM_RX_ENDP,EP_RX_NAK); /* nak until we clear the buffer */
+ if (maxNewBytes >= VCOM_RX_EPSIZE) {
+ SetEPRxCount(VCOM_RX_ENDP,VCOM_RX_EPSIZE);
+ SetEPRxStatus(VCOM_RX_ENDP,EP_RX_VALID);
}
}
diff --git a/libmaple/usb/usb_callbacks.h b/libmaple/usb/usb_callbacks.h
index a94de11..21ceb77 100644
--- a/libmaple/usb/usb_callbacks.h
+++ b/libmaple/usb/usb_callbacks.h
@@ -34,11 +34,11 @@ typedef enum {
extern RESET_STATE reset_state; /* tracks DTR/RTS */
extern uint8 line_dtr_rts;
-extern volatile uint8 countTx;
-extern uint8 vcomBufferRx[VCOM_RX_EPSIZE]; /* no reason this has to be VCOM_RX_EPSIZE, could be bigger */
-extern volatile uint8 recvBufIn; /* the FIFO in index to the recvbuffer */
-extern volatile uint8 recvBufOut; /* the FIFO out index to the recvbuffer */
-extern volatile uint8 maxNewBytes;
+extern volatile uint32 countTx;
+extern uint8 vcomBufferRx[VCOM_RX_BUFLEN]; /* no reason this has to be VCOM_RX_EPSIZE, could be bigger */
+extern volatile uint32 recvBufIn; /* the FIFO in index to the recvbuffer */
+extern volatile uint32 recvBufOut; /* the FIFO out index to the recvbuffer */
+extern volatile uint32 maxNewBytes;
void vcomDataTxCb(void);
void vcomDataRxCb(void);
diff --git a/libmaple/usb/usb_config.h b/libmaple/usb/usb_config.h
index ba05d42..e5f3979 100644
--- a/libmaple/usb/usb_config.h
+++ b/libmaple/usb/usb_config.h
@@ -26,6 +26,7 @@
#define VCOM_RX_EPNUM 0x03
#define VCOM_RX_ADDR 0x110
#define VCOM_RX_EPSIZE 0x40
+#define VCOM_RX_BUFLEN (VCOM_RX_EPSIZE*3)
#define bMaxPacketSize 0x40 /* 64B, maximum for USB FS Devices */