From 39bdd2a52ba1a77690da54c17b7cb4c51ea9182d Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Mon, 4 Sep 2023 17:44:49 +0800 Subject: [PATCH] Add core affinity bits check --- include/FreeRTOS.h | 4 ++++ tasks.c | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/FreeRTOS.h b/include/FreeRTOS.h index ca5818eae4..079475fd8c 100644 --- a/include/FreeRTOS.h +++ b/include/FreeRTOS.h @@ -1165,6 +1165,10 @@ #error configUSE_TASK_PREEMPTION_DISABLE is not supported in single core FreeRTOS #endif +#if ( ( configNUMBER_OF_CORES == 1 ) && ( configUSE_CORE_AFFINITY != 0 ) ) + #error configUSE_CORE_AFFINITY is not supported in single core FreeRTOS +#endif + #ifndef configINITIAL_TICK_COUNT #define configINITIAL_TICK_COUNT 0 #endif diff --git a/tasks.c b/tasks.c index 2786c5ab0e..0ce8d58273 100644 --- a/tasks.c +++ b/tasks.c @@ -305,7 +305,7 @@ typedef struct tskTaskControlBlock /* The old naming convention is used to #endif #if ( configUSE_CORE_AFFINITY == 1 ) && ( configNUMBER_OF_CORES > 1 ) - UBaseType_t uxCoreAffinityMask; /*< Used to link the task to certain cores. UBaseType_t must have greater than or equal to the number of bits as confNUM_CORES. */ + UBaseType_t uxCoreAffinityMask; /**< Used to link the task to certain cores. UBaseType_t must have greater than or equal to the number of bits as configNUMBER_OF_CORES. */ #endif ListItem_t xStateListItem; /**< The list that the state list item of a task is reference from denotes the state of that task (Ready, Blocked, Suspended ). */ @@ -3257,6 +3257,13 @@ void vTaskStartScheduler( void ) { BaseType_t xReturn; + #if ( configUSE_CORE_AFFINITY == 1 ) + { + /* UBaseType_t must have greater than or equal to the number of bits as confNUMBER_OF_CORES. */ + configASSERT( configNUMBER_OF_CORES <= ( sizeof( UBaseType_t ) * 8 ) ); + } + #endif + xReturn = prvCreateIdleTasks(); #if ( configUSE_TIMERS == 1 )