-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Esp8266 uart fixes #2990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Esp8266 uart fixes #2990
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ extern UartDevice UartDev; | |
|
||
// the uart to which OS messages go; -1 to disable | ||
static int uart_os = UART_OS; | ||
static int uart_os_stdin = UART_OS; | ||
|
||
#if MICROPY_REPL_EVENT_DRIVEN | ||
static os_event_t uart_evt_queue[16]; | ||
|
@@ -116,7 +117,7 @@ void uart_flush(uint8 uart) { | |
} | ||
|
||
/****************************************************************************** | ||
* FunctionName : uart1_write_char | ||
* FunctionName : uart_os_write_char | ||
* Description : Internal used function | ||
* Do some special deal while tx char is '\r' or '\n' | ||
* Parameters : char c - character to tx | ||
|
@@ -141,6 +142,11 @@ uart_os_config(int uart) { | |
uart_os = uart; | ||
} | ||
|
||
void ICACHE_FLASH_ATTR | ||
uart_os_input(int uart) { | ||
uart_os_stdin = uart; | ||
} | ||
|
||
/****************************************************************************** | ||
* FunctionName : uart0_rx_intr_handler | ||
* Description : Internal used function | ||
|
@@ -165,22 +171,29 @@ static void uart0_rx_intr_handler(void *para) { | |
// fifo full | ||
goto read_chars; | ||
} else if (UART_RXFIFO_TOUT_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_RXFIFO_TOUT_INT_ST)) { | ||
// rx timeout | ||
read_chars: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rx timeout what? |
||
ETS_UART_INTR_DISABLE(); | ||
|
||
while (READ_PERI_REG(UART_STATUS(uart_no)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S)) { | ||
uint8 RcvChar = READ_PERI_REG(UART_FIFO(uart_no)) & 0xff; | ||
// Raw data processing. | ||
if (uart_os_stdin == -1) { | ||
// Disable repl's stdin interpretation | ||
goto put_char; | ||
} | ||
if (RcvChar == mp_interrupt_char) { | ||
mp_keyboard_interrupt(); | ||
} else { | ||
put_char: | ||
ringbuf_put(&input_buf, RcvChar); | ||
} | ||
} | ||
|
||
mp_hal_signal_input(); | ||
|
||
// Clear pending FIFO interrupts | ||
WRITE_PERI_REG(UART_INT_CLR(UART_REPL), UART_RXFIFO_TOUT_INT_CLR | UART_RXFIFO_FULL_INT_ST); | ||
WRITE_PERI_REG(UART_INT_CLR(uart_no), UART_RXFIFO_TOUT_INT_CLR | UART_RXFIFO_FULL_INT_ST); | ||
ETS_UART_INTR_ENABLE(); | ||
} | ||
} | ||
|
@@ -263,6 +276,11 @@ void ICACHE_FLASH_ATTR uart_setup(uint8 uart) { | |
|
||
#if MICROPY_REPL_EVENT_DRIVEN | ||
void uart_task_handler(os_event_t *evt) { | ||
if (uart_os_stdin == -1) { | ||
// Disable repl's stdin interpretation | ||
return; | ||
} | ||
|
||
if (pyexec_repl_active) { | ||
// TODO: Just returning here isn't exactly right. | ||
// What really should be done is something like | ||
|
@@ -274,6 +292,7 @@ void uart_task_handler(os_event_t *evt) { | |
return; | ||
} | ||
|
||
// Buffered data processing and interpretation | ||
int c, ret = 0; | ||
while ((c = ringbuf_get(&input_buf)) >= 0) { | ||
if (c == interrupt_char) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,7 @@ typedef struct { | |
UartBautRate baut_rate; | ||
UartBitsNum4Char data_bits; | ||
UartExistParity exist_parity; | ||
UartParityMode parity; // chip size in byte | ||
UartParityMode parity; // even/odd | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not very related change, should be submitted separately. |
||
UartStopBitsNum stop_bits; | ||
UartFlowCtrl flow_ctrl; | ||
RcvMsgBuff rcv_buff; | ||
|
@@ -92,12 +92,12 @@ typedef struct { | |
} UartDevice; | ||
|
||
void uart_init(UartBautRate uart0_br, UartBautRate uart1_br); | ||
int uart0_rx(void); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated change. |
||
bool uart_rx_wait(uint32_t timeout_us); | ||
int uart_rx_char(void); | ||
void uart_tx_one_char(uint8 uart, uint8 TxChar); | ||
void uart_flush(uint8 uart); | ||
void uart_os_config(int uart); | ||
void uart_os_input(int uart); | ||
void uart_setup(uint8 uart); | ||
// check status of rx/tx | ||
int uart_rx_any(uint8 uart); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated change.
Also, "seems" sounds dangerous. This patch also "seems" to work, right?