From: Keith Packard Date: Tue, 23 Jun 2020 00:42:03 +0000 (-0700) Subject: altos: Add ao_delay_until to ao_notask X-Git-Tag: 1.9.5~1^2~49 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=48bc180211f226b0406aae28a85d5e5ee77455a2 altos: Add ao_delay_until to ao_notask Used on micropeak Signed-off-by: Keith Packard --- diff --git a/src/kernel/ao_notask.c b/src/kernel/ao_notask.c index e973c7ae..8c5743fd 100644 --- a/src/kernel/ao_notask.c +++ b/src/kernel/ao_notask.c @@ -40,18 +40,21 @@ ao_sleep(void *wchan) } #if HAS_AO_DELAY +void +ao_delay_until(AO_TICK_TYPE target) +{ + ao_arch_block_interrupts(); + while ((int16_t) (target - ao_tick_count) > 0) + ao_sleep((void *) &ao_tick_count); + ao_arch_release_interrupts(); +} + void ao_delay(AO_TICK_TYPE ticks) { - AO_TICK_TYPE target; - - if (!ticks) - ticks = 1; - target = ao_tick_count + ticks; - do { - ao_sleep(&ao_time); - } while ((int16_t) (target - ao_tick_count) > 0); + ao_delay_until(ao_time() + ticks); } + #endif void diff --git a/src/kernel/ao_notask.h b/src/kernel/ao_notask.h index 6ad15a56..f698a4ee 100644 --- a/src/kernel/ao_notask.h +++ b/src/kernel/ao_notask.h @@ -19,6 +19,9 @@ #ifndef _AO_NOTASK_H_ #define _AO_NOTASK_H_ +void +ao_delay_until(AO_TICK_TYPE target); + uint8_t ao_sleep(void *wchan);