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 ++++++++++++++++++++++-------------- n/avr/modules/utils/utils.host.c | 8 ++------ 2 files changed, 24 insertions(+), 20 deletions(-) (limited to 'n/avr/modules') 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 } diff --git a/n/avr/modules/utils/utils.host.c b/n/avr/modules/utils/utils.host.c index fcc93bf..8d2be82 100644 --- a/n/avr/modules/utils/utils.host.c +++ b/n/avr/modules/utils/utils.host.c @@ -22,14 +22,12 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * }}} */ -#define _GNU_SOURCE #include "utils.h" +#include "modules/host/host.h" #include #include #include -#include -#include /** Delay in seconds. */ void @@ -47,8 +45,6 @@ utils_delay (double s) void utils_reset (void) { - execlp (program_invocation_name, program_invocation_name, 0); - assert_perror (errno); - abort (); + host_reset (); } -- cgit v1.2.3