Commit 9ff7cb60 authored by Vinayak Kariappa Chettimada's avatar Vinayak Kariappa Chettimada Committed by Anas Nashif
Browse files

Bluetooth: Controller: Add advertiser clock accuracy value



Add implementation to set correct Advertiser's clock
accuracy value in the auxiliary pointer field in the common
extended payload format.

Signed-off-by: default avatarVinayak Kariappa Chettimada <vich@nordicsemi.no>
parent 71420c6b
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -403,8 +403,8 @@ static void pdu_b2b_aux_ptr_update(struct pdu_adv *pdu, uint8_t phy, uint8_t fla
				   uint8_t chan_idx, uint32_t offset_us, uint32_t cte_len_us)
{
	struct pdu_adv_com_ext_adv *com_hdr;
	struct pdu_adv_aux_ptr *aux_ptr;
	struct pdu_adv_ext_hdr *hdr;
	struct pdu_adv_aux_ptr *aux;
	uint8_t *dptr;

	com_hdr = &pdu->adv_ext_ind;
@@ -426,7 +426,7 @@ static void pdu_b2b_aux_ptr_update(struct pdu_adv *pdu, uint8_t phy, uint8_t fla
	LL_ASSERT(!hdr->adi);

	/* Update AuxPtr */
	aux = (void *)dptr;
	aux_ptr = (void *)dptr;
	offset_us += PDU_AC_US(pdu->len, phy, flags);
	/* Add CTE length to PDUs that have CTE attached.
	 * Periodic advertising chain may include PDUs without CTE.
@@ -436,15 +436,16 @@ static void pdu_b2b_aux_ptr_update(struct pdu_adv *pdu, uint8_t phy, uint8_t fla
	}
	offset_us = offset_us / OFFS_UNIT_30_US;
	if ((offset_us >> 13) != 0) {
		aux->offs = offset_us / (OFFS_UNIT_300_US / OFFS_UNIT_30_US);
		aux->offs_units = 1U;
		aux_ptr->offs = offset_us / (OFFS_UNIT_300_US / OFFS_UNIT_30_US);
		aux_ptr->offs_units = 1U;
	} else {
		aux->offs = offset_us;
		aux->offs_units = 0U;
		aux_ptr->offs = offset_us;
		aux_ptr->offs_units = 0U;
	}
	aux->chan_idx = chan_idx;
	aux->ca = 0;
	aux->phy = find_lsb_set(phy) - 1;
	aux_ptr->chan_idx = chan_idx;
	aux_ptr->ca = (lll_clock_ppm_local_get() <= SCA_50_PPM) ?
		      SCA_VALUE_50_PPM : SCA_VALUE_500_PPM;
	aux_ptr->phy = find_lsb_set(phy) - 1;
}

static void switch_radio_complete_and_b2b_tx(const struct lll_adv_sync *lll, uint8_t phy_s)
+6 −0
Original line number Diff line number Diff line
@@ -108,6 +108,12 @@
/* Value specified in BT Spec. Vol 6, Part B, section 2.3.4.6 */
#define OFFS_ADJUST_US          245760

/* Advertiser's Sleep Clock Accuracy Value */
#define SCA_500_PPM       500 /* 51 ppm to 500 ppm */
#define SCA_50_PPM        50  /* 0 ppm to 50 ppm */
#define SCA_VALUE_500_PPM 0   /* 51 ppm to 500 ppm */
#define SCA_VALUE_50_PPM  1   /* 0 ppm to 50 ppm */

/* Sleep Clock Accuracy, calculate drift in microseconds */
#define SCA_DRIFT_50_PPM_US(t)  (((t) * 50UL) / 1000000UL)
#define SCA_DRIFT_500_PPM_US(t) (((t) * 500UL) / 1000000UL)
+4 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include "pdu.h"

#include "lll.h"
#include "lll_clock.h"
#include "lll/lll_vendor.h"
#include "lll/lll_adv_types.h"
#include "lll_adv.h"
@@ -907,7 +908,9 @@ void ull_adv_aux_ptr_fill(uint8_t **dptr, uint8_t phy_s)

	/* FIXME: implementation defined */
	aux_ptr->chan_idx = 0U;
	aux_ptr->ca = 0U;

	aux_ptr->ca = (lll_clock_ppm_local_get() <= SCA_50_PPM) ?
		      SCA_VALUE_50_PPM : SCA_VALUE_500_PPM;

	/* NOTE: Aux Offset will be set in advertiser LLL event
	 */