]> granicus.if.org Git - esp-idf/commitdiff
esp_wifi: 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>
Wed, 22 May 2019 14:18:05 +0000 (22:18 +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. Add declaration for esp_wifi_internal_ioctl()
5. Fix the bug that WiFi stop leads to task watchdog

components/esp32/esp_adapter.c
components/esp_wifi/include/esp_private/wifi.h
components/esp_wifi/include/esp_private/wifi_os_adapter.h
components/esp_wifi/include/esp_wifi_types.h
components/esp_wifi/lib_esp32

index d34c2ac6e13f0207563e72ee95bc5ba78ba90b59..40888f5a53c7a9148779e62ed016657828593de2 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"
@@ -53,6 +54,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_SPIRAM_TRY_ALLOCATE_WIFI_LWIP is enabled. Prefer to allocate a chunk of memory in SPIRAM firstly.
  If failed, try to allocate it in internal memory then.
@@ -218,6 +221,41 @@ static void 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);
@@ -478,6 +516,7 @@ wifi_osi_funcs_t g_wifi_osi_funcs = {
     ._semphr_delete = semphr_delete_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,
index b6dea52a952aed89540d5300db85271a15f8c3fb..c8fbe90ed0bceeb47972283fb551dbcddc17d252 100644 (file)
@@ -307,6 +307,18 @@ esp_err_t esp_wifi_internal_set_log_mod(wifi_log_module_t module, uint32_t submo
   */
 esp_err_t esp_wifi_internal_get_log(wifi_log_level_t *log_level, uint32_t *log_mod);
 
+/**
+  * @brief     A general API to set/get WiFi internal configuration, it's for debug only
+  *
+  * @param     cmd : ioctl command type
+  * @param     cfg : configuration for the command
+  *
+  * @return    
+  *    - ESP_OK: succeed
+  *    - others: failed
+  */
+esp_err_t esp_wifi_internal_ioctl(int cmd, wifi_ioctl_config_t *cfg);
+
 #ifdef __cplusplus
 }
 #endif
index 752ccf990d77c3612d4916cf996f5671db08909d..165caa6edc547a9008239663d0785b6e345fc65b 100644 (file)
@@ -44,6 +44,7 @@ typedef struct {
     void (*_semphr_delete)(void *semphr);
     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 30c3d80dbedaff9d4c8f4ee2a81b6b63709b8c8e..8e930c555dfb8b4058234a55c6da27c5b3baa25c 100644 (file)
@@ -582,7 +582,33 @@ typedef struct {
     uint8_t mac[6];           /**< MAC address of the station which send probe request */
 } wifi_event_ap_probe_req_rx_t;
 
+/**
+  * @brief WiFi ioctl command type
+  *
+  */
+typedef enum {
+    WIFI_IOCTL_SET_STA_HT2040_COEX = 1, /**< Set the configuration of STA's HT2040 coexist management */
+    WIFI_IOCTL_GET_STA_HT2040_COEX,     /**< Get the configuration of STA's HT2040 coexist management */
+    WIFI_IOCTL_MAX,
+} wifi_ioctl_cmd_t;
 
+/**
+ * @brief Configuration for STA's HT2040 coexist management
+ *
+ */
+typedef struct {
+    int enable;                         /**< Indicate whether STA's HT2040 coexist management is enabled or not */
+} wifi_ht2040_coex_t;
+
+/**
+  * @brief Configuration for WiFi ioctl
+  *
+  */
+typedef struct {
+    union {
+        wifi_ht2040_coex_t ht2040_coex; /**< Configuration of STA's HT2040 coexist management */
+    } data;                             /**< Configuration of ioctl command */
+} wifi_ioctl_config_t;
 
 #ifdef __cplusplus
 }
index ef74d99a3732c6054c49901802ef657e45e110ed..da2bdc15f4198cdb515cef67772cd31c51e11929 160000 (submodule)
@@ -1 +1 @@
-Subproject commit ef74d99a3732c6054c49901802ef657e45e110ed
+Subproject commit da2bdc15f4198cdb515cef67772cd31c51e11929