sjanc commented on a change in pull request #354: nimble/ll: Add support for 
periodic advertising
URL: https://github.com/apache/mynewt-nimble/pull/354#discussion_r272577008
 
 

 ##########
 File path: nimble/controller/src/ble_ll_adv.c
 ##########
 @@ -1848,36 +1900,504 @@ ble_ll_adv_scheduled(struct ble_ll_adv_sm *advsm, 
uint32_t sch_start, void *arg)
 }
 
 #if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PERIODIC_ADV) == 1)
+static uint8_t
+ble_ll_adv_sync_pdu_make(uint8_t *dptr, void *pducb_arg, uint8_t *hdr_byte)
+{
+    struct ble_ll_adv_sm *advsm;
+    struct ble_ll_adv_sync *sync;
+    uint8_t adv_mode;
+    uint8_t pdu_type;
+    uint8_t ext_hdr_len;
+    uint32_t offset;
+
+    advsm = pducb_arg;
+    sync = SYNC_CURRENT(advsm);
+
+    assert(!ble_ll_adv_active_chanset_is_pri(advsm));
+    assert(!ble_ll_adv_active_chanset_is_sec(advsm));
+    assert(advsm->flags & BLE_LL_ADV_SM_FLAG_PERIODIC_SYNC_SENDING);
+
+    /* It's the same for AUX_SYNC_IND and AUX_CHAIN_IND */
+    pdu_type = BLE_ADV_PDU_TYPE_AUX_SYNC_IND;
+
+    /* non-connectable and non-scannable */
+    adv_mode = 0;
+
+    ext_hdr_len = sync->payload_len - BLE_LL_EXT_ADV_HDR_LEN - 
sync->sync_data_len;
+    dptr[0] = (adv_mode << 6) | ext_hdr_len;
+    dptr += 1;
+
+    dptr[0] = sync->ext_hdr;
+    dptr += 1;
+
+    if (sync->ext_hdr & (1 << BLE_LL_EXT_ADV_AUX_PTR_BIT)) {
+        if (!SYNC_NEXT(advsm)->sch.enqueued) {
+            /*
+             * Trim data here in case we do not have next sync scheduled. This
+             * can happen if next sync was outside advertising set period and
+             * was removed from scheduler.
+             */
+            offset = 0;
+        } else {
+            offset = os_cputime_ticks_to_usecs(SYNC_NEXT(advsm)->start_time - 
sync->start_time);
+        }
+
+        ble_ll_adv_put_aux_ptr(SYNC_NEXT(advsm)->chan, advsm->sec_phy,
+                               offset, dptr);
+
+        dptr += BLE_LL_EXT_ADV_AUX_PTR_SIZE;
+    }
+
+    if (sync->ext_hdr & (1 << BLE_LL_EXT_ADV_TX_POWER_BIT)) {
+        dptr[0] = advsm->adv_txpwr + ble_ll_get_tx_pwr_compensation();
+        dptr += BLE_LL_EXT_ADV_TX_POWER_SIZE;
+    }
+
+    if (sync->sync_data_len) {
+        os_mbuf_copydata(advsm->periodic_adv_data, sync->sync_data_offset,
+                         sync->sync_data_len, dptr);
+    }
+
+    *hdr_byte = pdu_type;
+
+    return sync->payload_len;
+}
+
+static int
+ble_ll_adv_sync_tx_start_cb(struct ble_ll_sched_item *sch)
+{
+    int rc;
+    uint32_t txstart;
+    struct ble_ll_adv_sm *advsm;
+    struct ble_ll_adv_sync *sync;
+
+    /* Get the state machine for the event */
+    advsm = (struct ble_ll_adv_sm *)sch->cb_arg;
+
+    /* Set the current advertiser */
+    g_ble_ll_cur_adv_sm = advsm;
+
+    ble_ll_adv_active_chanset_clear(advsm);
+    advsm->flags |= BLE_LL_ADV_SM_FLAG_PERIODIC_SYNC_SENDING;
+
+    /* Set the power */
+    ble_phy_txpwr_set(advsm->adv_txpwr);
+
+    /* Set channel */
+    sync = SYNC_CURRENT(advsm);
+    rc = ble_phy_setchan(sync->chan, advsm->periodic_access_addr,
+                         advsm->periodic_crcinit);
+
+    assert(rc == 0);
+
+#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
+    /* Set phy mode */
+     ble_phy_mode_set(advsm->sec_phy, advsm->sec_phy);
+#endif
+
+    /* Set transmit start time. */
+    txstart = sch->start_time + g_ble_ll_sched_offset_ticks;
+    rc = ble_phy_tx_set_start_time(txstart, sch->remainder);
+    if (rc) {
+        STATS_INC(ble_ll_stats, adv_late_starts);
+        goto adv_tx_done;
+    }
+
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
+    ble_phy_encrypt_disable();
+#endif
+
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) == 1)
+    ble_phy_resolv_list_disable();
+#endif
+
+    /* Transmit advertisement */
+    ble_phy_set_txend_cb(ble_ll_adv_tx_done, advsm);
 
 Review comment:
   yeah, maybe, I'll check that

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to