]> granicus.if.org Git - esp-idf/commitdiff
esp32: fix some WiFi bugs
authorliu zhifu <liuzhifu@espressif.com>
Fri, 26 Apr 2019 05:50:06 +0000 (13:50 +0800)
committerliu zhifu <liuzhifu@espressif.com>
Sun, 30 Jun 2019 08:14:07 +0000 (16:14 +0800)
Fix following WiFi bugs:
1. Make smartconfig thread-safe
2. Fix WiFi stop/deinit memory leak
3. Refactor for WiFi init/deinit/ioctl etc
4. Fix the bug that WiFi stop leads to task watchdog

components/esp32/include/esp_wifi_os_adapter.h
components/esp32/lib
components/esp32/wifi_os_adapter.c

index 1dd522c49c0b1a8bf32608871121a877d177759b..ba7c2d06ad567fa5e68fa953e24363afca665c56 100644 (file)
@@ -47,6 +47,7 @@ typedef struct {
     int32_t (*_semphr_give_from_isr)(void *semphr, void *hptw);
     int32_t (*_semphr_take)(void *semphr, uint32_t block_time_tick);
     int32_t (*_semphr_give)(void *semphr);
+    void *(*_wifi_thread_semphr_get)(void);
     void *(*_mutex_create)(void);
     void *(*_recursive_mutex_create)(void);
     void (*_mutex_delete)(void *mutex);
index 7def1ca81715689275e401b7e1d674b552738ea8..d4fc472cb423e18067623ffbf572e789429fcd57 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 7def1ca81715689275e401b7e1d674b552738ea8
+Subproject commit d4fc472cb423e18067623ffbf572e789429fcd57
index e63b0135fcd85fb8ddee5718fba8dd4296346070..cfe3d292391fd96953f7e6c434e218bcb5722c5b 100644 (file)
@@ -17,6 +17,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <assert.h>
+#include <pthread.h>
 
 #include "freertos/FreeRTOS.h"
 #include "freertos/task.h"
@@ -51,6 +52,8 @@
 extern void esp_dport_access_stall_other_cpu_start_wrap(void);
 extern void esp_dport_access_stall_other_cpu_end_wrap(void);
 
+#define TAG "esp_adapter"
+
 /*
  If CONFIG_WIFI_LWIP_ALLOCATION_FROM_SPIRAM_FIRST is enabled. Prefer to allocate a chunk of memory in SPIRAM firstly.
  If failed, try to allocate it in internal memory then.
@@ -216,6 +219,41 @@ static void IRAM_ATTR semphr_delete_wrapper(void *semphr)
     vSemaphoreDelete(semphr);
 }
 
+static void wifi_thread_semphr_free(void* data)
+{
+    xSemaphoreHandle *sem = (xSemaphoreHandle*)(data);
+
+    if (sem) {
+        vSemaphoreDelete(sem);
+    }
+}
+
+static void * wifi_thread_semphr_get_wrapper(void)
+{
+    static bool s_wifi_thread_sem_key_init = false;
+    static pthread_key_t s_wifi_thread_sem_key;
+    xSemaphoreHandle sem = NULL;
+
+    if (s_wifi_thread_sem_key_init == false) {
+        if (0 != pthread_key_create(&s_wifi_thread_sem_key, wifi_thread_semphr_free)) {
+            return NULL;
+        }
+        s_wifi_thread_sem_key_init = true;
+    }
+
+    sem = pthread_getspecific(s_wifi_thread_sem_key);
+    if (!sem) {
+        sem = xSemaphoreCreateCounting(1, 0);
+        if (sem) {
+            pthread_setspecific(s_wifi_thread_sem_key, sem);
+            ESP_LOGV(TAG, "thread sem create: sem=%p", sem);
+        }
+    }
+
+    ESP_LOGV(TAG, "thread sem get: sem=%p", sem);
+    return (void*)sem;
+}
+
 static int32_t IRAM_ATTR semphr_take_from_isr_wrapper(void *semphr, void *hptw)
 {
     return (int32_t)xSemaphoreTakeFromISR(semphr, hptw);
@@ -414,6 +452,7 @@ wifi_osi_funcs_t g_wifi_osi_funcs = {
     ._semphr_give_from_isr = semphr_give_from_isr_wrapper,
     ._semphr_take = semphr_take_wrapper,
     ._semphr_give = semphr_give_wrapper,
+    ._wifi_thread_semphr_get = wifi_thread_semphr_get_wrapper,
     ._mutex_create = mutex_create_wrapper,
     ._recursive_mutex_create = recursive_mutex_create_wrapper,
     ._mutex_delete = mutex_delete_wrapper,