diff --git a/components/freertos/FreeRTOS-Kernel-SMP/include/freertos/FreeRTOS.h b/components/freertos/FreeRTOS-Kernel-SMP/include/freertos/FreeRTOS.h index 6efa94bf27..b4c745b23c 100644 --- a/components/freertos/FreeRTOS-Kernel-SMP/include/freertos/FreeRTOS.h +++ b/components/freertos/FreeRTOS-Kernel-SMP/include/freertos/FreeRTOS.h @@ -3262,4 +3262,29 @@ typedef StaticStreamBuffer_t StaticMessageBuffer_t; #endif /* *INDENT-ON* */ +/*----------------------------------------------------------- +* IDF Compatibility +*----------------------------------------------------------*/ + +#ifdef ESP_PLATFORM + +/* + * Include ESP-IDF API additions implicitly for compatibility reasons. + * + * ESP-IDF API additions were previously added directly to FreeRTOS headers + * (e.g., task.h, queue.h). These APIs have now been moved to + * idf_additions.h. + * + * To ensure there are no breaking changes, we include idf_additions.h + * implicitly here so that those API additions are still accessible. Given + * that FreeRTOS.h must be included first before calling any FreeRTOS API, + * any existing source code can continue using these relocated APIs without + * any additional header inclusions via this implicit inclusion. + * + * Todo: Deprecate this implicit inclusion by ESP-IDF v6.0 (IDF-8126) + */ + #include "freertos/idf_additions.h" + +#endif /* ESP_PLATFORM */ + #endif /* INC_FREERTOS_H */ diff --git a/components/freertos/FreeRTOS-Kernel-SMP/include/freertos/task.h b/components/freertos/FreeRTOS-Kernel-SMP/include/freertos/task.h index 73af157edc..4ecc60acf4 100644 --- a/components/freertos/FreeRTOS-Kernel-SMP/include/freertos/task.h +++ b/components/freertos/FreeRTOS-Kernel-SMP/include/freertos/task.h @@ -3578,9 +3578,7 @@ TaskHandle_t xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION; /* * Return the handle of the task running on specified core. */ -#if ( configNUMBER_OF_CORES > 1 ) - TaskHandle_t xTaskGetCurrentTaskHandleForCore( BaseType_t xCoreID ) PRIVILEGED_FUNCTION; -#endif +TaskHandle_t xTaskGetCurrentTaskHandleForCore( BaseType_t xCoreID ) PRIVILEGED_FUNCTION; /* * Shortcut used by the queue implementation to prevent unnecessary call to diff --git a/components/freertos/FreeRTOS-Kernel-SMP/tasks.c b/components/freertos/FreeRTOS-Kernel-SMP/tasks.c index d021999871..2ff460167b 100644 --- a/components/freertos/FreeRTOS-Kernel-SMP/tasks.c +++ b/components/freertos/FreeRTOS-Kernel-SMP/tasks.c @@ -483,7 +483,16 @@ PRIVILEGED_DATA static List_t xPendingReadyList; /**< Ta PRIVILEGED_DATA static volatile UBaseType_t uxCurrentNumberOfTasks = ( UBaseType_t ) 0U; PRIVILEGED_DATA static volatile TickType_t xTickCount = ( TickType_t ) configINITIAL_TICK_COUNT; PRIVILEGED_DATA static volatile UBaseType_t uxTopReadyPriority = tskIDLE_PRIORITY; -PRIVILEGED_DATA static volatile BaseType_t xSchedulerRunning = pdFALSE; +#if ( ( ESP_PLATFORM == 1 ) && ( configNUM_CORES > 1 ) ) + +/* + * Workaround for non-thread safe multi-core OS startup (see IDF-4524) + */ +PRIVILEGED_DATA static volatile BaseType_t xSchedulerRunningPerCore[ configNUM_CORES ] = { pdFALSE }; + #define xSchedulerRunning xSchedulerRunningPerCore[ portGET_CORE_ID() ] +#else // ( ESP_PLATFORM == 1 ) && ( configNUM_CORES > 1 ) + PRIVILEGED_DATA static volatile BaseType_t xSchedulerRunning = pdFALSE; +#endif // ( ESP_PLATFORM == 1 ) && ( configNUM_CORES > 1 ) PRIVILEGED_DATA static volatile TickType_t xPendedTicks = ( TickType_t ) 0U; PRIVILEGED_DATA static volatile BaseType_t xYieldPendings[ configNUMBER_OF_CORES ] = { pdFALSE }; PRIVILEGED_DATA static volatile BaseType_t xNumOfOverflows = ( BaseType_t ) 0; @@ -6552,24 +6561,28 @@ static void prvResetNextTaskUnblockTime( void ) return xReturn; } - - TaskHandle_t xTaskGetCurrentTaskHandleForCore( BaseType_t xCoreID ) - { - TaskHandle_t xReturn = NULL; - - traceENTER_xTaskGetCurrentTaskHandleForCore( xCoreID ); - - if( taskVALID_CORE_ID( xCoreID ) != pdFALSE ) - { - xReturn = pxCurrentTCBs[ xCoreID ]; - } - - traceRETURN_xTaskGetCurrentTaskHandleForCore( xReturn ); - - return xReturn; - } #endif /* #if ( configNUMBER_OF_CORES == 1 ) */ + TaskHandle_t xTaskGetCurrentTaskHandleForCore( BaseType_t xCoreID ) + { + TaskHandle_t xReturn = NULL; + + traceENTER_xTaskGetCurrentTaskHandleForCore( xCoreID ); + + if( taskVALID_CORE_ID( xCoreID ) != pdFALSE ) + { + #if ( configNUMBER_OF_CORES == 1 ) + xReturn = pxCurrentTCB; + #else /* #if ( configNUMBER_OF_CORES == 1 ) */ + xReturn = pxCurrentTCBs[ xCoreID ]; + #endif /* #if ( configNUMBER_OF_CORES == 1 ) */ + } + + traceRETURN_xTaskGetCurrentTaskHandleForCore( xReturn ); + + return xReturn; + } + #endif /* ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) */ /*-----------------------------------------------------------*/ diff --git a/components/freertos/esp_additions/freertos_tasks_c_additions.h b/components/freertos/esp_additions/freertos_tasks_c_additions.h index ef70d65dac..76317c2028 100644 --- a/components/freertos/esp_additions/freertos_tasks_c_additions.h +++ b/components/freertos/esp_additions/freertos_tasks_c_additions.h @@ -440,7 +440,7 @@ BaseType_t xTaskGetCoreID( TaskHandle_t xTask ) } /*----------------------------------------------------------*/ -#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) +#if ( ( !CONFIG_FREERTOS_SMP ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) ) TaskHandle_t xTaskGetIdleTaskHandleForCore( BaseType_t xCoreID ) { @@ -451,10 +451,10 @@ BaseType_t xTaskGetCoreID( TaskHandle_t xTask ) return xIdleTaskHandle[ xCoreID ]; } -#endif /* INCLUDE_xTaskGetIdleTaskHandle */ +#endif /* ( ( !CONFIG_FREERTOS_SMP ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) ) */ /*----------------------------------------------------------*/ -#if ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) +#if ( ( !CONFIG_FREERTOS_SMP ) && ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) ) TaskHandle_t xTaskGetCurrentTaskHandleForCore( BaseType_t xCoreID ) { @@ -478,7 +478,7 @@ BaseType_t xTaskGetCoreID( TaskHandle_t xTask ) return xReturn; } -#endif /* ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) */ +#endif /* ( ( !CONFIG_FREERTOS_SMP ) && ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) ) */ /*----------------------------------------------------------*/ #if ( !CONFIG_FREERTOS_SMP && ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) ) @@ -743,7 +743,11 @@ uint8_t * pxTaskGetStackStart( TaskHandle_t xTask ) if( xYieldRequired != pdFALSE ) { - taskYIELD_IF_USING_PREEMPTION(); + #if CONFIG_FREERTOS_SMP + taskYIELD_TASK_CORE_IF_USING_PREEMPTION( pxTCB ); + #else + taskYIELD_IF_USING_PREEMPTION(); + #endif } } } @@ -849,16 +853,8 @@ uint8_t * pxTaskGetStackStart( TaskHandle_t xTask ) } else { - /* We have a task; return its reentrant struct. */ - #if ( CONFIG_FREERTOS_SMP ) - { - ret = &pxCurTask->xNewLib_reent; - } - #else /* CONFIG_FREERTOS_SMP */ - { - ret = &pxCurTask->xTLSBlock; - } - #endif /* CONFIG_FREERTOS_SMP */ + /* We have a currently executing task. Return its reentrant struct. */ + ret = &pxCurTask->xTLSBlock; } return ret; diff --git a/components/freertos/esp_additions/include/freertos/idf_additions.h b/components/freertos/esp_additions/include/freertos/idf_additions.h index 6c989f05be..b9fb9c47a0 100644 --- a/components/freertos/esp_additions/include/freertos/idf_additions.h +++ b/components/freertos/esp_additions/include/freertos/idf_additions.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -131,17 +131,21 @@ */ BaseType_t xTaskGetCoreID( TaskHandle_t xTask ); +#if ( ( !CONFIG_FREERTOS_SMP ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) ) + /** * @brief Get the handle of idle task for the given core. * * [refactor-todo] See if this needs to be deprecated (IDF-8145) * - * @note If CONFIG_FREERTOS_SMP is enabled, please call xTaskGetIdleTaskHandle() - * instead. * @param xCoreID The core to query * @return Handle of the idle task for the queried core */ -TaskHandle_t xTaskGetIdleTaskHandleForCore( BaseType_t xCoreID ); + TaskHandle_t xTaskGetIdleTaskHandleForCore( BaseType_t xCoreID ); + +#endif /* ( ( !CONFIG_FREERTOS_SMP ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) ) */ + +#if ( ( !CONFIG_FREERTOS_SMP ) && ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) ) /** * @brief Get the handle of the task currently running on a certain core @@ -152,13 +156,12 @@ TaskHandle_t xTaskGetIdleTaskHandleForCore( BaseType_t xCoreID ); * * [refactor-todo] See if this needs to be deprecated (IDF-8145) * - * @note If CONFIG_FREERTOS_SMP is enabled, please call xTaskGetCurrentTaskHandleCPU() - * instead. * @param xCoreID The core to query * @return Handle of the current task running on the queried core */ -TaskHandle_t xTaskGetCurrentTaskHandleForCore( BaseType_t xCoreID ); + TaskHandle_t xTaskGetCurrentTaskHandleForCore( BaseType_t xCoreID ); +#endif /* ( ( !CONFIG_FREERTOS_SMP ) && ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) ) */ #if ( !CONFIG_FREERTOS_SMP && ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) )