2626#include < string.h>
2727#include < inttypes.h>
2828#include " Arduino.h"
29- #include " wiring_private.h"
3029
3130#include " HardwareSerial.h"
31+ #include " HardwareSerial_private.h"
3232
3333// this next line disables the entire HardwareSerial.cpp,
3434// this is so I can support Attiny series and any other chip without a uart
3535#if defined(HAVE_HWSERIAL0) || defined(HAVE_HWSERIAL1) || defined(HAVE_HWSERIAL2) || defined(HAVE_HWSERIAL3)
3636
37- // Ensure that the various bit positions we use are available with a 0
38- // postfix, so we can always use the values for UART0 for all UARTs. The
39- // alternative, passing the various values for each UART to the
40- // HardwareSerial constructor also works, but makes the code bigger and
41- // slower.
42- #if !defined(TXC0)
43- #if defined(TXC)
44- // On ATmega8, the uart and its bits are not numbered, so there is no TXC0 etc.
45- #define TXC0 TXC
46- #define RXEN0 RXEN
47- #define TXEN0 TXEN
48- #define RXCIE0 RXCIE
49- #define UDRIE0 UDRIE
50- #define U2X0 U2X
51- #define UPE0 UPE
52- #define UDRE0 UDRE
53- #elif defined(TXC1)
54- // Some devices have uart1 but no uart0
55- #define TXC0 TXC1
56- #define RXEN0 RXEN1
57- #define TXEN0 TXEN1
58- #define RXCIE0 RXCIE1
59- #define UDRIE0 UDRIE1
60- #define U2X0 U2X1
61- #define UPE0 UPE1
62- #define UDRE0 UDRE1
63- #else
64- #error No UART found in HardwareSerial.cpp
65- #endif
66- #endif // !defined TXC0
67-
68- // Check at compiletime that it is really ok to use the bit positions of
69- // UART0 for the other UARTs as well, in case these values ever get
70- // changed for future hardware.
71- #if defined(TXC1) && (TXC1 != TXC0 || RXEN1 != RXEN0 || RXCIE1 != RXCIE0 || \
72- UDRIE1 != UDRIE0 || U2X1 != U2X0 || UPE1 != UPE0 || \
73- UDRE1 != UDRE0)
74- #error "Not all bit positions for UART1 are the same as for UART0"
75- #endif
76- #if defined(TXC2) && (TXC2 != TXC0 || RXEN2 != RXEN0 || RXCIE2 != RXCIE0 || \
77- UDRIE2 != UDRIE0 || U2X2 != U2X0 || UPE2 != UPE0 || \
78- UDRE2 != UDRE0)
79- #error "Not all bit positions for UART2 are the same as for UART0"
80- #endif
81- #if defined(TXC3) && (TXC3 != TXC0 || RXEN3 != RXEN0 || RXCIE3 != RXCIE0 || \
82- UDRIE3 != UDRIE0 || U3X3 != U3X0 || UPE3 != UPE0 || \
83- UDRE3 != UDRE0)
84- #error "Not all bit positions for UART3 are the same as for UART0"
85- #endif
86-
8737// SerialEvent functions are weak, so when the user doesn't define them,
8838// the linker just sets their address to 0 (which is checked below).
8939// The Serialx_available is just a wrapper around Serialx.available(),
@@ -127,28 +77,6 @@ void serialEventRun(void)
12777
12878// Actual interrupt handlers //////////////////////////////////////////////////////////////
12979
130- void HardwareSerial::_rx_complete_irq (void )
131- {
132- if (bit_is_clear (*_ucsra, UPE0)) {
133- // No Parity error, read byte and store it in the buffer if there is
134- // room
135- unsigned char c = *_udr;
136- int i = (unsigned int )(_rx_buffer_head + 1 ) % SERIAL_BUFFER_SIZE;
137-
138- // if we should be storing the received character into the location
139- // just before the tail (meaning that the head would advance to the
140- // current location of the tail), we're about to overflow the buffer
141- // and so we don't write the character or advance the head.
142- if (i != _rx_buffer_tail) {
143- _rx_buffer[_rx_buffer_head] = c;
144- _rx_buffer_head = i;
145- }
146- } else {
147- // Parity error, read byte but discard it
148- unsigned char c = *_udr;
149- };
150- }
151-
15280void HardwareSerial::_tx_udr_empty_irq (void )
15381{
15482 // If interrupts are enabled, there must be more data in the output
@@ -169,23 +97,6 @@ void HardwareSerial::_tx_udr_empty_irq(void)
16997 }
17098}
17199
172- // Constructors ////////////////////////////////////////////////////////////////
173-
174- HardwareSerial::HardwareSerial (
175- volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
176- volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
177- volatile uint8_t *ucsrc, volatile uint8_t *udr)
178- {
179- _tx_buffer_head = _tx_buffer_tail = 0 ;
180- _rx_buffer_head = _rx_buffer_tail = 0 ;
181- _ubrrh = ubrrh;
182- _ubrrl = ubrrl;
183- _ucsra = ucsra;
184- _ucsrb = ucsrb;
185- _ucsrc = ucsrc;
186- _udr = udr;
187- }
188-
189100// Public Methods //////////////////////////////////////////////////////////////
190101
191102void HardwareSerial::begin (unsigned long baud, byte config)
0 commit comments