altos/cc1111: Hack on USB driver to make Windows happy
authorKeith Packard <keithp@keithp.com>
Fri, 17 May 2013 10:21:08 +0000 (03:21 -0700)
committerKeith Packard <keithp@keithp.com>
Fri, 17 May 2013 10:38:51 +0000 (03:38 -0700)
The Windows modem driver is quite chatty at startup time, getting and
setting the comm parameters each time the device is opened. Sometimes,
when setting the parameters, the cc1111 would STALL EP0.

Most of the time, Windows would happily pass this as an error back to
AltosUI which would then re-try the open (and succeed, most of the
time).

Sometimes, Windows would stall for 30 seconds before passing the error
back. This made the whole UI freeze, and I suspect most people assumed
our app had died.

A bit of analysis with the beagle USB sniffer and I discovered the
STALL settings, but there wasn't any correlation between the data on
the wire and when the STALL would be generated.

So, I found a couple of other cc1111 USB stacks on the net and just
looked to see how our driver differed. There wasn't anything clearly
related, but there were a list of small differences:

 1) Other drivers didn't bother waiting for the hardware to
    ack the USBADDR setting; doing it this way means we can set
    the address *before* acking the setup packet. It'll get
    set eventually, at which point the device will start responding to
    packets again.

    Easy to fix, and saves a bit of code space too.

 2) The other drivers set the STALL bit for setup packets which aren't
    understood. This shouldn't have any effect on 'good' systems as
    those shouldn't ever be generating bogus setup packets anyways.

    The driver already handled the STALL state in the interrupt
    handler, the only requirement was to figure out when to explicitly
    set the STALL bit.

    That required moving the state updating code from the start of the
    ep0 setup handling to the end, after the setup packet had been
    examined and data queued in or out as appropriate.

 3) Our driver explicitly queued an IN packet for any setup request
    that wasn't waiting for an OUT pack. This appears to tie in with
    the USBADDR change above as before I made that change, this change
    caused the driver to fail to respond to most setup packets.

    This was simple once the above change was made, just move the
    generation of the IN packet inside the code that switched to the
    IN state.

Signed-off-by: Keith Packard <keithp@keithp.com>

No differences found