diff --git a/native/native-uart0.c b/native/native-uart0.c index e13447bb0eae518c1af653c9be38018548c68bb9..b43a7dcbe4fa5119de49b902ab100a8d4d3fd02c 100644 --- a/native/native-uart0.c +++ b/native/native-uart0.c @@ -1,17 +1,20 @@ /* - * TODO: - * make stdin/stdout customizable. + * native uart0 implementation */ #include <err.h> #include <stdio.h> #include <unistd.h> + #include <sys/select.h> #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; }