Skip to content

Commit

Permalink
make stdin/stdout customizable stub
Browse files Browse the repository at this point in the history
  • Loading branch information
LudwigKnuepfer authored and OlegHahm committed Jun 12, 2013
1 parent 79b97c9 commit 0ac1462
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions 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)
Expand All @@ -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()");
}
Expand All @@ -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;
}

0 comments on commit 0ac1462

Please sign in to comment.