summaryrefslogtreecommitdiff
path: root/n/avr
diff options
context:
space:
mode:
Diffstat (limited to 'n/avr')
-rw-r--r--n/avr/modules/uart/uart.host.c36
-rw-r--r--n/avr/modules/utils/utils.host.c8
2 files changed, 24 insertions, 20 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
}
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 <time.h>
#include <errno.h>
#include <assert.h>
-#include <unistd.h>
-#include <stdlib.h>
/** 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 ();
}