Skip to content

Commit

Permalink
xtensa/esp32: use common Espressif wireless source
Browse files Browse the repository at this point in the history
Update the wireless symbols from ESP32_* to ESPRESSIF_* for using common layer.
Remove ESP32 specific WiFi files and edit build system to use common layer.

Signed-off-by: Filipe Cavalcanti <[email protected]>
  • Loading branch information
fdcavalcanti committed Feb 25, 2025
1 parent 96de2e2 commit d6d295d
Show file tree
Hide file tree
Showing 69 changed files with 369 additions and 5,181 deletions.
15 changes: 13 additions & 2 deletions arch/xtensa/src/common/espressif/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,9 @@ config ESPRESSIF_WIRELESS
select ESP32S3_RNG if ARCH_CHIP_ESP32S3
select ESP32S3_RT_TIMER if ARCH_CHIP_ESP32S3
select ESP32S3_TIMER0 if ARCH_CHIP_ESP32S3
depends on ARCH_CHIP_ESP32S2 || ARCH_CHIP_ESP32S3
select ESP32_RNG if ARCH_CHIP_ESP32
select ESP32_RT_TIMER if ARCH_CHIP_ESP32
select ESP32_TIMER0 if ARCH_CHIP_ESP32
---help---
Enable Wireless support

Expand All @@ -529,9 +531,11 @@ config ESPRESSIF_WIFI

config ESPRESSIF_BLE
bool "BLE"
depends on ARCH_CHIP_ESP32S3
depends on ARCH_CHIP_ESP32S3 || ARCH_CHIP_ESP32
default n
select ESPRESSIF_WIRELESS
select BLUETOOTH_TXCMD_PINNED_TO_CORE if SMP && ARCH_CHIP_ESP32
select BLUETOOTH_CNTRL_HOST_FLOW_DISABLE if ARCH_CHIP_ESP32
---help---
Enable BLE support.

Expand Down Expand Up @@ -720,6 +724,13 @@ config ESPRESSIF_WIFI_LISTEN_INTERVAL
For example, if beacon interval is 100 ms and listen interval is 3, the interval for station to listen
to beacon is 300 ms.

config ESPRESSIF_WIFI_WLAN_BUFFER_OPTIMIZATION
bool "Enable optimization of WLAN driver buffer"
default n
depends on ARCH_CHIP_ESP32
---help---
Enable optimization of WLAN memory

endmenu # ESPRESSIF_WIFI

menu "BLE Configuration"
Expand Down
20 changes: 15 additions & 5 deletions arch/xtensa/src/common/espressif/Wireless.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,40 @@
#
############################################################################

ifeq ($(CONFIG_ARCH_CHIP_ESP32),y)
INCLUDES += $(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)include$(DELIM)$(CHIP_SERIES)$(DELIM)include
endif
ifeq ($(CONFIG_ARCH_CHIP_ESP32S3),y)
INCLUDES += $(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)include$(DELIM)esp32c3$(DELIM)include
INCLUDES += $(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_coex$(DELIM)include
endif
INCLUDES += $(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_coex$(DELIM)include
INCLUDES += $(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)$(CHIP_SERIES)$(DELIM)include
INCLUDES += $(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)nuttx$(DELIM)$(CHIP_SERIES)$(DELIM)include
INCLUDES += $(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)nuttx$(DELIM)include$(DELIM)esp_wifi

ifeq ($(CONFIG_ARCH_CHIP_ESP32),y)
EXTRA_LIBPATHS += -L $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)controller$(DELIM)lib_esp32$(DELIM)$(CHIP_SERIES)
endif
ifeq ($(CONFIG_ARCH_CHIP_ESP32S3),y)
EXTRA_LIBPATHS += -L $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)bt$(DELIM)controller$(DELIM)lib_esp32c3_family$(DELIM)$(CHIP_SERIES)
EXTRA_LIBPATHS += -L $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_coex$(DELIM)lib$(DELIM)$(CHIP_SERIES)
endif
EXTRA_LIBPATHS += -L $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_coex$(DELIM)lib$(DELIM)$(CHIP_SERIES)
EXTRA_LIBPATHS += -L $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_phy$(DELIM)lib$(DELIM)$(CHIP_SERIES)
EXTRA_LIBPATHS += -L $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_wifi$(DELIM)lib$(DELIM)$(CHIP_SERIES)

ifeq ($(CONFIG_ARCH_CHIP_ESP32S3),y)
ifeq ($(CONFIG_ARCH_CHIP_ESP32),y)
EXTRA_LIBS += -lrtc
endif

ifneq ($(CONFIG_ARCH_CHIP_ESP32S2),y)
EXTRA_LIBS += -lcoexist
endif

EXTRA_LIBS += -lphy

ifeq ($(CONFIG_ESPRESSIF_WIFI),y)
EXTRA_LIBS += -lcore -lnet80211 -lpp
endif

ifeq ($(CONFIG_WPA_WAPI_PSK),y)
EXTRA_LIBS += -lwapi
Expand Down Expand Up @@ -251,5 +263,3 @@ CHIP_CSRCS += crypto_mbedtls-rsa.c
CHIP_CSRCS += crypto_mbedtls.c
CHIP_CSRCS += tls_mbedtls.c
CHIP_CSRCS += aes-siv.c

endif
3 changes: 3 additions & 0 deletions arch/xtensa/src/common/espressif/esp_wifi_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
#include <nuttx/kmalloc.h>
#include <nuttx/wireless/wireless.h>

#ifdef CONFIG_ARCH_CHIP_ESP32
#include "esp32_wifi_adapter.h"
#endif
#ifdef CONFIG_ARCH_CHIP_ESP32S2
#include "esp32s2_wifi_adapter.h"
#endif
Expand Down
5 changes: 2 additions & 3 deletions arch/xtensa/src/common/espressif/esp_wireless.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ struct esp_wireless_priv_s
static inline void phy_digital_regs_store(void);
static inline void phy_digital_regs_load(void);
static int esp_swi_irq(int irq, void *context, void *arg);
#ifdef CONFIG_ESP32_WIFI
# if defined(CONFIG_ARCH_CHIP_ESP32) && defined(CONFIG_ESPRESSIF_WIFI)
static void esp_wifi_set_log_level(void);
#endif

Expand Down Expand Up @@ -1516,8 +1516,7 @@ int32_t esp_wifi_init(const wifi_init_config_t *config)
esp_wifi_set_sleep_wait_broadcast_data_time(wait_broadcast_data_time_us);
#endif

#if defined(CONFIG_ESP32S3_WIFI_BT_COEXIST) || \
defined(CONFIG_ESP32_WIFI_BT_COEXIST)
#if defined(CONFIG_ESPRESSIF_WIFI_BT_COEXIST)
ret = coex_init();
if (ret)
{
Expand Down
78 changes: 78 additions & 0 deletions arch/xtensa/src/common/espressif/esp_wlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ struct wlan_priv_s

/* Packet buffer cache */

#ifdef CONFIG_ESPRESSIF_WIFI_WLAN_BUFFER_OPTIMIZATION
struct wlan_pktbuf *pktbuf;
#else
struct wlan_pktbuf pktbuf[WLAN_PKTBUF_NUM];
#endif

/* RX packet queue */

Expand Down Expand Up @@ -292,6 +296,9 @@ static int wlan_ioctl(struct net_driver_s *dev, int cmd,
unsigned long arg);
#endif

static inline void wlan_free_buffer(struct wlan_priv_s *priv,
uint8_t *buffer);

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -324,6 +331,17 @@ static inline void wlan_init_buffer(struct wlan_priv_s *priv)
{
irqstate_t flags;

#ifdef CONFIG_ESPRESSIF_WIFI_WLAN_BUFFER_OPTIMIZATION
flags = spin_lock_irqsave(&priv->lock);

priv->dev.d_buf = NULL;
priv->dev.d_len = 0;

sq_init(&priv->rxb);
sq_init(&priv->txb);

spin_unlock_irqrestore(&priv->lock, flags);
#else
int i;
flags = spin_lock_irqsave(&priv->lock);

Expand All @@ -340,6 +358,40 @@ static inline void wlan_init_buffer(struct wlan_priv_s *priv)
}

spin_unlock_irqrestore(&priv->lock, flags);
#endif
}

/****************************************************************************
* Function: wlan_deinit_buffer
*
* Description:
* De-initialize the buffer list
*
* Input Parameters:
* priv - Reference to the driver state structure
*
* Returned Value:
* None.
*
****************************************************************************/

static inline void wlan_deinit_buffer(struct wlan_priv_s *priv)
{
#ifdef CONFIG_ESPRESSIF_WIFI_WLAN_BUFFER_OPTIMIZATION
struct wlan_pktbuf *pktbuf;
while ((pktbuf = (struct wlan_pktbuf *)wlan_recvframe(priv)) != NULL)
{
wlan_free_buffer(priv, (void *)pktbuf->buffer);
}

while ((pktbuf = (struct wlan_pktbuf *)wlan_txframe(priv)) != NULL)
{
wlan_free_buffer(priv, (void *)pktbuf->buffer);
}

sq_init(&priv->rxb);
sq_init(&priv->txb);
#endif
}

/****************************************************************************
Expand All @@ -360,6 +412,15 @@ static inline struct wlan_pktbuf *wlan_alloc_buffer(struct wlan_priv_s *priv)
{
struct wlan_pktbuf *pktbuf = NULL;

#ifdef CONFIG_ESPRESSIF_WIFI_WLAN_BUFFER_OPTIMIZATION
struct mallinfo info = kmm_mallinfo();
if (info.fordblks < MINIMUM_HEAP_SIZE)
{
return NULL;
}

pktbuf = kmm_malloc(sizeof(struct wlan_pktbuf) + WLAN_BUF_SIZE);
#else
sq_entry_t *entry;
irqstate_t flags = spin_lock_irqsave(&priv->lock);

Expand All @@ -371,6 +432,7 @@ static inline struct wlan_pktbuf *wlan_alloc_buffer(struct wlan_priv_s *priv)

spin_unlock_irqrestore(&priv->lock, flags);

#endif
return pktbuf;
}

Expand All @@ -394,12 +456,17 @@ static inline void wlan_free_buffer(struct wlan_priv_s *priv,
{
struct wlan_pktbuf *pktbuf;

#ifdef CONFIG_ESPRESSIF_WIFI_WLAN_BUFFER_OPTIMIZATION
pktbuf = container_of(buffer, struct wlan_pktbuf, buffer);
kmm_free(pktbuf);
#else
irqstate_t flags = spin_lock_irqsave(&priv->lock);

pktbuf = container_of(buffer, struct wlan_pktbuf, buffer);
sq_addlast(&pktbuf->entry, &priv->freeb);

spin_unlock_irqrestore(&priv->lock, flags);
#endif
}

/****************************************************************************
Expand Down Expand Up @@ -1098,6 +1165,9 @@ static int wlan_ifup(struct net_driver_s *dev)
ret = priv->ops->start();
if (ret < 0)
{
#ifdef CONFIG_ARCH_CHIP_ESP32
wlan_deinit_buffer(priv);
#endif
net_unlock();
nerr("ERROR: Failed to start Wi-Fi ret=%d\n", ret);
return ret;
Expand All @@ -1114,6 +1184,14 @@ static int wlan_ifup(struct net_driver_s *dev)
}

++g_callback_register_ref;

#ifdef CONFIG_ARCH_CHIP_ESP32
/* We can make sure that the WLAN TX and RX are not doing, because
* the process is in "net_lock()"
*/

wlan_deinit_buffer(priv);
#endif
net_unlock();

return OK;
Expand Down
3 changes: 3 additions & 0 deletions arch/xtensa/src/common/espressif/esp_wlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

#include <nuttx/config.h>

#ifdef CONFIG_ARCH_CHIP_ESP32
# include "esp32_wifi_adapter.h"
#endif
#ifdef CONFIG_ARCH_CHIP_ESP32S2
# include "esp32s2_wifi_adapter.h"
#endif
Expand Down
Loading

0 comments on commit d6d295d

Please sign in to comment.