μC/OS-II---Task管理2(os_task.c)

目录

    • 改变Task优先级
    • Task挂起
    • Task恢复
    • Task信息获取
    • Task调度器上锁(os_core.c)
    • Task调度器开锁(os_core.c)

在这里插入图片描述

改变Task优先级

#if OS_TASK_CHANGE_PRIO_EN > 0u
INT8U  OSTaskChangePrio (INT8U  oldprio,INT8U  newprio)
{
#if (OS_EVENT_EN)OS_EVENT  *pevent;
#if (OS_EVENT_MULTI_EN > 0u)OS_EVENT **pevents;
#endif
#endifOS_TCB    *ptcb;INT8U      y_new;INT8U      x_new;INT8U      y_old;OS_PRIO    bity_new;OS_PRIO    bitx_new;OS_PRIO    bity_old;OS_PRIO    bitx_old;
#if OS_CRITICAL_METHOD == 3uOS_CPU_SR  cpu_sr = 0u;                                 /* Storage for CPU status register         */
#endif/*$PAGE*/
#if OS_ARG_CHK_EN > 0uif (oldprio >= OS_LOWEST_PRIO){if (oldprio != OS_PRIO_SELF){return (OS_ERR_PRIO_INVALID);}}if (newprio >= OS_LOWEST_PRIO){return (OS_ERR_PRIO_INVALID);}#endifOS_ENTER_CRITICAL();if (OSTCBPrioTbl[newprio] != (OS_TCB *)0)               /* New priority must not already exist     */{OS_EXIT_CRITICAL();return (OS_ERR_PRIO_EXIST);}if (oldprio == OS_PRIO_SELF)                            /* See if changing self                    */{oldprio = OSTCBCur->OSTCBPrio;                      /* Yes, get priority                       */}ptcb = OSTCBPrioTbl[oldprio];if (ptcb == (OS_TCB *)0)                                /* Does task to change exist?              */{OS_EXIT_CRITICAL();                                 /* No, can't change its priority!          */return (OS_ERR_PRIO);}if (ptcb == OS_TCB_RESERVED)                            /* Is task assigned to Mutex               */{OS_EXIT_CRITICAL();                                 /* No, can't change its priority!          */return (OS_ERR_TASK_NOT_EXIST);}#if OS_LOWEST_PRIO <= 63uy_new                 = (INT8U) (newprio >> 3u);        /* Yes, compute new TCB fields             */x_new                 = (INT8U) (newprio & 0x07u);
#elsey_new                 = (INT8U) ((INT8U) (newprio >> 4u) & 0x0Fu);x_new                 = (INT8U) (newprio & 0x0Fu);
#endifbity_new              = (OS_PRIO) (1uL << y_new);bitx_new              = (OS_PRIO) (1uL << x_new);OSTCBPrioTbl[oldprio] = (OS_TCB *)0;                    /* Remove TCB from old priority            */OSTCBPrioTbl[newprio] =  ptcb;                          /* Place pointer to TCB @ new priority     */y_old                 =  ptcb->OSTCBY;bity_old              =  ptcb->OSTCBBitY;bitx_old              =  ptcb->OSTCBBitX;if ((OSRdyTbl[y_old] &   bitx_old) != 0u)               /* If task is ready make it not            */{OSRdyTbl[y_old] &= (OS_PRIO)~bitx_old;if (OSRdyTbl[y_old] == 0u){OSRdyGrp &= (OS_PRIO)~bity_old;}OSRdyGrp        |= bity_new;                       /* Make new priority ready to run          */OSRdyTbl[y_new] |= bitx_new;}#if (OS_EVENT_EN)pevent = ptcb->OSTCBEventPtr;if (pevent != (OS_EVENT *)0){pevent->OSEventTbl[y_old] &= (OS_PRIO)~bitx_old;    /* Remove old task prio from wait list     */if (pevent->OSEventTbl[y_old] == 0u){pevent->OSEventGrp    &= (OS_PRIO)~bity_old;}pevent->OSEventGrp        |= bity_new;              /* Add    new task prio to   wait list     */pevent->OSEventTbl[y_new] |= bitx_new;}#if (OS_EVENT_MULTI_EN > 0u)if (ptcb->OSTCBEventMultiPtr != (OS_EVENT **)0){pevents =  ptcb->OSTCBEventMultiPtr;pevent  = *pevents;while (pevent != (OS_EVENT *)0){pevent->OSEventTbl[y_old] &= (OS_PRIO)~bitx_old;   /* Remove old task prio from wait lists */if (pevent->OSEventTbl[y_old] == 0u){pevent->OSEventGrp    &= (OS_PRIO)~bity_old;}pevent->OSEventGrp        |= bity_new;          /* Add    new task prio to   wait lists    */pevent->OSEventTbl[y_new] |= bitx_new;pevents++;pevent                     = *pevents;}}#endif
#endifptcb->OSTCBPrio = newprio;                              /* Set new task priority                   */ptcb->OSTCBY    = y_new;ptcb->OSTCBX    = x_new;ptcb->OSTCBBitY = bity_new;ptcb->OSTCBBitX = bitx_new;OS_EXIT_CRITICAL();if (OSRunning == OS_TRUE){OS_Sched();                                         /* Find new highest priority task          */}return (OS_ERR_NONE);
}
#endif

Task挂起

#if OS_TASK_SUSPEND_EN > 0u
INT8U  OSTaskSuspend (INT8U prio)
{BOOLEAN    self;OS_TCB    *ptcb;INT8U      y;#if OS_CRITICAL_METHOD == 3u                     /* Allocate storage for CPU status register           */OS_CPU_SR  cpu_sr = 0u;#endif#if OS_ARG_CHK_EN > 0uif (prio == OS_TASK_IDLE_PRIO)                              /* Not allowed to suspend idle task    */{return (OS_ERR_TASK_SUSPEND_IDLE);}if (prio >= OS_LOWEST_PRIO)                                 /* Task priority valid ?               */{if (prio != OS_PRIO_SELF){return (OS_ERR_PRIO_INVALID);}}#endifOS_ENTER_CRITICAL();if (prio == OS_PRIO_SELF)                                   /* See if suspend SELF                 */{prio = OSTCBCur->OSTCBPrio;self = OS_TRUE;}else if (prio == OSTCBCur->OSTCBPrio)                       /* See if suspending self              */{self = OS_TRUE;}else{self = OS_FALSE;                                        /* No suspending another task          */}ptcb = OSTCBPrioTbl[prio];if (ptcb == (OS_TCB *)0)                                    /* Task to suspend must exist          */{OS_EXIT_CRITICAL();return (OS_ERR_TASK_SUSPEND_PRIO);}if (ptcb == OS_TCB_RESERVED)                                /* See if assigned to Mutex            */{OS_EXIT_CRITICAL();return (OS_ERR_TASK_NOT_EXIST);}y            = ptcb->OSTCBY;OSRdyTbl[y] &= (OS_PRIO)~ptcb->OSTCBBitX;                   /* Make task not ready                 */if (OSRdyTbl[y] == 0u){OSRdyGrp &= (OS_PRIO)~ptcb->OSTCBBitY;}ptcb->OSTCBStat |= OS_STAT_SUSPEND;                         /* Status of task is 'SUSPENDED'       */OS_EXIT_CRITICAL();if (self == OS_TRUE)                                        /* Context switch only if SELF         */{OS_Sched();                                             /* Find new highest priority task      */}return (OS_ERR_NONE);
}
#endif

Task恢复

#if OS_TASK_SUSPEND_EN > 0u
INT8U  OSTaskResume (INT8U prio)
{OS_TCB    *ptcb;
#if OS_CRITICAL_METHOD == 3u                                  /* Storage for CPU status register       */OS_CPU_SR  cpu_sr = 0u;
#endif
#if OS_ARG_CHK_EN > 0uif (prio >= OS_LOWEST_PRIO)                               /* Make sure task priority is valid      */{return (OS_ERR_PRIO_INVALID);}#endifOS_ENTER_CRITICAL();ptcb = OSTCBPrioTbl[prio];if (ptcb == (OS_TCB *)0)                                  /* Task to suspend must exist            */{OS_EXIT_CRITICAL();return (OS_ERR_TASK_RESUME_PRIO);}if (ptcb == OS_TCB_RESERVED)                              /* See if assigned to Mutex              */{OS_EXIT_CRITICAL();return (OS_ERR_TASK_NOT_EXIST);}if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) != OS_STAT_RDY)   /* Task must be suspended                */{ptcb->OSTCBStat &= (INT8U)~ (INT8U)OS_STAT_SUSPEND;   /* Remove suspension                     */if (ptcb->OSTCBStat == OS_STAT_RDY)                   /* See if task is now ready              */{if (ptcb->OSTCBDly == 0u){OSRdyGrp               |= ptcb->OSTCBBitY;    /* Yes, Make task ready to run           */OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;OS_EXIT_CRITICAL();if (OSRunning == OS_TRUE){OS_Sched();                               /* Find new highest priority task        */}}else{OS_EXIT_CRITICAL();}}else                                                  /* Must be pending on event              */{OS_EXIT_CRITICAL();}return (OS_ERR_NONE);}OS_EXIT_CRITICAL();return (OS_ERR_TASK_NOT_SUSPENDED);
}
#endif

Task信息获取

#if OS_TASK_QUERY_EN > 0u
INT8U  OSTaskQuery (INT8U    prio,OS_TCB  *p_task_data)
{OS_TCB    *ptcb;
#if OS_CRITICAL_METHOD == 3u                     /* Allocate storage for CPU status register           */OS_CPU_SR  cpu_sr = 0u;
#endif
#if OS_ARG_CHK_EN > 0uif (prio > OS_LOWEST_PRIO)                   /* Task priority valid ?                              */{if (prio != OS_PRIO_SELF){return (OS_ERR_PRIO_INVALID);}}if (p_task_data == (OS_TCB *)0)              /* Validate 'p_task_data'                             */{return (OS_ERR_PDATA_NULL);}#endifOS_ENTER_CRITICAL();if (prio == OS_PRIO_SELF)                    /* See if suspend SELF                                */{prio = OSTCBCur->OSTCBPrio;}ptcb = OSTCBPrioTbl[prio];if (ptcb == (OS_TCB *)0)                     /* Task to query must exist                           */{OS_EXIT_CRITICAL();return (OS_ERR_PRIO);}if (ptcb == OS_TCB_RESERVED)                 /* Task to query must not be assigned to a Mutex      */{OS_EXIT_CRITICAL();return (OS_ERR_TASK_NOT_EXIST);}/* Copy TCB into user storage area                    */OS_MemCopy ((INT8U *)p_task_data, (INT8U *)ptcb, sizeof (OS_TCB));OS_EXIT_CRITICAL();return (OS_ERR_NONE);
}
#endif

Task调度器上锁(os_core.c)

#if OS_SCHED_LOCK_EN > 0u
void  OSSchedLock (void)
{
#if OS_CRITICAL_METHOD == 3u                     /* Allocate storage for CPU status register           */OS_CPU_SR  cpu_sr = 0u;
#endifif (OSRunning == OS_TRUE)                    /* Make sure multitasking is running                  */{OS_ENTER_CRITICAL();if (OSIntNesting == 0u)                  /* Can't call from an ISR                             */{if (OSLockNesting < 255u)            /* Prevent OSLockNesting from wrapping back to 0      */{OSLockNesting++;                 /* Increment lock nesting level                       */}}OS_EXIT_CRITICAL();}
}
#endif

Task调度器开锁(os_core.c)

#if OS_SCHED_LOCK_EN > 0u
void  OSSchedUnlock (void)
{
#if OS_CRITICAL_METHOD == 3u                               /* Allocate storage for CPU status register */OS_CPU_SR  cpu_sr = 0u;
#endifif (OSRunning == OS_TRUE)                              /* Make sure multitasking is running        */{OS_ENTER_CRITICAL();if (OSIntNesting == 0u)                            /* Can't call from an ISR                   */{if (OSLockNesting > 0u)                        /* Do not decrement if already 0            */{OSLockNesting--;                           /* Decrement lock nesting level             */if (OSLockNesting == 0u)                   /* See if scheduler is enabled              */{OS_EXIT_CRITICAL();OS_Sched();                            /* See if a HPT is ready                    */}else{OS_EXIT_CRITICAL();}}else{OS_EXIT_CRITICAL();}}else{OS_EXIT_CRITICAL();}}
}
#endif

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/142113.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

多商家签到打卡奖励免单霸王餐小程序开发

多商家签到打卡奖励免单霸王餐小程序开发 用户注册和登录&#xff1a;提供用户注册和登录功能&#xff0c;以便用户能够参与签到打卡活动。 商家入驻&#xff1a;商家可申请入驻平台&#xff0c;提交相关资料并等待平台审核&#xff0c;审核通过后即可发布活动和奖励。 签到打…

【SSH】SSH异常处理思路

1.介绍 SSH&#xff08;Secure Shell&#xff09;是一种加密的网络协议&#xff0c;用于安全地远程连接到服务器或其他计算设备。它提供了加密的通信信道&#xff0c;以防止敏感信息被窃听或篡改。SSH支持多种身份验证方法&#xff0c;其中之一是密码身份验证。 密码登录是最常…

.one4-V-XXXXXXXX勒索病毒数据怎么处理|数据解密恢复

导言&#xff1a; 随着科技的不断发展&#xff0c;网络犯罪也在不断进化&#xff0c;.one4-V-XXXXXXXX勒索病毒作为其中的一种威胁&#xff0c;对个人和企业的数据安全构成了巨大的风险。本文将深入介绍.one4-V-XXXXXXXX勒索病毒的特点、详细的数据恢复方法&#xff0c;以及全…

Mysql 8.0 实现分组后获取组内极值算法 broup by

Mysql 8 中无法用低版本的 二次子查询实现&#xff0c;把数据集升序排列后&#xff0c;再外层做group By分组&#xff0c;取出第一条的方式。 因此引入了一个新函数&#xff0c;自动生成行序列&#xff0c;并且行序列按照指定字段分组后再根据自定字段进行排列原理如下 goupb…

相机通用类之LMI激光三角相机(3D),软触发硬触发(飞拍),并输出halcon格式对象

//在此之前可以先浏览我编写的通用上位机类&#xff0c;更方便理解 https://blog.csdn.net/m0_51559565/article/details/134403745最近完成一个关于LMI激光三角&#xff08;3D相机&#xff09;采图的demo&#xff0c;记录并说明用法。 先上代码。 using Lmi3d.GoSdk; using L…

使用FFmpeg转封装为hls(m3u8)流

​ 改造ffmpeg/doc/examples/remuxing.c&#xff0c;支持将输入流转封装为hls协议对应的github地址&#xff1a;GitHub - yagerfgcs/FFmpeg at examples/remuxing_support_hls修改点&#xff1a;增加设置hls头 // example:https://www.ffmpeg.org/ffmpeg-all.html#hls-2 // f…

c语言数据结构---三叉树

#include<stdio.h> #include<stdlib.h> #include<stack> using namespace std; typedef struct node{struct node*lchild;struct node*rchild;struct node*parent;char data; }Node,*Bit;Bit creat(){//先序创建 char b; int t; scanf("%c",&…

(个人实测保熟)记录Tecnomatix Process Simulate 16.1.2官方安装包及授权许可配置教程(Win10环境)

Tecnomatix Process Simulate 16是一款由西门子公司推出的一款工艺仿真解决方案,是虚拟制造仿真领域的领先解决方案,可帮助您数字化制造以及将创新思想和原材料转变为变革性产品的过程。在网上找了一些盗版的安装包&#xff0c;就很离谱。直接提示本"无法打开此安装程序包…

c语言数据结构---十字链表

#include<stdio.h> #include<stdlib.h> typedef struct node{//十字链表 输入三元组返回矩阵 int row,col,val;struct node *down,*right; }JD,*J; typedef struct {J *rhead,*chead;int mu,nu,tu;//行列非0元 }CS; CS creat(CS M){int m,n,t;;int k,j,e;JD *p,*q…

Elasticsearch和sboot整合

Elasticsearch是一个开源的、高性能的分布式搜索引擎&#xff0c;可以实现全文搜索、分析和存储等功能。Spring Boot是一个开源的Java框架&#xff0c;可以用于快速开发和部署应用程序。 将Elasticsearch和Spring Boot整合可以使得我们更加方便地使用Elasticsearch进行搜索和数…

Ajax实现步骤和原理

Ajax实现步骤和原理 一、什么是Ajax? Ajax 异步 JavaScript 和XML。   Ajax是一种用于创建快速动态网页的技术。   通过在后台与服务器进行少量数据交换&#xff0c;Ajax可以使网页实现异步更新。这意味着可以在不重新加载整个网页的情况下&#xff0c;对网页的某部分进…

Java并发面试题知识点总结(下篇)

大家好&#xff0c;我是栗筝i&#xff0c;从 2022 年 10 月份开始&#xff0c;我便开始致力于对 Java 技术栈进行全面而细致的梳理。这一过程&#xff0c;不仅是对我个人学习历程的回顾和总结&#xff0c;更是希望能够为各位提供一份参考。因此得到了很多读者的正面反馈。 而在…

Day01_《MySQL索引与性能优化》摘要

一、资料 视频&#xff1a;《尚硅谷MySQL数据库高级&#xff0c;mysql优化&#xff0c;数据库优化》—周阳 其他博主的完整笔记&#xff1a;MySQL 我的笔记&#xff1a;我的笔记只总结了视频p14-p46部分&#xff0c;因为只有这部分是讲解了MySQL的索引与explain语句分析优化…

【ruoyi】微服务关闭登录验证码

登录本地的nacos服务&#xff0c;修改&#xff1a;配置管理-配置列表-ruoyi-gateway-dev.yml 将验证码的enabled设置成false&#xff0c;即可

530.二叉搜索树的最小绝对

原题链接&#xff1a;530.二叉搜索树的最小绝对差 思路&#xff1a; 因为是二叉搜索树&#xff0c;根据他的特性&#xff0c;直接递归中序遍历获取所有元素&#xff0c;成为一个有序数组 然后在有序数值内进行双指针递归遍历即可获得最小差值 因为是有序数组&#xff0c;所以其…

深度学习之基于YoloV5的目标检测和双目测距系统

欢迎大家点赞、收藏、关注、评论啦 &#xff0c;由于篇幅有限&#xff0c;只展示了部分核心代码。 文章目录 一项目简介 二、功能三、系统四. 总结 一项目简介 双目测距系统利用两个相机的图像来计算目标到相机的距离。通过对左右相机图像进行立体匹配&#xff0c;可以获得目标…

Ubuntu安装Qt出现bash: ./qt-unified-linux-x64-4.6.1-online.run: 权限不够的问题解决

在Ubuntu安装qt&#xff0c;在官网下载了linux的版本下载后为类似qt-unified-linux-version.run的文件&#xff08;比如我这里是qt-unified-linux-x64-4.6.1-online.run&#xff09;的文件&#xff0c;直接在终端运行【这里的version注意改为文件的原有的名字】&#xff1a; .…

如果不用Baklib,哪一个帮助中心工具能够替代它?

在各行各业进入“留量时代”的当下&#xff0c;让用户获得良好的体验和留存老客户变得更为关键&#xff0c;这对于企业的客户服务提出了更高的要求。在使用各类互联网产品时&#xff0c;用户更倾向于通过自助方式寻找答案并解决问题&#xff0c;因此帮助中心的重要性也在不断提…

4路光栅尺磁栅尺编码器解码转换5MHz高速差分信号转Modbus TCP网络模块 YL97-RJ45

特点&#xff1a; ● 光栅尺磁栅尺解码转换成标准Modbus TCP协议 ● 光栅尺5V差分信号直接输入&#xff0c;4倍频计数 ● 模块可以输出5V的电源给光栅尺供电 ● 高速光栅尺磁栅尺计数&#xff0c;频率可达5MHz ● 支持4个光栅尺同时计数&#xff0c;可识别正反转 ● 可网…