8000 esp8266/uart: move receive handler to machine_uart. · dmkent/micropython@f4b9d95 · GitHub
  • [go: up one dir, main page]

    Skip to content

    Commit f4b9d95

    Browse files
    committed
    esp8266/uart: move receive handler to machine_uart.
    From @dpgeorge on micropython#2891: IMO this belongs in machine_uart.c, since it's specific to UART behaviour. Also, since UART1 can't receive it doesn't need to take an argument. Makes more sense here as it is UART specific.
    1 parent 2fe3e71 commit f4b9d95

    File tree

    4 files changed

    +28
    -28
    lines changed

    4 files changed

    +28
    -28
    lines changed

    esp8266/esp_mphal.c

    Lines changed: 0 additions & 25 deletions
    Original file line numberDiff line numberDiff line change
    @@ -149,31 +149,6 @@ void mp_hal_signal_input(void) {
    149149
    #endif
    150150
    }
    151151

    152-
    void mp_hal_uart_rx_intr(int uart_no) {
    153-
    int ch;
    154-
    mp_obj_t term = MP_STATE_PORT(term_obj);
    155-
    bool uart_term = (term == NULL || term == MP_STATE_PORT(pyb_uart_objs)[uart_no]);
    156-
    157-
    for (;;) {
    158-
    if ((ch = uart_rx_one_char(uart_no)) == -1) {
    159-
    break;
    160-
    }
    161-
    if (uart_term) {
    162-
    if (ch == mp_interrupt_char) {
    163-
    mp_keyboard_interrupt();
    164-
    } else {
    165-
    ringbuf_put(&input_buf, ch);
    166-
    }
    167-
    } else {
    168-
    void mp_uart_stuff_rx(mp_obj_t self_in, byte ch);
    169-
    mp_uart_stuff_rx(MP_STATE_PORT(pyb_uart_objs)[uart_no],ch);
    170-
    }
    171-
    }
    172-
    if (uart_term) {
    173-
    mp_hal_signal_input();
    174-
    }
    175-
    }
    176-
    177152

    178153
    static int call_dupterm_read(void) {
    179154
    if (MP_STATE_PORT(term_obj) == NULL) {

    esp8266/esp_mphal.h

    Lines changed: 0 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -37,8 +37,6 @@ extern const struct _mp_print_t mp_debug_print;
    3737
    extern ringbuf_t input_buf;
    3838
    // Call this after putting data to input_buf
    3939
    void mp_hal_signal_input(void);
    40-
    // Call this to put characters into connected uart buffer if repl connected
    41-
    void mp_hal_uart_rx_intr(int uart_no);
    4240
    // Call this when data is available in dupterm object
    4341
    void mp_hal_signal_dupterm_input(void);
    4442

    esp8266/machine_uart.c

    Lines changed: 24 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -248,6 +248,30 @@ void mp_uart_stuff_rx(mp_obj_t self_in, byte ch) {
    248248
    ringbuf_put(&self->rxbuf,ch);
    249249
    }
    250250

    251+
    void uart_handle_rx() {
    252+
    int ch;
    253+
    mp_obj_t term = MP_STATE_PORT(term_obj);
    254+
    bool uart_term = (term == NULL || term == MP_STATE_PORT(pyb_uart_objs)[0]);
    255+
    256+
    for (;;) {
    257+
    if ((ch = uart_rx_one_char(0)) == -1) {
    258+
    break;
    259+
    }
    260+
    if (uart_term) {
    261+
    if (ch == mp_interrupt_char) {
    262+
    mp_keyboard_interrupt();
    263+
    } else {
    264+
    ringbuf_put(&input_buf, ch);
    265+
    }
    266+
    } else {
    267+
    mp_uart_stuff_rx(MP_STATE_PORT(pyb_uart_objs)[0], ch);
    268+
    }
    269+
    }
    270+
    if (uart_term) {
    271+
    mp_hal_signal_input();
    272+
    }
    273+
    }
    274+
    251275
    // Waits at most timeout microseconds for at least 1 char to become ready for reading.
    252276
    // Returns true if something available, false if not.
    253277
    STATIC bool uart_rx_wait(pyb_uart_obj_t *self, uint32_t timeout_us) {

    esp8266/uart.c

    Lines changed: 4 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -38,6 +38,7 @@ static void uart0_rx_intr_handler(void *para);
    3838

    3939
    void soft_reset(void);
    4040
    void mp_keyboard_interrupt(void);
    41+
    void uart_handle_rx();
    4142

    4243
    /******************************************************************************
    4344
    * FunctionName : uart_config
    @@ -167,7 +168,9 @@ static void uart0_rx_intr_handler(void *para) {
    167168
    } else if (UART_RXFIFO_TOUT_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_RXFIFO_TOUT_INT_ST)) {
    168169
    read_chars:
    169170
    ETS_UART_INTR_DISABLE();
    170-
    mp_hal_uart_rx_intr(uart_no);
    171+
    172+
    uart_handle_rx();
    173+
    171174
    // Clear pending FIFO interrupts
    172175
    WRITE_PERI_REG(UART_INT_CLR(UART_REPL), UART_RXFIFO_TOUT_INT_CLR | UART_RXFIFO_FULL_INT_ST);
    173176
    ETS_UART_INTR_ENABLE();

    0 commit comments

    Comments
     (0)
    0