diff --git a/components/freertos/CMakeLists.txt b/components/freertos/CMakeLists.txt index e565e01ffa..ed7efd5785 100644 --- a/components/freertos/CMakeLists.txt +++ b/components/freertos/CMakeLists.txt @@ -95,6 +95,7 @@ endif() # Add ESP-additions source files list(APPEND srcs "esp_additions/freertos_compatibility.c" + "esp_additions/idf_additions_event_groups.c" "esp_additions/idf_additions.c") if(arch STREQUAL "linux") diff --git a/components/freertos/FreeRTOS-Kernel-SMP/portable/linux/port.c b/components/freertos/FreeRTOS-Kernel-SMP/portable/linux/port.c index c25bb0344a..8bc282cdb7 100644 --- a/components/freertos/FreeRTOS-Kernel-SMP/portable/linux/port.c +++ b/components/freertos/FreeRTOS-Kernel-SMP/portable/linux/port.c @@ -333,7 +333,7 @@ BaseType_t xPortSetInterruptMask( void ) void vPortClearInterruptMask( BaseType_t xMask ) { - // Only reenable interrupts if xMask is 0 + // Only re-enable interrupts if xMask is 0 uxInterruptLevel = xMask; if (uxInterruptLevel == 0 && uxCriticalNestingIDF == 0) { vPortEnableInterrupts(); @@ -621,14 +621,6 @@ portMUX_TYPE port_xISRLock = portMUX_INITIALIZER_UNLOCKED; static const char *TAG = "port"; - -/* When configSUPPORT_STATIC_ALLOCATION is set to 1 the application writer can - * use a callback function to optionally provide the memory required by the idle - * and timer tasks. This is the stack that will be used by the timer task. It is - * declared here, as a global, so it can be checked by a test that is implemented - * in a different file. */ -StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ]; - BaseType_t xPortCheckIfInISR(void) { return (uxInterruptNesting == 0) ? pdFALSE : pdTRUE; @@ -726,7 +718,16 @@ void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, #endif // configSUPPORT_STATIC_ALLOCATION == 1 /*-----------------------------------------------------------*/ -#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) +#if ( (configSUPPORT_STATIC_ALLOCATION == 1) && (configUSE_TIMERS == 1)) + +/* When configSUPPORT_STATIC_ALLOCATION is set to 1 the application writer can + * use a callback function to optionally provide the memory required by the idle + * and timer tasks. This is the stack that will be used by the timer task. It is + * declared here, as a global, so it can be checked by a test that is implemented + * in a different file. */ +StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ]; + + /* 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. */ @@ -751,7 +752,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 +#endif // configSUPPORT_STATIC_ALLOCATION == 1 && (configUSE_TIMERS == 1) void vPortTakeLock( portMUX_TYPE *lock ) { diff --git a/components/freertos/FreeRTOS-Kernel/portable/linux/port_idf.c b/components/freertos/FreeRTOS-Kernel/portable/linux/port_idf.c index a8823df715..5f58844e64 100644 --- a/components/freertos/FreeRTOS-Kernel/portable/linux/port_idf.c +++ b/components/freertos/FreeRTOS-Kernel/portable/linux/port_idf.c @@ -28,12 +28,6 @@ static const char *TAG = "port"; static volatile UBaseType_t uxInterruptNesting = 0; -/* When configSUPPORT_STATIC_ALLOCATION is set to 1 the application writer can - * use a callback function to optionally provide the memory required by the idle - * and timer tasks. This is the stack that will be used by the timer task. It is - * declared here, as a global, so it can be checked by a test that is implemented - * in a different file. */ -StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ]; BaseType_t xPortCheckIfInISR(void) { @@ -124,7 +118,15 @@ void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, #endif // configSUPPORT_STATIC_ALLOCATION == 1 /*-----------------------------------------------------------*/ -#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) +#if ( (configSUPPORT_STATIC_ALLOCATION == 1) && (configUSE_TIMERS == 1)) + +/* When configSUPPORT_STATIC_ALLOCATION is set to 1 the application writer can + * use a callback function to optionally provide the memory required by the idle + * and timer tasks. This is the stack that will be used by the timer task. It is + * declared here, as a global, so it can be checked by a test that is implemented + * in a different file. */ +StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ]; + /* 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. */ @@ -149,7 +151,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 +#endif // (configSUPPORT_STATIC_ALLOCATION == 1) && (configUSE_TIMERS == 1) void __attribute__((weak)) vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName) { diff --git a/components/freertos/Kconfig b/components/freertos/Kconfig index c631aad641..3bdf6a422f 100644 --- a/components/freertos/Kconfig +++ b/components/freertos/Kconfig @@ -160,8 +160,25 @@ menu "FreeRTOS" Enable backward compatibility with APIs prior to FreeRTOS v8.0.0. (see configENABLE_BACKWARD_COMPATIBILITY documentation for more details). + config FREERTOS_USE_TIMERS + bool "configUSE_TIMERS" + default y + help + Enable FreeRTOS Software Timers. Normally the timer task will only get pulled into the build + and created if any software timer related functions are used. This is achieved through IDF + defining a weak empty function for xTimerCreateTimerTask, which should take effect if timers.c + is not pulled into the build. + + In certain special cases (if you use configUSE_TRACE_FACILITY=y and event groups) the linker will + still pull in the xTimerCreateTimerTask from timers.c even if the function that utilized it gets + discarded due to not being used. + + In these cases you can use this option to force the timer task to be disabled. + + config FREERTOS_TIMER_SERVICE_TASK_NAME string "configTIMER_SERVICE_TASK_NAME" + depends on FREERTOS_USE_TIMERS default "Tmr Svc" help Sets the timer task's name (see configTIMER_SERVICE_TASK_NAME documentation for more details). @@ -170,12 +187,14 @@ menu "FreeRTOS" int "configTIMER_TASK_PRIORITY" range 1 25 default 1 + depends on FREERTOS_USE_TIMERS help Sets the timer task's priority (see configTIMER_TASK_PRIORITY documentation for more details). config FREERTOS_TIMER_TASK_STACK_DEPTH int "configTIMER_TASK_STACK_DEPTH" range 1536 32768 + depends on FREERTOS_USE_TIMERS default 2053 if IDF_TARGET_LINUX default 2048 help @@ -184,6 +203,7 @@ menu "FreeRTOS" config FREERTOS_TIMER_QUEUE_LENGTH int "configTIMER_QUEUE_LENGTH" range 5 20 + depends on FREERTOS_USE_TIMERS default 10 help Set the timer task's command queue length (see configTIMER_QUEUE_LENGTH documentation for more diff --git a/components/freertos/config/include/freertos/FreeRTOSConfig.h b/components/freertos/config/include/freertos/FreeRTOSConfig.h index 076e15345d..a1290d9706 100644 --- a/components/freertos/config/include/freertos/FreeRTOSConfig.h +++ b/components/freertos/config/include/freertos/FreeRTOSConfig.h @@ -34,7 +34,7 @@ #define STACK_OVERHEAD_OPTIMIZATION 0 #endif -/* apptrace mdule increases minimum stack usage */ +/* apptrace module increases minimum stack usage */ #if CONFIG_APPTRACE_ENABLE #define STACK_OVERHEAD_APPTRACE 1280 #else @@ -180,11 +180,15 @@ /* ------------------- Software Timer ---------------------- */ -#define configUSE_TIMERS 1 -#define configTIMER_TASK_PRIORITY CONFIG_FREERTOS_TIMER_TASK_PRIORITY -#define configTIMER_QUEUE_LENGTH CONFIG_FREERTOS_TIMER_QUEUE_LENGTH -#define configTIMER_TASK_STACK_DEPTH CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH -#define configTIMER_SERVICE_TASK_NAME CONFIG_FREERTOS_TIMER_SERVICE_TASK_NAME +#if CONFIG_FREERTOS_USE_TIMERS + #define configUSE_TIMERS 1 + #define configTIMER_TASK_PRIORITY CONFIG_FREERTOS_TIMER_TASK_PRIORITY + #define configTIMER_QUEUE_LENGTH CONFIG_FREERTOS_TIMER_QUEUE_LENGTH + #define configTIMER_TASK_STACK_DEPTH CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH + #define configTIMER_SERVICE_TASK_NAME CONFIG_FREERTOS_TIMER_SERVICE_TASK_NAME +#else + #define configUSE_TIMERS 0 +#endif /* ------------------------ List --------------------------- */ @@ -210,7 +214,11 @@ #define INCLUDE_uxTaskGetStackHighWaterMark 1 #define INCLUDE_eTaskGetState 1 #define INCLUDE_xTaskResumeFromISR 1 -#define INCLUDE_xTimerPendFunctionCall 1 +#if CONFIG_FREERTOS_USE_TIMERS + #define INCLUDE_xTimerPendFunctionCall 1 +#else + #define INCLUDE_xTimerPendFunctionCall 0 +#endif #define INCLUDE_xTaskGetSchedulerState 1 #define INCLUDE_xTaskGetCurrentTaskHandle 1 diff --git a/components/freertos/esp_additions/idf_additions.c b/components/freertos/esp_additions/idf_additions.c index ee02e838cc..172ad76573 100644 --- a/components/freertos/esp_additions/idf_additions.c +++ b/components/freertos/esp_additions/idf_additions.c @@ -17,8 +17,6 @@ #include "freertos/semphr.h" #include "freertos/stream_buffer.h" #include "freertos/message_buffer.h" -#include "freertos/event_groups.h" -#include "freertos/timers.h" #include "freertos/idf_additions.h" #include "esp_heap_caps.h" #include "esp_log.h" @@ -440,56 +438,3 @@ err: #endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ /*----------------------------------------------------------*/ - -/* ------------------------------ Event Groups ------------------------------ */ - -#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) - - EventGroupHandle_t xEventGroupCreateWithCaps( UBaseType_t uxMemoryCaps ) - { - EventGroupHandle_t xEventGroup; - StaticEventGroup_t * pxEventGroupBuffer; - - /* Allocate memory for the event group using the provided memory caps */ - pxEventGroupBuffer = heap_caps_malloc( sizeof( StaticEventGroup_t ), uxMemoryCaps ); - - if( pxEventGroupBuffer == NULL ) - { - return NULL; - } - - /* Create the event group using static creation API */ - xEventGroup = xEventGroupCreateStatic( pxEventGroupBuffer ); - - if( xEventGroup == NULL ) - { - heap_caps_free( pxEventGroupBuffer ); - } - - return xEventGroup; - } - -#endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ -/*----------------------------------------------------------*/ - -#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) - - void vEventGroupDeleteWithCaps( EventGroupHandle_t xEventGroup ) - { - BaseType_t xResult; - StaticEventGroup_t * pxEventGroupBuffer; - - /* Retrieve the buffer used to create the event group before deleting it - * */ - xResult = xEventGroupGetStaticBuffer( xEventGroup, &pxEventGroupBuffer ); - configASSERT( xResult == pdTRUE ); - - /* Delete the event group */ - vEventGroupDelete( xEventGroup ); - - /* Free the memory buffer */ - heap_caps_free( pxEventGroupBuffer ); - } - -#endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ -/*----------------------------------------------------------*/ diff --git a/components/freertos/esp_additions/idf_additions_event_groups.c b/components/freertos/esp_additions/idf_additions_event_groups.c new file mode 100644 index 0000000000..8fedd98c1c --- /dev/null +++ b/components/freertos/esp_additions/idf_additions_event_groups.c @@ -0,0 +1,78 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * This file contains the implementation for some the functions in + * idf_additions.h + * + * event group functions are split into a separate file due to the dependency chain + * xEventGroupCreateWithCaps->xEventGroupCreateStatic->event_groups.c->xTimerPendFunctionCallFromISR->timers.c + * + * In some cases this results in the weak timer task function getting overridden and + * used even if the event group functions were discarded due to not being used. + * + * Putting the event groups function in a separate file avoids this issue unless the users himself calls + * event group functions + */ + +#include "sdkconfig.h" +#include "freertos/FreeRTOS.h" +#include "freertos/event_groups.h" +#include "freertos/idf_additions.h" +#include "esp_heap_caps.h" + +/* ------------------------------ Event Groups ------------------------------ */ + +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + + EventGroupHandle_t xEventGroupCreateWithCaps( UBaseType_t uxMemoryCaps ) + { + EventGroupHandle_t xEventGroup; + StaticEventGroup_t * pxEventGroupBuffer; + + /* Allocate memory for the event group using the provided memory caps */ + pxEventGroupBuffer = heap_caps_malloc( sizeof( StaticEventGroup_t ), uxMemoryCaps ); + + if( pxEventGroupBuffer == NULL ) + { + return NULL; + } + + /* Create the event group using static creation API */ + xEventGroup = xEventGroupCreateStatic( pxEventGroupBuffer ); + + if( xEventGroup == NULL ) + { + heap_caps_free( pxEventGroupBuffer ); + } + + return xEventGroup; + } + +#endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ +/*----------------------------------------------------------*/ + +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + + void vEventGroupDeleteWithCaps( EventGroupHandle_t xEventGroup ) + { + BaseType_t xResult; + StaticEventGroup_t * pxEventGroupBuffer; + + /* Retrieve the buffer used to create the event group before deleting it + * */ + xResult = xEventGroupGetStaticBuffer( xEventGroup, &pxEventGroupBuffer ); + configASSERT( xResult == pdTRUE ); + + /* Delete the event group */ + vEventGroupDelete( xEventGroup ); + + /* Free the memory buffer */ + heap_caps_free( pxEventGroupBuffer ); + } + +#endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ +/*----------------------------------------------------------*/ diff --git a/components/freertos/port_common.c b/components/freertos/port_common.c index d41a34fc75..1429805ae2 100644 --- a/components/freertos/port_common.c +++ b/components/freertos/port_common.c @@ -57,6 +57,8 @@ void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; } +#if configUSE_TIMERS + void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize ) @@ -88,4 +90,6 @@ void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, *ppxTimerTaskStackBuffer = pxStackBufferTemp; *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; } +#endif //configUSE_TIMERS + #endif // configSUPPORT_STATIC_ALLOCATION == 1 diff --git a/tools/test_apps/system/build_test/sdkconfig.ci.freertos_timers_disabled_esp32 b/tools/test_apps/system/build_test/sdkconfig.ci.freertos_timers_disabled_esp32 new file mode 100644 index 0000000000..df65faf6cb --- /dev/null +++ b/tools/test_apps/system/build_test/sdkconfig.ci.freertos_timers_disabled_esp32 @@ -0,0 +1,2 @@ +CONFIG_IDF_TARGET="esp32" +CONFIG_FREERTOS_USE_TIMERS=n