Skip to content
Browse files

Updating ATmega1284P support; UART interrupt handling and second uart.

  • Loading branch information...
1 parent 568177b commit 97d796808389a58544815ebba441e28eafe4d2bd @mikaelpatel committed Feb 23, 2013
Showing with 47 additions and 7 deletions.
  1. +4 −1 Cosa/Board.hh
  2. +1 −0 Cosa/IOBuffer.hh
  3. +25 −3 Cosa/IOStream/Driver/UART.cpp
  4. +17 −3 Cosa/IOStream/Driver/UART.hh
View
5 Cosa/Board.hh
@@ -174,6 +174,9 @@ public:
#elif defined(__AVR_ATmega1284P__)
+#define USART_UDRE_vect USART0_UDRE_vect
+#define USART_RX_vect USART0_RX_vect
+
class Board {
friend class Pin;
friend class UART;
@@ -214,7 +217,7 @@ private:
*/
static volatile uint8_t* UART(uint8_t port)
{
- return (&UCSR0A);
+ return (port == 1 ? &UCSR1A : &UCSR0A);
}
public:
View
1 Cosa/IOBuffer.hh
@@ -121,6 +121,7 @@ public:
{
m_tail = 0;
m_head = 0;
+ return (0);
}
};
View
28 Cosa/IOStream/Driver/UART.cpp
@@ -73,7 +73,7 @@ static IOBuffer ibuf(sizeof(ibuffer), ibuffer);
static char obuffer[UART::BUFFER_MAX];
static IOBuffer obuf(sizeof(obuffer), obuffer);
-UART uart(0, &ibuf, &obuf) __attribute__ ((weak));
+UART uart(0, &ibuf, &obuf);
bool
UART::begin(uint32_t baudrate, uint8_t format)
@@ -140,8 +140,30 @@ ISR(USART_RX_vect)
uart.m_ibuf->putchar(UDR0);
}
-#if defined(__AVR_ATmega1280__) \
- || defined(__AVR_ATmega2560__)
+#if defined(__AVR_ATmega1284P__)
+
+UART* uart1 = 0;
+
+ISR(USART1_UDRE_vect)
+{
+ if (uart1 == 0) return;
+ int c = uart1->m_obuf->getchar();
+ if (c != -1) {
+ UDR1 = c;
+ }
+ else {
+ bit_clear(UCSR1B, UDRIE0);
+ }
+}
+
+ISR(USART1_RX_vect)
+{
+ if (uart1 == 0) return;
+ uart1->m_ibuf->putchar(UDR1);
+}
+#endif
+
+#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
// Fix: Add Arduino Mega UART interrupt handlers
View
20 Cosa/IOStream/Driver/UART.hh
@@ -108,6 +108,18 @@ public:
extern "C" void USART_UDRE_vect(void) __attribute__ ((signal));
extern "C" void USART_RX_vect(void) __attribute__ ((signal));
+#if defined(__AVR_ATmega1284P__)
+extern "C" void USART1_UDRE_vect(void) __attribute__ ((signal));
+extern "C" void USART1_RX_vect(void) __attribute__ ((signal));
+#endif
+#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
+extern "C" void USART1_UDRE_vect(void) __attribute__ ((signal));
+extern "C" void USART1_RX_vect(void) __attribute__ ((signal));
+extern "C" void USART2_UDRE_vect(void) __attribute__ ((signal));
+extern "C" void USART2_RX_vect(void) __attribute__ ((signal));
+extern "C" void USART3_UDRE_vect(void) __attribute__ ((signal));
+extern "C" void USART3_RX_vect(void) __attribute__ ((signal));
+#endif
class UART : public IOStream::Device {
private:
@@ -163,9 +175,11 @@ private:
// Interrupt handlers are friends
friend void USART_UDRE_vect(void);
friend void USART_RX_vect(void);
-
-#if defined(__AVR_ATmega1280__) \
- || defined(__AVR_ATmega2560__)
+#if defined(__AVR_ATmega1284P__)
+ friend void USART1_UDRE_vect(void);
+ friend void USART1_RX_vect(void);
+#endif
+#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
friend void USART1_UDRE_vect(void);
friend void USART1_RX_vect(void);
friend void USART2_UDRE_vect(void);

0 comments on commit 97d7968

Please sign in to comment.
Something went wrong with that request. Please try again.