diff --git a/components/freertos/FreeRTOS-Kernel/include/freertos/task.h b/components/freertos/FreeRTOS-Kernel/include/freertos/task.h index c316608ee8..7e898b2d32 100644 --- a/components/freertos/FreeRTOS-Kernel/include/freertos/task.h +++ b/components/freertos/FreeRTOS-Kernel/include/freertos/task.h @@ -3485,20 +3485,6 @@ BaseType_t xTaskGetAffinity( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; */ BaseType_t xTaskIncrementTick( void ) PRIVILEGED_FUNCTION; -#if ( configNUM_CORES > 1 ) - -/* - * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY - * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS - * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. - * - * Called from all other cores except core 0 when their tick interrupt - * occurs. This function will check if the current core requires time slicing, - * and also call the application tick hook. - */ - BaseType_t xTaskIncrementTickOtherCores( void ) PRIVILEGED_FUNCTION; -#endif /* configNUM_CORES > 1 */ - /* * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. diff --git a/components/freertos/FreeRTOS-Kernel/tasks.c b/components/freertos/FreeRTOS-Kernel/tasks.c index 51fc9b47b6..c55fa6a927 100644 --- a/components/freertos/FreeRTOS-Kernel/tasks.c +++ b/components/freertos/FreeRTOS-Kernel/tasks.c @@ -3369,90 +3369,6 @@ BaseType_t xTaskIncrementTick( void ) return xSwitchRequired; } - -#if ( configNUM_CORES > 1 ) - BaseType_t xTaskIncrementTickOtherCores( void ) - { - /* Minor optimization. This function can never switch cores mid - * execution */ - BaseType_t xCoreID = xPortGetCoreID(); - BaseType_t xSwitchRequired = pdFALSE; - - /* This function should never be called by Core 0. */ - configASSERT( xCoreID != 0 ); - - /* Called by the portable layer each time a tick interrupt occurs. - * Increments the tick then checks to see if the new tick value will cause any - * tasks to be unblocked. */ - traceTASK_INCREMENT_TICK( xTickCount ); - - if( uxSchedulerSuspended[ xCoreID ] == ( UBaseType_t ) 0U ) - { - /* We need take the kernel lock here as we are about to access - * kernel data structures. */ - taskENTER_CRITICAL_ISR( &xKernelLock ); - - /* A task being unblocked cannot cause an immediate context switch - * if preemption is turned off. */ - #if ( configUSE_PREEMPTION == 1 ) - { - /* Check if core 0 calling xTaskIncrementTick() has - * unblocked a task that can be run. */ - if( uxTopReadyPriority > pxCurrentTCB[ xCoreID ]->uxPriority ) - { - xSwitchRequired = pdTRUE; - } - else - { - mtCOVERAGE_TEST_MARKER(); - } - } - #endif /* if ( configUSE_PREEMPTION == 1 ) */ - - /* Tasks of equal priority to the currently running task will share - * processing time (time slice) if preemption is on, and the application - * writer has not explicitly turned time slicing off. */ - #if ( ( configUSE_PREEMPTION == 1 ) && ( configUSE_TIME_SLICING == 1 ) ) - { - if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ pxCurrentTCB[ xCoreID ]->uxPriority ] ) ) > ( UBaseType_t ) 1 ) - { - xSwitchRequired = pdTRUE; - } - else - { - mtCOVERAGE_TEST_MARKER(); - } - } - #endif /* ( ( configUSE_PREEMPTION == 1 ) && ( configUSE_TIME_SLICING == 1 ) ) */ - - /* Release the previously taken kernel lock as we have finished - * accessing the kernel data structures. */ - taskEXIT_CRITICAL_ISR( &xKernelLock ); - - #if ( configUSE_PREEMPTION == 1 ) - { - if( xYieldPending[ xCoreID ] != pdFALSE ) - { - xSwitchRequired = pdTRUE; - } - else - { - mtCOVERAGE_TEST_MARKER(); - } - } - #endif /* configUSE_PREEMPTION */ - } - - #if ( configUSE_TICK_HOOK == 1 ) - { - vApplicationTickHook(); - } - #endif - - return xSwitchRequired; - } -#endif /* ( configNUM_CORES > 1 ) */ - /*-----------------------------------------------------------*/ #if ( configUSE_APPLICATION_TASK_TAG == 1 ) diff --git a/components/freertos/esp_additions/freertos_tasks_c_additions.h b/components/freertos/esp_additions/freertos_tasks_c_additions.h index 02aeb66949..7f45a52219 100644 --- a/components/freertos/esp_additions/freertos_tasks_c_additions.h +++ b/components/freertos/esp_additions/freertos_tasks_c_additions.h @@ -75,6 +75,92 @@ _Static_assert( offsetof( StaticTask_t, pxDummy8 ) == offsetof( TCB_t, pxEndOfSt #endif /* ( CONFIG_FREERTOS_SMP && ( configNUM_CORES > 1 ) ) */ /*----------------------------------------------------------*/ +#if ( !CONFIG_FREERTOS_SMP && ( configNUM_CORES > 1 ) ) + + BaseType_t xTaskIncrementTickOtherCores( void ) + { + /* Minor optimization. This function can never switch cores mid + * execution */ + BaseType_t xCoreID = xPortGetCoreID(); + BaseType_t xSwitchRequired = pdFALSE; + + /* This function should never be called by Core 0. */ + configASSERT( xCoreID != 0 ); + + /* Called by the portable layer each time a tick interrupt occurs. + * Increments the tick then checks to see if the new tick value will + * cause any tasks to be unblocked. */ + traceTASK_INCREMENT_TICK( xTickCount ); + + if( uxSchedulerSuspended[ xCoreID ] == ( UBaseType_t ) 0U ) + { + /* We need take the kernel lock here as we are about to access + * kernel data structures. */ + taskENTER_CRITICAL_ISR( &xKernelLock ); + + /* A task being unblocked cannot cause an immediate context switch + * if preemption is turned off. */ + #if ( configUSE_PREEMPTION == 1 ) + { + /* Check if core 0 calling xTaskIncrementTick() has + * unblocked a task that can be run. */ + if( uxTopReadyPriority > pxCurrentTCB[ xCoreID ]->uxPriority ) + { + xSwitchRequired = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* if ( configUSE_PREEMPTION == 1 ) */ + + /* Tasks of equal priority to the currently running task will share + * processing time (time slice) if preemption is on, and the application + * writer has not explicitly turned time slicing off. */ + #if ( ( configUSE_PREEMPTION == 1 ) && ( configUSE_TIME_SLICING == 1 ) ) + { + if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ pxCurrentTCB[ xCoreID ]->uxPriority ] ) ) > ( UBaseType_t ) 1 ) + { + xSwitchRequired = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* ( ( configUSE_PREEMPTION == 1 ) && ( configUSE_TIME_SLICING == 1 ) ) */ + + /* Release the previously taken kernel lock as we have finished + * accessing the kernel data structures. */ + taskEXIT_CRITICAL_ISR( &xKernelLock ); + + #if ( configUSE_PREEMPTION == 1 ) + { + if( xYieldPending[ xCoreID ] != pdFALSE ) + { + xSwitchRequired = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configUSE_PREEMPTION */ + } + + #if ( configUSE_TICK_HOOK == 1 ) + { + vApplicationTickHook(); + } + #endif + + return xSwitchRequired; + } + +#endif /* ( !CONFIG_FREERTOS_SMP && ( configNUM_CORES > 1 ) ) */ +/*----------------------------------------------------------*/ + /* -------------------------------------------------- Task Creation ------------------------------------------------- */ #if CONFIG_FREERTOS_SMP diff --git a/components/freertos/esp_additions/include/esp_private/freertos_idf_additions_priv.h b/components/freertos/esp_additions/include/esp_private/freertos_idf_additions_priv.h index 7791d81996..4f38f5ec99 100644 --- a/components/freertos/esp_additions/include/esp_private/freertos_idf_additions_priv.h +++ b/components/freertos/esp_additions/include/esp_private/freertos_idf_additions_priv.h @@ -109,6 +109,22 @@ #endif /* ( CONFIG_FREERTOS_SMP && ( configNUM_CORES > 1 ) ) */ +/* + * In ESP-IDF FreeRTOS (i.e., multi-core SMP), core 0 manages the the FreeRTOS + * tick count. Thus only core 0 calls xTaskIncrementTick(). + * + * However, all other cores also receive a periodic tick interrupt. Thus all + * other cores should call this function instead. + * + * This function will check if the current core requires time slicing, and also + * call the application tick hook. However, the tick count will remain unchanged. + */ +#if ( !CONFIG_FREERTOS_SMP && ( configNUM_CORES > 1 ) ) + + BaseType_t xTaskIncrementTickOtherCores( void ); + +#endif /* ( !CONFIG_FREERTOS_SMP && ( configNUM_CORES > 1 ) ) */ + /*------------------------------------------------------------------------------ * TASK UTILITIES (PRIVATE) *----------------------------------------------------------------------------*/ diff --git a/components/freertos/port_systick.c b/components/freertos/port_systick.c index eedafc750b..73bd161108 100644 --- a/components/freertos/port_systick.c +++ b/components/freertos/port_systick.c @@ -9,6 +9,10 @@ #include #include "FreeRTOS.h" #include "task.h" +#if ( !CONFIG_FREERTOS_SMP && ( configNUM_CORES > 1 ) ) + /* Required for xTaskIncrementTickOtherCores() */ + #include "esp_private/freertos_idf_additions_priv.h" +#endif /* ( !CONFIG_FREERTOS_SMP && ( configNUM_CORES > 1 ) ) */ #if CONFIG_FREERTOS_SYSTICK_USES_CCOUNT #if CONFIG_FREERTOS_CORETIMER_0