fix(freertos): split idf_additions.c event groups to separate file

This commit is contained in:
Marius Vikhammer 2024-08-05 11:31:51 +08:00
parent 025b336916
commit 0bcee8518b
9 changed files with 133 additions and 84 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

@ -38,12 +38,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)
{
@ -201,7 +195,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. */
@ -226,7 +228,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

@ -164,18 +164,29 @@ menu "FreeRTOS"
config FREERTOS_USE_TIMERS
bool "configUSE_TIMERS"
default y
depends on !IDF_TARGET_LINUX
help
Enable FreeRTOS Software Timers.
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).
choice FREERTOS_TIMER_SERVICE_TASK_CORE_AFFINITY
prompt "configTIMER_SERVICE_TASK_CORE_AFFINITY"
depends on FREERTOS_USE_TIMERS
default FREERTOS_TIMER_TASK_NO_AFFINITY
help
Sets the timer task's core affinity
@ -192,6 +203,7 @@ menu "FreeRTOS"
config FREERTOS_TIMER_SERVICE_TASK_CORE_AFFINITY
hex
depends on FREERTOS_USE_TIMERS
default 0x0 if FREERTOS_TIMER_TASK_AFFINITY_CPU0
default 0x1 if FREERTOS_TIMER_TASK_AFFINITY_CPU1
default FREERTOS_NO_AFFINITY if FREERTOS_TIMER_TASK_NO_AFFINITY
@ -200,12 +212,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
@ -214,6 +228,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
@ -185,14 +185,15 @@
#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
#define configTIMER_SERVICE_TASK_CORE_AFFINITY CONFIG_FREERTOS_TIMER_SERVICE_TASK_CORE_AFFINITY
#else
#define configUSE_TIMERS 0
#endif
#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
#define configTIMER_SERVICE_TASK_CORE_AFFINITY CONFIG_FREERTOS_TIMER_SERVICE_TASK_CORE_AFFINITY
/* ------------------------ List --------------------------- */

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

@ -67,6 +67,8 @@ void vApplicationGetPassiveIdleTaskMemory(StaticTask_t ** ppxIdleTaskTCBBuffer,
}
#endif /* ( ( CONFIG_FREERTOS_SMP ) && ( configNUMBER_OF_CORES > 1 ) ) */
#if configUSE_TIMERS
void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer,
StackType_t **ppxTimerTaskStackBuffer,
uint32_t *pulTimerTaskStackSize)
@ -98,4 +100,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