Skip to content

canio: Run background tasks while waiting for message reception #5175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ports/atmel-samd/common-hal/canio/Listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions ports/esp32s2/common-hal/canio/Listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
7 changes: 7 additions & 0 deletions ports/stm/common-hal/canio/Listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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));
}

Expand Down