aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Starkjohann <cs+github@obdev.at>2008-06-10 17:44:17 +0000
committerChristian Starkjohann <cs+github@obdev.at>2008-06-10 17:44:17 +0000
commitdfb2c5fd5e27c6b82466a01ebc59a3ee00d125dc (patch)
tree0cb9d7efc98498debc9099479beacf8e7510cac6
parent72d295266837d4af7e67b3ffc5d0eed335438b13 (diff)
downloadv-usb-dfb2c5fd5e27c6b82466a01ebc59a3ee00d125dc.tar.gz
v-usb-dfb2c5fd5e27c6b82466a01ebc59a3ee00d125dc.tar.bz2
v-usb-dfb2c5fd5e27c6b82466a01ebc59a3ee00d125dc.zip
- added usbconfig.h option USB_CFG_CHECK_DATA_TOGGLING
-rw-r--r--usbdrv/Changelog.txt1
-rw-r--r--usbdrv/asmcommon.inc9
-rw-r--r--usbdrv/usbconfig-prototype.h8
-rw-r--r--usbdrv/usbdrv.c3
-rw-r--r--usbdrv/usbdrv.h6
5 files changed, 24 insertions, 3 deletions
diff --git a/usbdrv/Changelog.txt b/usbdrv/Changelog.txt
index c6af6bb..6c1a0d4 100644
--- a/usbdrv/Changelog.txt
+++ b/usbdrv/Changelog.txt
@@ -236,3 +236,4 @@ Scroll down to the bottom to see the most recent changes.
was not incremented, pointer to length was incremented instead.
- Added code to command line tool(s) which claims an interface. This code
is disabled by default, but may be necessary on newer Linux kernels.
+ - Added usbconfig.h option "USB_CFG_CHECK_DATA_TOGGLING".
diff --git a/usbdrv/asmcommon.inc b/usbdrv/asmcommon.inc
index 819c0bd..febfeb0 100644
--- a/usbdrv/asmcommon.inc
+++ b/usbdrv/asmcommon.inc
@@ -103,8 +103,8 @@ sofError:
reti
handleData:
- lds token, usbCurrentTok;[18]
- tst token ;[20]
+ lds shift, usbCurrentTok;[18]
+ tst shift ;[20]
breq doReturn ;[21]
lds x2, usbRxLen ;[22]
tst x2 ;[24]
@@ -113,8 +113,11 @@ handleData:
; recognized if usbPoll() was called less frequently than once every 4 ms.
cpi cnt, 4 ;[26] zero sized data packets are status phase only -- ignore and ack
brmi sendAckAndReti ;[27] keep rx buffer clean -- we must not NAK next SETUP
+#if USB_CFG_CHECK_DATA_TOGGLING
+ sts usbCurrentDataToken, token ; store for checking by C code
+#endif
sts usbRxLen, cnt ;[28] store received data, swap buffers
- sts usbRxToken, token ;[30]
+ sts usbRxToken, shift ;[30]
lds x2, usbInputBufOffset;[32] swap buffers
ldi cnt, USB_BUFSIZE ;[34]
sub cnt, x2 ;[35]
diff --git a/usbdrv/usbconfig-prototype.h b/usbdrv/usbconfig-prototype.h
index eb66b81..035c627 100644
--- a/usbdrv/usbconfig-prototype.h
+++ b/usbdrv/usbconfig-prototype.h
@@ -156,6 +156,14 @@ section at the end of this file).
* counts SOF packets. This feature requires that the hardware interrupt is
* connected to D- instead of D+.
*/
+#define USB_CFG_CHECK_DATA_TOGGLING 0
+/* define this macro to 1 if you want to filter out duplicate data packets
+ * sent by the host. Duplicates occur only as a consequence of communication
+ * errors, when the host does not receive an ACK. Please note that you need to
+ * implement the filtering yourself in usbFunctionWriteOut() and
+ * usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable
+ * for each control- and out-endpoint to check for duplicate packets.
+ */
#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0
/* define this macro to 1 if you want the function usbMeasureFrameLength()
* compiled in. This function can be used to calibrate the AVR's RC oscillator.
diff --git a/usbdrv/usbdrv.c b/usbdrv/usbdrv.c
index 20e9ad8..eed2d52 100644
--- a/usbdrv/usbdrv.c
+++ b/usbdrv/usbdrv.c
@@ -44,6 +44,9 @@ usbTxStatus_t usbTxStatus1;
usbTxStatus_t usbTxStatus3;
# endif
#endif
+#if USB_CFG_CHECK_DATA_TOGGLING
+uchar usbCurrentDataToken;/* when we check data toggling to ignore duplicate packets */
+#endif
/* USB status registers / not shared with asm code */
uchar *usbMsgPtr; /* data to transmit next -- ROM or RAM address */
diff --git a/usbdrv/usbdrv.h b/usbdrv/usbdrv.h
index 4769917..e2c08ec 100644
--- a/usbdrv/usbdrv.h
+++ b/usbdrv/usbdrv.h
@@ -339,6 +339,12 @@ extern volatile uchar usbSofCount;
* the macro USB_COUNT_SOF is defined to a value != 0.
*/
#endif
+#if USB_CFG_CHECK_DATA_TOGGLING
+extern uchar usbCurrentDataToken;
+/* This variable can be checked in usbFunctionWrite() and usbFunctionWriteOut()
+ * to ignore duplicate packets.
+ */
+#endif
#define USB_STRING_DESCRIPTOR_HEADER(stringLength) ((2*(stringLength)+2) | (3<<8))
/* This macro builds a descriptor header for a string descriptor given the