mirror of
https://github.com/micropython/micropython.git
synced 2025-07-21 04:51:12 +02:00
zephyr/src: Increase UART input buffer to 512 bytes and reduce latency.
There are two changes here: 1. Increase the UART input bufffer to 512 bytes. That's necessary to get basic REPL reliability tests working, and helps improve `mpremote` usage, eg copying large files. 2. Remove `uart_sem` semaphore. This is no longer needed because `zephyr_getchar()` should be fully non-blocking and have as low a latency as possible. `mp_hal_stdin_rx_chr()` (which calls `zephyr_getchar`) already uses `MICROPY_EVENT_POLL_HOOK` to get an efficient wait, and doing an extra wait and check for the semaphore in `zephyr_getchar()` just introduces unnecessary latency and can lead to slower input, and potentially overflowing the UART input buffer. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -23,12 +23,10 @@
|
||||
extern int mp_interrupt_char;
|
||||
void mp_sched_keyboard_interrupt(void);
|
||||
void mp_hal_signal_event(void);
|
||||
void mp_hal_wait_sem(struct k_sem *sem, uint32_t timeout_ms);
|
||||
|
||||
static struct k_sem uart_sem;
|
||||
#define UART_BUFSIZE 256
|
||||
#define UART_BUFSIZE (512)
|
||||
static uint8_t uart_ringbuf[UART_BUFSIZE];
|
||||
static uint8_t i_get, i_put;
|
||||
static uint16_t i_get, i_put;
|
||||
|
||||
static int console_irq_input_hook(uint8_t ch) {
|
||||
int i_next = (i_put + 1) & (UART_BUFSIZE - 1);
|
||||
@@ -44,8 +42,6 @@ static int console_irq_input_hook(uint8_t ch) {
|
||||
uart_ringbuf[i_put] = ch;
|
||||
i_put = i_next;
|
||||
}
|
||||
// printk("%x\n", ch);
|
||||
k_sem_give(&uart_sem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -55,8 +51,7 @@ int zephyr_getchar_check(void) {
|
||||
}
|
||||
|
||||
int zephyr_getchar(void) {
|
||||
mp_hal_wait_sem(&uart_sem, 0);
|
||||
if (k_sem_take(&uart_sem, K_MSEC(0)) == 0) {
|
||||
if (i_get != i_put) {
|
||||
unsigned int key = irq_lock();
|
||||
int c = (int)uart_ringbuf[i_get++];
|
||||
i_get &= UART_BUFSIZE - 1;
|
||||
@@ -67,7 +62,6 @@ int zephyr_getchar(void) {
|
||||
}
|
||||
|
||||
void zephyr_getchar_init(void) {
|
||||
k_sem_init(&uart_sem, 0, UINT_MAX);
|
||||
uart_console_in_debug_hook_install(console_irq_input_hook);
|
||||
// All NULLs because we're interested only in the callback above
|
||||
uart_register_input(NULL, NULL, NULL);
|
||||
|
Reference in New Issue
Block a user