From d28e65a78486bda1506e1ff557ded2919f0c669c Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 19 Aug 2019 06:28:12 -0500 Subject: [PATCH] drivers/timer/nrf_rtc_timer: clarify intent of ZLI compensation The variable enabling entry to the zero latency interrupt compensation loop was named generically, and its logic inverted, making the code difficult to understand. Change the name and initial value to more clearly indicate its role. Signed-off-by: Peter Bigot --- drivers/timer/nrf_rtc_timer.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/timer/nrf_rtc_timer.c b/drivers/timer/nrf_rtc_timer.c index a83aa13ddb9..65144b677c1 100644 --- a/drivers/timer/nrf_rtc_timer.c +++ b/drivers/timer/nrf_rtc_timer.c @@ -119,7 +119,7 @@ void z_clock_set_timeout(s32_t ticks, bool idle) k_spinlock_key_t key = k_spin_lock(&lock); u32_t cyc, dt, t = counter(); - bool flagged = false; + bool zli_fixup = IS_ENABLED(CONFIG_ZERO_LATENCY_IRQS); /* Round up to next tick boundary */ cyc = ticks * CYC_PER_TICK + 1 + counter_sub(t, last_count); @@ -162,7 +162,7 @@ void z_clock_set_timeout(s32_t ticks, bool idle) /* Missed it! */ NVIC_SetPendingIRQ(RTC1_IRQn); if (IS_ENABLED(CONFIG_ZERO_LATENCY_IRQS)) { - flagged = true; + zli_fixup = false; } } else if (dt == 1) { /* Too soon, interrupt won't arrive. */ @@ -173,16 +173,18 @@ void z_clock_set_timeout(s32_t ticks, bool idle) #ifdef CONFIG_ZERO_LATENCY_IRQS /* Failsafe. ZLIs can preempt us even though interrupts are - * masked, blowing up the sensitive timing above. If enabled, - * we need a final check (in a loop! because this too can be - * interrupted) to see that the comparator is still in the - * future. Don't bother being fancy with cycle counting here, - * just set an interrupt "soon" that we know will get the - * timer back to a known state. This handles (via some hairy - * modular expressions) the wraparound cases where we are - * preempted for as much as half the counter space. + * masked, blowing up the sensitive timing above. If the + * feature is enabled and we haven't recorded the presence of + * a pending interrupt then we need a final check (in a loop! + * because this too can be interrupted) to confirm that the + * comparator is still in the future. Don't bother being + * fancy with cycle counting here, just set an interrupt + * "soon" that we know will get the timer back to a known + * state. This handles (via some hairy modular expressions) + * the wraparound cases where we are preempted for as much as + * half the counter space. */ - if (!flagged && counter_sub(cyc, counter()) <= 0x7fffff) { + if (zli_fixup && counter_sub(cyc, counter()) <= 0x7fffff) { while (counter_sub(cyc, counter() + 2) > 0x7fffff) { cyc = counter() + 3; set_comparator(cyc);