Jelajahi Sumber

feat(esp_coex): add external coex slave support

xiaqilin 2 tahun lalu
induk
melakukan
d2660635aa

+ 1 - 1
components/esp_coex/Kconfig

@@ -26,4 +26,4 @@ menu "Wireless Coexistence"
             This function depends on BT-off
             because currently we do not support external coex and internal coex simultaneously.
 
-endmenu  # Wi-Fi
+endmenu  # Wireless Coexistence

+ 12 - 8
components/esp_coex/include/esp_coexist.h

@@ -15,6 +15,10 @@
 extern "C" {
 #endif
 
+#define EXTERNAL_COEXIST_WIRE_1 0
+#define EXTERNAL_COEXIST_WIRE_2 1
+#define EXTERNAL_COEXIST_WIRE_3 2
+#define EXTERNAL_COEXIST_WIRE_4 3
 /**
  * @brief coex prefer value
  */
@@ -26,10 +30,10 @@ typedef enum {
 } esp_coex_prefer_t;
 
 typedef enum {
-    EXTERN_COEX_WIRE_1 = 0,
-    EXTERN_COEX_WIRE_2,
-    EXTERN_COEX_WIRE_3,
-    EXTERN_COEX_WIRE_4,
+    EXTERN_COEX_WIRE_1 = EXTERNAL_COEXIST_WIRE_1,
+    EXTERN_COEX_WIRE_2 = EXTERNAL_COEXIST_WIRE_2,
+    EXTERN_COEX_WIRE_3 = EXTERNAL_COEXIST_WIRE_3,
+    EXTERN_COEX_WIRE_4 = EXTERNAL_COEXIST_WIRE_4,
     EXTERN_COEX_WIRE_NUM,
 } external_coex_wire_t;
 
@@ -49,19 +53,19 @@ typedef enum {
 typedef struct {
     union {
         uint32_t in_pin0 __attribute__((deprecated("Use 'request' instead")));
-        gpio_num_t request; /**< request gpio signal from slave to master */
+        gpio_num_t request; /**< request gpio signal from follower to leader */
     };
     union {
         uint32_t in_pin1 __attribute__((deprecated("Use 'priority' instead")));
-        gpio_num_t priority; /**< request gpio signal priority from slave to master */
+        gpio_num_t priority; /**< request gpio signal priority from follower to leader */
     };
     union {
         uint32_t out_pin0 __attribute__((deprecated("Use 'grant' instead")));
-        gpio_num_t grant; /**< grant gpio signal from master to slave */
+        gpio_num_t grant; /**< grant gpio signal from leader to follower */
     };
     union {
         uint32_t out_pin1 __attribute__((deprecated("Use 'tx_line' instead")));
-        gpio_num_t tx_line; /**< tx_line gpio signal from master to slave, indicates whether the master's WiFi is transmitting or not*/
+        gpio_num_t tx_line; /**< tx_line gpio signal from leader to follower, indicates whether the leader's WiFi is transmitting or not*/
     };
 } esp_external_coex_gpio_set_t;
 

+ 8 - 0
components/esp_coex/include/esp_coexist_internal.h

@@ -337,6 +337,14 @@ esp_err_t esp_coex_external_set(esp_coex_pti_level_t level1,
   */
 void esp_coex_external_stop(void);
 
+/**
+ * @brief Set external coexistence wire type.
+ *
+ * @param wire_type Set external coexistence wire type.
+ *
+ */
+void esp_coex_external_set_wire_type(external_coex_wire_t wire_type);
+
 #if SOC_EXTERNAL_COEX_LEADER_TX_LINE
 /**
   * @brief     Enable external coexist tx line

+ 1 - 1
components/esp_coex/lib

@@ -1 +1 @@
-Subproject commit 37698e17a4c7fd2e0872317fc8befaac3bb10cb4
+Subproject commit 0c8196afa1593ca23c680d78950ee7014165e958

+ 1 - 1
components/esp_coex/src/coexist.c

@@ -162,7 +162,7 @@ esp_err_t esp_enable_extern_coex_gpio_pin(external_coex_wire_t wire_type, esp_ex
         ESP_LOGE(TAG, "Configure external coex with unexpected gpio pin!!!");
         return ESP_ERR_INVALID_ARG;
     }
-
+    esp_coex_external_set_wire_type(wire_type);
 #if SOC_EXTERNAL_COEX_ADVANCE
     esp_coex_external_params(g_external_coex_params, 0, 0);
 #endif

+ 1 - 1
components/ieee802154/driver/esp_ieee802154_dev.c

@@ -623,7 +623,7 @@ esp_err_t ieee802154_mac_init(void)
     ieee802154_ll_enable_rx_abort_events(BIT(IEEE802154_RX_ABORT_BY_TX_ACK_TIMEOUT - 1) | BIT(IEEE802154_RX_ABORT_BY_TX_ACK_COEX_BREAK - 1));
 
     ieee802154_ll_set_ed_sample_mode(IEEE802154_ED_SAMPLE_AVG);
-#if CONFIG_ESP_COEX_SW_COEXIST_ENABLE && !CONFIG_IEEE802154_TEST
+#if !CONFIG_IEEE802154_TEST && CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
     esp_coex_ieee802154_ack_pti_set(IEEE802154_MIDDLE);
     IEEE802154_SET_TXRX_PTI(IEEE802154_SCENE_IDLE);
 #else

+ 2 - 5
components/ieee802154/driver/esp_ieee802154_util.c

@@ -21,8 +21,7 @@ uint8_t ieee802154_channel_to_freq(uint8_t channel)
     return (channel - 11) * 5 + 3;
 }
 
-#if CONFIG_ESP_COEX_SW_COEXIST_ENABLE && !CONFIG_IEEE802154_TEST
-
+#if !CONFIG_IEEE802154_TEST && CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
 void ieee802154_set_txrx_pti(ieee802154_txrx_scene_t txrx_scene)
 {
 
@@ -42,10 +41,8 @@ void ieee802154_set_txrx_pti(ieee802154_txrx_scene_t txrx_scene)
         assert(false);
         break;
     }
-
 }
-
-#endif // CONFIG_ESP_COEX_SW_COEXIST_ENABLE && !CONFIG_IEEE802154_TEST
+#endif // !CONFIG_IEEE802154_TEST && CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
 
 // TZ-97: implement these two functions using ETM common interface
 void ieee802154_etm_channel_clear(uint32_t channel)

+ 2 - 2
components/ieee802154/private_include/esp_ieee802154_util.h

@@ -190,7 +190,7 @@ typedef enum {
     IEEE802154_SCENE_RX_AT,     /*!< IEEE802154 radio coexistence scene RX AT */
 } ieee802154_txrx_scene_t;
 
-#if CONFIG_ESP_COEX_SW_COEXIST_ENABLE && !CONFIG_IEEE802154_TEST
+#if !CONFIG_IEEE802154_TEST && CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
 
 /**
  * @brief  Set the IEEE802154 radio coexistence scene during transmitting or receiving.
@@ -206,7 +206,7 @@ void ieee802154_set_txrx_pti(ieee802154_txrx_scene_t txrx_scene);
 
 #define IEEE802154_SET_TXRX_PTI(txrx_scene)
 
-#endif // CONFIG_ESP_COEX_SW_COEXIST_ENABLE && !CONFIG_IEEE802154_TEST
+#endif // !CONFIG_IEEE802154_TEST && CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
 
 /**
  * @brief  Convert the frequence to the index of channel.

+ 29 - 0
examples/openthread/ot_br/main/Kconfig.projbuild

@@ -8,4 +8,33 @@ menu "OpenThread Border Router Example"
             SSID and PSK, and then form a Thread network automatically. Otherwise, user need
             to configure Wi-Fi and Thread manually.
 
+    menu "External coexist wire type and pin config"
+        config EXTERNAL_COEX_WIRE_TYPE
+            int "The wire_type of external coexist"
+            depends on ESP_COEX_EXTERNAL_COEXIST_ENABLE
+            default 3
+            range 0 3
+            help
+                Select wire_type for external coexist, the wire_type define in external_coex_wire_t.
+
+        config EXTERNAL_COEX_REQUEST_PIN
+            int "The number of external coexist request pin"
+            depends on ESP_COEX_EXTERNAL_COEXIST_ENABLE && (EXTERNAL_COEX_WIRE_TYPE >= 0)
+            default 0
+
+        config EXTERNAL_COEX_GRANT_PIN
+            int "The number of external coexist grant pin"
+            depends on ESP_COEX_EXTERNAL_COEXIST_ENABLE && (EXTERNAL_COEX_WIRE_TYPE >= 1)
+            default 1
+
+        config EXTERNAL_COEX_PRIORITY_PIN
+            int "The number of external coexist priority pin"
+            depends on ESP_COEX_EXTERNAL_COEXIST_ENABLE && (EXTERNAL_COEX_WIRE_TYPE >= 2)
+            default 2
+
+        config EXTERNAL_COEX_TX_LINE_PIN
+            int "The number of external coexist tx_line pin"
+            depends on ESP_COEX_EXTERNAL_COEXIST_ENABLE && (EXTERNAL_COEX_WIRE_TYPE = 3)
+            default 3
+    endmenu # External coexist wire type and pin config
 endmenu

+ 15 - 2
examples/openthread/ot_br/main/esp_ot_br.c

@@ -1,5 +1,5 @@
 /*
- * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
+ * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
  *
  * SPDX-License-Identifier: CC0-1.0
  *
@@ -32,7 +32,6 @@
 #include "esp_vfs_dev.h"
 #include "esp_vfs_eventfd.h"
 #include "esp_wifi.h"
-#include "esp_coexist.h"
 #include "mdns.h"
 #include "nvs_flash.h"
 #include "protocol_examples_common.h"
@@ -47,6 +46,15 @@
 
 #define TAG "esp_ot_br"
 
+#if CONFIG_EXTERNAL_COEX_ENABLE
+static void ot_br_external_coexist_init(void)
+{
+    esp_external_coex_gpio_set_t gpio_pin = ESP_OPENTHREAD_DEFAULT_EXTERNAL_COEX_CONFIG();
+    esp_external_coex_set_work_mode(EXTERNAL_COEX_LEADER_ROLE);
+    ESP_ERROR_CHECK(esp_enable_extern_coex_gpio_pin(CONFIG_EXTERNAL_COEX_WIRE_TYPE, gpio_pin));
+}
+#endif /* CONFIG_EXTERNAL_COEX_ENABLE */
+
 static void ot_task_worker(void *aContext)
 {
     esp_openthread_platform_config_t config = {
@@ -118,6 +126,11 @@ void app_main(void)
     ESP_ERROR_CHECK(esp_coex_wifi_i154_enable());
 #else
     ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE));
+
+#if CONFIG_EXTERNAL_COEX_ENABLE
+    ot_br_external_coexist_init();
+#endif // CONFIG_EXTERNAL_COEX_ENABLE
+
 #endif
     esp_openthread_set_backbone_netif(get_example_netif());
 #else

+ 32 - 2
examples/openthread/ot_br/main/esp_ot_config.h

@@ -1,5 +1,5 @@
 /*
- * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
+ * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
  *
  * SPDX-License-Identifier: CC0-1.0
  *
@@ -13,7 +13,7 @@
  */
 
 #pragma once
-
+#include "esp_coexist.h"
 #include "esp_openthread_types.h"
 
 #if CONFIG_OPENTHREAD_RADIO_NATIVE
@@ -100,3 +100,33 @@
         .netif_queue_size = 10,                 \
         .task_queue_size = 10,                  \
     }
+
+#if CONFIG_EXTERNAL_COEX_ENABLE
+#if CONFIG_EXTERNAL_COEX_WIRE_TYPE == EXTERNAL_COEXIST_WIRE_1
+#define ESP_OPENTHREAD_DEFAULT_EXTERNAL_COEX_CONFIG()   \
+    {                                                   \
+        .request = CONFIG_EXTERNAL_COEX_REQUEST_PIN,    \
+    }
+#elif CONFIG_EXTERNAL_COEX_WIRE_TYPE == EXTERNAL_COEXIST_WIRE_2
+#define ESP_OPENTHREAD_DEFAULT_EXTERNAL_COEX_CONFIG()   \
+    {                                                   \
+        .request = CONFIG_EXTERNAL_COEX_REQUEST_PIN,    \
+        .grant = CONFIG_EXTERNAL_COEX_GRANT_PIN,        \
+    }
+#elif CONFIG_EXTERNAL_COEX_WIRE_TYPE == EXTERNAL_COEXIST_WIRE_3
+#define ESP_OPENTHREAD_DEFAULT_EXTERNAL_COEX_CONFIG()   \
+    {                                                   \
+        .request = CONFIG_EXTERNAL_COEX_REQUEST_PIN,    \
+        .priority = CONFIG_EXTERNAL_COEX_PRIORITY_PIN,  \
+        .grant = CONFIG_EXTERNAL_COEX_GRANT_PIN,        \
+    }
+#elif CONFIG_EXTERNAL_COEX_WIRE_TYPE == EXTERNAL_COEXIST_WIRE_4
+#define ESP_OPENTHREAD_DEFAULT_EXTERNAL_COEX_CONFIG()   \
+    {                                                   \
+        .request = CONFIG_EXTERNAL_COEX_REQUEST_PIN,    \
+        .priority = CONFIG_EXTERNAL_COEX_PRIORITY_PIN,  \
+        .grant = CONFIG_EXTERNAL_COEX_GRANT_PIN,        \
+        .tx_line = CONFIG_EXTERNAL_COEX_TX_LINE_PIN,    \
+    }
+#endif
+#endif // CONFIG_EXTERNAL_COEX_ENABLE

+ 29 - 0
examples/openthread/ot_rcp/main/Kconfig.projbuild

@@ -18,4 +18,33 @@ menu "OpenThread RCP Example"
         default 5
         range 0 25
 
+    menu "External coexist wire type and pin config"
+        config EXTERNAL_COEX_WIRE_TYPE
+            int "The wire_type of external coexist"
+            depends on ESP_COEX_EXTERNAL_COEXIST_ENABLE
+            default 3
+            range 0 3
+            help
+                Select wire_type for external coexist, the wire_type define in external_coex_wire_t.
+
+        config EXTERNAL_COEX_REQUEST_PIN
+            int "The number of external coexist request pin"
+            depends on ESP_COEX_EXTERNAL_COEXIST_ENABLE && (EXTERNAL_COEX_WIRE_TYPE >= 0)
+            default 0
+
+        config EXTERNAL_COEX_GRANT_PIN
+            int "The number of external coexist grant pin"
+            depends on ESP_COEX_EXTERNAL_COEXIST_ENABLE && (EXTERNAL_COEX_WIRE_TYPE >= 1)
+            default 1
+
+        config EXTERNAL_COEX_PRIORITY_PIN
+            int "The number of external coexist priority pin"
+            depends on ESP_COEX_EXTERNAL_COEXIST_ENABLE && (EXTERNAL_COEX_WIRE_TYPE >= 2)
+            default 2
+
+        config EXTERNAL_COEX_TX_LINE_PIN
+            int "The number of external coexist tx_line pin"
+            depends on ESP_COEX_EXTERNAL_COEXIST_ENABLE && (EXTERNAL_COEX_WIRE_TYPE = 3)
+            default 3
+    endmenu # External coexist wire type and pin config
 endmenu

+ 35 - 1
examples/openthread/ot_rcp/main/esp_ot_config.h

@@ -1,5 +1,5 @@
 /*
- * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
+ * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
  *
  * SPDX-License-Identifier: CC0-1.0
  *
@@ -14,6 +14,10 @@
 
 #pragma once
 
+#if CONFIG_EXTERNAL_COEX_ENABLE
+#include "esp_coexist.h"
+#endif
+
 #include "esp_openthread_types.h"
 #define ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG()                   \
     {                                                           \
@@ -79,3 +83,33 @@
         .netif_queue_size = 10,                 \
         .task_queue_size = 10,                  \
     }
+
+#if CONFIG_EXTERNAL_COEX_ENABLE
+#if CONFIG_EXTERNAL_COEX_WIRE_TYPE == EXTERNAL_COEXIST_WIRE_1
+#define ESP_OPENTHREAD_DEFAULT_EXTERNAL_COEX_CONFIG()   \
+    {                                                   \
+        .request = CONFIG_EXTERNAL_COEX_REQUEST_PIN,    \
+    }
+#elif CONFIG_EXTERNAL_COEX_WIRE_TYPE == EXTERNAL_COEXIST_WIRE_2
+#define ESP_OPENTHREAD_DEFAULT_EXTERNAL_COEX_CONFIG()   \
+    {                                                   \
+        .request = CONFIG_EXTERNAL_COEX_REQUEST_PIN,    \
+        .grant = CONFIG_EXTERNAL_COEX_GRANT_PIN,        \
+    }
+#elif CONFIG_EXTERNAL_COEX_WIRE_TYPE == EXTERNAL_COEXIST_WIRE_3
+#define ESP_OPENTHREAD_DEFAULT_EXTERNAL_COEX_CONFIG()   \
+    {                                                   \
+        .request = CONFIG_EXTERNAL_COEX_REQUEST_PIN,    \
+        .priority = CONFIG_EXTERNAL_COEX_PRIORITY_PIN,  \
+        .grant = CONFIG_EXTERNAL_COEX_GRANT_PIN,        \
+    }
+#elif CONFIG_EXTERNAL_COEX_WIRE_TYPE == EXTERNAL_COEXIST_WIRE_4
+#define ESP_OPENTHREAD_DEFAULT_EXTERNAL_COEX_CONFIG()   \
+    {                                                   \
+        .request = CONFIG_EXTERNAL_COEX_REQUEST_PIN,    \
+        .priority = CONFIG_EXTERNAL_COEX_PRIORITY_PIN,  \
+        .grant = CONFIG_EXTERNAL_COEX_GRANT_PIN,        \
+        .tx_line = CONFIG_EXTERNAL_COEX_TX_LINE_PIN,    \
+    }
+#endif
+#endif // CONFIG_EXTERNAL_COEX_ENABLE

+ 20 - 1
examples/openthread/ot_rcp/main/esp_ot_rcp.c

@@ -1,5 +1,5 @@
 /*
- * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
+ * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
  *
  * SPDX-License-Identifier: CC0-1.0
  *
@@ -22,6 +22,10 @@
 #include "esp_vfs_eventfd.h"
 #include "driver/uart.h"
 
+#if CONFIG_EXTERNAL_COEX_ENABLE
+#include "esp_coexist.h"
+#endif
+
 #if !SOC_IEEE802154_SUPPORTED
 #error "RCP is only supported for the SoCs which have IEEE 802.15.4 module"
 #endif
@@ -30,6 +34,17 @@
 
 extern void otAppNcpInit(otInstance *instance);
 
+#if CONFIG_EXTERNAL_COEX_ENABLE
+#if SOC_EXTERNAL_COEX_ADVANCE
+static void ot_external_coexist_init(void)
+{
+    esp_external_coex_gpio_set_t gpio_pin = ESP_OPENTHREAD_DEFAULT_EXTERNAL_COEX_CONFIG();
+    esp_external_coex_set_work_mode(EXTERNAL_COEX_FOLLOWER_ROLE);
+    ESP_ERROR_CHECK(esp_enable_extern_coex_gpio_pin(CONFIG_EXTERNAL_COEX_WIRE_TYPE, gpio_pin));
+}
+#endif // SOC_EXTERNAL_COEX_ADVANCE
+#endif // CONFIG_EXTERNAL_COEX_ENABLE
+
 static void ot_task_worker(void *aContext)
 {
     esp_openthread_platform_config_t config = {
@@ -41,6 +56,10 @@ static void ot_task_worker(void *aContext)
     // Initialize the OpenThread stack
     ESP_ERROR_CHECK(esp_openthread_init(&config));
 
+#if CONFIG_EXTERNAL_COEX_ENABLE
+    ot_external_coexist_init();
+#endif // CONFIG_EXTERNAL_COEX_ENABLE
+
     // Initialize the OpenThread ncp
     otAppNcpInit(esp_openthread_get_instance());