Bluetooth: Controller: Simplify ticker reschedule_in_window

Simplify ticker reschedule_in_window implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
This commit is contained in:
Vinayak Kariappa Chettimada 2023-10-05 21:26:11 +02:00 committed by Carles Cufí
commit c96375ec1e

View file

@ -2469,11 +2469,15 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance,
ticker_id_resched_prev = ticker_id_resched;
ticker_id_resched = ticker_resched->next;
}
/* Exit if no tickers to be rescheduled */
if (ticker_id_resched == TICKER_NULL) {
/* Done */
break;
}
/* Ensure that resched ticker is expired */
LL_ASSERT(ticker_resched->ticks_to_expire == 0U);
/* Check for intersection with already active node */
window_start_ticks = 0U;
if (instance->ticks_slot_previous > ticks_elapsed) {
@ -2484,8 +2488,6 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance,
ticks_elapsed;
}
ticker_id_next = ticker_resched->next;
/* If drift was applied to this node, this must be
* taken into consideration. Reduce the window with
* the amount of drift already applied.
@ -2499,6 +2501,10 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance,
if (ext_data->ticks_drift < ext_data->ticks_slot_window) {
ticks_slot_window = ext_data->ticks_slot_window -
ext_data->ticks_drift;
/* Window available, proceed to calculate further
* drift
*/
ticker_id_next = ticker_resched->next;
} else {
/* Window has been exhausted - we can't reschedule */
ticker_id_next = TICKER_NULL;
@ -2556,7 +2562,7 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance,
/* Next expiry is too close - try the next
* node
*/
window_end_ticks = 0;
window_end_ticks = 0U;
}
/* Calculate new ticks_to_expire as end of window minus
@ -2578,7 +2584,7 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance,
}
} else {
/* No space in window - try the next node */
ticks_to_expire = 0;
ticks_to_expire = 0U;
}
/* Decide if the re-scheduling ticker node fits in the
@ -2616,9 +2622,7 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance,
ticker_id_next = ticker_next->next;
}
ext_data->ticks_drift += ticks_to_expire -
ticker_resched->ticks_to_expire;
ticker_resched->ticks_to_expire = ticks_to_expire;
ext_data->ticks_drift += ticks_to_expire;
/* Place the ticker node sorted by expiration time and adjust
* delta times
@ -2629,21 +2633,20 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance,
struct ticker_node *ticker_next;
ticker_next = &nodes[ticker_id_next];
if (ticker_resched->ticks_to_expire >
ticker_next->ticks_to_expire) {
if (ticks_to_expire > ticker_next->ticks_to_expire) {
/* Node is after this - adjust delta */
ticker_resched->ticks_to_expire -=
ticker_next->ticks_to_expire;
ticks_to_expire -= ticker_next->ticks_to_expire;
} else {
/* Node is before this one */
ticker_next->ticks_to_expire -=
ticker_resched->ticks_to_expire;
ticker_next->ticks_to_expire -= ticks_to_expire;
break;
}
ticker_id_prev = ticker_id_next;
ticker_id_next = ticker_next->next;
}
ticker_resched->ticks_to_expire = ticks_to_expire;
/* If the node moved in the list, insert it */
if (ticker_id_prev != TICKER_NULL) {
/* Remove node from its current position in list */