From 62b0fff5812e770f3addaf09a79b90bcf5dd80f7 Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Tue, 13 Dec 2022 11:30:46 +0530 Subject: [PATCH] nimble/host: Add helper macros to set interval min / max for perdiodic adv --- nimble/host/include/host/ble_gap.h | 7 ++++--- nimble/host/src/ble_gap.c | 7 +++---- nimble/include/nimble/hci_common.h | 2 ++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/nimble/host/include/host/ble_gap.h b/nimble/host/include/host/ble_gap.h index b132189a0..47a1d5647 100644 --- a/nimble/host/include/host/ble_gap.h +++ b/nimble/host/include/host/ble_gap.h @@ -44,6 +44,7 @@ struct hci_conn_update; #define BLE_GAP_SCAN_WIN_MS(t) ((t) * 1000 / BLE_HCI_SCAN_ITVL) #define BLE_GAP_CONN_ITVL_MS(t) ((t) * 1000 / BLE_HCI_CONN_ITVL) #define BLE_GAP_SUPERVISION_TIMEOUT_MS(t) ((t) / 10) +#define BLE_GAP_PERIODIC_ITVL_MS(t) ((t) * 1000 / BLE_HCI_PERIODIC_ADV_ITVL) /** 30 ms. */ #define BLE_GAP_ADV_FAST_INTERVAL1_MIN BLE_GAP_ADV_ITVL_MS(30) @@ -1458,14 +1459,14 @@ int ble_gap_ext_adv_active(uint8_t instance); /** @brief Periodic advertising parameters */ struct ble_gap_periodic_adv_params { /** If include TX power in advertising PDU */ - unsigned int include_tx_power:1; + unsigned int include_tx_power : 1; - /** Minimum advertising interval in 0.625ms units, if 0 stack use sane + /** Minimum advertising interval in 1.25ms units, if 0 stack use sane * defaults */ uint16_t itvl_min; - /** Maximum advertising interval in 0.625ms units, if 0 stack use sane + /** Maximum advertising interval in 1.25ms units, if 0 stack use sane * defaults */ uint16_t itvl_max; diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index ba1ec7fb0..b6d54bc30 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -3418,12 +3418,11 @@ ble_gap_periodic_adv_params_tx(uint8_t instance, /* Fill optional fields if application did not specify them. */ if (params->itvl_min == 0 && params->itvl_max == 0) { - /* TODO defines for those */ - cmd.min_itvl = htole16(30 / 1.25); //30 ms - cmd.max_itvl = htole16(60 / 1.25); //150 ms + cmd.min_itvl = BLE_GAP_PERIODIC_ITVL_MS(30); + cmd.max_itvl = BLE_GAP_PERIODIC_ITVL_MS(60); } else { - cmd.min_itvl = htole16( params->itvl_min); + cmd.min_itvl = htole16(params->itvl_min); cmd.max_itvl = htole16(params->itvl_max); } diff --git a/nimble/include/nimble/hci_common.h b/nimble/include/nimble/hci_common.h index 7c5ebe9a0..eadb0b0e6 100644 --- a/nimble/include/nimble/hci_common.h +++ b/nimble/include/nimble/hci_common.h @@ -1265,6 +1265,8 @@ struct ble_hci_vs_set_antenna_cp { #define BLE_HCI_ADV_ITVL_DEF (0x800) /* 1.28 seconds */ #define BLE_HCI_ADV_CHANMASK_DEF (0x7) /* all channels */ +#define BLE_HCI_PERIODIC_ADV_ITVL (1250) /* usecs */ + /* Set scan parameters */ #define BLE_HCI_SCAN_TYPE_PASSIVE (0) #define BLE_HCI_SCAN_TYPE_ACTIVE (1)