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
The following commit(s) were added to refs/heads/master by this push:
new 266e81d2 nimble/ll: Add option to define maximum allowed TX power
266e81d2 is described below
commit 266e81d2d32fa1e58bd7d7b9fc51156be50e0301
Author: Szymon Janc <[email protected]>
AuthorDate: Tue Oct 4 14:36:38 2022 +0200
nimble/ll: Add option to define maximum allowed TX power
This allows to limit (clip) maximum allowed TX power to meet
requirements for selected LE PHY power class.
---
nimble/controller/src/ble_ll.c | 6 ++++--
nimble/controller/src/ble_ll_adv.c | 3 ++-
nimble/controller/src/ble_ll_hci_vs.c | 8 ++++++--
nimble/controller/syscfg.yml | 8 ++++++++
4 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/nimble/controller/src/ble_ll.c b/nimble/controller/src/ble_ll.c
index 011b0e5f..d8d2e6bc 100644
--- a/nimble/controller/src/ble_ll.c
+++ b/nimble/controller/src/ble_ll.c
@@ -1376,7 +1376,8 @@ ble_ll_task(void *arg)
ble_phy_init();
/* Set output power to default */
- g_ble_ll_tx_power = ble_ll_tx_power_round(MYNEWT_VAL(BLE_LL_TX_PWR_DBM));
+ 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);
/* Tell the host that we are ready to receive packets */
@@ -1623,7 +1624,8 @@ ble_ll_reset(void)
g_ble_ll_rx_power_compensation = 0;
/* Set output power to default */
- g_ble_ll_tx_power = ble_ll_tx_power_round(MYNEWT_VAL(BLE_LL_TX_PWR_DBM));
+ 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);
/* FLush all packets from Link layer queues */
diff --git a/nimble/controller/src/ble_ll_adv.c
b/nimble/controller/src/ble_ll_adv.c
index 6ba46177..49228246 100644
--- a/nimble/controller/src/ble_ll_adv.c
+++ b/nimble/controller/src/ble_ll_adv.c
@@ -3528,7 +3528,8 @@ ble_ll_adv_ext_set_param(const uint8_t *cmdbuf, uint8_t
len,
/* no preference */
advsm->tx_power = ble_ll_tx_power_round(g_ble_ll_tx_power -
g_ble_ll_tx_power_compensation);
} else {
- advsm->tx_power = ble_ll_tx_power_round(cmd->tx_power -
g_ble_ll_tx_power_compensation);
+ advsm->tx_power = ble_ll_tx_power_round(min(cmd->tx_power,
MYNEWT_VAL(BLE_LL_TX_PWR_MAX_DBM)) -
+
g_ble_ll_tx_power_compensation);
}
/* we can always store as those are validated and used only when needed */
diff --git a/nimble/controller/src/ble_ll_hci_vs.c
b/nimble/controller/src/ble_ll_hci_vs.c
index e9c4e2d1..9f7fb185 100644
--- a/nimble/controller/src/ble_ll_hci_vs.c
+++ b/nimble/controller/src/ble_ll_hci_vs.c
@@ -124,9 +124,13 @@ ble_ll_hci_vs_set_tx_power(uint16_t ocf, const uint8_t
*cmdbuf, uint8_t cmdlen,
if (cmd->tx_power == 127) {
/* restore reset default */
- g_ble_ll_tx_power =
ble_ll_tx_power_round(MYNEWT_VAL(BLE_LL_TX_PWR_DBM) -
g_ble_ll_tx_power_compensation);
+ 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)) -
+
g_ble_ll_tx_power_compensation);
} else {
- g_ble_ll_tx_power = ble_ll_tx_power_round(cmd->tx_power -
g_ble_ll_tx_power_compensation);
+ g_ble_ll_tx_power = ble_ll_tx_power_round(min(cmd->tx_power,
+
MYNEWT_VAL(BLE_LL_TX_PWR_MAX_DBM)) -
+
g_ble_ll_tx_power_compensation);
}
ble_ll_tx_power_set(g_ble_ll_tx_power);
diff --git a/nimble/controller/syscfg.yml b/nimble/controller/syscfg.yml
index 686821ae..38f63795 100644
--- a/nimble/controller/syscfg.yml
+++ b/nimble/controller/syscfg.yml
@@ -69,6 +69,14 @@ syscfg.defs:
may be rounded up or down depending on used radio.
value: '0'
+ BLE_LL_TX_PWR_MAX_DBM:
+ description: >
+ Maximum allowed transmit power level (in dBm). This limits maximum
+ power to specified value (including FEM and/or host compensation).
+ Useful for ensuring selected power class of device. Defaults to
+ maximum allowed by specification (Power Class 1).
+ value: '20'
+
BLE_LL_NUM_COMP_PKT_ITVL_MS:
description: >
Determines the interval at which the controller will send the