Merge commit '1ad74' into ide-1.5.x

This commit is contained in:
Cristian Maglie 2014-04-01 17:19:54 +02:00
commit 710e4fb7b8
3 changed files with 27 additions and 13 deletions

View File

@ -83,7 +83,7 @@ void HardwareSerial::_tx_udr_empty_irq(void)
// If interrupts are enabled, there must be more data in the output // If interrupts are enabled, there must be more data in the output
// buffer. Send the next byte // buffer. Send the next byte
unsigned char c = _tx_buffer[_tx_buffer_tail]; unsigned char c = _tx_buffer[_tx_buffer_tail];
_tx_buffer_tail = (_tx_buffer_tail + 1) % SERIAL_BUFFER_SIZE; _tx_buffer_tail = (_tx_buffer_tail + 1) % SERIAL_TX_BUFFER_SIZE;
*_udr = c; *_udr = c;
@ -152,7 +152,7 @@ void HardwareSerial::end()
int HardwareSerial::available(void) int HardwareSerial::available(void)
{ {
return (unsigned int)(SERIAL_BUFFER_SIZE + _rx_buffer_head - _rx_buffer_tail) % SERIAL_BUFFER_SIZE; return (unsigned int)(SERIAL_RX_BUFFER_SIZE + _rx_buffer_head - _rx_buffer_tail) % SERIAL_RX_BUFFER_SIZE;
} }
int HardwareSerial::peek(void) int HardwareSerial::peek(void)
@ -171,7 +171,7 @@ int HardwareSerial::read(void)
return -1; return -1;
} else { } else {
unsigned char c = _rx_buffer[_rx_buffer_tail]; unsigned char c = _rx_buffer[_rx_buffer_tail];
_rx_buffer_tail = (uint8_t)(_rx_buffer_tail + 1) % SERIAL_BUFFER_SIZE; _rx_buffer_tail = (rx_buffer_index_t)(_rx_buffer_tail + 1) % SERIAL_RX_BUFFER_SIZE;
return c; return c;
} }
} }
@ -207,7 +207,7 @@ size_t HardwareSerial::write(uint8_t c)
sbi(*_ucsra, TXC0); sbi(*_ucsra, TXC0);
return 1; return 1;
} }
uint8_t i = (_tx_buffer_head + 1) % SERIAL_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 // If the output buffer is full, there's nothing for it other than to
// wait for the interrupt handler to empty it a bit // wait for the interrupt handler to empty it a bit

View File

@ -32,10 +32,24 @@
// using a ring buffer (I think), in which head is the index of the location // 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 // to which to write the next incoming character and tail is the index of the
// location from which to read. // location from which to read.
#if !(defined(SERIAL_TX_BUFFER_SIZE) && defined(SERIAL_RX_BUFFER_SIZE))
#if (RAMEND < 1000) #if (RAMEND < 1000)
#define SERIAL_BUFFER_SIZE 16 #define SERIAL_TX_BUFFER_SIZE 16
#define SERIAL_RX_BUFFER_SIZE 16
#else #else
#define SERIAL_BUFFER_SIZE 64 #define SERIAL_TX_BUFFER_SIZE 64
#define SERIAL_RX_BUFFER_SIZE 64
#endif
#endif
#if (SERIAL_TX_BUFFER_SIZE>256)
typedef uint16_t tx_buffer_index_t;
#else
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 #endif
// Define config for Serial.begin(baud, config); // Define config for Serial.begin(baud, config);
@ -76,16 +90,16 @@ class HardwareSerial : public Stream
// Has any byte been written to the UART since begin() // Has any byte been written to the UART since begin()
bool _written; bool _written;
volatile uint8_t _rx_buffer_head; volatile rx_buffer_index_t _rx_buffer_head;
volatile uint8_t _rx_buffer_tail; volatile rx_buffer_index_t _rx_buffer_tail;
volatile uint8_t _tx_buffer_head; volatile tx_buffer_index_t _tx_buffer_head;
volatile uint8_t _tx_buffer_tail; volatile tx_buffer_index_t _tx_buffer_tail;
// Don't put any members after these buffers, since only the first // Don't put any members after these buffers, since only the first
// 32 bytes of this struct can be accessed quickly using the ldd // 32 bytes of this struct can be accessed quickly using the ldd
// instruction. // instruction.
unsigned char _rx_buffer[SERIAL_BUFFER_SIZE]; unsigned char _rx_buffer[SERIAL_RX_BUFFER_SIZE];
unsigned char _tx_buffer[SERIAL_BUFFER_SIZE]; unsigned char _tx_buffer[SERIAL_TX_BUFFER_SIZE];
public: public:
inline HardwareSerial( inline HardwareSerial(

View File

@ -99,7 +99,7 @@ void HardwareSerial::_rx_complete_irq(void)
// No Parity error, read byte and store it in the buffer if there is // No Parity error, read byte and store it in the buffer if there is
// room // room
unsigned char c = *_udr; unsigned char c = *_udr;
uint8_t i = (unsigned int)(_rx_buffer_head + 1) % SERIAL_BUFFER_SIZE; rx_buffer_index_t i = (unsigned int)(_rx_buffer_head + 1) % SERIAL_RX_BUFFER_SIZE;
// if we should be storing the received character into the location // if we should be storing the received character into the location
// just before the tail (meaning that the head would advance to the // just before the tail (meaning that the head would advance to the