Commit e9e43cf5 authored by John Holman's avatar John Holman Committed by Martino Facchin

Prevent buffer retransmission when transmit buffer is empty

Moving the head buffer pointer and setting interrupt flag is now
atomic in write(). Previously an intervening ISR could empty the
buffer before the second ISR is triggered causing retransmission.

Fixes: #3745 (original issue only)
parent d50e5978
......@@ -246,9 +246,14 @@ size_t HardwareSerial::write(uint8_t c)
}
_tx_buffer[_tx_buffer_head] = c;
_tx_buffer_head = i;
sbi(*_ucsrb, UDRIE0);
// make atomic to prevent execution of ISR between setting the
// head pointer and setting the interrupt flag resulting in buffer
// retransmission
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
_tx_buffer_head = i;
sbi(*_ucsrb, UDRIE0);
}
return 1;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment