MCPcopy Create free account
hub / github.com/FreeRTOS/FreeRTOS-Kernel / xTaskCreate

Function xTaskCreate

tasks.c:1209–1295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1207#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
1208
1209 BaseType_t xTaskCreate( TaskFunction_t pxTaskCode,
1210 const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1211 const configSTACK_DEPTH_TYPE usStackDepth,
1212 void * const pvParameters,
1213 UBaseType_t uxPriority,
1214 TaskHandle_t * const pxCreatedTask )
1215 {
1216 TCB_t * pxNewTCB;
1217 BaseType_t xReturn;
1218
1219 /* If the stack grows down then allocate the stack then the TCB so the stack
1220 * does not grow into the TCB. Likewise if the stack grows up then allocate
1221 * the TCB then the stack. */
1222 #if ( portSTACK_GROWTH > 0 )
1223 {
1224 /* Allocate space for the TCB. Where the memory comes from depends on
1225 * the implementation of the port malloc function and whether or not static
1226 * allocation is being used. */
1227 pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) );
1228
1229 if( pxNewTCB != NULL )
1230 {
1231 /* Allocate space for the stack used by the task being created.
1232 * The base of the stack memory stored in the TCB so the task can
1233 * be deleted later if required. */
1234 pxNewTCB->pxStack = ( StackType_t * ) pvPortMallocStack( ( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ) ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */
1235
1236 if( pxNewTCB->pxStack == NULL )
1237 {
1238 /* Could not allocate the stack. Delete the allocated TCB. */
1239 vPortFree( pxNewTCB );
1240 pxNewTCB = NULL;
1241 }
1242 }
1243 }
1244 #else /* portSTACK_GROWTH */
1245 {
1246 StackType_t * pxStack;
1247
1248 /* Allocate space for the stack used by the task being created. */
1249 pxStack = pvPortMallocStack( ( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ) ) ); /*lint !e9079 All values returned by pvPortMalloc() have at least the alignment required by the MCU's stack and this allocation is the stack. */
1250
1251 if( pxStack != NULL )
1252 {
1253 /* Allocate space for the TCB. */
1254 pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) ); /*lint !e9087 !e9079 All values returned by pvPortMalloc() have at least the alignment required by the MCU's stack, and the first member of TCB_t is always a pointer to the task's stack. */
1255
1256 if( pxNewTCB != NULL )
1257 {
1258 /* Store the stack location in the TCB. */
1259 pxNewTCB->pxStack = pxStack;
1260 }
1261 else
1262 {
1263 /* The stack cannot be used as the TCB was not created. Free
1264 * it again. */
1265 vPortFreeStack( pxStack );
1266 }

Callers 3

prvCreateIdleTasksFunction · 0.85
xTimerCreateTimerTaskFunction · 0.85
MPU_xTaskCreateFunction · 0.85

Calls 4

prvInitialiseNewTaskFunction · 0.85
prvAddNewTaskToReadyListFunction · 0.85
pvPortMallocFunction · 0.50
vPortFreeFunction · 0.50

Tested by

no test coverage detected