2013-05-15 16:04:48 +02:00
|
|
|
/*
|
2013-06-03 19:37:22 +02:00
|
|
|
* native uart0 implementation
|
2013-05-15 16:04:48 +02:00
|
|
|
*/
|
|
|
|
|
2013-05-14 17:42:08 +02:00
|
|
|
#include <err.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
2013-06-03 19:37:22 +02:00
|
|
|
|
2013-05-14 17:42:08 +02:00
|
|
|
#include <sys/select.h>
|
|
|
|
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "board_uart0.h"
|
|
|
|
|
2013-06-03 19:37:22 +02:00
|
|
|
int _native_uart_in;
|
|
|
|
int _native_uart_out;
|
|
|
|
|
2013-05-14 17:42:08 +02:00
|
|
|
fd_set _native_uart_rfds;
|
|
|
|
|
2013-07-15 20:57:12 +02:00
|
|
|
inline int uart0_puts(char *astring, int length)
|
2013-05-14 17:42:08 +02:00
|
|
|
{
|
|
|
|
return puts(astring);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _native_handle_uart0_input()
|
|
|
|
{
|
|
|
|
char buf[42];
|
|
|
|
int nread;
|
|
|
|
|
2013-07-16 17:57:52 +02:00
|
|
|
if (!FD_ISSET(_native_uart_in, &_native_rfds)) {
|
|
|
|
DEBUG("_native_handle_uart0_input - nothing to do\n");
|
|
|
|
return;
|
|
|
|
}
|
2013-06-03 19:37:22 +02:00
|
|
|
DEBUG("_native_handle_uart0_input\n");
|
2013-05-14 17:42:08 +02:00
|
|
|
_native_in_syscall = 0;
|
|
|
|
_native_in_isr = 1;
|
|
|
|
|
2013-06-03 19:37:22 +02:00
|
|
|
nread = read(_native_uart_in, buf, sizeof(buf));
|
2013-05-14 17:42:08 +02:00
|
|
|
if (nread == -1) {
|
|
|
|
err(1, "_native_handle_uart0_input(): read()");
|
|
|
|
}
|
|
|
|
for(int pos = 0; pos < nread; pos++) {
|
|
|
|
uart0_handle_incoming(buf[pos]);
|
|
|
|
}
|
|
|
|
uart0_notify_thread();
|
|
|
|
|
|
|
|
_native_in_isr = 0;
|
|
|
|
cpu_switch_context_exit();
|
|
|
|
}
|
|
|
|
|
2013-07-16 17:57:52 +02:00
|
|
|
int _native_set_uart_fds(void)
|
|
|
|
{
|
|
|
|
DEBUG("_native_set_uart_fds");
|
|
|
|
FD_SET(_native_uart_in, &_native_rfds);
|
|
|
|
return _native_uart_in;
|
|
|
|
}
|
|
|
|
|
2013-05-14 17:42:08 +02:00
|
|
|
void _native_init_uart0()
|
|
|
|
{
|
2013-06-03 19:37:22 +02:00
|
|
|
_native_uart_out = STDOUT_FILENO;
|
|
|
|
_native_uart_in = STDIN_FILENO;
|
|
|
|
|
2013-05-14 17:42:08 +02:00
|
|
|
puts("RIOT native uart0 initialized.");
|
|
|
|
}
|
2013-05-15 16:04:48 +02:00
|
|
|
|
|
|
|
int putchar(int c) {
|
2013-06-03 19:37:22 +02:00
|
|
|
write(_native_uart_out, &c, 1);
|
2013-05-15 16:04:48 +02:00
|
|
|
return 0;
|
|
|
|
}
|