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 27ed71508e5456dffb12923f3a8732d16a6940f2 Author: Szymon Janc <[email protected]> AuthorDate: Mon Sep 26 14:09:04 2022 +0200 nimble/ll: Move RX power compensation from PHY to LL This will make is easier to handle FEM RX power compensation in generic way. --- nimble/controller/include/controller/ble_phy.h | 3 --- nimble/controller/src/ble_ll.c | 6 ++++++ nimble/controller/src/ble_ll_conn.c | 3 ++- nimble/controller/src/ble_ll_hci.c | 3 ++- nimble/controller/src/ble_ll_priv.h | 2 ++ nimble/controller/src/ble_ll_scan.c | 8 +++++--- nimble/controller/src/ble_ll_scan_aux.c | 5 +++-- nimble/drivers/dialog_cmac/src/ble_phy.c | 5 ----- nimble/drivers/nrf51/src/ble_phy.c | 12 +----------- nimble/drivers/nrf5x/src/ble_phy.c | 12 +----------- 10 files changed, 22 insertions(+), 37 deletions(-) diff --git a/nimble/controller/include/controller/ble_phy.h b/nimble/controller/include/controller/ble_phy.h index 5a989e2f..495a068c 100644 --- a/nimble/controller/include/controller/ble_phy.h +++ b/nimble/controller/include/controller/ble_phy.h @@ -119,9 +119,6 @@ int ble_phy_txpower_round(int dbm); /* Get the transmit power */ int ble_phy_txpwr_get(void); -/* Set RX path power compensation value rounded to integer dB */ -void ble_phy_set_rx_pwr_compensation(int8_t compensation); - /* Disable the PHY */ void ble_phy_disable(void); diff --git a/nimble/controller/src/ble_ll.c b/nimble/controller/src/ble_ll.c index d9f3955e..bb44a278 100644 --- a/nimble/controller/src/ble_ll.c +++ b/nimble/controller/src/ble_ll.c @@ -66,6 +66,8 @@ */ int8_t g_ble_ll_tx_power = MYNEWT_VAL(BLE_LL_TX_PWR_DBM); +int8_t g_ble_ll_tx_power_compensation; +int8_t g_ble_ll_rx_power_compensation; /* Supported states */ #if MYNEWT_VAL(BLE_LL_ROLE_BROADCASTER) @@ -1589,6 +1591,10 @@ ble_ll_reset(void) ble_ll_sync_reset(); #endif + /* reset power compensation */ + g_ble_ll_tx_power_compensation = 0; + g_ble_ll_rx_power_compensation = 0; + /* FLush all packets from Link layer queues */ ble_ll_flush_pkt_queue(&g_ble_ll_data.ll_tx_pkt_q); ble_ll_flush_pkt_queue(&g_ble_ll_data.ll_rx_pkt_q); diff --git a/nimble/controller/src/ble_ll_conn.c b/nimble/controller/src/ble_ll_conn.c index d7a202da..eeed8b66 100644 --- a/nimble/controller/src/ble_ll_conn.c +++ b/nimble/controller/src/ble_ll_conn.c @@ -43,6 +43,7 @@ #include "controller/ble_ll_utils.h" #include "ble_ll_conn_priv.h" #include "ble_ll_ctrl_priv.h" +#include "ble_ll_priv.h" #if MYNEWT_PKG_apache_mynewt_nimble__nimble_transport_common_hci_ipc #include <nimble/transport/hci_ipc.h> #endif @@ -3489,7 +3490,7 @@ ble_ll_conn_rx_data_pdu(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *hdr) #endif /* Update RSSI */ - connsm->conn_rssi = hdr->rxinfo.rssi; + connsm->conn_rssi = hdr->rxinfo.rssi + g_ble_ll_rx_power_compensation; /* * If we are a peripheral, we can only start to use peripheral latency diff --git a/nimble/controller/src/ble_ll_hci.c b/nimble/controller/src/ble_ll_hci.c index f0151b49..39085d4c 100644 --- a/nimble/controller/src/ble_ll_hci.c +++ b/nimble/controller/src/ble_ll_hci.c @@ -826,7 +826,8 @@ ble_ll_write_rf_path_compensation(const uint8_t *cmdbuf, uint8_t len) tx_path_pwr_compensation = tx; rx_path_pwr_compensation = rx; - ble_phy_set_rx_pwr_compensation(rx_path_pwr_compensation / 10); + g_ble_ll_tx_power_compensation = tx / 10; + g_ble_ll_rx_power_compensation = rx / 10; return BLE_ERR_SUCCESS; } diff --git a/nimble/controller/src/ble_ll_priv.h b/nimble/controller/src/ble_ll_priv.h index ca8e0829..c373de20 100644 --- a/nimble/controller/src/ble_ll_priv.h +++ b/nimble/controller/src/ble_ll_priv.h @@ -25,6 +25,8 @@ extern "C" { #endif extern int8_t g_ble_ll_tx_power; +extern int8_t g_ble_ll_tx_power_compensation; +extern int8_t g_ble_ll_rx_power_compensation; #ifdef MYNEWT diff --git a/nimble/controller/src/ble_ll_scan.c b/nimble/controller/src/ble_ll_scan.c index 75441bb5..d9354050 100644 --- a/nimble/controller/src/ble_ll_scan.c +++ b/nimble/controller/src/ble_ll_scan.c @@ -41,6 +41,7 @@ #include "controller/ble_ll_trace.h" #include "controller/ble_ll_sync.h" #include "ble_ll_conn_priv.h" +#include "ble_ll_priv.h" #if MYNEWT_VAL(BLE_LL_ROLE_OBSERVER) @@ -716,7 +717,7 @@ ble_ll_scan_send_adv_report(uint8_t pdu_type, if (scansm->ext_scanning) { rc = ble_ll_hci_send_legacy_ext_adv_report(evtype, adva, adva_type, - hdr->rxinfo.rssi, + hdr->rxinfo.rssi + g_ble_ll_rx_power_compensation, adv_data_len, om, inita, inita_type); goto done; @@ -725,11 +726,12 @@ goto done; if (subev == BLE_HCI_LE_SUBEV_DIRECT_ADV_RPT) { rc = ble_ll_hci_send_dir_adv_report(adva, adva_type, inita, inita_type, - hdr->rxinfo.rssi); + hdr->rxinfo.rssi + g_ble_ll_rx_power_compensation); goto done; } - rc = ble_ll_hci_send_adv_report(evtype, adva, adva_type, hdr->rxinfo.rssi, + rc = ble_ll_hci_send_adv_report(evtype, adva, adva_type, + hdr->rxinfo.rssi + g_ble_ll_rx_power_compensation, adv_data_len, om); done: if (!rc && scansm->scan_filt_dups) { diff --git a/nimble/controller/src/ble_ll_scan_aux.c b/nimble/controller/src/ble_ll_scan_aux.c index 63e2feb2..0800f4af 100644 --- a/nimble/controller/src/ble_ll_scan_aux.c +++ b/nimble/controller/src/ble_ll_scan_aux.c @@ -38,6 +38,7 @@ #include "controller/ble_ll_whitelist.h" #include "controller/ble_ll_resolv.h" #include "controller/ble_ll_sync.h" +#include "ble_ll_priv.h" #define BLE_LL_SCAN_AUX_F_AUX_ADV 0x0001 #define BLE_LL_SCAN_AUX_F_AUX_CHAIN 0x0002 @@ -408,7 +409,7 @@ ble_ll_hci_ev_update_ext_adv_report_from_ext(struct ble_hci_ev *hci_ev, report->pri_phy = rxinfo->phy; report->sec_phy = 0; report->sid = 0xff; - report->rssi = rxhdr->rxinfo.rssi; + report->rssi = rxhdr->rxinfo.rssi + g_ble_ll_rx_power_compensation; report->periodic_itvl = 0; report->data_len = 0; @@ -529,7 +530,7 @@ ble_ll_hci_ev_send_ext_adv_report(struct os_mbuf *rxpdu, hci_subev = (void *)(*hci_ev)->data; report = hci_subev->reports; - report->rssi = rxinfo->rssi; + report->rssi = rxinfo->rssi + g_ble_ll_rx_power_compensation; report->data_len = min(max_data_len, data_len - offset); os_mbuf_copydata(rxpdu, offset, report->data_len, report->data); diff --git a/nimble/drivers/dialog_cmac/src/ble_phy.c b/nimble/drivers/dialog_cmac/src/ble_phy.c index 077675a3..33c41d2c 100644 --- a/nimble/drivers/dialog_cmac/src/ble_phy.c +++ b/nimble/drivers/dialog_cmac/src/ble_phy.c @@ -1673,11 +1673,6 @@ ble_phy_txpower_round(int dbm) return 0; } -void -ble_phy_set_rx_pwr_compensation(int8_t compensation) -{ -} - int ble_phy_setchan(uint8_t chan, uint32_t access_addr, uint32_t crc_init) { diff --git a/nimble/drivers/nrf51/src/ble_phy.c b/nimble/drivers/nrf51/src/ble_phy.c index c0d827d7..94302ad3 100644 --- a/nimble/drivers/nrf51/src/ble_phy.c +++ b/nimble/drivers/nrf51/src/ble_phy.c @@ -102,7 +102,6 @@ struct ble_phy_obj uint8_t phy_privacy; uint8_t phy_tx_pyld_len; uint8_t *rxdptr; - int8_t rx_pwr_compensation; uint32_t phy_aar_scratch; uint32_t phy_access_address; struct ble_mbuf_hdr rxhdr; @@ -626,8 +625,7 @@ ble_phy_rx_end_isr(void) /* Set RSSI and CRC status flag in header */ ble_hdr = &g_ble_phy_data.rxhdr; assert(NRF_RADIO->EVENTS_RSSIEND != 0); - ble_hdr->rxinfo.rssi = (-1 * NRF_RADIO->RSSISAMPLE) + - g_ble_phy_data.rx_pwr_compensation; + ble_hdr->rxinfo.rssi = (-1 * NRF_RADIO->RSSISAMPLE); dptr = g_ble_phy_data.rxdptr; @@ -855,8 +853,6 @@ ble_phy_init(void) /* Set phy channel to an invalid channel so first set channel works */ g_ble_phy_data.phy_chan = BLE_PHY_NUM_CHANS; - g_ble_phy_data.rx_pwr_compensation = 0; - /* Toggle peripheral power to reset (just in case) */ NRF_RADIO->POWER = 0; NRF_RADIO->POWER = 1; @@ -1318,12 +1314,6 @@ ble_phy_txpwr_get(void) return g_ble_phy_data.phy_txpwr_dbm; } -void -ble_phy_set_rx_pwr_compensation(int8_t compensation) -{ - g_ble_phy_data.rx_pwr_compensation = compensation; -} - /** * ble phy setchan * diff --git a/nimble/drivers/nrf5x/src/ble_phy.c b/nimble/drivers/nrf5x/src/ble_phy.c index 84f60cef..90d3a346 100644 --- a/nimble/drivers/nrf5x/src/ble_phy.c +++ b/nimble/drivers/nrf5x/src/ble_phy.c @@ -144,7 +144,6 @@ struct ble_phy_obj uint8_t phy_tx_phy_mode; uint8_t phy_rx_phy_mode; uint8_t phy_bcc_offset; - int8_t rx_pwr_compensation; uint32_t phy_aar_scratch; uint32_t phy_access_address; struct ble_mbuf_hdr rxhdr; @@ -1168,8 +1167,7 @@ ble_phy_rx_end_isr(void) /* Set RSSI and CRC status flag in header */ ble_hdr = &g_ble_phy_data.rxhdr; assert(NRF_RADIO->EVENTS_RSSIEND != 0); - ble_hdr->rxinfo.rssi = (-1 * NRF_RADIO->RSSISAMPLE) + - g_ble_phy_data.rx_pwr_compensation; + ble_hdr->rxinfo.rssi = (-1 * NRF_RADIO->RSSISAMPLE); dptr = (uint8_t *)&g_ble_phy_rx_buf[0]; dptr += 3; @@ -1503,8 +1501,6 @@ ble_phy_init(void) g_ble_phy_data.phy_tx_phy_mode = BLE_PHY_MODE_1M; g_ble_phy_data.phy_rx_phy_mode = BLE_PHY_MODE_1M; - g_ble_phy_data.rx_pwr_compensation = 0; - /* Set phy channel to an invalid channel so first set channel works */ g_ble_phy_data.phy_chan = BLE_PHY_NUM_CHANS; @@ -2004,12 +2000,6 @@ ble_phy_txpwr_get(void) return g_ble_phy_data.phy_txpwr_dbm; } -void -ble_phy_set_rx_pwr_compensation(int8_t compensation) -{ - g_ble_phy_data.rx_pwr_compensation = compensation; -} - /** * ble phy setchan *
