Skip to content

Commit

Permalink
sys/stdio: s/uart_stdio/stdio_uart/
Browse files Browse the repository at this point in the history
  • Loading branch information
haukepetersen committed Aug 22, 2018
1 parent 717e84f commit d55616a
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 110 deletions.
4 changes: 2 additions & 2 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
59 changes: 59 additions & 0 deletions sys/include/stdio_uart.h
Original file line number Diff line number Diff line change
@@ -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 */
83 changes: 0 additions & 83 deletions sys/include/uart_stdio.h

This file was deleted.

File renamed without changes.
52 changes: 27 additions & 25 deletions sys/uart_stdio/uart_stdio.c → sys/stdio_uart/stdio_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@
* 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
* directory for more details.
*/

/**
* @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>
*
* @}
*/
Expand All @@ -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"
Expand All @@ -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(&ethos, (const uint8_t *)buffer, len, ETHOS_FRAME_TYPE_TEXT);
#endif
Expand Down

0 comments on commit d55616a

Please sign in to comment.