sys/stdio: s/rtt_stdio/stdio_rtt/
This commit is contained in:
parent
d55616a7f5
commit
9bd2363643
@ -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
|
||||
|
||||
|
||||
@ -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 */
|
||||
51
sys/include/stdio_rtt.h
Normal file
51
sys/include/stdio_rtt.h
Normal file
@ -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 */
|
||||
@ -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
|
||||
```
|
||||
@ -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;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user