Skip to content

Commit

Permalink
stdio_native: initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Dec 18, 2019
1 parent 1b125b7 commit aa16766
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions cpu/native/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions cpu/native/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
ifneq (,$(filter periph_spi,$(USEMODULE)))
USEMODULE += periph_spidev_linux
endif
ifeq (,$(filter stdio_%,$(USEMODULE)))
USEMODULE += stdio_native
endif
3 changes: 3 additions & 0 deletions cpu/native/startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#include "board_internal.h"
#include "native_internal.h"
#include "stdio_base.h"
#include "tty_uart.h"

#include "periph/init.h"
Expand Down Expand Up @@ -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];
Expand Down
1 change: 1 addition & 0 deletions cpu/native/stdio_native/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base
39 changes: 39 additions & 0 deletions cpu/native/stdio_native/stdio_native.c
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*/

#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);
}

/** @} */

0 comments on commit aa16766

Please sign in to comment.