Allow the USB system to be disabled/enabled at run-time
authorKeith Packard <keithp@keithp.com>
Sat, 25 Apr 2009 20:18:37 +0000 (13:18 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 25 Apr 2009 20:18:37 +0000 (13:18 -0700)
ao.h
ao_usb.c

diff --git a/ao.h b/ao.h
index e9761c183029405525e4536e46c1b56240ff6e4c..d5669ae90fa1a1d268e5b96b496167bfff97a9c8 100644 (file)
--- a/ao.h
+++ b/ao.h
@@ -273,6 +273,14 @@ ao_usb_flush(void);
 void
 ao_usb_isr(void) interrupt 6;
 
 void
 ao_usb_isr(void) interrupt 6;
 
+/* Enable the USB controller */
+void
+ao_usb_enable(void);
+
+/* Disable the USB controller */
+void
+ao_usb_disable(void);
+
 /* Initialize the USB system */
 void
 ao_usb_init(void);
 /* Initialize the USB system */
 void
 ao_usb_init(void);
index c1520d750fc7e7c13c8790636f4da7e596df957e..1868ec3cea8355fd1de3e4e09f3e0cb987e86d6a 100644 (file)
--- a/ao_usb.c
+++ b/ao_usb.c
@@ -514,7 +514,7 @@ ao_usb_getchar(void) __critical
 }
 
 void
 }
 
 void
-ao_usb_init(void)
+ao_usb_enable(void)
 {
        /* Turn on the USB controller */
        SLEEP |= SLEEP_USB_EN;
 {
        /* Turn on the USB controller */
        SLEEP |= SLEEP_USB_EN;
@@ -537,6 +537,30 @@ ao_usb_init(void)
        USBCIF = 0;
        USBOIF = 0;
        USBIIF = 0;
        USBCIF = 0;
        USBOIF = 0;
        USBIIF = 0;
+}
+
+void
+ao_usb_disable(void)
+{
+       /* Disable USB interrupts */
+       USBIIE = 0;
+       USBOIE = 0;
+       USBCIE = 0;
+       IEN2 &= ~IEN2_USBIE;
        
        
+       /* Clear any pending interrupts */
+       USBCIF = 0;
+       USBOIF = 0;
+       USBIIF = 0;
+
+       /* Turn off the USB controller */
+       SLEEP &= ~SLEEP_USB_EN;
+}
+
+void
+ao_usb_init(void)
+{
+       ao_usb_enable();
+
        ao_add_task(&ao_usb_task, ao_usb_ep0, "usb");
 }
        ao_add_task(&ao_usb_task, ao_usb_ep0, "usb");
 }