| 1 | /* | 
| 2 |   HardwareSerial0.cpp - Hardware serial library for Wiring | 
| 3 |   Copyright (c) 2006 Nicholas Zambetti.  All right reserved. | 
| 4 |  | 
| 5 |   This library is free software; you can redistribute it and/or | 
| 6 |   modify it under the terms of the GNU Lesser General Public | 
| 7 |   License as published by the Free Software Foundation; either | 
| 8 |   version 2.1 of the License, or (at your option) any later version. | 
| 9 |  | 
| 10 |   This library is distributed in the hope that it will be useful, | 
| 11 |   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 12 |   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
| 13 |   Lesser General Public License for more details. | 
| 14 |  | 
| 15 |   You should have received a copy of the GNU Lesser General Public | 
| 16 |   License along with this library; if not, write to the Free Software | 
| 17 |   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA | 
| 18 |  | 
| 19 |   Modified 23 November 2006 by David A. Mellis | 
| 20 |   Modified 28 September 2010 by Mark Sproul | 
| 21 |   Modified 14 August 2012 by Alarus | 
| 22 |   Modified 3 December 2013 by Matthijs Kooijman | 
| 23 | */ | 
| 24 | 
 | 
| 25 | #include "Arduino.h" | 
| 26 | #include "HardwareSerial.h" | 
| 27 | #include "HardwareSerial_private.h" | 
| 28 | 
 | 
| 29 | // Each HardwareSerial is defined in its own file, sine the linker pulls | 
| 30 | // in the entire file when any element inside is used. --gc-sections can | 
| 31 | // additionally cause unused symbols to be dropped, but ISRs have the | 
| 32 | // "used" attribute so are never dropped and they keep the | 
| 33 | // HardwareSerial instance in as well. Putting each instance in its own | 
| 34 | // file prevents the linker from pulling in any unused instances in the | 
| 35 | // first place. | 
| 36 | 
 | 
| 37 | #if defined(HAVE_HWSERIAL0) | 
| 38 | 
 | 
| 39 | #if defined(USART_RX_vect) | 
| 40 |   ISR(USART_RX_vect) | 
| 41 | #elif defined(USART0_RX_vect) | 
| 42 |   ISR(USART0_RX_vect) | 
| 43 | #elif defined(USART_RXC_vect) | 
| 44 |   ISR(USART_RXC_vect) // ATmega8 | 
| 45 | #else | 
| 46 |   #error "Don't know what the Data Received vector is called for Serial" | 
| 47 | #endif | 
| 48 |   { | 
| 49 |     Serial._rx_complete_irq(); | 
| 50 |   } | 
| 51 | 
 | 
| 52 | #if defined(UART0_UDRE_vect) | 
| 53 | ISR(UART0_UDRE_vect) | 
| 54 | #elif defined(UART_UDRE_vect) | 
| 55 | ISR(UART_UDRE_vect) | 
| 56 | #elif defined(USART0_UDRE_vect) | 
| 57 | ISR(USART0_UDRE_vect) | 
| 58 | #elif defined(USART_UDRE_vect) | 
| 59 | ISR(USART_UDRE_vect) | 
| 60 | #else | 
| 61 |   #error "Don't know what the Data Register Empty vector is called for Serial" | 
| 62 | #endif | 
| 63 | { | 
| 64 |   Serial._tx_udr_empty_irq(); | 
| 65 | } | 
| 66 | 
 | 
| 67 | #if defined(UBRRH) && defined(UBRRL) | 
| 68 |   HardwareSerial Serial(&UBRRH, &UBRRL, &UCSRA, &UCSRB, &UCSRC, &UDR); | 
| 69 | #else | 
| 70 |   HardwareSerial Serial(&UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UCSR0C, &UDR0); | 
| 71 | #endif | 
| 72 | 
 | 
| 73 | // Function that can be weakly referenced by serialEventRun to prevent | 
| 74 | // pulling in this file if it's not otherwise used. | 
| 75 | bool Serial0_available() { | 
| 76 |   return Serial.available(); | 
| 77 | } | 
| 78 | 
 | 
| 79 | #endif // HAVE_HWSERIAL0 | 
| 80 | 
 |