diff options
| author | Jerry Needell <jerryneedell@gmail.com> | 2018-04-16 08:11:14 -0400 |
|---|---|---|
| committer | Jerry Needell <jerryneedell@gmail.com> | 2018-04-16 08:11:14 -0400 |
| commit | e55e06d501ca2b607d10a9279f1f7e80a8b83f0e (patch) | |
| tree | 64012b1870c814a36986e5952334731ec5bf00fe | |
| parent | 10eabf6bc22391292c7bec42f611a876698d587f (diff) | |
modify tick.c to work when interrupts disabled - modify PulseIn.c to cast argument to common_hal_delay_us
| -rw-r--r-- | ports/atmel-samd/common-hal/pulseio/PulseIn.c | 2 | ||||
| -rw-r--r-- | ports/atmel-samd/tick.c | 18 |
2 files changed, 15 insertions, 5 deletions
diff --git a/ports/atmel-samd/common-hal/pulseio/PulseIn.c b/ports/atmel-samd/common-hal/pulseio/PulseIn.c index 2dca52913..bf6dfa8d5 100644 --- a/ports/atmel-samd/common-hal/pulseio/PulseIn.c +++ b/ports/atmel-samd/common-hal/pulseio/PulseIn.c @@ -286,7 +286,7 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self, common_hal_mcu_disable_interrupts(); gpio_set_pin_level(self->pin, !self->idle_state); - common_hal_mcu_delay_us(trigger_duration); + common_hal_mcu_delay_us((uint32_t)trigger_duration); gpio_set_pin_level(self->pin, self->idle_state); common_hal_mcu_enable_interrupts(); } diff --git a/ports/atmel-samd/tick.c b/ports/atmel-samd/tick.c index f5fd57f5d..5c66df3cb 100644 --- a/ports/atmel-samd/tick.c +++ b/ports/atmel-samd/tick.c @@ -59,14 +59,24 @@ void tick_init() { void tick_delay(uint32_t us) { uint32_t ticks_per_us = common_hal_mcu_processor_get_frequency() / 1000 / 1000; uint32_t us_between_ticks = SysTick->VAL / ticks_per_us; - uint64_t start_ms = ticks_ms; + uint32_t start_tick; while (us > 1000) { - while (ticks_ms == start_ms) {} + start_tick=SysTick->VAL; // wait for SysTick->VAL to RESET + while (SysTick->VAL < start_tick) {} us -= us_between_ticks; - start_ms = ticks_ms; us_between_ticks = 1000; } - while (SysTick->VAL > ((us_between_ticks - us) * ticks_per_us)) {} + if(us&&(us < us_between_ticks)){ + while (SysTick->VAL > ((us_between_ticks - us) * ticks_per_us)) {} + } + else { + start_tick=SysTick->VAL; // wait for SysTick->VAL to RESET + while (SysTick->VAL < start_tick) {} + us -= us_between_ticks; + if(us){ + while (SysTick->VAL > ((1000 - us) * ticks_per_us)) {} + } + } } // us counts down! |
