1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-25 06:23:53 +01:00

Merge pull request #17446 from gschorcht/sys/std_available

sys/stdio: add optional function stdio_available
This commit is contained in:
Alexandre Abadie 2022-01-03 18:15:06 +01:00 committed by GitHub
commit 74b38ca641
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 0 deletions

View File

@ -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

View File

@ -17,6 +17,7 @@ endif
ifneq (,$(filter stdio_cdc_acm,$(USEMODULE)))
USEMODULE += usbus_cdc_acm
USEMODULE += isrpipe
USEMODULE += stdio_available
endif
ifneq (,$(filter stdio_rtt,$(USEMODULE)))
@ -37,6 +38,7 @@ endif
ifneq (,$(filter stdio_uart_rx,$(USEMODULE)))
USEMODULE += isrpipe
USEMODULE += stdio_uart
USEMODULE += stdio_available
endif
ifneq (,$(filter stdio_uart,$(USEMODULE)))

View File

@ -49,10 +49,16 @@ config MODULE_STDIO_UART_RX
bool
depends on MODULE_STDIO_UART
select MODULE_ISRPIPE
select MODULE_STDIO_AVAILABLE
default y if MODULE_STDIN
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"

View File

@ -25,6 +25,8 @@
#include <unistd.h>
#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
*

View File

@ -67,6 +67,13 @@ void stdio_init(void)
#endif
}
#if IS_USED(MODULE_STDIO_AVAILABLE)
int stdio_available(void)
{
return tsrb_avail(&stdio_uart_isrpipe.tsrb);
}
#endif
ssize_t stdio_read(void* buffer, size_t count)
{
#ifdef MODULE_STDIO_UART_RX

View File

@ -58,5 +58,6 @@ config MODULE_STDIO_CDC_ACM
bool "CDC ACM"
depends on MODULE_USBUS_CDC_ACM
select MODULE_ISRPIPE
select MODULE_STDIO_AVAILABLE
endchoice

View File

@ -51,6 +51,13 @@ void stdio_init(void)
#endif
}
#if IS_USED(MODULE_STDIO_AVAILABLE)
int stdio_available(void)
{
return tsrb_avail(&_cdc_stdio_isrpipe.tsrb);
}
#endif
ssize_t stdio_read(void* buffer, size_t len)
{
(void)buffer;