From 6cb43749a4d82d8f5343cd801eee561d0e2db4dc Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Fri, 27 Mar 2020 15:04:00 +0530 Subject: [PATCH] Bluetooth: controller: Fix ticks_slot_previous calculation Fix ticks_slot_previous calculation in the ticker_job when tickers are skipped. Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/controller/ticker/ticker.c | 37 ++++++++------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/subsys/bluetooth/controller/ticker/ticker.c b/subsys/bluetooth/controller/ticker/ticker.c index af9617b1a65..a1ada4e4b0b 100644 --- a/subsys/bluetooth/controller/ticker/ticker.c +++ b/subsys/bluetooth/controller/ticker/ticker.c @@ -1388,33 +1388,24 @@ static inline void ticker_job_worker_bh(struct ticker_instance *instance, #if !defined(CONFIG_BT_TICKER_COMPATIBILITY_MODE) ticks_latency -= ticks_to_expire; +#endif /* !CONFIG_BT_TICKER_COMPATIBILITY_MODE */ - if (ticker->lazy_current != 0U && - !TICKER_RESCHEDULE_PENDING(ticker)) { + /* decrement ticks_slot_previous */ + if (instance->ticks_slot_previous > ticks_to_expire) { + instance->ticks_slot_previous -= ticks_to_expire; + } else { instance->ticker_id_slot_previous = TICKER_NULL; instance->ticks_slot_previous = 0U; - } else -#endif /* !CONFIG_BT_TICKER_COMPATIBILITY_MODE */ - { - /* decrement ticks_slot_previous */ - if (instance->ticks_slot_previous > ticks_to_expire) { - instance->ticks_slot_previous -= - ticks_to_expire; - } else { - instance->ticker_id_slot_previous = TICKER_NULL; - instance->ticks_slot_previous = 0U; - } + } - /* If a reschedule is set pending, we will need to keep - * the slot_previous information - */ - if (!TICKER_RESCHEDULE_PENDING(ticker) && - ticker->ticks_slot != 0U) { - instance->ticker_id_slot_previous = - id_expired; - instance->ticks_slot_previous = - ticker->ticks_slot; - } + /* If a reschedule is set pending, we will need to keep + * the slot_previous information + */ + if ((ticker->ticks_slot != 0U) && + (((ticker->req - ticker->ack) & 0xff) == 2U) && + !TICKER_RESCHEDULE_PENDING(ticker)) { + instance->ticker_id_slot_previous = id_expired; + instance->ticks_slot_previous = ticker->ticks_slot; } /* ticker expired, set ticks_to_expire zero */