]> granicus.if.org Git - esp-idf/commitdiff
freertos: cleanup tick/idle hook functionality
authorMahavir Jain <mahavir@espressif.com>
Fri, 31 Aug 2018 09:48:09 +0000 (15:18 +0530)
committerMahavir Jain <mahavir@espressif.com>
Mon, 17 Sep 2018 11:35:17 +0000 (17:05 +0530)
If CONFIG_FREERTOS_LEGACY_HOOKS is kept enabled then defining
idle/tick hooks will be applications responsibility as was the
case earlier.

Signed-off-by: Mahavir Jain <mahavir@espressif.com>
components/esp32/freertos_hooks.c
components/esp32/pm_esp32.c
components/freertos/Kconfig
components/freertos/include/freertos/FreeRTOSConfig.h
components/freertos/include/freertos/portmacro.h
components/freertos/tasks.c
docs/en/api-reference/system/freertos_additions.rst

index 328ef36e26cea3c163101eb7fb60d26acb5e615a..e5198542b807234d01bab840a4f9966d086cc7e7 100644 (file)
@@ -59,11 +59,10 @@ void esp_vApplicationIdleHook()
 #ifdef CONFIG_PM_ENABLE
     esp_pm_impl_idle_hook();
 #endif
-}
 
-extern void esp_vApplicationWaitiHook( void )
-{
+#ifndef CONFIG_FREERTOS_USE_TICKLESS_IDLE
     asm("waiti 0");
+#endif
 }
 
 esp_err_t esp_register_freertos_idle_hook_for_cpu(esp_freertos_idle_cb_t new_idle_cb, UBaseType_t cpuid)
index 5d77dd8db669ec5f369d17f453c133f9de866c60..bf0141833747186e419a9d01689db0596e16807a 100644 (file)
@@ -455,7 +455,7 @@ void IRAM_ATTR esp_pm_impl_isr_hook()
 
 #if CONFIG_FREERTOS_USE_TICKLESS_IDLE
 
-bool IRAM_ATTR vApplicationSleep( TickType_t xExpectedIdleTime )
+void IRAM_ATTR vApplicationSleep( TickType_t xExpectedIdleTime )
 {
     bool result = false;
     portENTER_CRITICAL(&s_switch_lock);
@@ -499,7 +499,11 @@ bool IRAM_ATTR vApplicationSleep( TickType_t xExpectedIdleTime )
         }
     }
     portEXIT_CRITICAL(&s_switch_lock);
-    return result;
+
+    /* Tick less idle was not successful, can block till next interrupt here */
+    if (!result) {
+        asm("waiti 0");
+    }
 }
 #endif //CONFIG_FREERTOS_USE_TICKLESS_IDLE
 
index 16c7c4bc87e35e3b3f2e0e29acf981abfb096da9..df474e6b908e4ee1e0a04376afe46fb8c0e98d25 100644 (file)
@@ -173,24 +173,6 @@ config FREERTOS_LEGACY_HOOKS
         hooks can also still be enabled. Please enable this only if you have code that for some
         reason can't be migrated to the esp_register_freertos_xxx_hook system.
 
-if FREERTOS_LEGACY_HOOKS
-
-config FREERTOS_LEGACY_IDLE_HOOK
-    bool "Enable legacy idle hook"
-    default n
-    help
-        If enabled, FreeRTOS will call a function called vApplicationIdleHook when the idle thread
-        on a CPU is running. Please make sure your code defines such a function.
-
-config FREERTOS_LEGACY_TICK_HOOK
-    bool "Enable legacy tick hook"
-    default n
-    help
-        If enabled, FreeRTOS will call a function called vApplicationTickHook when a FreeRTOS
-        tick is executed. Please make sure your code defines such a function.
-
-endif #FREERTOS_LEGACY_HOOKS
-
 config FREERTOS_MAX_TASK_NAME_LEN
     int "Maximum task name length"
     range 1 256
index f74b79d4eaefcaee0242ddc6dda0784d852e7159..aa33917e2c07d11b21fb09e2c5cfbead6f313f28 100644 (file)
@@ -159,9 +159,8 @@ int xt_clock_freq(void) __attribute__((deprecated));
  *----------------------------------------------------------*/
 
 #define configUSE_PREEMPTION                   1
-#define configUSE_IDLE_HOOK                            ( CONFIG_FREERTOS_LEGACY_IDLE_HOOK )
-
-#define configUSE_TICK_HOOK                            ( CONFIG_FREERTOS_LEGACY_TICK_HOOK )
+#define configUSE_IDLE_HOOK                            1
+#define configUSE_TICK_HOOK                            1
 
 #define configTICK_RATE_HZ                             ( CONFIG_FREERTOS_HZ )
 
index 48b8993957e0f8b2f3241df3d1537354e6747e7a..adeb3bb00973b1b909896025a18af1695d68b02f 100644 (file)
@@ -368,10 +368,15 @@ typedef struct {
 #endif
 
 extern void esp_vApplicationIdleHook( void );
-extern void esp_vApplicationWaitiHook( void );
+extern void esp_vApplicationTickHook( void );
+
+#ifndef CONFIG_FREERTOS_LEGACY_HOOKS
+#define vApplicationIdleHook    esp_vApplicationIdleHook
+#define vApplicationTickHook    esp_vApplicationTickHook
+#endif /* !CONFIG_FREERTOS_LEGACY_HOOKS */
 
 void _xt_coproc_release(volatile void * coproc_sa_base);
-bool vApplicationSleep( TickType_t xExpectedIdleTime );
+void vApplicationSleep( TickType_t xExpectedIdleTime );
 
 #define portSUPPRESS_TICKS_AND_SLEEP( idleTime ) vApplicationSleep( idleTime )
 
index b86fa4e7772b5be0cbf2c3a2281594053e3e28bf..0f42f3c474acda1a25f8bc0d9394da881a406167 100644 (file)
@@ -489,7 +489,6 @@ to its original value when it is released. */
 #if configUSE_TICK_HOOK > 0
        extern void vApplicationTickHook( void );
 #endif
-extern void esp_vApplicationTickHook( void );
 
 #if  portFIRST_TASK_HOOK
        extern void vPortFirstTaskHook(TaskFunction_t taskfn);
@@ -2497,7 +2496,9 @@ BaseType_t xSwitchRequired = pdFALSE;
                #if ( configUSE_TICK_HOOK == 1 )
                vApplicationTickHook();
                #endif /* configUSE_TICK_HOOK */
+               #if ( CONFIG_FREERTOS_LEGACY_HOOKS == 1 )
                esp_vApplicationTickHook();
+               #endif /* CONFIG_FREERTOS_LEGACY_HOOKS */
 
                /*
                  We can't really calculate what we need, that's done on core 0... just assume we need a switch.
@@ -2640,7 +2641,9 @@ BaseType_t xSwitchRequired = pdFALSE;
                                #if ( configUSE_TICK_HOOK == 1 )
                                vApplicationTickHook();
                                #endif /* configUSE_TICK_HOOK */
+                               #if ( CONFIG_FREERTOS_LEGACY_HOOKS == 1 )
                                esp_vApplicationTickHook();
+                               #endif /* CONFIG_FREERTOS_LEGACY_HOOKS */
                        }
                        else
                        {
@@ -2660,7 +2663,9 @@ BaseType_t xSwitchRequired = pdFALSE;
                        vApplicationTickHook();
                }
                #endif
+               #if ( CONFIG_FREERTOS_LEGACY_HOOKS == 1 )
                esp_vApplicationTickHook();
+               #endif /* CONFIG_FREERTOS_LEGACY_HOOKS */
        }
 
        #if ( configUSE_PREEMPTION == 1 )
@@ -3434,10 +3439,12 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters )
                        vApplicationIdleHook();
                }
                #endif /* configUSE_IDLE_HOOK */
+               #if ( CONFIG_FREERTOS_LEGACY_HOOKS == 1 )
                {
                        /* Call the esp-idf hook system */
                        esp_vApplicationIdleHook();
                }
+               #endif /* CONFIG_FREERTOS_LEGACY_HOOKS */
 
 
                /* This conditional compilation should use inequality to 0, not equality
@@ -3447,7 +3454,6 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters )
                #if ( configUSE_TICKLESS_IDLE != 0 )
                {
                TickType_t xExpectedIdleTime;
-               BaseType_t xEnteredSleep = pdFALSE;
 
                        /* It is not desirable to suspend then resume the scheduler on
                        each iteration of the idle task.  Therefore, a preliminary
@@ -3469,7 +3475,7 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters )
                                        if( xExpectedIdleTime >= configEXPECTED_IDLE_TIME_BEFORE_SLEEP )
                                        {
                                                traceLOW_POWER_IDLE_BEGIN();
-                                               xEnteredSleep = portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime );
+                                               portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime );
                                                traceLOW_POWER_IDLE_END();
                                        }
                                        else
@@ -3483,16 +3489,7 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters )
                        {
                                mtCOVERAGE_TEST_MARKER();
                        }
-                       /* It might be possible to enter tickless idle again, so skip
-                        * the fallback sleep hook if tickless idle was successful
-                        */
-                       if ( !xEnteredSleep )
-                       {
-                               esp_vApplicationWaitiHook();
-                       }
                }
-               #else
-               esp_vApplicationWaitiHook();
                #endif /* configUSE_TICKLESS_IDLE */
        }
 }
index 24e47a390fb241230a20589b09d38f6d1f780f3d..e083a01977a999dac9b62e24aa1746c85651dd33 100644 (file)
@@ -374,9 +374,8 @@ defined Idle Hook and Tick Hook on every iteration of the Idle Task and Tick
 Interrupt respectively. 
 
 Vanilla FreeRTOS hooks are referred to as **Legacy Hooks** in ESP-IDF FreeRTOS. 
-To enable legacy hooks, :envvar:`CONFIG_FREERTOS_LEGACY_HOOKS`, 
-:envvar:`CONFIG_FREERTOS_LEGACY_IDLE_HOOK`, and :envvar:`CONFIG_FREERTOS_LEGACY_TICK_HOOK` 
-should all be enabled in ``make menuconfig``.
+To enable legacy hooks, :envvar:`CONFIG_FREERTOS_LEGACY_HOOKS` should be enabled
+in ``make menuconfig``.
 
 Due to vanilla FreeRTOS being designed for single core, ``vApplicationIdleHook()``
 and ``vApplicationTickHook()`` can only be defined once. However, the ESP32 is dual core