Skip to content

Commit 7133e14

Browse files
committed
Merge branch 'feature/wifi_bt_new_coex' into 'master'
Feature/wifi bt new coex See merge request idf/esp-idf!2087
2 parents aca0008 + 3b3ad87 commit 7133e14

File tree

13 files changed

+456
-65
lines changed

13 files changed

+456
-65
lines changed

.gitlab-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ build_template_app:
9898
- make all V=1
9999
# Check if there are any stray printf/ets_printf references in WiFi libs
100100
- cd ../components/esp32/lib
101-
- test $(xtensa-esp32-elf-nm *.a | grep -w printf | wc -l) -eq 0
102-
- test $(xtensa-esp32-elf-nm *.a | grep -w ets_printf | wc -l) -eq 0
101+
- test $(ls *.a|awk '{if ($1 != "libcoexist.a") print $1}' | xargs xtensa-esp32-elf-nm | grep -w printf | wc -l) -eq 0
102+
- test $(ls *.a|awk '{if ($1 != "libcoexist.a") print $1}' | xargs xtensa-esp32-elf-nm | grep -w ets_printf | wc -l) -eq 0
103103

104104

105105
.build_template: &build_template

components/bt/bt.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,13 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
540540
esp_pm_lock_acquire(s_pm_lock);
541541
#endif
542542

543-
esp_phy_load_cal_and_init();
543+
esp_phy_load_cal_and_init(PHY_BT_MODULE);
544+
esp_modem_sleep_register(MODEM_BLE_MODULE);
545+
546+
/* TODO: Classic BT should be registered once it supports
547+
* modem sleep */
548+
549+
esp_modem_sleep_exit(MODEM_BLE_MODULE);
544550

545551
if (btdm_bb_init_flag == false) {
546552
btdm_bb_init_flag = true;
@@ -549,6 +555,8 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
549555

550556
ret = btdm_controller_enable(mode);
551557
if (ret) {
558+
esp_modem_sleep_deregister(MODEM_BLE_MODULE);
559+
esp_phy_rf_deinit(PHY_BT_MODULE);
552560
return ESP_ERR_INVALID_STATE;
553561
}
554562

@@ -571,7 +579,10 @@ esp_err_t esp_bt_controller_disable(void)
571579
}
572580

573581
if (ret == ESP_BT_MODE_IDLE) {
574-
esp_phy_rf_deinit();
582+
/* TODO: Need to de-register classic BT once it supports
583+
* modem sleep */
584+
esp_modem_sleep_deregister(MODEM_BLE_MODULE);
585+
esp_phy_rf_deinit(PHY_BT_MODULE);
575586
btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED;
576587
}
577588

components/bt/lib

Submodule lib updated 1 file

components/esp32/Kconfig

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,12 +822,40 @@ menu Wi-Fi
822822
config SW_COEXIST_ENABLE
823823
bool "Software controls WiFi/Bluetooth coexistence"
824824
depends on BT_ENABLED
825-
default n
825+
default y
826826
help
827827
If enabled, WiFi & Bluetooth coexistence is controlled by software rather than hardware.
828828
Recommended for heavy traffic scenarios. Both coexistence configuration options are
829829
automatically managed, no user intervention is required.
830830

831+
choice SW_COEXIST_PREFERENCE
832+
prompt "WiFi/Bluetooth coexistence performance preference"
833+
depends on SW_COEXIST_ENABLE
834+
default SW_COEXIST_PREFERENCE_BALANCE
835+
help
836+
Choose Bluetooth/WiFi/Balance for different preference.
837+
If choose WiFi, it will make WiFi performance better. Such, keep WiFi Audio more smooth.
838+
If choose Bluetooth, it will make Bluetooth performance better. Such, keep Bluetooth(A2DP) Audio more smooth.
839+
If choose Balance, the performance of WiFi and bluetooth will be balance. It's default.
840+
Except config preference in menuconfig, you can also call esp_coex_preference_set() dynamically.
841+
842+
config SW_COEXIST_PREFERENCE_WIFI
843+
bool "WiFi"
844+
845+
config SW_COEXIST_PREFERENCE_BT
846+
bool "Bluetooth(include BR/EDR and BLE)"
847+
848+
config SW_COEXIST_PREFERENCE_BALANCE
849+
bool "Balance"
850+
851+
endchoice
852+
853+
config SW_COEXIST_PREFERENCE_VALUE
854+
int
855+
depends on SW_COEXIST_ENABLE
856+
default 0 if SW_COEXIST_PREFERENCE_WIFI
857+
default 1 if SW_COEXIST_PREFERENCE_BT
858+
default 2 if SW_COEXIST_PREFERENCE_BALANCE
831859

832860
config ESP32_WIFI_STATIC_RX_BUFFER_NUM
833861
int "Max number of WiFi static RX buffers"
@@ -919,27 +947,33 @@ config ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM
919947

920948
config ESP32_WIFI_AMPDU_TX_ENABLED
921949
bool "WiFi AMPDU TX"
950+
default y if SW_COEXIST_ENABLE
922951
default y
923952
help
924953
Select this option to enable AMPDU TX feature
954+
Suggest enable it when SW_COEXIST_ENABLE is defined.
925955

926956

927957
config ESP32_WIFI_TX_BA_WIN
928958
int "WiFi AMPDU TX BA window size"
929959
depends on ESP32_WIFI_AMPDU_TX_ENABLED
930960
range 2 32
961+
default 2 if SW_COEXIST_ENABLE
931962
default 6
932963
help
933964
Set the size of WiFi Block Ack TX window. Generally a bigger value means higher throughput but
934965
more memory. Most of time we should NOT change the default value unless special reason, e.g.
935966
test the maximum UDP TX throughput with iperf etc. For iperf test in shieldbox, the recommended
936-
value is 9~12.
967+
value is 9~12. If SW_COEXIST_ENABLE is defined, suggest value is 2.
937968

938969
config ESP32_WIFI_AMPDU_RX_ENABLED
939970
bool "WiFi AMPDU RX"
971+
depends on !SW_COEXIST_ENABLE
972+
default y
940973
default y
941974
help
942975
Select this option to enable AMPDU RX feature
976+
Suggest disable this option when SW_COEXIST_ENABLE is enabled. It can improve WiFi RX performance normally.
943977

944978
config ESP32_WIFI_RX_BA_WIN
945979
int "WiFi AMPDU RX BA window size"

components/esp32/include/esp_coexist.h

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,79 @@
1818
extern "C" {
1919
#endif
2020

21+
typedef enum {
22+
COEX_PREFER_WIFI = 0,
23+
COEX_PREFER_BT,
24+
COEX_PREFER_BALANCE,
25+
COEX_PREFER_NUM,
26+
} coex_prefer_t;
27+
2128
/**
2229
* @brief Init software coexist
30+
* extern function for internal use.
2331
*
2432
* @return Init ok or failed.
2533
*/
2634
esp_err_t coex_init(void);
2735

2836
/**
2937
* @brief De-init software coexist
38+
* extern function for internal use.
3039
*/
3140
void coex_deinit(void);
3241

3342
/**
34-
* @brief Get software coexist enable or not
43+
* @brief Pause software coexist
44+
* extern function for internal use.
45+
*/
46+
void coex_pause(void);
47+
48+
/**
49+
* @brief Resume software coexist
50+
* extern function for internal use.
51+
*/
52+
void coex_resume(void);
53+
54+
/**
55+
* @brief Get software coexist version string
56+
* extern function for internal use.
57+
* @return : version string
58+
*/
59+
const char *coex_version_get(void);
60+
61+
/**
62+
* @brief Coexist performance preference set from libbt.a
63+
* extern function for internal use.
3564
*
36-
* @return software coexist enable status.
65+
* @param prefer : the prefer enumeration value
66+
* @return : ESP_OK - success, other - failed
3767
*/
38-
bool coexist_get_enable(void);
68+
esp_err_t coex_preference_set(coex_prefer_t prefer);
3969

4070
/**
41-
* @brief Set software coexist enable or not
71+
* @brief Get software coexist version string
4272
*
43-
* @param enable software coexist or disable it
73+
* @return : version string
74+
*/
75+
static inline const char *esp_coex_version_get(void)
76+
{
77+
return coex_version_get();
78+
}
79+
80+
/**
81+
* @brief Set coexist preference of performance
82+
* For example, if prefer to bluetooth, then it will make A2DP(play audio via classic bt)
83+
* more smooth while wifi is runnning something.
84+
* If prefer to wifi, it will do similar things as prefer to bluetooth.
85+
* Default, it prefer to balance.
4486
*
45-
* @return Void.
87+
* @param prefer : the prefer enumeration value
88+
* @return : ESP_OK - success, other - failed
4689
*/
47-
void coexist_set_enable(bool enable);
90+
static inline esp_err_t esp_coex_preference_set(coex_prefer_t prefer)
91+
{
92+
return coex_preference_set(prefer);
93+
}
4894

4995
#ifdef __cplusplus
5096
}

components/esp32/include/esp_phy_init.h

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,43 @@ typedef enum {
4646
PHY_RF_CAL_FULL = 0x00000002 /*!< Do full RF calibration. Produces best results, but also consumes a lot of time and current. Suggested to be used once. */
4747
} esp_phy_calibration_mode_t;
4848

49+
50+
/**
51+
* @brief Modules for modem sleep
52+
*/
53+
typedef enum{
54+
MODEM_BLE_MODULE, //!< BLE controller used
55+
MODEM_CLASSIC_BT_MODULE, //!< Classic BT controller used
56+
MODEM_WIFI_STATION_MODULE, //!< Wi-Fi Station used
57+
MODEM_WIFI_SOFTAP_MODULE, //!< Wi-Fi SoftAP used
58+
MODEM_WIFI_SNIFFER_MODULE, //!< Wi-Fi Sniffer used
59+
MODEM_USER_MODULE, //!< User used
60+
MODEM_MODULE_COUNT //!< Number of items
61+
}modem_sleep_module_t;
62+
63+
/**
64+
* @brief Module WIFI mask for medem sleep
65+
*/
66+
#define MODEM_BT_MASK ((1<<MODEM_BLE_MODULE) | \
67+
(1<<MODEM_CLASSIC_BT_MODULE))
68+
69+
/**
70+
* @brief Module WIFI mask for medem sleep
71+
*/
72+
#define MODEM_WIFI_MASK ((1<<MODEM_WIFI_STATION_MODULE) | \
73+
(1<<MODEM_WIFI_SOFTAP_MODULE) | \
74+
(1<<MODEM_WIFI_SNIFFER_MODULE))
75+
76+
/**
77+
* @brief Modules needing to call phy_rf_init
78+
*/
79+
typedef enum{
80+
PHY_BT_MODULE, //!< Bluetooth used
81+
PHY_WIFI_MODULE, //!< Wi-Fi used
82+
PHY_MODEM_MODULE, //!< Modem sleep used
83+
PHY_MODULE_COUNT //!< Number of items
84+
}phy_rf_module_t;
85+
4986
/**
5087
* @brief Get PHY init data
5188
*
@@ -130,8 +167,8 @@ esp_err_t esp_phy_store_cal_data_to_nvs(const esp_phy_calibration_data_t* cal_da
130167
* @return ESP_OK on success.
131168
* @return ESP_FAIL on fail.
132169
*/
133-
esp_err_t esp_phy_rf_init(const esp_phy_init_data_t* init_data,
134-
esp_phy_calibration_mode_t mode, esp_phy_calibration_data_t* calibration_data);
170+
esp_err_t esp_phy_rf_init(const esp_phy_init_data_t* init_data,esp_phy_calibration_mode_t mode,
171+
esp_phy_calibration_data_t* calibration_data, phy_rf_module_t module);
135172

136173
/**
137174
* @brief De-initialize PHY and RF module
@@ -142,12 +179,32 @@ esp_err_t esp_phy_rf_init(const esp_phy_init_data_t* init_data,
142179
*
143180
* @return ESP_OK on success.
144181
*/
145-
esp_err_t esp_phy_rf_deinit(void);
182+
esp_err_t esp_phy_rf_deinit(phy_rf_module_t module);
146183

147184
/**
148185
* @brief Load calibration data from NVS and initialize PHY and RF module
149186
*/
150-
void esp_phy_load_cal_and_init(void);
187+
void esp_phy_load_cal_and_init(phy_rf_module_t module);
188+
189+
/**
190+
* @brief Module requires to enter modem sleep
191+
*/
192+
esp_err_t esp_modem_sleep_enter(modem_sleep_module_t module);
193+
194+
/**
195+
* @brief Module requires to exit modem sleep
196+
*/
197+
esp_err_t esp_modem_sleep_exit(modem_sleep_module_t module);
198+
199+
/**
200+
* @brief Register module to make it be able to require to enter/exit modem sleep
201+
*/
202+
esp_err_t esp_modem_sleep_register(modem_sleep_module_t module);
203+
204+
/**
205+
* @brief De-register module from modem sleep list
206+
*/
207+
esp_err_t esp_modem_sleep_deregister(modem_sleep_module_t module);
151208

152209
#ifdef __cplusplus
153210
}

components/esp32/include/esp_wifi_types.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,9 @@ typedef struct {
174174
}wifi_fast_scan_threshold_t;
175175

176176
typedef enum {
177-
WIFI_PS_NONE, /**< No power save */
178-
WIFI_PS_MODEM, /**< Modem power save */
177+
WIFI_PS_NONE, /**< No power save */
178+
WIFI_PS_MIN_MODEM, /**< Minimum modem power save. In this mode, station wakes up to receive beacon every DTIM period */
179+
WIFI_PS_MAX_MODEM, /**< Maximum modem power save. In this mode, station wakes up to receive beacon every listen interval */
179180
} wifi_ps_type_t;
180181

181182
#define WIFI_PROTOCOL_11B 1
@@ -208,6 +209,7 @@ typedef struct {
208209
bool bssid_set; /**< whether set MAC address of target AP or not. Generally, station_config.bssid_set needs to be 0; and it needs to be 1 only when users need to check the MAC address of the AP.*/
209210
uint8_t bssid[6]; /**< MAC address of target AP*/
210211
uint8_t channel; /**< channel of target AP. Set to 1~13 to scan starting from the specified channel before connecting to AP. If the channel of AP is unknown, set it to 0.*/
212+
uint16_t listen_interval; /**< Listen interval for ESP32 station to receive beacon in maximum power save mode, units: beacon interval */
211213
wifi_sort_method_t sort_method; /**< sort the connect AP in the list by rssi or security mode */
212214
wifi_fast_scan_threshold_t threshold; /**< When scan_method is set to WIFI_FAST_SCAN, only APs which have an auth mode that is more secure than the selected auth mode and a signal stronger than the minimum RSSI will be used. */
213215
} wifi_sta_config_t;

0 commit comments

Comments
 (0)