From 08792dc2e4726cdc546ac97d44d2175ffdac09be Mon Sep 17 00:00:00 2001 From: schodet Date: Mon, 17 Oct 2005 21:42:58 +0000 Subject: Ajout du code d'uart pour simulavrxx. --- n/avr/modules/uart/avrconfig.h | 1 + n/avr/modules/uart/test/avrconfig_polling.h | 1 + n/avr/modules/uart/test/avrconfig_ring.h | 1 + n/avr/modules/uart/test/avrconfig_twoports.h | 1 + n/avr/modules/uart/uart.simu.c | 78 ++++++++++++++++++++++++++++ n/avr/modules/uart/uart0.c | 8 +-- n/avr/modules/uart/uart1.c | 8 +-- n/avr/modules/uart/uart_common.h | 4 ++ 8 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 n/avr/modules/uart/uart.simu.c (limited to 'n/avr/modules/uart') diff --git a/n/avr/modules/uart/avrconfig.h b/n/avr/modules/uart/avrconfig.h index c52072c..d645e69 100644 --- a/n/avr/modules/uart/avrconfig.h +++ b/n/avr/modules/uart/avrconfig.h @@ -66,5 +66,6 @@ #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/n/avr/modules/uart/test/avrconfig_polling.h b/n/avr/modules/uart/test/avrconfig_polling.h index 81e5f0e..99b4514 100644 --- a/n/avr/modules/uart/test/avrconfig_polling.h +++ b/n/avr/modules/uart/test/avrconfig_polling.h @@ -71,5 +71,6 @@ #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/n/avr/modules/uart/test/avrconfig_ring.h b/n/avr/modules/uart/test/avrconfig_ring.h index e712d05..f35f904 100644 --- a/n/avr/modules/uart/test/avrconfig_ring.h +++ b/n/avr/modules/uart/test/avrconfig_ring.h @@ -71,5 +71,6 @@ #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/n/avr/modules/uart/test/avrconfig_twoports.h b/n/avr/modules/uart/test/avrconfig_twoports.h index 07993fc..d4c8fa6 100644 --- a/n/avr/modules/uart/test/avrconfig_twoports.h +++ b/n/avr/modules/uart/test/avrconfig_twoports.h @@ -71,5 +71,6 @@ #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/n/avr/modules/uart/uart.simu.c b/n/avr/modules/uart/uart.simu.c new file mode 100644 index 0000000..e860579 --- /dev/null +++ b/n/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/n/avr/modules/uart/uart0.c b/n/avr/modules/uart/uart0.c index 66444eb..4a8fb35 100644 --- a/n/avr/modules/uart/uart0.c +++ b/n/avr/modules/uart/uart0.c @@ -25,8 +25,10 @@ #define UART_N 0 -#ifdef HOST -#include "uart.host.c" +#if defined (HOST) +# include "uart.host.c" +#elif defined (SIMU) +# include "uart.simu.c" #else -#include "uart.avr.c" +# include "uart.avr.c" #endif diff --git a/n/avr/modules/uart/uart1.c b/n/avr/modules/uart/uart1.c index 8a15e2c..c391527 100644 --- a/n/avr/modules/uart/uart1.c +++ b/n/avr/modules/uart/uart1.c @@ -25,8 +25,10 @@ #define UART_N 1 -#ifdef HOST -#include "uart.host.c" +#if defined (HOST) +# include "uart.host.c" +#elif defined (SIMU) +# include "uart.simu.c" #else -#include "uart.avr.c" +# include "uart.avr.c" #endif diff --git a/n/avr/modules/uart/uart_common.h b/n/avr/modules/uart/uart_common.h index a856aa9..8f5a3af 100644 --- a/n/avr/modules/uart/uart_common.h +++ b/n/avr/modules/uart/uart_common.h @@ -67,6 +67,8 @@ || !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) \ @@ -76,6 +78,8 @@ || !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 -- cgit v1.2.3