diff options
Diffstat (limited to 'cores/arduino')
-rw-r--r-- | cores/arduino/HardwareSerial.cpp | 4 | ||||
-rw-r--r-- | cores/arduino/HardwareSerial.h | 21 |
2 files changed, 15 insertions, 10 deletions
diff --git a/cores/arduino/HardwareSerial.cpp b/cores/arduino/HardwareSerial.cpp index a634b28..b9dce07 100644 --- a/cores/arduino/HardwareSerial.cpp +++ b/cores/arduino/HardwareSerial.cpp @@ -171,7 +171,7 @@ int HardwareSerial::read(void) return -1; } else { unsigned char c = _rx_buffer[_rx_buffer_tail]; - _rx_buffer_tail = (BUFPOINTER)(_rx_buffer_tail + 1) % SERIAL_RX_BUFFER_SIZE; + _rx_buffer_tail = (rx_buffer_index_t)(_rx_buffer_tail + 1) % SERIAL_RX_BUFFER_SIZE; return c; } } @@ -207,7 +207,7 @@ size_t HardwareSerial::write(uint8_t c) sbi(*_ucsra, TXC0); return 1; } - BUFPOINTER i = (_tx_buffer_head + 1) % SERIAL_TX_BUFFER_SIZE; + tx_buffer_index_t i = (_tx_buffer_head + 1) % SERIAL_TX_BUFFER_SIZE; // If the output buffer is full, there's nothing for it other than to // wait for the interrupt handler to empty it a bit diff --git a/cores/arduino/HardwareSerial.h b/cores/arduino/HardwareSerial.h index e21e55b..b96e5d0 100644 --- a/cores/arduino/HardwareSerial.h +++ b/cores/arduino/HardwareSerial.h @@ -32,7 +32,7 @@ // using a ring buffer (I think), in which head is the index of the location // to which to write the next incoming character and tail is the index of the // location from which to read. -#if !(defined(SERIAL_TX_BUFFER_SIZE)&&defined(SERIAL_RX_BUFFER_SIZE)) +#if !(defined(SERIAL_TX_BUFFER_SIZE) && defined(SERIAL_RX_BUFFER_SIZE)) #if (RAMEND < 1000) #define SERIAL_TX_BUFFER_SIZE 16 #define SERIAL_RX_BUFFER_SIZE 16 @@ -41,10 +41,15 @@ #define SERIAL_RX_BUFFER_SIZE 64 #endif #endif -#if (SERIAL_TX_BUFFER_SIZE>255) || (SERIAL_RX_BUFFER_SIZE>255) -#define BUFPOINTER uint16_t +#if (SERIAL_TX_BUFFER_SIZE>256) +typedef uint16_t tx_buffer_index_t; #else -#define BUFPOINTER uint8_t +typedef uint8_t tx_buffer_index_t; +#endif +#if (SERIAL_RX_BUFFER_SIZE>256) +typedef uint16_t rx_buffer_index_t; +#else +typedef uint8_t rx_buffer_index_t; #endif // Define config for Serial.begin(baud, config); @@ -85,10 +90,10 @@ class HardwareSerial : public Stream // Has any byte been written to the UART since begin() bool _written; - volatile BUFPOINTER _rx_buffer_head; - volatile BUFPOINTER _rx_buffer_tail; - volatile BUFPOINTER _tx_buffer_head; - volatile BUFPOINTER _tx_buffer_tail; + volatile rx_buffer_index_t _rx_buffer_head; + volatile rx_buffer_index_t _rx_buffer_tail; + volatile tx_buffer_index_t _tx_buffer_head; + volatile tx_buffer_index_t _tx_buffer_tail; // Don't put any members after these buffers, since only the first // 32 bytes of this struct can be accessed quickly using the ldd |