From b0ef95b6eb82a8803650b6bb42e9c1ee42b43d79 Mon Sep 17 00:00:00 2001 From: Mahavir Jain Date: Wed, 29 Aug 2018 11:39:04 +0530 Subject: [PATCH 1/3] task_wdt: correct critical section API in ISR context Signed-off-by: Mahavir Jain --- components/esp32/task_wdt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/esp32/task_wdt.c b/components/esp32/task_wdt.c index 7e8883bdfd..3058537303 100644 --- a/components/esp32/task_wdt.c +++ b/components/esp32/task_wdt.c @@ -135,7 +135,7 @@ void __attribute__((weak)) esp_task_wdt_isr_user_handler(void) */ static void task_wdt_isr(void *arg) { - portENTER_CRITICAL(&twdt_spinlock); + portENTER_CRITICAL_ISR(&twdt_spinlock); twdt_task_t *twdttask; const char *cpu; //Reset hardware timer so that 2nd stage timeout is not reached (will trigger system reset) @@ -169,12 +169,12 @@ static void task_wdt_isr(void *arg) esp_task_wdt_isr_user_handler(); if (twdt_config->panic){ //Trigger Panic if configured to do so ESP_EARLY_LOGE(TAG, "Aborting."); - portEXIT_CRITICAL(&twdt_spinlock); + portEXIT_CRITICAL_ISR(&twdt_spinlock); esp_reset_reason_set_hint(ESP_RST_TASK_WDT); abort(); } - portEXIT_CRITICAL(&twdt_spinlock); + portEXIT_CRITICAL_ISR(&twdt_spinlock); } /* From 152043d469f26f71f1e67590daad22ddf949d5b4 Mon Sep 17 00:00:00 2001 From: Mahavir Jain Date: Thu, 30 Aug 2018 15:59:01 +0530 Subject: [PATCH 2/3] esp_ringbuf: move ringbuf to seperate component Signed-off-by: Mahavir Jain --- components/driver/CMakeLists.txt | 2 +- components/esp_ringbuf/CMakeLists.txt | 6 +++ components/esp_ringbuf/component.mk | 0 .../include/freertos/ringbuf.h | 0 .../{freertos => esp_ringbuf}/ringbuf.c | 52 +++++++++---------- components/esp_ringbuf/test/component.mk | 5 ++ .../test/test_ringbuf.c | 0 components/freertos/CMakeLists.txt | 2 - docs/Doxyfile | 3 +- 9 files changed, 40 insertions(+), 30 deletions(-) create mode 100644 components/esp_ringbuf/CMakeLists.txt create mode 100644 components/esp_ringbuf/component.mk rename components/{freertos => esp_ringbuf}/include/freertos/ringbuf.h (100%) rename components/{freertos => esp_ringbuf}/ringbuf.c (97%) create mode 100644 components/esp_ringbuf/test/component.mk rename components/{freertos => esp_ringbuf}/test/test_ringbuf.c (100%) diff --git a/components/driver/CMakeLists.txt b/components/driver/CMakeLists.txt index 5e396ede55..13cfd703c4 100644 --- a/components/driver/CMakeLists.txt +++ b/components/driver/CMakeLists.txt @@ -23,6 +23,6 @@ set(COMPONENT_SRCS "can.c" set(COMPONENT_ADD_INCLUDEDIRS "include") set(COMPONENT_PRIV_INCLUDEDIRS "include/driver") -set(COMPONENT_REQUIRES) +set(COMPONENT_REQUIRES esp_ringbuf) register_component() diff --git a/components/esp_ringbuf/CMakeLists.txt b/components/esp_ringbuf/CMakeLists.txt new file mode 100644 index 0000000000..9117521a27 --- /dev/null +++ b/components/esp_ringbuf/CMakeLists.txt @@ -0,0 +1,6 @@ +set(COMPONENT_ADD_INCLUDEDIRS "include") +set(COMPONENT_SRCS "ringbuf.c") + +set(COMPONENT_REQUIRES) + +register_component() diff --git a/components/esp_ringbuf/component.mk b/components/esp_ringbuf/component.mk new file mode 100644 index 0000000000..e69de29bb2 diff --git a/components/freertos/include/freertos/ringbuf.h b/components/esp_ringbuf/include/freertos/ringbuf.h similarity index 100% rename from components/freertos/include/freertos/ringbuf.h rename to components/esp_ringbuf/include/freertos/ringbuf.h diff --git a/components/freertos/ringbuf.c b/components/esp_ringbuf/ringbuf.c similarity index 97% rename from components/freertos/ringbuf.c rename to components/esp_ringbuf/ringbuf.c index 606cea148d..9a7117b74c 100644 --- a/components/freertos/ringbuf.c +++ b/components/esp_ringbuf/ringbuf.c @@ -14,10 +14,10 @@ #include #include -#include "FreeRTOS.h" -#include "task.h" -#include "semphr.h" -#include "ringbuf.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/semphr.h" +#include "freertos/ringbuf.h" //32-bit alignment macros #define rbALIGN_SIZE( xSize ) ( ( xSize + portBYTE_ALIGNMENT_MASK ) & ~portBYTE_ALIGNMENT_MASK ) @@ -566,7 +566,7 @@ static BaseType_t prvReceiveGeneric(Ringbuffer_t *pxRingbuffer, void **pvItem1, } //Semaphore obtained, check if item can be retrieved - taskENTER_CRITICAL(&pxRingbuffer->mux); + portENTER_CRITICAL(&pxRingbuffer->mux); if (prvCheckItemAvail(pxRingbuffer) == pdTRUE) { //Item is available for retrieval BaseType_t xIsSplit; @@ -591,14 +591,14 @@ static BaseType_t prvReceiveGeneric(Ringbuffer_t *pxRingbuffer, void **pvItem1, if (pxRingbuffer->xItemsWaiting > 0) { xReturnSemaphore = pdTRUE; } - taskEXIT_CRITICAL(&pxRingbuffer->mux); + portEXIT_CRITICAL(&pxRingbuffer->mux); break; } //No item available for retrieval, adjust ticks and take the semaphore again if (xTicksToWait != portMAX_DELAY) { xTicksRemaining = xTicksEnd - xTaskGetTickCount(); } - taskEXIT_CRITICAL(&pxRingbuffer->mux); + portEXIT_CRITICAL(&pxRingbuffer->mux); /* * Gap between critical section and re-acquiring of the semaphore. If * semaphore is given now, priority inversion might occur (see docs) @@ -616,7 +616,7 @@ static BaseType_t prvReceiveGenericFromISR(Ringbuffer_t *pxRingbuffer, void **pv BaseType_t xReturn = pdFALSE; BaseType_t xReturnSemaphore = pdFALSE; - taskENTER_CRITICAL_ISR(&pxRingbuffer->mux); + portENTER_CRITICAL_ISR(&pxRingbuffer->mux); if(prvCheckItemAvail(pxRingbuffer) == pdTRUE) { BaseType_t xIsSplit; if (pxRingbuffer->uxRingbufferFlags & rbBYTE_BUFFER_FLAG) { @@ -641,7 +641,7 @@ static BaseType_t prvReceiveGenericFromISR(Ringbuffer_t *pxRingbuffer, void **pv xReturnSemaphore = pdTRUE; } } - taskEXIT_CRITICAL_ISR(&pxRingbuffer->mux); + portEXIT_CRITICAL_ISR(&pxRingbuffer->mux); if (xReturnSemaphore == pdTRUE) { xSemaphoreGiveFromISR(pxRingbuffer->xItemsBufferedSemaphore, NULL); //Give semaphore back so other tasks can retrieve @@ -766,7 +766,7 @@ BaseType_t xRingbufferSend(RingbufHandle_t xRingbuffer, const void *pvItem, size break; } //Semaphore obtained, check if item can fit - taskENTER_CRITICAL(&pxRingbuffer->mux); + portENTER_CRITICAL(&pxRingbuffer->mux); if(pxRingbuffer->xCheckItemFits(pxRingbuffer, xItemSize) == pdTRUE) { //Item will fit, copy item pxRingbuffer->vCopyItem(pxRingbuffer, pvItem, xItemSize); @@ -775,14 +775,14 @@ BaseType_t xRingbufferSend(RingbufHandle_t xRingbuffer, const void *pvItem, size if (prvGetFreeSize(pxRingbuffer) > 0) { xReturnSemaphore = pdTRUE; } - taskEXIT_CRITICAL(&pxRingbuffer->mux); + portEXIT_CRITICAL(&pxRingbuffer->mux); break; } //Item doesn't fit, adjust ticks and take the semaphore again if (xTicksToWait != portMAX_DELAY) { xTicksRemaining = xTicksEnd - xTaskGetTickCount(); } - taskEXIT_CRITICAL(&pxRingbuffer->mux); + portEXIT_CRITICAL(&pxRingbuffer->mux); /* * Gap between critical section and re-acquiring of the semaphore. If * semaphore is given now, priority inversion might occur (see docs) @@ -815,7 +815,7 @@ BaseType_t xRingbufferSendFromISR(RingbufHandle_t xRingbuffer, const void *pvIte //Attempt to send an item BaseType_t xReturn; BaseType_t xReturnSemaphore = pdFALSE; - taskENTER_CRITICAL_ISR(&pxRingbuffer->mux); + portENTER_CRITICAL_ISR(&pxRingbuffer->mux); if (pxRingbuffer->xCheckItemFits(xRingbuffer, xItemSize) == pdTRUE) { pxRingbuffer->vCopyItem(xRingbuffer, pvItem, xItemSize); xReturn = pdTRUE; @@ -826,7 +826,7 @@ BaseType_t xRingbufferSendFromISR(RingbufHandle_t xRingbuffer, const void *pvIte } else { xReturn = pdFALSE; } - taskEXIT_CRITICAL_ISR(&pxRingbuffer->mux); + portEXIT_CRITICAL_ISR(&pxRingbuffer->mux); if (xReturn == pdTRUE) { //Indicate item was successfully sent @@ -997,9 +997,9 @@ void vRingbufferReturnItem(RingbufHandle_t xRingbuffer, void *pvItem) configASSERT(pxRingbuffer); configASSERT(pvItem != NULL); - taskENTER_CRITICAL(&pxRingbuffer->mux); + portENTER_CRITICAL(&pxRingbuffer->mux); pxRingbuffer->vReturnItem(pxRingbuffer, (uint8_t *)pvItem); - taskEXIT_CRITICAL(&pxRingbuffer->mux); + portEXIT_CRITICAL(&pxRingbuffer->mux); xSemaphoreGive(pxRingbuffer->xFreeSpaceSemaphore); } @@ -1009,9 +1009,9 @@ void vRingbufferReturnItemFromISR(RingbufHandle_t xRingbuffer, void *pvItem, Bas configASSERT(pxRingbuffer); configASSERT(pvItem != NULL); - taskENTER_CRITICAL_ISR(&pxRingbuffer->mux); + portENTER_CRITICAL_ISR(&pxRingbuffer->mux); pxRingbuffer->vReturnItem(pxRingbuffer, (uint8_t *)pvItem); - taskEXIT_CRITICAL_ISR(&pxRingbuffer->mux); + portEXIT_CRITICAL_ISR(&pxRingbuffer->mux); xSemaphoreGiveFromISR(pxRingbuffer->xFreeSpaceSemaphore, pxHigherPriorityTaskWoken); } @@ -1045,9 +1045,9 @@ size_t xRingbufferGetCurFreeSize(RingbufHandle_t xRingbuffer) configASSERT(pxRingbuffer); size_t xFreeSize; - taskENTER_CRITICAL(&pxRingbuffer->mux); + portENTER_CRITICAL(&pxRingbuffer->mux); xFreeSize = pxRingbuffer->xGetCurMaxSize(pxRingbuffer); - taskEXIT_CRITICAL(&pxRingbuffer->mux); + portEXIT_CRITICAL(&pxRingbuffer->mux); return xFreeSize; } @@ -1057,7 +1057,7 @@ BaseType_t xRingbufferAddToQueueSetRead(RingbufHandle_t xRingbuffer, QueueSetHan configASSERT(pxRingbuffer); BaseType_t xReturn; - taskENTER_CRITICAL(&pxRingbuffer->mux); + portENTER_CRITICAL(&pxRingbuffer->mux); //Cannot add semaphore to queue set if semaphore is not empty. Temporarily hold semaphore BaseType_t xHoldSemaphore = xSemaphoreTake(pxRingbuffer->xItemsBufferedSemaphore, 0); xReturn = xQueueAddToSet(pxRingbuffer->xItemsBufferedSemaphore, xQueueSet); @@ -1065,7 +1065,7 @@ BaseType_t xRingbufferAddToQueueSetRead(RingbufHandle_t xRingbuffer, QueueSetHan //Return semaphore if temporarily held configASSERT(xSemaphoreGive(pxRingbuffer->xItemsBufferedSemaphore) == pdTRUE); } - taskEXIT_CRITICAL(&pxRingbuffer->mux); + portEXIT_CRITICAL(&pxRingbuffer->mux); return xReturn; } @@ -1083,7 +1083,7 @@ BaseType_t xRingbufferRemoveFromQueueSetRead(RingbufHandle_t xRingbuffer, QueueS configASSERT(pxRingbuffer); BaseType_t xReturn; - taskENTER_CRITICAL(&pxRingbuffer->mux); + portENTER_CRITICAL(&pxRingbuffer->mux); //Cannot remove semaphore from queue set if semaphore is not empty. Temporarily hold semaphore BaseType_t xHoldSemaphore = xSemaphoreTake(pxRingbuffer->xItemsBufferedSemaphore, 0); xReturn = xQueueRemoveFromSet(pxRingbuffer->xItemsBufferedSemaphore, xQueueSet); @@ -1091,7 +1091,7 @@ BaseType_t xRingbufferRemoveFromQueueSetRead(RingbufHandle_t xRingbuffer, QueueS //Return semaphore if temporarily held configASSERT(xSemaphoreGive(pxRingbuffer->xItemsBufferedSemaphore) == pdTRUE); } - taskEXIT_CRITICAL(&pxRingbuffer->mux); + portEXIT_CRITICAL(&pxRingbuffer->mux); return xReturn; } @@ -1100,7 +1100,7 @@ void vRingbufferGetInfo(RingbufHandle_t xRingbuffer, UBaseType_t *uxFree, UBaseT Ringbuffer_t *pxRingbuffer = (Ringbuffer_t *)xRingbuffer; configASSERT(pxRingbuffer); - taskENTER_CRITICAL(&pxRingbuffer->mux); + portENTER_CRITICAL(&pxRingbuffer->mux); if (uxFree != NULL) { *uxFree = (UBaseType_t)(pxRingbuffer->pucFree - pxRingbuffer->pucHead); } @@ -1113,7 +1113,7 @@ void vRingbufferGetInfo(RingbufHandle_t xRingbuffer, UBaseType_t *uxFree, UBaseT if (uxItemsWaiting != NULL) { *uxItemsWaiting = (UBaseType_t)(pxRingbuffer->xItemsWaiting); } - taskEXIT_CRITICAL(&pxRingbuffer->mux); + portEXIT_CRITICAL(&pxRingbuffer->mux); } void xRingbufferPrintInfo(RingbufHandle_t xRingbuffer) diff --git a/components/esp_ringbuf/test/component.mk b/components/esp_ringbuf/test/component.mk new file mode 100644 index 0000000000..5dd172bdb7 --- /dev/null +++ b/components/esp_ringbuf/test/component.mk @@ -0,0 +1,5 @@ +# +#Component Makefile +# + +COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive diff --git a/components/freertos/test/test_ringbuf.c b/components/esp_ringbuf/test/test_ringbuf.c similarity index 100% rename from components/freertos/test/test_ringbuf.c rename to components/esp_ringbuf/test/test_ringbuf.c diff --git a/components/freertos/CMakeLists.txt b/components/freertos/CMakeLists.txt index bcd9b0c42e..96a0d2b5fc 100644 --- a/components/freertos/CMakeLists.txt +++ b/components/freertos/CMakeLists.txt @@ -7,7 +7,6 @@ set(COMPONENT_SRCS "FreeRTOS-openocd.c" "port.c" "portasm.S" "queue.c" - "ringbuf.c" "tasks.c" "timers.c" "xtensa_context.S" @@ -28,7 +27,6 @@ set_source_files_properties( event_groups.c timers.c queue.c - ringbuf.c PROPERTIES COMPILE_DEFINITIONS _ESP_FREERTOS_INTERNAL ) diff --git a/docs/Doxyfile b/docs/Doxyfile index 1db49e60cc..fd241f0191 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -179,7 +179,8 @@ INPUT = \ ../../components/freertos/include/freertos/semphr.h \ ../../components/freertos/include/freertos/timers.h \ ../../components/freertos/include/freertos/event_groups.h \ - ../../components/freertos/include/freertos/ringbuf.h \ + ### Ringbuffer + ../../components/esp_ringbuf/include/freertos/ringbuf.h \ ### Helper functions for error codes ../../components/esp32/include/esp_err.h \ ### System APIs From ff81dc16e066bb5f76d3650144bffc23ccd33208 Mon Sep 17 00:00:00 2001 From: Mahavir Jain Date: Fri, 31 Aug 2018 15:18:09 +0530 Subject: [PATCH 3/3] freertos: cleanup tick/idle hook functionality 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 --- components/esp32/freertos_hooks.c | 5 ++--- components/esp32/pm_esp32.c | 8 +++++-- components/freertos/Kconfig | 18 ---------------- .../include/freertos/FreeRTOSConfig.h | 5 ++--- .../freertos/include/freertos/portmacro.h | 9 ++++++-- components/freertos/tasks.c | 21 ++++++++----------- .../system/freertos_additions.rst | 5 ++--- 7 files changed, 28 insertions(+), 43 deletions(-) diff --git a/components/esp32/freertos_hooks.c b/components/esp32/freertos_hooks.c index 328ef36e26..e5198542b8 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 5d77dd8db6..bf01418337 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 16c7c4bc87..df474e6b90 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 f74b79d4ea..aa33917e2c 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 48b8993957..adeb3bb009 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 b86fa4e777..0f42f3c474 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 24e47a390f..e083a01977 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