From fe738598dacd97149db738216fe4e574b8a926a7 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Fri, 20 Apr 2018 11:59:33 -0400 Subject: [PATCH] modify tick.c to simplify - remove interupt disable from common_hal_pulseio_pulsein_resume --- ports/atmel-samd/common-hal/pulseio/PulseIn.c | 4 ---- ports/atmel-samd/tick.c | 15 ++------------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/ports/atmel-samd/common-hal/pulseio/PulseIn.c b/ports/atmel-samd/common-hal/pulseio/PulseIn.c index 0b551858c8..6e3aa3abb3 100644 --- a/ports/atmel-samd/common-hal/pulseio/PulseIn.c +++ b/ports/atmel-samd/common-hal/pulseio/PulseIn.c @@ -283,13 +283,9 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self, if (trigger_duration > 0) { gpio_set_pin_pull_mode(self->pin, GPIO_PULL_OFF); gpio_set_pin_direction(self->pin, GPIO_DIRECTION_OUT); - if(trigger_duration < 1000 ){ // only disable interrupts for < 1 ms - common_hal_mcu_disable_interrupts(); - } gpio_set_pin_level(self->pin, !self->idle_state); common_hal_mcu_delay_us((uint32_t)trigger_duration); gpio_set_pin_level(self->pin, self->idle_state); - common_hal_mcu_enable_interrupts(); } // Reconfigure the pin and make sure its set to detect the first edge. diff --git a/ports/atmel-samd/tick.c b/ports/atmel-samd/tick.c index 8a927785f4..72dddbe86f 100644 --- a/ports/atmel-samd/tick.c +++ b/ports/atmel-samd/tick.c @@ -60,26 +60,15 @@ void tick_delay(uint32_t us) { uint32_t ticks_per_us = common_hal_mcu_processor_get_frequency() / 1000 / 1000; uint32_t us_until_next_tick = SysTick->VAL / ticks_per_us; uint32_t start_tick; - while (us > 1000) { - // check if interrupts are disabled - if(__get_PRIMASK()) - return; // if not just return + while (us > us_until_next_tick) { start_tick=SysTick->VAL; // wait for SysTick->VAL to RESET while (SysTick->VAL < start_tick) {} us -= us_until_next_tick; us_until_next_tick = 1000; } - if(us&&(us < us_until_next_tick)){ + if(us){ while (SysTick->VAL > ((us_until_next_tick - us) * ticks_per_us)) {} } - else { - start_tick=SysTick->VAL; // wait for SysTick->VAL to RESET - while (SysTick->VAL < start_tick) {} - us -= us_until_next_tick; - if(us){ - while (SysTick->VAL > ((1000 - us) * ticks_per_us)) {} - } - } } // us counts down!