Преглед на файлове

Avoid possible race condition

Remove possible race condition in setting and clearing transmitting.
Not from direct handling of this interrupt, but maybe another interrupt
happens right after we set UDR1, which by the time it finishes, the
transmit complete interrupt happens which clears it and returns and we
set transmitting.
main
Kurt Eckhardt преди 8 години
родител
ревизия
9aa92c1c38
променени са 1 файла, в които са добавени 5 реда и са изтрити 1 реда
  1. +5
    -1
      teensy/HardwareSerial.cpp

+ 5
- 1
teensy/HardwareSerial.cpp Целия файл

@@ -146,6 +146,7 @@ void HardwareSerial::write(uint8_t c)
#endif
{
uint8_t i;
uint8_t status;

if (!(UCSR1B & (1<<TXEN1))) {
#if ARDUINO >= 100
@@ -162,9 +163,12 @@ void HardwareSerial::write(uint8_t c)
// to the data register and be done. This shortcut helps
// significantly improve the effective datarate at high (>
// 500kbit/s) bitrates, where interrupt overhead becomes a slowdown.
if (tx_buffer_head == tx_buffer_tail && bit_is_set(UCSR1A, UDRE1)) {
if ((tx_buffer_head == tx_buffer_tail) && (UCSR1A & (1<<UDRE1))) {
status = SREG;
cli();
UDR1 = c;
transmitting = 1;
SREG = status;
return 1;
}


Loading…
Отказ
Запис