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.
pull/7018/head
robert-hh 2021-03-03 08:44:38 +01:00 zatwierdzone przez Damien George
rodzic a075e0b7d8
commit 0461640983
1 zmienionych plików z 6 dodań i 3 usunięć

Wyświetl plik

@ -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);