Просмотр исходного кода

freertos: Refactor port common functions

This commit refactors port_common.c so that it only contains implementation of
FreeRTOS port functions that are common to all FreeRTOS ports (i.e., on all
architectures and on all FreeRTOS implementations).
Darian Leung 3 лет назад
Родитель
Сommit
486cc33fb3

+ 1 - 1
components/freertos/CMakeLists.txt

@@ -53,6 +53,7 @@ else()
     list(APPEND srcs
         "app_startup.c"
         "FreeRTOS-openocd.c"
+        "port_common.c"
         "${kernel_dir}/portable/${arch}/portasm.S")
 
     list(APPEND private_include_dirs
@@ -63,7 +64,6 @@ else()
         list(APPEND include_dirs "${kernel_dir}/portable/${arch}/include/freertos") # Xtensa headers via #include "xx.h"
     else()
         list(APPEND srcs
-            "${kernel_dir}/portable/port_common.c"
             "${kernel_dir}/portable/port_systick.c"
             "esp_additions/freertos_v8_compat.c")
 

+ 0 - 66
components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/port.c

@@ -385,72 +385,6 @@ void vPortFreeStack( void *pv )
 }
 #endif
 
-#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
-void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
-                                   StackType_t **ppxIdleTaskStackBuffer,
-                                   uint32_t *pulIdleTaskStackSize )
-{
-    StackType_t *pxStackBufferTemp;
-    StaticTask_t *pxTCBBufferTemp;
-
-    /* If the stack grows down then allocate the stack then the TCB so the stack
-     * does not grow into the TCB.  Likewise if the stack grows up then allocate
-     * the TCB then the stack. */
-    #if (portSTACK_GROWTH > 0)
-    {
-        //Allocate TCB and stack buffer in internal memory
-        pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
-        pxStackBufferTemp = pvPortMalloc(configMINIMAL_STACK_SIZE);
-    }
-    #else /* portSTACK_GROWTH */
-    {
-        //Allocate TCB and stack buffer in internal memory
-        pxStackBufferTemp = pvPortMalloc(configMINIMAL_STACK_SIZE);
-        pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
-    }
-    #endif /* portSTACK_GROWTH */
-
-    assert(pxStackBufferTemp != NULL);
-    assert(pxTCBBufferTemp != NULL);
-    // Write back pointers
-    *ppxIdleTaskStackBuffer = pxStackBufferTemp;
-    *ppxIdleTaskTCBBuffer = pxTCBBufferTemp;
-    *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
-}
-
-void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer,
-                                    StackType_t **ppxTimerTaskStackBuffer,
-                                    uint32_t *pulTimerTaskStackSize )
-{
-    StaticTask_t *pxTCBBufferTemp;
-    StackType_t *pxStackBufferTemp;
-
-    /* If the stack grows down then allocate the stack then the TCB so the stack
-     * does not grow into the TCB.  Likewise if the stack grows up then allocate
-     * the TCB then the stack. */
-    #if (portSTACK_GROWTH > 0)
-    {
-        //Allocate TCB and stack buffer in internal memory
-        pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
-        pxStackBufferTemp = pvPortMalloc(configTIMER_TASK_STACK_DEPTH);
-    }
-    #else /* portSTACK_GROWTH */
-    {
-        //Allocate TCB and stack buffer in internal memory
-        pxStackBufferTemp = pvPortMalloc(configTIMER_TASK_STACK_DEPTH);
-        pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
-    }
-    #endif /* portSTACK_GROWTH */
-
-    assert(pxTCBBufferTemp != NULL);
-    assert(pxStackBufferTemp != NULL);
-    //Write back pointers
-    *ppxTimerTaskTCBBuffer = pxTCBBufferTemp;
-    *ppxTimerTaskStackBuffer = pxStackBufferTemp;
-    *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
-}
-#endif //( configSUPPORT_STATIC_ALLOCATION == 1 )
-
 // ------------------------ Stack --------------------------
 
 /**

+ 0 - 66
components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c

@@ -406,72 +406,6 @@ void vPortFreeStack( void *pv )
 }
 #endif
 
-#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
-void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
-                                   StackType_t **ppxIdleTaskStackBuffer,
-                                   uint32_t *pulIdleTaskStackSize )
-{
-    StackType_t *pxStackBufferTemp;
-    StaticTask_t *pxTCBBufferTemp;
-
-    /* If the stack grows down then allocate the stack then the TCB so the stack
-     * does not grow into the TCB.  Likewise if the stack grows up then allocate
-     * the TCB then the stack. */
-    #if (portSTACK_GROWTH > 0)
-    {
-        //Allocate TCB and stack buffer in internal memory
-        pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
-        pxStackBufferTemp = pvPortMalloc(configMINIMAL_STACK_SIZE);
-    }
-    #else /* portSTACK_GROWTH */
-    {
-        //Allocate TCB and stack buffer in internal memory
-        pxStackBufferTemp = pvPortMalloc(configMINIMAL_STACK_SIZE);
-        pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
-    }
-    #endif /* portSTACK_GROWTH */
-
-    assert(pxStackBufferTemp != NULL);
-    assert(pxTCBBufferTemp != NULL);
-    // Write back pointers
-    *ppxIdleTaskStackBuffer = pxStackBufferTemp;
-    *ppxIdleTaskTCBBuffer = pxTCBBufferTemp;
-    *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
-}
-
-void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer,
-                                    StackType_t **ppxTimerTaskStackBuffer,
-                                    uint32_t *pulTimerTaskStackSize )
-{
-    StaticTask_t *pxTCBBufferTemp;
-    StackType_t *pxStackBufferTemp;
-
-    /* If the stack grows down then allocate the stack then the TCB so the stack
-     * does not grow into the TCB.  Likewise if the stack grows up then allocate
-     * the TCB then the stack. */
-    #if (portSTACK_GROWTH > 0)
-    {
-        //Allocate TCB and stack buffer in internal memory
-        pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
-        pxStackBufferTemp = pvPortMalloc(configTIMER_TASK_STACK_DEPTH);
-    }
-    #else /* portSTACK_GROWTH */
-    {
-        //Allocate TCB and stack buffer in internal memory
-        pxStackBufferTemp = pvPortMalloc(configTIMER_TASK_STACK_DEPTH);
-        pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
-    }
-    #endif /* portSTACK_GROWTH */
-
-    assert(pxTCBBufferTemp != NULL);
-    assert(pxStackBufferTemp != NULL);
-    //Write back pointers
-    *ppxTimerTaskTCBBuffer = pxTCBBufferTemp;
-    *ppxTimerTaskStackBuffer = pxStackBufferTemp;
-    *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
-}
-#endif //( configSUPPORT_STATIC_ALLOCATION == 1 )
-
 // ------------------------ Stack --------------------------
 
 // User exception dispatcher when exiting

+ 4 - 0
components/freertos/FreeRTOS-Kernel/portable/linux/port_idf.c

@@ -95,6 +95,7 @@ void vApplicationTickHook( void )
 
 void vPortYieldOtherCore( BaseType_t coreid ) { } // trying to skip for now
 
+#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
  * implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
  * used by the Idle task. */
@@ -120,8 +121,10 @@ void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
      * configMINIMAL_STACK_SIZE is specified in words, not bytes. */
     *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
 }
+#endif // configSUPPORT_STATIC_ALLOCATION == 1
 /*-----------------------------------------------------------*/
 
+#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
  * application must provide an implementation of vApplicationGetTimerTaskMemory()
  * to provide the memory that is used by the Timer service task. */
@@ -146,6 +149,7 @@ void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
      * configMINIMAL_STACK_SIZE is specified in words, not bytes. */
     *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
 }
+#endif // configSUPPORT_STATIC_ALLOCATION == 1
 
 void __attribute__((weak)) vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName)
 {

+ 39 - 18
components/freertos/FreeRTOS-Kernel/portable/port_common.c → components/freertos/port_common.c

@@ -11,8 +11,14 @@
 #include "esp_memory_utils.h"
 #include "sdkconfig.h"
 
+/* ----------------------------------------- Port Implementations (Common)  --------------------------------------------
+ * - Common FreeRTOS port function implementations
+ * - These functions are common to all FreeRTOS ports (i.e., on all architectures and all FreeRTOS implementations).
+ * ------------------------------------------------------------------------------------------------------------------ */
+
 // -------------------- Heap Related -----------------------
 
+#if !CONFIG_FREERTOS_SMP    // IDF-3997
 bool xPortCheckValidTCBMem(const void *ptr)
 {
     return esp_ptr_internal(ptr) && esp_ptr_byte_accessible(ptr);
@@ -26,16 +32,18 @@ bool xPortcheckValidStackMem(const void *ptr)
     return esp_ptr_internal(ptr) && esp_ptr_byte_accessible(ptr);
 #endif
 }
+#endif
 
 // ------------- FreeRTOS Static Allocation ----------------
 
 /*
-This function is required by FreeRTOS when configSUPPORT_STATIC_ALLOCATION is
-enabled and is used by FreeRTOS to obtain memory for its IDLE tasks.
+These function are required by FreeRTOS when configSUPPORT_STATIC_ALLOCATION is
+enabled and is used by FreeRTOS to obtain memory for its IDLE/Timer tasks.
 
 Like the pvPortMallocTcbMem() and pvPortMallocStackMem() macros, TCB and stack
 memory MUST be placed in internal RAM.
 */
+#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
 void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
                                    StackType_t **ppxIdleTaskStackBuffer,
                                    uint32_t *pulIdleTaskStackSize )
@@ -49,14 +57,24 @@ void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
     #if (portSTACK_GROWTH > 0)
     {
         //Allocate TCB and stack buffer in internal memory
-        pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
-        pxStackBufferTemp = pvPortMallocStackMem(configMINIMAL_STACK_SIZE);
+        #if CONFIG_FREERTOS_SMP     // IDF-3997
+            pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
+            pxStackBufferTemp = pvPortMalloc(configMINIMAL_STACK_SIZE);
+        #else
+            pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
+            pxStackBufferTemp = pvPortMallocStackMem(configMINIMAL_STACK_SIZE);
+        #endif /* CONFIG_FREERTOS_SMP */
     }
     #else /* portSTACK_GROWTH */
     {
         //Allocate TCB and stack buffer in internal memory
-        pxStackBufferTemp = pvPortMallocStackMem(configMINIMAL_STACK_SIZE);
-        pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
+        #if CONFIG_FREERTOS_SMP     // IDF-3997
+            pxStackBufferTemp = pvPortMalloc(configMINIMAL_STACK_SIZE);
+            pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
+        #else
+            pxStackBufferTemp = pvPortMallocStackMem(configMINIMAL_STACK_SIZE);
+            pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
+        #endif /* CONFIG_FREERTOS_SMP */
     }
     #endif /* portSTACK_GROWTH */
 
@@ -68,14 +86,6 @@ void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
     *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
 }
 
-/*
-This function is required by FreeRTOS when configSUPPORT_STATIC_ALLOCATION is
-enabled and is used by the FreeRTOS Timer to obtain memory for its daemone task.
-
-
-Like the pvPortMallocTcbMem() and pvPortMallocStackMem() macros, TCB and stack
-memory MUST be placed in internal RAM.
-*/
 void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer,
                                     StackType_t **ppxTimerTaskStackBuffer,
                                     uint32_t *pulTimerTaskStackSize )
@@ -89,14 +99,24 @@ void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer,
     #if (portSTACK_GROWTH > 0)
     {
         //Allocate TCB and stack buffer in internal memory
-        pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
-        pxStackBufferTemp = pvPortMallocStackMem(configTIMER_TASK_STACK_DEPTH);
+        #if CONFIG_FREERTOS_SMP     // IDF-3997
+            pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
+            pxStackBufferTemp = pvPortMalloc(configTIMER_TASK_STACK_DEPTH);
+        #else
+            pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
+            pxStackBufferTemp = pvPortMallocStackMem(configTIMER_TASK_STACK_DEPTH);
+        #endif /* CONFIG_FREERTOS_SMP */
     }
     #else /* portSTACK_GROWTH */
     {
         //Allocate TCB and stack buffer in internal memory
-        pxStackBufferTemp = pvPortMallocStackMem(configTIMER_TASK_STACK_DEPTH);
-        pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
+        #if CONFIG_FREERTOS_SMP     // IDF-3997
+            pxStackBufferTemp = pvPortMalloc(configTIMER_TASK_STACK_DEPTH);
+            pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
+        #else
+            pxStackBufferTemp = pvPortMallocStackMem(configTIMER_TASK_STACK_DEPTH);
+            pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
+        #endif /* CONFIG_FREERTOS_SMP */
     }
     #endif /* portSTACK_GROWTH */
 
@@ -107,3 +127,4 @@ void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer,
     *ppxTimerTaskStackBuffer = pxStackBufferTemp;
     *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
 }
+#endif // configSUPPORT_STATIC_ALLOCATION == 1