aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino/HardwareSerial.h
diff options
context:
space:
mode:
authorMatthijs Kooijman <matthijs@stdin.nl>2013-04-18 11:38:13 +0200
committerCristian Maglie <c.maglie@bug.st>2014-01-16 16:59:06 +0100
commit80d6af62730f11f9f23ec7a14d69bc6cfa01dd03 (patch)
treece95365a73852a5f0ee7030e7276c977a7dcfc44 /cores/arduino/HardwareSerial.h
parent3babfc2a855e49c5781f433fb5bd1227c8161dd8 (diff)
Move interrupt handlers into HardwareSerial class
The actual interrupt vectors are of course defined as before, but they let new methods in the HardwareSerial class do the actual work. This greatly reduces code duplication and prepares for one of my next commits which requires the tx interrupt handler to be called from another context as well. The actual content of the interrupts handlers was pretty much identical, so that remains unchanged (except that store_char was now only needed once, so it was inlined). Now all access to the buffers are inside the HardwareSerial class, the buffer variables can be made private. One would expect a program size reduction from this change (at least with multiple UARTs), but due to the fact that the interrupt handlers now only have indirect access to a few registers (which previously were just hardcoded in the handlers) and because there is some extra function call overhead, the code size on the uno actually increases by around 70 bytes. On the mega, which has four UARTs, the code size decreases by around 70 bytes.
Diffstat (limited to 'cores/arduino/HardwareSerial.h')
-rw-r--r--cores/arduino/HardwareSerial.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/cores/arduino/HardwareSerial.h b/cores/arduino/HardwareSerial.h
index 5513226..cf3f6bd 100644
--- a/cores/arduino/HardwareSerial.h
+++ b/cores/arduino/HardwareSerial.h
@@ -74,7 +74,6 @@ class HardwareSerial : public Stream
volatile uint8_t *_udr;
bool transmitting;
- public:
volatile uint8_t _rx_buffer_head;
volatile uint8_t _rx_buffer_tail;
volatile uint8_t _tx_buffer_head;
@@ -86,6 +85,7 @@ class HardwareSerial : public Stream
unsigned char _rx_buffer[SERIAL_BUFFER_SIZE];
unsigned char _tx_buffer[SERIAL_BUFFER_SIZE];
+ public:
HardwareSerial(
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
@@ -104,6 +104,10 @@ class HardwareSerial : public Stream
inline size_t write(int n) { return write((uint8_t)n); }
using Print::write; // pull in write(str) and write(buf, size) from Print
operator bool() { return true; }
+
+ // Interrupt handlers - Not intended to be called externally
+ void _rx_complete_irq(void);
+ void _tx_udr_empty_irq(void);
};
#if defined(UBRRH) || defined(UBRR0H)