summaryrefslogtreecommitdiff
path: root/n/avr/modules/uart/uart.host.c
diff options
context:
space:
mode:
authorschodet2005-07-05 18:39:06 +0000
committerschodet2005-07-05 18:39:06 +0000
commitdc1a4f2bdbb5723fd0b5a19aa533211b34c06adb (patch)
tree06ecafe7e040e62a379497b3bd386d171f6e14da /n/avr/modules/uart/uart.host.c
parent8837b88c9d9cce383fd1e3467abadef51cbc5b1c (diff)
Fix: echo sur l'uart host.
Add: mode de compilation de test. Add: erreurs à la termios. Fix: détails...
Diffstat (limited to 'n/avr/modules/uart/uart.host.c')
-rw-r--r--n/avr/modules/uart/uart.host.c48
1 files changed, 39 insertions, 9 deletions
diff --git a/n/avr/modules/uart/uart.host.c b/n/avr/modules/uart/uart.host.c
index 3bbd112..661401c 100644
--- a/n/avr/modules/uart/uart.host.c
+++ b/n/avr/modules/uart/uart.host.c
@@ -23,6 +23,7 @@
*
* }}} */
#define _GNU_SOURCE
+#include "common.h"
#include "uart.h"
#include "uart_common.h"
@@ -31,26 +32,56 @@
#include <assert.h>
#include <stdlib.h>
-#include <stdio.h>
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
+#include <pty.h>
+#include <fcntl.h>
/* Pseudo terminal file descriptor. */
static int uart_pt_fd;
+/** Setup a non canonical mode. */
+static void
+setup_raw (int fd)
+{
+ struct termios tc;
+ tcgetattr (fd, &tc);
+ tc.c_iflag &= ~(IGNPAR | PARMRK | ISTRIP | IGNBRK | BRKINT | IGNCR |
+ ICRNL | INLCR | IXON | IXOFF | IXANY | IMAXBEL);
+ tc.c_iflag |= INPCK;
+ tc.c_oflag &= ~(OPOST);
+ tc.c_cflag &= ~(HUPCL | CSTOPB | PARENB | PARODD | CSIZE);
+ tc.c_cflag |= CS8 | CLOCAL | CREAD;
+ tc.c_lflag &= ~(ICANON | ECHO | ISIG | IEXTEN | NOFLSH | TOSTOP);
+ tc.c_cc[VTIME] = 0;
+ tc.c_cc[VMIN] = 1;
+ tcflush (fd, TCIFLUSH);
+ tcsetattr (fd, TCSANOW, &tc);
+}
+
/** Initialise uart. */
void
uart_init (void)
{
+ int slave_fd;
+ const char *name;
+#define STRINGIFY(x) #x
+#define FILE_NAME(x) "uart" STRINGIFY(x) ".pts"
/* Open and unlock pt. */
- uart_pt_fd = getpt ();
- if (uart_pt_fd == -1)
+ if (openpty (&uart_pt_fd, &slave_fd, 0, 0, 0) == -1
+ || grantpt (uart_pt_fd) == -1
+ || unlockpt (uart_pt_fd) == -1)
assert_perror (errno);
- if (grantpt (uart_pt_fd) == -1 || unlockpt (uart_pt_fd) == -1)
+ /* 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);
- /* Display its name. */
- printf ("uart%d: %s\n", UART_N, ptsname (uart_pt_fd));
+ /* Make slave raw. */
+ setup_raw (slave_fd);
+ /* slave_fd is left open. */
}
/** Read a char. */
@@ -62,9 +93,9 @@ uart_getc (void)
n = read (uart_pt_fd, &c, 1);
if (n == -1)
assert_perror (errno);
- /* This is quite unusual... */
+ /* This is a quite unusual behavior... */
if (n == 0)
- return 0;
+ return 0xff;
return c;
}
@@ -72,7 +103,6 @@ uart_getc (void)
void
uart_putc (uint8_t c)
{
- int n;
write (uart_pt_fd, &c, 1);
}