In USB pollchar, wait for packet before re-checking USB out len
authorKeith Packard <keithp@keithp.com>
Thu, 5 Nov 2009 05:32:07 +0000 (21:32 -0800)
committerKeith Packard <keithp@keithp.com>
Thu, 5 Nov 2009 05:32:07 +0000 (21:32 -0800)
This probably wouldn't actually cause a problem, but it seems more
reliable to wait for a packet interrupt before re-reading the packet
OUT len register. This could avoid spinning while waiting for a USB
packet, which seems like a good thing.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/ao_usb.c

index daca71a734e911995045318b6afe802ac60b3581..527e9b302ec387355317b447c7cacad1ea926540 100644 (file)
@@ -377,11 +377,13 @@ char
 ao_usb_pollchar(void) __critical
 {
        char c;
-       while (ao_usb_out_bytes == 0) {
+       if (ao_usb_out_bytes == 0) {
                USBINDEX = AO_USB_OUT_EP;
                if ((USBCSOL & USBCSOL_OUTPKT_RDY) == 0)
                        return AO_READ_AGAIN;
                ao_usb_out_bytes = (USBCNTH << 8) | USBCNTL;
+               if (ao_usb_out_bytes == 0)
+                       return AO_READ_AGAIN;
        }
        --ao_usb_out_bytes;
        c = USBFIFO[AO_USB_OUT_EP << 1];