From 002057f91868a1febb62b624d3d1829f6a00522a Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 9 Nov 2017 10:03:06 +0100 Subject: [PATCH] sys: make uart_stdio RX optional --- Makefile.dep | 12 +++++++++++- makefiles/pseudomodules.inc.mk | 1 + sys/stdio_uart/stdio_uart.c | 31 +++++++++++++++++++++++++++---- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/Makefile.dep b/Makefile.dep index f89090bbb5..f8cc68c8b4 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -396,8 +396,18 @@ ifneq (,$(filter stdio_rtt,$(USEMODULE))) USEMODULE += xtimer endif -ifneq (,$(filter stdio_uart,$(USEMODULE))) +ifneq (,$(filter shell,$(USEMODULE))) + ifneq (,$(filter stdio_uart,$(USEMODULE))) + USEMODULE += stdio_uart_rx + endif +endif + +ifneq (,$(filter stdio_uart_rx,$(USEMODULE))) USEMODULE += isrpipe + USEMODULE += stdio_uart +endif + +ifneq (,$(filter stdio_uart,$(USEMODULE))) FEATURES_REQUIRED += periph_uart endif diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 6132f5b16d..60dd770d8f 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -67,6 +67,7 @@ PSEUDOMODULES += sock PSEUDOMODULES += sock_ip PSEUDOMODULES += sock_tcp PSEUDOMODULES += sock_udp +PSEUDOMODULES += stdio_uart_rx # print ascii representation in function od_hex_dump() PSEUDOMODULES += od_string diff --git a/sys/stdio_uart/stdio_uart.c b/sys/stdio_uart/stdio_uart.c index cb2a32a5f6..91c9ff91c6 100644 --- a/sys/stdio_uart/stdio_uart.c +++ b/sys/stdio_uart/stdio_uart.c @@ -27,6 +27,8 @@ * @} */ +#include + #include "stdio_uart.h" #include "board.h" @@ -45,16 +47,31 @@ extern ethos_t ethos; #define ENABLE_DEBUG 0 #include "debug.h" - +#ifdef MODULE_STDIO_UART_RX static char _rx_buf_mem[STDIO_UART_RX_BUFSIZE]; isrpipe_t stdio_uart_isrpipe = ISRPIPE_INIT(_rx_buf_mem); +#endif void stdio_init(void) { -#ifndef USE_ETHOS_FOR_STDIO - uart_init(STDIO_UART_DEV, STDIO_UART_BAUDRATE, (uart_rx_cb_t) isrpipe_write_one, &stdio_uart_isrpipe); + uart_rx_cb_t cb; + void *arg; + +#ifdef MODULE_STDIO_UART_RX + cb = (uart_rx_cb_t) isrpipe_write_one; + arg = &stdio_uart_isrpipe; #else - uart_init(ETHOS_UART, ETHOS_BAUDRATE, (uart_rx_cb_t) isrpipe_write_one, &stdio_uart_isrpipe); +#ifdef USE_ETHOS_FOR_STDIO +#error "ethos needs stdio_uart_rx" +#endif + cb = NULL; + arg = NULL; +#endif + +#ifndef USE_ETHOS_FOR_STDIO + uart_init(STDIO_UART_DEV, STDIO_UART_BAUDRATE, cb, arg); +#else + uart_init(ETHOS_UART, ETHOS_BAUDRATE, cb, arg); #endif #if MODULE_VFS vfs_bind_stdio(); @@ -63,7 +80,13 @@ void stdio_init(void) ssize_t stdio_read(void* buffer, size_t count) { +#ifdef MODULE_STDIO_UART_RX return (ssize_t)isrpipe_read(&stdio_uart_isrpipe, (char *)buffer, count); +#else + (void)buffer; + (void)count; + return -ENOTSUP; +#endif } ssize_t stdio_write(const void* buffer, size_t len)