From 3947ce7c8a79883c964aa19d6c29988b565dd722 Mon Sep 17 00:00:00 2001 From: schodet Date: Sat, 9 Jul 2005 12:16:06 +0000 Subject: STDIO support for uart. --- n/avr/modules/uart/uart.host.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'n/avr/modules/uart/uart.host.c') 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 #include +/* 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); -- cgit v1.2.3