Fix a bug in the (unused) RTS/CTS code; Clarify documentation.
[bertos.git] / drv / ser_avr.c
index 4947b540755fa451e6173006a405088894b50a32..0841c68ff49cc9c51eed63c3d68b14dc95cde245 100755 (executable)
  * \author Stefano Fedrigo <aleph@develer.com>
  */
 
-/*
- * $Log$
- * Revision 1.10  2004/08/10 06:30:41  bernie
- * Major redesign of serial bus policy handling.
- *
- * Revision 1.9  2004/08/02 20:20:29  aleph
- * Merge from project_ks
- *
- * Revision 1.8  2004/07/29 22:57:09  bernie
- * Several tweaks to reduce code size on ATmega8.
- *
- * Revision 1.7  2004/07/18 21:54:23  bernie
- * Add ATmega8 support.
- *
- * Revision 1.5  2004/06/27 15:25:40  aleph
- * Add missing callbacks for SPI;
- * Change UNUSED() macro to new version with two args;
- * Use TX line filling only on the correct KBUS serial port;
- * Fix nasty IRQ disabling bug in recv complete hander for port 1.
- *
- * Revision 1.4  2004/06/03 11:27:09  bernie
- * Add dual-license information.
- *
- * Revision 1.3  2004/06/02 21:35:24  aleph
- * Serial enhancements: interruptible receive handler and 8 bit serial status for AVR; remove volatile attribute to FIFOBuffer, useless for new fifobuf routens
- *
- * Revision 1.2  2004/05/23 18:21:53  bernie
- * Trim CVS logs and cleanup header info.
- *
- */
+/*#*
+ *#* $Log$
+ *#* Revision 1.12  2004/08/29 22:06:10  bernie
+ *#* Fix a bug in the (unused) RTS/CTS code; Clarify documentation.
+ *#*
+ *#* Revision 1.10  2004/08/10 06:30:41  bernie
+ *#* Major redesign of serial bus policy handling.
+ *#*
+ *#* Revision 1.9  2004/08/02 20:20:29  aleph
+ *#* Merge from project_ks
+ *#*
+ *#* Revision 1.8  2004/07/29 22:57:09  bernie
+ *#* Several tweaks to reduce code size on ATmega8.
+ *#*
+ *#* Revision 1.7  2004/07/18 21:54:23  bernie
+ *#* Add ATmega8 support.
+ *#*
+ *#* Revision 1.5  2004/06/27 15:25:40  aleph
+ *#* Add missing callbacks for SPI;
+ *#* Change UNUSED() macro to new version with two args;
+ *#* Use TX line filling only on the correct KBUS serial port;
+ *#* Fix nasty IRQ disabling bug in recv complete hander for port 1.
+ *#*
+ *#* Revision 1.4  2004/06/03 11:27:09  bernie
+ *#* Add dual-license information.
+ *#*
+ *#* Revision 1.3  2004/06/02 21:35:24  aleph
+ *#* Serial enhancements: interruptible receive handler and 8 bit serial status for AVR; remove volatile attribute to FIFOBuffer, useless for new fifobuf routens
+ *#*
+ *#* Revision 1.2  2004/05/23 18:21:53  bernie
+ *#* Trim CVS logs and cleanup header info.
+ *#*
+ *#*/
 
 #include "ser.h"
 #include "ser_p.h"
-#include "kdebug.h"
 #include "config.h"
-#include "hw.h"
+#include "hw.h"  /* Required for bus macros overrides */
+
+#include <drv/kdebug.h>
 #include <drv/timer.h>
 #include <mware/fifobuf.h>
 
 
 
 /*!
- * \def CONFIG_SER_STROBE
- *
- * This is a debug facility that can be used to
- * monitor SER interrupt activity on an external pin.
- *
- * To use strobes, redefine the macros SER_STROBE_ON,
- * SER_STROBE_OFF and SER_STROBE_INIT and set
- * CONFIG_SER_STROBE to 1.
- */
-#ifndef CONFIG_SER_STROBE
-       #define SER_STROBE_ON    do {/*nop*/} while(0)
-       #define SER_STROBE_OFF   do {/*nop*/} while(0)
-       #define SER_STROBE_INIT  do {/*nop*/} while(0)
-#endif
-
-
-/*!
- * \name Overridable serial hooks
+ * \name Overridable serial bus hooks
  *
  * These can be redefined in hw.h to implement
  * special bus policies such as half-duplex, 485, etc.
 #endif
 
 
+/*!
+ * \def CONFIG_SER_STROBE
+ *
+ * This is a debug facility that can be used to
+ * monitor SER interrupt activity on an external pin.
+ *
+ * To use strobes, redefine the macros SER_STROBE_ON,
+ * SER_STROBE_OFF and SER_STROBE_INIT and set
+ * CONFIG_SER_STROBE to 1.
+ */
+#ifndef CONFIG_SER_STROBE
+       #define SER_STROBE_ON    do {/*nop*/} while(0)
+       #define SER_STROBE_OFF   do {/*nop*/} while(0)
+       #define SER_STROBE_INIT  do {/*nop*/} while(0)
+#endif
+
+
 /* From the high-level serial driver */
 extern struct Serial ser_handles[SER_CNT];
 
+
 /*!
  * Internal hardware state structure
  *
- * \a sending var is true if we are transmitting.
- * SPI note: this flag is necessary because the SPI sends and receives bytes
- * at the same time and the SPI IRQ is unique for send/receive.
- * The only way to start transmission is to write data in SPDR (this
- * is done by spi_starttx()). We do this *only* if a transfer is
- * not already started.
+ * The \a sending variable is true while the transmission
+ * interrupt is retriggering itself.
  *
  * For the USARTs the \a sending flag is useful for taking specific
  * actions before sending a burst of data, at the start of a trasmission
  * but not before every char sent.
+ *
+ * For the SPI, this flag is necessary because the SPI sends and receives
+ * bytes at the same time and the SPI IRQ is unique for send/receive.
+ * The only way to start transmission is to write data in SPDR (this
+ * is done by spi_starttx()). We do this *only* if a transfer is
+ * not already started.
  */
 struct AvrSerial
 {
@@ -280,6 +287,7 @@ struct AvrSerial
        volatile bool sending;
 };
 
+
 /*
  * These are to trick GCC into *not* using
  * absolute addressing mode when accessing
@@ -337,7 +345,7 @@ static void uart0_setbaudrate(UNUSED(struct SerialHardware *, _hw), unsigned lon
 #endif
        UBRR0L = (period);
 
-       DB(kprintf("uart0_setbaudrate(rate=%lu): period=%d\n", rate, period);)
+       //DB(kprintf("uart0_setbaudrate(rate=%lu): period=%d\n", rate, period);)
 }
 
 static void uart0_setparity(UNUSED(struct SerialHardware *, _hw), int parity)
@@ -386,7 +394,7 @@ static void uart1_setbaudrate(UNUSED(struct SerialHardware *, _hw), unsigned lon
        UBRR1H = (period) >> 8;
        UBRR1L = (period);
 
-       DB(kprintf("uart1_setbaudrate(rate=%ld): period=%d\n", rate, period);)
+       //DB(kprintf("uart1_setbaudrate(rate=%ld): period=%d\n", rate, period);)
 }
 
 static void uart1_setparity(UNUSED(struct SerialHardware *, _hw), int parity)
@@ -549,7 +557,7 @@ SIGNAL(SIG_UART0_DATA)
        {
                // Disable rx interrupt and tx, enable CTS interrupt
                // UNTESTED
-               UCSR0B = BV(RXCIE) | BV(RXEN);
+               UCSR0B = BV(RXCIE) | BV(RXEN) | BV(TXEN);
                sbi(EIFR, EIMSKB_CTS);
                sbi(EIMSK, EIMSKB_CTS);
        }
@@ -620,7 +628,7 @@ SIGNAL(SIG_UART1_DATA)
        {
                // Disable rx interrupt and tx, enable CTS interrupt
                // UNTESTED
-               UCSR1B = BV(RXCIE) | BV(RXEN);
+               UCSR1B = BV(RXCIE) | BV(RXEN) | BV(TXEN);
                sbi(EIFR, EIMSKB_CTS);
                sbi(EIMSK, EIMSKB_CTS);
        }