Skip to content

Commit

Permalink
ieee802154: update files for Zephyr support
Browse files Browse the repository at this point in the history
FreeRTOS-related code (e.g. locks) are replaced with Zephyr-specific
equivalents.

Signed-off-by: Martin Jäger <martin@libre.solar>
  • Loading branch information
martinjaeger committed Dec 11, 2024
1 parent 3efa906 commit bd1fb9c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 21 deletions.
13 changes: 7 additions & 6 deletions components/esp_phy/src/btbb_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
#include <stdint.h>
#include "esp_check.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "esp_private/btbb.h"

#include <zephyr/kernel.h>

#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;

Expand Down Expand Up @@ -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
Expand All @@ -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);
}
24 changes: 11 additions & 13 deletions components/ieee802154/driver/esp_ieee802154_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <string.h>
#include "sdkconfig.h"
#include "freertos/portmacro.h"
#include "soc/periph_defs.h"
#include "soc/soc.h"
#include "soc/ieee802154_periph.h"
Expand Down Expand Up @@ -39,6 +38,9 @@
#endif // SOC_PM_RETENTION_HAS_CLOCK_BUG
#endif // CONFIG_PM_ENABLE

#include <zephyr/kernel.h>
#include <zephyr/drivers/interrupt_controller/intc_esp32c3.h>

static bool s_rf_closed = true;
#define CCA_DETECTION_TIME 8

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand All @@ -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;
}
Expand Down
30 changes: 28 additions & 2 deletions zephyr/esp32c6/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

0 comments on commit bd1fb9c

Please sign in to comment.