Skip to content

Commit aca328e

Browse files
committed
2 parents 0d77e47 + 259b41b commit aca328e

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

examples/template_configuration/FreeRTOSConfig.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,13 @@
566566
* tskNO_AFFINITY if left undefined. */
567567
#define configTIMER_SERVICE_TASK_CORE_AFFINITY tskNO_AFFINITY
568568

569+
/* When using SMP (i.e. configNUMBER_OF_CORES is greater than one), set
570+
* configIDLE_AFFINITY to 1 to pin each Idle task to its corresponding
571+
* core. When set to 1, Idle task N will only run on core N, using an affinity
572+
* mask of (1 << N). Set to 0 to allow the scheduler to run Idle tasks on any
573+
* available core. Defaults to 0 if left undefined. */
574+
#define configIDLE_AFFINITY 0
575+
569576
/******************************************************************************/
570577
/* ARMv8-M secure side port related definitions. ******************************/
571578
/******************************************************************************/

include/FreeRTOS.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@
377377
#define configIDLE_SHOULD_YIELD 1
378378
#endif
379379

380+
#ifndef configIDLE_AFFINITY
381+
#define configIDLE_AFFINITY 0
382+
#endif
383+
380384
#if configMAX_TASK_NAME_LEN < 1
381385
#error configMAX_TASK_NAME_LEN must be set to a minimum of 1 in FreeRTOSConfig.h
382386
#endif

tasks.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3811,8 +3811,13 @@ static BaseType_t prvCreateIdleTasks( void )
38113811
/* Assign idle task to each core before SMP scheduler is running. */
38123812
xIdleTaskHandles[ xCoreID ]->xTaskRunState = xCoreID;
38133813
pxCurrentTCBs[ xCoreID ] = xIdleTaskHandles[ xCoreID ];
3814+
#if ( ( configIDLE_AFFINITY == 1 ) && ( configUSE_CORE_AFFINITY == 1 ) )
3815+
{
3816+
xIdleTaskHandles[ xCoreID ]->uxCoreAffinityMask = ( ( UBaseType_t ) 1U << ( UBaseType_t ) xCoreID );
3817+
}
3818+
#endif
38143819
}
3815-
#endif
3820+
#endif /* if ( configNUMBER_OF_CORES == 1 ) */
38163821
}
38173822
}
38183823

0 commit comments

Comments
 (0)