diff --git a/components/esp32/freertos_hooks.c b/components/esp32/freertos_hooks.c index 328ef36e2..e5198542b 100644 --- a/components/esp32/freertos_hooks.c +++ b/components/esp32/freertos_hooks.c @@ -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) diff --git a/components/esp32/pm_esp32.c b/components/esp32/pm_esp32.c index 5d77dd8db..bf0141833 100644 --- a/components/esp32/pm_esp32.c +++ b/components/esp32/pm_esp32.c @@ -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 diff --git a/components/freertos/Kconfig b/components/freertos/Kconfig index 16c7c4bc8..df474e6b9 100644 --- a/components/freertos/Kconfig +++ b/components/freertos/Kconfig @@ -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 diff --git a/components/freertos/include/freertos/FreeRTOSConfig.h b/components/freertos/include/freertos/FreeRTOSConfig.h index f74b79d4e..aa33917e2 100644 --- a/components/freertos/include/freertos/FreeRTOSConfig.h +++ b/components/freertos/include/freertos/FreeRTOSConfig.h @@ -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 ) diff --git a/components/freertos/include/freertos/portmacro.h b/components/freertos/include/freertos/portmacro.h index 48b899395..adeb3bb00 100644 --- a/components/freertos/include/freertos/portmacro.h +++ b/components/freertos/include/freertos/portmacro.h @@ -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 ) diff --git a/components/freertos/tasks.c b/components/freertos/tasks.c index b86fa4e77..0f42f3c47 100644 --- a/components/freertos/tasks.c +++ b/components/freertos/tasks.c @@ -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 */ } } diff --git a/docs/en/api-reference/system/freertos_additions.rst b/docs/en/api-reference/system/freertos_additions.rst index 24e47a390..e083a0197 100644 --- a/docs/en/api-reference/system/freertos_additions.rst +++ b/docs/en/api-reference/system/freertos_additions.rst @@ -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