summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2009-04-13 21:51:59 -0700
committerKeith Packard <keithp@keithp.com>2009-04-13 21:51:59 -0700
commitb56a44e48552bc32dbba9ff21770c370219a684a (patch)
tree00c759a9aea00333525312c76efe6ee9dc172945
parentcdaf3fc5802acf2ddc7972a15649ab0e1b31b873 (diff)
Fix USB input/output by reloading packet limits.
The USB controller is reset during the connection process, which clears the packet limits set in the controller at initialization time. Reload those values when the configuration is set. Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--ao_test.c15
-rw-r--r--ao_usb.c33
2 files changed, 39 insertions, 9 deletions
diff --git a/ao_test.c b/ao_test.c
index 9a8adc3d..5d50ab83 100644
--- a/ao_test.c
+++ b/ao_test.c
@@ -21,6 +21,7 @@ struct ao_task __xdata blink_0_task;
struct ao_task __xdata blink_1_task;
struct ao_task __xdata wakeup_task;
struct ao_task __xdata beep_task;
+struct ao_task __xdata echo_task;
void delay(int n) __reentrant
{
@@ -84,6 +85,19 @@ beep(void)
}
void
+echo(void)
+{
+ uint8_t c;
+ for (;;) {
+ c = ao_usb_getchar();
+ ao_usb_putchar(c);
+ if (c == '\r')
+ ao_usb_putchar('\n');
+ ao_usb_flush();
+ }
+}
+
+void
main(void)
{
CLKCON = 0;
@@ -94,5 +108,6 @@ main(void)
ao_add_task(&blink_1_task, blink_1);
ao_add_task(&wakeup_task, wakeup);
ao_add_task(&beep_task, beep);
+ ao_add_task(&echo_task, echo);
ao_start_scheduler();
}
diff --git a/ao_usb.c b/ao_usb.c
index d8f099c0..3e9bb5b3 100644
--- a/ao_usb.c
+++ b/ao_usb.c
@@ -301,6 +301,24 @@ ao_usb_set_address(uint8_t address)
}
static void
+ao_usb_set_configuration(void)
+{
+ uint8_t size;
+
+ /* Set the IN max packet size, double buffered */
+ USBINDEX = AO_USB_IN_EP;
+ size = AO_USB_IN_SIZE >> 3;
+ USBMAXI = size;
+// USBCSIH |= USBCSIH_IN_DBL_BUF;
+
+ /* Set the OUT max packet size, double buffered */
+ USBINDEX = AO_USB_OUT_EP;
+ size = AO_USB_OUT_SIZE >> 3;
+ USBMAXO = size;
+// USBCSOH = USBCSOH_OUT_DBL_BUF;
+}
+
+static void
ao_usb_ep0_setup(void)
{
/* Pull the setup packet out of the fifo */
@@ -350,6 +368,7 @@ ao_usb_ep0_setup(void)
break;
case AO_USB_REQ_SET_CONFIGURATION:
ao_usb_configuration = ao_usb_setup.value;
+ ao_usb_set_configuration();
break;
}
break;
@@ -494,6 +513,10 @@ ao_usb_getchar(void)
}
--ao_usb_out_bytes;
c = USBFIFO[AO_USB_OUT_EP << 1];
+ if (ao_usb_out_bytes == 0) {
+ USBINDEX = AO_USB_OUT_EP;
+ USBCSOL &= ~USBCSOL_OUTPKT_RDY;
+ }
ao_interrupt_enable();
return c;
}
@@ -504,15 +527,7 @@ ao_usb_init(void)
/* Turn on the USB controller */
SLEEP |= SLEEP_USB_EN;
- /* Set the IN max packet size, double buffered */
- USBINDEX = AO_USB_IN_EP;
- USBMAXI = AO_USB_IN_SIZE >> 3;
- USBCSIH |= USBCSIH_IN_DBL_BUF;
-
- /* Set the OUT max packet size, double buffered */
- USBINDEX = AO_USB_OUT_EP;
- USBMAXO = AO_USB_OUT_SIZE >> 3;
- USBCSOH = USBCSOH_OUT_DBL_BUF;
+ ao_usb_set_configuration();
/* IN interrupts on the control an IN endpoints */
USBIIE = (1 << AO_USB_CONTROL_EP) | (1 << AO_USB_IN_EP);