From a71dec81a25fe9f8087540bb78596700e06ad47f Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Sat, 25 Dec 2021 13:08:33 +0100 Subject: [PATCH] sys/stdio_base: add optional function stdio_available A couple of `stdio` backend implementations allow to check for the number of available bytes for reading before the blocking `stdio_read` is called. This helps to implement non-blocking functionalities while waiting for `stdin`. --- makefiles/pseudomodules.inc.mk | 1 + sys/Kconfig.stdio | 5 +++++ sys/include/stdio_base.h | 14 ++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 063eb10722..c2a03b2d4a 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -152,6 +152,7 @@ PSEUDOMODULES += sock_udp PSEUDOMODULES += socket_zep_hello PSEUDOMODULES += soft_uart_modecfg PSEUDOMODULES += stdin +PSEUDOMODULES += stdio_available PSEUDOMODULES += stdio_cdc_acm PSEUDOMODULES += stdio_ethos PSEUDOMODULES += stdio_uart_rx diff --git a/sys/Kconfig.stdio b/sys/Kconfig.stdio index f031cb0f43..f167e26988 100644 --- a/sys/Kconfig.stdio +++ b/sys/Kconfig.stdio @@ -53,6 +53,11 @@ config MODULE_STDIO_UART_RX help Reception when using UART-based STDIO needs to be enabled. +config MODULE_STDIO_AVAILABLE + bool + help + Indicates that the implementation supports function stdio_available + config MODULE_PRINTF_FLOAT bool "Float support in printf" diff --git a/sys/include/stdio_base.h b/sys/include/stdio_base.h index e76bd2ff19..d9a972064f 100644 --- a/sys/include/stdio_base.h +++ b/sys/include/stdio_base.h @@ -25,6 +25,8 @@ #include +#include "kernel_defines.h" + #ifdef __cplusplus extern "C" { #endif @@ -34,6 +36,18 @@ extern "C" { */ void stdio_init(void); +#if IS_USED(MODULE_STDIO_AVAILABLE) || DOXYGEN +/** + * @brief Get the number of bytes available for reading from stdio. + * + * @warning This function is only available if the implementation supports + * it and the @c stdio_available module is enabled. + * + * @return number of available bytes + */ +int stdio_available(void); +#endif + /** * @brief read @p len bytes from stdio uart into @p buffer *