Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Learning Notes-RTOS Task creation

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report