@@ -172,7 +172,7 @@ typedef enum
172172
173173/**
174174 * Defines affinity to all available cores.
175- *
175+ *
176176 */
177177#define tskNO_AFFINITY ( ( UBaseType_t ) -1U )
178178
@@ -1244,11 +1244,152 @@ void vTaskResume( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
12441244BaseType_t xTaskResumeFromISR ( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION ;
12451245
12461246#if ( configUSE_CORE_AFFINITY == 1 )
1247- void vTaskCoreAffinitySet ( const TaskHandle_t xTask , UBaseType_t uxCoreAffinityMask );
1248- UBaseType_t vTaskCoreAffinityGet ( const TaskHandle_t xTask );
1247+ /**
1248+ * @brief Sets the core affinity mask for a task.
1249+ *
1250+ * It sets the cores on which a task can run. configUSE_CORE_AFFINITY must
1251+ * be defined as 1 for this function to be available.
1252+ *
1253+ * @param xTask The handle of the task to set the core affinity mask for.
1254+ * Passing NULL will set the core affinity mask for the calling task.
1255+ *
1256+ * @param uxCoreAffinityMask A bitwise value that indicates the cores on
1257+ * which the task can run. Cores are numbered from 0 to configNUM_CORES - 1.
1258+ * For example, to ensure that a task can run on core 0 and core 1, set
1259+ * uxCoreAffinityMask to 0x03.
1260+ *
1261+ * Example usage:
1262+ *
1263+ * // The function that creates task.
1264+ * void vAFunction( void )
1265+ * {
1266+ * TaskHandle_t xHandle;
1267+ * UBaseType_t uxCoreAffinityMask;
1268+ *
1269+ * // Create a task, storing the handle.
1270+ * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &( xHandle ) );
1271+ *
1272+ * // Define the core affinity mask such that this task can only run
1273+ * // on core 0 and core 2.
1274+ * uxCoreAffinityMask = ( ( 1 << 0 ) | ( 1 << 2 ) );
1275+ *
1276+ * //Set the core affinity mask for the task.
1277+ * vTaskCoreAffinitySet( xHandle, uxCoreAffinityMask );
1278+ * }
1279+ */
1280+ void vTaskCoreAffinitySet ( const TaskHandle_t xTask , UBaseType_t uxCoreAffinityMask );
12491281#endif
12501282
1283+ #if ( configUSE_CORE_AFFINITY == 1 )
1284+ /**
1285+ * @brief Gets the core affinity mask for a task.
1286+ *
1287+ * configUSE_CORE_AFFINITY must be defined as 1 for this function to be
1288+ * available.
1289+ *
1290+ * @param xTask The handle of the task to get the core affinity mask for.
1291+ * Passing NULL will get the core affinity mask for the calling task.
1292+ *
1293+ * @return The core affinity mask which is a bitwise value that indicates
1294+ * the cores on which a task can run. Cores are numbered from 0 to
1295+ * configNUM_CORES - 1. For example, if a task can run on core 0 and core 1,
1296+ * the core affinity mask is 0x03.
1297+ *
1298+ * Example usage:
1299+ *
1300+ * // Task handle of the networking task - it is populated elsewhere.
1301+ * TaskHandle_t xNetworkingTaskHandle;
1302+ *
1303+ * void vAFunction( void )
1304+ * {
1305+ * TaskHandle_t xHandle;
1306+ * UBaseType_t uxNetworkingCoreAffinityMask;
1307+ *
1308+ * // Create a task, storing the handle.
1309+ * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &( xHandle ) );
1310+ *
1311+ * //Get the core affinity mask for the networking task.
1312+ * uxNetworkingCoreAffinityMask = vTaskCoreAffinityGet( xNetworkingTaskHandle );
1313+ *
1314+ * // Here is a hypothetical scenario, just for the example. Assume that we
1315+ * // have 2 cores - Core 0 and core 1. We want to pin the application task to
1316+ * // the core different than the networking task to ensure that the
1317+ * // application task does not interfere with networking.
1318+ * if( ( uxNetworkingCoreAffinityMask & ( 1 << 0 ) ) != 0 )
1319+ * {
1320+ * // The networking task can run on core 0, pin our task to core 1.
1321+ * vTaskCoreAffinitySet( xHandle, ( 1 << 1 ) );
1322+ * }
1323+ * else
1324+ * {
1325+ * // Otherwise, pin our task to core 0.
1326+ * vTaskCoreAffinitySet( xHandle, ( 1 << 0 ) );
1327+ * }
1328+ * }
1329+ */
1330+ UBaseType_t vTaskCoreAffinityGet ( const TaskHandle_t xTask );
1331+ #endif
1332+
1333+ /**
1334+ * @brief Disables preemption for a task.
1335+ *
1336+ * @param xTask The handle of the task to disable preemption. Passing NULL
1337+ * disables preemption for the calling task.
1338+ *
1339+ * Example usage:
1340+ *
1341+ * void vTaskCode( void *pvParameters )
1342+ * {
1343+ * // Silence warnings about unused parameters.
1344+ * ( void ) pvParameters;
1345+ *
1346+ * for( ;; )
1347+ * {
1348+ * // ... Perform some function here.
1349+ *
1350+ * // Disable preemption for this task.
1351+ * vTaskPreemptionDisable( NULL );
1352+ *
1353+ * // The task will not be preempted when it is executing in this portion ...
1354+ *
1355+ * // ... until the preemption is enabled again.
1356+ * vTaskPreemptionEnable( NULL );
1357+ *
1358+ * // The task can be preempted when it is executing in this portion.
1359+ * }
1360+ * }
1361+ */
12511362void vTaskPreemptionDisable ( const TaskHandle_t xTask );
1363+
1364+ /**
1365+ * @brief Enables preemption for a task.
1366+ *
1367+ * @param xTask The handle of the task to enable preemption. Passing NULL
1368+ * enables preemption for the calling task.
1369+ *
1370+ * Example usage:
1371+ *
1372+ * void vTaskCode( void *pvParameters )
1373+ * {
1374+ * // Silence warnings about unused parameters.
1375+ * ( void ) pvParameters;
1376+ *
1377+ * for( ;; )
1378+ * {
1379+ * // ... Perform some function here.
1380+ *
1381+ * // Disable preemption for this task.
1382+ * vTaskPreemptionDisable( NULL );
1383+ *
1384+ * // The task will not be preempted when it is executing in this portion ...
1385+ *
1386+ * // ... until the preemption is enabled again.
1387+ * vTaskPreemptionEnable( NULL );
1388+ *
1389+ * // The task can be preempted when it is executing in this portion.
1390+ * }
1391+ * }
1392+ */
12521393void vTaskPreemptionEnable ( const TaskHandle_t xTask );
12531394
12541395/*-----------------------------------------------------------
0 commit comments