uart: fix compilation on recent avr-gcc
authorOlivier Matz <zer0@droids-corp.org>
Sat, 24 May 2014 16:52:21 +0000 (18:52 +0200)
committerOlivier Matz <zer0@droids-corp.org>
Sat, 24 May 2014 16:54:03 +0000 (18:54 +0200)
Signed-off-by: Olivier Matz <zer0@droids-corp.org>
modules/comm/uart/test/.config
modules/comm/uart/test/main.c
modules/comm/uart/uart.c
modules/comm/uart/uart_defs.h
modules/comm/uart/uart_setconf.c

index f397aae..eaa69c5 100644 (file)
@@ -11,6 +11,7 @@
 # CONFIG_MCU_AT90S2343 is not set
 # CONFIG_MCU_ATTINY22 is not set
 # CONFIG_MCU_ATTINY26 is not set
 # CONFIG_MCU_AT90S2343 is not set
 # CONFIG_MCU_ATTINY22 is not set
 # CONFIG_MCU_ATTINY26 is not set
+# CONFIG_MCU_ATTINY45 is not set
 # CONFIG_MCU_AT90S4414 is not set
 # CONFIG_MCU_AT90S4433 is not set
 # CONFIG_MCU_AT90S4434 is not set
 # CONFIG_MCU_AT90S4414 is not set
 # CONFIG_MCU_AT90S4433 is not set
 # CONFIG_MCU_AT90S4434 is not set
@@ -40,6 +41,7 @@ CONFIG_MCU_ATMEGA168=y
 # CONFIG_MCU_ATMEGA32 is not set
 # CONFIG_MCU_ATMEGA323 is not set
 # CONFIG_MCU_ATMEGA325 is not set
 # CONFIG_MCU_ATMEGA32 is not set
 # CONFIG_MCU_ATMEGA323 is not set
 # CONFIG_MCU_ATMEGA325 is not set
+# CONFIG_MCU_ATMEGA328P is not set
 # CONFIG_MCU_ATMEGA3250 is not set
 # CONFIG_MCU_ATMEGA64 is not set
 # CONFIG_MCU_ATMEGA645 is not set
 # CONFIG_MCU_ATMEGA3250 is not set
 # CONFIG_MCU_ATMEGA64 is not set
 # CONFIG_MCU_ATMEGA645 is not set
@@ -51,6 +53,9 @@ CONFIG_MCU_ATMEGA168=y
 # CONFIG_MCU_AT90S1200 is not set
 # CONFIG_MCU_ATMEGA2560 is not set
 # CONFIG_MCU_ATMEGA256 is not set
 # CONFIG_MCU_AT90S1200 is not set
 # CONFIG_MCU_ATMEGA2560 is not set
 # CONFIG_MCU_ATMEGA256 is not set
+# CONFIG_MCU_ATXMEGA128A1 is not set
+# CONFIG_MCU_ATMEGA168P is not set
+# CONFIG_MCU_ATMEGA1284P is not set
 CONFIG_QUARTZ=16000000
 
 #
 CONFIG_QUARTZ=16000000
 
 #
@@ -79,7 +84,9 @@ CONFIG_MODULE_CIRBUF=y
 # CONFIG_MODULE_FIXED_POINT is not set
 # CONFIG_MODULE_VECT2 is not set
 # CONFIG_MODULE_GEOMETRY is not set
 # CONFIG_MODULE_FIXED_POINT is not set
 # CONFIG_MODULE_VECT2 is not set
 # CONFIG_MODULE_GEOMETRY is not set
+CONFIG_MODULE_HOSTSIM=y
 # CONFIG_MODULE_SCHEDULER is not set
 # CONFIG_MODULE_SCHEDULER is not set
+# CONFIG_MODULE_SCHEDULER_STATS is not set
 # CONFIG_MODULE_SCHEDULER_CREATE_CONFIG is not set
 # CONFIG_MODULE_SCHEDULER_USE_TIMERS is not set
 CONFIG_MODULE_SCHEDULER_TIMER0=y
 # CONFIG_MODULE_SCHEDULER_CREATE_CONFIG is not set
 # CONFIG_MODULE_SCHEDULER_USE_TIMERS is not set
 CONFIG_MODULE_SCHEDULER_TIMER0=y
@@ -160,9 +167,10 @@ CONFIG_MODULE_UART_CREATE_CONFIG=y
 # CONFIG_MODULE_ENCODERS_SPI_CREATE_CONFIG is not set
 
 #
 # CONFIG_MODULE_ENCODERS_SPI_CREATE_CONFIG is not set
 
 #
-# Robot specific modules
+# Robot specific modules (fixed point lib may be needed)
 #
 # CONFIG_MODULE_ROBOT_SYSTEM is not set
 #
 # CONFIG_MODULE_ROBOT_SYSTEM is not set
+# CONFIG_MODULE_ROBOT_SYSTEM_USE_F64 is not set
 # CONFIG_MODULE_ROBOT_SYSTEM_MOT_AND_EXT is not set
 # CONFIG_MODULE_POSITION_MANAGER is not set
 # CONFIG_MODULE_COMPENSATE_CENTRIFUGAL_FORCE is not set
 # CONFIG_MODULE_ROBOT_SYSTEM_MOT_AND_EXT is not set
 # CONFIG_MODULE_POSITION_MANAGER is not set
 # CONFIG_MODULE_COMPENSATE_CENTRIFUGAL_FORCE is not set
@@ -187,6 +195,9 @@ CONFIG_MODULE_UART_CREATE_CONFIG=y
 #
 # CONFIG_MODULE_CC2420 is not set
 # CONFIG_MODULE_CC2420_CREATE_CONFIG is not set
 #
 # CONFIG_MODULE_CC2420 is not set
 # CONFIG_MODULE_CC2420_CREATE_CONFIG is not set
+# CONFIG_MODULE_XBEE is not set
+# CONFIG_MODULE_XBEE_STATS is not set
+# CONFIG_MODULE_XBEE_ATCMD_HELP is not set
 
 #
 # Crypto modules
 
 #
 # Crypto modules
@@ -232,12 +243,15 @@ CONFIG_AVRDUDE_PROG_STK200=y
 # CONFIG_AVRDUDE_PROG_PAVR is not set
 # CONFIG_AVRDUDE_PROG_BUTTERFLY is not set
 # CONFIG_AVRDUDE_PROG_AVR910 is not set
 # CONFIG_AVRDUDE_PROG_PAVR is not set
 # CONFIG_AVRDUDE_PROG_BUTTERFLY is not set
 # CONFIG_AVRDUDE_PROG_AVR910 is not set
+# CONFIG_AVRDUDE_PROG_AVR911 is not set
 # CONFIG_AVRDUDE_PROG_STK500 is not set
 # CONFIG_AVRDUDE_PROG_AVRISP is not set
 # CONFIG_AVRDUDE_PROG_BSD is not set
 # CONFIG_AVRDUDE_PROG_DAPA is not set
 # CONFIG_AVRDUDE_PROG_JTAG1 is not set
 # CONFIG_AVRDUDE_PROG_AVR109 is not set
 # CONFIG_AVRDUDE_PROG_STK500 is not set
 # CONFIG_AVRDUDE_PROG_AVRISP is not set
 # CONFIG_AVRDUDE_PROG_BSD is not set
 # CONFIG_AVRDUDE_PROG_DAPA is not set
 # CONFIG_AVRDUDE_PROG_JTAG1 is not set
 # CONFIG_AVRDUDE_PROG_AVR109 is not set
+# CONFIG_AVRDUDE_PROG_AVRISPMKII is not set
+# CONFIG_AVRDUDE_PROG_ARDUINO is not set
 CONFIG_AVRDUDE_PORT="/dev/parport0"
 CONFIG_AVRDUDE_BAUDRATE=19200
 
 CONFIG_AVRDUDE_PORT="/dev/parport0"
 CONFIG_AVRDUDE_BAUDRATE=19200
 
index b5ef729..23ed2f0 100644 (file)
@@ -1,6 +1,6 @@
-/*  
+/*
  *  Copyright Droids Corporation, Microb Technology, Eirbot (2005)
  *  Copyright Droids Corporation, Microb Technology, Eirbot (2005)
- * 
+ *
  *  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
  *  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
  *  Revision : $Id: main.c,v 1.15.10.5 2008-12-27 16:29:08 zer0 Exp $
  *
  */
  *  Revision : $Id: main.c,v 1.15.10.5 2008-12-27 16:29:08 zer0 Exp $
  *
  */
-#include <uart.h>
 #include <aversive/wait.h>
 #include <aversive/wait.h>
+#include <aversive/pgmspace.h>
+
+#include <uart.h>
 
 #include <stdio.h>
 
 
 #include <stdio.h>
 
-#include <avr/io.h>
-#include <avr/pgmspace.h>
+/* sending "pop" on cmdline uart resets the robot */
+void emergency(char c)
+{
+       static uint8_t i = 0;
+
+       printf("%c\n", c);
+
+       if ((i == 0 && c == 'p') ||
+           (i == 1 && c == 'o') ||
+           (i == 2 && c == 'p'))
+               i++;
+       else if ( !(i == 1 && c == 'p') )
+               i = 0;
+       if (i == 3) {
+#ifdef HOST_VERSION
+               hostsim_uart_exit();
+#endif
+               reset();
+       }
+}
 
 /*
  * This code sends a counter value to uart.
  */
 int main(void)
 
 /*
  * This code sends a counter value to uart.
  */
 int main(void)
-{  
+{
        int i;
 
        int i;
 
+#ifdef HOST_VERSION
+       hostsim_uart_init();
+       hostsim_ittimer_enable(100000);
+#endif
+
        /* initialize uart with the default parameters ( see
         * uart_config.h ) */
        /* initialize uart with the default parameters ( see
         * uart_config.h ) */
-       uart_init();  
+       uart_init();
+       uart_register_rx_event(0, emergency);
+
        /* enable interrupts */
        sei();
 
        /* enable interrupts */
        sei();
 
@@ -47,24 +73,26 @@ int main(void)
                wait_ms(100);
        }
        uart_send(0, '\n');
                wait_ms(100);
        }
        uart_send(0, '\n');
-  
+
+#ifndef HOST_VERSION
        /* now we want to do a printf : we must register the
         * uart0_send as stdout. Here no receive function is
         * specified. */
        fdevopen(uart0_dev_send, NULL);
        /* now we want to do a printf : we must register the
         * uart0_send as stdout. Here no receive function is
         * specified. */
        fdevopen(uart0_dev_send, NULL);
-  
+#endif
+
        /** ready to do a nice printf on the uart */
        printf("Uart is cool !!\n");
        /** ready to do a nice printf on the uart */
        printf("Uart is cool !!\n");
-  
-       /* one drawback of the previous printf is that the format
-        * chain is srored in RAM and this can take a huge size if
+
+       /* one drawback of the previous printf is that the format
+        * chain is stored in RAM and this can take a huge size if
         * there are many printf. To avoid this problem, please use
         * there are many printf. To avoid this problem, please use
-        * printf_P together with PSTR, like in the next example. */ 
+        * printf_P together with PSTR, like in the next example. */
        while (1) {
                printf_P(PSTR("This format string takes no RAM "
                              "space. %i\n"), i++);
                wait_ms(1000);
        }
        while (1) {
                printf_P(PSTR("This format string takes no RAM "
                              "space. %i\n"), i++);
                wait_ms(1000);
        }
-  
+
        return 0;
 }
        return 0;
 }
index 231d599..102db28 100644 (file)
@@ -84,55 +84,55 @@ const struct regs uart_regs[UART_HW_NUM] = {
  * there is no new data in the transmit buffer.
  */
 #ifdef UART0_COMPILE
  * there is no new data in the transmit buffer.
  */
 #ifdef UART0_COMPILE
-#ifndef SIG_UART0_DATA
+#ifndef USART0_UDRE_vect
 #if defined(USART_UDRE_vect)
 #if defined(USART_UDRE_vect)
-#define SIG_UART0_DATA USART_UDRE_vect
-#elif defined(USART0_UDRE_vect)
-#define SIG_UART0_DATA USART0_UDRE_vect
+#define USART0_UDRE_vect USART_UDRE_vect
 #elif defined(SIG_USART0_DATA)
 #elif defined(SIG_USART0_DATA)
-#define SIG_UART0_DATA SIG_USART0_DATA
+#define USART0_UDRE_vect SIG_USART0_DATA
+#elif defined(SIG_UART0_DATA)
+#define USART0_UDRE_vect SIG_UART0_DATA
 #endif
 #endif
 #endif
 #endif
-SIGNAL(SIG_UART0_DATA)
+SIGNAL(USART0_UDRE_vect)
 {
        uart_send_next_char(0);
 }
 #endif
 #ifdef UART1_COMPILE
 {
        uart_send_next_char(0);
 }
 #endif
 #ifdef UART1_COMPILE
-#ifndef SIG_UART1_DATA
-#if defined(USART1_UDRE_vect)
-#define SIG_UART1_DATA USART1_UDRE_vect
-#elif defined(SIG_USART1_DATA)
-#define SIG_UART1_DATA SIG_USART1_DATA
+#ifndef USART1_UDRE_vect
+#if defined(SIG_USART1_DATA)
+#define USART1_UDRE_vect SIG_USART1_DATA
+#elif defined(SIG_UART1_DATA)
+#define USART1_UDRE_vect SIG_UART1_DATA
 #endif
 #endif
 #endif
 #endif
-SIGNAL(SIG_UART1_DATA)
+SIGNAL(USART1_UDRE_vect)
 {
        uart_send_next_char(1);
 }
 #endif
 #ifdef UART2_COMPILE
 {
        uart_send_next_char(1);
 }
 #endif
 #ifdef UART2_COMPILE
-#ifndef SIG_UART2_DATA
-#if defined(USART2_UDRE_vect)
-#define SIG_UART2_DATA USART2_UDRE_vect
-#elif defined(SIG_USART2_DATA)
-#define SIG_UART2_DATA SIG_USART2_DATA
+#ifndef USART2_UDRE_vect
+#if defined(SIG_USART2_DATA)
+#define USART2_UDRE_vect SIG_USART2_DATA
+#elif defined(SIG_UART2_DATA)
+#define USART2_UDRE_vect SIG_UART2_DATA
 #endif
 #endif
 #endif
 #endif
-SIGNAL(SIG_UART2_DATA)
+SIGNAL(USART2_UDRE_vect)
 {
        uart_send_next_char(2);
 }
 #endif
 #ifdef UART3_COMPILE
 {
        uart_send_next_char(2);
 }
 #endif
 #ifdef UART3_COMPILE
-#ifndef SIG_UART3_DATA
-#if defined(USART3_UDRE_vect)
-#define SIG_UART3_DATA USART3_UDRE_vect
-#elif defined(SIG_USART3_DATA)
-#define SIG_UART3_DATA SIG_USART3_DATA
+#ifndef USART3_UDRE_vect
+#if defined(SIG_USART3_DATA)
+#define USART3_UDRE_vect SIG_USART3_DATA
+#elif defined(SIG_UART3_DATA)
+#define USART3_UDRE_vect SIG_UART3_DATA
 #endif
 #endif
 #endif
 #endif
-SIGNAL(SIG_UART3_DATA)
+SIGNAL(USART3_UDRE_vect)
 {
        uart_send_next_char(3);
 }
 {
        uart_send_next_char(3);
 }
@@ -145,55 +145,55 @@ static void uart_recv_next_char(uint8_t num);
  * a new unread data in the reception buffer.
  */
 #ifdef UART0_COMPILE
  * a new unread data in the reception buffer.
  */
 #ifdef UART0_COMPILE
-#ifndef SIG_UART0_RECV
+#ifndef USART0_RX_vect
 #if defined(USART_RX_vect)
 #if defined(USART_RX_vect)
-#define SIG_UART0_RECV USART_RX_vect
-#elif defined(USART0_RX_vect)
-#define SIG_UART0_RECV USART0_RX_vect
+#define USART0_RX_vect USART_RX_vect
 #elif defined(SIG_USART0_RECV)
 #elif defined(SIG_USART0_RECV)
-#define SIG_UART0_RECV SIG_USART0_RECV
+#define USART0_RX_vect SIG_USART0_RECV
+#elif defined(SIG_UART0_RECV)
+#define USART0_RX_vect SIG_UART0_RECV
 #endif
 #endif
 #endif
 #endif
-SIGNAL(SIG_UART0_RECV)
+SIGNAL(USART0_RX_vect)
 {
        uart_recv_next_char(0);
 }
 #endif
 #ifdef UART1_COMPILE
 {
        uart_recv_next_char(0);
 }
 #endif
 #ifdef UART1_COMPILE
-#ifndef SIG_UART1_RECV
-#if defined(USART1_RX_vect)
-#define SIG_UART1_RECV USART1_RX_vect
-#elif defined(SIG_USART1_RECV)
-#define SIG_UART1_RECV SIG_USART1_RECV
+#ifndef USART1_RX_vect
+#if defined(SIG_USART1_RECV)
+#define USART1_RX_vect SIG_USART1_RECV
+#elif defined(SIG_UART1_RECV)
+#define USART1_RX_vect SIG_UART1_RECV
 #endif
 #endif
 #endif
 #endif
-SIGNAL(SIG_UART1_RECV)
+SIGNAL(USART1_RX_vect)
 {
        uart_recv_next_char(1);
 }
 #endif
 #ifdef UART2_COMPILE
 {
        uart_recv_next_char(1);
 }
 #endif
 #ifdef UART2_COMPILE
-#ifndef SIG_UART2_RECV
-#if defined(USART2_RX_vect)
-#define SIG_UART2_RECV USART2_RX_vect
-#elif defined(SIG_USART2_RECV)
-#define SIG_UART2_RECV SIG_USART2_RECV
+#ifndef USART2_RX_vect
+#if defined(SIG_USART2_RECV)
+#define USART2_RX_vect SIG_USART2_RECV
+#elif defined(SIG_UART2_RECV)
+#define USART2_RX_vect SIG_UART2_RECV
 #endif
 #endif
 #endif
 #endif
-SIGNAL(SIG_UART2_RECV)
+SIGNAL(USART2_RX_vect)
 {
        uart_recv_next_char(2);
 }
 #endif
 #ifdef UART3_COMPILE
 {
        uart_recv_next_char(2);
 }
 #endif
 #ifdef UART3_COMPILE
-#ifndef SIG_UART3_RECV
-#if defined(USART3_RX_vect)
-#define SIG_UART3_RECV USART3_RX_vect
-#elif defined(SIG_USART3_RECV)
-#define SIG_UART3_RECV SIG_USART3_RECV
+#ifndef USART3_RX_vect
+#if defined(SIG_USART3_RECV)
+#define USART3_RX_vect SIG_USART3_RECV
+#elif defined(SIG_UART3_RECV)
+#define USART3_RX_vect SIG_UART3_RECV
 #endif
 #endif
 #endif
 #endif
-SIGNAL(SIG_UART3_RECV)
+SIGNAL(USART3_RX_vect)
 {
        uart_recv_next_char(3);
 }
 {
        uart_recv_next_char(3);
 }
index e8d6171..9a7e437 100644 (file)
 #endif\r
 \r
 \r
 #endif\r
 \r
 \r
-/* For arch with only one UART, we consider that UART0 = UART */\r
-#if !defined(SIG_UART0_DATA) && !defined(SIG_USART0_DATA)\r
-#if defined SIG_UART_DATA\r
-#define SIG_UART0_DATA SIG_UART_DATA\r
-#elif defined SIG_USART_DATA\r
-#define SIG_UART0_DATA SIG_USART_DATA\r
-#endif\r
-#endif\r
-\r
-#if !defined(SIG_UART0_RECV) && !defined(SIG_USART0_RECV)\r
-#if defined SIG_UART_RECV\r
-#define SIG_UART0_RECV  SIG_UART_RECV\r
-#elif defined SIG_USART_RECV\r
-#define SIG_UART0_RECV  SIG_USART_RECV\r
-#endif\r
-#endif\r
-\r
 #if !defined(UDR0) && defined(UDR)\r
 #define UDR0 UDR\r
 #endif\r
 #if !defined(UDR0) && defined(UDR)\r
 #define UDR0 UDR\r
 #endif\r
 \r
 \r
 /* if the signal USART is defined, the uC has a USART. */\r
 \r
 \r
 /* if the signal USART is defined, the uC has a USART. */\r
-#if ( defined SIG_USART0_RECV ) || ( defined SIG_USART_RECV )\r
-#define UART_IS_USART 1\r
-#elif (defined USART_UDRE_vect) || (defined USART_TXC_vect) || (defined USART_RXC_vect)\r
-#define UART_IS_USART 1\r
-#elif (defined USART1_UDRE_vect) || (defined USART1_TXC_vect) || (defined USART1_RXC_vect)\r
-#define UART_IS_USART 1\r
-#else\r
+#if defined(UART_TX_vect)\r
 #define UART_IS_USART 0\r
 #define UART_IS_USART 0\r
+#else\r
+#define UART_IS_USART 1\r
 #endif\r
 \r
 /* if the U2X macro is defined, the uC has the U2X option. */\r
 #endif\r
 \r
 /* if the U2X macro is defined, the uC has the U2X option. */\r
index 7088887..91c12af 100644 (file)
@@ -98,10 +98,10 @@ static int8_t uart_set_nbits_parity(int8_t num, struct uart_config * u)
 {
        /* number of bit in the frame */
        if (u->nbits == 8)
 {
        /* number of bit in the frame */
        if (u->nbits == 8)
-               *uart_regs[num].ucsrb &= ~(1 << CHR9);
+               *uart_regs[num].ucsrb &= ~(1 << UCSZ2);
 #ifdef CONFIG_MODULE_UART_9BITS
        else if (u->nbits == 9)
 #ifdef CONFIG_MODULE_UART_9BITS
        else if (u->nbits == 9)
-               *uart_regs[num].ucsrb |= (1 << CHR9);
+               *uart_regs[num].ucsrb |= (1 << UCSZ2);
 #endif
        else
                return ENOTSUP;
 #endif
        else
                return ENOTSUP;