From e612db7d327853630f5ff083a78f6402483d55f4 Mon Sep 17 00:00:00 2001 From: Darian Leung Date: Tue, 29 Aug 2023 00:59:20 +0800 Subject: [PATCH] refactor(freertos/idf): Move weak xTimerCreateTimerTask() to IDF additions header A weak xTimerCreateTimerTask() was added to tasks.c as a workaround in ESP-IDF in order to prevent timers.c from being linked when unused. This commit moves that workaround to `freertos_tasks_c_additions.h` --- components/freertos/FreeRTOS-Kernel/tasks.c | 6 ------ .../freertos_tasks_c_additions.h | 21 +++++++++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/components/freertos/FreeRTOS-Kernel/tasks.c b/components/freertos/FreeRTOS-Kernel/tasks.c index da7bdab9de..592af7071e 100644 --- a/components/freertos/FreeRTOS-Kernel/tasks.c +++ b/components/freertos/FreeRTOS-Kernel/tasks.c @@ -6304,9 +6304,3 @@ static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait, #endif #endif /* if ( configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H == 1 ) */ - -/* If timers.c is not referenced anywhere, don't create the timer task to save RAM */ -BaseType_t __attribute__( ( weak ) ) xTimerCreateTimerTask( void ) -{ - return pdPASS; -} diff --git a/components/freertos/esp_additions/freertos_tasks_c_additions.h b/components/freertos/esp_additions/freertos_tasks_c_additions.h index b88947abf0..c9c64b1964 100644 --- a/components/freertos/esp_additions/freertos_tasks_c_additions.h +++ b/components/freertos/esp_additions/freertos_tasks_c_additions.h @@ -242,6 +242,27 @@ _Static_assert( offsetof( StaticTask_t, pxDummy8 ) == offsetof( TCB_t, pxEndOfSt #endif /* CONFIG_FREERTOS_SMP && ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ /*----------------------------------------------------------*/ +#if ( configUSE_TIMERS == 1 ) + +/* + * In ESP-IDF, configUSE_TIMERS is always defined as 1 (i.e., not user configurable). + * However, tasks.c: vTaskStartScheduler() will always call xTimerCreateTimerTask() + * if ( configUSE_TIMERS == 1 ), thus causing the linker to link timers.c and + * wasting some memory (due to the timer task being created)/ + * + * If we provide a weak version of xTimerCreateTimerTask(), this version will be + * compiled if the application does not call any other FreeRTOS timer functions. + * Thus we can save some text/RAM as timers.c will not be linked and the timer + * task never created. + */ + BaseType_t __attribute__( ( weak ) ) xTimerCreateTimerTask( void ) + { + return pdPASS; + } + +#endif /* configUSE_TIMERS */ +/*----------------------------------------------------------*/ + /* ------------------------------------------------- Task Utilities ------------------------------------------------- */ #if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )