aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple/usb/usb_callbacks.c
diff options
context:
space:
mode:
authorAJM <poslathian@poslathian.(none)>2010-12-14 00:48:13 -0500
committerAJM <poslathian@poslathian.(none)>2010-12-14 00:48:13 -0500
commit40573207a2a5d17110c58a8d4051a4f2804b960a (patch)
tree76cd1f2ad41dddeb8f0eb426bda95c4ab4716f2a /libmaple/usb/usb_callbacks.c
parent125cbc814bc032ba217e8c10e0ceb43981126ce3 (diff)
downloadlibrambutan-40573207a2a5d17110c58a8d4051a4f2804b960a.tar.gz
librambutan-40573207a2a5d17110c58a8d4051a4f2804b960a.zip
changed the serialusb to be simplest possible design
no longer use a ring buffer. No longer double buffer a local rx buffer and the packet memory. Instead, we read out of packet memory and block it for all reads. This is going to be slower. but it tests OK (unlike the old one...).
Diffstat (limited to 'libmaple/usb/usb_callbacks.c')
-rw-r--r--libmaple/usb/usb_callbacks.c30
1 files changed, 4 insertions, 26 deletions
diff --git a/libmaple/usb/usb_callbacks.c b/libmaple/usb/usb_callbacks.c
index d04f610..4d7e57a 100644
--- a/libmaple/usb/usb_callbacks.c
+++ b/libmaple/usb/usb_callbacks.c
@@ -37,7 +37,7 @@ volatile uint32 countTx = 0;
volatile uint32 recvBufIn = 0;
volatile uint32 recvBufOut = 0;
volatile uint32 maxNewBytes = VCOM_RX_BUFLEN;
-
+volatile uint32 newBytes = 0;
RESET_STATE reset_state = DTR_UNSET;
uint8 line_dtr_rts = 0;
@@ -47,7 +47,7 @@ void vcomDataTxCb(void) {
/* allows usbSendBytes to stop blocking */
- countTx = 0;
+ countTx = 0; /* assumes tx transactions are atomic 64 bytes (nearly certain they are) */
}
/* we could get arbitrarily complicated here for speed purposes
@@ -60,9 +60,8 @@ 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);
+ newBytes = GetEPRxCount(VCOM_RX_ENDP);
SetEPRxStatus(VCOM_RX_ENDP,EP_RX_NAK);
- /* assert (newBytes <= maxNewBytes); */
/* todo, not checking very carefully for edge cases. USUALLY,
if we emit the reset pulse and send 4 bytes, then newBytes
@@ -117,28 +116,7 @@ void vcomDataRxCb(void) {
- 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_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_BUFLEN;
- }
-
- maxNewBytes -= newBytes;
-
- if (maxNewBytes >= VCOM_RX_EPSIZE) {
- SetEPRxCount(VCOM_RX_ENDP,VCOM_RX_EPSIZE);
- SetEPRxStatus(VCOM_RX_ENDP,EP_RX_VALID);
- }
-
+ PMAToUserBufferCopy(&vcomBufferRx[0],VCOM_RX_ADDR,newBytes);
}
void vcomManagementCb(void) {