mirror of
https://github.com/espressif/esp-idf.git
synced 2024-09-20 00:36:01 -04:00
wpa_supplicant: Run eloop timer in ppTask context
Currently eloop runs in timer context which may cause some inconsistent behavior. Add changes to run eloop in ppTask context
This commit is contained in:
parent
554f3bdc38
commit
404aa30290
@ -16,6 +16,7 @@
|
||||
#include "common.h"
|
||||
#include "list.h"
|
||||
#include "eloop.h"
|
||||
#include "esp_wifi_driver.h"
|
||||
|
||||
struct eloop_timeout {
|
||||
struct dl_list list;
|
||||
@ -42,12 +43,29 @@ static void *eloop_data_lock = NULL;
|
||||
|
||||
static struct eloop_data eloop;
|
||||
|
||||
static int eloop_run_wrapper(void *data)
|
||||
{
|
||||
eloop_run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void eloop_run_timer(void)
|
||||
{
|
||||
/* Execute timers in pptask context to make it thread safe */
|
||||
wifi_ipc_config_t cfg;
|
||||
|
||||
cfg.fn = eloop_run_wrapper;
|
||||
cfg.arg = NULL;
|
||||
cfg.arg_size = 0;
|
||||
esp_wifi_ipc_internal(&cfg, false);
|
||||
}
|
||||
|
||||
int eloop_init(void)
|
||||
{
|
||||
os_memset(&eloop, 0, sizeof(eloop));
|
||||
dl_list_init(&eloop.timeout);
|
||||
os_timer_disarm(&eloop.eloop_timer);
|
||||
os_timer_setfn(&eloop.eloop_timer, (ETSTimerFunc *)eloop_run, NULL);
|
||||
os_timer_setfn(&eloop.eloop_timer, (ETSTimerFunc *)eloop_run_timer, NULL);
|
||||
|
||||
eloop_data_lock = os_recursive_mutex_create();
|
||||
|
||||
|
@ -54,14 +54,20 @@ extern const wifi_osi_funcs_t *wifi_funcs;
|
||||
/* Check if eloop runs its timers correctly & in correct order */
|
||||
TEST_CASE("Test eloop timers run", "[eloop]")
|
||||
{
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
cfg.nvs_enable = false;
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
TEST_ESP_OK(esp_wifi_stop());
|
||||
TEST_ESP_OK(esp_wifi_deinit());
|
||||
/* Reset memory stats since some is leaked during the first initialization */
|
||||
test_utils_record_free_mem();
|
||||
|
||||
int execution_order[6] = {1, 5, 3, 0, 2, 4};
|
||||
int index[6] = {0,1,2,3,4,5};
|
||||
t = 0;
|
||||
|
||||
wifi_funcs = WIFI_OSI_FUNCS_INITIALIZER();
|
||||
if (!wifi_funcs) {
|
||||
TEST_ASSERT(1);
|
||||
}
|
||||
eloop_init();
|
||||
/* We need pptask to run eloop, wifi init will do that */
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
os_get_reltime(&ts);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
eloop_register_timeout(timeouts_sec[i], timeouts_usec[i],
|
||||
@ -70,8 +76,9 @@ TEST_CASE("Test eloop timers run", "[eloop]")
|
||||
|
||||
/* wait for all timers to run */
|
||||
os_sleep(20, 0);
|
||||
t = 0;
|
||||
/* check the execution order, this will also check whether they were fired at correct time */
|
||||
TEST_ASSERT(memcmp(execution_order, executed_order, 6*sizeof(int)) == 0);
|
||||
eloop_destroy();
|
||||
TEST_ESP_OK(esp_wifi_stop());
|
||||
TEST_ESP_OK(esp_wifi_deinit());
|
||||
os_sleep(3, 0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user