feat(wifi): support sample beacon feature

fix: adapt soc wakeup quick wake, fix light sleep beacon sample

feat(pm): giveup beacon and resample if rx prop too low (a16fa11)
This commit is contained in:
liuning
2024-12-27 14:15:23 +08:00
parent 2a0791b223
commit c00d092bdb
13 changed files with 193 additions and 29 deletions

View File

@@ -56,7 +56,7 @@ lmac_stop_hw_txq = 0x40001df8;
ppTxFragmentProc = 0x40001e08;
esf_buf_setup = 0x40001e0c;
hal_crypto_set_key_entry = 0x40001e18;
pm_start = 0x40001e34;
/*pm_start = 0x40001e34;*/
pm_stop = 0x40001e38;
hal_set_sta_tbtt = 0x40001e4c;
//pm_update_next_tbtt = 0x40001e50;
@@ -65,7 +65,7 @@ pm_set_sleep_type = 0x40001e54;
//pm_tx_data_process = 0x40001eb4;
/*pm_attach = 0x40001eb8;*/
/*pm_coex_schm_process = 0x40001ebc;*/
pm_on_probe_resp_rx = 0x40001ecc;
/*pm_on_probe_resp_rx = 0x40001ecc;*/
pm_send_probe_stop = 0x40001edc;
hal_sniffer_rx_set_promis = 0x40001ef4;
hal_sniffer_set_promis_misc_pkt = 0x40001efc;
@@ -183,7 +183,7 @@ hal_get_time_to_sta_next_tbtt = 0x4000303c;
pm_scale_listen_interval = 0x40003040;
pm_beacon_monitor_tbtt_start = 0x40003044;
pm_beacon_monitor_tbtt_stop = 0x40003048;
pm_beacon_monitor_timeout_process = 0x4000304c;
/*pm_beacon_monitor_timeout_process = 0x4000304c;*/
pm_beacon_monitor_tbtt_timeout_process = 0x40003050;
pm_on_tsf_timer = 0x40003054;
pp_coex_tx_release = 0x40003058;
@@ -191,26 +191,26 @@ ppRegressAmpdu = 0x4000305c;
trc_onPPTxDone = 0x40003060;
is_fragmented_pkt = 0x40003064;
pm_tx_null_data_done_quick_wake_process = 0x40003068;
pm_enable_beacon_monitor_timer = 0x4000306c;
/*pm_enable_beacon_monitor_timer = 0x4000306c;*/
pm_disable_beacon_monitor_timer = 0x40003070;
pm_beacon_offset_get_average = 0x40003074;
/*pm_beacon_offset_get_average = 0x40003074;
pm_beacon_offset_get_expect = 0x40003078;
pm_beacon_offset_get_params = 0x4000307c;
pm_beacon_offset_sample_start = 0x40003080;
pm_beacon_offset_sample_start = 0x40003080;*/
pm_beacon_offset_sample = 0x40003084;
pm_beacon_offset_reset = 0x40003088;
/*pm_beacon_offset_reset = 0x40003088;*/
pm_beacon_offset_is_sampling = 0x4000308c;
pm_beacon_offset_is_enabled = 0x40003090;
pm_beacon_offset_configure = 0x40003094;
/*pm_beacon_offset_configure = 0x40003094;*/
pm_beacon_offset_resample_timeout_process = 0x40003098;
pm_beacon_offset_set_rx_beacon_standard = 0x4000309c;
pm_beacon_offset_get_rx_beacon_success_rate = 0x400030a0;
/*pm_beacon_offset_set_rx_beacon_standard = 0x4000309c;*/
/*pm_beacon_offset_get_rx_beacon_success_rate = 0x400030a0;*/
pm_beacon_offset_add_total_counter = 0x400030a4;
pm_beacon_offset_add_loss_counter = 0x400030a8;
pm_beacon_offset_check = 0x400030ac;
pm_beacon_offset_init = 0x400030b0;
/*pm_beacon_offset_check = 0x400030ac;*/
/*pm_beacon_offset_init = 0x400030b0;*/
pm_beacon_offset_deinit = 0x400030b4;
pm_get_tbtt_count = 0x400030b8;
/*pm_get_tbtt_count = 0x400030b8;*/
pm_coex_schm_overall_period_get = 0x400030bc;
pm_coex_pwr_update = 0x400030c0;
/* Data (.data, .bss, .rodata) */

View File

@@ -568,7 +568,7 @@ ppResortTxAMPDU = 0x40001c20;
ppResumeTxAMPDU = 0x40001c24;
/*ppRxFragmentProc = 0x40001c28;*/
/* ppRxPkt = 0x40001c2c; */
ppRxProtoProc = 0x40001c30;
/* ppRxProtoProc = 0x40001c30; */
ppSearchTxQueue = 0x40001c34;
ppSearchTxframe = 0x40001c38;
ppSelectNextQueue = 0x40001c3c;

View File

@@ -755,7 +755,7 @@ ppResortTxAMPDU = 0x400016fc;
ppResumeTxAMPDU = 0x40001700;
/* ppRxFragmentProc = 0x40001704; */
/* ppRxPkt = 0x40001708; */
ppRxProtoProc = 0x4000170c;
/* ppRxProtoProc = 0x4000170c; */
ppSearchTxQueue = 0x40001710;
ppSearchTxframe = 0x40001714;
ppSelectNextQueue = 0x40001718;

View File

@@ -156,11 +156,11 @@ pm_beacon_monitor_tbtt_timeout_process = 0x40000e00;
/*pm_update_next_tbtt = 0x40000e04;*/
pm_twt_disallow_tx = 0x40000e08;
pm_clear_wakeup_signal = 0x40000e0c;
pm_mac_disable_tsf_tbtt_soc_wakeup = 0x40000e10;
/*pm_mac_disable_tsf_tbtt_soc_wakeup = 0x40000e10;
pm_mac_disable_tsf_tbtt_modem_wakeup = 0x40000e14;
pm_mac_enable_tsf_tbtt_soc_wakeup = 0x40000e18;
pm_mac_enable_tsf_tbtt_modem_wakeup = 0x40000e1c;
pm_mac_modem_params_rt_update = 0x40000e20;
pm_mac_modem_params_rt_update = 0x40000e20;*/
pm_update_at_next_beacon = 0x40000e24;
tbtt_adaptive_setup = 0x40000e28;
tbtt_adaptive_servo = 0x40000e2c;
@@ -187,8 +187,8 @@ ppRecycleRxPkt = 0x40000e7c;
ppResortTxAMPDU = 0x40000e80;
ppResumeTxAMPDU = 0x40000e84;
ppRxFragmentProc = 0x40000e88;
/*ppRxPkt = 0x40000e8c;*/
ppRxProtoProc = 0x40000e90;
/* ppRxPkt = 0x40000e8c; */
/* ppRxProtoProc = 0x40000e90; */
ppSearchTxQueue = 0x40000e94;
ppSearchTxframe = 0x40000e98;
ppSelectNextQueue = 0x40000e9c;
@@ -338,7 +338,7 @@ get_sublen_offset = 0x400010d8;
pm_coex_schm_overall_period_get = 0x40001504;
ppRemoveHEAMPDUflags = 0x4000150c;
tsf_hal_get_tbtt_interval = 0x40001510;
pm_get_tbtt_count = 0x4000151c;
/*pm_get_tbtt_count = 0x4000151c;*/
tsf_hal_get_time = 0x40001520;
tsf_hal_get_counter_value = 0x40001524;
/* Data (.data, .bss, .rodata) */

View File

@@ -102,7 +102,7 @@ ppRecycleRxPkt = 0x40000d14;
ppResumeTxAMPDU = 0x40000d1c;
/*ppRxFragmentProc = 0x40000d20;*/
//ppRxPkt = 0x40000d24;
ppRxProtoProc = 0x40000d28;
//ppRxProtoProc = 0x40000d28;
ppSearchTxQueue = 0x40000d2c;
ppSearchTxframe = 0x40000d30;
ppSelectNextQueue = 0x40000d34;

View File

@@ -160,11 +160,11 @@ pm_beacon_monitor_tbtt_timeout_process = 0x40000d6c;
pm_update_next_tbtt = 0x40000d70;
pm_twt_disallow_tx = 0x40000d74;
pm_clear_wakeup_signal = 0x40000d78;
pm_mac_disable_tsf_tbtt_soc_wakeup = 0x40000d7c;
/*pm_mac_disable_tsf_tbtt_soc_wakeup = 0x40000d7c;
pm_mac_disable_tsf_tbtt_modem_wakeup = 0x40000d80;
pm_mac_enable_tsf_tbtt_soc_wakeup = 0x40000d84;
pm_mac_enable_tsf_tbtt_modem_wakeup = 0x40000d88;
pm_mac_modem_params_rt_update = 0x40000d8c;
pm_mac_modem_params_rt_update = 0x40000d8c;*/
pm_update_at_next_beacon = 0x40000d90;
pm_get_null_max_tx_time = 0x40000d94;
pm_coex_schm_overall_period_get = 0x40000d98;

View File

@@ -1010,7 +1010,7 @@ ppResortTxAMPDU = 0x40005634;
ppResumeTxAMPDU = 0x40005640;
/* ppRxFragmentProc = 0x4000564c; */
/* ppRxPkt = 0x40005658; */
ppRxProtoProc = 0x40005664;
/* ppRxProtoProc = 0x40005664; */
ppSearchTxQueue = 0x40005670;
ppSearchTxframe = 0x4000567c;
ppSelectNextQueue = 0x40005688;

View File

@@ -462,8 +462,9 @@ menu "Wi-Fi"
default 3
depends on ESP_WIFI_SLP_BEACON_LOST_OPT
help
Maximum number of consecutive lost beacons allowed, WiFi keeps Rx state when
the number of consecutive beacons lost is greater than the given threshold.
Maximum number of consecutive lost beacons allowed, the WiFi Rx state behaviour
will be determined by ESP_WIFI_SLP_BEACON_LOST_OVER_THRESHOLD_POLICY
when the number of consecutive beacons lost is greater than the given threshold.
config ESP_WIFI_SLP_PHY_ON_DELTA_EARLY_TIME
int "Delta early time for RF PHY on"
@@ -483,6 +484,77 @@ menu "Wi-Fi"
Delta timeout time for rf phy off, When the beacon is lost, the next rf phy off will
be delayed for the time specified by the configuration item. Unit: 1024 microsecond.
choice ESP_WIFI_SLP_BEACON_LOST_OVER_THRESHOLD_POLICY
prompt "Beacon strategy when beacon loss exceeds threshold"
depends on ESP_WIFI_SLP_BEACON_LOST_OPT
default ESP_WIFI_SLP_BEACON_LOST_OVER_THRESHOLD_AUTO
help
Select the strategy to apply when the number of lost beacons exceeds the threshold.
- "Receive beacon": Keep RF on until a beacon is successfully received.
- "Drop beacon": Turn off RF and skip beacon reception during this period.
- "Auto": Beacon will been dropped only if ESP_WIFI_SLP_SAMPLE_BEACON_FEATURE enabled
and expected rx beacon probability stays below the standard.
config ESP_WIFI_SLP_BEACON_LOST_OVER_THRESHOLD_RECEIVE
bool "Receive beacon"
config ESP_WIFI_SLP_BEACON_LOST_OVER_THRESHOLD_DROP
bool "Drop beacon"
config ESP_WIFI_SLP_BEACON_LOST_OVER_THRESHOLD_AUTO
bool "Auto"
endchoice
config ESP_WIFI_SLP_SAMPLE_BEACON_FEATURE
bool "Sample beacon to calculate beacon offset"
default n
depends on ESP_WIFI_SLP_BEACON_LOST_OPT && !ESP_WIFI_ENHANCED_LIGHT_SLEEP
help
Select to enable feature sampling beacons to calculate beacon offset.
menu "Beacon Sample Configuration Options"
visible if ESP_WIFI_SLP_SAMPLE_BEACON_FEATURE
config ESP_WIFI_SLP_SAMPLE_BEACON_COUNT
int "Sample beacons at wifi connected to adjust beacon parameters"
range 100 1200
default 300
depends on ESP_WIFI_SLP_SAMPLE_BEACON_FEATURE
help
Numble of sampled beacons at wifi connected to adjust beacon parameters.
config ESP_WIFI_SLP_SAMPLE_BEACON_DIFFERENCE_PERCENT
int "Difference percentage triggers unstable event"
range 0 100
default 20
depends on ESP_WIFI_SLP_SAMPLE_BEACON_FEATURE
help
Difference triggers event WIFI_EVENT_STA_BEACON_OFFSET_UNSTABLE
when the actual rx beacon probability continuously falls below
the expected probability by this value.
unit: percentage
config ESP_WIFI_SLP_SAMPLE_BEACON_STANDARD_PERCENT
int "Standard percentage triggers beacon drop"
range 0 100
default 55
depends on ESP_WIFI_SLP_SAMPLE_BEACON_FEATURE
help
Standard triggers beacon drop when the expected rx beacon probability
falls below this value under ESP_WIFI_SLP_BEACON_LOST_DROP_BEACON_AUTO mode.
unit: percentage
config ESP_WIFI_SLP_SAMPLE_BEACON_RESAMPLE_PERIOD
int "Resample period"
range 0 255
default 3
depends on ESP_WIFI_SLP_SAMPLE_BEACON_FEATURE
help
Resample period if beacon drop is active under ESP_WIFI_SLP_BEACON_LOST_DROP_BEACON_AUTO mode.
It means never resample if setting this value to 0.
unit: hours
endmenu # "Beacon Sample Configuration Options"
config ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM
int "Maximum espnow encrypt peers number"
range 0 4 if IDF_TARGET_ESP32C2

View File

@@ -790,6 +790,24 @@ esp_err_t esp_wifi_disconnect_internal(void);
*/
uint32_t esp_wifi_internal_get_mac_clock_time(void);
#if CONFIG_ESP_WIFI_SLP_SAMPLE_BEACON_FEATURE
/**
* @brief Configure wifi beacon offset default parameters
*
* @param config: the configuration parameters for wifi beacon offset
*
* @return
* - ESP_OK: succeed
* - others: failed
*/
esp_err_t esp_wifi_beacon_offset_configure(wifi_beacon_offset_config_t *config);
#endif
/**
* @brief empty init pm_beacon_offset.
*/
void pm_beacon_offset_funcs_empty_init(void);
#ifdef __cplusplus
}
#endif

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -41,6 +41,16 @@ typedef struct {
} data; /**< Configuration of ioctl command */
} wifi_ioctl_config_t;
/**
* @brief Mode for WiFi beacon drop
*
*/
typedef enum {
WIFI_BEACON_DROP_DISABLED,
WIFI_BEACON_DROP_AUTO,
WIFI_BEACON_DROP_FORCED,
} wifi_beacon_drop_t;
/**
* @brief WiFi beacon monitor parameter configuration
*
@@ -59,8 +69,22 @@ typedef struct {
uint16_t modem_state_consecutive; /**< PMU MODEM state consecutive count limit */
uint16_t rf_ctrl_wait_cycle; /**< RF on wait time (unit: Modem APB clock cycle) */
#endif
wifi_beacon_drop_t beacon_drop; /**< Whether to drop the beacon if the beacon lost exceeds loss_threshold */
} wifi_beacon_monitor_config_t;
/**
* @brief WiFi beacon sample parameter configuration
*
*/
typedef struct {
uint16_t sample_period; /**< Sample beacon period, unit: number of beacons */
uint8_t resample_period; /**< Resample period if beacon drop is active under the auto mode, unit: hours */
/**< Standard triggers beacon drop when the expected rx beacon probability falls below this value under the auto mode, unit: percentage */
uint8_t standard;
/**< Difference triggers an unstable event when the actual rx beacon probability continuously falls below the expected probability by this value, unit: percentage */
uint8_t difference;
} wifi_beacon_offset_config_t;
#ifdef __cplusplus
}
#endif

View File

@@ -1840,6 +1840,21 @@ esp_err_t esp_wifi_action_tx_req(wifi_action_tx_req_t *req);
* - ESP_FAIL: failed to perform roc operation
*/
esp_err_t esp_wifi_remain_on_channel(wifi_roc_req_t * req);
#if CONFIG_ESP_WIFI_SLP_SAMPLE_BEACON_FEATURE
/**
* @brief Sample numbers of beacons to calculate beacon parameters
*
* @attention This API should be called after station connected to AP.
*
* @return
* - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
*/
esp_err_t esp_wifi_beacon_offset_sample_beacon(void);
#endif
#ifdef __cplusplus
}
#endif

View File

@@ -1110,6 +1110,7 @@ typedef enum {
WIFI_EVENT_AP_WRONG_PASSWORD, /**< a station tried to connect with wrong password */
WIFI_EVENT_STA_BEACON_OFFSET_UNSTABLE, /**< Station sampled beacon offset unstable */
WIFI_EVENT_MAX, /**< Invalid Wi-Fi event ID */
} wifi_event_t;
@@ -1509,6 +1510,11 @@ typedef struct {
typedef wifi_tx_info_t esp_80211_tx_info_t;
/** Argument structure for WIFI_EVENT_STA_BEACON_OFFSET_UNSTABLE event */
typedef struct {
float beacon_success_rate; /**< Received beacon success rate */
} wifi_event_sta_beacon_offset_unstable_t;
#ifdef __cplusplus
}
#endif

View File

@@ -64,6 +64,14 @@ static esp_pm_lock_handle_t s_wifi_modem_sleep_lock;
wifi_mac_time_update_cb_t s_wifi_mac_time_update_cb = NULL;
#endif
#if CONFIG_ESP_WIFI_SLP_BEACON_LOST_OVER_THRESHOLD_AUTO
#define ESP_WIFI_SLP_BEACON_LOST_DROP_BEACON_MODE WIFI_BEACON_DROP_AUTO
#elif CONFIG_ESP_WIFI_SLP_BEACON_LOST_OVER_THRESHOLD_DROP
#define ESP_WIFI_SLP_BEACON_LOST_DROP_BEACON_MODE WIFI_BEACON_DROP_FORCED
#else
#define ESP_WIFI_SLP_BEACON_LOST_DROP_BEACON_MODE WIFI_BEACON_DROP_DISABLED
#endif
#if SOC_PM_SUPPORT_PMU_MODEM_STATE
# define WIFI_BEACON_MONITOR_CONFIG_DEFAULT(ena) { \
.enable = (ena), \
@@ -75,7 +83,8 @@ wifi_mac_time_update_cb_t s_wifi_mac_time_update_cb = NULL;
.broadcast_wakeup = 1, \
.tsf_time_sync_deviation = 5, \
.modem_state_consecutive = 10, \
.rf_ctrl_wait_cycle = 20 \
.rf_ctrl_wait_cycle = 20, \
.beacon_drop = ESP_WIFI_SLP_BEACON_LOST_DROP_BEACON_MODE \
}
#else
# define WIFI_BEACON_MONITOR_CONFIG_DEFAULT(ena) { \
@@ -83,10 +92,18 @@ wifi_mac_time_update_cb_t s_wifi_mac_time_update_cb = NULL;
.loss_timeout = CONFIG_ESP_WIFI_SLP_BEACON_LOST_TIMEOUT, \
.loss_threshold = CONFIG_ESP_WIFI_SLP_BEACON_LOST_THRESHOLD, \
.delta_intr_early = CONFIG_ESP_WIFI_SLP_PHY_ON_DELTA_EARLY_TIME, \
.delta_loss_timeout = CONFIG_ESP_WIFI_SLP_PHY_OFF_DELTA_TIMEOUT_TIME \
.delta_loss_timeout = CONFIG_ESP_WIFI_SLP_PHY_OFF_DELTA_TIMEOUT_TIME, \
.beacon_drop = ESP_WIFI_SLP_BEACON_LOST_DROP_BEACON_MODE \
}
#endif
#define WIFI_BEACON_OFFSET_CONFIG_DEFAULT(ena) { \
.sample_period = (ena) ? CONFIG_ESP_WIFI_SLP_SAMPLE_BEACON_COUNT : 0, \
.resample_period = CONFIG_ESP_WIFI_SLP_SAMPLE_BEACON_RESAMPLE_PERIOD, \
.standard = CONFIG_ESP_WIFI_SLP_SAMPLE_BEACON_STANDARD_PERCENT, \
.difference = CONFIG_ESP_WIFI_SLP_SAMPLE_BEACON_DIFFERENCE_PERCENT \
}
static const char* TAG = "wifi_init";
static void __attribute__((constructor)) s_set_default_wifi_log_level(void)
@@ -185,6 +202,11 @@ static esp_err_t wifi_deinit_internal(void)
roam_deinit_app();
#endif
#if CONFIG_ESP_WIFI_SLP_SAMPLE_BEACON_FEATURE
wifi_beacon_offset_config_t offset_config = WIFI_BEACON_OFFSET_CONFIG_DEFAULT(false);
esp_wifi_beacon_offset_configure(&offset_config);
#endif
err = esp_wifi_deinit_internal();
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to deinit Wi-Fi driver (0x%x)", err);
@@ -460,6 +482,12 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config)
wifi_beacon_monitor_config_t monitor_config = WIFI_BEACON_MONITOR_CONFIG_DEFAULT(true);
esp_wifi_beacon_monitor_configure(&monitor_config);
#endif
#if CONFIG_ESP_WIFI_SLP_SAMPLE_BEACON_FEATURE
wifi_beacon_offset_config_t offset_config = WIFI_BEACON_OFFSET_CONFIG_DEFAULT(true);
esp_wifi_beacon_offset_configure(&offset_config);
#endif
adc2_cal_include(); //This enables the ADC2 calibration constructor at start up.
esp_wifi_config_info();
@@ -702,5 +730,6 @@ void esp32c2_eco4_rom_ptr_init(void)
void pm_beacon_offset_funcs_init(void)
{
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
pm_beacon_offset_funcs_empty_init();
}
#endif