From cfac07c1ccf31bc4a0395c0b100b23ef4512b32d Mon Sep 17 00:00:00 2001 From: root Date: Wed, 28 Apr 2021 11:20:13 -0500 Subject: [PATCH 1/3] Wrap pulsein when maxlen is exceeded --- ports/raspberrypi/common-hal/pulseio/PulseIn.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index 8d04981b6c..66e5721eec 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -141,9 +141,16 @@ void common_hal_pulseio_pulsein_interrupt() { } // ignore pulses that are too short if (result <= MAX_PULSE && result > MIN_PULSE) { - self->buffer[buf_index] = (uint16_t) result; - buf_index++; - self->len++; + self->buffer[buf_index] = (uint16_t) result; + if (self->len < self->maxlen) { + self->len++; + } + if (buf_index < self->maxlen) { + buf_index++; + } else { + self->start = 0; + buf_index = 0; + } } } } From 1ec59cd534d13d418f8c8d7a6375ac1535d0c561 Mon Sep 17 00:00:00 2001 From: DavePutz Date: Thu, 29 Apr 2021 12:38:13 -0500 Subject: [PATCH 2/3] Fix up indentation --- ports/raspberrypi/common-hal/pulseio/PulseIn.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index 66e5721eec..6e0c838d34 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -141,16 +141,16 @@ void common_hal_pulseio_pulsein_interrupt() { } // ignore pulses that are too short if (result <= MAX_PULSE && result > MIN_PULSE) { - self->buffer[buf_index] = (uint16_t) result; - if (self->len < self->maxlen) { - self->len++; + self->buffer[buf_index] = (uint16_t) result; + if (self->len < self->maxlen) { + self->len++; } - if (buf_index < self->maxlen) { - buf_index++; - } else { - self->start = 0; - buf_index = 0; - } + if (buf_index < self->maxlen) { + buf_index++; + } else { + self->start = 0; + buf_index = 0; + } } } } From 41b273e0c1e379067a2cd4b5e1436f2e39311aae Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 30 Apr 2021 09:17:14 -0500 Subject: [PATCH 3/3] py/vm.c: Restore lost bits of MICROPY_OPT_COMPUTED_GOTO_SAVE_SPACE This fixes a problem where boards that enabled this (most SAM D21s) would crash on the first bytecode instruction. Closes: #4686 --- py/vm.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/py/vm.c b/py/vm.c index 17ac860e6e..14541766ca 100644 --- a/py/vm.c +++ b/py/vm.c @@ -127,11 +127,21 @@ mp_vm_return_kind_t PLACE_IN_ITCM(mp_execute_bytecode)(mp_code_state_t * code_st #endif #if MICROPY_OPT_COMPUTED_GOTO #include "py/vmentrytable.h" + #if MICROPY_OPT_COMPUTED_GOTO_SAVE_SPACE + #define ONE_TRUE_DISPATCH() one_true_dispatch : do { \ + TRACE(ip); \ + MARK_EXC_IP_GLOBAL(); \ + goto *(void *)((char *) && entry_MP_BC_LOAD_CONST_FALSE + entry_table[*ip++]); \ + } while (0) + #define DISPATCH() do { goto one_true_dispatch; } while (0) + #else + #define ONE_TRUE_DISPATCH() DISPATCH() #define DISPATCH() do { \ TRACE(ip); \ MARK_EXC_IP_GLOBAL(); \ goto *entry_table[*ip++]; \ -} while (0) + } while (0) + #endif #define DISPATCH_WITH_PEND_EXC_CHECK() goto pending_exception_check #define ENTRY(op) entry_##op #define ENTRY_DEFAULT entry_default @@ -197,7 +207,7 @@ mp_vm_return_kind_t PLACE_IN_ITCM(mp_execute_bytecode)(mp_code_state_t * code_st for (;;) { dispatch_loop: #if MICROPY_OPT_COMPUTED_GOTO - DISPATCH(); + ONE_TRUE_DISPATCH(); #else TRACE(ip); MARK_EXC_IP_GLOBAL();