From c1aa462b9cecd5d3e6010395f210e44ddafe632b Mon Sep 17 00:00:00 2001 From: schodet Date: Sat, 8 Oct 2005 13:58:07 +0000 Subject: Utilise le module host. --- n/avr/modules/uart/uart.host.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 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 5306484..e39b15a 100644 --- a/n/avr/modules/uart/uart.host.c +++ b/n/avr/modules/uart/uart.host.c @@ -25,6 +25,7 @@ #define _GNU_SOURCE #include "common.h" #include "uart.h" +#include "modules/host/host.h" #include "uart_common.h" @@ -90,20 +91,27 @@ uart_init (void) const char *name; #define STRINGIFY(x) #x #define FILE_NAME(x) "uart" STRINGIFY(x) ".pts" - /* Open and unlock pt. */ - if (openpty (&uart_pt_fd, &slave_fd, 0, 0, 0) == -1 - || grantpt (uart_pt_fd) == -1 - || unlockpt (uart_pt_fd) == -1) - assert_perror (errno); - /* Make a link to the slave pts. */ - unlink (FILE_NAME (UART_N)); - name = ptsname (uart_pt_fd); - assert (name); - if (symlink (name, FILE_NAME (UART_N)) == -1) - assert_perror (errno); - /* Make slave raw. */ - setup_raw (slave_fd); - /* slave_fd is left open. */ + /* Try to access an already opened pts. */ + uart_pt_fd = host_fetch_integer (FILE_NAME (UART_N)); + if (uart_pt_fd == -1) + { + /* Open and unlock pt. */ + if (openpty (&uart_pt_fd, &slave_fd, 0, 0, 0) == -1 + || grantpt (uart_pt_fd) == -1 + || unlockpt (uart_pt_fd) == -1) + assert_perror (errno); + /* Make a link to the slave pts. */ + unlink (FILE_NAME (UART_N)); + name = ptsname (uart_pt_fd); + assert (name); + if (symlink (name, FILE_NAME (UART_N)) == -1) + assert_perror (errno); + /* Register the file descriptor in case of reset. */ + host_register_integer (FILE_NAME (UART_N), uart_pt_fd); + /* Make slave raw. */ + setup_raw (slave_fd); + /* slave_fd is left open. */ + } #endif } -- cgit v1.2.3