You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2023/05/19 13:50:59 UTC

[mynewt-nimble] branch master updated (46fdbeeb -> 550d5a77)

This is an automated email from the ASF dual-hosted git repository.

janc pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git


    from 46fdbeeb nimble/ll: Fix ports build
     new bd8c9662 nimble/ll: Rework how TX power is configured
     new 550d5a77 nimble/ll: Add function for getting current PHY channel

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 nimble/controller/include/controller/ble_phy.h |  1 +
 nimble/controller/src/ble_ll.c                 | 14 ++++++++++++--
 nimble/controller/src/ble_ll_adv.c             | 26 +++++++++-----------------
 nimble/controller/src/ble_ll_conn.c            |  3 +++
 nimble/controller/src/ble_ll_hci_vs.c          |  2 --
 nimble/controller/src/ble_ll_scan.c            |  7 +++++++
 nimble/controller/src/ble_ll_scan_aux.c        |  8 ++++++++
 nimble/drivers/dialog_cmac/src/ble_phy.c       |  6 ++++++
 nimble/drivers/native/src/ble_phy.c            |  6 ++++++
 nimble/drivers/nrf51/src/ble_phy.c             |  6 ++++++
 nimble/drivers/nrf5x/src/ble_phy.c             |  6 ++++++
 11 files changed, 64 insertions(+), 21 deletions(-)


[mynewt-nimble] 01/02: nimble/ll: Rework how TX power is configured

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit bd8c96621f8007b06a4770a143ddc88e73734d2a
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Wed May 17 13:39:22 2023 +0200

    nimble/ll: Rework how TX power is configured
    
    TX power is now always configured after channel (and PHY) is set before
    transmission is started. There is no "default" TX power and all users
    are expected to set it explicitly before transmission. This means that
    at the end of advertising TX power is not set back to global value.
    
    Main rationale for this change is to properly handle FEM that may have
    amplification factor depends on signal frequency (channel used).
---
 nimble/controller/src/ble_ll.c          | 14 ++++++++++++--
 nimble/controller/src/ble_ll_adv.c      | 26 +++++++++-----------------
 nimble/controller/src/ble_ll_conn.c     |  3 +++
 nimble/controller/src/ble_ll_hci_vs.c   |  2 --
 nimble/controller/src/ble_ll_scan.c     |  7 +++++++
 nimble/controller/src/ble_ll_scan_aux.c |  8 ++++++++
 6 files changed, 39 insertions(+), 21 deletions(-)

diff --git a/nimble/controller/src/ble_ll.c b/nimble/controller/src/ble_ll.c
index 4da7a1f8..ed1795be 100644
--- a/nimble/controller/src/ble_ll.c
+++ b/nimble/controller/src/ble_ll.c
@@ -76,6 +76,7 @@
 
 /* This is TX power on PHY (or FEM PA if enabled) */
 int8_t g_ble_ll_tx_power;
+static int8_t g_ble_ll_tx_power_phy_current;
 int8_t g_ble_ll_tx_power_compensation;
 int8_t g_ble_ll_rx_power_compensation;
 
@@ -1365,7 +1366,7 @@ ble_ll_task(void *arg)
     /* Set output power to default */
     g_ble_ll_tx_power = ble_ll_tx_power_round(MIN(MYNEWT_VAL(BLE_LL_TX_PWR_DBM),
                                                   MYNEWT_VAL(BLE_LL_TX_PWR_MAX_DBM)));
-    ble_ll_tx_power_set(g_ble_ll_tx_power);
+    g_ble_ll_tx_power_phy_current = INT8_MAX;
 
     /* Tell the host that we are ready to receive packets */
     ble_ll_hci_send_noop();
@@ -1617,7 +1618,7 @@ ble_ll_reset(void)
     /* Set output power to default */
     g_ble_ll_tx_power = ble_ll_tx_power_round(MIN(MYNEWT_VAL(BLE_LL_TX_PWR_DBM),
                                                   MYNEWT_VAL(BLE_LL_TX_PWR_MAX_DBM)));
-    ble_ll_tx_power_set(g_ble_ll_tx_power);
+    g_ble_ll_tx_power_phy_current = INT8_MAX;
 
     /* FLush all packets from Link layer queues */
     ble_ll_flush_pkt_queue(&g_ble_ll_data.ll_tx_pkt_q);
@@ -2011,6 +2012,15 @@ ble_ll_tx_power_set(int tx_power)
     tx_power -= MYNEWT_VAL(BLE_FEM_PA_GAIN);
 #endif
 #endif
+
+    /* If current TX power configuration matches requested one we don't need
+     * to update PHY tx power.
+     */
+    if (g_ble_ll_tx_power_phy_current == tx_power) {
+        return;
+    }
+
+    g_ble_ll_tx_power_phy_current = tx_power;
     ble_phy_tx_power_set(tx_power);
 }
 
diff --git a/nimble/controller/src/ble_ll_adv.c b/nimble/controller/src/ble_ll_adv.c
index ab5e6e2d..c7f16e11 100644
--- a/nimble/controller/src/ble_ll_adv.c
+++ b/nimble/controller/src/ble_ll_adv.c
@@ -1030,9 +1030,6 @@ ble_ll_adv_tx_done(void *arg)
 {
     struct ble_ll_adv_sm *advsm;
 
-    /* reset power to default after advertising */
-    ble_ll_tx_power_set(g_ble_ll_tx_power);
-
     advsm = (struct ble_ll_adv_sm *)arg;
 
     ble_ll_trace_u32x2(BLE_LL_TRACE_ID_ADV_TXDONE, advsm->adv_instance,
@@ -1111,9 +1108,6 @@ ble_ll_adv_tx_start_cb(struct ble_ll_sched_item *sch)
         goto adv_tx_done;
     }
 
-    /* Set the power */
-    ble_ll_tx_power_set(advsm->tx_power);
-
     /* Set channel */
     rc = ble_phy_setchan(advsm->adv_chan, BLE_ACCESS_ADDR_ADV, BLE_LL_CRCINIT_ADV);
     BLE_LL_ASSERT(rc == 0);
@@ -1131,6 +1125,9 @@ ble_ll_adv_tx_start_cb(struct ble_ll_sched_item *sch)
 #endif
 #endif
 
+    /* Set the power */
+    ble_ll_tx_power_set(advsm->tx_power);
+
     /* Set transmit start time. */
     txstart = sch->start_time + g_ble_ll_sched_offset_ticks;
     rc = ble_phy_tx_set_start_time(txstart, sch->remainder);
@@ -1255,9 +1252,6 @@ ble_ll_adv_secondary_tx_start_cb(struct ble_ll_sched_item *sch)
 
     ble_ll_adv_active_chanset_set_sec(advsm);
 
-    /* Set the power */
-    ble_ll_tx_power_set(advsm->tx_power);
-
     /* Set channel */
     aux = AUX_CURRENT(advsm);
     rc = ble_phy_setchan(aux->chan, BLE_ACCESS_ADDR_ADV,
@@ -1269,6 +1263,9 @@ ble_ll_adv_secondary_tx_start_cb(struct ble_ll_sched_item *sch)
      ble_phy_mode_set(advsm->sec_phy, advsm->sec_phy);
 #endif
 
+    /* Set the power */
+    ble_ll_tx_power_set(advsm->tx_power);
+
     /* Set transmit start time. */
     txstart = sch->start_time + g_ble_ll_sched_offset_ticks;
     rc = ble_phy_tx_set_start_time(txstart, sch->remainder);
@@ -1741,8 +1738,6 @@ ble_ll_adv_halt(void)
 
         ble_ll_trace_u32(BLE_LL_TRACE_ID_ADV_HALT, advsm->adv_instance);
 
-        ble_ll_tx_power_set(g_ble_ll_tx_power);
-
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PERIODIC_ADV)
         if (advsm->flags & BLE_LL_ADV_SM_FLAG_PERIODIC_SYNC_SENDING) {
             ble_ll_adv_flags_clear(advsm,
@@ -2176,9 +2171,6 @@ ble_ll_adv_sync_pdu_make(uint8_t *dptr, void *pducb_arg, uint8_t *hdr_byte)
 static void
 ble_ll_adv_sync_tx_done(struct ble_ll_adv_sm *advsm)
 {
-    /* reset power to default after advertising */
-    ble_ll_tx_power_set(g_ble_ll_tx_power);
-
     /* for sync we trace a no pri nor sec set */
     ble_ll_trace_u32x2(BLE_LL_TRACE_ID_ADV_TXDONE, advsm->adv_instance, 0);
 
@@ -2232,9 +2224,6 @@ ble_ll_adv_sync_tx_start_cb(struct ble_ll_sched_item *sch)
     ble_ll_adv_active_chanset_clear(advsm);
     ble_ll_adv_flags_set(advsm, BLE_LL_ADV_SM_FLAG_PERIODIC_SYNC_SENDING);
 
-    /* Set the power */
-    ble_ll_tx_power_set(advsm->tx_power);
-
     /* Set channel */
     sync = SYNC_CURRENT(advsm);
     rc = ble_phy_setchan(sync->chan, advsm->periodic_access_addr,
@@ -2247,6 +2236,9 @@ ble_ll_adv_sync_tx_start_cb(struct ble_ll_sched_item *sch)
      ble_phy_mode_set(advsm->sec_phy, advsm->sec_phy);
 #endif
 
+    /* Set the power */
+    ble_ll_tx_power_set(advsm->tx_power);
+
     /* Set transmit start time. */
     txstart = sch->start_time + g_ble_ll_sched_offset_ticks;
     rc = ble_phy_tx_set_start_time(txstart, sch->remainder);
diff --git a/nimble/controller/src/ble_ll_conn.c b/nimble/controller/src/ble_ll_conn.c
index b70a2376..78146f4f 100644
--- a/nimble/controller/src/ble_ll_conn.c
+++ b/nimble/controller/src/ble_ll_conn.c
@@ -1523,6 +1523,9 @@ ble_ll_conn_event_start_cb(struct ble_ll_sched_item *sch)
     ble_phy_mode_set(connsm->phy_data.tx_phy_mode, connsm->phy_data.rx_phy_mode);
 #endif
 
+    /* Set the power */
+    ble_ll_tx_power_set(g_ble_ll_tx_power);
+
     switch (connsm->conn_role) {
 #if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
     case BLE_LL_CONN_ROLE_CENTRAL:
diff --git a/nimble/controller/src/ble_ll_hci_vs.c b/nimble/controller/src/ble_ll_hci_vs.c
index b5affc2f..7fd9a6ea 100644
--- a/nimble/controller/src/ble_ll_hci_vs.c
+++ b/nimble/controller/src/ble_ll_hci_vs.c
@@ -84,8 +84,6 @@ ble_ll_hci_vs_set_tx_power(uint16_t ocf, const uint8_t *cmdbuf, uint8_t cmdlen,
                                                   g_ble_ll_tx_power_compensation);
     }
 
-    ble_ll_tx_power_set(g_ble_ll_tx_power);
-
     rsp->tx_power = g_ble_ll_tx_power + g_ble_ll_tx_power_compensation;
     *rsplen = sizeof(*rsp);
 
diff --git a/nimble/controller/src/ble_ll_scan.c b/nimble/controller/src/ble_ll_scan.c
index 748cf3ac..3c507323 100644
--- a/nimble/controller/src/ble_ll_scan.c
+++ b/nimble/controller/src/ble_ll_scan.c
@@ -785,6 +785,13 @@ ble_ll_scan_start(struct ble_ll_scan_sm *scansm)
     ble_phy_mode_set(phy_mode, phy_mode);
 #endif
 
+    /* if scan is not passive we need to set tx power as we may end up sending
+     * package
+     */
+    if (scansm->scanp->scan_type != BLE_SCAN_TYPE_PASSIVE) {
+        ble_ll_tx_power_set(g_ble_ll_tx_power);
+    }
+
     rc = ble_phy_rx_set_start_time(ble_ll_tmr_get() +
                                    g_ble_ll_sched_offset_ticks, 0);
     if (!rc || rc == BLE_PHY_ERR_RX_LATE) {
diff --git a/nimble/controller/src/ble_ll_scan_aux.c b/nimble/controller/src/ble_ll_scan_aux.c
index 6160fef2..3d5f2775 100644
--- a/nimble/controller/src/ble_ll_scan_aux.c
+++ b/nimble/controller/src/ble_ll_scan_aux.c
@@ -142,6 +142,14 @@ ble_ll_scan_aux_sched_cb(struct ble_ll_sched_item *sch)
     ble_phy_mode_set(phy_mode, phy_mode);
 #endif
 
+    /* if scan is not passive we need to set tx power as we may end up sending
+     * package
+     */
+    /* TODO do this only on first AUX? */
+    if (aux->scan_type != BLE_SCAN_TYPE_PASSIVE) {
+        ble_ll_tx_power_set(g_ble_ll_tx_power);
+    }
+
     rc = ble_phy_rx_set_start_time(sch->start_time + g_ble_ll_sched_offset_ticks,
                                    sch->remainder);
     if (rc != 0 && rc != BLE_PHY_ERR_RX_LATE) {


[mynewt-nimble] 02/02: nimble/ll: Add function for getting current PHY channel

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 550d5a77cac8913d2b97b9238c87d85456a0623d
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Wed May 17 13:48:11 2023 +0200

    nimble/ll: Add function for getting current PHY channel
    
    This is useful for dynamic FEM drivers.
---
 nimble/controller/include/controller/ble_phy.h | 1 +
 nimble/drivers/dialog_cmac/src/ble_phy.c       | 6 ++++++
 nimble/drivers/native/src/ble_phy.c            | 6 ++++++
 nimble/drivers/nrf51/src/ble_phy.c             | 6 ++++++
 nimble/drivers/nrf5x/src/ble_phy.c             | 6 ++++++
 5 files changed, 25 insertions(+)

diff --git a/nimble/controller/include/controller/ble_phy.h b/nimble/controller/include/controller/ble_phy.h
index bba8bccb..ab96cb9c 100644
--- a/nimble/controller/include/controller/ble_phy.h
+++ b/nimble/controller/include/controller/ble_phy.h
@@ -86,6 +86,7 @@ int ble_phy_init(void);
 
 /* Set the PHY channel */
 int ble_phy_setchan(uint8_t chan, uint32_t access_addr, uint32_t crcinit);
+uint8_t ble_phy_chan_get(void);
 
 #if MYNEWT_VAL(BLE_PHY_VARIABLE_TIFS)
 /* Set T_ifs time for next transition */
diff --git a/nimble/drivers/dialog_cmac/src/ble_phy.c b/nimble/drivers/dialog_cmac/src/ble_phy.c
index 997ce2ab..938455bb 100644
--- a/nimble/drivers/dialog_cmac/src/ble_phy.c
+++ b/nimble/drivers/dialog_cmac/src/ble_phy.c
@@ -1697,6 +1697,12 @@ ble_phy_setchan(uint8_t chan, uint32_t access_addr, uint32_t crc_init)
     return 0;
 }
 
+uint8_t
+ble_phy_chan_get(void)
+{
+    return g_ble_phy_data.channel;
+}
+
 void
 ble_phy_restart_rx(void)
 {
diff --git a/nimble/drivers/native/src/ble_phy.c b/nimble/drivers/native/src/ble_phy.c
index 7635621c..e27f36e9 100644
--- a/nimble/drivers/native/src/ble_phy.c
+++ b/nimble/drivers/native/src/ble_phy.c
@@ -551,6 +551,12 @@ ble_phy_setchan(uint8_t chan, uint32_t access_addr, uint32_t crcinit)
     return 0;
 }
 
+uint8_t
+ble_phy_chan_get(void)
+{
+    return g_ble_phy_data.phy_chan;
+}
+
 /**
  * Disable the PHY. This will do the following:
  *  -> Turn off all phy interrupts.
diff --git a/nimble/drivers/nrf51/src/ble_phy.c b/nimble/drivers/nrf51/src/ble_phy.c
index f35c7781..c3a523dc 100644
--- a/nimble/drivers/nrf51/src/ble_phy.c
+++ b/nimble/drivers/nrf51/src/ble_phy.c
@@ -1365,6 +1365,12 @@ ble_phy_setchan(uint8_t chan, uint32_t access_addr, uint32_t crcinit)
     return 0;
 }
 
+uint8_t
+ble_phy_chan_get(void)
+{
+    return g_ble_phy_data.phy_chan;
+}
+
 /**
  * Stop the timer used to count microseconds when using RTC for cputime
  */
diff --git a/nimble/drivers/nrf5x/src/ble_phy.c b/nimble/drivers/nrf5x/src/ble_phy.c
index bbf4f0a5..223afbff 100644
--- a/nimble/drivers/nrf5x/src/ble_phy.c
+++ b/nimble/drivers/nrf5x/src/ble_phy.c
@@ -2126,6 +2126,12 @@ ble_phy_setchan(uint8_t chan, uint32_t access_addr, uint32_t crcinit)
     return 0;
 }
 
+uint8_t
+ble_phy_chan_get(void)
+{
+    return g_ble_phy_data.phy_chan;
+}
+
 /**
  * Stop the timer used to count microseconds when using RTC for cputime
  */