Skip to content

Commit ec784fd

Browse files
cvinayakcfriedt
authored andcommitted
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: Vinayak Kariappa Chettimada <[email protected]>
1 parent 6af9a43 commit ec784fd

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,8 @@ static void pdu_b2b_aux_ptr_update(struct pdu_adv *pdu, uint8_t phy, uint8_t fla
403403
uint8_t chan_idx, uint32_t offset_us, uint32_t cte_len_us)
404404
{
405405
struct pdu_adv_com_ext_adv *com_hdr;
406+
struct pdu_adv_aux_ptr *aux_ptr;
406407
struct pdu_adv_ext_hdr *hdr;
407-
struct pdu_adv_aux_ptr *aux;
408408
uint8_t *dptr;
409409

410410
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
426426
LL_ASSERT(!hdr->adi);
427427

428428
/* Update AuxPtr */
429-
aux = (void *)dptr;
429+
aux_ptr = (void *)dptr;
430430
offset_us += PDU_AC_US(pdu->len, phy, flags);
431431
/* Add CTE length to PDUs that have CTE attached.
432432
* 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
436436
}
437437
offset_us = offset_us / OFFS_UNIT_30_US;
438438
if ((offset_us >> 13) != 0) {
439-
aux->offs = offset_us / (OFFS_UNIT_300_US / OFFS_UNIT_30_US);
440-
aux->offs_units = 1U;
439+
aux_ptr->offs = offset_us / (OFFS_UNIT_300_US / OFFS_UNIT_30_US);
440+
aux_ptr->offs_units = 1U;
441441
} else {
442-
aux->offs = offset_us;
443-
aux->offs_units = 0U;
442+
aux_ptr->offs = offset_us;
443+
aux_ptr->offs_units = 0U;
444444
}
445-
aux->chan_idx = chan_idx;
446-
aux->ca = 0;
447-
aux->phy = find_lsb_set(phy) - 1;
445+
aux_ptr->chan_idx = chan_idx;
446+
aux_ptr->ca = (lll_clock_ppm_local_get() <= SCA_50_PPM) ?
447+
SCA_VALUE_50_PPM : SCA_VALUE_500_PPM;
448+
aux_ptr->phy = find_lsb_set(phy) - 1;
448449
}
449450

450451
static void switch_radio_complete_and_b2b_tx(const struct lll_adv_sync *lll, uint8_t phy_s)

subsys/bluetooth/controller/ll_sw/pdu.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@
108108
/* Value specified in BT Spec. Vol 6, Part B, section 2.3.4.6 */
109109
#define OFFS_ADJUST_US 245760
110110

111+
/* Advertiser's Sleep Clock Accuracy Value */
112+
#define SCA_500_PPM 500 /* 51 ppm to 500 ppm */
113+
#define SCA_50_PPM 50 /* 0 ppm to 50 ppm */
114+
#define SCA_VALUE_500_PPM 0 /* 51 ppm to 500 ppm */
115+
#define SCA_VALUE_50_PPM 1 /* 0 ppm to 50 ppm */
116+
111117
/* Sleep Clock Accuracy, calculate drift in microseconds */
112118
#define SCA_DRIFT_50_PPM_US(t) (((t) * 50UL) / 1000000UL)
113119
#define SCA_DRIFT_500_PPM_US(t) (((t) * 500UL) / 1000000UL)

subsys/bluetooth/controller/ll_sw/ull_adv_aux.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "pdu.h"
2323

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

908909
/* FIXME: implementation defined */
909910
aux_ptr->chan_idx = 0U;
910-
aux_ptr->ca = 0U;
911+
912+
aux_ptr->ca = (lll_clock_ppm_local_get() <= SCA_50_PPM) ?
913+
SCA_VALUE_50_PPM : SCA_VALUE_500_PPM;
911914

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

0 commit comments

Comments
 (0)