mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 10:32:44 +01:00
sys/stdio: s/uart_stdio/stdio_uart/
This commit is contained in:
parent
717e84f7b2
commit
d55616a7f5
@ -374,7 +374,7 @@ ifneq (,$(filter newlib,$(USEMODULE)))
|
||||
USEMODULE += newlib_syscalls_default
|
||||
endif
|
||||
ifeq (,$(filter rtt_stdio,$(USEMODULE)))
|
||||
USEMODULE += uart_stdio
|
||||
USEMODULE += stdio_uart
|
||||
endif
|
||||
endif
|
||||
|
||||
@ -390,7 +390,7 @@ ifneq (,$(filter rtt_stdio,$(USEMODULE)))
|
||||
USEMODULE += xtimer
|
||||
endif
|
||||
|
||||
ifneq (,$(filter uart_stdio,$(USEMODULE)))
|
||||
ifneq (,$(filter stdio_uart,$(USEMODULE)))
|
||||
USEMODULE += isrpipe
|
||||
FEATURES_REQUIRED += periph_uart
|
||||
endif
|
||||
|
59
sys/include/stdio_uart.h
Normal file
59
sys/include/stdio_uart.h
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
* 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_uart STDIO over UART
|
||||
* @ingroup sys
|
||||
*
|
||||
* @brief Standard input/output backend using UART
|
||||
*
|
||||
* @{
|
||||
* @file
|
||||
*
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
*/
|
||||
|
||||
#ifndef STDIO_UART_H
|
||||
#define STDIO_UART_H
|
||||
|
||||
/* Boards may override the default STDIO UART device */
|
||||
#include "board.h"
|
||||
#include "stdio_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef STDIO_UART_DEV
|
||||
/**
|
||||
* @brief UART device to use for STDIO
|
||||
*/
|
||||
#define STDIO_UART_DEV UART_DEV(0)
|
||||
#endif
|
||||
|
||||
#ifndef STDIO_UART_BAUDRATE
|
||||
/**
|
||||
* @brief Baudrate for STDIO
|
||||
*/
|
||||
#define STDIO_UART_BAUDRATE (115200)
|
||||
#endif
|
||||
|
||||
#ifndef STDIO_UART_RX_BUFSIZE
|
||||
/**
|
||||
* @brief Buffer size for STDIO
|
||||
*/
|
||||
#define STDIO_UART_RX_BUFSIZE (64)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/** @} */
|
||||
#endif /* STDIO_UART_H */
|
@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* 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_uart_stdio UART stdio
|
||||
* @ingroup sys
|
||||
*
|
||||
* @brief stdio init/read/write functions for UARTs
|
||||
*
|
||||
* @{
|
||||
* @file
|
||||
*
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*/
|
||||
#ifndef UART_STDIO_H
|
||||
#define UART_STDIO_H
|
||||
|
||||
/* Boards may override the default STDIO UART device */
|
||||
#include <stdint.h>
|
||||
#include "board.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef UART_STDIO_DEV
|
||||
/**
|
||||
* @brief UART device to use for STDIO
|
||||
*/
|
||||
#define UART_STDIO_DEV UART_DEV(0)
|
||||
#endif
|
||||
|
||||
#ifndef UART_STDIO_BAUDRATE
|
||||
/**
|
||||
* @brief Baudrate for STDIO
|
||||
*/
|
||||
#define UART_STDIO_BAUDRATE (115200)
|
||||
#endif
|
||||
|
||||
#ifndef UART_STDIO_RX_BUFSIZE
|
||||
/**
|
||||
* @brief Buffer size for STDIO
|
||||
*/
|
||||
#define UART_STDIO_RX_BUFSIZE (64)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief initialize the module
|
||||
*/
|
||||
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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/** @} */
|
||||
#endif /* UART_STDIO_H */
|
@ -2,6 +2,7 @@
|
||||
* Copyright (C) 2013 INRIA
|
||||
* 2015 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
* 2016 Eistec AB
|
||||
* 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
|
||||
@ -9,18 +10,19 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup sys
|
||||
* @ingroup sys
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief UART stdio implementation
|
||||
* @brief STDIO over UART implementation
|
||||
*
|
||||
* This file implements a UART callback and read/write functions.
|
||||
* This file implements a UART callback and the STDIO read/write functions
|
||||
*
|
||||
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
||||
* @author Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.de>
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
* @author Joakim Nohlgård <joakim.nohlgard@eistec.se>
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
@ -31,7 +33,7 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#include "uart_stdio.h"
|
||||
#include "stdio_uart.h"
|
||||
|
||||
#include "board.h"
|
||||
#include "periph/uart.h"
|
||||
@ -49,73 +51,73 @@ extern ethos_t ethos;
|
||||
#define ENABLE_DEBUG 0
|
||||
#include "debug.h"
|
||||
|
||||
static char _rx_buf_mem[UART_STDIO_RX_BUFSIZE];
|
||||
isrpipe_t uart_stdio_isrpipe = ISRPIPE_INIT(_rx_buf_mem);
|
||||
static char _rx_buf_mem[STDIO_UART_RX_BUFSIZE];
|
||||
isrpipe_t stdio_uart_isrpipe = ISRPIPE_INIT(_rx_buf_mem);
|
||||
|
||||
#if MODULE_VFS
|
||||
static ssize_t uart_stdio_vfs_read(vfs_file_t *filp, void *dest, size_t nbytes);
|
||||
static ssize_t uart_stdio_vfs_write(vfs_file_t *filp, const void *src, size_t nbytes);
|
||||
static ssize_t stdio_uart_vfs_read(vfs_file_t *filp, void *dest, size_t nbytes);
|
||||
static ssize_t stdio_uart_vfs_write(vfs_file_t *filp, const void *src, size_t nbytes);
|
||||
|
||||
/**
|
||||
* @brief VFS file operation table for stdin/stdout/stderr
|
||||
*/
|
||||
static vfs_file_ops_t uart_stdio_vfs_ops = {
|
||||
.read = uart_stdio_vfs_read,
|
||||
.write = uart_stdio_vfs_write,
|
||||
static vfs_file_ops_t stdio_uart_vfs_ops = {
|
||||
.read = stdio_uart_vfs_read,
|
||||
.write = stdio_uart_vfs_write,
|
||||
};
|
||||
|
||||
static ssize_t uart_stdio_vfs_read(vfs_file_t *filp, void *dest, size_t nbytes)
|
||||
static ssize_t stdio_uart_vfs_read(vfs_file_t *filp, void *dest, size_t nbytes)
|
||||
{
|
||||
int fd = filp->private_data.value;
|
||||
if (fd != STDIN_FILENO) {
|
||||
return -EBADF;
|
||||
}
|
||||
return uart_stdio_read(dest, nbytes);
|
||||
return stdio_uart_read(dest, nbytes);
|
||||
}
|
||||
|
||||
static ssize_t uart_stdio_vfs_write(vfs_file_t *filp, const void *src, size_t nbytes)
|
||||
static ssize_t stdio_uart_vfs_write(vfs_file_t *filp, const void *src, size_t nbytes)
|
||||
{
|
||||
int fd = filp->private_data.value;
|
||||
if (fd == STDIN_FILENO) {
|
||||
return -EBADF;
|
||||
}
|
||||
return uart_stdio_write(src, nbytes);
|
||||
return stdio_uart_write(src, nbytes);
|
||||
}
|
||||
#endif
|
||||
|
||||
void uart_stdio_init(void)
|
||||
void stdio_init(void)
|
||||
{
|
||||
#ifndef USE_ETHOS_FOR_STDIO
|
||||
uart_init(UART_STDIO_DEV, UART_STDIO_BAUDRATE, (uart_rx_cb_t) isrpipe_write_one, &uart_stdio_isrpipe);
|
||||
uart_init(STDIO_UART_DEV, STDIO_UART_BAUDRATE, (uart_rx_cb_t) isrpipe_write_one, &stdio_uart_isrpipe);
|
||||
#else
|
||||
uart_init(ETHOS_UART, ETHOS_BAUDRATE, (uart_rx_cb_t) isrpipe_write_one, &uart_stdio_isrpipe);
|
||||
uart_init(ETHOS_UART, ETHOS_BAUDRATE, (uart_rx_cb_t) isrpipe_write_one, &stdio_uart_isrpipe);
|
||||
#endif
|
||||
#if MODULE_VFS
|
||||
int fd;
|
||||
fd = vfs_bind(STDIN_FILENO, O_RDONLY, &uart_stdio_vfs_ops, (void *)STDIN_FILENO);
|
||||
fd = vfs_bind(STDIN_FILENO, O_RDONLY, &stdio_uart_vfs_ops, (void *)STDIN_FILENO);
|
||||
if (fd < 0) {
|
||||
/* How to handle errors on init? */
|
||||
}
|
||||
fd = vfs_bind(STDOUT_FILENO, O_WRONLY, &uart_stdio_vfs_ops, (void *)STDOUT_FILENO);
|
||||
fd = vfs_bind(STDOUT_FILENO, O_WRONLY, &stdio_uart_vfs_ops, (void *)STDOUT_FILENO);
|
||||
if (fd < 0) {
|
||||
/* How to handle errors on init? */
|
||||
}
|
||||
fd = vfs_bind(STDERR_FILENO, O_WRONLY, &uart_stdio_vfs_ops, (void *)STDERR_FILENO);
|
||||
fd = vfs_bind(STDERR_FILENO, O_WRONLY, &stdio_uart_vfs_ops, (void *)STDERR_FILENO);
|
||||
if (fd < 0) {
|
||||
/* How to handle errors on init? */
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int uart_stdio_read(char* buffer, int count)
|
||||
ssize_t stdio_read(void* buffer, size_t count)
|
||||
{
|
||||
return isrpipe_read(&uart_stdio_isrpipe, buffer, count);
|
||||
return (ssize_t)isrpipe_read(&stdio_uart_isrpipe, (char *)buffer, count);
|
||||
}
|
||||
|
||||
int uart_stdio_write(const char* buffer, int len)
|
||||
ssize_t stdio_write(const void* buffer, size_t len)
|
||||
{
|
||||
#ifndef USE_ETHOS_FOR_STDIO
|
||||
uart_write(UART_STDIO_DEV, (const uint8_t *)buffer, (size_t)len);
|
||||
uart_write(STDIO_UART_DEV, (const uint8_t *)buffer, len);
|
||||
#else
|
||||
ethos_send_frame(ðos, (const uint8_t *)buffer, len, ETHOS_FRAME_TYPE_TEXT);
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user