diff --git a/drivers/Makefile.dep b/drivers/Makefile.dep index 0940945c31..024b604a09 100644 --- a/drivers/Makefile.dep +++ b/drivers/Makefile.dep @@ -48,6 +48,10 @@ ifneq (,$(filter ccs811_%,$(USEMODULE))) USEMODULE += ccs811 endif +ifneq (,$(filter ethos_%,$(USEMODULE))) + USEMODULE += ethos +endif + ifneq (,$(filter hmc5883l_%,$(USEMODULE))) USEMODULE += hmc5883l endif diff --git a/drivers/ethos/Makefile b/drivers/ethos/Makefile index 48422e909a..7c6f250804 100644 --- a/drivers/ethos/Makefile +++ b/drivers/ethos/Makefile @@ -1 +1,7 @@ +# exclude submodule sources from *.c wildcard source selection +SRC := $(filter-out stdio.c,$(wildcard *.c)) + +# enable submodules +SUBMODULES := 1 + include $(RIOTBASE)/Makefile.base diff --git a/drivers/ethos/Makefile.dep b/drivers/ethos/Makefile.dep index f2cb64f153..4ed515dcdc 100644 --- a/drivers/ethos/Makefile.dep +++ b/drivers/ethos/Makefile.dep @@ -3,3 +3,7 @@ USEMODULE += iolist USEMODULE += netdev_eth USEMODULE += random USEMODULE += tsrb + +ifneq (,$(filter ethos_stdio,$(USEMODULE))) + USEMODULE += isrpipe +endif diff --git a/drivers/ethos/ethos.c b/drivers/ethos/ethos.c index 8fd83b8692..ff9b7b586b 100644 --- a/drivers/ethos/ethos.c +++ b/drivers/ethos/ethos.c @@ -40,7 +40,7 @@ #ifdef MODULE_STDIO_ETHOS #include "stdio_uart.h" #include "isrpipe.h" -extern isrpipe_t stdio_uart_isrpipe; +extern isrpipe_t ethos_stdio_isrpipe; #endif #define ENABLE_DEBUG 0 @@ -106,7 +106,7 @@ static void _handle_char(ethos_t *dev, char c) #ifdef MODULE_STDIO_ETHOS case ETHOS_FRAME_TYPE_TEXT: dev->framesize++; - isrpipe_write_one(&stdio_uart_isrpipe, c); + isrpipe_write_one(ðos_stdio_isrpipe, c); #endif } } diff --git a/drivers/ethos/stdio.c b/drivers/ethos/stdio.c new file mode 100644 index 0000000000..0d97248e14 --- /dev/null +++ b/drivers/ethos/stdio.c @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2013 INRIA + * 2015 Kaspar Schleiser + * 2016 Eistec AB + * 2018-21 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @{ + * + * @file + * @author Oliver Hahm + * @author Ludwig Knüpfer + * @author Kaspar Schleiser + * @author Joakim Nohlgård + * @author Hauke Petersen + * @author Martine S. Lenders + */ + +#include "ethos.h" +#include "isrpipe.h" +#include "stdio_uart.h" + +extern ethos_t ethos; + +static uint8_t _rx_buf_mem[STDIO_UART_RX_BUFSIZE]; +isrpipe_t ethos_stdio_isrpipe = ISRPIPE_INIT(_rx_buf_mem); + +static void _isrpipe_write(void *arg, uint8_t data) +{ + isrpipe_write_one(arg, (char)data); +} + +void stdio_init(void) +{ + uart_init(ETHOS_UART, ETHOS_BAUDRATE, _isrpipe_write, ðos_stdio_isrpipe); + +#if MODULE_VFS + vfs_bind_stdio(); +#endif +} + +extern unsigned ethos_unstuff_readbyte(uint8_t *buf, uint8_t byte, + bool *escaped, uint8_t *frametype); + +ssize_t stdio_read(void* buffer, size_t len) +{ + return (ssize_t)isrpipe_read(ðos_stdio_isrpipe, buffer, len); +} + +ssize_t stdio_write(const void* buffer, size_t len) +{ + ethos_send_frame(ðos, (const uint8_t *)buffer, len, ETHOS_FRAME_TYPE_TEXT); + return len; +} + +/** @} */ diff --git a/drivers/include/ethos.h b/drivers/include/ethos.h index 6a36f8e3e9..fec36a934b 100644 --- a/drivers/include/ethos.h +++ b/drivers/include/ethos.h @@ -34,7 +34,7 @@ extern "C" { #endif /* if using ethos + stdio, use STDIO_UART values unless overridden */ -#if IS_USED(MODULE_STDIO_ETHOS) || defined(DOXYGEN) +#if IS_USED(MODULE_ETHOS_STDIO) || defined(DOXYGEN) #include "stdio_uart.h" /** * @defgroup drivers_ethos_config Ethernet-over-serial driver driver compile configuration diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 753b1708f7..6032855e65 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -24,6 +24,7 @@ PSEUDOMODULES += dhcpv6_client_mud_url PSEUDOMODULES += dhcpv6_relay PSEUDOMODULES += dns_msg PSEUDOMODULES += ecc_% +PSEUDOMODULES += ethos_stdio PSEUDOMODULES += event_% PSEUDOMODULES += event_timeout PSEUDOMODULES += event_timeout_ztimer diff --git a/makefiles/stdio.inc.mk b/makefiles/stdio.inc.mk index 7d75fa7083..27da93b496 100644 --- a/makefiles/stdio.inc.mk +++ b/makefiles/stdio.inc.mk @@ -24,9 +24,8 @@ ifneq (,$(filter stdio_rtt,$(USEMODULE))) endif ifneq (,$(filter stdio_ethos,$(USEMODULE))) - USEMODULE += ethos + USEMODULE += ethos_stdio USEMODULE += stdin - USEMODULE += stdio_uart endif ifneq (,$(filter stdin,$(USEMODULE))) diff --git a/sys/stdio_uart/stdio_uart.c b/sys/stdio_uart/stdio_uart.c index 60eb1a83bb..21f715be5b 100644 --- a/sys/stdio_uart/stdio_uart.c +++ b/sys/stdio_uart/stdio_uart.c @@ -35,11 +35,6 @@ #include "periph/uart.h" #include "isrpipe.h" -#ifdef MODULE_STDIO_ETHOS -#include "ethos.h" -extern ethos_t ethos; -#endif - #if MODULE_VFS #include "vfs.h" #endif @@ -65,11 +60,7 @@ void stdio_init(void) arg = NULL; #endif -#ifdef MODULE_STDIO_ETHOS - uart_init(ETHOS_UART, ETHOS_BAUDRATE, cb, arg); -#else uart_init(STDIO_UART_DEV, STDIO_UART_BAUDRATE, cb, arg); -#endif #if MODULE_VFS vfs_bind_stdio(); @@ -89,10 +80,6 @@ ssize_t stdio_read(void* buffer, size_t count) ssize_t stdio_write(const void* buffer, size_t len) { -#ifdef MODULE_STDIO_ETHOS - ethos_send_frame(ðos, (const uint8_t *)buffer, len, ETHOS_FRAME_TYPE_TEXT); -#else uart_write(STDIO_UART_DEV, (const uint8_t *)buffer, len); -#endif return len; }