From 77c4fd9a5306e236114c1ec27f3c3dbfa442be74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fin=20Maa=C3=9F?= Date: Fri, 16 Jan 2026 18:16:26 +0100 Subject: [PATCH] console: add functions to set the timeout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While the tty_* api already has functions to set the rx and the tx timeout, the console_* api didn't had one. Signed-off-by: Fin Maaß --- include/zephyr/console/console.h | 22 ++++++++++++++++++++++ subsys/console/getchar.c | 10 ++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/zephyr/console/console.h b/include/zephyr/console/console.h index fbecfdad0d3..31827780f7c 100644 --- a/include/zephyr/console/console.h +++ b/include/zephyr/console/console.h @@ -110,6 +110,28 @@ void console_getline_init(void); */ char *console_getline(void); +/** + * @brief Set receive timeout for console operations. + * + * Set timeout for console_getchar() and console_read() operations. + * Default timeout after initialization is K_FOREVER. + * + * @param timeout Maximum time to wait when reading. + */ +void console_set_rx_timeout(k_timeout_t timeout); + + +/** + * @brief Set transmit timeout for console operations. + * + * Set timeout for console_putchar() and console_write() operations, for + * a case when output buffer is full. + * Default timeout after initialization is K_FOREVER. + * + * @param timeout Maximum time to wait when writing. + */ +void console_set_tx_timeout(k_timeout_t timeout); + #ifdef __cplusplus } #endif diff --git a/subsys/console/getchar.c b/subsys/console/getchar.c index ba8055ecfe0..c11ebdc9a3e 100644 --- a/subsys/console/getchar.c +++ b/subsys/console/getchar.c @@ -47,6 +47,16 @@ int console_getchar(void) return c; } +void console_set_rx_timeout(k_timeout_t timeout) +{ + console_serial.rx_timeout = timeout; +} + +void console_set_tx_timeout(k_timeout_t timeout) +{ + console_serial.tx_timeout = timeout; +} + int console_init(void) { const struct device *uart_dev;