summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrobert-hh <robert@hammelrath.com>2021-03-03 08:44:38 +0100
committerDamien George <damien@micropython.org>2021-03-12 00:39:26 +1100
commit046164098337cc79dd0f6c710f49bdf6765aa711 (patch)
tree1fa560d3c8998f570d7728261f89584fea18e165
parenta075e0b7d87a66a4b2ee9f75bcf70887157c7ae2 (diff)
rp2/rp2_pio: Fix sm.get(buf) to not wait after getting last item.
sm.get(buf) was waiting for one item more than the length of the supplied buffer. Even if this item was not stored, sm_get would block trying to get an item from the RX fifo. As part of the fix, the edge case for a zero length buffer was moved up to the section where the function arguments are handled. In case of a zero length buffer, sm.get() now returns immediately that buffer.
-rw-r--r--ports/rp2/rp2_pio.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/ports/rp2/rp2_pio.c b/ports/rp2/rp2_pio.c
index 6101164a1..9786e569d 100644
--- a/ports/rp2/rp2_pio.c
+++ b/ports/rp2/rp2_pio.c
@@ -608,6 +608,9 @@ STATIC mp_obj_t rp2_state_machine_get(size_t n_args, const mp_obj_t *args) {
} else {
bufinfo.typecode |= 0x20; // make lowercase to support upper and lower
}
+ if (bufinfo.len == 0) { // edge case: buffer of zero length supplied
+ return args[1];
+ }
}
if (n_args > 2) {
shift = mp_obj_get_int(args[2]);
@@ -625,9 +628,6 @@ STATIC mp_obj_t rp2_state_machine_get(size_t n_args, const mp_obj_t *args) {
if (dest == NULL) {
return mp_obj_new_int_from_uint(value);
}
- if (dest >= dest_top) {
- return args[1];
- }
if (bufinfo.typecode == 'b') {
*(uint8_t *)dest = value;
dest += sizeof(uint8_t);
@@ -640,6 +640,9 @@ STATIC mp_obj_t rp2_state_machine_get(size_t n_args, const mp_obj_t *args) {
} else {
mp_raise_ValueError("unsupported buffer type");
}
+ if (dest >= dest_top) {
+ return args[1];
+ }
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_state_machine_get_obj, 1, 3, rp2_state_machine_get);