Changed to interrupt guards

This commit is contained in:
Joshua Broekhuijsen 2023-10-23 18:00:21 -05:00
parent 0f07a9b96e
commit ecf5a6be97
2 changed files with 2 additions and 10 deletions

View File

@ -56,7 +56,6 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
self->idle_state = idle_state;
self->start = 0;
self->len = 0;
self->len_target = 0;
common_hal_rp2pio_statemachine_construct(&self->state_machine,
pulsein_program, MP_ARRAY_SIZE(pulsein_program),
@ -134,8 +133,6 @@ void common_hal_pulseio_pulsein_interrupt(void *self_in) {
self->buffer[buf_index] = (uint16_t)result;
if (self->len < self->maxlen) {
self->len++;
self->len_target++; // The interrupt will only cause a problem in either len or len_target, not both.
// So we can just check for a match, and choose the higher.
} else {
self->start = (self->start + 1) % self->maxlen;
}
@ -176,14 +173,10 @@ uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t *self) {
mp_raise_IndexError_varg(translate("pop from empty %q"), MP_QSTR_PulseIn);
}
uint16_t value = self->buffer[self->start];
common_hal_mcu_disable_interrupts();
self->start = (self->start + 1) % self->maxlen;
self->len_target--;
self->len--;
if (self->len != self->len_target) {
uint16_t len_accurate = self->len > self->len_target ? self->len : self->len_target;
self->len_target = len_accurate;
self->len = len_accurate;
}
common_hal_mcu_enable_interrupts();
return value;
}

View File

@ -43,7 +43,6 @@ typedef struct {
volatile bool last_level;
volatile uint32_t level_count;
volatile uint16_t len;
volatile uint16_t len_target;
volatile uint16_t start;
rp2pio_statemachine_obj_t state_machine;
} pulseio_pulsein_obj_t;