summaryrefslogtreecommitdiff
path: root/n/avr/modules/uart/uart.host.c
diff options
context:
space:
mode:
authorschodet2005-07-09 12:16:06 +0000
committerschodet2005-07-09 12:16:06 +0000
commit3947ce7c8a79883c964aa19d6c29988b565dd722 (patch)
tree14e4fa639617ffc9fc81e87b2b821b410449fc4b /n/avr/modules/uart/uart.host.c
parent5ae2619ef0052a827646009474d8a8e3f2196aa7 (diff)
STDIO support for uart.
Diffstat (limited to 'n/avr/modules/uart/uart.host.c')
-rw-r--r--n/avr/modules/uart/uart.host.c37
1 files changed, 34 insertions, 3 deletions
diff --git a/n/avr/modules/uart/uart.host.c b/n/avr/modules/uart/uart.host.c
index 661401c..5306484 100644
--- a/n/avr/modules/uart/uart.host.c
+++ b/n/avr/modules/uart/uart.host.c
@@ -38,6 +38,20 @@
#include <pty.h>
#include <fcntl.h>
+/* Check uart driver. */
+#if UART_N == 0
+# define STDIO 1
+# define PTS 2
+# if AC_UART (HOST_DRIVER) == STDIO
+# define DRIVER_STDIO
+# elif AC_UART (HOST_DRIVER) == PTS
+# else
+# error "uart: invalid host driver"
+# endif
+#endif
+
+#ifndef DRIVER_STDIO
+
/* Pseudo terminal file descriptor. */
static int uart_pt_fd;
@@ -60,10 +74,18 @@ setup_raw (int fd)
tcsetattr (fd, TCSANOW, &tc);
}
+#endif /* DRIVER_STDIO */
+
/** Initialise uart. */
void
uart_init (void)
{
+#ifdef DRIVER_STDIO
+# define uart_pt_fd_in 0
+# define uart_pt_fd_out 1
+#else
+# define uart_pt_fd_in uart_pt_fd
+# define uart_pt_fd_out uart_pt_fd
int slave_fd;
const char *name;
#define STRINGIFY(x) #x
@@ -82,6 +104,7 @@ uart_init (void)
/* Make slave raw. */
setup_raw (slave_fd);
/* slave_fd is left open. */
+#endif
}
/** Read a char. */
@@ -90,12 +113,16 @@ uart_getc (void)
{
uint8_t c;
int n;
- n = read (uart_pt_fd, &c, 1);
+ n = read (uart_pt_fd_in, &c, 1);
if (n == -1)
assert_perror (errno);
/* This is a quite unusual behavior... */
if (n == 0)
return 0xff;
+#ifdef DRIVER_STDIO
+ if (c == '\n')
+ c = '\r';
+#endif
return c;
}
@@ -103,7 +130,11 @@ uart_getc (void)
void
uart_putc (uint8_t c)
{
- write (uart_pt_fd, &c, 1);
+#ifdef DRIVER_STDIO
+ if (c == '\r')
+ c = '\n';
+#endif
+ write (uart_pt_fd_out, &c, 1);
}
/** Retrieve availlable chars. */
@@ -115,7 +146,7 @@ uart_poll (void)
int r;
/* Use select to poll. */
FD_ZERO (&fds);
- FD_SET (uart_pt_fd, &fds);
+ FD_SET (uart_pt_fd_in, &fds);
tv.tv_sec = 0;
tv.tv_usec = 0;
r = select (FD_SETSIZE, &fds, 0, 0, &tv);