feat(802.15.4): get txpower table from phylib

This commit is contained in:
zhuanghang
2026-01-23 16:42:32 +08:00
committed by Zhang Wen Xu
parent 5d36094661
commit b115848dff
7 changed files with 56 additions and 29 deletions
@@ -8,8 +8,4 @@
#include "hal/ieee802154_common_ll.h"
#define IEEE802154_TXPOWER_VALUE_MAX 20
#define IEEE802154_TXPOWER_VALUE_MIN -15
#define IEEE802154_TXPOWER_INDEX_MIN 3
#define IEEE802154_RSSI_COMPENSATION_VALUE 0
@@ -8,8 +8,4 @@
#include "hal/ieee802154_common_ll.h"
#define IEEE802154_TXPOWER_VALUE_MAX 20
#define IEEE802154_TXPOWER_VALUE_MIN -15
#define IEEE802154_TXPOWER_INDEX_MIN 3
#define IEEE802154_RSSI_COMPENSATION_VALUE 0
@@ -14,10 +14,6 @@ extern "C" {
extern uint32_t bt_bb_get_rssi_comp(void);
#define IEEE802154_TXPOWER_VALUE_MAX 20
#define IEEE802154_TXPOWER_VALUE_MIN -24
#define IEEE802154_TXPOWER_INDEX_MIN 0
#define IEEE802154_RSSI_COMPENSATION_VALUE bt_bb_get_rssi_comp()
#ifdef __cplusplus
@@ -12,11 +12,6 @@
extern "C" {
#endif
// todo: TZ-2155
#define IEEE802154_TXPOWER_VALUE_MAX 10
#define IEEE802154_TXPOWER_VALUE_MIN -14
#define IEEE802154_TXPOWER_INDEX_MIN 0
#define IEEE802154_RSSI_COMPENSATION_VALUE 0
static inline uint32_t ieee802154_ll_get_rx_filter_not_work_cnt(void)
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -15,6 +15,30 @@
static ieee802154_pib_t s_ieee802154_pib;
static bool is_pending = false;
extern const int8_t* bt_bb_get_tx_pwr_table(uint8_t *length);
static inline int8_t IEEE802154_TXPOWER_VALUE_MAX(void)
{
uint8_t length = 0;
const int8_t *tx_pwr_table = bt_bb_get_tx_pwr_table(&length);
if (!tx_pwr_table || length == 0) {
ESP_LOGE(IEEE802154_TAG, "Failed to get tx power table");
return 0;
}
return tx_pwr_table[length - 1];
}
static inline int8_t IEEE802154_TXPOWER_VALUE_MIN(void)
{
uint8_t length = 0;
const int8_t *tx_pwr_table = bt_bb_get_tx_pwr_table(&length);
if (!tx_pwr_table || length == 0) {
ESP_LOGE(IEEE802154_TAG, "Failed to get tx power table");
return 0;
}
return tx_pwr_table[0];
}
static inline void set_pending(void)
{
is_pending = true;
@@ -42,22 +66,36 @@ void ieee802154_pib_init(void)
s_ieee802154_pib.channel = 11;
s_ieee802154_pib.cca_threshold = CONFIG_IEEE802154_CCA_THRESHOLD;
s_ieee802154_pib.cca_mode = CONFIG_IEEE802154_CCA_MODE;
memset(&s_ieee802154_pib.power_table, IEEE802154_TXPOWER_VALUE_MAX, sizeof(s_ieee802154_pib.power_table));
memset(&s_ieee802154_pib.power_table, IEEE802154_TXPOWER_VALUE_MAX(), sizeof(s_ieee802154_pib.power_table));
set_pending();
}
IEEE802154_NOINLINE static uint8_t ieee802154_txpower_convert(int8_t txpower)
{
uint8_t ieee820154_txpower_index = 0;
if (txpower >= IEEE802154_TXPOWER_VALUE_MAX) {
ieee820154_txpower_index = 15;
} else if (txpower <= IEEE802154_TXPOWER_VALUE_MIN) {
ieee820154_txpower_index = IEEE802154_TXPOWER_INDEX_MIN;
} else {
ieee820154_txpower_index = (uint8_t)((txpower - IEEE802154_TXPOWER_VALUE_MIN) / 3) + IEEE802154_TXPOWER_INDEX_MIN;
uint8_t ieee802154_txpower_index = 0;
uint8_t length = 0;
const int8_t *tx_pwr_table = bt_bb_get_tx_pwr_table(&length);
if (!tx_pwr_table || length == 0) {
ESP_LOGE(IEEE802154_TAG, "Failed to get tx power table");
return 0;
}
return ieee820154_txpower_index;
if (txpower <= tx_pwr_table[0]) {
ieee802154_txpower_index = 0;
} else if (txpower >= tx_pwr_table[length - 1]) {
ieee802154_txpower_index = length - 1;
} else {
uint8_t i = 0;
for (i = length-1; i != 0; i--) {
if (tx_pwr_table[i] <= txpower) {
break;
}
}
ieee802154_txpower_index = i;
}
return ieee802154_txpower_index;
}
void ieee802154_pib_update(void)
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -80,3 +80,9 @@ void ieee802154_etm_set_event_task(uint32_t channel, uint32_t event, uint32_t ta
REG_WRITE(ETM_CHENSET_AD0_REG, (REG_READ(ETM_CHENSET_AD0_REG) | 1 << channel));
}
__attribute__((weak)) const int8_t* bt_bb_get_tx_pwr_table(uint8_t *length)
{
ESP_LOGE(IEEE802154_TAG, "bt_bb_get_tx_pwr_table is not implemented");
return NULL;
}