To accelerate sending ACKs, this patch avoids the call setup overhead
of usb_tx and introduces a dedicated inline function. In experiments,
this reduced EOP-to-ACK time by about 10 full-speed bit times.
---
 softusb-input/main.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/softusb-input/main.c b/softusb-input/main.c
index 0318aee..dc6fa26 100644
--- a/softusb-input/main.c
+++ b/softusb-input/main.c
@@ -99,6 +99,16 @@ static void usb_tx(const unsigned char *buf, unsigned char 
len)
        while(rio8(SIE_TX_BUSY));
 }
 
+static inline void usb_ack(void)
+{
+       wio8(SIE_TX_DATA, 0x80); /* send SYNC */
+       while(rio8(SIE_TX_PENDING));
+       wio8(SIE_TX_DATA, USB_PID_ACK); /* send SYNC */
+       while(rio8(SIE_TX_PENDING));
+       wio8(SIE_TX_VALID, 0);
+       while(rio8(SIE_TX_BUSY));
+}
+
 static const char transfer_start[] PROGMEM = "Transfer start: ";
 static const char timeout_error[] PROGMEM = "RX timeout error\n";
 static const char bitstuff_error[] PROGMEM = "RX bitstuff error\n";
@@ -163,7 +173,6 @@ static int usb_in(unsigned addr, unsigned char 
expected_data,
     unsigned char *buf, unsigned char maxlen)
 {
        unsigned char in[3];
-       unsigned char ack[1] = { USB_PID_ACK };
        unsigned char len = 1;
        unsigned char i;
 
@@ -203,7 +212,7 @@ ignore:
                WAIT_RX(0, ignore_eop);
        goto complain; /* this doesn't stop - just quit silently */
 ignore_eop:
-       usb_tx(ack, 1);
+       usb_ack();
 complain:
        print_string(datax_mismatch);
        return 0;
@@ -218,7 +227,7 @@ receive:
                buf[len++] = rio8(SIE_RX_DATA);
        }
 eop:
-       usb_tx(ack, 1);
+       usb_ack();
        return len;
 
 discard:
-- 
1.7.1

_______________________________________________
http://lists.milkymist.org/listinfo.cgi/devel-milkymist.org
IRC: #milkymist@Freenode

Reply via email to