FreeRTOS 之 vTaskDelete ()

vTaskDelete () function analysis

task. h
void vTaskDelete( TaskHandle_t xTask );

to sum up

Delete the task instance previously created using xTaskCreate () or xTaskCreateStatic ().
The deleted task no longer exists, so it cannot enter the running state.
Do not try to use the deleted task handle.
When a task is deleted, the idle task is responsible for releasing the memory used to save the stack and data structure (task control block) of the deleted task. Therefore, if the application uses the vTaskDelete () API function, the application must also ensure that idle tasks do not occupy processing time (the idle task time must be allocated in the running state).
Only the memory allocated to the task by the kernel itself will be automatically released when the task is deleted. The memory or any other resources allocated to the task by the application (not the kernel) must be explicitly released by the application when the task is deleted.

parameter

parameter significance
xTask The handle of the task to be deleted (main task). To get the task handle, you can use xTaskCreate () to create the task and use the pxCreatedTask parameter, or use xTaskCreateStatic () to create the task and store the return value, or use the task name when calling xTaskGetHandle () Tasks can delete themselves by passing NULL instead of a valid task handle.

return value

None

Use routines

void vOtherFunction( void )
 {
 TaskHandle_t xHandle = NULL;

     // Create the task, storing the handle.
     xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );

     // Use the handle to delete the task.
     if( xHandle != NULL )
     {
         vTaskDelete( xHandle );
     }
 }

Explanation

no

Freertos more exciting

Published 163 original articles · Liked 183 · Visit 120,000+

Guess you like

Origin blog.csdn.net/qq_31339221/article/details/102648705