From 3e844ec271fa69e2153408cf17aabfacf9723db1 Mon Sep 17 00:00:00 2001 From: Alec Berg Date: Thu, 21 Aug 2014 08:32:37 -0700 Subject: [PATCH] zinger: keyborg: fix runtime bug with task_wait_event() Fix zinger and keyborg to use correct event mask when timing out from task_wait_event(): TASK_EVENT_TIMER. On zinger, move storing the last event to after enabling interrupts. This gives an opportunity to interrupt handler to set the wake event. BUG=chrome-os-partner:30135 BRANCH=none TEST=load on zinger, and test PD communication with samus. notably tested sending rw_hash vdm from samus, which is known to cause zinger to retry the following ping transmit. The retry on the ping transmit uses task_wait_event(), and without this fix we were getting false wake events that had been stored up from the last rx received event. with this fix, the retry mechanism works. Change-Id: I9a6902ceaab49a00d3660f9813ca7761cf38f190 Signed-off-by: Alec Berg Reviewed-on: https://chromium-review.googlesource.com/213560 Reviewed-by: Todd Broch --- board/keyborg/runtime.c | 2 +- board/zinger/runtime.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/board/keyborg/runtime.c b/board/keyborg/runtime.c index e3a8021ef1..e86d591172 100644 --- a/board/keyborg/runtime.c +++ b/board/keyborg/runtime.c @@ -68,7 +68,7 @@ void tim2_interrupt(void) if (STM32_TIM_CNT(3) == last_deadline >> 16) { STM32_TIM_DIER(2) = 0; task_clear_pending_irq(STM32_IRQ_TIM2); - last_event = 1 << 29 /* task event wake */; + last_event = TASK_EVENT_TIMER; need_wfi = 0; } else { need_wfi = 1; diff --git a/board/zinger/runtime.c b/board/zinger/runtime.c index 775afdccec..deaa87d6ab 100644 --- a/board/zinger/runtime.c +++ b/board/zinger/runtime.c @@ -56,7 +56,7 @@ void tim2_interrupt(void) { STM32_TIM_DIER(2) = 0; /* disable match interrupt */ task_clear_pending_irq(STM32_IRQ_TIM2); - last_event = 1 << 29 /* task event wake */; + last_event = TASK_EVENT_TIMER; } DECLARE_IRQ(STM32_IRQ_TIM2, tim2_interrupt, 1); @@ -85,10 +85,12 @@ uint32_t task_wait_event(int timeout_us) asm volatile("wfi"); STM32_TIM_DIER(2) = 0; /* disable match interrupt */ - evt = last_event; - last_event = 0; asm volatile("cpsie i ; isb"); + /* note: interrupt that woke us up will run here */ + + evt = last_event; + last_event = 0; return evt; }