diff --git a/source/FreeRTOS_IP.c b/source/FreeRTOS_IP.c index 38e6e01d19..903ed5b813 100644 --- a/source/FreeRTOS_IP.c +++ b/source/FreeRTOS_IP.c @@ -1016,13 +1016,28 @@ BaseType_t FreeRTOS_IPInit_Multi( void ) { static StaticTask_t xIPTaskBuffer; static StackType_t xIPTaskStack[ ipconfigIP_TASK_STACK_SIZE_WORDS ]; - xIPTaskHandle = xTaskCreateStatic( &prvIPTask, - "IP-Task", - ipconfigIP_TASK_STACK_SIZE_WORDS, - NULL, - ipconfigIP_TASK_PRIORITY, - xIPTaskStack, - &xIPTaskBuffer ); + #if ( ipconfigIP_TASK_AFFINITY > 0 ) + { + xIPTaskHandle = xTaskCreateStaticAffinitySet( &prvIPTask, + "IP-Task", + ipconfigIP_TASK_STACK_SIZE_WORDS, + NULL, + ipconfigIP_TASK_PRIORITY, + xIPTaskStack, + &xIPTaskBuffer, + ipconfigIP_TASK_AFFINITY ); + } + #else /* if ( ipconfigIP_TASK_AFFINITY ) */ + { + xIPTaskHandle = xTaskCreateStatic( &prvIPTask, + "IP-Task", + ipconfigIP_TASK_STACK_SIZE_WORDS, + NULL, + ipconfigIP_TASK_PRIORITY, + xIPTaskStack, + &xIPTaskBuffer ); + } + #endif /* ipconfigIP_TASK_AFFINITY */ if( xIPTaskHandle != NULL ) { @@ -1031,12 +1046,26 @@ BaseType_t FreeRTOS_IPInit_Multi( void ) } #else /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ { - xReturn = xTaskCreate( &prvIPTask, - "IP-task", - ipconfigIP_TASK_STACK_SIZE_WORDS, - NULL, - ipconfigIP_TASK_PRIORITY, - &( xIPTaskHandle ) ); + #if ( ipconfigIP_TASK_AFFINITY > 0 ) + { + xReturn = xTaskCreateAffinitySet( &prvIPTask, + "IP-task", + ipconfigIP_TASK_STACK_SIZE_WORDS, + NULL, + ipconfigIP_TASK_PRIORITY, + ipconfigIP_TASK_AFFINITY, + &( xIPTaskHandle ) ); + } + #else /* if ( ipconfigIP_TASK_AFFINITY ) */ + { + xReturn = xTaskCreate( &prvIPTask, + "IP-task", + ipconfigIP_TASK_STACK_SIZE_WORDS, + NULL, + ipconfigIP_TASK_PRIORITY, + &( xIPTaskHandle ) ); + } + #endif /* ipconfigIP_TASK_AFFINITY */ } #endif /* configSUPPORT_STATIC_ALLOCATION */ } diff --git a/source/include/FreeRTOSIPConfigDefaults.h b/source/include/FreeRTOSIPConfigDefaults.h index dcd7564447..342a054cd0 100644 --- a/source/include/FreeRTOSIPConfigDefaults.h +++ b/source/include/FreeRTOSIPConfigDefaults.h @@ -1139,6 +1139,46 @@ STATIC_ASSERT( pdMS_TO_TICKS( ipconfigPHY_LS_LOW_CHECK_TIME_MS ) <= portMAX_DELA /*---------------------------------------------------------------------------*/ +/* + * ipconfigIP_TASK_AFFINITY + * + * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigIP_TASK_AFFINITY + * + * Type: UBaseType_t + * Unit: task affinity + * Minimum: 0 + * Maximum: (2 ^ configNUMBER_OF_CORES) - 1 + * + * When running using a SMP kernel, task affinity can be used to prevent + * concurrent execution of code that does not fully support SMP. Until + * the TCP library and ports fully supports SMP, it is necessary to set + * the affinity of all tasks which use TCP functions to the same core in + * order to prevent concurrent execution. + * + * An alternative to setting task affinity is to set configRUN_MULTIPLE_PRIORITIES + * to 0. + * + * Task affinity is defined as shifting a bit by the core number. + * + * Example: + * (1U << 0U) //run only on core 0 + * (1U << 1U) //run only on core 1 + */ + +#ifndef ipconfigIP_TASK_AFFINITY + #define ipconfigIP_TASK_AFFINITY ( 0 ) +#endif + +#if ( ipconfigIP_TASK_AFFINITY < 0 ) + #error ipconfigIP_TASK_AFFINITY must be at least 0 +#endif + +#if ( ipconfigIP_TASK_AFFINITY > 0 && configUSE_CORE_AFFINITY == 0 ) + #error configUSE_CORE_AFFINITY must be 1 in order to use ipconfigIP_TASK_AFFINITY +#endif + +/*---------------------------------------------------------------------------*/ + /* * ipconfigIP_TASK_STACK_SIZE_WORDS *