summaryrefslogtreecommitdiff
path: root/ports
diff options
context:
space:
mode:
authorPaul Kierstead <paulkierstead@gmail.com>2018-09-01 17:07:30 +0000
committerDan Halbert <halbert@halwitz.org>2018-09-12 13:25:49 -0400
commit02b3f62460df879b83018a32a4a47aa68d81af58 (patch)
tree86156107da626daaa203b1531d7a3b103504b316 /ports
parent2cb703913d865255b86106f5bd78b3a19f7775c8 (diff)
When UART timeout of zero is given, make read() return data already available
Diffstat (limited to 'ports')
-rw-r--r--ports/atmel-samd/common-hal/busio/UART.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/ports/atmel-samd/common-hal/busio/UART.c b/ports/atmel-samd/common-hal/busio/UART.c
index 20e662ec6..fbed1d506 100644
--- a/ports/atmel-samd/common-hal/busio/UART.c
+++ b/ports/atmel-samd/common-hal/busio/UART.c
@@ -254,7 +254,7 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t
uint64_t start_ticks = ticks_ms;
// Busy-wait until timeout or until we've read enough chars.
- while (ticks_ms - start_ticks < self->timeout_ms) {
+ while (ticks_ms - start_ticks <= self->timeout_ms) {
// Read as many chars as we can right now, up to len.
size_t num_read = io_read(io, data, len);
@@ -273,6 +273,10 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t
#ifdef MICROPY_VM_HOOK_LOOP
MICROPY_VM_HOOK_LOOP
#endif
+ // If we are zero timeout, make sure we don't loop again (in the event
+ // we read in under 1ms)
+ if (self->timeout_ms == 0)
+ break;
}
if (total_read == 0) {