From 33db1583c0e8755399a18399ed12c4c8c91f70f8 Mon Sep 17 00:00:00 2001 From: Xu Si Yu Date: Fri, 17 Jul 2026 19:15:48 +0800 Subject: [PATCH] feat(802.15.4): reorganize source file structure --- components/ieee802154/CMakeLists.txt | 4 + .../ieee802154/driver/esp_ieee802154_dev.c | 4 + components/ieee802154/esp_ieee802154.c | 92 +-------- .../ieee802154/esp_ieee802154_multipan.c | 99 ++++++++++ .../ieee802154/include/esp_ieee802154.h | 166 ---------------- .../include/esp_ieee802154_multipan.h | 187 ++++++++++++++++++ components/ieee802154/linker.lf | 6 +- 7 files changed, 298 insertions(+), 260 deletions(-) create mode 100644 components/ieee802154/esp_ieee802154_multipan.c create mode 100644 components/ieee802154/include/esp_ieee802154_multipan.h diff --git a/components/ieee802154/CMakeLists.txt b/components/ieee802154/CMakeLists.txt index 5f410b3e9bf..96b81e30cb5 100644 --- a/components/ieee802154/CMakeLists.txt +++ b/components/ieee802154/CMakeLists.txt @@ -31,6 +31,10 @@ if(CONFIG_IEEE802154_DEBUG) list(APPEND srcs "driver/esp_ieee802154_debug.c") endif() +if(CONFIG_IEEE802154_MULTI_PAN_ENABLE) + list(APPEND srcs "esp_ieee802154_multipan.c") +endif() + idf_component_register( SRCS "${srcs}" INCLUDE_DIRS "${include}" diff --git a/components/ieee802154/driver/esp_ieee802154_dev.c b/components/ieee802154/driver/esp_ieee802154_dev.c index 44bd72e07bc..4f6a2c5f6b6 100644 --- a/components/ieee802154/driver/esp_ieee802154_dev.c +++ b/components/ieee802154/driver/esp_ieee802154_dev.c @@ -27,6 +27,10 @@ #include "esp_attr.h" #include "esp_phy_init.h" +#if CONFIG_IEEE802154_MULTI_PAN_ENABLE +#include "esp_ieee802154_multipan.h" +#endif + #if CONFIG_PM_ENABLE #include "esp_pm.h" #include "esp_private/esp_clk.h" diff --git a/components/ieee802154/esp_ieee802154.c b/components/ieee802154/esp_ieee802154.c index 189bb002b7c..3ed014fb34c 100644 --- a/components/ieee802154/esp_ieee802154.c +++ b/components/ieee802154/esp_ieee802154.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -170,96 +170,6 @@ esp_err_t esp_ieee802154_set_coordinator(bool enable) return ESP_OK; } -#if CONFIG_IEEE802154_MULTI_PAN_ENABLE - -uint16_t esp_ieee802154_get_multipan_panid(esp_ieee802154_multipan_index_t index) -{ - assert(index < CONFIG_IEEE802154_INTERFACE_NUM); - return ieee802154_ll_get_multipan_panid(index); -} - -esp_err_t esp_ieee802154_set_multipan_panid(esp_ieee802154_multipan_index_t index, uint16_t panid) -{ - assert(index < CONFIG_IEEE802154_INTERFACE_NUM); - ieee802154_ll_set_multipan_panid(index, panid); - return ESP_OK; -} - -uint16_t esp_ieee802154_get_multipan_short_address(esp_ieee802154_multipan_index_t index) -{ - assert(index < CONFIG_IEEE802154_INTERFACE_NUM); - return ieee802154_ll_get_multipan_short_addr(index); -} - -esp_err_t esp_ieee802154_set_multipan_short_address(esp_ieee802154_multipan_index_t index, uint16_t short_address) -{ - assert(index < CONFIG_IEEE802154_INTERFACE_NUM); - ieee802154_ll_set_multipan_short_addr(index, short_address); - return ESP_OK; -} - -esp_err_t esp_ieee802154_get_multipan_extended_address(esp_ieee802154_multipan_index_t index, uint8_t *ext_addr) -{ - assert(index < CONFIG_IEEE802154_INTERFACE_NUM); - assert(ext_addr != NULL); - ieee802154_ll_get_multipan_ext_addr(index, ext_addr); - return ESP_OK; -} - -esp_err_t esp_ieee802154_set_multipan_extended_address(esp_ieee802154_multipan_index_t index, const uint8_t *ext_addr) -{ - assert(index < CONFIG_IEEE802154_INTERFACE_NUM); - assert(ext_addr != NULL); - ieee802154_ll_set_multipan_ext_addr(index, ext_addr); - return ESP_OK; -} - -uint8_t esp_ieee802154_get_multipan_enable(void) -{ - return ieee802154_ll_get_multipan_enable_mask(); -} - -esp_err_t esp_ieee802154_set_multipan_enable(uint8_t mask) -{ - assert(mask < (1 << CONFIG_IEEE802154_INTERFACE_NUM)); - ieee802154_ll_set_multipan_enable_mask(mask); - return ESP_OK; -} - -esp_ieee802154_pending_mode_t esp_ieee802154_multipan_get_pending_mode(esp_ieee802154_multipan_index_t index) -{ - assert(index < CONFIG_IEEE802154_INTERFACE_NUM); - return ieee802154_pib_get_pending_mode(index); -} - -esp_err_t esp_ieee802154_multipan_set_pending_mode(esp_ieee802154_multipan_index_t inf_index, esp_ieee802154_pending_mode_t pending_mode) -{ - assert(inf_index < CONFIG_IEEE802154_INTERFACE_NUM); - ieee802154_pib_set_pending_mode(inf_index, pending_mode); - return ESP_OK; -} - -esp_err_t esp_ieee802154_multipan_add_pending_addr(esp_ieee802154_multipan_index_t inf_index, const uint8_t *addr, bool is_short) -{ - assert(inf_index < CONFIG_IEEE802154_INTERFACE_NUM); - return ieee802154_add_pending_addr(inf_index, addr, is_short); -} - -esp_err_t esp_ieee802154_multipan_clear_pending_addr(esp_ieee802154_multipan_index_t inf_index, const uint8_t *addr, bool is_short) -{ - assert(inf_index < CONFIG_IEEE802154_INTERFACE_NUM); - return ieee802154_clear_pending_addr(inf_index, addr, is_short); -} - -esp_err_t esp_ieee802154_multipan_reset_pending_table(esp_ieee802154_multipan_index_t inf_index, bool is_short) -{ - assert(inf_index < CONFIG_IEEE802154_INTERFACE_NUM); - ieee802154_reset_pending_table(inf_index, is_short); - return ESP_OK; -} - -#endif // CONFIG_IEEE802154_MULTI_PAN_ENABLE - esp_err_t esp_ieee802154_set_ack_timeout(uint32_t timeout) { // Divide by 16 and round it up. diff --git a/components/ieee802154/esp_ieee802154_multipan.c b/components/ieee802154/esp_ieee802154_multipan.c new file mode 100644 index 00000000000..3c15f8fc2a2 --- /dev/null +++ b/components/ieee802154/esp_ieee802154_multipan.c @@ -0,0 +1,99 @@ +/* + * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "sdkconfig.h" +#include + +#include "esp_err.h" +#include "esp_ieee802154_ack.h" +#include "esp_ieee802154_pib.h" +#include "esp_ieee802154_util.h" + +uint16_t esp_ieee802154_get_multipan_panid(esp_ieee802154_multipan_index_t index) +{ + assert(index < CONFIG_IEEE802154_INTERFACE_NUM); + return ieee802154_ll_get_multipan_panid(index); +} + +esp_err_t esp_ieee802154_set_multipan_panid(esp_ieee802154_multipan_index_t index, uint16_t panid) +{ + assert(index < CONFIG_IEEE802154_INTERFACE_NUM); + ieee802154_ll_set_multipan_panid(index, panid); + return ESP_OK; +} + +uint16_t esp_ieee802154_get_multipan_short_address(esp_ieee802154_multipan_index_t index) +{ + assert(index < CONFIG_IEEE802154_INTERFACE_NUM); + return ieee802154_ll_get_multipan_short_addr(index); +} + +esp_err_t esp_ieee802154_set_multipan_short_address(esp_ieee802154_multipan_index_t index, uint16_t short_address) +{ + assert(index < CONFIG_IEEE802154_INTERFACE_NUM); + ieee802154_ll_set_multipan_short_addr(index, short_address); + return ESP_OK; +} + +esp_err_t esp_ieee802154_get_multipan_extended_address(esp_ieee802154_multipan_index_t index, uint8_t *ext_addr) +{ + assert(index < CONFIG_IEEE802154_INTERFACE_NUM); + assert(ext_addr != NULL); + ieee802154_ll_get_multipan_ext_addr(index, ext_addr); + return ESP_OK; +} + +esp_err_t esp_ieee802154_set_multipan_extended_address(esp_ieee802154_multipan_index_t index, const uint8_t *ext_addr) +{ + assert(index < CONFIG_IEEE802154_INTERFACE_NUM); + assert(ext_addr != NULL); + ieee802154_ll_set_multipan_ext_addr(index, ext_addr); + return ESP_OK; +} + +uint8_t esp_ieee802154_get_multipan_enable(void) +{ + return ieee802154_ll_get_multipan_enable_mask(); +} + +esp_err_t esp_ieee802154_set_multipan_enable(uint8_t mask) +{ + assert(mask < (1 << CONFIG_IEEE802154_INTERFACE_NUM)); + ieee802154_ll_set_multipan_enable_mask(mask); + return ESP_OK; +} + +esp_ieee802154_pending_mode_t esp_ieee802154_multipan_get_pending_mode(esp_ieee802154_multipan_index_t index) +{ + assert(index < CONFIG_IEEE802154_INTERFACE_NUM); + return ieee802154_pib_get_pending_mode(index); +} + +esp_err_t esp_ieee802154_multipan_set_pending_mode(esp_ieee802154_multipan_index_t inf_index, esp_ieee802154_pending_mode_t pending_mode) +{ + assert(inf_index < CONFIG_IEEE802154_INTERFACE_NUM); + ieee802154_pib_set_pending_mode(inf_index, pending_mode); + return ESP_OK; +} + +esp_err_t esp_ieee802154_multipan_add_pending_addr(esp_ieee802154_multipan_index_t inf_index, const uint8_t *addr, bool is_short) +{ + assert(inf_index < CONFIG_IEEE802154_INTERFACE_NUM); + return ieee802154_add_pending_addr(inf_index, addr, is_short); +} + +esp_err_t esp_ieee802154_multipan_clear_pending_addr(esp_ieee802154_multipan_index_t inf_index, const uint8_t *addr, bool is_short) +{ + assert(inf_index < CONFIG_IEEE802154_INTERFACE_NUM); + return ieee802154_clear_pending_addr(inf_index, addr, is_short); +} + +esp_err_t esp_ieee802154_multipan_reset_pending_table(esp_ieee802154_multipan_index_t inf_index, bool is_short) +{ + assert(inf_index < CONFIG_IEEE802154_INTERFACE_NUM); + ieee802154_reset_pending_table(inf_index, is_short); + return ESP_OK; +} diff --git a/components/ieee802154/include/esp_ieee802154.h b/components/ieee802154/include/esp_ieee802154.h index 02ae67f421f..f76d9c199f3 100644 --- a/components/ieee802154/include/esp_ieee802154.h +++ b/components/ieee802154/include/esp_ieee802154.h @@ -286,98 +286,6 @@ esp_err_t esp_ieee802154_get_extended_address(uint8_t *ext_addr); */ esp_err_t esp_ieee802154_set_extended_address(const uint8_t *ext_addr); -/** - * @brief Get the device PAN ID for specific interface. - * - * @param[in] index The interface index. - * - * @return The device PAN ID. - * - */ -uint16_t esp_ieee802154_get_multipan_panid(esp_ieee802154_multipan_index_t index); - -/** - * @brief Set the device PAN ID for specific interface. - * - * @param[in] index The interface index. - * @param[in] panid The device PAN ID. - * - * @return - * - ESP_OK on success. - * - ESP_FAIL on failure. - */ -esp_err_t esp_ieee802154_set_multipan_panid(esp_ieee802154_multipan_index_t index, uint16_t panid); - -/** - * @brief Get the device short address for specific interface. - * - * @param[in] index The interface index. - * - * @return The device short address. - * - */ -uint16_t esp_ieee802154_get_multipan_short_address(esp_ieee802154_multipan_index_t index); - -/** - * @brief Set the device short address for specific interface. - * - * @param[in] index The interface index. - * @param[in] short_address The device short address. - * - * @return - * - ESP_OK on success. - * - ESP_FAIL on failure. - */ -esp_err_t esp_ieee802154_set_multipan_short_address(esp_ieee802154_multipan_index_t index, uint16_t short_address); - -/** - * @brief Get the device extended address for specific interface. - * - * @param[in] index The interface index. - * @param[out] ext_addr The pointer to the device extended address. Must not be NULL. - * - * @return - * - ESP_OK on success. - * - ESP_ERR_INVALID_ARG if ext_addr is NULL. - * - ESP_FAIL on failure. - */ -esp_err_t esp_ieee802154_get_multipan_extended_address(esp_ieee802154_multipan_index_t index, uint8_t *ext_addr); - -/** - * @brief Set the device extended address for specific interface. - * - * @param[in] index The interface index. - * @param[in] ext_addr The pointer to the device extended address. Must not be NULL. - * - * @return - * - ESP_OK on success. - * - ESP_ERR_INVALID_ARG if addr is NULL. - * - ESP_FAIL on failure. - */ -esp_err_t esp_ieee802154_set_multipan_extended_address(esp_ieee802154_multipan_index_t index, const uint8_t *ext_addr); - -/** - * @brief Get the device current multipan interface enable mask. - * - * @return Current multipan interface enable mask. - * - */ -uint8_t esp_ieee802154_get_multipan_enable(void); - -/** - * @brief Enable specific interface for the device. - * - * As an example, call `esp_ieee802154_set_multipan_enable(BIT(ESP_IEEE802154_MULTIPAN_0) | BIT(ESP_IEEE802154_MULTIPAN_1));` - * to enable multipan interface 0 and 1. - * - * @param[in] mask The multipan interface bit mask. - * - * @return - * - ESP_OK on success. - * - ESP_FAIL on failure. - */ -esp_err_t esp_ieee802154_set_multipan_enable(uint8_t mask); - /** * @brief Get the device coordinator. * @@ -779,80 +687,6 @@ esp_err_t esp_ieee802154_event_callback_list_register(esp_ieee802154_event_cb_li */ esp_err_t esp_ieee802154_event_callback_list_unregister(void); -/** - * @brief Add a pending address to the multipan table for the specified interface. - * - * @note This API should be called only when the IEEE 802.15.4 subsystem is enabled. - * - * @param inf_index Index of the interface. - * @param addr Pointer to the address to add. - * @param is_short True if the address is a short address, false if extended. - * - * @return - * - ESP_OK on success. - * - ESP_FAIL on failure. - */ -esp_err_t esp_ieee802154_multipan_add_pending_addr(esp_ieee802154_multipan_index_t inf_index, const uint8_t *addr, bool is_short); - -/** - * @brief Remove a pending address from the multipan table for the specified interface. - * - * @note This API should be called only when the IEEE 802.15.4 subsystem is enabled. - * - * @param inf_index Index of the interface. - * @param addr Pointer to the address to remove. - * @param is_short True if the address is a short address, false if extended. - * - * @return - * - ESP_OK on success. - * - ESP_FAIL on failure. - */ -esp_err_t esp_ieee802154_multipan_clear_pending_addr(esp_ieee802154_multipan_index_t inf_index, const uint8_t *addr, bool is_short); - -/** - * @brief Reset the pending address table for the specified interface. - * - * @note This API clears all pending addresses of the specified type (short or extended) for the interface. - * - * @param inf_index Index of the interface. - * @param is_short True to reset short addresses, false to reset extended addresses. - * - * @return - * - ESP_OK on success. - * - ESP_FAIL on failure. - */ -esp_err_t esp_ieee802154_multipan_reset_pending_table(esp_ieee802154_multipan_index_t inf_index, bool is_short); - -/** - * @brief Get the auto frame pending mode of the specified multipan interface. - * - * @note This API returns the logical pending mode configured for a given multipan - * interface. The value is used by the ACK generation logic together with the - * per-interface pending address table. - * - * @param inf_index Index of the multipan interface. - * - * @return - * - The auto frame pending mode, refer to esp_ieee802154_pending_mode_t. - */ -esp_ieee802154_pending_mode_t esp_ieee802154_multipan_get_pending_mode(esp_ieee802154_multipan_index_t inf_index); - -/** - * @brief Set the auto frame pending mode of the specified multipan interface. - * - * @note This API configures the logical pending mode for a given multipan interface. - * The configured mode is used by the ACK generation logic together with the - * per-interface pending address table. - * - * @param inf_index Index of the multipan interface. - * @param pending_mode Pending mode to set for this interface. - * - * @return - * - ESP_OK on success. - * - ESP_FAIL on failure. - */ -esp_err_t esp_ieee802154_multipan_set_pending_mode(esp_ieee802154_multipan_index_t inf_index, esp_ieee802154_pending_mode_t pending_mode); - #ifdef __cplusplus } #endif diff --git a/components/ieee802154/include/esp_ieee802154_multipan.h b/components/ieee802154/include/esp_ieee802154_multipan.h new file mode 100644 index 00000000000..f49da2a4b87 --- /dev/null +++ b/components/ieee802154/include/esp_ieee802154_multipan.h @@ -0,0 +1,187 @@ +/* + * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include "sdkconfig.h" +#include "esp_err.h" +#include "esp_ieee802154_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Get the device PAN ID for specific interface. + * + * @param[in] index The interface index. + * + * @return The device PAN ID. + * + */ +uint16_t esp_ieee802154_get_multipan_panid(esp_ieee802154_multipan_index_t index); + +/** + * @brief Set the device PAN ID for specific interface. + * + * @param[in] index The interface index. + * @param[in] panid The device PAN ID. + * + * @return + * - ESP_OK on success. + * - ESP_FAIL on failure. + */ +esp_err_t esp_ieee802154_set_multipan_panid(esp_ieee802154_multipan_index_t index, uint16_t panid); + +/** + * @brief Get the device short address for specific interface. + * + * @param[in] index The interface index. + * + * @return The device short address. + * + */ +uint16_t esp_ieee802154_get_multipan_short_address(esp_ieee802154_multipan_index_t index); + +/** + * @brief Set the device short address for specific interface. + * + * @param[in] index The interface index. + * @param[in] short_address The device short address. + * + * @return + * - ESP_OK on success. + * - ESP_FAIL on failure. + */ +esp_err_t esp_ieee802154_set_multipan_short_address(esp_ieee802154_multipan_index_t index, uint16_t short_address); + +/** + * @brief Get the device extended address for specific interface. + * + * @param[in] index The interface index. + * @param[out] ext_addr The pointer to the device extended address. Must not be NULL. + * + * @return + * - ESP_OK on success. + * - ESP_ERR_INVALID_ARG if ext_addr is NULL. + * - ESP_FAIL on failure. + */ +esp_err_t esp_ieee802154_get_multipan_extended_address(esp_ieee802154_multipan_index_t index, uint8_t *ext_addr); + +/** + * @brief Set the device extended address for specific interface. + * + * @param[in] index The interface index. + * @param[in] ext_addr The pointer to the device extended address. Must not be NULL. + * + * @return + * - ESP_OK on success. + * - ESP_ERR_INVALID_ARG if addr is NULL. + * - ESP_FAIL on failure. + */ +esp_err_t esp_ieee802154_set_multipan_extended_address(esp_ieee802154_multipan_index_t index, const uint8_t *ext_addr); + +/** + * @brief Get the device current multipan interface enable mask. + * + * @return Current multipan interface enable mask. + * + */ +uint8_t esp_ieee802154_get_multipan_enable(void); + +/** + * @brief Enable specific interface for the device. + * + * As an example, call `esp_ieee802154_set_multipan_enable(BIT(ESP_IEEE802154_MULTIPAN_0) | BIT(ESP_IEEE802154_MULTIPAN_1));` + * to enable multipan interface 0 and 1. + * + * @param[in] mask The multipan interface bit mask. + * + * @return + * - ESP_OK on success. + * - ESP_FAIL on failure. + */ +esp_err_t esp_ieee802154_set_multipan_enable(uint8_t mask); + +/** + * @brief Add a pending address to the multipan table for the specified interface. + * + * @note This API should be called only when the IEEE 802.15.4 subsystem is enabled. + * + * @param inf_index Index of the interface. + * @param addr Pointer to the address to add. + * @param is_short True if the address is a short address, false if extended. + * + * @return + * - ESP_OK on success. + * - ESP_FAIL on failure. + */ +esp_err_t esp_ieee802154_multipan_add_pending_addr(esp_ieee802154_multipan_index_t inf_index, const uint8_t *addr, bool is_short); + +/** + * @brief Remove a pending address from the multipan table for the specified interface. + * + * @note This API should be called only when the IEEE 802.15.4 subsystem is enabled. + * + * @param inf_index Index of the interface. + * @param addr Pointer to the address to remove. + * @param is_short True if the address is a short address, false if extended. + * + * @return + * - ESP_OK on success. + * - ESP_FAIL on failure. + */ +esp_err_t esp_ieee802154_multipan_clear_pending_addr(esp_ieee802154_multipan_index_t inf_index, const uint8_t *addr, bool is_short); + +/** + * @brief Reset the pending address table for the specified interface. + * + * @note This API clears all pending addresses of the specified type (short or extended) for the interface. + * + * @param inf_index Index of the interface. + * @param is_short True to reset short addresses, false to reset extended addresses. + * + * @return + * - ESP_OK on success. + * - ESP_FAIL on failure. + */ +esp_err_t esp_ieee802154_multipan_reset_pending_table(esp_ieee802154_multipan_index_t inf_index, bool is_short); + +/** + * @brief Get the auto frame pending mode of the specified multipan interface. + * + * @note This API returns the logical pending mode configured for a given multipan + * interface. The value is used by the ACK generation logic together with the + * per-interface pending address table. + * + * @param inf_index Index of the multipan interface. + * + * @return + * - Current pending mode of type refer to esp_ieee802154_pending_mode_t + */ +esp_ieee802154_pending_mode_t esp_ieee802154_multipan_get_pending_mode(esp_ieee802154_multipan_index_t inf_index); + +/** + * @brief Set the auto frame pending mode of the specified multipan interface. + * + * @note This API configures the logical pending mode for a given multipan interface. + * The configured mode is used by the ACK generation logic together with the + * per-interface pending address table. + * + * @param inf_index Index of the multipan interface. + * @param pending_mode Pending mode to set for this interface. + * + * @return + * - ESP_OK on success. + * - ESP_FAIL on failure. + */ +esp_err_t esp_ieee802154_multipan_set_pending_mode(esp_ieee802154_multipan_index_t inf_index, esp_ieee802154_pending_mode_t pending_mode); + +#ifdef __cplusplus +} +#endif diff --git a/components/ieee802154/linker.lf b/components/ieee802154/linker.lf index f56ca9ee8fc..13c3c9f129b 100644 --- a/components/ieee802154/linker.lf +++ b/components/ieee802154/linker.lf @@ -79,9 +79,9 @@ entries: esp_ieee802154_util: ieee802154_channel_to_freq (noflash) if IEEE802154_MULTI_PAN_ENABLE = y: - esp_ieee802154: esp_ieee802154_get_multipan_extended_address (noflash) - esp_ieee802154: esp_ieee802154_get_multipan_panid (noflash) - esp_ieee802154: esp_ieee802154_get_multipan_short_address (noflash) + esp_ieee802154_multipan: esp_ieee802154_get_multipan_extended_address (noflash) + esp_ieee802154_multipan: esp_ieee802154_get_multipan_panid (noflash) + esp_ieee802154_multipan: esp_ieee802154_get_multipan_short_address (noflash) esp_ieee802154_dev: is_broadcast_addr (noflash) esp_ieee802154_dev: is_broadcast_panid (noflash) esp_ieee802154_dev: update_mpf_index (noflash)