Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hardware/arduino/sam/cores/arduino/RingBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <stdint.h>

// Define constants and variables for buffering incoming serial data. We're
// using a ring buffer (I think), in which head is the index of the location
// using a ring buffer, 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.
#define SERIAL_BUFFER_SIZE 128
Expand Down
6 changes: 3 additions & 3 deletions hardware/arduino/sam/cores/arduino/UARTClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ size_t UARTClass::write( const uint8_t uc_data )
(_tx_buffer->_iTail != _tx_buffer->_iHead))
{
// If busy we buffer
unsigned int l = (_tx_buffer->_iHead + 1) % SERIAL_BUFFER_SIZE;
while (_tx_buffer->_iTail == l)
int nextWrite = (_tx_buffer->_iHead + 1) % SERIAL_BUFFER_SIZE;
while (_tx_buffer->_iTail == nextWrite)
; // Spin locks if we're about to overwrite the buffer. This continues once the data is sent

_tx_buffer->_aucBuffer[_tx_buffer->_iHead] = uc_data;
_tx_buffer->_iHead = l;
_tx_buffer->_iHead = nextWrite;
// Make sure TX interrupt is enabled
_pUart->UART_IER = UART_IER_TXRDY;
}
Expand Down