Skip to content

Commit d9c6e10

Browse files
committed
Extended yield() support to Stream, analog, Serial, Audio.
1 parent 74dea07 commit d9c6e10

File tree

8 files changed

+15
-9
lines changed

8 files changed

+15
-9
lines changed

hardware/arduino/avr/cores/arduino/HardwareSerial.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,8 @@ int HardwareSerial::read(void)
449449
void HardwareSerial::flush()
450450
{
451451
// UDR is kept full while the buffer is not empty, so TXC triggers when EMPTY && SENT
452-
while (transmitting && ! (*_ucsra & _BV(TXC0)));
452+
while (transmitting && ! (*_ucsra & _BV(TXC0)))
453+
yield();
453454
transmitting = false;
454455
}
455456

@@ -461,7 +462,7 @@ size_t HardwareSerial::write(uint8_t c)
461462
// wait for the interrupt handler to empty it a bit
462463
// ???: return 0 here instead?
463464
while (i == _tx_buffer->tail)
464-
;
465+
yield();
465466

466467
_tx_buffer->buffer[_tx_buffer->head] = c;
467468
_tx_buffer->head = i;

hardware/arduino/avr/cores/arduino/Stream.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ int Stream::timedRead()
3434
do {
3535
c = read();
3636
if (c >= 0) return c;
37+
yield();
3738
} while(millis() - _startMillis < _timeout);
3839
return -1; // -1 indicates timeout
3940
}
@@ -46,6 +47,7 @@ int Stream::timedPeek()
4647
do {
4748
c = peek();
4849
if (c >= 0) return c;
50+
yield();
4951
} while(millis() - _startMillis < _timeout);
5052
return -1; // -1 indicates timeout
5153
}

hardware/arduino/avr/cores/arduino/wiring_analog.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ int analogRead(uint8_t pin)
7575
sbi(ADCSRA, ADSC);
7676

7777
// ADSC is cleared when the conversion finishes
78-
while (bit_is_set(ADCSRA, ADSC));
78+
while (bit_is_set(ADCSRA, ADSC))
79+
yield();
7980

8081
// we have to read ADCL first; doing so locks both ADCL
8182
// and ADCH until ADCH is read. reading ADCL second would

hardware/arduino/sam/cores/arduino/Stream.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ int Stream::timedRead()
3434
do {
3535
c = read();
3636
if (c >= 0) return c;
37+
yield();
3738
} while(millis() - _startMillis < _timeout);
3839
return -1; // -1 indicates timeout
3940
}
@@ -46,6 +47,7 @@ int Stream::timedPeek()
4647
do {
4748
c = peek();
4849
if (c >= 0) return c;
50+
yield();
4951
} while(millis() - _startMillis < _timeout);
5052
return -1; // -1 indicates timeout
5153
}

hardware/arduino/sam/cores/arduino/UARTClass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ void UARTClass::flush( void )
104104
{
105105
// Wait for transmission to complete
106106
while ((_pUart->UART_SR & UART_SR_TXRDY) != UART_SR_TXRDY)
107-
;
107+
yield();
108108
}
109109

110110
size_t UARTClass::write( const uint8_t uc_data )
111111
{
112112
// Check if the transmitter is ready
113113
while ((_pUart->UART_SR & UART_SR_TXRDY) != UART_SR_TXRDY)
114-
;
114+
yield();
115115

116116
// Send character
117117
_pUart->UART_THR = uc_data;

hardware/arduino/sam/cores/arduino/USARTClass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ void USARTClass::flush( void )
105105
{
106106
// Wait for transmission to complete
107107
while ((_pUsart->US_CSR & US_CSR_TXRDY) != US_CSR_TXRDY)
108-
;
108+
yield();
109109
}
110110

111111
size_t USARTClass::write( const uint8_t uc_data )
112112
{
113113
// Check if the transmitter is ready
114114
while ((_pUsart->US_CSR & US_CSR_TXRDY) != US_CSR_TXRDY)
115-
;
115+
yield();
116116

117117
// Send character
118118
_pUsart->US_THR = uc_data ;

hardware/arduino/sam/cores/arduino/syscalls_sam3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ extern int _write( int file, char *ptr, int len )
113113

114114
// Check if the transmitter is ready
115115
while ((UART->UART_SR & UART_SR_TXRDY) != UART_SR_TXRDY)
116-
;
116+
yield();
117117

118118
// Send character
119119
UART->UART_THR = *ptr;

hardware/arduino/sam/libraries/Audio/Audio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ size_t AudioClass::write(const uint32_t *data, size_t size) {
5454
if (next == half || next == last) {
5555
enqueue();
5656
while (next == running)
57-
;
57+
yield();
5858
}
5959
}
6060

0 commit comments

Comments
 (0)