Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Learning Notes-RTOS Task creation

Shulou Source: shulou.com Published: 2022-06-03 07:07:00 09月24日 Update

Task creation

1 tasks require RAM to save task-related status information (task control block)

2 A certain RAM is required as the task stack

XTaskCreate () will be allocated from the FreeRTOS heap and must provide a memory management file

Heap_4.c is used by default

3 Macro configSUPPORT_DYNAMIC_ALLOCATION must be 1

4. If the function xTaskCreateStatic () is created, these RAM will need to be provided by the user.

ConfigSUPPORT_STATIC_ALLOCATION is set to 1

5 tasks can be created before or after Task Scheduler starts.

The most commonly used one

BaseType_t xTaskCreate (TaskFunction_t pxTaskCode

Const char * const pcName

Const uint16_t usStackDepth

Void * const pvParameters

UBaseType_t uxPriority

TaskHandle_t * const pxCreatedTask)

PxCreatedTask task handle, which is the task stack of the task, which may be used by other API

The return value reflects the success or error code of the task creation.

PdPASS: the task was created successfully.

6 not commonly used

TaskHandle_t xTaskCreateStatic (TaskFunction_t pxTaskCode

Const char * const pcName

Const uint32_t ulStackDepth

Void * const pvParameters

UBaseType_t uxPriority

StackType_t * const puxStackBuffer

StaticTask_t * const pxTaskBuffer)

PxTaskBuffer: task control block.

Return value: NULL: task creation failed

Other values: the task is created successfully, and the task handle of the task is returned.

7 vTaskDelete (TaskHandle_t xTaskToDelete)

XTaskToDelete: the task handle of the task to delete.

You can use NULL as a parameter to delete the task itself

8 key experiments (learning dynamic creation):

Task creation:

# define START_TASK_PRIO 1 / / Task priority

# define START_STK_SIZE 128 / / Task stack size

TaskHandle_t StartTask_Handler; / / Task handle

Void start_task (void * pvParameters); / / Task function

XTaskCreate ((TaskFunction_t) start_task, / / Task function

(const char*) "start_task", / / Task name

(uint16_t) START_STK_SIZE, / / Task stack size

(void*) NULL, / / parameters passed to the task function

(UBaseType_t) START_TASK_PRIO, / / Task priority

(TaskHandle_t*) & StartTask_Handler); / / Task handle

VTaskStartScheduler (); / / enable task scheduling

Start the task:

TaskENTER_CRITICAL (); / / enter the critical area

/ / create a TASK1 task

.

/ / create a TASK2 task

VTaskDelete (StartTask_Handler); / / Delete the start task

TaskEXIT_CRITICAL (); / / exit the critical area

Task stack, task handle, task function declaration, etc., so that it is easy to modify. These things

Xi can put it in a .h header file.

Start tasks: create other application tasks and kernel objects such as semaphores and queues

Tags: Task handle function stack success priority parameter size common use file control scheduling learning thing signal information key memory kernel dynamic Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Huawei Microsoft MariaDB Apple