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`
This commit is contained in:
Darian Leung 2023-08-29 00:59:20 +08:00
parent a5f9a2505e
commit e612db7d32
2 changed files with 21 additions and 6 deletions

View File

@ -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;
}

View File

@ -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 )