Merge branch 'contrib/github_pr_13578_v5.2' into 'release/v5.2'

Make FreeRTOS configUSE_TIMERS optional in KConfig (GitHub PR) (v5.2)

See merge request espressif/esp-idf!32808
This commit is contained in:
Jiang Jiang Jian 2024-08-23 13:45:34 +08:00
commit a54dfc3912
9 changed files with 142 additions and 81 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,2 @@
CONFIG_IDF_TARGET="esp32"
CONFIG_FREERTOS_USE_TIMERS=n