Bluetooth: controller: Refactor out drift compensation code
Refactor out drift compensation implementation so as to reuse it for Periodic Sync feature. Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
This commit is contained in:
parent
057653c220
commit
732de50f67
7 changed files with 59 additions and 56 deletions
|
@ -307,7 +307,7 @@ enum {
|
|||
|
||||
};
|
||||
|
||||
struct event_done_extra_slave {
|
||||
struct event_done_extra_drift {
|
||||
uint32_t start_to_address_actual_us;
|
||||
uint32_t window_widening_event_us;
|
||||
uint32_t preamble_to_addr_us;
|
||||
|
@ -322,9 +322,11 @@ struct event_done_extra {
|
|||
#if defined(CONFIG_BT_CTLR_LE_ENC)
|
||||
uint8_t mic_state;
|
||||
#endif /* CONFIG_BT_CTLR_LE_ENC */
|
||||
#if defined(CONFIG_BT_PERIPHERAL) || defined(CONFIG_BT_CTLR_SCAN_PERIODIC)
|
||||
union {
|
||||
struct event_done_extra_slave slave;
|
||||
struct event_done_extra_drift drift;
|
||||
};
|
||||
#endif /* CONFIG_BT_PERIPHERAL || CONFIG_BT_CTLR_SCAN_PERIODIC */
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -632,11 +632,11 @@ static void isr_done(void *param)
|
|||
addr_us_get(0);
|
||||
#endif /* !CONFIG_BT_CTLR_PHY */
|
||||
|
||||
e->slave.start_to_address_actual_us =
|
||||
e->drift.start_to_address_actual_us =
|
||||
radio_tmr_aa_restore() - radio_tmr_ready_get();
|
||||
e->slave.window_widening_event_us =
|
||||
e->drift.window_widening_event_us =
|
||||
lll->slave.window_widening_event_us;
|
||||
e->slave.preamble_to_addr_us = preamble_to_addr_us;
|
||||
e->drift.preamble_to_addr_us = preamble_to_addr_us;
|
||||
|
||||
/* Reset window widening, as anchor point sync-ed */
|
||||
lll->slave.window_widening_event_us = 0;
|
||||
|
|
|
@ -1319,6 +1319,50 @@ void *ull_event_done(void *param)
|
|||
return evdone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Extract timing from completed event
|
||||
*
|
||||
* @param node_rx_event_done[in] Done event containing fresh timing information
|
||||
* @param ticks_drift_plus[out] Positive part of drift uncertainty window
|
||||
* @param ticks_drift_minus[out] Negative part of drift uncertainty window
|
||||
*/
|
||||
void ull_drift_ticks_get(struct node_rx_event_done *done,
|
||||
uint32_t *ticks_drift_plus,
|
||||
uint32_t *ticks_drift_minus)
|
||||
{
|
||||
uint32_t start_to_address_expected_us;
|
||||
uint32_t start_to_address_actual_us;
|
||||
uint32_t window_widening_event_us;
|
||||
uint32_t preamble_to_addr_us;
|
||||
|
||||
start_to_address_actual_us =
|
||||
done->extra.drift.start_to_address_actual_us;
|
||||
window_widening_event_us =
|
||||
done->extra.drift.window_widening_event_us;
|
||||
preamble_to_addr_us =
|
||||
done->extra.drift.preamble_to_addr_us;
|
||||
|
||||
start_to_address_expected_us = EVENT_JITTER_US +
|
||||
EVENT_TICKER_RES_MARGIN_US +
|
||||
window_widening_event_us +
|
||||
preamble_to_addr_us;
|
||||
|
||||
if (start_to_address_actual_us <= start_to_address_expected_us) {
|
||||
*ticks_drift_plus =
|
||||
HAL_TICKER_US_TO_TICKS(window_widening_event_us);
|
||||
*ticks_drift_minus =
|
||||
HAL_TICKER_US_TO_TICKS((start_to_address_expected_us -
|
||||
start_to_address_actual_us));
|
||||
} else {
|
||||
*ticks_drift_plus =
|
||||
HAL_TICKER_US_TO_TICKS(start_to_address_actual_us);
|
||||
*ticks_drift_minus =
|
||||
HAL_TICKER_US_TO_TICKS(EVENT_JITTER_US +
|
||||
EVENT_TICKER_RES_MARGIN_US +
|
||||
preamble_to_addr_us);
|
||||
}
|
||||
}
|
||||
|
||||
static inline int init_reset(void)
|
||||
{
|
||||
memq_link_t *link;
|
||||
|
|
|
@ -1096,8 +1096,8 @@ void ull_conn_done(struct node_rx_event_done *done)
|
|||
if (0) {
|
||||
#if defined(CONFIG_BT_PERIPHERAL)
|
||||
} else if (lll->role) {
|
||||
ull_slave_done(done, &ticks_drift_plus,
|
||||
&ticks_drift_minus);
|
||||
ull_drift_ticks_get(done, &ticks_drift_plus,
|
||||
&ticks_drift_minus);
|
||||
|
||||
if (!conn->tx_head) {
|
||||
ull_conn_tx_demux(UINT8_MAX);
|
||||
|
@ -1281,8 +1281,7 @@ void ull_conn_done(struct node_rx_event_done *done)
|
|||
}
|
||||
|
||||
/* update conn ticker */
|
||||
if ((ticks_drift_plus != 0U) || (ticks_drift_minus != 0U) ||
|
||||
(lazy != 0U) || (force != 0U)) {
|
||||
if (ticks_drift_plus || ticks_drift_minus || lazy || force) {
|
||||
uint8_t ticker_id = TICKER_ID_CONN_BASE + lll->handle;
|
||||
struct ll_conn *conn = lll->hdr.parent;
|
||||
uint32_t ticker_status;
|
||||
|
|
|
@ -41,3 +41,6 @@ void *ull_update_mark(void *param);
|
|||
void *ull_update_unmark(void *param);
|
||||
void *ull_update_mark_get(void);
|
||||
int ull_disable(void *param);
|
||||
void ull_drift_ticks_get(struct node_rx_event_done *done,
|
||||
uint32_t *ticks_drift_plus,
|
||||
uint32_t *ticks_drift_minus);
|
||||
|
|
|
@ -329,49 +329,6 @@ void ull_slave_setup(memq_link_t *link, struct node_rx_hdr *rx,
|
|||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Extract timing from completed event
|
||||
*
|
||||
* @param node_rx_event_done[in] Done event containing fresh timing information
|
||||
* @param ticks_drift_plus[out] Positive part of drift uncertainty window
|
||||
* @param ticks_drift_minus[out] Negative part of drift uncertainty window
|
||||
*/
|
||||
void ull_slave_done(struct node_rx_event_done *done, uint32_t *ticks_drift_plus,
|
||||
uint32_t *ticks_drift_minus)
|
||||
{
|
||||
uint32_t start_to_address_expected_us;
|
||||
uint32_t start_to_address_actual_us;
|
||||
uint32_t window_widening_event_us;
|
||||
uint32_t preamble_to_addr_us;
|
||||
|
||||
start_to_address_actual_us =
|
||||
done->extra.slave.start_to_address_actual_us;
|
||||
window_widening_event_us =
|
||||
done->extra.slave.window_widening_event_us;
|
||||
preamble_to_addr_us =
|
||||
done->extra.slave.preamble_to_addr_us;
|
||||
|
||||
start_to_address_expected_us = EVENT_JITTER_US +
|
||||
EVENT_TICKER_RES_MARGIN_US +
|
||||
window_widening_event_us +
|
||||
preamble_to_addr_us;
|
||||
|
||||
if (start_to_address_actual_us <= start_to_address_expected_us) {
|
||||
*ticks_drift_plus =
|
||||
HAL_TICKER_US_TO_TICKS(window_widening_event_us);
|
||||
*ticks_drift_minus =
|
||||
HAL_TICKER_US_TO_TICKS((start_to_address_expected_us -
|
||||
start_to_address_actual_us));
|
||||
} else {
|
||||
*ticks_drift_plus =
|
||||
HAL_TICKER_US_TO_TICKS(start_to_address_actual_us);
|
||||
*ticks_drift_minus =
|
||||
HAL_TICKER_US_TO_TICKS(EVENT_JITTER_US +
|
||||
EVENT_TICKER_RES_MARGIN_US +
|
||||
preamble_to_addr_us);
|
||||
}
|
||||
}
|
||||
|
||||
void ull_slave_latency_cancel(struct ll_conn *conn, uint16_t handle)
|
||||
{
|
||||
/* break peripheral latency */
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
|
||||
void ull_slave_setup(memq_link_t *link, struct node_rx_hdr *rx,
|
||||
struct node_rx_ftr *ftr, struct lll_conn *lll);
|
||||
void ull_slave_done(struct node_rx_event_done *done, uint32_t *ticks_drift_plus,
|
||||
uint32_t *ticks_drift_minus);
|
||||
void ull_slave_latency_cancel(struct ll_conn *conn, uint16_t handle);
|
||||
void ull_slave_ticker_cb(uint32_t ticks_at_expire, uint32_t remainder, uint16_t lazy,
|
||||
void *param);
|
||||
void ull_slave_ticker_cb(uint32_t ticks_at_expire, uint32_t remainder,
|
||||
uint16_t lazy, void *param);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue