From aa16766188bdb4ea73e6c92fd884eb6ea8ec93dd Mon Sep 17 00:00:00 2001 From: "Martine S. Lenders" Date: Wed, 18 Dec 2019 11:56:23 +0100 Subject: [PATCH] stdio_native: initial import --- Makefile.dep | 2 +- cpu/native/Makefile | 4 +++ cpu/native/Makefile.dep | 3 ++ cpu/native/startup.c | 3 ++ cpu/native/stdio_native/Makefile | 1 + cpu/native/stdio_native/stdio_native.c | 39 ++++++++++++++++++++++++++ 6 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 cpu/native/stdio_native/Makefile create mode 100644 cpu/native/stdio_native/stdio_native.c diff --git a/Makefile.dep b/Makefile.dep index c2f6b5bd7fb66..dde5823a2e8de 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -423,7 +423,7 @@ ifneq (,$(filter newlib,$(USEMODULE))) ifeq (,$(filter newlib_syscalls_%,$(USEMODULE))) USEMODULE += newlib_syscalls_default endif - ifeq (,$(filter stdio_cdc_acm stdio_null stdio_rtt,$(USEMODULE))) + ifeq (,$(filter stdio_cdc_acm stdio_native stdio_null stdio_rtt,$(USEMODULE))) USEMODULE += stdio_uart endif endif diff --git a/cpu/native/Makefile b/cpu/native/Makefile index cc0605cc5f4d0..b266cb783e70f 100644 --- a/cpu/native/Makefile +++ b/cpu/native/Makefile @@ -15,6 +15,10 @@ ifneq (,$(filter socket_zep,$(USEMODULE))) DIRS += socket_zep endif +ifneq (,$(filter stdio_native,$(USEMODULE))) + DIRS += stdio_native +endif + ifneq (,$(filter mtd_native,$(USEMODULE))) DIRS += mtd endif diff --git a/cpu/native/Makefile.dep b/cpu/native/Makefile.dep index 4923a58c59145..5563226643d39 100644 --- a/cpu/native/Makefile.dep +++ b/cpu/native/Makefile.dep @@ -1,3 +1,6 @@ ifneq (,$(filter periph_spi,$(USEMODULE))) USEMODULE += periph_spidev_linux endif +ifeq (,$(filter stdio_%,$(USEMODULE))) + USEMODULE += stdio_native +endif diff --git a/cpu/native/startup.c b/cpu/native/startup.c index a059621d18145..33013a46cc39e 100644 --- a/cpu/native/startup.c +++ b/cpu/native/startup.c @@ -41,6 +41,7 @@ #include "board_internal.h" #include "native_internal.h" +#include "stdio_base.h" #include "tty_uart.h" #include "periph/init.h" @@ -399,6 +400,8 @@ static void _reset_handler(void) __attribute__((constructor)) static void startup(int argc, char **argv, char **envp) { _native_init_syscalls(); + /* initialize stdio as early as possible */ + stdio_init(); _native_argv = argv; _progname = argv[0]; diff --git a/cpu/native/stdio_native/Makefile b/cpu/native/stdio_native/Makefile new file mode 100644 index 0000000000000..48422e909a47d --- /dev/null +++ b/cpu/native/stdio_native/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base diff --git a/cpu/native/stdio_native/stdio_native.c b/cpu/native/stdio_native/stdio_native.c new file mode 100644 index 0000000000000..fe2ffef233dbf --- /dev/null +++ b/cpu/native/stdio_native/stdio_native.c @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2019 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. + */ + +/** + * @{ + * + * @file + * @author Martine S. Lenders + */ + +#include "kernel_defines.h" +#include "native_internal.h" +#include "vfs.h" + +#include "stdio_base.h" + +void stdio_init(void) +{ + if (IS_USED(MODULE_VFS)) { + vfs_bind_stdio(); + } +} + +ssize_t stdio_read(void* buffer, size_t max_len) +{ + return real_read(STDIN_FILENO, buffer, max_len); +} + +ssize_t stdio_write(const void* buffer, size_t len) +{ + return real_write(STDOUT_FILENO, buffer, len); +} + +/** @} */