Unverified Commit 4cd65d15 authored by Earle F. Philhower, III's avatar Earle F. Philhower, III Committed by GitHub

Remove timeout for SerialUART/SerialPIO::read/peek (#466)

Fixes #464 and other incompatibilities

Remove the timeout check from ::read and ::peek on the SerialUART/PIO
classes  (SerialUSB already ignores it).  See documentation
https://www.arduino.cc/reference/en/language/functions/communication/serial/settimeout/
and thanks to @jandrassy's explanation
https://github.com/earlephilhower/arduino-pico/issues/464#issuecomment-1031657044
parent bbae702e
......@@ -258,16 +258,10 @@ int SerialPIO::peek() {
return -1;
}
// If there's something in the FIFO now, just peek at it
uint32_t start = millis();
uint32_t now = millis();
while ((now - start) < _timeout) {
if (_writer != _reader) {
return _queue[_reader];
}
delay(1);
now = millis();
if (_writer != _reader) {
return _queue[_reader];
}
return -1; // Nothing available before timeout
return -1;
}
int SerialPIO::read() {
......@@ -275,18 +269,12 @@ int SerialPIO::read() {
if (!_running || !m || (_rx == NOPIN)) {
return -1;
}
uint32_t start = millis();
uint32_t now = millis();
while ((now - start) < _timeout) {
if (_writer != _reader) {
auto ret = _queue[_reader];
_reader = (_reader + 1) % _fifosize;
return ret;
}
delay(1);
now = millis();
if (_writer != _reader) {
auto ret = _queue[_reader];
_reader = (_reader + 1) % _fifosize;
return ret;
}
return -1; // Timeout
return -1;
}
int SerialPIO::available() {
......
......@@ -158,16 +158,10 @@ int SerialUART::peek() {
if (!_running || !m) {
return -1;
}
uint32_t start = millis();
uint32_t now = millis();
while ((now - start) < _timeout) {
if (_writer != _reader) {
return _queue[_reader];
}
delay(1);
now = millis();
if (_writer != _reader) {
return _queue[_reader];
}
return -1; // Nothing available before timeout
return -1;
}
int SerialUART::read() {
......@@ -175,18 +169,12 @@ int SerialUART::read() {
if (!_running || !m) {
return -1;
}
uint32_t start = millis();
uint32_t now = millis();
while ((now - start) < _timeout) {
if (_writer != _reader) {
auto ret = _queue[_reader];
_reader = (_reader + 1) % _fifoSize;
return ret;
}
delay(1);
now = millis();
if (_writer != _reader) {
auto ret = _queue[_reader];
_reader = (_reader + 1) % _fifoSize;
return ret;
}
return -1; // Timeout
return -1;
}
int SerialUART::available() {
......
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