feat(802.15.4): introduce a series of APIs related power table

This commit is contained in:
zwx
2025-01-03 14:22:21 +08:00
parent acacf85a1d
commit 07e0f9df4c
7 changed files with 178 additions and 15 deletions
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -7,6 +7,7 @@
#include <stdint.h>
#include <string.h>
#include "hal/ieee802154_ll.h"
#include "esp_check.h"
#include "esp_ieee802154_pib.h"
#include "esp_ieee802154_util.h"
@@ -40,7 +41,7 @@ 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;
s_ieee802154_pib.txpower = IEEE802154_TXPOWER_VALUE_MAX;
memset(&s_ieee802154_pib.power_table, IEEE802154_TXPOWER_VALUE_MAX, sizeof(s_ieee802154_pib.power_table));
set_pending();
}
@@ -62,7 +63,7 @@ void ieee802154_pib_update(void)
{
if (ieee802154_pib_is_pending()) {
ieee802154_ll_set_freq(ieee802154_channel_to_freq(s_ieee802154_pib.channel));
ieee802154_ll_set_power(ieee802154_txpower_convert(s_ieee802154_pib.txpower));
ieee802154_ll_set_power(ieee802154_txpower_convert(ieee802154_pib_get_power()));
ieee802154_ll_set_cca_mode(s_ieee802154_pib.cca_mode);
ieee802154_ll_set_cca_threshold(s_ieee802154_pib.cca_threshold);
@@ -86,6 +87,7 @@ uint8_t ieee802154_pib_get_channel(void)
void ieee802154_pib_set_channel(uint8_t channel)
{
ESP_RETURN_ON_FALSE(ieee802154_is_valid_channel(channel), , IEEE802154_TAG, "Failed to set channel, reason: Invalid channel: %d", channel);
if (s_ieee802154_pib.channel != channel) {
s_ieee802154_pib.channel = channel;
set_pending();
@@ -94,15 +96,48 @@ void ieee802154_pib_set_channel(uint8_t channel)
int8_t ieee802154_pib_get_power(void)
{
return s_ieee802154_pib.txpower;
int8_t ret_power = 0;
ieee802154_pib_get_power_with_channel(s_ieee802154_pib.channel, &ret_power);
return ret_power;
}
void ieee802154_pib_set_power(int8_t power)
{
if (s_ieee802154_pib.txpower != power) {
s_ieee802154_pib.txpower = power;
ieee802154_pib_set_power_with_channel(s_ieee802154_pib.channel, power);
}
esp_err_t ieee802154_pib_set_power_table(esp_ieee802154_txpower_table_t power_table)
{
if (memcmp(&s_ieee802154_pib.power_table, &power_table, sizeof(esp_ieee802154_txpower_table_t)) != 0) {
memcpy((void *)&s_ieee802154_pib.power_table, (void *)&power_table, sizeof(esp_ieee802154_txpower_table_t));
set_pending();
}
return ESP_OK;
}
esp_err_t ieee802154_pib_get_power_table(esp_ieee802154_txpower_table_t *out_power_table)
{
ESP_RETURN_ON_FALSE(out_power_table != NULL, ESP_ERR_INVALID_ARG, IEEE802154_TAG, "Invalid power table");
memcpy((void *)out_power_table, (void *)&s_ieee802154_pib.power_table, sizeof(esp_ieee802154_txpower_table_t));
return ESP_OK;
}
esp_err_t ieee802154_pib_set_power_with_channel(uint8_t channel, int8_t power)
{
ESP_RETURN_ON_FALSE(ieee802154_is_valid_channel(channel), ESP_ERR_INVALID_ARG, IEEE802154_TAG, "Invalid channel: %d", channel);
if (s_ieee802154_pib.power_table.channel[channel - IEEE802154_OQPSK_2P4G_CHANNEL_MIN] != power) {
s_ieee802154_pib.power_table.channel[channel - IEEE802154_OQPSK_2P4G_CHANNEL_MIN] = power;
set_pending();
}
return ESP_OK;
}
esp_err_t ieee802154_pib_get_power_with_channel(uint8_t channel, int8_t *out_power)
{
ESP_RETURN_ON_FALSE(ieee802154_is_valid_channel(channel), ESP_ERR_INVALID_ARG, IEEE802154_TAG, "Invalid channel: %d", channel);
ESP_RETURN_ON_FALSE(out_power != NULL, ESP_ERR_INVALID_ARG, IEEE802154_TAG, "The pointer of out_power should not be NULL");
*out_power = s_ieee802154_pib.power_table.channel[channel - IEEE802154_OQPSK_2P4G_CHANNEL_MIN];
return ESP_OK;
}
bool ieee802154_pib_get_promiscuous(void)
@@ -13,12 +13,12 @@
uint8_t ieee802154_freq_to_channel(uint8_t freq)
{
return (freq - 3) / 5 + 11;
return (freq - 3) / 5 + IEEE802154_OQPSK_2P4G_CHANNEL_MIN;
}
uint8_t ieee802154_channel_to_freq(uint8_t channel)
{
return (channel - 11) * 5 + 3;
return (channel - IEEE802154_OQPSK_2P4G_CHANNEL_MIN) * 5 + 3;
}
#if !CONFIG_IEEE802154_TEST && (CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE)