summaryrefslogtreecommitdiff
path: root/n/avr/modules/uart/uart.host.c
diff options
context:
space:
mode:
authorschodet2005-10-08 13:58:07 +0000
committerschodet2005-10-08 13:58:07 +0000
commitc1aa462b9cecd5d3e6010395f210e44ddafe632b (patch)
tree80ce8ed9847cc3c319602bbb39e0e80fde6e9ed8 /n/avr/modules/uart/uart.host.c
parentca63cc9444a390be6e0b44dfa745fa1984a1d197 (diff)
Utilise le module host.
Diffstat (limited to 'n/avr/modules/uart/uart.host.c')
-rw-r--r--n/avr/modules/uart/uart.host.c36
1 files changed, 22 insertions, 14 deletions
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
}