Commit dc48999e authored by Vinayak Kariappa Chettimada's avatar Vinayak Kariappa Chettimada Committed by Carles Cufi
Browse files

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: default avatarVinayak Kariappa Chettimada <vich@nordicsemi.no>
parent 8896da1d
Loading
Loading
Loading
Loading
+0 −31
Original line number Diff line number Diff line
@@ -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;
+0 −2
Original line number Diff line number Diff line
@@ -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);
+4 −0
Original line number Diff line number Diff line
@@ -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
+51 −3
Original line number Diff line number Diff line
@@ -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,