FreeRTOS (creation and deletion of tasks)

1. What is a task?

Task can be understood asprocess/thread. Creating a task will open up a space in the memory.

For example: playing games and spending time with your girlfriend can be regarded as tasks

MarkText, Google Chrome, and Notepad in Windows systems are all tasks. Tasks usually contain while(1) infinite loops.

2. Functions related to task creation and deletion

There are three functions related to task creation and deletion:

The difference between dynamic creation and static creation of tasks: The stack of a dynamically created task is allocated by the system, while the stack of a statically created task is passed by the user himself. Typically tasks are created dynamically. 

  • 1. pvTaskCode: Pointer to the task function, the task must be implemented to never return (i.e., continuous loop);
  • 2. pcName: The name of the task, mainly used for debugging, the maximum length is 16 by default;
  • 3. pvParameters: The size of the specified task stack;
  • 4. uxPriority: task priority, the larger the value, the greater the priority; 
  • 5. pxCreatedTask: The handle used to return the created task can be referenced

vTaskDelete function prototype 

 void vTaskDelete(TaskHandle_t xTaskToDelete);

Simply pass the handle of the task to be deleted to this function to delete the task.

When the parameter passed in is NULL, it means deleting the task itself (the currently running task).

A small experiment in task creation

Requirements: Create two tasks to realize the flipping of led1 and led2 respectively.

Some settings of cubemx

Code

 

 

 

おすすめ

転載: blog.csdn.net/m0_70987863/article/details/131678401