static void
ao_usb_set_stat_tx(int ep, uint32_t stat_tx)
{
- cli();
+ ao_arch_block_interrupts();
_ao_usb_set_stat_tx(ep, stat_tx);
- sei();
+ ao_arch_release_interrupts();
}
static void
ao_usb_set_stat_rx(int ep, uint32_t stat_rx) {
uint32_t epr_write, epr_old;
- cli();
+ ao_arch_block_interrupts();
epr_write = epr_old = stm_usb.epr[ep];
epr_write &= STM_USB_EPR_PRESERVE_MASK;
epr_write |= STM_USB_EPR_INVARIANT;
STM_USB_EPR_STAT_RX_MASK << STM_USB_EPR_STAT_RX,
stat_rx << STM_USB_EPR_STAT_RX);
stm_usb.epr[ep] = epr_write;
- sei();
+ ao_arch_release_interrupts();
}
/*
ao_usb_init_ep(uint8_t ep, uint32_t addr, uint32_t type, uint32_t stat_rx, uint32_t stat_tx)
{
uint32_t epr;
- cli();
+ ao_arch_block_interrupts();
epr = stm_usb.epr[ep];
epr = ((0 << STM_USB_EPR_CTR_RX) |
(epr & (1 << STM_USB_EPR_DTOG_RX)) |
(stat_tx << STM_USB_EPR_STAT_TX)) |
(addr << STM_USB_EPR_EA));
stm_usb.epr[ep] = epr;
- sei();
+ ao_arch_release_interrupts();
debug ("writing epr[%d] 0x%08x wrote 0x%08x\n",
ep, epr, stm_usb.epr[ep]);
}
ao_usb_in_send(void)
{
debug ("send %d\n", ao_usb_tx_count);
+ ao_usb_in_pending = 1;
ao_usb_write(ao_usb_tx_buffer, ao_usb_in_tx_buffer, 0, ao_usb_tx_count);
ao_usb_bdt[AO_USB_IN_EPR].single.count_tx = ao_usb_tx_count;
ao_usb_set_stat_tx(AO_USB_IN_EPR, STM_USB_EPR_STAT_TX_VALID);
- ao_usb_in_pending = 1;
ao_usb_tx_count = 0;
}
-/* Wait for a free IN buffer */
+/* Wait for a free IN buffer. Interrupts are blocked */
static void
-ao_usb_in_wait(void)
+_ao_usb_in_wait(void)
{
for (;;) {
/* Check if the current buffer is writable */
if (ao_usb_tx_count < AO_USB_IN_SIZE)
break;
- cli();
/* Wait for an IN buffer to be ready */
while (ao_usb_in_pending)
ao_sleep(&ao_usb_in_pending);
- sei();
}
}
void
-ao_usb_flush(void) __critical
+ao_usb_flush(void)
{
if (!ao_usb_running)
return;
* packet was full, in which case we now
* want to send an empty packet
*/
+ ao_arch_block_interrupts();
if (!ao_usb_in_flushed) {
ao_usb_in_flushed = 1;
- cli();
/* Wait for an IN buffer to be ready */
while (ao_usb_in_pending)
ao_sleep(&ao_usb_in_pending);
- sei();
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();
+ ao_usb_in_flushed = 0;
ao_usb_tx_buffer[ao_usb_tx_count++] = (uint8_t) c;
/* Send the packet when full */
if (ao_usb_tx_count == AO_USB_IN_SIZE)
ao_usb_in_send();
- ao_usb_in_flushed = 0;
+ ao_arch_release_interrupts();
}
static void
-ao_usb_out_recv(void)
+_ao_usb_out_recv(void)
{
ao_usb_out_avail = 0;
/* Check to see if a packet has arrived */
if (!ao_usb_out_avail)
return AO_READ_AGAIN;
- ao_usb_out_recv();
+ _ao_usb_out_recv();
}
/* Pull a character out of the fifo */
ao_usb_pollchar(void)
{
char c;
- cli();
+ ao_arch_block_interrupts();
c = _ao_usb_pollchar();
- sei();
+ ao_arch_release_interrupts();
return c;
}
char
-ao_usb_getchar(void) __critical
+ao_usb_getchar(void)
{
char 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;
}
void
ao_usb_disable(void)
{
+ ao_arch_block_interrupts();
stm_usb.cntr = (1 << STM_USB_CNTR_FRES);
stm_usb.istr = 0;
/* Disable the interface */
stm_rcc.apb1enr &+ ~(1 << STM_RCC_APB1ENR_USBEN);
+ ao_arch_release_interrupts();
}
void
* pulled low and doesn't work at all
*/
+ ao_arch_block_interrupts();
+
/* Route interrupts */
stm_nvic_set_priority(STM_ISR_USB_LP_POS, 3);
stm_nvic_set_enable(STM_ISR_USB_LP_POS);
(0 << STM_USB_CNTR_PDWN) |
(0 << STM_USB_CNTR_FRES));
+ ao_arch_release_interrupts();
+
for (t = 0; t < 1000; t++)
ao_arch_nop();
/* Enable USB pull-up */