From 0ac14625f36af000a618ab86b691349911b7910c Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Mon, 3 Jun 2013 19:37:22 +0200 Subject: [PATCH] make stdin/stdout customizable stub --- native/native-uart0.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/native/native-uart0.c b/native/native-uart0.c index e13447bb0eae..b43a7dcbe4fa 100644 --- a/native/native-uart0.c +++ b/native/native-uart0.c @@ -1,17 +1,20 @@ /* - * TODO: - * make stdin/stdout customizable. + * native uart0 implementation */ #include #include #include + #include #include "cpu.h" #include "debug.h" #include "board_uart0.h" +int _native_uart_in; +int _native_uart_out; + fd_set _native_uart_rfds; static inline int uart0_puts(char *astring, int length) @@ -24,10 +27,11 @@ void _native_handle_uart0_input() char buf[42]; int nread; + DEBUG("_native_handle_uart0_input\n"); _native_in_syscall = 0; _native_in_isr = 1; - nread = read(0, buf, sizeof(buf)); + nread = read(_native_uart_in, buf, sizeof(buf)); if (nread == -1) { err(1, "_native_handle_uart0_input(): read()"); } @@ -42,13 +46,17 @@ void _native_handle_uart0_input() void _native_init_uart0() { - /* Watch stdin (fd 0) to see when it has input. */ + _native_uart_out = STDOUT_FILENO; + _native_uart_in = STDIN_FILENO; + + /* set fds for select in lpm */ FD_ZERO(&_native_uart_rfds); - FD_SET(0, &_native_uart_rfds); + FD_SET(_native_uart_in, &_native_uart_rfds); + puts("RIOT native uart0 initialized."); } int putchar(int c) { - write(1, &c, 1); + write(_native_uart_out, &c, 1); return 0; }