1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

make stdin/stdout customizable stub

This commit is contained in:
Ludwig Ortmann 2013-06-03 19:37:22 +02:00 committed by Oliver Hahm
parent 79b97c9946
commit 0ac14625f3

View File

@ -1,17 +1,20 @@
/* /*
* TODO: * native uart0 implementation
* make stdin/stdout customizable.
*/ */
#include <err.h> #include <err.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <sys/select.h> #include <sys/select.h>
#include "cpu.h" #include "cpu.h"
#include "debug.h" #include "debug.h"
#include "board_uart0.h" #include "board_uart0.h"
int _native_uart_in;
int _native_uart_out;
fd_set _native_uart_rfds; fd_set _native_uart_rfds;
static inline int uart0_puts(char *astring, int length) static inline int uart0_puts(char *astring, int length)
@ -24,10 +27,11 @@ void _native_handle_uart0_input()
char buf[42]; char buf[42];
int nread; int nread;
DEBUG("_native_handle_uart0_input\n");
_native_in_syscall = 0; _native_in_syscall = 0;
_native_in_isr = 1; _native_in_isr = 1;
nread = read(0, buf, sizeof(buf)); nread = read(_native_uart_in, buf, sizeof(buf));
if (nread == -1) { if (nread == -1) {
err(1, "_native_handle_uart0_input(): read()"); err(1, "_native_handle_uart0_input(): read()");
} }
@ -42,13 +46,17 @@ void _native_handle_uart0_input()
void _native_init_uart0() 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_ZERO(&_native_uart_rfds);
FD_SET(0, &_native_uart_rfds); FD_SET(_native_uart_in, &_native_uart_rfds);
puts("RIOT native uart0 initialized."); puts("RIOT native uart0 initialized.");
} }
int putchar(int c) { int putchar(int c) {
write(1, &c, 1); write(_native_uart_out, &c, 1);
return 0; return 0;
} }