diff --git a/Makefile.dep b/Makefile.dep index 7a4f918147da89a9b03231c9c65ff6cfa485f684..b511ca08e62ce89576bef929f7b8813be07a0f74 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -373,7 +373,7 @@ ifneq (,$(filter newlib,$(USEMODULE))) ifeq (,$(filter newlib_syscalls_%,$(USEMODULE))) USEMODULE += newlib_syscalls_default endif - ifeq (,$(filter rtt_stdio,$(USEMODULE))) + ifeq (,$(filter stdio_rtt,$(USEMODULE))) USEMODULE += stdio_uart endif endif @@ -386,7 +386,7 @@ ifneq (,$(filter posix_sockets,$(USEMODULE))) USEMODULE += xtimer endif -ifneq (,$(filter rtt_stdio,$(USEMODULE))) +ifneq (,$(filter stdio_rtt,$(USEMODULE))) USEMODULE += xtimer endif diff --git a/sys/include/rtt_stdio.h b/sys/include/rtt_stdio.h deleted file mode 100644 index 2ce337420eed28aa53f44163ab3f71d81efd421e..0000000000000000000000000000000000000000 --- a/sys/include/rtt_stdio.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2016 Michael Andersen <m.andersen@berkeley.edu> - * - * 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. - */ - -/** - * @defgroup sys_rtt_stdio SEGGER RTT stdio - * @ingroup sys - * - * @brief stdio init/read/write functions for SEGGER RTT. This is - * designed to shadow the functions in uart_stdio - * - * @{ - * @file - * - * @author Michael Andersen <m.andersen@cs.berkeley.edu> - */ -#ifndef RTT_STDIO_H -#define RTT_STDIO_H - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief initialize the module. This is a noop. - */ -void uart_stdio_init(void); - -/** - * @brief read @p len bytes from stdio uart into @p buffer - * - * @param[out] buffer buffer to read into - * @param[in] len nr of bytes to read - * - * @return nr of bytes read - * @return <0 on error - */ -int uart_stdio_read(char* buffer, int len); - -/** - * @brief write @p len bytes from @p buffer into uart - * - * @param[in] buffer buffer to read from - * @param[in] len nr of bytes to write - * - * @return nr of bytes written - * @return <0 on error - */ -int uart_stdio_write(const char* buffer, int len); - -/** - * @brief enable stdin polling, at a power consumption cost. This is enabled - * by default unless RTT_STDIO_DISABLE_STDIN is defined. - */ -void rtt_stdio_enable_stdin(void); - -/** - * @brief enable stdout blocking and free space polling. This must be done - * with caution because if there is no RTT client attached, all - * writes to stdout will block indefinitely. This can be enabled - * automatically by defining RTT_STDIO_ENABLE_BLOCKING_STDOUT - */ -void rtt_stdio_enable_blocking_stdout(void); - -#ifdef __cplusplus -} -#endif -/** @} */ -#endif /* RTT_STDIO_H */ diff --git a/sys/include/stdio_rtt.h b/sys/include/stdio_rtt.h new file mode 100644 index 0000000000000000000000000000000000000000..8d3b03de5e1c868fbada7751d8f504634289734f --- /dev/null +++ b/sys/include/stdio_rtt.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2016 Michael Andersen <m.andersen@berkeley.edu> + * 2018 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. + */ + +/** + * @defgroup sys_stdio_rtt STDIO over SEGGER RTT + * @ingroup sys + * + * @brief STDIO mapping for running the STDIO over SEGGER's RTT interface + * + * @{ + * @file + * + * @author Michael Andersen <m.andersen@cs.berkeley.edu> + * @author Hauke Petersen <hauke.petersen@fu-berlin.de> + */ + +#ifndef STDIO_RTT_H +#define STDIO_RTT_H + +#include "stdio_base.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief enable stdin polling, at a power consumption cost. This is enabled + * by default unless STDIO_RTT_DISABLE_STDIN is defined. + */ +void rtt_stdio_enable_stdin(void); + +/** + * @brief enable stdout blocking and free space polling. This must be done + * with caution because if there is no RTT client attached, all + * writes to stdout will block indefinitely. This can be enabled + * automatically by defining STDIO_RTT_ENABLE_BLOCKING_STDOUT + */ +void rtt_stdio_enable_blocking_stdout(void); + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif /* STDIO_RTT_H */ diff --git a/sys/rtt_stdio/Makefile b/sys/stdio_rtt/Makefile similarity index 100% rename from sys/rtt_stdio/Makefile rename to sys/stdio_rtt/Makefile diff --git a/sys/rtt_stdio/README.md b/sys/stdio_rtt/README.md similarity index 93% rename from sys/rtt_stdio/README.md rename to sys/stdio_rtt/README.md index abd868f2a67e1246453301e5dde37457da1b5ce6..e42bc28be847e0278fb0f9bc05919285a946a856 100644 --- a/sys/rtt_stdio/README.md +++ b/sys/stdio_rtt/README.md @@ -11,7 +11,7 @@ and enables stdio on platforms that do not have a UART. To use this module, add ``` -USEMODULE += rtt_stdio +USEMODULE += stdio_rtt ``` to your makefile. By default the module will drop bytes written to stdout if the @@ -19,7 +19,7 @@ buffer is full. If you know for certain that the debugger is attached, you can obtain lossless stdout by adding ``` -CFLAGS += -DRTT_STDIO_ENABLE_BLOCKING_STDOUT +CFLAGS += -DSTDIO_RTT_ENABLE_BLOCKING_STDOUT ``` to your makefile. Note well that if you do NOT plug in the debugger and run @@ -41,5 +41,5 @@ can increase the number of unnecessary wakeups from sleep. To disable stdin, add this to your makefile: ``` -CFLAGS += -DRTT_STDIO_DISABLE_STDIN +CFLAGS += -DSTDIO_RTT_DISABLE_STDIN ``` diff --git a/sys/rtt_stdio/rtt_stdio.c b/sys/stdio_rtt/stdio_rtt.c similarity index 95% rename from sys/rtt_stdio/rtt_stdio.c rename to sys/stdio_rtt/stdio_rtt.c index d829f77580dbab1edbeb664b7e8daff78de8dc44..692d3aea146ad0ccfc022084f14bc6358fe4eb87 100644 --- a/sys/rtt_stdio/rtt_stdio.c +++ b/sys/stdio_rtt/stdio_rtt.c @@ -67,10 +67,8 @@ * @file * @brief SEGGER RTT stdio implementation * - * This file implements UART read/write functions, but it - * is actually a virtual UART backed by a ringbuffer that - * complies with SEGGER RTT. It is designed to shadow - * uart_stdio that is used by newlib. + * This file implements RIOTs STDIO interface and works with a ringbuffer that + * complies with SEGGER RTT. * * @author Michael Andersen <m.andersen@cs.berkeley.edu> * @@ -84,8 +82,8 @@ #include <fcntl.h> #endif #include <string.h> -#include <rtt_stdio.h> +#include "stdio_rtt.h" #include "thread.h" #include "mutex.h" #include "xtimer.h" @@ -319,12 +317,12 @@ static ssize_t rtt_stdio_vfs_write(vfs_file_t *filp, const void *src, size_t nby #endif -void uart_stdio_init(void) { - #ifndef RTT_STDIO_DISABLE_STDIN +void stdio_init(void) { + #ifndef STDIO_RTT_DISABLE_STDIN stdin_enabled = 1; #endif - #ifdef RTT_STDIO_ENABLE_BLOCKING_STDOUT + #ifdef STDIO_RTT_ENABLE_BLOCKING_STDOUT blocking_stdout = 1; #endif @@ -363,8 +361,8 @@ void rtt_stdio_enable_blocking_stdout(void) { actually have an RTT console (because we are deployed on a battery somewhere) then we REALLY don't want to poll especially since we are not expecting to EVER get input. */ -int uart_stdio_read(char* buffer, int count) { - int res = rtt_read(buffer, count); +ssize_t stdio_read(void* buffer, size_t count) { + int res = rtt_read((void *)buffer, (uint16_t)count); if (res == 0) { if (!stdin_enabled) { mutex_lock(&_rx_mutex); @@ -379,15 +377,16 @@ int uart_stdio_read(char* buffer, int count) { return res; } } - return res; + return (ssize_t)res; } -int uart_stdio_write(const char* buffer, int len) { - int written = rtt_write(buffer, len); +ssize_t stdio_write(const void* in, size_t len) { + const char *buffer = (const char *)in; + int written = rtt_write(buffer, (unsigned)len); xtimer_ticks32_t last_wakeup = xtimer_now(); - while (blocking_stdout && written < len) { + while (blocking_stdout && ((size_t)written < len)) { xtimer_periodic_wakeup(&last_wakeup, STDIO_POLL_INTERVAL); written += rtt_write(&buffer[written], len-written); } - return written; + return (ssize_t)written; }