diff --git a/components/freertos/FreeRTOS-Kernel/include/freertos/task.h b/components/freertos/FreeRTOS-Kernel/include/freertos/task.h index 9da4e26cfb..804390db99 100644 --- a/components/freertos/FreeRTOS-Kernel/include/freertos/task.h +++ b/components/freertos/FreeRTOS-Kernel/include/freertos/task.h @@ -204,6 +204,15 @@ typedef enum #define tskNO_AFFINITY ( ( BaseType_t ) 0x7FFFFFFF ) /* Todo: Update tskNO_AFFINITY value to -1 (IDF-7908) */ +/** + * Macro to check if an xCoreID value is valid + * + * @return pdTRUE if valid, pdFALSE otherwise. + * + * \ingroup Tasks + */ +#define taskVALID_CORE_ID( xCoreID ) ( ( ( ( ( BaseType_t ) xCoreID ) >= 0 && ( ( BaseType_t ) xCoreID ) < configNUMBER_OF_CORES ) || ( ( ( BaseType_t ) xCoreID ) == tskNO_AFFINITY ) ) ? pdTRUE : pdFALSE ) + /** * * Macro for forcing a context switch. diff --git a/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c b/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c index d5f82a04ea..6e98187250 100644 --- a/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c +++ b/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c @@ -52,9 +52,6 @@ _Static_assert(portBYTE_ALIGNMENT == 16, "portBYTE_ALIGNMENT must be set to 16"); -_Static_assert(tskNO_AFFINITY == CONFIG_FREERTOS_NO_AFFINITY, "incorrect tskNO_AFFINITY value"); - - /* ---------------------------------------------------- Variables ------------------------------------------------------ * - Various variables used to maintain the FreeRTOS port's state. Used from both port.c and various .S files * - Constant offsets are used by assembly to jump to particular TCB members or a stack area (such as the CPSA). We use diff --git a/components/freertos/FreeRTOS-Kernel/tasks.c b/components/freertos/FreeRTOS-Kernel/tasks.c index d793e15656..8f34bf2faa 100644 --- a/components/freertos/FreeRTOS-Kernel/tasks.c +++ b/components/freertos/FreeRTOS-Kernel/tasks.c @@ -1037,7 +1037,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, #if ( configNUMBER_OF_CORES > 1 ) /* Check that xCoreID is valid */ - configASSERT( ( ( xCoreID >= 0 ) && ( xCoreID < configNUMBER_OF_CORES ) ) || ( xCoreID == tskNO_AFFINITY ) ); + configASSERT( taskVALID_CORE_ID( xCoreID ) == pdTRUE ); #else /* Hard code xCoreID to 0 */ xCoreID = 0; @@ -2288,9 +2288,9 @@ static BaseType_t prvCreateIdleTasks( void ) BaseType_t xReturn = pdPASS; BaseType_t xCoreID; -#if ( configNUMBER_OF_CORES > 1 ) - char cIdleName[ configMAX_TASK_NAME_LEN ]; -#endif /* #if ( configNUMBER_OF_CORES > 1 ) */ + #if ( configNUMBER_OF_CORES > 1 ) + char cIdleName[ configMAX_TASK_NAME_LEN ]; + #endif /* #if ( configNUMBER_OF_CORES > 1 ) */ /* Add each idle task at the lowest priority. */ for( xCoreID = ( BaseType_t ) 0; xCoreID < ( BaseType_t ) configNUMBER_OF_CORES; xCoreID++ ) @@ -2396,7 +2396,6 @@ static BaseType_t prvCreateIdleTasks( void ) portPRIVILEGE_BIT, /* In effect ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), but tskIDLE_PRIORITY is zero. */ &xIdleTaskHandle[ xCoreID ], /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */ xCoreID ); - } #endif /* configSUPPORT_STATIC_ALLOCATION */ } diff --git a/components/freertos/esp_additions/freertos_tasks_c_additions.h b/components/freertos/esp_additions/freertos_tasks_c_additions.h index c7a9fe6ab8..c56f77afa2 100644 --- a/components/freertos/esp_additions/freertos_tasks_c_additions.h +++ b/components/freertos/esp_additions/freertos_tasks_c_additions.h @@ -29,9 +29,7 @@ */ _Static_assert( offsetof( StaticTask_t, pxDummy6 ) == offsetof( TCB_t, pxStack ) ); _Static_assert( offsetof( StaticTask_t, pxDummy8 ) == offsetof( TCB_t, pxEndOfStack ) ); -#if CONFIG_FREERTOS_SMP - _Static_assert( tskNO_AFFINITY == CONFIG_FREERTOS_NO_AFFINITY, "CONFIG_FREERTOS_NO_AFFINITY must be the same as tskNO_AFFINITY" ); -#endif /* CONFIG_FREERTOS_SMP */ +_Static_assert( tskNO_AFFINITY == ( BaseType_t ) CONFIG_FREERTOS_NO_AFFINITY, "CONFIG_FREERTOS_NO_AFFINITY must be the same as tskNO_AFFINITY" ); /* ------------------------------------------------- Kernel Control ------------------------------------------------- */ @@ -343,7 +341,7 @@ _Static_assert( offsetof( StaticTask_t, pxDummy8 ) == offsetof( TCB_t, pxEndOfSt configASSERT( portVALID_STACK_MEM( puxStackBuffer ) ); configASSERT( portVALID_TCB_MEM( pxTaskBuffer ) ); - configASSERT( ( ( xCoreID >= 0 ) && ( xCoreID < configNUM_CORES ) ) || ( xCoreID == tskNO_AFFINITY ) ); + configASSERT( taskVALID_CORE_ID( xCoreID ) == pdTRUE ); #if ( configASSERT_DEFINED == 1 ) { @@ -480,8 +478,7 @@ BaseType_t xTaskGetCoreID( TaskHandle_t xTask ) } #else /* CONFIG_FREERTOS_SMP */ { - configASSERT( xCoreID < configNUMBER_OF_CORES ); - configASSERT( xCoreID != tskNO_AFFINITY ); + configASSERT( taskVALID_CORE_ID( xCoreID ) == pdTRUE ); /* A critical section is not required as this function does not * guarantee that the TCB will still be valid when this function @@ -502,8 +499,7 @@ BaseType_t xTaskGetCoreID( TaskHandle_t xTask ) { uint32_t ulRunTimeCounter; - configASSERT( xCoreID < configNUMBER_OF_CORES ); - configASSERT( xCoreID != tskNO_AFFINITY ); + configASSERT( taskVALID_CORE_ID( xCoreID ) == pdTRUE ); /* For SMP, we need to take the kernel lock here as we are about to * access kernel data structures. */ @@ -526,8 +522,7 @@ BaseType_t xTaskGetCoreID( TaskHandle_t xTask ) { configRUN_TIME_COUNTER_TYPE ulTotalTime, ulReturn; - configASSERT( xCoreID < configNUMBER_OF_CORES ); - configASSERT( xCoreID != tskNO_AFFINITY ); + configASSERT( taskVALID_CORE_ID( xCoreID ) == pdTRUE ); ulTotalTime = portGET_RUN_TIME_COUNTER_VALUE();