From bd1fb9c65ea712827c25816610afdad9342ef8cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4ger?= Date: Tue, 10 Dec 2024 13:08:41 +0100 Subject: [PATCH] ieee802154: update files for Zephyr support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FreeRTOS-related code (e.g. locks) are replaced with Zephyr-specific equivalents. Signed-off-by: Martin Jäger --- components/esp_phy/src/btbb_init.c | 13 ++++---- .../ieee802154/driver/esp_ieee802154_dev.c | 24 +++++++-------- zephyr/esp32c6/CMakeLists.txt | 30 +++++++++++++++++-- 3 files changed, 46 insertions(+), 21 deletions(-) diff --git a/components/esp_phy/src/btbb_init.c b/components/esp_phy/src/btbb_init.c index 41d78dd83a..114c2f2bde 100644 --- a/components/esp_phy/src/btbb_init.c +++ b/components/esp_phy/src/btbb_init.c @@ -7,12 +7,13 @@ #include #include "esp_check.h" #include "esp_log.h" -#include "freertos/FreeRTOS.h" #include "esp_private/btbb.h" +#include + #define BTBB_ENABLE_VERSION_PRINT 1 -static _lock_t s_btbb_access_lock; +static struct k_spinlock s_btbb_access_lock; /* Reference count of enabling BT BB */ static uint8_t s_btbb_access_ref = 0; @@ -57,7 +58,7 @@ static void btbb_sleep_retention_deinit(void) void esp_btbb_enable(void) { - _lock_acquire(&s_btbb_access_lock); + k_spinlock_key_t key = k_spin_lock(&s_btbb_access_lock); if (s_btbb_access_ref == 0) { bt_bb_v2_init_cmplx(BTBB_ENABLE_VERSION_PRINT); #if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE @@ -77,16 +78,16 @@ void esp_btbb_enable(void) #endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE } s_btbb_access_ref++; - _lock_release(&s_btbb_access_lock); + k_spin_unlock(&s_btbb_access_lock, key); } void esp_btbb_disable(void) { - _lock_acquire(&s_btbb_access_lock); + k_spinlock_key_t key = k_spin_lock(&s_btbb_access_lock); if (s_btbb_access_ref && (--s_btbb_access_ref == 0)) { #if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE btbb_sleep_retention_deinit(); #endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE } - _lock_release(&s_btbb_access_lock); + k_spin_unlock(&s_btbb_access_lock, key); } diff --git a/components/ieee802154/driver/esp_ieee802154_dev.c b/components/ieee802154/driver/esp_ieee802154_dev.c index b91eb11a89..27b0c29ea0 100644 --- a/components/ieee802154/driver/esp_ieee802154_dev.c +++ b/components/ieee802154/driver/esp_ieee802154_dev.c @@ -6,7 +6,6 @@ #include #include "sdkconfig.h" -#include "freertos/portmacro.h" #include "soc/periph_defs.h" #include "soc/soc.h" #include "soc/ieee802154_periph.h" @@ -39,6 +38,9 @@ #endif // SOC_PM_RETENTION_HAS_CLOCK_BUG #endif // CONFIG_PM_ENABLE +#include +#include + static bool s_rf_closed = true; #define CCA_DETECTION_TIME 8 @@ -68,8 +70,8 @@ static bool s_needs_next_operation = false; static uint8_t s_rx_index = 0; static uint8_t s_enh_ack_frame[128]; static uint8_t s_recent_rx_frame_info_index; -static portMUX_TYPE s_ieee802154_spinlock = portMUX_INITIALIZER_UNLOCKED; -static intr_handle_t s_ieee802154_isr_handle = NULL; +static struct k_spinlock s_ieee802154_spinlock; +static k_spinlock_key_t s_ieee802154_key; static esp_err_t ieee802154_sleep_init(void); static esp_err_t ieee802154_sleep_deinit(void); @@ -640,15 +642,15 @@ static IRAM_ATTR void isr_handle_ed_done(void) IEEE802154_STATIC IRAM_ATTR void ieee802154_enter_critical(void) { - portENTER_CRITICAL(&s_ieee802154_spinlock); + s_ieee802154_key = k_spin_lock(&s_ieee802154_spinlock); } IEEE802154_STATIC IRAM_ATTR void ieee802154_exit_critical(void) { - portEXIT_CRITICAL(&s_ieee802154_spinlock); + k_spin_unlock(&s_ieee802154_spinlock, s_ieee802154_key); } -IEEE802154_NOINLINE static void ieee802154_isr(void *arg) +IEEE802154_NOINLINE static void ieee802154_isr(const void *arg) { ieee802154_enter_critical(); ieee802154_ll_events events = ieee802154_ll_get_events(); @@ -810,7 +812,7 @@ esp_err_t ieee802154_mac_init(void) ieee802154_set_state(IEEE802154_STATE_IDLE); // TODO: Add flags for IEEE802154 ISR allocating. TZ-102 - ret = esp_intr_alloc(ieee802154_periph.irq_id, 0, ieee802154_isr, NULL, &s_ieee802154_isr_handle); + ret = esp_intr_alloc(ieee802154_periph.irq_id, 0, ieee802154_isr, NULL, NULL); ESP_RETURN_ON_FALSE(ret == ESP_OK, ESP_FAIL, IEEE802154_TAG, "IEEE802154 MAC init failed"); ESP_RETURN_ON_FALSE(ieee802154_sleep_init() == ESP_OK, ESP_FAIL, IEEE802154_TAG, "IEEE802154 MAC sleep init failed"); @@ -820,12 +822,8 @@ esp_err_t ieee802154_mac_init(void) esp_err_t ieee802154_mac_deinit(void) { - esp_err_t ret = ESP_OK; - if (s_ieee802154_isr_handle) { - ret = esp_intr_free(s_ieee802154_isr_handle); - s_ieee802154_isr_handle = NULL; - ESP_RETURN_ON_FALSE(ret == ESP_OK, ESP_FAIL, IEEE802154_TAG, "IEEE802154 MAC ISR deinit failed"); - } + esp_err_t ret = esp_intr_disable(ieee802154_periph.irq_id); + ESP_RETURN_ON_FALSE(ret == ESP_OK, ESP_FAIL, IEEE802154_TAG, "IEEE802154 MAC ISR deinit failed"); ESP_RETURN_ON_FALSE(ieee802154_sleep_deinit() == ESP_OK, ESP_FAIL, IEEE802154_TAG, "IEEE802154 MAC sleep deinit failed"); return ret; } diff --git a/zephyr/esp32c6/CMakeLists.txt b/zephyr/esp32c6/CMakeLists.txt index 6a1e9c8a36..b814657801 100644 --- a/zephyr/esp32c6/CMakeLists.txt +++ b/zephyr/esp32c6/CMakeLists.txt @@ -109,6 +109,9 @@ if(CONFIG_SOC_SERIES_ESP32C6) ../../components/wpa_supplicant/src/eap_peer ../../components/mbedtls/port/include + ../../components/ieee802154/include + ../../components/ieee802154/private_include + ../port/include/boot ) @@ -304,8 +307,8 @@ if(CONFIG_SOC_SERIES_ESP32C6) ../../components/hal/ledc_hal.c ) - ## shared WIFI/BT resources - if (CONFIG_BT OR CONFIG_WIFI_ESP32) + ## shared WIFI/BT/IEEE802154 resources + if (CONFIG_BT OR CONFIG_WIFI_ESP32 OR CONFIG_IEEE802154) zephyr_sources( ../../components/esp_phy/src/phy_init.c ../../components/esp_phy/src/lib_printf.c @@ -556,6 +559,29 @@ if(CONFIG_SOC_SERIES_ESP32C6) endif() + ## IEEE 802.15.4 definitions + if (CONFIG_IEEE802154) + zephyr_sources( + ../../components/esp_phy/src/btbb_init.c + ../../components/soc/${CONFIG_SOC_SERIES}/ieee802154_periph.c + ../../components/ieee802154/esp_ieee802154.c + ../../components/ieee802154/driver/esp_ieee802154_ack.c + ../../components/ieee802154/driver/esp_ieee802154_dev.c + ../../components/ieee802154/driver/esp_ieee802154_frame.c + ../../components/ieee802154/driver/esp_ieee802154_pib.c + ../../components/ieee802154/driver/esp_ieee802154_util.c + ../../components/ieee802154/driver/esp_ieee802154_sec.c + ../../components/ieee802154/driver/esp_ieee802154_timer.c + ) + + zephyr_compile_definitions(CONFIG_IEEE802154_ENABLED) + + zephyr_link_libraries( + btbb + -L${CMAKE_CURRENT_SOURCE_DIR}/../blobs/lib/${CONFIG_SOC_SERIES} + ) + endif() + zephyr_link_libraries_ifdef(CONFIG_NEWLIB_LIBC c) endif()