当前位置:网站首页>FreeRTOS--Priority Experiment
FreeRTOS--Priority Experiment
2022-08-02 12:31:00 【Mountain,】
FreeRTOS创建任务时,可以设置任务的优先级.在FreeRTOSThe value of medium priority is smaller,优先级越低,其他的RTOSare the smaller the priority value,优先级越高,这点需要注意.
Task prioritization experiment:
Create three flags first,Only when the task is running,The corresponding task flag is 1.防止编译器优化掉,用volatile 修饰.
static volatile int Task1RunningFlag = 0;
static volatile int Task2RunningFlag = 0;
static volatile int Task3RunningFlag = 0;
void Task1(void * param)
{
while(1)
{
Task1RunningFlag = 1;
Task2RunningFlag = 0;
Task3RunningFlag = 0;
printf("A");
}
}
TaskHandle_t xHandleTask2;
void Task2(void * param)
{
while(1)
{
Task1RunningFlag = 0;
Task2RunningFlag = 1;
Task3RunningFlag = 0;
printf("a");
}
}
StackType_t xTask3Stack[100];
StaticTask_t xTask3Tcb;
void Task3(void * param)
{
while(1)
{
Task1RunningFlag = 0;
Task2RunningFlag = 0;
Task3RunningFlag = 1;
printf("1");
}
}
int main( void )
{
prvSetupHardware();
printf("Hello World!\r\n");
xTaskCreate(Task1,"Task1",100,NULL,1,&xHandleTask1);
xTaskCreate(Task2,"Task2",100,NULL,1,&xHandleTask2);
xTaskCreateStatic(Task3,"Task3",100,NULL,1,xTask3Stack,&xTask3Tcb);
vTaskStartScheduler();
return 0;
}
First set the priority of the three tasks to the same priority.
点击Debug进入仿真,Then add the three flag bits to the logic analyzer,Then set the variable to bit状态.

注意:用staticModified variables cannot be added to the logic analyzer initially,所以要去掉static修饰.如果要用static修饰,需要在main函数中打断点,wait for the program to runmain函数中,此时才能把staticModified variables are added to the logic analyzer.
点击全速运行,Observe the logic analyzer status.
可以看到,Only one task is running at a time,And the three tasks are executed interleaved with each other,Describe same-priority tasks,先后执行.
修改任务优先级,把任务1The priority is set to high priority,任务2、3优先级不变,然后看实验现象.
xTaskCreate(Task1,"Task1",100,NULL,2,&xHandleTask1);
xTaskCreate(Task2,"Task2",100,NULL,1,&xHandleTask2);
xTaskCreateStatic(Task3,"Task3",100,NULL,1,xTask3Stack,&xTask3Tcb);
输出结果:
可以看到,只有任务1在执行,任务2、3都得不到执行.Indicates that high-priority tasks are executed first,If the high priority task does not give up execution,Then the low priority task will never get executed.
Next set up two high priority tasks,看看实验结果:
xTaskCreate(Task1,"Task1",100,NULL,2,&xHandleTask1);
xTaskCreate(Task2,"Task2",100,NULL,2,&xHandleTask2);
xTaskCreateStatic(Task3,"Task3",100,NULL,1,xTask3Stack,&xTask3Tcb);

可以看到,Two high-priority tasks are executed alternately,Low priority tasks are not executed.
The above experiments are described inFreeRTOSin the default task scheduling mode,高优先级任务优先执行,Alternate execution of tasks with the same priority.
边栏推荐
- 手撸架构,Mysql 面试126问
- SQL function TRIM
- Import and export data of SQL Server database
- FreeRTOS实验--删除任务
- 免费文档翻译-免费批量文档翻译软件推荐
- 中原银行实时风控体系建设实践
- Taurus.MVC V3.0.3 Microservice Open Source Framework Released: Make the evolution of .NET architecture easier in large concurrency.
- SQL Server修改数据
- 30行代码实现无服务器实时健康码识别--操作手册
- Thymeleaf
猜你喜欢

The 7 most commonly used data analysis thinking, solve 95% of the analysis problems

7种最常用数据分析思维,解决95%的分析难题

FreeRTOS实验--删除任务

SQL Server2019安装步骤及脱机安装Microsoft机器学习组件下一步不能继续的问题

Data Lake (3): Hudi Concept Terminology

js秒表倒计时插件

php字符串的截取方式

翻译英语的软件-免费翻译软件-各种语言互相翻译

Drools(8): WorkBench uses

【The 6th Strong Net Cup CTF-Wp】
随机推荐
LeetCode_139_单词拆分
MD5详解(校验文件完整性)
SQL Server 2014安装教程(保姆级图解教程)
FreeRTOS创建任务--动态创建、静态创建
手撸架构,Redis面试41问
中原银行实时风控体系建设实践
力扣704-二分查找
linux basic command explanation
FreeRTOS中名称规范
Intelligent Image Analysis-Intelligent Home Appliance Image Target Detection Statistical Counting Detection and Recognition-iCREDIT
openresty 性能优化
openGauss数据库基本操作(超详细)
Manual architecture, Mysql interview 126 questions
基础协议讲解
力扣35-搜索插入位置——二分查找
自定义mvc框架复习
Likou 35 - search for insertion position - binary search
主流跨端技术一览
30 lines of code to realize serverless real-time health code recognition -- operation manual
Thymeleaf