Przeglądaj źródła

freertos: Update SMP idle hooks

This commit updates the usage of idle hooks in SMP FreeRTOS as follows:

- IDF style idle hooks are now called from vApplicationMinimalIdleHook()
- If the user provdies their own vApplicationMinimalIdleHook(), it can be
  wrapped using -Wl,--wrap if CONFIG_FREERTOS_USE_MINIMAL_IDLE_HOOK is
  enabled.
- SMP port no longer uses vApplicationIdleHook() as it's only called from
  the prvIdleTask() and not every prvMinimalIdleTask()
Darian Leung 3 lat temu
rodzic
commit
e6d43ab56f

+ 6 - 0
CMakeLists.txt

@@ -206,6 +206,12 @@ else()
     list(APPEND link_options "-Wl,--gc-sections")
 endif()
 
+# SMP FreeRTOS user provided minimal idle hook. This allows the user to provide
+# their own copy of vApplicationMinimalIdleHook()
+if(CONFIG_FREERTOS_USE_MINIMAL_IDLE_HOOK)
+    list(APPEND link_options "-Wl,--wrap=vApplicationMinimalIdleHook")
+endif()
+
 # Placing jump tables in flash would cause issues with code that required
 # to be placed in IRAM
 list(APPEND compile_options "-fno-jump-tables")

+ 5 - 1
components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/include/freertos/FreeRTOSConfig_smp.h

@@ -148,7 +148,7 @@ This file get's pulled into assembly sources. Therefore, some includes need to b
 #endif
 #define configUSE_CORE_AFFINITY                         1
 #define configRUN_MULTIPLE_PRIORITIES                   1
-#define configUSE_MINIMAL_IDLE_HOOK                     1
+#define configUSE_MINIMAL_IDLE_HOOK                     1   // This is always enabled to call IDF style idle hooks, by can be "--Wl,--wrap" if users enable CONFIG_FREERTOS_USE_MINIMAL_IDLE_HOOK
 
 // ------------- Synchronization Primitives ----------------
 
@@ -183,7 +183,11 @@ This file get's pulled into assembly sources. Therefore, some includes need to b
 
 // ------------------------ Hooks --------------------------
 
+#if CONFIG_FREERTOS_USE_IDLE_HOOK
 #define configUSE_IDLE_HOOK                             1
+#else
+#define configUSE_IDLE_HOOK                             0
+#endif
 #define configUSE_TICK_HOOK                             1
 #if CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE
 #define configCHECK_FOR_STACK_OVERFLOW                  0

+ 13 - 8
components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c

@@ -613,19 +613,24 @@ void vApplicationTickHook( void )
 }
 #endif
 
-#if ( configUSE_IDLE_HOOK == 1 )
-void vApplicationIdleHook( void )
+#if CONFIG_FREERTOS_USE_MINIMAL_IDLE_HOOK
+/*
+By default, the port uses vApplicationMinimalIdleHook() to run IDF style idle
+hooks. However, users may also want to provide their own vApplicationMinimalIdleHook().
+In this case, we use to -Wl,--wrap option to wrap the user provided vApplicationMinimalIdleHook()
+*/
+extern void __real_vApplicationMinimalIdleHook( void );
+void __wrap_vApplicationMinimalIdleHook( void )
 {
-    esp_vApplicationIdleHook();
+    esp_vApplicationIdleHook(); //Run IDF style hooks
+    __real_vApplicationMinimalIdleHook(); //Call the user provided vApplicationMinimalIdleHook()
 }
-#endif
-
-#if ( configUSE_MINIMAL_IDLE_HOOK == 1 )
+#else // CONFIG_FREERTOS_USE_MINIMAL_IDLE_HOOK
 void vApplicationMinimalIdleHook( void )
 {
-    esp_vApplicationIdleHook();
+    esp_vApplicationIdleHook(); //Run IDF style hooks
 }
-#endif
+#endif // CONFIG_FREERTOS_USE_MINIMAL_IDLE_HOOK
 
 /* ---------------------------------------------- Misc Implementations -------------------------------------------------
  *

+ 8 - 0
components/freertos/Kconfig

@@ -215,6 +215,14 @@ menu "FreeRTOS"
             - The FreeRTOS idle hook is NOT the same as the ESP-IDF Idle Hook, but both can be enabled
               simultaneously.
 
+    config FREERTOS_USE_MINIMAL_IDLE_HOOK
+        bool "Use FreeRTOS minimal idle hook"
+        depends on FREERTOS_SMP
+        default n
+        help
+            - The application must provide the hook function ``void vApplicationMinimalIdleHook( void );``
+            - ``vApplicationMinimalIdleHook()`` is called from FreeRTOS idle task(s)
+
     config FREERTOS_USE_TICK_HOOK
         bool "Use FreeRTOS tick hook"
         default n