Skip to content

Commit

Permalink
Merge branch 'feature/extenal_coexist_slave_support_v5.1' into 'relea…
Browse files Browse the repository at this point in the history
…se/v5.1'

feat(esp_coex): add external coex slave support (backport v5.1)

See merge request espressif/esp-idf!25976
  • Loading branch information
chshu committed Sep 18, 2023
2 parents 8ce86c3 + ca37e4d commit 66c9fb0
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 25 deletions.
2 changes: 1 addition & 1 deletion components/esp_coex/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 12 additions & 8 deletions components/esp_coex/include/esp_coexist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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;

Expand All @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions components/esp_coex/include/esp_coexist_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/esp_coex/src/coexist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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!!!\n");
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
Expand Down
2 changes: 1 addition & 1 deletion components/ieee802154/driver/esp_ieee802154_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions components/ieee802154/driver/esp_ieee802154_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions components/ieee802154/private_include/esp_ieee802154_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
29 changes: 29 additions & 0 deletions examples/openthread/ot_br/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 15 additions & 2 deletions examples/openthread/ot_br/main/esp_ot_br.c
Original file line number Diff line number Diff line change
@@ -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
*
Expand Down Expand Up @@ -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"
Expand All @@ -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 = {
Expand Down Expand Up @@ -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
Expand Down
34 changes: 32 additions & 2 deletions examples/openthread/ot_br/main/esp_ot_config.h
Original file line number Diff line number Diff line change
@@ -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
*
Expand All @@ -13,7 +13,7 @@
*/

#pragma once

#include "esp_coexist.h"
#include "esp_openthread_types.h"

#if CONFIG_OPENTHREAD_RADIO_NATIVE
Expand Down Expand Up @@ -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 changes: 29 additions & 0 deletions examples/openthread/ot_rcp/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 35 additions & 1 deletion examples/openthread/ot_rcp/main/esp_ot_config.h
Original file line number Diff line number Diff line change
@@ -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
*
Expand All @@ -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() \
{ \
Expand Down Expand Up @@ -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
21 changes: 20 additions & 1 deletion examples/openthread/ot_rcp/main/esp_ot_rcp.c
Original file line number Diff line number Diff line change
@@ -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
*
Expand All @@ -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
Expand All @@ -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 = {
Expand All @@ -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());

Expand Down

0 comments on commit 66c9fb0

Please sign in to comment.