summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
9b97421)
Discarding output before USB is plugged in allows threads that send output
and do other things to work without a USB connection. Unfortuantely, there
doesn't appear to be any way to detect when the USB link is disconnected,
which means that once USB is enabled, future writes will continue to block.
USB reset causes the USB interrupts to all be reconfigured back to power-on
state.
Signed-off-by: Keith Packard <keithp@keithp.com>
static __xdata uint16_t ao_usb_in_bytes;
static __xdata uint16_t ao_usb_out_bytes;
static __xdata uint8_t ao_usb_iif;
static __xdata uint16_t ao_usb_in_bytes;
static __xdata uint16_t ao_usb_out_bytes;
static __xdata uint8_t ao_usb_iif;
-static __xdata uint8_t ao_usb_oif;
+static __xdata uint8_t ao_usb_running;
+
+static void
+ao_usb_set_interrupts(void)
+{
+ /* IN interrupts on the control an IN endpoints */
+ USBIIE = (1 << AO_USB_CONTROL_EP) | (1 << AO_USB_IN_EP);
+
+ /* OUT interrupts on the OUT endpoint */
+ USBOIE = (1 << AO_USB_OUT_EP);
+
+ /* Only care about reset */
+ USBCIE = USBCIE_RSTIE;
+}
/* This interrupt is shared with port 2,
* so when we hook that up, fix this
/* This interrupt is shared with port 2,
* so when we hook that up, fix this
if (ao_usb_iif & (1 << AO_USB_IN_EP))
ao_wakeup(&ao_usb_in_bytes);
if (ao_usb_iif & (1 << AO_USB_IN_EP))
ao_wakeup(&ao_usb_in_bytes);
- ao_usb_oif |= USBOIF;
- if (ao_usb_oif & (1 << AO_USB_OUT_EP))
+ if (USBOIF & (1 << AO_USB_OUT_EP))
ao_wakeup(&ao_usb_out_bytes);
ao_wakeup(&ao_usb_out_bytes);
+
+ if (USBCIF & USBCIF_RSTIF)
+ ao_usb_set_interrupts();
void
ao_usb_set_address(uint8_t address)
{
void
ao_usb_set_address(uint8_t address)
{
USBADDR = address | 0x80;
while (USBADDR & 0x80)
;
USBADDR = address | 0x80;
while (USBADDR & 0x80)
;
void
ao_usb_putchar(char c) __critical
{
void
ao_usb_putchar(char c) __critical
{
+ if (!ao_usb_running)
+ return;
for (;;) {
USBINDEX = AO_USB_IN_EP;
if ((USBCSIL & USBCSIL_INPKT_RDY) == 0)
for (;;) {
USBINDEX = AO_USB_IN_EP;
if ((USBCSIL & USBCSIL_INPKT_RDY) == 0)
ao_usb_set_configuration();
ao_usb_set_configuration();
- /* IN interrupts on the control an IN endpoints */
- USBIIE = (1 << AO_USB_CONTROL_EP) | (1 << AO_USB_IN_EP);
+ ao_usb_set_interrupts();
- /* OUT interrupts on the OUT endpoint */
- USBOIE = (1 << AO_USB_OUT_EP);
-
- /* Ignore control interrupts */
- USBCIE = 0;
-
/* enable USB interrupts */
IEN2 |= IEN2_USBIE;
/* enable USB interrupts */
IEN2 |= IEN2_USBIE;
__xdata __at (0xde04) volatile uint8_t USBOIF;
__xdata __at (0xde06) volatile uint8_t USBCIF;
__xdata __at (0xde04) volatile uint8_t USBOIF;
__xdata __at (0xde06) volatile uint8_t USBCIF;
+
+# define USBCIF_SOFIF (1 << 3)
+# define USBCIF_RSTIF (1 << 2)
+# define USBCIF_RESUMEIF (1 << 1)
+# define USBCIF_SUSPENDIF (1 << 0)
+
__xdata __at (0xde07) volatile uint8_t USBIIE;
__xdata __at (0xde09) volatile uint8_t USBOIE;
__xdata __at (0xde07) volatile uint8_t USBIIE;
__xdata __at (0xde09) volatile uint8_t USBOIE;