Skip to content

Commit

Permalink
softusb: minimize time between SETUP/OUT and DATAx
Browse files Browse the repository at this point in the history
By not waiting until the transmitter is idle, we can reduce the
time between the end of the SE0 indicating EOP of SETUP or OUT
and the first transition of the following DATAx to a mere two
bit times (as oppose to ~6 bit times before).

While I haven't been able to find anything in the USB standard
that would require such tight timing, AVR USB chips (i.e., the
ATmega32U2 of atusb and the AT90USB162 of the Faderfox LV3)
flat out ignore any transfers with longer delays.
  • Loading branch information
wpwrak authored and Sebastien Bourdeauducq committed Nov 30, 2011
1 parent dae5ff5 commit 6ca46c2
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions softusb-input/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static void make_usb_token(unsigned char pid, unsigned int elevenbits, unsigned
out[2] |= usb_crc5(out[1], out[2]) << 3;
}

static void usb_tx(const unsigned char *buf, unsigned char len)
static void usb_tx_nowait(const unsigned char *buf, unsigned char len)
{
unsigned char i;

Expand All @@ -130,9 +130,15 @@ static void usb_tx(const unsigned char *buf, unsigned char len)
}
while(rio8(SIE_TX_PENDING));
wio8(SIE_TX_VALID, 0);
}

static void usb_tx(const unsigned char *buf, unsigned char len)
{
usb_tx_nowait(buf, len);
while(rio8(SIE_TX_BUSY));
}


static inline void usb_ack(void)
{
wio8(SIE_TX_DATA, 0x80); /* send SYNC */
Expand Down Expand Up @@ -302,7 +308,7 @@ static char usb_out(unsigned addr, const unsigned char *buf, unsigned char len)

/* send OUT */
make_usb_token(USB_PID_OUT, addr, out);
usb_tx(out, 3);
usb_tx_nowait(out, 3);

/* send DATAx */
usb_tx(buf, len);
Expand Down Expand Up @@ -346,7 +352,7 @@ static int control_transfer(unsigned char addr, struct setup_packet *p,
TRIGGER_ON();

/* send them back-to-back */
usb_tx(setup, 3);
usb_tx_nowait(setup, 3);
usb_tx(usb_buffer, 11);

TRIGGER_OFF();
Expand Down

0 comments on commit 6ca46c2

Please sign in to comment.