μ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;审核通过后即可发布活动和奖励。 签到打…

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

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

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

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

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

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

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

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

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

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

OSCNet: Orientation-Shared Convolutional Network for CT Metal Artifact Learning

OSCNet: 面向共享的CT金属伪影学习卷积网络 论文链接&#xff1a;https://ieeexplore.ieee.org/document/10237226 项目链接&#xff1a;https://github.com/hongwang01/OSCNet&#xff08;目前不会开源&#xff09; Abstract X射线计算机断层扫描(CT)已广泛应用于疾病诊断和…

如何利用IP代理进行海外推广?

在当今数字化的时代&#xff0c;网络营销已经成为企业策略的重要组成部分。而对于进去海外市场的跨境玩家来说&#xff0c;海外的推广推广是重中之重。然而&#xff0c;在开展推广的过程中&#xff0c;我们常常会遇到各种挑战&#xff0c;如地域限制、访问速度慢等。 为了解决…

arcgis--消除坐标系信息的两种方法

方法一&#xff1a;在【目录】中右击待修改数据&#xff0c;选择【属性】&#xff0c;选择【XY坐标】选项卡&#xff0c;点击清楚按钮。 方法二&#xff1a;在【数据管理工具】-【投影与变换】-【定义投影】中清楚坐标系信息。如下&#xff1a;

el-table实现单选和隐藏全选框和回显数据

0 效果 1 单选 <el-table ref"clientTableRef" selection-change"clientChangeHandle"><el-table-column fixed type"selection" width"50" align"center" /><el-table-column label"客户名称" a…

ChatGPT-4:OpenAI的革命性升级

在人工智能领域&#xff0c;OpenAI这家公司凭借其创新性的技术&#xff0c;成为了备受瞩目的领导者。他们最近发布的ChatGPT-4&#xff0c;以其卓越的语言处理能力和先进的模型架构&#xff0c;引领了语言模型领域的革命性升级。 ChatGPT-4的模型容量相较于前一版本有了显著的提…

“糖尿病日”感言

长期旺盛的写作欲&#xff0c;今天忽地就莫名其妙地衰退下来了。感到浑身都不舒服&#xff0c;特别是过去从未出现过的腰微痛、乏力现象发生了。 转念一想&#xff0c;或是老龄人一日不如一日的正常反应吧&#xff1f;而且&#xff0c;今天恰逢“ 联合国糖尿病日”&#xff0c…

【MySQL】库和表的操作

目录 一、库操作1.创建数据库字符集和校验规则校验规则对数据库的影响 2.查看数据库3.修改数据库4.删除数据库5.数据库备份6.查看连接情况 二、表操作1.创建表2.查看表3.修改表4.删除表 一、库操作 1.创建数据库 create database db1; //方法1 create database is not exists…

Live800:金牌客服常用的6大提问技巧

在客服行业&#xff0c;提问技巧是非常重要的一项技能。好的提问技巧不仅能够帮助客服人员更好地了解客户需求&#xff0c;还能够提高客户满意度和忠诚度。以下是金牌客服常用的6大提问技巧&#xff0c;希望能够对客服人员提升工作效率有所帮助。 1、开放性问题 开放性问题是指…

物联网AI MicroPython学习之语法 umqtt客户端

学物联网&#xff0c;来万物简单IoT物联网&#xff01;&#xff01; umqtt 介绍 模块功能: MQTT客户端功能 - 连线、断线、发布消息、订阅主题、KeepAlive等功能。 MQTT协议采用订阅者/发布者模式&#xff0c;协议中定义了消息服务质量&#xff08;Quality of Service&#x…

能链智电的野心,充电桩装不下

作者 | 张未 来源 | 洞见新研社 从油到电&#xff0c;从平台到资产运营方&#xff0c;从国内到国外&#xff0c;能链智电的野心&#xff0c;充电桩装不下。 “充电桩服务第一股”能链智电&#xff0c;曾作为平台型企业&#xff0c;连接了充电桩上下游&#xff0c;为充电桩制造…

基于SSM的供电所档案管理系统

末尾获取源码 开发语言&#xff1a;Java Java开发工具&#xff1a;JDK1.8 后端框架&#xff1a;SSM 前端&#xff1a;采用JSP技术开发 数据库&#xff1a;MySQL5.7和Navicat管理工具结合 服务器&#xff1a;Tomcat8.5 开发软件&#xff1a;IDEA / Eclipse 是否Maven项目&#x…

Realistic fault detection of li-ion battery via dynamical deep learning

昇科能源、清华大学欧阳明高院士团队等的最新研究成果《动态深度学习实现锂离子电池异常检测》&#xff0c;用已经处理的整车充电段数据&#xff0c;分析车辆当前或近期是否存在故障。 思想步骤&#xff1a; 用正常电池的充电片段数据构造训练集&#xff0c;用如下的方式构造…

Web APIs——正则表达式使用

1、什么是正则表达式 正则表达式&#xff08;Regular Expression&#xff09;是用于匹配字符串中字符组合的模式。在JavaScript中&#xff0c;正则表达式也是对象 通常用来查找、替换那些符合正则表达式的文本&#xff0c;许多语言都支持正则表达式 1.1 正则表达式使用场景 例如…