Add preliminary FreeRTOS support; Enforce CONFIG_* definitions.
[bertos.git] / drv / ser_avr.c
index aa239de4af9f038426fca84fccfbcc7b0c25c013..90d81fc429a4518bb213d897a21f52e0e819ab68 100755 (executable)
@@ -3,7 +3,7 @@
  * <!--
  * Copyright 2003, 2004 Develer S.r.l. (http://www.develer.com/)
  * Copyright 2000 Bernardo Innocenti <bernie@codewiz.org>
- * This file is part of DevLib - See devlib/README for information.
+ * This file is part of DevLib - See README.devlib for information.
  * -->
  *
  * \brief AVR UART and SPI I/O driver
 
 /*#*
  *#* $Log$
+ *#* Revision 1.29  2005/11/27 23:31:48  bernie
+ *#* Support avr-libc 1.4.
+ *#*
+ *#* Revision 1.28  2005/11/04 16:20:02  bernie
+ *#* Fix reference to README.devlib in header.
+ *#*
+ *#* Revision 1.27  2005/07/03 15:19:31  bernie
+ *#* Doxygen fix.
+ *#*
+ *#* Revision 1.26  2005/04/11 19:10:27  bernie
+ *#* Include top-level headers from cfg/ subdir.
+ *#*
+ *#* Revision 1.25  2005/01/25 08:37:26  bernie
+ *#* CONFIG_SER_HWHANDSHAKE fixes.
+ *#*
  *#* Revision 1.24  2005/01/14 00:49:16  aleph
  *#* Rename callbacks; SerialHardwareVT.txSending: New callback; Add SPI_BUS macros.
  *#*
 
 #include "ser.h"
 #include "ser_p.h"
-#include "config.h"
 #include "hw.h"  /* Required for bus macros overrides */
+#include <appconfig.h>
 
-#include <debug.h>
+#include <cfg/debug.h>
 #include <drv/timer.h>
 #include <mware/fifobuf.h>
 
-#include <avr/signal.h>
 #include <avr/io.h>
+#if defined(__AVR_LIBC_VERSION__) && (__AVR_LIBC_VERSION__ >= 10400UL)
+       #include <avr/interrupt.h>
+#else
+       #include <avr/signal.h>
+#endif
 
 
-/*!
- * \name Hardware handshake (RTS/CTS).
- * \{
- */
-#ifndef RTS_ON
-#define RTS_ON      do {} while (0)
-#endif
-#ifndef RTS_OFF
-#define RTS_OFF     do {} while (0)
-#endif
-#ifndef IS_CTS_ON
-#define IS_CTS_ON   true
-#endif
-#ifndef EIMSKB_CTS
-#define EIMSKB_CTS  0 /*!< Dummy value, must be overridden */
+#if !CONFIG_SER_HWHANDSHAKE
+       /*!
+        * \name Hardware handshake (RTS/CTS).
+        * \{
+        */
+       #define RTS_ON      do {} while (0)
+       #define RTS_OFF     do {} while (0)
+       #define IS_CTS_ON   true
+       #define EIMSKF_CTS  0 /*!< Dummy value, must be overridden */
+       /*\}*/
 #endif
-/*\}*/
 
 
 /*!
  */
 #ifndef SER_SPI_BUS_TXINIT
        /*!
-        * \def SER_SPI_BUS_TXINIT
-        *
         * Default TXINIT macro - invoked in spi_init()
         * The default is no action.
         */
 
 #ifndef SER_SPI_BUS_TXCLOSE
        /*!
-        * \def SER_SPI_BUS_TXCLOSE
-        *
         * Invoked after the last character has been transmitted.
         * The default is no action.
         */
@@ -436,7 +445,7 @@ static void uart0_setbaudrate(UNUSED_ARG(struct SerialHardware *, _hw), unsigned
        /* Compute baud-rate period */
        uint16_t period = (((CLOCK_FREQ / 16UL) + (rate / 2)) / rate) - 1;
 
-#ifndef __AVR_ATmega103__
+#if !CPU_AVR_ATMEGA103
        UBRR0H = (period) >> 8;
 #endif
        UBRR0L = (period);
@@ -673,7 +682,7 @@ SIGNAL(SIG_CTS)
 {
        // Re-enable UDR empty interrupt and TX, then disable CTS interrupt
        UCSR0B = BV(RXCIE) | BV(UDRIE) | BV(RXEN) | BV(TXEN);
-       cbi(EIMSK, EIMSKB_CTS);
+       EIMSK &= ~EIMSKF_CTS;
 }
 
 #endif // CONFIG_SER_HWHANDSHAKE
@@ -701,8 +710,8 @@ SIGNAL(SIG_UART0_DATA)
                // Disable rx interrupt and tx, enable CTS interrupt
                // UNTESTED
                UCSR0B = BV(RXCIE) | BV(RXEN) | BV(TXEN);
-               sbi(EIFR, EIMSKB_CTS);
-               sbi(EIMSK, EIMSKB_CTS);
+               EIFR |= EIMSKF_CTS;
+               EIMSK |= EIMSKF_CTS;
        }
 #endif
        else
@@ -772,8 +781,8 @@ SIGNAL(SIG_UART1_DATA)
                // Disable rx interrupt and tx, enable CTS interrupt
                // UNTESTED
                UCSR1B = BV(RXCIE) | BV(RXEN) | BV(TXEN);
-               sbi(EIFR, EIMSKB_CTS);
-               sbi(EIMSK, EIMSKB_CTS);
+               EIFR |= EIMSKF_CTS;
+               EIMSK |= EIMSKF_CTS;
        }
 #endif
        else