Skip to content

Commit

Permalink
Merge pull request #11310 from OTAkeys/make_uart_stdio_rx_optional
Browse files Browse the repository at this point in the history
sys: make uart_stdio RX optional (attempt #2)
  • Loading branch information
kaspar030 authored May 9, 2019
2 parents 793072c + 002057f commit a9f1a85
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
12 changes: 11 additions & 1 deletion Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,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

Expand Down
1 change: 1 addition & 0 deletions makefiles/pseudomodules.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,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
Expand Down
29 changes: 26 additions & 3 deletions sys/stdio_uart/stdio_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
* @}
*/

#include <errno.h>

#include "stdio_uart.h"

#include "board.h"
Expand All @@ -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)
{
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
#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, (uart_rx_cb_t) isrpipe_write_one, &stdio_uart_isrpipe);
uart_init(STDIO_UART_DEV, STDIO_UART_BAUDRATE, cb, arg);
#else
uart_init(ETHOS_UART, ETHOS_BAUDRATE, (uart_rx_cb_t) isrpipe_write_one, &stdio_uart_isrpipe);
uart_init(ETHOS_UART, ETHOS_BAUDRATE, cb, arg);
#endif
#if MODULE_VFS
vfs_bind_stdio();
Expand All @@ -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)
Expand Down

0 comments on commit a9f1a85

Please sign in to comment.