Răsfoiți Sursa

Merge branch 'feature/amazon_freertos_compat_v2' into 'master'

Changes for Amazon Freertos compatibility

See merge request idf/esp-idf!2123
Ivan Grokhotkov 7 ani în urmă
părinte
comite
22fbcd276c

+ 6 - 6
components/driver/spi_common.c

@@ -438,7 +438,7 @@ bool IRAM_ATTR spicommon_dmaworkaround_req_reset(int dmachan, dmaworkaround_cb_t
 {
     int otherchan = (dmachan == 1) ? 2 : 1;
     bool ret;
-    portENTER_CRITICAL(&dmaworkaround_mux);
+    portENTER_CRITICAL_ISR(&dmaworkaround_mux);
     if (dmaworkaround_channels_busy[otherchan-1]) {
         //Other channel is busy. Call back when it's done.
         dmaworkaround_cb = cb;
@@ -450,7 +450,7 @@ bool IRAM_ATTR spicommon_dmaworkaround_req_reset(int dmachan, dmaworkaround_cb_t
         periph_module_reset( PERIPH_SPI_DMA_MODULE );
         ret = true;
     }
-    portEXIT_CRITICAL(&dmaworkaround_mux);
+    portEXIT_CRITICAL_ISR(&dmaworkaround_mux);
     return ret;
 }
 
@@ -461,7 +461,7 @@ bool IRAM_ATTR spicommon_dmaworkaround_reset_in_progress()
 
 void IRAM_ATTR spicommon_dmaworkaround_idle(int dmachan)
 {
-    portENTER_CRITICAL(&dmaworkaround_mux);
+    portENTER_CRITICAL_ISR(&dmaworkaround_mux);
     dmaworkaround_channels_busy[dmachan-1] = 0;
     if (dmaworkaround_waiting_for_chan == dmachan) {
         //Reset DMA
@@ -471,14 +471,14 @@ void IRAM_ATTR spicommon_dmaworkaround_idle(int dmachan)
         dmaworkaround_cb(dmaworkaround_cb_arg);
 
     }
-    portEXIT_CRITICAL(&dmaworkaround_mux);
+    portEXIT_CRITICAL_ISR(&dmaworkaround_mux);
 }
 
 void IRAM_ATTR spicommon_dmaworkaround_transfer_active(int dmachan)
 {
-    portENTER_CRITICAL(&dmaworkaround_mux);
+    portENTER_CRITICAL_ISR(&dmaworkaround_mux);
     dmaworkaround_channels_busy[dmachan-1] = 1;
-    portEXIT_CRITICAL(&dmaworkaround_mux);
+    portEXIT_CRITICAL_ISR(&dmaworkaround_mux);
 }
 
 

+ 1 - 2
components/esp32/cpu_start.c

@@ -38,8 +38,6 @@
 #include "freertos/queue.h"
 #include "freertos/portmacro.h"
 
-#include "tcpip_adapter.h"
-
 #include "esp_heap_caps_init.h"
 #include "sdkconfig.h"
 #include "esp_system.h"
@@ -55,6 +53,7 @@
 #include "esp_newlib.h"
 #include "esp_brownout.h"
 #include "esp_int_wdt.h"
+#include "esp_task.h"
 #include "esp_task_wdt.h"
 #include "esp_phy_init.h"
 #include "esp_cache_err_int.h"

+ 2 - 2
components/esp32/crosscore_int.c

@@ -61,10 +61,10 @@ static void IRAM_ATTR esp_crosscore_isr(void *arg) {
         DPORT_WRITE_PERI_REG(DPORT_CPU_INTR_FROM_CPU_1_REG, 0);
     }
     //Grab the reason and clear it.
-    portENTER_CRITICAL(&reason_spinlock);
+    portENTER_CRITICAL_ISR(&reason_spinlock);
     my_reason_val=*my_reason;
     *my_reason=0;
-    portEXIT_CRITICAL(&reason_spinlock);
+    portEXIT_CRITICAL_ISR(&reason_spinlock);
 
     //Check what we need to do.
     if (my_reason_val & REASON_YIELD) {

+ 5 - 5
components/esp32/esp_timer_esp32.c

@@ -243,7 +243,7 @@ void IRAM_ATTR esp_timer_impl_set_alarm(uint64_t timestamp)
 
 static void IRAM_ATTR timer_alarm_isr(void *arg)
 {
-    portENTER_CRITICAL(&s_time_update_lock);
+    portENTER_CRITICAL_ISR(&s_time_update_lock);
     // Timekeeping: adjust s_time_base_us if counter has passed ALARM_OVERFLOW_VAL
     if (timer_overflow_happened()) {
         timer_count_reload();
@@ -256,17 +256,17 @@ static void IRAM_ATTR timer_alarm_isr(void *arg)
     // Set alarm to the next overflow moment. Later, upper layer function may
     // call esp_timer_impl_set_alarm to change this to an earlier value.
     REG_WRITE(FRC_TIMER_ALARM_REG(1), ALARM_OVERFLOW_VAL);
-    portEXIT_CRITICAL(&s_time_update_lock);
+    portEXIT_CRITICAL_ISR(&s_time_update_lock);
     // Call the upper layer handler
     (*s_alarm_handler)(arg);
 }
 
 void IRAM_ATTR esp_timer_impl_update_apb_freq(uint32_t apb_ticks_per_us)
 {
-    portENTER_CRITICAL(&s_time_update_lock);
+    portENTER_CRITICAL_ISR(&s_time_update_lock);
     /* Bail out if the timer is not initialized yet */
     if (s_timer_interrupt_handle == NULL) {
-        portEXIT_CRITICAL(&s_time_update_lock);
+        portEXIT_CRITICAL_ISR(&s_time_update_lock);
         return;
     }
 
@@ -308,7 +308,7 @@ void IRAM_ATTR esp_timer_impl_update_apb_freq(uint32_t apb_ticks_per_us)
     s_timer_ticks_per_us = new_ticks_per_us;
     s_timer_us_per_overflow = ALARM_OVERFLOW_VAL / new_ticks_per_us;
 
-    portEXIT_CRITICAL(&s_time_update_lock);
+    portEXIT_CRITICAL_ISR(&s_time_update_lock);
 }
 
 esp_err_t esp_timer_impl_init(intr_handler_t alarm_handler)

+ 4 - 1
components/freertos/tasks.c

@@ -3878,6 +3878,10 @@ BaseType_t xTaskGetAffinity( TaskHandle_t xTask )
 
 	static void prvDeleteTCB( TCB_t *pxTCB )
 	{
+		/* This call is required for any port specific cleanup related to task.
+		It must be above the vPortFree() calls. */
+		portCLEAN_UP_TCB( pxTCB );
+
 		/* Free up the memory allocated by the scheduler for the task.  It is up
 		to the task to free any memory allocated at the application level. */
 		#if ( configUSE_NEWLIB_REENTRANT == 1 )
@@ -3920,7 +3924,6 @@ BaseType_t xTaskGetAffinity( TaskHandle_t xTask )
 				/* Neither the stack nor the TCB were allocated dynamically, so
 				nothing needs to be freed. */
 				configASSERT( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_AND_TCB	)
-				portCLEAN_UP_TCB( pxTCB );
 				mtCOVERAGE_TEST_MARKER();
 			}
 		}

+ 8 - 8
components/heap/heap_trace.c

@@ -77,7 +77,7 @@ esp_err_t heap_trace_start(heap_trace_mode_t mode_param)
     if (buffer == NULL || total_records == 0) {
         return ESP_ERR_INVALID_STATE;
     }
-    taskENTER_CRITICAL(&trace_mux);
+    portENTER_CRITICAL(&trace_mux);
 
     tracing = false;
     mode = mode_param;
@@ -87,7 +87,7 @@ esp_err_t heap_trace_start(heap_trace_mode_t mode_param)
     has_overflowed = false;
     heap_trace_resume();
 
-    taskEXIT_CRITICAL(&trace_mux);
+    portEXIT_CRITICAL(&trace_mux);
     return ESP_OK;
 }
 
@@ -128,13 +128,13 @@ esp_err_t heap_trace_get(size_t index, heap_trace_record_t *record)
     }
     esp_err_t result = ESP_OK;
 
-    taskENTER_CRITICAL(&trace_mux);
+    portENTER_CRITICAL(&trace_mux);
     if (index >= count) {
         result = ESP_ERR_INVALID_ARG; /* out of range for 'count' */
     } else {
         memcpy(record, &buffer[index], sizeof(heap_trace_record_t));
     }
-    taskEXIT_CRITICAL(&trace_mux);
+    portEXIT_CRITICAL(&trace_mux);
     return result;
 }
 
@@ -192,7 +192,7 @@ void heap_trace_dump(void)
 /* Add a new allocation to the heap trace records */
 static IRAM_ATTR void record_allocation(const heap_trace_record_t *record)
 {
-    taskENTER_CRITICAL(&trace_mux);
+    portENTER_CRITICAL(&trace_mux);
     if (tracing) {
         if (count == total_records) {
             has_overflowed = true;
@@ -211,7 +211,7 @@ static IRAM_ATTR void record_allocation(const heap_trace_record_t *record)
         count++;
         total_allocations++;
     }
-    taskEXIT_CRITICAL(&trace_mux);
+    portEXIT_CRITICAL(&trace_mux);
 }
 
 // remove a record, used when freeing
@@ -224,7 +224,7 @@ static void remove_record(int index);
 */
 static IRAM_ATTR void record_free(void *p, void **callers)
 {
-    taskENTER_CRITICAL(&trace_mux);
+    portENTER_CRITICAL(&trace_mux);
     if (tracing && count > 0) {
         total_frees++;
         /* search backwards for the allocation record matching this free */
@@ -244,7 +244,7 @@ static IRAM_ATTR void record_free(void *p, void **callers)
             }
         }
     }
-    taskEXIT_CRITICAL(&trace_mux);
+    portEXIT_CRITICAL(&trace_mux);
 }
 
 /* remove the entry at 'index' from the ringbuffer of saved records */

+ 2 - 3
components/heap/multi_heap_platform.h

@@ -16,7 +16,6 @@
 #ifdef ESP_PLATFORM
 
 #include <freertos/FreeRTOS.h>
-#include <freertos/task.h>
 #include <rom/ets_sys.h>
 #include <assert.h>
 
@@ -24,14 +23,14 @@
    we need to use portmux spinlocks here not RTOS mutexes */
 #define MULTI_HEAP_LOCK(PLOCK) do {               \
         if((PLOCK) != NULL) {                               \
-            taskENTER_CRITICAL((portMUX_TYPE *)(PLOCK));    \
+            portENTER_CRITICAL((portMUX_TYPE *)(PLOCK));    \
         }                                                   \
     } while(0)
 
 
 #define MULTI_HEAP_UNLOCK(PLOCK) do {                \
         if ((PLOCK) != NULL) {                              \
-            taskEXIT_CRITICAL((portMUX_TYPE *)(PLOCK));     \
+            portEXIT_CRITICAL((portMUX_TYPE *)(PLOCK));     \
         }                                                   \
     } while(0)
 

+ 5 - 0
components/newlib/include/sys/reent.h

@@ -446,6 +446,7 @@ extern const struct __sFILE_fake __sf_fake_stderr;
     _NULL \
   }
 
+#ifndef ESP_PLATFORM
 #define _REENT_INIT_PTR(var) \
   { memset((var), 0, sizeof(*(var))); \
     (var)->_stdin = (__FILE *)&__sf_fake_stdin; \
@@ -453,6 +454,10 @@ extern const struct __sFILE_fake __sf_fake_stderr;
     (var)->_stderr = (__FILE *)&__sf_fake_stderr; \
     (var)->_current_locale = "C"; \
   }
+#else
+extern void esp_reent_init(struct _reent* reent);
+#define _REENT_INIT_PTR(var) esp_reent_init(var)
+#endif
 
 /* Only built the assert() calls if we are built with debugging.  */
 #if DEBUG

+ 4 - 0
components/pthread/component.mk

@@ -7,3 +7,7 @@ COMPONENT_SRCDIRS := .
 COMPONENT_ADD_INCLUDEDIRS := include
 
 COMPONENT_ADD_LDFLAGS := -lpthread
+
+ifdef CONFIG_ENABLE_STATIC_TASK_CLEAN_UP_HOOK
+COMPONENT_ADD_LDFLAGS += -Wl,--wrap=vPortCleanUpTCB
+endif

+ 31 - 0
components/pthread/pthread_local_storage.c

@@ -142,6 +142,29 @@ static void pthread_local_storage_thread_deleted_callback(int index, void *v_tls
     free(tls);
 }
 
+#if defined(CONFIG_ENABLE_STATIC_TASK_CLEAN_UP_HOOK)
+/* Called from FreeRTOS task delete hook */
+void pthread_local_storage_cleanup(TaskHandle_t task)
+{
+    void *tls = pvTaskGetThreadLocalStoragePointer(task, PTHREAD_TLS_INDEX);
+    if (tls != NULL) {
+        pthread_local_storage_thread_deleted_callback(PTHREAD_TLS_INDEX, tls);
+        vTaskSetThreadLocalStoragePointer(task, PTHREAD_TLS_INDEX, NULL);
+    }
+}
+
+void __real_vPortCleanUpTCB(void *tcb);
+
+/* If static task cleanup hook is defined then its applications responsibility to define `vPortCleanUpTCB`.
+   Here we are wrapping it, so that we can do pthread specific TLS cleanup and then invoke application
+   real specific `vPortCleanUpTCB` */
+void __wrap_vPortCleanUpTCB(void *tcb)
+{
+    pthread_local_storage_cleanup(tcb);
+    __real_vPortCleanUpTCB(tcb);
+}
+#endif
+
 /* this function called from pthread_task_func for "early" cleanup of TLS in a pthread */
 void pthread_internal_local_storage_destructor_callback()
 {
@@ -151,10 +174,14 @@ void pthread_internal_local_storage_destructor_callback()
         /* remove the thread-local-storage pointer to avoid the idle task cleanup
            calling it again...
         */
+#if defined(CONFIG_ENABLE_STATIC_TASK_CLEAN_UP_HOOK)
+        vTaskSetThreadLocalStoragePointer(NULL, PTHREAD_TLS_INDEX, NULL);
+#else
         vTaskSetThreadLocalStoragePointerAndDelCallback(NULL,
                                                         PTHREAD_TLS_INDEX,
                                                         NULL,
                                                         NULL);
+#endif
     }
 }
 
@@ -196,10 +223,14 @@ int pthread_setspecific(pthread_key_t key, const void *value)
         if (tls == NULL) {
             return ENOMEM;
         }
+#if defined(CONFIG_ENABLE_STATIC_TASK_CLEAN_UP_HOOK)
+        vTaskSetThreadLocalStoragePointer(NULL, PTHREAD_TLS_INDEX, tls);
+#else
         vTaskSetThreadLocalStoragePointerAndDelCallback(NULL,
                                                         PTHREAD_TLS_INDEX,
                                                         tls,
                                                         pthread_local_storage_thread_deleted_callback);
+#endif
     }
 
     value_entry_t *entry = find_value(tls, key);

+ 2 - 0
components/smartconfig/component.mk

@@ -0,0 +1,2 @@
+#
+# Component Makefile

+ 0 - 0
components/esp32/smartconfig.h → components/smartconfig/include/smartconfig.h


+ 0 - 0
components/esp32/smartconfig.c → components/smartconfig/smartconfig.c


+ 1 - 1
components/wpa_supplicant/port/include/os.h

@@ -19,7 +19,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include "rom/ets_sys.h"
-#include "lwip/mem.h"
+
 typedef long os_time_t;
 
 /**