power save: wifi beacon monitor support for esp32c6

power save: fix multicast more data always true cause wifi goto sleep fail
This commit is contained in:
Li Shuai 2023-02-05 17:03:07 +08:00 committed by wuzhenghui
parent 8a69bc4f9e
commit 7ee1b09433
7 changed files with 64 additions and 14 deletions

View File

@ -338,10 +338,10 @@ menu "Wi-Fi"
help
WiFi module can be compiled without SoftAP to save code size.
config ESP_WIFI_AUTO_BEACON_ENABLE
config ESP_WIFI_ENHANCED_LIGHT_SLEEP
bool "WiFi modem automatically receives the beacon"
default n
depends on ESP_PHY_MAC_BB_PD
depends on ESP_PHY_MAC_BB_PD && SOC_PM_SUPPORT_BEACON_WAKEUP
help
The wifi modem automatically receives the beacon frame during light sleep.
@ -372,7 +372,7 @@ menu "Wi-Fi"
int "Delta early time for RF PHY on"
range 0 100
default 2
depends on ESP_WIFI_SLP_BEACON_LOST_OPT
depends on ESP_WIFI_SLP_BEACON_LOST_OPT && SOC_WIFI_SUPPORT_VARIABLE_BEACON_WINDOW
help
Delta early time for rf phy on, When the beacon is lost, the next rf phy on will
be earlier the time specified by the configuration item, Unit: 32 microsecond.
@ -381,7 +381,7 @@ menu "Wi-Fi"
int "Delta timeout time for RF PHY off"
range 0 8
default 2
depends on ESP_WIFI_SLP_BEACON_LOST_OPT
depends on ESP_WIFI_SLP_BEACON_LOST_OPT && SOC_WIFI_SUPPORT_VARIABLE_BEACON_WINDOW
help
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.

View File

@ -624,11 +624,9 @@ void esp_wifi_set_keep_alive_time(uint32_t keep_alive_time);
/**
* @brief Configure wifi beacon montior default parameters
*
* @param enable: enable or disable beacon monitor
* @param timeout: timeout time for close rf phy when beacon loss occurs, Unit: 1024 microsecond
* @param threshold: maximum number of consecutive lost beacons allowed
* @param config: the configuration parameters for wifi beacon monitor
*/
void esp_wifi_beacon_monitor_configure(bool enable, int timeout, int threshold, int delta_intr_early, int delta_timeout);
void esp_wifi_beacon_monitor_configure(wifi_beacon_monitor_config_t *config);
/**
* @brief Require WiFi to enable or disable Advanced DTIM sleep function

View File

@ -891,6 +891,23 @@ typedef struct {
uint8_t peer_macaddr[6]; /**< Enrollee mac address */
} wifi_event_ap_wps_rg_success_t;
/** WiFi beacon monitor parameter configuration */
typedef struct {
bool enable; /**< Enable or disable beacon monitor */
uint8_t loss_timeout; /**< Beacon lost timeout */
uint8_t loss_threshold; /**< Maximum number of consecutive lost beacons allowed */
uint8_t delta_intr_early; /**< Delta early time for RF PHY on */
uint8_t delta_loss_timeout; /**< Delta timeout time for RF PHY off */
#if MAC_SUPPORT_PMU_MODEM_STATE
uint8_t beacon_abort: 1, /**< Enable or disable beacon abort */
broadcast_wakeup: 1, /**< Enable or disable TIM element multicast wakeup */
reserved: 6; /**< Reserved */
uint8_t tsf_time_sync_deviation; /**< Deviation range to sync with AP TSF timestamp */
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_monitor_config_t;
#ifdef __cplusplus
}
#endif

View File

@ -56,6 +56,28 @@ uint64_t g_wifi_feature_caps =
#endif
0;
#if SOC_PM_SUPPORT_PMU_MODEM_STATE
# define WIFI_BEACON_MONITOR_CONFIG_DEFAULT(ena) { \
.enable = (ena), \
.loss_timeout = CONFIG_ESP_WIFI_SLP_BEACON_LOST_TIMEOUT, \
.loss_threshold = CONFIG_ESP_WIFI_SLP_BEACON_LOST_THRESHOLD, \
.delta_intr_early = 0, \
.delta_loss_timeout = 0, \
.beacon_abort = 1, \
.broadcast_wakeup = 1, \
.tsf_time_sync_deviation = 5, \
.modem_state_consecutive = 10, \
.rf_ctrl_wait_cycle = 20 \
}
#else
# define WIFI_BEACON_MONITOR_CONFIG_DEFAULT(ena) { \
.enable = (ena), \
.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 \
}
#endif
static const char* TAG = "wifi_init";
@ -113,7 +135,8 @@ esp_err_t esp_wifi_deinit(void)
}
#if CONFIG_ESP_WIFI_SLP_BEACON_LOST_OPT
esp_wifi_beacon_monitor_configure(false, 0, 0, 0, 0);
wifi_beacon_monitor_config_t monitor_config = WIFI_BEACON_MONITOR_CONFIG_DEFAULT(false);
esp_wifi_beacon_monitor_configure(&monitor_config);
#endif
#if CONFIG_ESP_WIFI_SLP_IRAM_OPT
@ -124,7 +147,7 @@ esp_err_t esp_wifi_deinit(void)
esp_pm_unregister_skip_light_sleep_callback(esp_wifi_internal_is_tsf_active);
esp_pm_unregister_inform_out_light_sleep_overhead_callback(esp_wifi_internal_update_light_sleep_wake_ahead_time);
esp_sleep_disable_wifi_wakeup();
# if CONFIG_ESP_WIFI_AUTO_BEACON_ENABLE
# if CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP
esp_sleep_disable_wifi_beacon_wakeup();
# endif
#endif /* SOC_WIFI_HW_TSF */
@ -240,7 +263,7 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config)
return ret;
}
esp_sleep_enable_wifi_wakeup();
# if CONFIG_ESP_WIFI_AUTO_BEACON_ENABLE
# if CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP
esp_sleep_enable_wifi_beacon_wakeup();
# endif
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
@ -276,9 +299,8 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config)
}
}
#if CONFIG_ESP_WIFI_SLP_BEACON_LOST_OPT
esp_wifi_beacon_monitor_configure(true, CONFIG_ESP_WIFI_SLP_BEACON_LOST_TIMEOUT,
CONFIG_ESP_WIFI_SLP_BEACON_LOST_THRESHOLD, CONFIG_ESP_WIFI_SLP_PHY_ON_DELTA_EARLY_TIME,
CONFIG_ESP_WIFI_SLP_PHY_OFF_DELTA_TIMEOUT_TIME);
wifi_beacon_monitor_config_t monitor_config = WIFI_BEACON_MONITOR_CONFIG_DEFAULT(true);
esp_wifi_beacon_monitor_configure(&monitor_config);
#endif
adc2_cal_include(); //This enables the ADC2 calibration constructor at start up.

View File

@ -457,6 +457,9 @@
#define SOC_PM_SUPPORT_MAC_BB_PD (1)
#define SOC_PM_SUPPORT_PMU_MODEM_STATE (1)
/* macro redefine for pass esp_wifi headers md5sum check */
#define MAC_SUPPORT_PMU_MODEM_STATE SOC_PM_SUPPORT_PMU_MODEM_STATE
#define SOC_PM_SUPPORT_DEEPSLEEP_CHECK_STUB_ONLY (1) /*!<Supports CRC only the stub code in RTC memory */

View File

@ -20,6 +20,14 @@ menu "Example Configuration"
For example, if beacon interval is 100 ms and listen interval is 3, the interval for station to listen
to beacon is 300 ms.
config EXAMPLE_WIFI_BEACON_TIMEOUT
int "WiFi beacon timeout"
default 6
range 6 30
help
For Station, If the station does not receive a beacon frame from the connected SoftAP during the
inactive time, disconnect from SoftAP. Default 6s.
choice EXAMPLE_POWER_SAVE_MODE
prompt "power save mode"
default EXAMPLE_POWER_SAVE_MIN_MODEM

View File

@ -25,6 +25,7 @@
#define DEFAULT_PWD CONFIG_EXAMPLE_WIFI_PASSWORD
#define DEFAULT_LISTEN_INTERVAL CONFIG_EXAMPLE_WIFI_LISTEN_INTERVAL
#define DEFAULT_BEACON_TIMEOUT CONFIG_EXAMPLE_WIFI_BEACON_TIMEOUT
#if CONFIG_EXAMPLE_POWER_SAVE_MIN_MODEM
#define DEFAULT_PS_MODE WIFI_PS_MIN_MODEM
@ -76,6 +77,7 @@ static void wifi_power_save(void)
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());
ESP_ERROR_CHECK(esp_wifi_set_inactive_time(WIFI_IF_STA, DEFAULT_BEACON_TIMEOUT));
ESP_LOGI(TAG, "esp_wifi_set_ps().");
esp_wifi_set_ps(DEFAULT_PS_MODE);