altos: Do not release interrupts from any pollchar function
authorKeith Packard <keithp@keithp.com>
Sun, 24 Mar 2013 22:00:20 +0000 (15:00 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 31 Mar 2013 19:24:24 +0000 (12:24 -0700)
getchar relies on interrupts being blocked across the pollchar calls
and into the sleep call or it may go to sleep with data pending.

This prefixes all pollchar functions with _ to indicate that they are
to be called with interrupts blocked and eliminates all interrupt
manipulation calls from within the pollchar functions.

Signed-off-by: Keith Packard <keithp@keithp.com>
14 files changed:
src/avr/ao_serial_avr.c
src/avr/ao_usb_avr.c
src/cc1111/ao_serial.c
src/cc1111/ao_usb.c
src/core/ao.h
src/core/ao_packet.h
src/core/ao_serial.h
src/core/ao_stdio.c
src/drivers/ao_btm.c
src/drivers/ao_packet.c
src/drivers/ao_packet_master.c
src/drivers/ao_packet_slave.c
src/stm/ao_serial_stm.c
src/stm/ao_usb_stm.c

index dcee246ce3eb66191e393708aeee88858dc7ef34..e0f813d5acd33fdeb62049a5c8a1814599948bbf 100644 (file)
@@ -59,52 +59,51 @@ ISR(USART1_UDRE_vect)
        ao_wakeup(&ao_serial1_tx_fifo);
 }
 
        ao_wakeup(&ao_serial1_tx_fifo);
 }
 
-char
-ao_serial1_getchar(void) __critical
-{
-       char    c;
-       cli();
-       while (ao_fifo_empty(ao_serial1_rx_fifo))
-               ao_sleep(&ao_serial1_rx_fifo);
-       ao_fifo_remove(ao_serial1_rx_fifo, c);
-       sei();
-       return c;
-}
-
 #if USE_SERIAL_1_STDIN
 #if USE_SERIAL_1_STDIN
-char
-ao_serial1_pollchar(void) __critical
+int
+_ao_serial1_pollchar(void)
 {
        char    c;
 {
        char    c;
-       cli();
        if (ao_fifo_empty(ao_serial1_rx_fifo)) {
                sei();
                return AO_READ_AGAIN;
        }
        ao_fifo_remove(ao_serial1_rx_fifo,c);
        if (ao_fifo_empty(ao_serial1_rx_fifo)) {
                sei();
                return AO_READ_AGAIN;
        }
        ao_fifo_remove(ao_serial1_rx_fifo,c);
-       sei();
        return c;
 }
 #endif
 
        return c;
 }
 #endif
 
+char
+ao_serial1_getchar(void) __critical
+{
+       char    c;
+
+       ao_arch_block_interrupts();
+       while (ao_fifo_empty(ao_serial1_rx_fifo))
+               ao_sleep(&ao_serial1_rx_fifo);
+       ao_fifo_remove(ao_serial1_rx_fifo, c);
+       ao_arch_release_interrupts();
+       return c;
+}
+
 void
 void
-ao_serial1_putchar(char c) __critical
+ao_serial1_putchar(char c)
 {
 {
-       cli();
+       ao_arch_block_interrupts();
        while (ao_fifo_full(ao_serial1_tx_fifo))
                ao_sleep(&ao_serial1_tx_fifo);
        ao_fifo_insert(ao_serial1_tx_fifo, c);
        ao_serial_tx1_start();
        while (ao_fifo_full(ao_serial1_tx_fifo))
                ao_sleep(&ao_serial1_tx_fifo);
        ao_fifo_insert(ao_serial1_tx_fifo, c);
        ao_serial_tx1_start();
-       sei();
+       ao_arch_release_interrupts();
 }
 
 void
 ao_serial1_drain(void) __critical
 {
 }
 
 void
 ao_serial1_drain(void) __critical
 {
-       cli();
+       ao_arch_block_interrupts();
        while (!ao_fifo_empty(ao_serial1_tx_fifo))
                ao_sleep(&ao_serial1_tx_fifo);
        while (!ao_fifo_empty(ao_serial1_tx_fifo))
                ao_sleep(&ao_serial1_tx_fifo);
-       sei();
+       ao_arch_release_interrupts();
 }
 
 static const struct {
 }
 
 static const struct {
@@ -155,7 +154,7 @@ ao_serial_init(void)
                  (1 << RXCIE1) |       /* Enable receive interrupts */
                  (1 << UDRIE1));       /* Enable transmit empty interrupts */
 #if USE_SERIAL_1_STDIN
                  (1 << RXCIE1) |       /* Enable receive interrupts */
                  (1 << UDRIE1));       /* Enable transmit empty interrupts */
 #if USE_SERIAL_1_STDIN
-       ao_add_stdio(ao_serial1_pollchar,
+       ao_add_stdio(_ao_serial1_pollchar,
                     ao_serial1_putchar,
                     NULL);
 #endif
                     ao_serial1_putchar,
                     NULL);
 #endif
index 2ef546c98dc2d4d1f462bb2c042c9c9885a8df85..bd75b17d7a5cc21638ea2d02c81b04019525a8ad 100644 (file)
@@ -411,7 +411,7 @@ ao_usb_ep0(void)
 
 /* Wait for a free IN buffer */
 static void
 
 /* 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 */
 {
        for (;;) {
                /* Check if the current buffer is writable */
@@ -419,7 +419,6 @@ ao_usb_in_wait(void)
                if (UEINTX & (1 << RWAL))
                        break;
 
                if (UEINTX & (1 << RWAL))
                        break;
 
-               cli();
                /* Wait for an IN buffer to be ready */
                for (;;) {
                        UENUM = AO_USB_IN_EP;
                /* Wait for an IN buffer to be ready */
                for (;;) {
                        UENUM = AO_USB_IN_EP;
@@ -430,24 +429,24 @@ ao_usb_in_wait(void)
                }
                /* Ack the interrupt */
                UEINTX &= ~(1 << TXINI);
                }
                /* Ack the interrupt */
                UEINTX &= ~(1 << TXINI);
-               sei();
        }
 }
 
 /* Queue the current IN buffer for transmission */
 static void
        }
 }
 
 /* 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
 {
        UENUM = AO_USB_IN_EP;
        UEINTX &= ~(1 << FIFOCON);
 }
 
 void
-ao_usb_flush(void) __critical
+ao_usb_flush(void)
 {
        if (!ao_usb_running)
                return;
 
 {
        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
        /* Anytime we've sent a character since
         * the last time we flushed, we'll need
         * to send a packet -- the only other time
@@ -457,18 +456,20 @@ ao_usb_flush(void) __critical
         */
        if (!ao_usb_in_flushed) {
                ao_usb_in_flushed = 1;
         */
        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
 }
 
 void
-ao_usb_putchar(char c) __critical __reentrant
+ao_usb_putchar(char c)
 {
        if (!ao_usb_running)
                return;
 
 {
        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;
 
        /* Queue a byte */
        UENUM = AO_USB_IN_EP;
@@ -476,11 +477,12 @@ ao_usb_putchar(char c) __critical __reentrant
 
        /* Send the packet when full */
        if ((UEINTX & (1 << RWAL)) == 0)
 
        /* Send the packet when full */
        if ((UEINTX & (1 << RWAL)) == 0)
-               ao_usb_in_send();
+               _ao_usb_in_send();
        ao_usb_in_flushed = 0;
        ao_usb_in_flushed = 0;
+       ao_arch_release_interrupts();
 }
 
 }
 
-static int
+int
 _ao_usb_pollchar(void)
 {
        uint8_t c;
 _ao_usb_pollchar(void)
 {
        uint8_t c;
@@ -517,25 +519,15 @@ _ao_usb_pollchar(void)
        return c;
 }
 
        return c;
 }
 
-int
-ao_usb_pollchar(void)
-{
-       int     c;
-       cli();
-       c = _ao_usb_pollchar();
-       sei();
-       return c;
-}
-
 char
 char
-ao_usb_getchar(void) __critical
+ao_usb_getchar(void)
 {
        int     c;
 
 {
        int     c;
 
-       cli();
+       ao_arch_block_interrupts();
        while ((c = _ao_usb_pollchar()) == AO_READ_AGAIN)
                ao_sleep(&ao_stdin_ready);
        while ((c = _ao_usb_pollchar()) == AO_READ_AGAIN)
                ao_sleep(&ao_stdin_ready);
-       sei();
+       ao_arch_release_interrupts();
        return c;
 }
 
        return c;
 }
 
@@ -668,5 +660,5 @@ ao_usb_init(void)
 #if USB_DEBUG
        ao_add_task(&ao_usb_echo_task, ao_usb_echo, "usb echo");
 #endif
 #if USB_DEBUG
        ao_add_task(&ao_usb_echo_task, ao_usb_echo, "usb echo");
 #endif
-       ao_add_stdio(ao_usb_pollchar, ao_usb_putchar, ao_usb_flush);
+       ao_add_stdio(_ao_usb_pollchar, ao_usb_putchar, ao_usb_flush);
 }
 }
index 8913a9b075333d1532064d5357aebd90051d7369..81727836d260e84ab88f3a1ae78c559296d9a525 100644 (file)
@@ -92,7 +92,7 @@ ao_serial0_getchar(void) __critical
 
 #if USE_SERIAL_0_STDIN
 int
 
 #if USE_SERIAL_0_STDIN
 int
-ao_serial0_pollchar(void) __critical
+_ao_serial0_pollchar(void)
 {
        uint8_t c;
        if (ao_fifo_empty(ao_serial0_rx_fifo))
 {
        uint8_t c;
        if (ao_fifo_empty(ao_serial0_rx_fifo))
@@ -180,7 +180,7 @@ ao_serial1_getchar(void) __critical
 
 #if USE_SERIAL_1_STDIN
 int
 
 #if USE_SERIAL_1_STDIN
 int
-ao_serial1_pollchar(void) __critical
+_ao_serial1_pollchar(void)
 {
        uint8_t c;
        if (ao_fifo_empty(ao_serial1_rx_fifo))
 {
        uint8_t c;
        if (ao_fifo_empty(ao_serial1_rx_fifo))
@@ -271,7 +271,7 @@ ao_serial_init(void)
        IEN0 |= IEN0_URX0IE;
        IEN2 |= IEN2_UTX0IE;
 #if USE_SERIAL_0_STDIN && !DELAY_SERIAL_0_STDIN
        IEN0 |= IEN0_URX0IE;
        IEN2 |= IEN2_UTX0IE;
 #if USE_SERIAL_0_STDIN && !DELAY_SERIAL_0_STDIN
-       ao_add_stdio(ao_serial0_pollchar,
+       ao_add_stdio(_ao_serial0_pollchar,
                     ao_serial0_putchar,
                     NULL);
 #endif
                     ao_serial0_putchar,
                     NULL);
 #endif
@@ -327,7 +327,7 @@ ao_serial_init(void)
        IEN2 |= IEN2_UTX1IE;
 
 #if USE_SERIAL_1_STDIN && !DELAY_SERIAL_1_STDIN
        IEN2 |= IEN2_UTX1IE;
 
 #if USE_SERIAL_1_STDIN && !DELAY_SERIAL_1_STDIN
-       ao_add_stdio(ao_serial1_pollchar,
+       ao_add_stdio(_ao_serial1_pollchar,
                     ao_serial1_putchar,
                     NULL);
 #endif
                     ao_serial1_putchar,
                     NULL);
 #endif
index f66e807cf7bf13e2d9c774a56645cde6fca4923a..8bd2efdf73706e2c9060e02d389191fa2112f04b 100644 (file)
@@ -383,18 +383,18 @@ ao_usb_putchar(char c) __critical __reentrant
 }
 
 int
 }
 
 int
-ao_usb_pollchar(void) __critical
+_ao_usb_pollchar(void)
 {
        uint8_t c;
        if (ao_usb_out_bytes == 0) {
                USBINDEX = AO_USB_OUT_EP;
                if ((USBCSOL & USBCSOL_OUTPKT_RDY) == 0)
 {
        uint8_t c;
        if (ao_usb_out_bytes == 0) {
                USBINDEX = AO_USB_OUT_EP;
                if ((USBCSOL & USBCSOL_OUTPKT_RDY) == 0)
-                       return -1;
+                       return AO_READ_AGAIN;
                ao_usb_out_bytes = (USBCNTH << 8) | USBCNTL;
                if (ao_usb_out_bytes == 0) {
                        USBINDEX = AO_USB_OUT_EP;
                        USBCSOL &= ~USBCSOL_OUTPKT_RDY;
                ao_usb_out_bytes = (USBCNTH << 8) | USBCNTL;
                if (ao_usb_out_bytes == 0) {
                        USBINDEX = AO_USB_OUT_EP;
                        USBCSOL &= ~USBCSOL_OUTPKT_RDY;
-                       return -1;
+                       return AO_READ_AGAIN;
                }
        }
        --ao_usb_out_bytes;
                }
        }
        --ao_usb_out_bytes;
@@ -407,12 +407,14 @@ ao_usb_pollchar(void) __critical
 }
 
 char
 }
 
 char
-ao_usb_getchar(void) __critical
+ao_usb_getchar(void)
 {
        int     c;
 
 {
        int     c;
 
-       while ((c = ao_usb_pollchar()) == AO_READ_AGAIN)
+       ao_arch_block_interrupts();
+       while ((c = _ao_usb_pollchar()) == AO_READ_AGAIN)
                ao_sleep(&ao_stdin_ready);
                ao_sleep(&ao_stdin_ready);
+       ao_arch_release_interrupts();
        return c;
 }
 
        return c;
 }
 
@@ -459,5 +461,5 @@ ao_usb_init(void)
        ao_usb_enable();
 
        ao_add_task(&ao_usb_task, ao_usb_ep0, "usb");
        ao_usb_enable();
 
        ao_add_task(&ao_usb_task, ao_usb_ep0, "usb");
-       ao_add_stdio(ao_usb_pollchar, ao_usb_putchar, ao_usb_flush);
+       ao_add_stdio(_ao_usb_pollchar, ao_usb_putchar, ao_usb_flush);
 }
 }
index e3161b4c383319031c06f17e9a9462015296a522..6c790f69046cf7fefb94ac37224a9c6fccca2195 100644 (file)
@@ -638,7 +638,7 @@ ao_monitor_init(void) __reentrant;
 #define AO_READ_AGAIN  (-1)
 
 struct ao_stdio {
 #define AO_READ_AGAIN  (-1)
 
 struct ao_stdio {
-       int     (*pollchar)(void);
+       int     (*_pollchar)(void);     /* Called with interrupts blocked */
        void    (*putchar)(char c) __reentrant;
        void    (*flush)(void);
        uint8_t echo;
        void    (*putchar)(char c) __reentrant;
        void    (*flush)(void);
        uint8_t echo;
index 08b184d60fc340596208c2660b842fc07cff7a69..6d121bb933d36431bf34453aa9b47e927cd7e8a3 100644 (file)
@@ -63,7 +63,7 @@ void
 ao_packet_putchar(char c) __reentrant;
 
 int
 ao_packet_putchar(char c) __reentrant;
 
 int
-ao_packet_pollchar(void);
+_ao_packet_pollchar(void);
 
 #if PACKET_HAS_MASTER
 /* ao_packet_master.c */
 
 #if PACKET_HAS_MASTER
 /* ao_packet_master.c */
index a799bf2c9bc4afd6322d507d7b27626d866a29e9..baf213c01ad510eee2d278439ef546df2d04b321 100644 (file)
@@ -32,7 +32,7 @@ char
 ao_serial0_getchar(void);
 
 int
 ao_serial0_getchar(void);
 
 int
-ao_serial0_pollchar(void);
+_ao_serial0_pollchar(void);
 
 void
 ao_serial0_putchar(char c);
 
 void
 ao_serial0_putchar(char c);
@@ -52,7 +52,7 @@ char
 ao_serial1_getchar(void);
 
 int
 ao_serial1_getchar(void);
 
 int
-ao_serial1_pollchar(void);
+_ao_serial1_pollchar(void);
 
 void
 ao_serial1_putchar(char c);
 
 void
 ao_serial1_putchar(char c);
@@ -72,7 +72,7 @@ char
 ao_serial2_getchar(void);
 
 int
 ao_serial2_getchar(void);
 
 int
-ao_serial2_pollchar(void);
+_ao_serial2_pollchar(void);
 
 void
 ao_serial2_putchar(char c);
 
 void
 ao_serial2_putchar(char c);
@@ -92,7 +92,7 @@ char
 ao_serial3_getchar(void);
 
 int
 ao_serial3_getchar(void);
 
 int
-ao_serial3_pollchar(void);
+_ao_serial3_pollchar(void);
 
 void
 ao_serial3_putchar(char c);
 
 void
 ao_serial3_putchar(char c);
index 1748dfe8d940ecc550ff41911db01b0259291ec9..977d74b1800bdafc2cc24be64bcc99331f608ed1 100644 (file)
@@ -99,20 +99,21 @@ char
 getchar(void) __reentrant
 {
        int c;
 getchar(void) __reentrant
 {
        int c;
-       ao_arch_critical(
-               int8_t stdio = ao_cur_stdio;
+       int8_t stdio;
 
 
-               for (;;) {
-                       c = ao_stdios[stdio].pollchar();
-                       if (c != AO_READ_AGAIN)
-                               break;
-                       if (++stdio == ao_num_stdios)
-                               stdio = 0;
-                       if (stdio == ao_cur_stdio)
-                               ao_sleep(&ao_stdin_ready);
-               }
-               ao_cur_stdio = stdio;
-               );
+       ao_arch_block_interrupts();
+       stdio = ao_cur_stdio;
+       for (;;) {
+               c = ao_stdios[stdio]._pollchar();
+               if (c != AO_READ_AGAIN)
+                       break;
+               if (++stdio == ao_num_stdios)
+                       stdio = 0;
+               if (stdio == ao_cur_stdio)
+                       ao_sleep(&ao_stdin_ready);
+       }
+       ao_cur_stdio = stdio;
+       ao_arch_release_interrupts();
        return c;
 }
 
        return c;
 }
 
@@ -123,13 +124,13 @@ ao_echo(void)
 }
 
 int8_t
 }
 
 int8_t
-ao_add_stdio(int (*pollchar)(void),
+ao_add_stdio(int (*_pollchar)(void),
             void (*putchar)(char),
             void (*flush)(void)) __reentrant
 {
        if (ao_num_stdios == AO_NUM_STDIOS)
                ao_panic(AO_PANIC_STDIO);
             void (*putchar)(char),
             void (*flush)(void)) __reentrant
 {
        if (ao_num_stdios == AO_NUM_STDIOS)
                ao_panic(AO_PANIC_STDIO);
-       ao_stdios[ao_num_stdios].pollchar = pollchar;
+       ao_stdios[ao_num_stdios]._pollchar = _pollchar;
        ao_stdios[ao_num_stdios].putchar = putchar;
        ao_stdios[ao_num_stdios].flush = flush;
        ao_stdios[ao_num_stdios].echo = 1;
        ao_stdios[ao_num_stdios].putchar = putchar;
        ao_stdios[ao_num_stdios].flush = flush;
        ao_stdios[ao_num_stdios].echo = 1;
index c862200a8fe01232f199777abe434d2ab4160b49..de1f31a3c53248d0c05a43abd2e974c2be360e77 100644 (file)
 
 #ifndef ao_serial_btm_getchar
 #define ao_serial_btm_putchar  ao_serial1_putchar
 
 #ifndef ao_serial_btm_getchar
 #define ao_serial_btm_putchar  ao_serial1_putchar
-#define ao_serial_btm_pollchar ao_serial1_pollchar
+#define _ao_serial_btm_pollchar        _ao_serial1_pollchar
 #define ao_serial_btm_set_speed ao_serial1_set_speed
 #define ao_serial_btm_drain    ao_serial1_drain
 #define ao_serial_btm_set_speed ao_serial1_set_speed
 #define ao_serial_btm_drain    ao_serial1_drain
+#define ao_serial_btm_rx_fifo  ao_serial1_rx_fifo
 #endif
 
 int8_t                 ao_btm_stdio;
 #endif
 
 int8_t                 ao_btm_stdio;
@@ -111,6 +112,30 @@ __code struct ao_cmds ao_btm_cmds[] = {
 #define AO_BTM_MAX_REPLY       16
 __xdata char           ao_btm_reply[AO_BTM_MAX_REPLY];
 
 #define AO_BTM_MAX_REPLY       16
 __xdata char           ao_btm_reply[AO_BTM_MAX_REPLY];
 
+/*
+ * Read one bluetooth character.
+ * Returns AO_READ_AGAIN if no character arrives within 10ms
+ */
+
+static int
+ao_btm_getchar(void)
+{
+       int     c;
+
+       ao_arch_block_interrupts();
+       while ((c = _ao_serial_btm_pollchar()) == AO_READ_AGAIN) {
+               ao_alarm(AO_MS_TO_TICKS(10));
+               c = ao_sleep(&ao_serial_btm_rx_fifo);
+               ao_clear_alarm();
+               if (c) {
+                       c = AO_READ_AGAIN;
+                       break;
+               }
+       }
+       ao_arch_release_interrupts();
+       return c;
+}
+
 /*
  * Read a line of data from the serial port, truncating
  * it after a few characters.
 /*
  * Read a line of data from the serial port, truncating
  * it after a few characters.
@@ -122,24 +147,13 @@ ao_btm_get_line(void)
        uint8_t ao_btm_reply_len = 0;
        int c;
 
        uint8_t ao_btm_reply_len = 0;
        int c;
 
-       for (;;) {
-
-               while ((c = ao_serial_btm_pollchar()) != AO_READ_AGAIN) {
-                       ao_btm_log_in_char(c);
-                       if (ao_btm_reply_len < sizeof (ao_btm_reply))
-                               ao_btm_reply[ao_btm_reply_len++] = c;
-                       if (c == '\r' || c == '\n')
-                               goto done;
-               }
-               for (c = 0; c < 10; c++) {
-                       ao_delay(AO_MS_TO_TICKS(10));
-                       if (!ao_fifo_empty(ao_serial1_rx_fifo))
-                               break;
-               }
-               if (c == 10)
-                       goto done;
+       while ((c = ao_btm_getchar()) != AO_READ_AGAIN) {
+               ao_btm_log_in_char(c);
+               if (ao_btm_reply_len < sizeof (ao_btm_reply))
+                       ao_btm_reply[ao_btm_reply_len++] = c;
+               if (c == '\r' || c == '\n')
+                       break;
        }
        }
-done:
        for (c = ao_btm_reply_len; c < sizeof (ao_btm_reply);)
                ao_btm_reply[c++] = '\0';
        return ao_btm_reply_len;
        for (c = ao_btm_reply_len; c < sizeof (ao_btm_reply);)
                ao_btm_reply[c++] = '\0';
        return ao_btm_reply_len;
@@ -279,7 +293,7 @@ ao_btm(void)
        /* Turn off status reporting */
        ao_btm_cmd("ATQ1\r");
 
        /* Turn off status reporting */
        ao_btm_cmd("ATQ1\r");
 
-       ao_btm_stdio = ao_add_stdio(ao_serial_btm_pollchar,
+       ao_btm_stdio = ao_add_stdio(_ao_serial_btm_pollchar,
                                    ao_serial_btm_putchar,
                                    NULL);
        ao_btm_echo(0);
                                    ao_serial_btm_putchar,
                                    NULL);
        ao_btm_echo(0);
index 913199232a75b46d2db390ac9e665686626529e0..5a50747888a01225da2a8bc7cbe0f6dd247f7334 100644 (file)
@@ -169,12 +169,10 @@ ao_packet_putchar(char c) __reentrant
                tx_data[ao_packet_tx_used++] = c;
 }
 
                tx_data[ao_packet_tx_used++] = c;
 }
 
+/* May be called with interrupts blocked */
 int
 int
-ao_packet_pollchar(void)
+_ao_packet_pollchar(void)
 {
 {
-       /* No need to block interrupts, all variables here
-        * are only manipulated in task context
-        */
        if (!ao_packet_enable)
                return AO_READ_AGAIN;
 
        if (!ao_packet_enable)
                return AO_READ_AGAIN;
 
index 023c788ba86c4be6c0d8d0efcc548f5e8df973e3..4c0dc57303005e6132bfa961f88be5c3b6b86346 100644 (file)
@@ -21,7 +21,12 @@ static char
 ao_packet_getchar(void)
 {
        int c;
 ao_packet_getchar(void)
 {
        int c;
-       while ((c = ao_packet_pollchar()) == AO_READ_AGAIN) {
+
+       /* No need to block interrupts in this function as
+        * all packet variables are only modified from task
+        * context, not an interrupt handler
+        */
+       while ((c = _ao_packet_pollchar()) == AO_READ_AGAIN) {
                if (!ao_packet_enable)
                        break;
                if (ao_packet_master_sleeping)
                if (!ao_packet_enable)
                        break;
                if (ao_packet_master_sleeping)
index e45775cb00e1a20817c2f9a13e1e80c6e5503665..e75df0d619fb92509d0a76011757cb7e8b2d75b4 100644 (file)
@@ -59,7 +59,7 @@ ao_packet_slave_stop(void)
 void
 ao_packet_slave_init(uint8_t enable)
 {
 void
 ao_packet_slave_init(uint8_t enable)
 {
-       ao_add_stdio(ao_packet_pollchar,
+       ao_add_stdio(_ao_packet_pollchar,
                     ao_packet_putchar,
                     NULL);
        if (enable)
                     ao_packet_putchar,
                     NULL);
        if (enable)
index ce33f97e97416eaaf2a9eddfb54ba9f19943cb9e..2133c5845e0ca33233332ffc7717ad87ab49b6be 100644 (file)
@@ -59,24 +59,11 @@ ao_usart_isr(struct ao_stm_usart *usart, int stdin)
        }
 }
 
        }
 }
 
-char
-ao_usart_getchar(struct ao_stm_usart *usart)
-{
-       char c;
-       ao_arch_block_interrupts();
-       while (ao_fifo_empty(usart->rx_fifo))
-               ao_sleep(&usart->rx_fifo);
-       ao_fifo_remove(usart->rx_fifo, c);
-       ao_arch_release_interrupts();
-       return c;
-}
-
 int
 int
-ao_usart_pollchar(struct ao_stm_usart *usart)
+_ao_usart_pollchar(struct ao_stm_usart *usart)
 {
        int     c;
        
 {
        int     c;
        
-       ao_arch_block_interrupts();
        if (ao_fifo_empty(usart->rx_fifo))
                c = AO_READ_AGAIN;
        else {
        if (ao_fifo_empty(usart->rx_fifo))
                c = AO_READ_AGAIN;
        else {
@@ -84,10 +71,20 @@ ao_usart_pollchar(struct ao_stm_usart *usart)
                ao_fifo_remove(usart->rx_fifo,u);
                c = u;
        }
                ao_fifo_remove(usart->rx_fifo,u);
                c = u;
        }
-       ao_arch_release_interrupts();
        return c;
 }
 
        return c;
 }
 
+char
+ao_usart_getchar(struct ao_stm_usart *usart)
+{
+       int c;
+       ao_arch_block_interrupts();
+       while ((c = _ao_usart_pollchar(usart)) == AO_READ_AGAIN)
+               ao_sleep(&usart->rx_fifo);
+       ao_arch_release_interrupts();
+       return (char) c;
+}
+
 void
 ao_usart_putchar(struct ao_stm_usart *usart, char c)
 {
 void
 ao_usart_putchar(struct ao_stm_usart *usart, char c)
 {
@@ -201,9 +198,9 @@ ao_serial1_putchar(char c)
 }
 
 int
 }
 
 int
-ao_serial1_pollchar(void)
+_ao_serial1_pollchar(void)
 {
 {
-       return ao_usart_pollchar(&ao_stm_usart1);
+       return _ao_usart_pollchar(&ao_stm_usart1);
 }
 
 void
 }
 
 void
@@ -232,9 +229,9 @@ ao_serial2_putchar(char c)
 }
 
 int
 }
 
 int
-ao_serial2_pollchar(void)
+_ao_serial2_pollchar(void)
 {
 {
-       return ao_usart_pollchar(&ao_stm_usart2);
+       return _ao_usart_pollchar(&ao_stm_usart2);
 }
 
 void
 }
 
 void
@@ -263,9 +260,9 @@ ao_serial3_putchar(char c)
 }
 
 int
 }
 
 int
-ao_serial3_pollchar(void)
+_ao_serial3_pollchar(void)
 {
 {
-       return ao_usart_pollchar(&ao_stm_usart3);
+       return _ao_usart_pollchar(&ao_stm_usart3);
 }
 
 void
 }
 
 void
@@ -309,7 +306,7 @@ ao_serial_init(void)
        stm_nvic_set_enable(STM_ISR_USART1_POS);
        stm_nvic_set_priority(STM_ISR_USART1_POS, 4);
 #if USE_SERIAL_1_STDIN
        stm_nvic_set_enable(STM_ISR_USART1_POS);
        stm_nvic_set_priority(STM_ISR_USART1_POS, 4);
 #if USE_SERIAL_1_STDIN
-       ao_add_stdio(ao_serial1_pollchar,
+       ao_add_stdio(_ao_serial1_pollchar,
                     ao_serial1_putchar,
                     NULL);
 #endif
                     ao_serial1_putchar,
                     NULL);
 #endif
@@ -346,7 +343,7 @@ ao_serial_init(void)
        stm_nvic_set_enable(STM_ISR_USART2_POS);
        stm_nvic_set_priority(STM_ISR_USART2_POS, 4);
 #if USE_SERIAL_2_STDIN
        stm_nvic_set_enable(STM_ISR_USART2_POS);
        stm_nvic_set_priority(STM_ISR_USART2_POS, 4);
 #if USE_SERIAL_2_STDIN
-       ao_add_stdio(ao_serial2_pollchar,
+       ao_add_stdio(_ao_serial2_pollchar,
                     ao_serial2_putchar,
                     NULL);
 #endif
                     ao_serial2_putchar,
                     NULL);
 #endif
@@ -390,7 +387,7 @@ ao_serial_init(void)
        stm_nvic_set_enable(STM_ISR_USART3_POS);
        stm_nvic_set_priority(STM_ISR_USART3_POS, 4);
 #if USE_SERIAL_3_STDIN
        stm_nvic_set_enable(STM_ISR_USART3_POS);
        stm_nvic_set_priority(STM_ISR_USART3_POS, 4);
 #if USE_SERIAL_3_STDIN
-       ao_add_stdio(ao_serial3_pollchar,
+       ao_add_stdio(_ao_serial3_pollchar,
                     ao_serial3_putchar,
                     NULL);
 #endif
                     ao_serial3_putchar,
                     NULL);
 #endif
index 9379e5cd62efd19a8cdf994669fa171be0a9f11b..dfa58c42a784f86c1807f121a498e924e24ea23e 100644 (file)
@@ -229,10 +229,9 @@ ao_usb_set_stat_tx(int ep, uint32_t stat_tx)
 }
 
 static void
 }
 
 static void
-ao_usb_set_stat_rx(int ep, uint32_t stat_rx) {
+_ao_usb_set_stat_rx(int ep, uint32_t stat_rx) {
        uint32_t        epr_write, epr_old;
 
        uint32_t        epr_write, epr_old;
 
-       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;
        epr_write = epr_old = stm_usb.epr[ep];
        epr_write &= STM_USB_EPR_PRESERVE_MASK;
        epr_write |= STM_USB_EPR_INVARIANT;
@@ -240,6 +239,12 @@ ao_usb_set_stat_rx(int ep, uint32_t stat_rx) {
                              STM_USB_EPR_STAT_RX_MASK << STM_USB_EPR_STAT_RX,
                              stat_rx << STM_USB_EPR_STAT_RX);
        stm_usb.epr[ep] = epr_write;
                              STM_USB_EPR_STAT_RX_MASK << STM_USB_EPR_STAT_RX,
                              stat_rx << STM_USB_EPR_STAT_RX);
        stm_usb.epr[ep] = epr_write;
+}
+
+static void
+ao_usb_set_stat_rx(int ep, uint32_t stat_rx) {
+       ao_arch_block_interrupts();
+       _ao_usb_set_stat_rx(ep, stat_rx);
        ao_arch_release_interrupts();
 }
 
        ao_arch_release_interrupts();
 }
 
@@ -870,10 +875,10 @@ _ao_usb_out_recv(void)
        ao_usb_rx_pos = 0;
 
        /* ACK the packet */
        ao_usb_rx_pos = 0;
 
        /* ACK the packet */
-       ao_usb_set_stat_rx(AO_USB_OUT_EPR, STM_USB_EPR_STAT_RX_VALID);
+       _ao_usb_set_stat_rx(AO_USB_OUT_EPR, STM_USB_EPR_STAT_RX_VALID);
 }
 
 }
 
-static int
+int
 _ao_usb_pollchar(void)
 {
        uint8_t c;
 _ao_usb_pollchar(void)
 {
        uint8_t c;
@@ -896,16 +901,6 @@ _ao_usb_pollchar(void)
        return c;
 }
 
        return c;
 }
 
-int
-ao_usb_pollchar(void)
-{
-       int     c;
-       ao_arch_block_interrupts();
-       c = _ao_usb_pollchar();
-       ao_arch_release_interrupts();
-       return c;
-}
-
 char
 ao_usb_getchar(void)
 {
 char
 ao_usb_getchar(void)
 {