/* Wait for a free IN buffer */
static void
-ao_usb_in_wait(void)
+_ao_usb_in_wait(void)
{
for (;;) {
/* Check if the current buffer is writable */
if (UEINTX & (1 << RWAL))
break;
- cli();
/* Wait for an IN buffer to be ready */
for (;;) {
UENUM = AO_USB_IN_EP;
}
/* Ack the interrupt */
UEINTX &= ~(1 << TXINI);
- sei();
}
}
/* Queue the current IN buffer for transmission */
static void
-ao_usb_in_send(void)
+_ao_usb_in_send(void)
{
UENUM = AO_USB_IN_EP;
UEINTX &= ~(1 << FIFOCON);
}
void
-ao_usb_flush(void) __critical
+ao_usb_flush(void)
{
if (!ao_usb_running)
return;
+ ao_arch_block_interrupts();
/* Anytime we've sent a character since
* the last time we flushed, we'll need
* to send a packet -- the only other time
*/
if (!ao_usb_in_flushed) {
ao_usb_in_flushed = 1;
- ao_usb_in_wait();
- ao_usb_in_send();
+ _ao_usb_in_wait();
+ _ao_usb_in_send();
}
+ ao_arch_release_interrupts();
}
void
-ao_usb_putchar(char c) __critical __reentrant
+ao_usb_putchar(char c)
{
if (!ao_usb_running)
return;
- ao_usb_in_wait();
+ ao_arch_block_interrupts();
+ _ao_usb_in_wait();
/* Queue a byte */
UENUM = AO_USB_IN_EP;
/* Send the packet when full */
if ((UEINTX & (1 << RWAL)) == 0)
- ao_usb_in_send();
+ _ao_usb_in_send();
ao_usb_in_flushed = 0;
+ ao_arch_release_interrupts();
}
-static char
+int
_ao_usb_pollchar(void)
{
- char c;
+ uint8_t c;
uint8_t intx;
if (!ao_usb_running)
}
char
-ao_usb_pollchar(void)
-{
- char c;
- cli();
- c = _ao_usb_pollchar();
- sei();
- return c;
-}
-
-char
-ao_usb_getchar(void) __critical
+ao_usb_getchar(void)
{
- char c;
+ int c;
- cli();
+ ao_arch_block_interrupts();
while ((c = _ao_usb_pollchar()) == AO_READ_AGAIN)
ao_sleep(&ao_stdin_ready);
- sei();
+ ao_arch_release_interrupts();
return c;
}
}
#endif
-static void
-ao_usb_irq(void)
-{
- printf ("control: %d out: %d in: %d\n",
- control_count, out_count, in_count);
-}
-
-__code struct ao_cmds ao_usb_cmds[] = {
- { ao_usb_irq, "i\0Show USB interrupt counts" },
- { 0, NULL }
-};
-
void
ao_usb_init(void)
{
#if USB_DEBUG
ao_add_task(&ao_usb_echo_task, ao_usb_echo, "usb echo");
#endif
- ao_cmd_register(&ao_usb_cmds[0]);
- ao_add_stdio(ao_usb_pollchar, ao_usb_putchar, ao_usb_flush);
+ ao_add_stdio(_ao_usb_pollchar, ao_usb_putchar, ao_usb_flush);
}