From 98ca108be5e44b9fe5731e48ff4d95e9a748ecdc Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Mon, 16 Dec 2019 01:47:44 +0100 Subject: [PATCH] cpu/esp8266: move esp_wifi to cpu/esp_common --- cpu/esp8266/Makefile | 4 ---- cpu/esp8266/esp-wifi/Makefile | 7 ------ cpu/esp_common/Makefile | 4 ++++ cpu/esp_common/Makefile.include | 7 +++++- cpu/esp_common/esp-now/doc.txt | 2 ++ cpu/esp_common/esp-wifi/Makefile | 9 ++++++++ cpu/{esp8266 => esp_common}/esp-wifi/doc.txt | 12 +++++----- .../esp-wifi/esp_wifi_gnrc.c | 8 ++++--- .../esp-wifi/esp_wifi_netdev.c | 22 +++++++------------ .../esp-wifi/esp_wifi_netdev.h | 4 ++-- .../esp-wifi/esp_wifi_params.h | 6 ++--- 11 files changed, 46 insertions(+), 39 deletions(-) delete mode 100644 cpu/esp8266/esp-wifi/Makefile create mode 100644 cpu/esp_common/esp-wifi/Makefile rename cpu/{esp8266 => esp_common}/esp-wifi/doc.txt (79%) rename cpu/{esp8266 => esp_common}/esp-wifi/esp_wifi_gnrc.c (90%) rename cpu/{esp8266 => esp_common}/esp-wifi/esp_wifi_netdev.c (97%) rename cpu/{esp8266 => esp_common}/esp-wifi/esp_wifi_netdev.h (93%) rename cpu/{esp8266 => esp_common}/esp-wifi/esp_wifi_params.h (90%) diff --git a/cpu/esp8266/Makefile b/cpu/esp8266/Makefile index ebb63f918f..a332efe228 100644 --- a/cpu/esp8266/Makefile +++ b/cpu/esp8266/Makefile @@ -8,10 +8,6 @@ DIRS += periph DIRS += sdk DIRS += vendor -ifneq (, $(filter esp_wifi, $(USEMODULE))) - DIRS += esp-wifi -endif - INCLUDES += -I$(ESP8266_RTOS_SDK_DIR)/components/esp8266/include/internal include $(RIOTBASE)/Makefile.base diff --git a/cpu/esp8266/esp-wifi/Makefile b/cpu/esp8266/esp-wifi/Makefile deleted file mode 100644 index 1b6125f2d9..0000000000 --- a/cpu/esp8266/esp-wifi/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -MODULE=esp_wifi - -# we have to do it in that way to avoid that pkg/lwip is found first -CFLAGS += -I$(ESP8266_RTOS_SDK_DIR)/components/lwip/lwip/src/include -CFLAGS += -I$(ESP8266_RTOS_SDK_DIR)/components/lwip/port/esp8266/include/ - -include $(RIOTBASE)/Makefile.base diff --git a/cpu/esp_common/Makefile b/cpu/esp_common/Makefile index 507c89092f..98aa75ff8e 100644 --- a/cpu/esp_common/Makefile +++ b/cpu/esp_common/Makefile @@ -10,4 +10,8 @@ ifneq (,$(filter esp_now,$(USEMODULE))) DIRS += esp-now endif +ifneq (,$(filter esp_wifi,$(USEMODULE))) + DIRS += esp-wifi +endif + include $(RIOTBASE)/Makefile.base diff --git a/cpu/esp_common/Makefile.include b/cpu/esp_common/Makefile.include index 87d0483589..5e95922473 100644 --- a/cpu/esp_common/Makefile.include +++ b/cpu/esp_common/Makefile.include @@ -97,7 +97,12 @@ ifneq (,$(filter esp_wifi esp_now esp_eth,$(USEMODULE))) CFLAGS += -DSCHED_PRIO_LEVELS=32 endif -# lwIP thread priority has to be lower than that of ESP hardware driver threads +ifneq (,$(filter esp_wifi esp_now esp_eth,$(USEMODULE))) + INCLUDES += -I$(RIOTCPU)/esp_common/esp-wifi +endif + +# The threads for handling the ESP hardware have the priorities from 2 to 4. +# The priority of lwIP TCPIP thread should be lower than these priorities. ifneq (,$(filter lwip,$(USEMODULE))) CFLAGS += -DTCPIP_THREAD_PRIO=5 endif diff --git a/cpu/esp_common/esp-now/doc.txt b/cpu/esp_common/esp-now/doc.txt index 63ddf45019..61cd86e9f5 100644 --- a/cpu/esp_common/esp-now/doc.txt +++ b/cpu/esp_common/esp-now/doc.txt @@ -9,6 +9,8 @@ /** * @defgroup cpu_esp_common_esp_now ESP-NOW netdev interface * @ingroup cpu_esp_common + * @ingroup cpu_esp32 + * @ingroup cpu_esp8266 * @brief WiFi based ESP-NOW network device driver * * @author Gunar Schorcht diff --git a/cpu/esp_common/esp-wifi/Makefile b/cpu/esp_common/esp-wifi/Makefile new file mode 100644 index 0000000000..c92f98eb6d --- /dev/null +++ b/cpu/esp_common/esp-wifi/Makefile @@ -0,0 +1,9 @@ +MODULE=esp_wifi + +ifeq (esp8266,$(CPU)) + # we have to do it in that way to avoid that pkg/lwip is found first + CFLAGS += -I$(ESP8266_RTOS_SDK_DIR)/components/lwip/lwip/src/include + CFLAGS += -I$(ESP8266_RTOS_SDK_DIR)/components/lwip/port/esp8266/include/ +endif + +include $(RIOTBASE)/Makefile.base diff --git a/cpu/esp8266/esp-wifi/doc.txt b/cpu/esp_common/esp-wifi/doc.txt similarity index 79% rename from cpu/esp8266/esp-wifi/doc.txt rename to cpu/esp_common/esp-wifi/doc.txt index 97031d3a76..d04109e767 100644 --- a/cpu/esp8266/esp-wifi/doc.txt +++ b/cpu/esp_common/esp-wifi/doc.txt @@ -7,14 +7,16 @@ */ /** - * @defgroup cpu_esp8266_esp_wifi ESP8266 WiFi netdev interface + * @defgroup cpu_esp_common_esp_wifi ESP-WiFi netdev interface + * @ingroup cpu_esp_common + * @ingroup cpu_esp32 * @ingroup cpu_esp8266 - * @brief Network device driver for the ESP8266 WiFi interface + * @brief Network device driver for the ESP SoC WiFi interface * * @author Gunar Schorcht -This module realizes a `netdev` interface for the built-in WiFi interface -of ESP8266. To enable the WiFi interface, module `esp_wifi` has to be used. +This module realizes a `netdev` interface for the built-in WiFi interface of +ESP SoCs. To enable the WiFi interface, module `esp_wifi` has to be used. Furthermore, the following configuration parameters have to be defined: Configuration Parameter | Description @@ -34,7 +36,7 @@ make -C examples/gnrc_networking BOARD=... ``` @note The Wifi network interface (module `esp_wifi`) and the -\ref esp8266_esp_now_network_interface "ESP-NOW network interface" (module `esp_now`) +ESP-NOW network interface (module `esp_now`) can be used simultaneously, for example, to realize a border router for a mesh network which uses ESP-NOW. */ diff --git a/cpu/esp8266/esp-wifi/esp_wifi_gnrc.c b/cpu/esp_common/esp-wifi/esp_wifi_gnrc.c similarity index 90% rename from cpu/esp8266/esp-wifi/esp_wifi_gnrc.c rename to cpu/esp_common/esp-wifi/esp_wifi_gnrc.c index 157dd4cc28..56e1fcf947 100644 --- a/cpu/esp8266/esp-wifi/esp_wifi_gnrc.c +++ b/cpu/esp_common/esp-wifi/esp_wifi_gnrc.c @@ -7,20 +7,22 @@ */ /** - * @ingroup cpu_esp8266_esp_wifi + * @ingroup cpu_esp_common_esp_wifi * @{ * * @file - * @brief GNRC network interface part for ESP8266 WiFi interface + * @brief GNRC network interface part for ESP WiFi interface * * @author Gunar Schorcht */ #if defined(MODULE_ESP_WIFI) && defined(MODULE_GNRC_NETIF_ETHERNET) +#include "net/ethernet.h" +#include "net/gnrc/netif/ethernet.h" + #include "esp_wifi_params.h" #include "esp_wifi_netdev.h" -#include "net/gnrc/netif/ethernet.h" /** the only ESP WiFi device */ extern esp_wifi_netdev_t _esp_wifi_dev; diff --git a/cpu/esp8266/esp-wifi/esp_wifi_netdev.c b/cpu/esp_common/esp-wifi/esp_wifi_netdev.c similarity index 97% rename from cpu/esp8266/esp-wifi/esp_wifi_netdev.c rename to cpu/esp_common/esp-wifi/esp_wifi_netdev.c index 388ea8a059..c635c8ede2 100644 --- a/cpu/esp8266/esp-wifi/esp_wifi_netdev.c +++ b/cpu/esp_common/esp-wifi/esp_wifi_netdev.c @@ -7,11 +7,11 @@ */ /** - * @ingroup cpu_esp8266_esp_wifi + * @ingroup cpu_esp_common_esp_wifi * @{ * * @file - * @brief Network device driver for the ESP8266 WiFi interface + * @brief Network device driver for the ESP SoCs WiFi interface * * @author Gunar Schorcht */ @@ -22,9 +22,6 @@ #include #include -#include "net/gnrc/netif/ethernet.h" -#include "net/gnrc/netif/raw.h" -#include "net/gnrc.h" #include "net/ethernet.h" #include "net/netdev/eth.h" #include "od.h" @@ -50,9 +47,6 @@ #include "debug.h" #include "log.h" -#define SYSTEM_EVENT_WIFI_RX_DONE (SYSTEM_EVENT_MAX + 3) -#define SYSTEM_EVENT_WIFI_TX_DONE (SYSTEM_EVENT_MAX + 4) - #define ESP_WIFI_DEBUG(f, ...) \ DEBUG("[esp_wifi] %s: " f "\n", __func__, ## __VA_ARGS__) @@ -77,7 +71,7 @@ /** * The SDK interface of the WiFi module uses the lwIP `pbuf` structure for * packets sent to and received from the WiFi interface. For compatibility - * reasons with the binary SDK libraries we need to incclude the SDK lwIP + * reasons with the binary SDK libraries we need to include the SDK lwIP * `pbuf` header here. * * To avoid compilation errors, we need to undefine all our pkg/lwIP settings @@ -321,9 +315,8 @@ esp_err_t _esp_wifi_rx_cb(void *buffer, uint16_t len, void *eb) ESP_WIFI_DEBUG("buf=%p len=%d eb=%p", buffer, len, eb); /* - * The ring buffer uses a single byte for the pkt length, followed by the mac address, - * followed by the actual packet data. The MTU for ESP-NOW is 250 bytes, so len will never - * exceed the limits of a byte as the mac address length is not included. + * The ring buffer uses two bytes for the pkt length, followed by the + * actual packet data. */ if (ringbuffer_get_free(&_esp_wifi_dev.rx_buf) < len + sizeof(uint16_t)) { ESP_WIFI_DEBUG("buffer full, dropping incoming packet of %d bytes", len); @@ -453,7 +446,7 @@ static esp_err_t IRAM_ATTR _esp_system_event_handler(void *ctx, system_event_t * else if (reason <= REASON_HANDSHAKE_TIMEOUT) { reason_str = _esp_wifi_disc_reasons[reason - INDEX_BEACON_TIMEOUT]; } - ESP_WIFI_LOG_INFO("Wifi disconnected from ssid %s, reason %d (%s)", + ESP_WIFI_LOG_INFO("WiFi disconnected from ssid %s, reason %d (%s)", event->event_info.disconnected.ssid, event->event_info.disconnected.reason, reason_str); @@ -754,7 +747,7 @@ void esp_wifi_setup (esp_wifi_netdev_t* dev) #ifndef MODULE_ESP_NOW /* if module esp_now is used, the following part is already done */ -#if MCU_ESP32 +#ifdef MCU_ESP32 extern portMUX_TYPE g_intr_lock_mux; mutex_init(&g_intr_lock_mux); #endif @@ -820,5 +813,6 @@ void esp_wifi_setup (esp_wifi_netdev_t* dev) dev->event_conn = 0; dev->event_disc = 0; } + #endif /* MODULE_ESP_WIFI */ /**@}*/ diff --git a/cpu/esp8266/esp-wifi/esp_wifi_netdev.h b/cpu/esp_common/esp-wifi/esp_wifi_netdev.h similarity index 93% rename from cpu/esp8266/esp-wifi/esp_wifi_netdev.h rename to cpu/esp_common/esp-wifi/esp_wifi_netdev.h index 21ff2b5a7f..3a04d0ffd7 100644 --- a/cpu/esp8266/esp-wifi/esp_wifi_netdev.h +++ b/cpu/esp_common/esp-wifi/esp_wifi_netdev.h @@ -7,11 +7,11 @@ */ /** - * @ingroup cpu_esp8266_esp_wifi + * @ingroup cpu_esp_common_esp_wifi * @{ * * @file - * @brief Network device driver for the ESP32 WiFi interface + * @brief Network device driver for the ESP SoCs WiFi interface * * @author Gunar Schorcht */ diff --git a/cpu/esp8266/esp-wifi/esp_wifi_params.h b/cpu/esp_common/esp-wifi/esp_wifi_params.h similarity index 90% rename from cpu/esp8266/esp-wifi/esp_wifi_params.h rename to cpu/esp_common/esp-wifi/esp_wifi_params.h index 9298c2d4a3..3ad1dc7357 100644 --- a/cpu/esp8266/esp-wifi/esp_wifi_params.h +++ b/cpu/esp_common/esp-wifi/esp_wifi_params.h @@ -7,12 +7,12 @@ */ /** - * @ingroup cpu_esp8266_esp_wifi - * @ingroup cpu_esp8266_conf + * @ingroup cpu_esp_common_esp_wifi + * @ingroup cpu_esp_common_conf * @{ * * @file - * @brief Parameters for the ESP32 WiFi netdev interface + * @brief Parameters for the ESP SoCs WiFi netdev interface * * @author Gunar Schorcht */