summaryrefslogtreecommitdiffhomepage
path: root/digital/avr/modules/uart
diff options
context:
space:
mode:
authorNicolas Schodet2007-10-07 22:16:03 +0200
committerNicolas Schodet2007-10-07 22:16:03 +0200
commit583f00e0b8efe2832f63efb478a51d3ad35e92ed (patch)
treee2cd42af768a4d248883d7fcebcb2124aad6fbe5 /digital/avr/modules/uart
parente38de75f64149d148e66572e330b7ce808782b1f (diff)
Included SI2E avr modules.
Well, this need more works...
Diffstat (limited to 'digital/avr/modules/uart')
-rw-r--r--digital/avr/modules/uart/Makefile5
-rw-r--r--digital/avr/modules/uart/Makefile.module3
-rw-r--r--digital/avr/modules/uart/README24
-rw-r--r--digital/avr/modules/uart/avrconfig.h71
-rw-r--r--digital/avr/modules/uart/test/Makefile18
-rw-r--r--digital/avr/modules/uart/test/avrconfig_polling.h76
-rw-r--r--digital/avr/modules/uart/test/avrconfig_ring.h76
-rw-r--r--digital/avr/modules/uart/test/avrconfig_twoports.h76
-rw-r--r--digital/avr/modules/uart/test/test_uart.c70
-rw-r--r--digital/avr/modules/uart/uart.avr.c299
-rw-r--r--digital/avr/modules/uart/uart.h60
-rw-r--r--digital/avr/modules/uart/uart.host.c175
-rw-r--r--digital/avr/modules/uart/uart.simu.c78
-rw-r--r--digital/avr/modules/uart/uart.txt26
-rw-r--r--digital/avr/modules/uart/uart0.c34
-rw-r--r--digital/avr/modules/uart/uart1.c34
-rw-r--r--digital/avr/modules/uart/uart_common.h87
17 files changed, 1212 insertions, 0 deletions
diff --git a/digital/avr/modules/uart/Makefile b/digital/avr/modules/uart/Makefile
new file mode 100644
index 00000000..f0f25611
--- /dev/null
+++ b/digital/avr/modules/uart/Makefile
@@ -0,0 +1,5 @@
+BASE = ../..
+DOC = uart.html
+EXTRACTDOC = uart.h avrconfig.h
+
+include $(BASE)/make/Makefile.gen
diff --git a/digital/avr/modules/uart/Makefile.module b/digital/avr/modules/uart/Makefile.module
new file mode 100644
index 00000000..09f3b60e
--- /dev/null
+++ b/digital/avr/modules/uart/Makefile.module
@@ -0,0 +1,3 @@
+uart_SOURCES = uart0.c uart1.c
+EXTRA_CLEAN_FILES += uart0.pts uart1.pts
+HOST_LIBS += -lutil
diff --git a/digital/avr/modules/uart/README b/digital/avr/modules/uart/README
new file mode 100644
index 00000000..4ec8736a
--- /dev/null
+++ b/digital/avr/modules/uart/README
@@ -0,0 +1,24 @@
+avr.uart - UART AVR module.
+
+Uart module for AVR. See modules README for more details about AVR modules.
+
+
+Copyright (C) 2005 Nicolas Schodet
+
+Robot APB Team/Efrei 2006.
+ Web: http://assos.efrei.fr/robot/
+ Email: robot AT efrei DOT fr
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
diff --git a/digital/avr/modules/uart/avrconfig.h b/digital/avr/modules/uart/avrconfig.h
new file mode 100644
index 00000000..d645e69a
--- /dev/null
+++ b/digital/avr/modules/uart/avrconfig.h
@@ -0,0 +1,71 @@
+#ifndef avrconfig_h
+#define avrconfig_h
+/* avrconfig.h - UART module configuration template. */
+/* avr.uart - UART AVR module. {{{
+ *
+ * Copyright (C) 2005 Nicolas Schodet
+ *
+ * Robot APB Team/Efrei 2006.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
+/* uart - UART module. */
+/** Select hardware uart for primary uart: 0, 1 or -1 to disable. */
+#define AC_UART0_PORT 0
+/** Baudrate: 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 76800,
+ * 115200, 230400, 250000, 500000, 1000000. */
+#define AC_UART0_BAUDRATE 115200
+/** Send mode:
+ * - POLLING: no interrupts.
+ * - RING: interrupts, ring buffer. */
+#define AC_UART0_SEND_MODE RING
+/** Recv mode, same as send mode. */
+#define AC_UART0_RECV_MODE RING
+/** Character size: 5, 6, 7, 8, 9 (only 8 implemented). */
+#define AC_UART0_CHAR_SIZE 8
+/** Parity : ODD, EVEN, NONE. */
+#define AC_UART0_PARITY EVEN
+/** Stop bits : 1, 2. */
+#define AC_UART0_STOP_BITS 1
+/** Send buffer size, should be power of 2 for RING mode. */
+#define AC_UART0_SEND_BUFFER_SIZE 32
+/** Recv buffer size, should be power of 2 for RING mode. */
+#define AC_UART0_RECV_BUFFER_SIZE 32
+/** If the send buffer is full when putc:
+ * - DROP: drop the new byte.
+ * - WAIT: wait until there is room in the send buffer. */
+#define AC_UART0_SEND_BUFFER_FULL WAIT
+/** In HOST compilation:
+ * - STDIO: use stdin/out.
+ * - PTS: use pseudo terminal. */
+#define AC_UART0_HOST_DRIVER PTS
+/** Same thing for secondary port. */
+#define AC_UART1_PORT -1
+#define AC_UART1_BAUDRATE 115200
+#define AC_UART1_SEND_MODE RING
+#define AC_UART1_RECV_MODE RING
+#define AC_UART1_CHAR_SIZE 8
+#define AC_UART1_PARITY EVEN
+#define AC_UART1_STOP_BITS 1
+#define AC_UART1_SEND_BUFFER_SIZE 32
+#define AC_UART1_RECV_BUFFER_SIZE 32
+#define AC_UART1_SEND_BUFFER_FULL WAIT
+#define AC_UART1_HOST_DRIVER PTS
+
+#endif /* avrconfig_h */
diff --git a/digital/avr/modules/uart/test/Makefile b/digital/avr/modules/uart/test/Makefile
new file mode 100644
index 00000000..4f394f2a
--- /dev/null
+++ b/digital/avr/modules/uart/test/Makefile
@@ -0,0 +1,18 @@
+BASE = ../../..
+PROGS = test_uart
+SIMU_PROGS = test_uart
+test_uart_SOURCES = test_uart.c
+MODULES = uart utils
+CONFIGFILE = avrconfig_ring.h
+# atmega8, atmega8535, atmega128...
+AVR_MCU = atmega8
+# -O2 : speed
+# -Os : size
+OPTIMIZE = -O2
+
+# Test compilations.
+TEST_MCU = atmega8 atmega8535 atmega128
+TEST_CONFIGFILES = avrconfig_ring.h avrconfig_polling.h avrconfig_twoports.h
+avrconfig_twoports_TEST_MCU = atmega128
+
+include $(BASE)/make/Makefile.gen
diff --git a/digital/avr/modules/uart/test/avrconfig_polling.h b/digital/avr/modules/uart/test/avrconfig_polling.h
new file mode 100644
index 00000000..99b45147
--- /dev/null
+++ b/digital/avr/modules/uart/test/avrconfig_polling.h
@@ -0,0 +1,76 @@
+#ifndef avrconfig_polling_h
+#define avrconfig_polling_h
+/* avrconfig_polling.h - test_uart config file. */
+/* avr.uart - UART AVR module. {{{
+ *
+ * Copyright (C) 2005 Nicolas Schodet
+ *
+ * Robot APB Team/Efrei 2006.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
+/* global */
+/** AVR Frequency : 1000000, 1843200, 2000000, 3686400, 4000000, 7372800,
+ * 8000000, 11059200, 14745600, 16000000, 18432000, 20000000. */
+#define AC_FREQ 14745600
+
+/* uart - UART module. */
+/** Select hardware uart for primary uart: 0, 1 or -1 to disable. */
+#define AC_UART0_PORT 0
+/** Baudrate: 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 76800,
+ * 115200, 230400, 250000, 500000, 1000000. */
+#define AC_UART0_BAUDRATE 9600
+/** Send mode:
+ * - POLLING: no interrupts.
+ * - RING: interrupts, ring buffer. */
+#define AC_UART0_SEND_MODE POLLING
+/** Recv mode, same as send mode. */
+#define AC_UART0_RECV_MODE POLLING
+/** Character size: 5, 6, 7, 8, 9 (only 8 implemented). */
+#define AC_UART0_CHAR_SIZE 8
+/** Parity : ODD, EVEN, NONE. */
+#define AC_UART0_PARITY EVEN
+/** Stop bits : 1, 2. */
+#define AC_UART0_STOP_BITS 1
+/** Send buffer size, should be power of 2 for RING mode. */
+#define AC_UART0_SEND_BUFFER_SIZE 32
+/** Recv buffer size, should be power of 2 for RING mode. */
+#define AC_UART0_RECV_BUFFER_SIZE 32
+/** If the send buffer is full when putc:
+ * - DROP: drop the new byte.
+ * - WAIT: wait until there is room in the send buffer. */
+#define AC_UART0_SEND_BUFFER_FULL WAIT
+/** In HOST compilation:
+ * - STDIO: use stdin/out.
+ * - PTS: use pseudo terminal. */
+#define AC_UART0_HOST_DRIVER STDIO
+/** Same thing for secondary port. */
+#define AC_UART1_PORT -1
+#define AC_UART1_BAUDRATE 115200
+#define AC_UART1_SEND_MODE RING
+#define AC_UART1_RECV_MODE RING
+#define AC_UART1_CHAR_SIZE 8
+#define AC_UART1_PARITY EVEN
+#define AC_UART1_STOP_BITS 1
+#define AC_UART1_SEND_BUFFER_SIZE 32
+#define AC_UART1_RECV_BUFFER_SIZE 32
+#define AC_UART1_SEND_BUFFER_FULL WAIT
+#define AC_UART1_HOST_DRIVER STDIO
+
+#endif /* avrconfig_polling_h */
diff --git a/digital/avr/modules/uart/test/avrconfig_ring.h b/digital/avr/modules/uart/test/avrconfig_ring.h
new file mode 100644
index 00000000..f35f9048
--- /dev/null
+++ b/digital/avr/modules/uart/test/avrconfig_ring.h
@@ -0,0 +1,76 @@
+#ifndef avrconfig_ring_h
+#define avrconfig_ring_h
+/* avrconfig_ring.h - test_uart config file. */
+/* avr.uart - UART AVR module. {{{
+ *
+ * Copyright (C) 2005 Nicolas Schodet
+ *
+ * Robot APB Team/Efrei 2006.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
+/* global */
+/** AVR Frequency : 1000000, 1843200, 2000000, 3686400, 4000000, 7372800,
+ * 8000000, 11059200, 14745600, 16000000, 18432000, 20000000. */
+#define AC_FREQ 14745600
+
+/* uart - UART module. */
+/** Select hardware uart for primary uart: 0, 1 or -1 to disable. */
+#define AC_UART0_PORT 0
+/** Baudrate: 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 76800,
+ * 115200, 230400, 250000, 500000, 1000000. */
+#define AC_UART0_BAUDRATE 115200
+/** Send mode:
+ * - POLLING: no interrupts.
+ * - RING: interrupts, ring buffer. */
+#define AC_UART0_SEND_MODE RING
+/** Recv mode, same as send mode. */
+#define AC_UART0_RECV_MODE RING
+/** Character size: 5, 6, 7, 8, 9 (only 8 implemented). */
+#define AC_UART0_CHAR_SIZE 8
+/** Parity : ODD, EVEN, NONE. */
+#define AC_UART0_PARITY EVEN
+/** Stop bits : 1, 2. */
+#define AC_UART0_STOP_BITS 1
+/** Send buffer size, should be power of 2 for RING mode. */
+#define AC_UART0_SEND_BUFFER_SIZE 32
+/** Recv buffer size, should be power of 2 for RING mode. */
+#define AC_UART0_RECV_BUFFER_SIZE 32
+/** If the send buffer is full when putc:
+ * - DROP: drop the new byte.
+ * - WAIT: wait until there is room in the send buffer. */
+#define AC_UART0_SEND_BUFFER_FULL WAIT
+/** In HOST compilation:
+ * - STDIO: use stdin/out.
+ * - PTS: use pseudo terminal. */
+#define AC_UART0_HOST_DRIVER PTS
+/** Same thing for secondary port. */
+#define AC_UART1_PORT -1
+#define AC_UART1_BAUDRATE 115200
+#define AC_UART1_SEND_MODE RING
+#define AC_UART1_RECV_MODE RING
+#define AC_UART1_CHAR_SIZE 8
+#define AC_UART1_PARITY EVEN
+#define AC_UART1_STOP_BITS 1
+#define AC_UART1_SEND_BUFFER_SIZE 32
+#define AC_UART1_RECV_BUFFER_SIZE 32
+#define AC_UART1_SEND_BUFFER_FULL WAIT
+#define AC_UART1_HOST_DRIVER PTS
+
+#endif /* avrconfig_ring_h */
diff --git a/digital/avr/modules/uart/test/avrconfig_twoports.h b/digital/avr/modules/uart/test/avrconfig_twoports.h
new file mode 100644
index 00000000..d4c8fa6c
--- /dev/null
+++ b/digital/avr/modules/uart/test/avrconfig_twoports.h
@@ -0,0 +1,76 @@
+#ifndef avrconfig_twoports_h
+#define avrconfig_twoports_h
+/* avrconfig_twoports.h - test_uart config file. */
+/* avr.uart - UART AVR module. {{{
+ *
+ * Copyright (C) 2005 Nicolas Schodet
+ *
+ * Robot APB Team/Efrei 2006.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
+/* global */
+/** AVR Frequency : 1000000, 1843200, 2000000, 3686400, 4000000, 7372800,
+ * 8000000, 11059200, 14745600, 16000000, 18432000, 20000000. */
+#define AC_FREQ 14745600
+
+/* uart - UART module. */
+/** Select hardware uart for primary uart: 0, 1 or -1 to disable. */
+#define AC_UART0_PORT 0
+/** Baudrate: 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 76800,
+ * 115200, 230400, 250000, 500000, 1000000. */
+#define AC_UART0_BAUDRATE 115200
+/** Send mode:
+ * - POLLING: no interrupts.
+ * - RING: interrupts, ring buffer. */
+#define AC_UART0_SEND_MODE RING
+/** Recv mode, same as send mode. */
+#define AC_UART0_RECV_MODE POLLING
+/** Character size: 5, 6, 7, 8, 9 (only 8 implemented). */
+#define AC_UART0_CHAR_SIZE 8
+/** Parity : ODD, EVEN, NONE. */
+#define AC_UART0_PARITY EVEN
+/** Stop bits : 1, 2. */
+#define AC_UART0_STOP_BITS 1
+/** Send buffer size, should be power of 2 for RING mode. */
+#define AC_UART0_SEND_BUFFER_SIZE 32
+/** Recv buffer size, should be power of 2 for RING mode. */
+#define AC_UART0_RECV_BUFFER_SIZE 32
+/** If the send buffer is full when putc:
+ * - DROP: drop the new byte.
+ * - WAIT: wait until there is room in the send buffer. */
+#define AC_UART0_SEND_BUFFER_FULL DROP
+/** In HOST compilation:
+ * - STDIO: use stdin/out.
+ * - PTS: use pseudo terminal. */
+#define AC_UART0_HOST_DRIVER PTS
+/** Same thing for secondary port. */
+#define AC_UART1_PORT 1
+#define AC_UART1_BAUDRATE 115200
+#define AC_UART1_SEND_MODE POLLING
+#define AC_UART1_RECV_MODE RING
+#define AC_UART1_CHAR_SIZE 8
+#define AC_UART1_PARITY ODD
+#define AC_UART1_STOP_BITS 2
+#define AC_UART1_SEND_BUFFER_SIZE 32
+#define AC_UART1_RECV_BUFFER_SIZE 16
+#define AC_UART1_SEND_BUFFER_FULL DROP
+#define AC_UART1_HOST_DRIVER PTS
+
+#endif /* avrconfig_twoports_h */
diff --git a/digital/avr/modules/uart/test/test_uart.c b/digital/avr/modules/uart/test/test_uart.c
new file mode 100644
index 00000000..86b20581
--- /dev/null
+++ b/digital/avr/modules/uart/test/test_uart.c
@@ -0,0 +1,70 @@
+/* test_uart.c */
+/* avr.uart - UART AVR module. {{{
+ *
+ * Copyright (C) 2005 Nicolas Schodet
+ *
+ * Robot APB Team/Efrei 2006.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+#include "common.h"
+#include "modules/uart/uart.h"
+#include "modules/utils/utils.h"
+#include "io.h"
+
+int
+main (int argc, char **argv)
+{
+ avr_init (argc, argv);
+ sei ();
+ uart0_init ();
+ uart0_putc ('N');
+ uart0_putc ('i');
+ uart0_putc ('0');
+ uart0_putc ('!');
+ uart0_putc ('\r');
+#if AC_UART1_PORT != -1
+ uart1_init ();
+ uart1_putc ('N');
+ uart1_putc ('i');
+ uart1_putc ('1');
+ uart1_putc ('!');
+ uart1_putc ('\r');
+ while (1)
+ {
+ utils_delay (0.1);
+ if (uart0_poll ())
+ {
+ char c = uart0_getc ();
+ if (c == 'z')
+ utils_reset ();
+ uart0_putc (c);
+ }
+ if (uart1_poll ())
+ uart1_putc (uart1_getc ());
+ }
+#else
+ while (1)
+ {
+ char c = uart0_getc ();
+ if (c == 'z')
+ utils_reset ();
+ uart0_putc (c);
+ }
+#endif
+}
diff --git a/digital/avr/modules/uart/uart.avr.c b/digital/avr/modules/uart/uart.avr.c
new file mode 100644
index 00000000..1282ad80
--- /dev/null
+++ b/digital/avr/modules/uart/uart.avr.c
@@ -0,0 +1,299 @@
+/* uart.avr.c */
+/* avr.uart - UART AVR module. {{{
+ *
+ * Copyright (C) 2005 Nicolas Schodet
+ *
+ * Robot APB Team/Efrei 2006.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+#include "common.h"
+#include "uart.h"
+
+#include "uart_common.h"
+
+#if AC_UART (PORT) != -1
+
+#include "io.h"
+
+/* Tested AVR check. */
+#if defined (__AVR_ATmega8__)
+#elif defined (__AVR_ATmega8535__)
+#elif defined (__AVR_ATmega128__)
+# define PE UPE
+#elif defined (__AVR_ATmega64__)
+# define PE UPE
+#else
+# warning "uart: not tested on this chip"
+#endif
+
+/* UART port number. */
+#if AC_UART (PORT) == 0
+# if !defined (UBRRH)
+# if defined (UBRR0H)
+# define UBRRH UBRR0H
+# define UBRRL UBRR0L
+# define UCSRA UCSR0A
+# define UCSRB UCSR0B
+# define UCSRC UCSR0C
+# define UDR UDR0
+# define SIG_UART_RECV SIG_UART0_RECV
+# define SIG_UART_DATA SIG_UART0_DATA
+# else
+# error "uart: can not find uart 0"
+# endif /* defined (UBRR0H) */
+# endif /* !defined (UBRRH) */
+#else /* AC_UART (PORT) == 1 */
+# if defined (UBRR1H)
+# define UBRRH UBRR1H
+# define UBRRL UBRR1L
+# define UCSRA UCSR1A
+# define UCSRB UCSR1B
+# define UCSRC UCSR1C
+# define UDR UDR1
+# define SIG_UART_RECV SIG_UART1_RECV
+# define SIG_UART_DATA SIG_UART1_DATA
+# else
+# error "uart: can not find uart 1"
+# endif /* defined (UBRR1H) */
+#endif /* AC_UART (PORT) == 1 */
+
+/* UR selector (UCSRC & UBRRH multiplexed). */
+#if defined (URSEL)
+# define SELECTOR _BV (URSEL)
+#else
+# define SELECTOR 0
+#endif
+
+/* Baud rate error check. */
+#define UBRR_VAL (AC_FREQ / 16 / AC_UART (BAUDRATE) - 1)
+#define BAUDRATE_VAL (AC_FREQ / 16 / (UBRR_VAL + 1))
+
+#if BAUDRATE_VAL - AC_UART (BAUDRATE) > 2
+#warning "uart: baud rate error > 2"
+#elif BAUDRATE_VAL - AC_UART (BAUDRATE) > 1
+#warning "uart: baud rate error > 1"
+#elif BAUDRATE_VAL - AC_UART (BAUDRATE) > 0
+#warning "uart: baud rate error > 0"
+#endif
+
+/* Mode. */
+#define POLLING 1
+#define RING 2
+#define SEND_MODE AC_UART (SEND_MODE)
+#define RECV_MODE AC_UART (RECV_MODE)
+#if RECV_MODE == POLLING
+# define RECV_IE 0
+#elif RECV_MODE == RING
+# define RECV_IE _BV (RXCIE)
+#else
+# error "uart: bad mode"
+#endif
+
+/* Parity. */
+#define ODD (_BV (UPM1) | _BV (UPM0))
+#define EVEN _BV (UPM1)
+#define NONE 0
+#define PARITY AC_UART (PARITY)
+
+/* Stop bits. */
+#if AC_UART (STOP_BITS) == 1
+#define STOP_BITS 0
+#elif AC_UART (STOP_BITS) == 2
+#define STOP_BITS _BV (USBS)
+#else
+#error "uart: bad stop bits value"
+#endif
+
+/* Character size. */
+#define CHAR_SIZE (_BV (UCSZ1) | _BV (UCSZ0))
+
+/* Buffers. */
+#if SEND_MODE == RING
+# define SEND_BUFFER_SIZE AC_UART (SEND_BUFFER_SIZE)
+# define SEND_BUFFER_MASK (SEND_BUFFER_SIZE - 1)
+# if SEND_BUFFER_SIZE & SEND_BUFFER_MASK
+# error "uart: send buffer size must be a power of 2"
+# endif
+#endif
+#if RECV_MODE == RING
+# define RECV_BUFFER_SIZE AC_UART (RECV_BUFFER_SIZE)
+# define RECV_BUFFER_MASK (RECV_BUFFER_SIZE - 1)
+# if RECV_BUFFER_SIZE & RECV_BUFFER_MASK
+# error "uart: recv buffer size must be a power of 2"
+# endif
+#endif
+
+/* Send buffer. */
+#if SEND_MODE == RING
+static uint8_t uart_send_buffer[SEND_BUFFER_SIZE];
+static volatile uint8_t uart_send_head, uart_send_tail;
+#endif
+
+/* Recv buffer. */
+#if RECV_MODE == RING
+static uint8_t uart_recv_buffer[RECV_BUFFER_SIZE];
+static volatile uint8_t uart_recv_head, uart_recv_tail;
+#endif
+
+/* Full buffer politic. */
+#define DROP 1
+#define WAIT 2
+#define SEND_BUFFER_FULL AC_UART (SEND_BUFFER_FULL)
+#if SEND_BUFFER_FULL != DROP && SEND_BUFFER_FULL != WAIT
+# error "uart: bad full buffer politic"
+#endif
+
+/* Error code. */
+#define ERROR_BITS (_BV (FE) | _BV (DOR) | _BV (PE))
+
+/* +AutoDec */
+/* -AutoDec */
+
+/** Initialise uart. */
+void
+uart_init (void)
+{
+ /* Set baud rate. */
+#if (UBRR_VAL >> 8) != 0
+ UBRRH = UBRR_VAL >> 8;
+#endif
+ UBRRL = UBRR_VAL & 0xff;
+ UCSRA = 0;
+ /* Set format and enable uart. */
+ UCSRC = SELECTOR | PARITY | STOP_BITS | CHAR_SIZE;
+ UCSRB = RECV_IE | _BV (RXEN) | _BV (TXEN);
+#if RECV_MODE == RING
+ uart_recv_head = 0;
+ uart_recv_tail = 0;
+#endif
+#if SEND_MODE == RING
+ uart_send_head = 0;
+ uart_send_tail = 0;
+#endif
+}
+
+/** Read a char. */
+uint8_t
+uart_getc (void)
+{
+#if RECV_MODE == POLLING
+ uint8_t tmperr, c;
+ loop_until_bit_is_set (UCSRA, RXC);
+ tmperr = UCSRA & ERROR_BITS;
+ c = UDR;
+ if (tmperr)
+ return 0xff;
+ else
+ return c;
+#elif RECV_MODE == RING
+ uint8_t tmptail = uart_recv_tail;
+ while (uart_recv_head == tmptail)
+ ;
+ tmptail = (tmptail + 1) & RECV_BUFFER_MASK;
+ uart_recv_tail = tmptail;
+ return uart_recv_buffer[tmptail];
+#endif
+}
+
+/** Write a char. */
+void
+uart_putc (uint8_t c)
+{
+#if SEND_MODE == POLLING
+# if SEND_BUFFER_FULL == WAIT
+ loop_until_bit_is_set (UCSRA, UDRE);
+# else
+ if (!(UCSRA & _BV (UDRE)))
+ return;
+# endif
+ UDR = c;
+#elif SEND_MODE == RING
+ uint8_t tmphead;
+ tmphead = (uart_send_head + 1) & SEND_BUFFER_MASK;
+# if SEND_BUFFER_FULL == WAIT
+ while (tmphead == uart_send_tail)
+ ;
+# else
+ if (tmphead == uart_send_tail)
+ return;
+# endif
+ uart_send_buffer[tmphead] = c;
+ uart_send_head = tmphead;
+ UCSRB |= _BV (UDRIE);
+#endif
+}
+
+/** Retrieve availlable chars. */
+uint8_t
+uart_poll (void)
+{
+#if RECV_MODE == POLLING
+ return UCSRA & _BV (RXC);
+#elif RECV_MODE == RING
+ return (uart_recv_head - uart_recv_tail) & RECV_BUFFER_MASK;
+#endif
+}
+
+#if RECV_MODE == RING
+
+/* Handle received char for ring buffer. */
+SIGNAL (SIG_UART_RECV)
+{
+ uint8_t c;
+ uint8_t tmphead;
+ uint8_t tmperr;
+ tmperr = UCSRA & ERROR_BITS;
+ c = UDR;
+ if (tmperr)
+ c = 0xff;
+ tmphead = (uart_recv_head + 1) & RECV_BUFFER_MASK;
+ uart_recv_head = tmphead;
+ /* If overflowed, clear the receive buffer. */
+ if (tmphead == uart_recv_tail)
+ {
+ tmphead = (tmphead + 1) & RECV_BUFFER_MASK;
+ uart_recv_head = tmphead;
+ c = 0xff;
+ }
+ uart_recv_buffer[tmphead] = c;
+}
+
+#endif /* RECV_MODE == RING */
+
+#if SEND_MODE == RING
+
+/** Handle data register empty for ring buffer. */
+SIGNAL (SIG_UART_DATA)
+{
+ uint8_t tmptail;
+ if (uart_send_head != uart_send_tail)
+ {
+ tmptail = (uart_send_tail + 1) & SEND_BUFFER_MASK;
+ uart_send_tail = tmptail;
+ UDR = uart_send_buffer[tmptail];
+ }
+ else
+ {
+ UCSRB &= ~_BV (UDRIE);
+ }
+}
+
+#endif /* SEND_MODE == RING */
+
+#endif /* AC_UART (PORT) != -1 */
diff --git a/digital/avr/modules/uart/uart.h b/digital/avr/modules/uart/uart.h
new file mode 100644
index 00000000..f510a01d
--- /dev/null
+++ b/digital/avr/modules/uart/uart.h
@@ -0,0 +1,60 @@
+#ifndef uart_h
+#define uart_h
+/* uart.h */
+/* avr.uart - UART AVR module. {{{
+ *
+ * Copyright (C) 2005 Nicolas Schodet
+ *
+ * Robot APB Team/Efrei 2006.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
+/** Initialise uart. */
+void
+uart0_init (void);
+
+/** Read a char. */
+uint8_t
+uart0_getc (void);
+
+/** Write a char. */
+void
+uart0_putc (uint8_t c);
+
+/** Retrieve availlable chars. */
+uint8_t
+uart0_poll (void);
+
+/** Initialise uart. */
+void
+uart1_init (void);
+
+/** Read a char. */
+uint8_t
+uart1_getc (void);
+
+/** Write a char. */
+void
+uart1_putc (uint8_t c);
+
+/** Retrieve availlable chars. */
+uint8_t
+uart1_poll (void);
+
+#endif /* uart_h */
diff --git a/digital/avr/modules/uart/uart.host.c b/digital/avr/modules/uart/uart.host.c
new file mode 100644
index 00000000..9a335b2a
--- /dev/null
+++ b/digital/avr/modules/uart/uart.host.c
@@ -0,0 +1,175 @@
+/* uart.host.c */
+/* avr.uart - UART AVR module. {{{
+ *
+ * Copyright (C) 2005 Nicolas Schodet
+ *
+ * Robot APB Team/Efrei 2006.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+#define _GNU_SOURCE
+#include "common.h"
+#include "uart.h"
+#include "modules/host/host.h"
+
+#include "uart_common.h"
+
+#if AC_UART (PORT) != -1
+
+#include <stdlib.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <unistd.h>
+#include <pty.h>
+#include <fcntl.h>
+#include <stdio.h>
+
+/* Check uart driver. */
+#if UART_N == 0
+# define STDIO 1
+# define PTS 2
+# if AC_UART (HOST_DRIVER) == STDIO
+# define DRIVER_STDIO
+# elif AC_UART (HOST_DRIVER) == PTS
+# else
+# error "uart: invalid host driver"
+# endif
+#endif
+
+#ifndef DRIVER_STDIO
+
+/* 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);
+}
+
+#endif /* DRIVER_STDIO */
+
+/** Initialise uart. */
+void
+uart_init (void)
+{
+#ifdef DRIVER_STDIO
+ int r;
+# define uart_pt_fd_in 0
+# define uart_pt_fd_out 1
+ /* Always use line buffering. */
+ r = setvbuf (stdout, 0, _IOLBF, BUFSIZ);
+ assert (r == 0);
+#else
+# define uart_pt_fd_in uart_pt_fd
+# define uart_pt_fd_out uart_pt_fd
+ int slave_fd;
+ const char *name;
+#define STRINGIFY(x) #x
+#define FILE_NAME(x) "uart" STRINGIFY(x) ".pts"
+ /* 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
+}
+
+/** Read a char. */
+uint8_t
+uart_getc (void)
+{
+ uint8_t c;
+ int n;
+ n = read (uart_pt_fd_in, &c, 1);
+ if (n == -1)
+ assert_perror (errno);
+#ifdef DRIVER_STDIO
+ /* Quit if EOF from stdin. */
+ if (n == 0)
+ exit (0);
+ if (c == '\n')
+ c = '\r';
+#else
+ /* This is a quite unusual and dangerous behavior... */
+ if (n == 0)
+ return 0xff;
+#endif
+ return c;
+}
+
+/** Write a char. */
+void
+uart_putc (uint8_t c)
+{
+#ifdef DRIVER_STDIO
+ if (c == '\r')
+ c = '\n';
+#endif
+ write (uart_pt_fd_out, &c, 1);
+}
+
+/** Retrieve availlable chars. */
+uint8_t
+uart_poll (void)
+{
+ fd_set fds;
+ struct timeval tv;
+ int r;
+ /* Use select to poll. */
+ FD_ZERO (&fds);
+ FD_SET (uart_pt_fd_in, &fds);
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ r = select (FD_SETSIZE, &fds, 0, 0, &tv);
+ /* Check result. */
+ if (r == -1)
+ assert_perror (errno);
+ return r;
+}
+
+#endif /* AC_UART (PORT) != -1 */
diff --git a/digital/avr/modules/uart/uart.simu.c b/digital/avr/modules/uart/uart.simu.c
new file mode 100644
index 00000000..e8605790
--- /dev/null
+++ b/digital/avr/modules/uart/uart.simu.c
@@ -0,0 +1,78 @@
+/* uart.simu.c - used for simulavrxx pseudo ports. */
+/* avr.uart - UART AVR module. {{{
+ *
+ * Copyright (C) 2005 Nicolas Schodet
+ *
+ * Robot APB Team/Efrei 2006.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+#include "common.h"
+#include "uart.h"
+
+#include "uart_common.h"
+
+#if AC_UART (PORT) != -1
+
+int uart (eof);
+
+/** Initialise uart. */
+void
+uart_init (void)
+{
+ uart (eof) = 0;
+}
+
+/** Use this as exit point. */
+void
+uart (exit) (void)
+{
+ uart (eof) = 1;
+}
+
+/** Read a char. */
+uint8_t
+uart_getc (void)
+{
+ uint8_t c;
+ if (uart (eof))
+ return 0xff;
+ c = *(uint8_t *) 0x20;
+ if (!c)
+ {
+ uart (exit) ();
+ c = 0xff;
+ }
+ return c;
+}
+
+/** Write a char. */
+void
+uart_putc (uint8_t c)
+{
+ *(uint8_t *) 0x22 = c;
+}
+
+/** Retrieve availlable chars. */
+uint8_t
+uart_poll (void)
+{
+ return !uart (eof);
+}
+
+#endif /* AC_UART (PORT) != -1 */
diff --git a/digital/avr/modules/uart/uart.txt b/digital/avr/modules/uart/uart.txt
new file mode 100644
index 00000000..b6f1129f
--- /dev/null
+++ b/digital/avr/modules/uart/uart.txt
@@ -0,0 +1,26 @@
+*Title: Module AVR UART
+*Author: Ni
+
+* Utilisation
+
+Rien de plus simple. Appeler la fonction |uart0_init| au démarrage, puis
+|uart0_putc| pour envoyer un caractère, |uart0_getc| pour en recevoir. La
+fonction |uart0_poll| permet de connaître à l'avance si des caractère sont
+disponibles.
+
+En cas d'erreur de réception, la fonction |uart0_getc| renvois 0xff. Ce n'est
+pas forcément adapté à une transmission binaire car on ne peut pas distinguer
+un 0xff légitime d'une erreur de transmission.
+
+On peut configurer deux uarts, dans ce cas les fonctions sont en double.
+
+Comme pour tous les modules, copier la partie concernant l'uart depuis
+|avrconfig.h|.
+
+Dans le cas de la compilation en host, un pseudo-terminal est ouvert pour les
+communications, un lien vers le pseudo-terminal est crée en |uart0.pts|. Dans
+le futur, on pourra peut-être configurer ce fichier par la ligne de commande.
+
+* Doc
+
+*File: uart.exd
diff --git a/digital/avr/modules/uart/uart0.c b/digital/avr/modules/uart/uart0.c
new file mode 100644
index 00000000..4a8fb358
--- /dev/null
+++ b/digital/avr/modules/uart/uart0.c
@@ -0,0 +1,34 @@
+/* uart0.c - Compile primary port. */
+/* avr.uart - UART AVR module. {{{
+ *
+ * Copyright (C) 2005 Nicolas Schodet
+ *
+ * Robot APB Team/Efrei 2006.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
+#define UART_N 0
+
+#if defined (HOST)
+# include "uart.host.c"
+#elif defined (SIMU)
+# include "uart.simu.c"
+#else
+# include "uart.avr.c"
+#endif
diff --git a/digital/avr/modules/uart/uart1.c b/digital/avr/modules/uart/uart1.c
new file mode 100644
index 00000000..c3915278
--- /dev/null
+++ b/digital/avr/modules/uart/uart1.c
@@ -0,0 +1,34 @@
+/* uart1.c - Compile secondary port. */
+/* avr.uart - UART AVR module. {{{
+ *
+ * Copyright (C) 2005 Nicolas Schodet
+ *
+ * Robot APB Team/Efrei 2006.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
+#define UART_N 1
+
+#if defined (HOST)
+# include "uart.host.c"
+#elif defined (SIMU)
+# include "uart.simu.c"
+#else
+# include "uart.avr.c"
+#endif
diff --git a/digital/avr/modules/uart/uart_common.h b/digital/avr/modules/uart/uart_common.h
new file mode 100644
index 00000000..8f5a3af4
--- /dev/null
+++ b/digital/avr/modules/uart/uart_common.h
@@ -0,0 +1,87 @@
+#ifndef uart_common_h
+#define uart_common_h
+/* uart_common.h - UART module common part. */
+/* avr.uart - UART AVR module. {{{
+ *
+ * Copyright (C) 2005 Nicolas Schodet
+ *
+ * Robot APB Team/Efrei 2006.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
+/* This symbol should be 0 or 1. */
+#ifndef UART_N
+# error "uart: UART_N missing"
+#endif
+
+/* Utility macros. */
+#define PASTE4_SUB(a, b, c, d) a ## b ## c ## d
+#define PASTE4(a, b, c, d) PASTE4_SUB (a, b, c, d)
+
+/* Port selection macros. */
+#define AC_UART(x) PASTE4(AC_UART, UART_N, _, x)
+#define uart(x) PASTE4(uart, UART_N, _, x)
+
+/* Define uart symbols. */
+#define uart_error uart (error)
+#define uart_error_code uart (error_code)
+#define uart_getc uart (getc)
+#define uart_init uart (init)
+#define uart_poll uart (poll)
+#define uart_putc uart (putc)
+#define uart_recv_buffer uart (recv_buffer)
+#define uart_recv_head uart (recv_head)
+#define uart_recv_tail uart (recv_tail)
+#define uart_send_buffer uart (send_buffer)
+#define uart_send_head uart (send_head)
+#define uart_send_tail uart (send_tail)
+
+/* Unimplemented features. */
+#if AC_UART (CHAR_SIZE) != 8
+# error "uart: char size != 8 not implemented"
+#endif
+
+/* Test that everythings is configured. */
+#if !defined (AC_UART0_PORT) \
+ || !defined (AC_UART0_BAUDRATE) \
+ || !defined (AC_UART0_SEND_MODE) \
+ || !defined (AC_UART0_RECV_MODE) \
+ || !defined (AC_UART0_CHAR_SIZE) \
+ || !defined (AC_UART0_PARITY) \
+ || !defined (AC_UART0_STOP_BITS) \
+ || !defined (AC_UART0_SEND_BUFFER_SIZE) \
+ || !defined (AC_UART0_RECV_BUFFER_SIZE) \
+ || !defined (AC_UART0_SEND_BUFFER_FULL) \
+ || !defined (AC_UART0_HOST_DRIVER) \
+ || !defined (AC_UART1_PORT) \
+ || !defined (AC_UART1_BAUDRATE) \
+ || !defined (AC_UART1_SEND_MODE) \
+ || !defined (AC_UART1_RECV_MODE) \
+ || !defined (AC_UART1_CHAR_SIZE) \
+ || !defined (AC_UART1_PARITY) \
+ || !defined (AC_UART1_STOP_BITS) \
+ || !defined (AC_UART1_SEND_BUFFER_SIZE) \
+ || !defined (AC_UART1_RECV_BUFFER_SIZE) \
+ || !defined (AC_UART1_SEND_BUFFER_FULL) \
+ || !defined (AC_UART1_HOST_DRIVER) \
+ || AC_UART0_PORT == AC_UART1_PORT
+# error "uart: error in configuration"
+#endif
+
+#endif /* uart_common_h */