Skip to content

Commit ecf5a6b

Browse files
committed
Changed to interrupt guards
1 parent 0f07a9b commit ecf5a6b

File tree

2 files changed

+2
-10
lines changed

2 files changed

+2
-10
lines changed

ports/raspberrypi/common-hal/pulseio/PulseIn.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
5656
self->idle_state = idle_state;
5757
self->start = 0;
5858
self->len = 0;
59-
self->len_target = 0;
6059

6160
common_hal_rp2pio_statemachine_construct(&self->state_machine,
6261
pulsein_program, MP_ARRAY_SIZE(pulsein_program),
@@ -134,8 +133,6 @@ void common_hal_pulseio_pulsein_interrupt(void *self_in) {
134133
self->buffer[buf_index] = (uint16_t)result;
135134
if (self->len < self->maxlen) {
136135
self->len++;
137-
self->len_target++; // The interrupt will only cause a problem in either len or len_target, not both.
138-
// So we can just check for a match, and choose the higher.
139136
} else {
140137
self->start = (self->start + 1) % self->maxlen;
141138
}
@@ -176,14 +173,10 @@ uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t *self) {
176173
mp_raise_IndexError_varg(translate("pop from empty %q"), MP_QSTR_PulseIn);
177174
}
178175
uint16_t value = self->buffer[self->start];
176+
common_hal_mcu_disable_interrupts();
179177
self->start = (self->start + 1) % self->maxlen;
180-
self->len_target--;
181178
self->len--;
182-
if (self->len != self->len_target) {
183-
uint16_t len_accurate = self->len > self->len_target ? self->len : self->len_target;
184-
self->len_target = len_accurate;
185-
self->len = len_accurate;
186-
}
179+
common_hal_mcu_enable_interrupts();
187180
return value;
188181
}
189182

ports/raspberrypi/common-hal/pulseio/PulseIn.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ typedef struct {
4343
volatile bool last_level;
4444
volatile uint32_t level_count;
4545
volatile uint16_t len;
46-
volatile uint16_t len_target;
4746
volatile uint16_t start;
4847
rp2pio_statemachine_obj_t state_machine;
4948
} pulseio_pulsein_obj_t;

0 commit comments

Comments
 (0)