From cabe96e188fd1eaedb2c829976cbe58f9e6f7a9c Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 18 Aug 2021 11:35:06 -0500 Subject: [PATCH 1/3] canio: Run background tasks while waiting for message reception Closes: #5004 --- ports/atmel-samd/common-hal/canio/Listener.c | 7 +++++++ ports/stm/common-hal/canio/Listener.c | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/ports/atmel-samd/common-hal/canio/Listener.c b/ports/atmel-samd/common-hal/canio/Listener.c index adb3048496..ce09764757 100644 --- a/ports/atmel-samd/common-hal/canio/Listener.c +++ b/ports/atmel-samd/common-hal/canio/Listener.c @@ -30,6 +30,8 @@ #include "py/obj.h" #include "py/runtime.h" +#include "lib/utils/interrupt_char.h" + #include "common-hal/canio/__init__.h" #include "common-hal/canio/Listener.h" #include "shared-bindings/canio/Listener.h" @@ -356,6 +358,11 @@ mp_obj_t common_hal_canio_listener_receive(canio_listener_obj_t *self) { if (supervisor_ticks_ms64() > deadline) { return NULL; } + RUN_BACKGROUND_TASKS; + // Allow user to break out of a timeout with a KeyboardInterrupt. + if (mp_hal_is_interrupted()) { + return NULL; + } } while (!common_hal_canio_listener_in_waiting(self)); } int index = self->hw->RXFS.bit.F0GI; diff --git a/ports/stm/common-hal/canio/Listener.c b/ports/stm/common-hal/canio/Listener.c index 23634eba69..3aca0d067b 100644 --- a/ports/stm/common-hal/canio/Listener.c +++ b/ports/stm/common-hal/canio/Listener.c @@ -30,6 +30,8 @@ #include "py/obj.h" #include "py/runtime.h" +#include "lib/utils/interrupt_char.h" + #include "common-hal/canio/__init__.h" #include "common-hal/canio/Listener.h" #include "shared-bindings/canio/Listener.h" @@ -272,6 +274,11 @@ mp_obj_t common_hal_canio_listener_receive(canio_listener_obj_t *self) { if (supervisor_ticks_ms64() > deadline) { return NULL; } + RUN_BACKGROUND_TASKS; + // Allow user to break out of a timeout with a KeyboardInterrupt. + if ( mp_hal_is_interrupted() ) { + return NULL; + } } while (!common_hal_canio_listener_in_waiting(self)); } From 6ea136987ec85175ff762749e4828347e8b43de1 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 19 Aug 2021 13:54:13 -0500 Subject: [PATCH 2/3] run codeformat --- ports/stm/common-hal/canio/Listener.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/stm/common-hal/canio/Listener.c b/ports/stm/common-hal/canio/Listener.c index 3aca0d067b..dc819180f9 100644 --- a/ports/stm/common-hal/canio/Listener.c +++ b/ports/stm/common-hal/canio/Listener.c @@ -276,7 +276,7 @@ mp_obj_t common_hal_canio_listener_receive(canio_listener_obj_t *self) { } RUN_BACKGROUND_TASKS; // Allow user to break out of a timeout with a KeyboardInterrupt. - if ( mp_hal_is_interrupted() ) { + if (mp_hal_is_interrupted()) { return NULL; } } while (!common_hal_canio_listener_in_waiting(self)); From 371f166de112d54f59be28a3e6d7a4f57a50a092 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 18 Aug 2021 11:35:06 -0500 Subject: [PATCH 3/3] canio: Run background tasks while waiting for message reception Closes: #5004 --- ports/esp32s2/common-hal/canio/Listener.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ports/esp32s2/common-hal/canio/Listener.c b/ports/esp32s2/common-hal/canio/Listener.c index 5e968f2393..8100261743 100644 --- a/ports/esp32s2/common-hal/canio/Listener.c +++ b/ports/esp32s2/common-hal/canio/Listener.c @@ -151,6 +151,11 @@ mp_obj_t common_hal_canio_listener_receive(canio_listener_obj_t *self) { if (supervisor_ticks_ms64() > deadline) { return NULL; } + RUN_BACKGROUND_TASKS; + // Allow user to break out of a timeout with a KeyboardInterrupt. + if (mp_hal_is_interrupted()) { + return NULL; + } } while (!common_hal_canio_listener_in_waiting(self)); }