From dc48999ee16322e25ede16531c2132a4aa785b29 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Fri, 17 Jul 2020 15:27:42 +0530 Subject: [PATCH] Bluetooth: controller: Fill event counter in sync info Fill the referenced event counter of the Periodic Advertising SYNC_IND PDU into the sync info struct in the Common Extended Advertising Header Format. Signed-off-by: Vinayak Kariappa Chettimada --- .../ll_sw/nordic/lll/lll_adv_sync.c | 31 ----------- .../ll_sw/nordic/lll/lll_adv_sync.h | 2 - subsys/bluetooth/controller/ll_sw/pdu.h | 4 ++ .../bluetooth/controller/ll_sw/ull_adv_sync.c | 54 +++++++++++++++++-- 4 files changed, 55 insertions(+), 36 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c index 688531295af..5a5e9845af8 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c @@ -85,37 +85,6 @@ void lll_adv_sync_prepare(void *param) LL_ASSERT(!err || err == -EINPROGRESS); } -void lll_adv_sync_offset_fill(uint32_t ticks_offset, uint32_t start_us, - struct pdu_adv *pdu) -{ - struct pdu_adv_com_ext_adv *p; - struct pdu_adv_sync_info *si; - struct pdu_adv_hdr *h; - uint8_t *ptr; - - p = (void *)&pdu->adv_ext_ind; - h = (void *)p->ext_hdr_adi_adv_data; - ptr = (uint8_t *)h + sizeof(*h); - - if (h->adv_addr) { - ptr += BDADDR_SIZE; - } - - if (h->adi) { - ptr += sizeof(struct pdu_adv_adi); - } - - if (h->aux_ptr) { - ptr += sizeof(struct pdu_adv_aux_ptr); - } - - si = (void *)ptr; - si->offs = (HAL_TICKER_TICKS_TO_US(ticks_offset) - start_us) / 30; - if (si->offs_units) { - si->offs /= 10; - } -} - static int init_reset(void) { return 0; diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.h b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.h index 81c95f533ce..25c46889d7f 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.h @@ -7,7 +7,5 @@ int lll_adv_sync_init(void); int lll_adv_sync_reset(void); void lll_adv_sync_prepare(void *param); -void lll_adv_sync_offset_fill(uint32_t ticks_offset, uint32_t start_us, - struct pdu_adv *pdu); extern uint16_t ull_adv_sync_lll_handle_get(struct lll_adv_sync *lll); diff --git a/subsys/bluetooth/controller/ll_sw/pdu.h b/subsys/bluetooth/controller/ll_sw/pdu.h index 4b5c6d10602..cb1fdf74edf 100644 --- a/subsys/bluetooth/controller/ll_sw/pdu.h +++ b/subsys/bluetooth/controller/ll_sw/pdu.h @@ -77,6 +77,10 @@ /* Standard allows 2 us timing uncertainty inside the event */ #define EVENT_MAFS_MAX_US (EVENT_MAFS_US + 2) +/* SyncInfo field Sync Packet Offset Units field encoding */ +#define SYNC_PKT_OFFS_UNIT_30_US 30 +#define SYNC_PKT_OFFS_UNIT_300_US 300 + /* * Macros to return correct Data Channel PDU time * Note: formula is valid for 1M, 2M and Coded S8 diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c b/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c index d23f750fb16..68aac6affce 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c @@ -43,6 +43,10 @@ static inline void sync_release(struct ll_adv_sync_set *sync); static inline uint16_t sync_handle_get(struct ll_adv_sync_set *sync); static inline uint8_t sync_stop(struct ll_adv_sync_set *sync); static void mfy_sync_offset_get(void *param); +static inline struct pdu_adv_sync_info *sync_info_get(struct pdu_adv *pdu); +static inline void sync_info_offset_fill(struct pdu_adv_sync_info *si, + uint32_t ticks_offset, + uint32_t start_us); static void ticker_cb(uint32_t ticks_at_expire, uint32_t remainder, uint16_t lazy, void *param); static void ticker_op_cb(uint32_t status, void *param); @@ -730,7 +734,9 @@ static inline uint8_t sync_stop(struct ll_adv_sync_set *sync) static void mfy_sync_offset_get(void *param) { struct ll_adv_set *adv = param; + struct lll_adv_sync *lll_sync; struct ll_adv_sync_set *sync; + struct pdu_adv_sync_info *si; uint32_t ticks_to_expire; uint32_t ticks_current; struct pdu_adv *pdu; @@ -738,7 +744,8 @@ static void mfy_sync_offset_get(void *param) uint8_t retry; uint8_t id; - sync = (void *)HDR_LLL2EVT(adv->lll.sync); + lll_sync = adv->lll.sync; + sync = (void *)HDR_LLL2EVT(lll_sync); ticker_id = TICKER_ID_ADV_SYNC_BASE + sync_handle_get(sync); id = TICKER_NULL; @@ -775,10 +782,51 @@ static void mfy_sync_offset_get(void *param) /* NOTE: as remainder not used in scheduling primary PDU * packet timer starts transmission after 1 tick hence the +1. */ - sync->lll.ticks_offset = ticks_to_expire + 1; + lll_sync->ticks_offset = ticks_to_expire + 1; pdu = lll_adv_aux_data_curr_get(adv->lll.aux); - lll_adv_sync_offset_fill(ticks_to_expire, 0, pdu); + si = sync_info_get(pdu); + sync_info_offset_fill(si, ticks_to_expire, 0); + si->evt_cntr = lll_sync->event_counter + lll_sync->latency_prepare; +} + +static inline struct pdu_adv_sync_info *sync_info_get(struct pdu_adv *pdu) +{ + struct pdu_adv_com_ext_adv *p; + struct pdu_adv_hdr *h; + uint8_t *ptr; + + p = (void *)&pdu->adv_ext_ind; + h = (void *)p->ext_hdr_adi_adv_data; + ptr = (uint8_t *)h + sizeof(*h); + + if (h->adv_addr) { + ptr += BDADDR_SIZE; + } + + if (h->adi) { + ptr += sizeof(struct pdu_adv_adi); + } + + if (h->aux_ptr) { + ptr += sizeof(struct pdu_adv_aux_ptr); + } + + return (void *)ptr; +} + +static inline void sync_info_offset_fill(struct pdu_adv_sync_info *si, + uint32_t ticks_offset, + uint32_t start_us) +{ + uint32_t offs; + + offs = HAL_TICKER_TICKS_TO_US(ticks_offset) - start_us; + if (si->offs_units) { + si->offs = offs / SYNC_PKT_OFFS_UNIT_300_US; + } else { + si->offs = offs / SYNC_PKT_OFFS_UNIT_30_US; + } } static void ticker_cb(uint32_t ticks_at_expire, uint32_t remainder,