Skip to content

Commit

Permalink
Support external coexist formal code for C2 & S3,
Browse files Browse the repository at this point in the history
and optimize RX category in external coex.
  • Loading branch information
alex.li authored and gspatankar committed Nov 8, 2022
1 parent 4307be2 commit 9bbe6e7
Show file tree
Hide file tree
Showing 8 changed files with 429 additions and 36 deletions.
4 changes: 2 additions & 2 deletions components/esp_wifi/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,14 @@ menu "Wi-Fi"
config ESP_WIFI_EXTERNAL_COEXIST_ENABLE
bool "WiFi External Coexistence"
default n
depends on (!BT_ENABLED && (IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3))
depends on (!(BT_ENABLED||NIMBLE_ENABLED)&&(!IDF_TARGET_ESP32))
help
If enabled, HW External coexistence arbitration is managed by GPIO pins.
It can support three types of wired combinations so far which are 1-wired/2-wired/3-wired.
User can select GPIO pins in application code with configure interfaces.

This function depends on BT-off
because currently we don't support external coex and internal coex simultaneously.
because currently we do not support external coex and internal coex simultaneously.

config ESP_WIFI_GCMP_SUPPORT
bool "WiFi GCMP Support(GCMP128 and GCMP256)"
Expand Down
40 changes: 20 additions & 20 deletions components/esp_wifi/esp32s3/esp_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ static void * IRAM_ATTR zalloc_internal_wrapper(size_t size)

static int coex_init_wrapper(void)
{
#if CONFIG_SW_COEXIST_ENABLE
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
return coex_init();
#else
return 0;
Expand All @@ -584,14 +584,14 @@ static int coex_init_wrapper(void)

static void coex_deinit_wrapper(void)
{
#if CONFIG_SW_COEXIST_ENABLE
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
coex_deinit();
#endif
}

static int coex_enable_wrapper(void)
{
#if CONFIG_SW_COEXIST_ENABLE
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
return coex_enable();
#else
return 0;
Expand All @@ -600,14 +600,14 @@ static int coex_enable_wrapper(void)

static void coex_disable_wrapper(void)
{
#if CONFIG_SW_COEXIST_ENABLE
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
coex_disable();
#endif
}

static IRAM_ATTR uint32_t coex_status_get_wrapper(void)
{
#if CONFIG_SW_COEXIST_ENABLE
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
return coex_status_get();
#else
return 0;
Expand All @@ -616,14 +616,14 @@ static IRAM_ATTR uint32_t coex_status_get_wrapper(void)

static void coex_condition_set_wrapper(uint32_t type, bool dissatisfy)
{
#if CONFIG_SW_COEXIST_ENABLE
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
coex_condition_set(type, dissatisfy);
#endif
}

static int coex_wifi_request_wrapper(uint32_t event, uint32_t latency, uint32_t duration)
{
#if CONFIG_SW_COEXIST_ENABLE
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
return coex_wifi_request(event, latency, duration);
#else
return 0;
Expand All @@ -632,7 +632,7 @@ static int coex_wifi_request_wrapper(uint32_t event, uint32_t latency, uint32_t

static IRAM_ATTR int coex_wifi_release_wrapper(uint32_t event)
{
#if CONFIG_SW_COEXIST_ENABLE
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
return coex_wifi_release(event);
#else
return 0;
Expand All @@ -641,7 +641,7 @@ static IRAM_ATTR int coex_wifi_release_wrapper(uint32_t event)

static int coex_wifi_channel_set_wrapper(uint8_t primary, uint8_t secondary)
{
#if CONFIG_SW_COEXIST_ENABLE
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
return coex_wifi_channel_set(primary, secondary);
#else
return 0;
Expand All @@ -650,7 +650,7 @@ static int coex_wifi_channel_set_wrapper(uint8_t primary, uint8_t secondary)

static IRAM_ATTR int coex_event_duration_get_wrapper(uint32_t event, uint32_t *duration)
{
#if CONFIG_SW_COEXIST_ENABLE
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
return coex_event_duration_get(event, duration);
#else
return 0;
Expand All @@ -659,7 +659,7 @@ static IRAM_ATTR int coex_event_duration_get_wrapper(uint32_t event, uint32_t *d

static int coex_pti_get_wrapper(uint32_t event, uint8_t *pti)
{
#if CONFIG_SW_COEXIST_ENABLE
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
return coex_pti_get(event, pti);
#else
return 0;
Expand All @@ -668,21 +668,21 @@ static int coex_pti_get_wrapper(uint32_t event, uint8_t *pti)

static void coex_schm_status_bit_clear_wrapper(uint32_t type, uint32_t status)
{
#if CONFIG_SW_COEXIST_ENABLE
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
coex_schm_status_bit_clear(type, status);
#endif
}

static void coex_schm_status_bit_set_wrapper(uint32_t type, uint32_t status)
{
#if CONFIG_SW_COEXIST_ENABLE
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
coex_schm_status_bit_set(type, status);
#endif
}

static IRAM_ATTR int coex_schm_interval_set_wrapper(uint32_t interval)
{
#if CONFIG_SW_COEXIST_ENABLE
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
return coex_schm_interval_set(interval);
#else
return 0;
Expand All @@ -691,7 +691,7 @@ static IRAM_ATTR int coex_schm_interval_set_wrapper(uint32_t interval)

static uint32_t coex_schm_interval_get_wrapper(void)
{
#if CONFIG_SW_COEXIST_ENABLE
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
return coex_schm_interval_get();
#else
return 0;
Expand All @@ -700,7 +700,7 @@ static uint32_t coex_schm_interval_get_wrapper(void)

static uint8_t coex_schm_curr_period_get_wrapper(void)
{
#if CONFIG_SW_COEXIST_ENABLE
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
return coex_schm_curr_period_get();
#else
return 0;
Expand All @@ -709,7 +709,7 @@ static uint8_t coex_schm_curr_period_get_wrapper(void)

static void * coex_schm_curr_phase_get_wrapper(void)
{
#if CONFIG_SW_COEXIST_ENABLE
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
return coex_schm_curr_phase_get();
#else
return NULL;
Expand All @@ -718,7 +718,7 @@ static void * coex_schm_curr_phase_get_wrapper(void)

static int coex_schm_curr_phase_idx_set_wrapper(int idx)
{
#if CONFIG_SW_COEXIST_ENABLE
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
return coex_schm_curr_phase_idx_set(idx);
#else
return 0;
Expand All @@ -727,7 +727,7 @@ static int coex_schm_curr_phase_idx_set_wrapper(int idx)

static int coex_schm_curr_phase_idx_get_wrapper(void)
{
#if CONFIG_SW_COEXIST_ENABLE
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
return coex_schm_curr_phase_idx_get();
#else
return 0;
Expand All @@ -736,7 +736,7 @@ static int coex_schm_curr_phase_idx_get_wrapper(void)

static int coex_register_start_cb_wrapper(int (* cb)(void))
{
#if CONFIG_SW_COEXIST_ENABLE
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
return coex_register_start_cb(cb);
#else
return 0;
Expand Down
101 changes: 88 additions & 13 deletions components/esp_wifi/include/esp_coexist.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ typedef enum {
ESP_COEX_ST_TYPE_BT,
} esp_coex_status_type_t;

#if CONFIG_EXTERNAL_COEX_ENABLE
/**
* @brief external coex gpio pti
*/
typedef struct {
int32_t in_pin0;
int32_t in_pin1;
int32_t out_pin0;
uint32_t in_pin0;
uint32_t in_pin1;
uint32_t out_pin0;
uint32_t out_pin1;
} esp_external_coex_gpio_set_t;

/**
Expand All @@ -59,16 +61,43 @@ typedef enum {
} esp_coex_pti_level_t;

/**
* @brief external coex pti
* @brief external coex follower pti
*/
typedef struct {
uint32_t pti_val1;
uint32_t pti_val2;
} esp_external_coex_follower_pti_t;

/**
* @brief external coex role
*/
typedef enum {
EXTERNAL_COEX_LEADER_ROLE = 0,
EXTERNAL_COEX_FOLLOWER_ROLE = 2,
EXTERNAL_COEX_UNKNOWN_ROLE,
} esp_extern_coex_work_mode_t;

/**
* @brief external coex wiretype & role composition
*/
typedef enum {
wire_3_leader_mode = 0,
wire_2_leader_mode,
wire_1_leader_mode,
wire_3_follower_mode,
wire_2_follower_mode,
wire_1_follower_mode,
} external_coex_classification;

/**
* @brief external coex advance setup
*/
typedef struct {
uint32_t in_pti1;
uint32_t in_pti2;
uint32_t in_pti3;
uint32_t out_pti1;
uint32_t out_pti2;
uint32_t out_pti3;
} esp_external_coex_pti_set_t;
esp_extern_coex_work_mode_t work_mode;
uint8_t delay_us;
bool is_high_valid;
} esp_external_coex_advance_t;
#endif

#define ESP_COEX_BLE_ST_MESH_CONFIG 0x08
#define ESP_COEX_BLE_ST_MESH_TRAFFIC 0x10
Expand Down Expand Up @@ -115,15 +144,61 @@ esp_err_t esp_coex_status_bit_clear(esp_coex_status_type_t type, uint32_t status

#if CONFIG_EXTERNAL_COEX_ENABLE
/**
* @brief Setup gpio pin and corresponding pti level, start external coex.
* @brief Setup gpio pin and corresponding pti level, start external coex,
* the default work mode is leader role, the default output grant validate pin is high,
* and the default delay output grant value is zero.
* @param wire_type : to select the whole external coex gpio number.
* @param gpio_pin : gpio pin number to choose.
* @return : ESP_OK - success, other - failed
*/
esp_err_t esp_enable_extern_coex_gpio_pin(external_coex_wire_t wire_type,
esp_external_coex_gpio_set_t gpio_pin);
esp_external_coex_gpio_set_t gpio_pin);

/**
* @brief Disable external coex.
* @return : ESP_OK - success, other - failed
*/
esp_err_t esp_disable_extern_coex_gpio_pin();

#if SOC_EXTERNAL_COEX_ADVANCE
/**
* @brief Configure leader work mode, gpio pin correspondly and finally enable external coex,
* demand not to call the legacy function of `esp_enable_extern_coex_gpio_pin` any more.
* @param wire_type : to select the whole external coex gpio number.
* @param gpio_pin : gpio pin number to select.
* @return : ESP_OK - success, other - failed
*/
esp_err_t esp_external_coex_leader_role_set_gpio_pin(external_coex_wire_t wire_type, uint32_t in_pin0,
uint32_t in_pin1, uint32_t out_pin0);

/**
* @brief Configure follower work mode, gpio pin correspondly and finally enable external coex,
* demand not to call the legacy function of `esp_enable_extern_coex_gpio_pin` any more.
* @param wire_type : to select the whole external coex gpio number.
* @param gpio_pin : gpio pin number to select.
* @return : ESP_OK - success, other - failed
*/
esp_err_t esp_external_coex_follower_role_set_gpio_pin(external_coex_wire_t wire_type, uint32_t in_pin0,
uint32_t out_pin0, uint32_t out_pin1);

/**
* @brief Configure output grant signal latency in delay microseconds only for leader role of external coex,
* demand to call this function before `esp_external_coex_leader_role_set_gpio_pin`,
* if users want to setup output delay value.
* @param delay_us : to setup how many microseconds the output signal performs latency.
* @return : ESP_OK - success, other - failed
*/
esp_err_t esp_external_coex_set_grant_delay(uint8_t delay_us);

/**
* @brief Configure output grant signal is high validate or not only for leader role of external coex,
* demand to call this function before `esp_external_coex_leader_role_set_gpio_pin`,
* if users want to setup output grant validate pin value.
* @param is_high_valid : to select true means the output grant signal validate is high, other - validate is low.
* @return : ESP_OK - success, other - failed
*/
esp_err_t esp_external_coex_set_validate_high(bool is_high_valid);
#endif
#endif

#ifdef __cplusplus
Expand Down
22 changes: 22 additions & 0 deletions components/esp_wifi/include/esp_coexist_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,28 @@ int coex_register_start_cb(int (* cb)(void));
esp_err_t esp_coex_adapter_register(coex_adapter_funcs_t *funcs);

#if CONFIG_EXTERNAL_COEX_ENABLE
/**
* @brief Force RX Anttena only in external coex situation.
*/
extern void phy_coex_force_rx_ant(void);

/**
* @brief Dismiss RX Anttena only in external coex situation.
*/
extern void phy_coex_dismiss_rx_ant(void);

/**
* @brief Set external coexistence advanced informations, like working mode and grant mode in which level.
*
* @param outpti1 Only for slave mode, external coex output priority in level1.
* @param output2 Only for slave mode, external coex output priority in level2.
*
* @return
* - ESP_OK: succeed
*/
esp_err_t esp_coex_external_params(esp_external_coex_advance_t coex_info,
uint32_t out_pti1, uint32_t out_pti2);

/**
* @brief Set external coexistence pti level and enable it.
*
Expand Down
Loading

0 comments on commit 9bbe6e7

Please sign in to comment.