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/proto/test/avrconfig.h | 6 ++++- n/avr/modules/uart/avrconfig.h | 6 ++++- n/avr/modules/uart/test/avrconfig_polling.h | 4 +++ n/avr/modules/uart/test/avrconfig_ring.h | 4 +++ n/avr/modules/uart/test/avrconfig_twoports.h | 4 +++ n/avr/modules/uart/uart.host.c | 37 +++++++++++++++++++++++++--- 6 files changed, 56 insertions(+), 5 deletions(-) (limited to 'n/avr') diff --git a/n/avr/modules/proto/test/avrconfig.h b/n/avr/modules/proto/test/avrconfig.h index 08d7418..20cdbfb 100644 --- a/n/avr/modules/proto/test/avrconfig.h +++ b/n/avr/modules/proto/test/avrconfig.h @@ -56,6 +56,10 @@ * - DROP: drop the new byte. * - WAIT: wait until there is room in the send buffer. */ #define AC_UART0_SEND_BUFFER_FULL WAIT +/** In HOST compilation: + * - STDIO: use stdin/out. + * - PTS: use pseudo terminal. */ +#define AC_UART0_HOST_DRIVER PTS /** Same thing for secondary port. */ #define AC_UART1_PORT -1 #define AC_UART1_BAUDRATE 115200 @@ -66,7 +70,7 @@ #define AC_UART1_STOP_BITS 1 #define AC_UART1_SEND_BUFFER_SIZE 32 #define AC_UART1_RECV_BUFFER_SIZE 32 -#define AC_UART0_SEND_BUFFER_FULL WAIT +#define AC_UART1_SEND_BUFFER_FULL WAIT /* proto - Protocol module. */ /** Maximum argument size. */ diff --git a/n/avr/modules/uart/avrconfig.h b/n/avr/modules/uart/avrconfig.h index 0710835..c52072c 100644 --- a/n/avr/modules/uart/avrconfig.h +++ b/n/avr/modules/uart/avrconfig.h @@ -51,6 +51,10 @@ * - DROP: drop the new byte. * - WAIT: wait until there is room in the send buffer. */ #define AC_UART0_SEND_BUFFER_FULL WAIT +/** In HOST compilation: + * - STDIO: use stdin/out. + * - PTS: use pseudo terminal. */ +#define AC_UART0_HOST_DRIVER PTS /** Same thing for secondary port. */ #define AC_UART1_PORT -1 #define AC_UART1_BAUDRATE 115200 @@ -61,6 +65,6 @@ #define AC_UART1_STOP_BITS 1 #define AC_UART1_SEND_BUFFER_SIZE 32 #define AC_UART1_RECV_BUFFER_SIZE 32 -#define AC_UART0_SEND_BUFFER_FULL WAIT +#define AC_UART1_SEND_BUFFER_FULL WAIT #endif /* avrconfig_h */ diff --git a/n/avr/modules/uart/test/avrconfig_polling.h b/n/avr/modules/uart/test/avrconfig_polling.h index f56a2e1..81e5f0e 100644 --- a/n/avr/modules/uart/test/avrconfig_polling.h +++ b/n/avr/modules/uart/test/avrconfig_polling.h @@ -56,6 +56,10 @@ * - DROP: drop the new byte. * - WAIT: wait until there is room in the send buffer. */ #define AC_UART0_SEND_BUFFER_FULL WAIT +/** In HOST compilation: + * - STDIO: use stdin/out. + * - PTS: use pseudo terminal. */ +#define AC_UART0_HOST_DRIVER STDIO /** Same thing for secondary port. */ #define AC_UART1_PORT -1 #define AC_UART1_BAUDRATE 115200 diff --git a/n/avr/modules/uart/test/avrconfig_ring.h b/n/avr/modules/uart/test/avrconfig_ring.h index 5d80b62..e712d05 100644 --- a/n/avr/modules/uart/test/avrconfig_ring.h +++ b/n/avr/modules/uart/test/avrconfig_ring.h @@ -56,6 +56,10 @@ * - DROP: drop the new byte. * - WAIT: wait until there is room in the send buffer. */ #define AC_UART0_SEND_BUFFER_FULL WAIT +/** In HOST compilation: + * - STDIO: use stdin/out. + * - PTS: use pseudo terminal. */ +#define AC_UART0_HOST_DRIVER PTS /** Same thing for secondary port. */ #define AC_UART1_PORT -1 #define AC_UART1_BAUDRATE 115200 diff --git a/n/avr/modules/uart/test/avrconfig_twoports.h b/n/avr/modules/uart/test/avrconfig_twoports.h index e9551dd..07993fc 100644 --- a/n/avr/modules/uart/test/avrconfig_twoports.h +++ b/n/avr/modules/uart/test/avrconfig_twoports.h @@ -56,6 +56,10 @@ * - DROP: drop the new byte. * - WAIT: wait until there is room in the send buffer. */ #define AC_UART0_SEND_BUFFER_FULL DROP +/** In HOST compilation: + * - STDIO: use stdin/out. + * - PTS: use pseudo terminal. */ +#define AC_UART0_HOST_DRIVER PTS /** Same thing for secondary port. */ #define AC_UART1_PORT 1 #define AC_UART1_BAUDRATE 115200 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