Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arch/xtensa: unify WiFi source code for ESP32|S2|S3 #15749

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion arch/xtensa/src/common/espressif/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,12 @@ config ESPRESSIF_WIRELESS
select ESP32S2_RNG if ARCH_CHIP_ESP32S2
select ESP32S2_RT_TIMER if ARCH_CHIP_ESP32S2
select ESP32S2_TIMER0 if ARCH_CHIP_ESP32S2
depends on ARCH_CHIP_ESP32S2
select ESP32S3_RNG if ARCH_CHIP_ESP32S3
select ESP32S3_RT_TIMER if ARCH_CHIP_ESP32S3
select ESP32S3_TIMER0 if 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 @@ -524,6 +529,34 @@ config ESPRESSIF_WIFI
---help---
Enable Wi-Fi support

config ESPRESSIF_BLE
bool "BLE"
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.

config ESP_COEX_SW_COEXIST_ENABLE
bool "Software WiFi/Bluetooth/IEEE 802.15.4 coexistence"
depends on (ESPRESSIF_WIFI && ESPRESSIF_BLE)
default y
---help---
If enabled, WiFi & Bluetooth coexistence is controlled by software rather than hardware.
Recommended for heavy traffic scenarios. Both coexistence configuration options are
automatically managed, no user intervention is required.
If only Bluetooth is used, it is recommended to disable this option to reduce binary file
size.

menuconfig ESPRESSIF_WIFI_BT_COEXIST
bool "Wi-Fi and BT coexist"
default y if ESPRESSIF_WIFI && ESPRESSIF_BLE
default n
depends on ESPRESSIF_WIFI && ESPRESSIF_BLE
select ESPRESSIF_WIFI_STA_DISCONNECT_PM

menu "Wi-Fi Configuration"
depends on ESPRESSIF_WIFI

Expand Down Expand Up @@ -691,4 +724,30 @@ 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"
depends on ESPRESSIF_BLE

config ESPRESSIF_BLE_TASK_STACK_SIZE
int "Controller task stack size"
default 4096

config ESPRESSIF_BLE_TASK_PRIORITY
int "Controller task priority"
default 253

config ESPRESSIF_BLE_INTERRUPT_SAVE_STATUS
int "Number of interrupt save status"
default 3
---help---
Number of interrupt save status variables to keep track. Increase it if any related bug is found.

endmenu # BLE Configuration
22 changes: 22 additions & 0 deletions arch/xtensa/src/common/espressif/Wireless.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,35 @@
#
############################################################################

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
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)
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_ESP32),y)
EXTRA_LIBS += -lrtc
endif

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

EXTRA_LIBS += -lphy

ifeq ($(CONFIG_ESPRESSIF_WIFI),y)
Expand Down
6 changes: 6 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,9 +34,15 @@
#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
#ifdef CONFIG_ARCH_CHIP_ESP32S3
#include "esp32s3_wifi_adapter.h"
#endif

#include "esp_wifi_utils.h"
#include "esp_wireless.h"
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
6 changes: 6 additions & 0 deletions arch/xtensa/src/common/espressif/esp_wlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@

#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
#ifdef CONFIG_ARCH_CHIP_ESP32S3
# include "esp32s3_wifi_adapter.h"
#endif

#ifndef __ASSEMBLY__

Expand Down
Loading