Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c233edddd8 |
@ -121,16 +121,18 @@ int HardwareSerial::availableForWrite(void)
|
|||||||
void HardwareSerial::rx_complete_irq(void)
|
void HardwareSerial::rx_complete_irq(void)
|
||||||
{
|
{
|
||||||
// which UART to use
|
// which UART to use
|
||||||
UART_TypeDef* uart = (uartNum == 1) ? UART_1 : UART_0;
|
UART_TypeDef* uart = UART_0;
|
||||||
rx_buffer_index_t i;
|
if (uartNum == 1)
|
||||||
|
uart = UART_1;
|
||||||
|
|
||||||
|
// find next index in buffer with upper limit
|
||||||
|
uint8_t i = (uint8_t)(_rx_buffer_head + 1)%SERIAL_RX_BUFFER_SIZE;
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
// while there is something to receive, put the data into the buffer
|
// while there is something to receive, put the data into the buffer
|
||||||
// and edit the buffer index
|
// and edit the buffer index
|
||||||
while(!UART_IS_RX_FIFO_EMPTY(uart))
|
while(!UART_IS_RX_FIFO_EMPTY(uart))
|
||||||
{
|
{
|
||||||
c = UART_READ_BYTE(uart);
|
c = UART_READ_BYTE(uart);
|
||||||
// find next index in buffer with upper limit
|
|
||||||
i = (unsigned int)(_rx_buffer_head + 1)%SERIAL_RX_BUFFER_SIZE;
|
|
||||||
if (i != _rx_buffer_tail)
|
if (i != _rx_buffer_tail)
|
||||||
{
|
{
|
||||||
// write if there is space in the buffer
|
// write if there is space in the buffer
|
||||||
|
|||||||
@ -41,15 +41,7 @@
|
|||||||
// often work, but occasionally a race condition can occur that makes
|
// often work, but occasionally a race condition can occur that makes
|
||||||
// Serial behave erratically. See https://github.com/arduino/Arduino/issues/2405
|
// Serial behave erratically. See https://github.com/arduino/Arduino/issues/2405
|
||||||
|
|
||||||
#if !defined(SERIAL_RX_BUFFER_SIZE)
|
|
||||||
#define SERIAL_RX_BUFFER_SIZE 64
|
#define SERIAL_RX_BUFFER_SIZE 64
|
||||||
#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);
|
// Define config for Serial.begin(baud, config);
|
||||||
// parity: 7...4 bits = 0 (no), 2 (even), 3 (odd)
|
// parity: 7...4 bits = 0 (no), 2 (even), 3 (odd)
|
||||||
@ -76,8 +68,8 @@ typedef uint8_t rx_buffer_index_t;
|
|||||||
class HardwareSerial : public Stream
|
class HardwareSerial : public Stream
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
volatile rx_buffer_index_t _rx_buffer_head;
|
volatile uint8_t _rx_buffer_head;
|
||||||
volatile rx_buffer_index_t _rx_buffer_tail;
|
volatile uint8_t _rx_buffer_tail;
|
||||||
unsigned char _rx_buffer[SERIAL_RX_BUFFER_SIZE];
|
unsigned char _rx_buffer[SERIAL_RX_BUFFER_SIZE];
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user