μC/OS-II---事件标志组管理1(os_flag.c)

目录

    • 事件标志组创建
    • 事件标志组删除
    • 事件标志组获取/等待

在这里插入图片描述

  • 当任务要与多个事件同步时,就要使用事件标志组。
  • 一个事件标志就是一个二值信号,事件标志组是若干二值信号的组合。
  • 使用事件标志组同步任务分为独立性同步和关联性同步。

事件标志组创建

  • flags:事件标志组的初始值。
OS_FLAG_GRP  *OSFlagCreate (OS_FLAGS  flags,INT8U    *perr)
{OS_FLAG_GRP *pgrp;
#if OS_CRITICAL_METHOD == 3u                        /* Allocate storage for CPU status register        */OS_CPU_SR    cpu_sr = 0u;
#endif
#ifdef OS_SAFETY_CRITICALif (perr == (INT8U *)0){OS_SAFETY_CRITICAL_EXCEPTION();return ((OS_FLAG_GRP *)0);}#endif
#ifdef OS_SAFETY_CRITICAL_IEC61508if (OSSafetyCriticalStartFlag == OS_TRUE){OS_SAFETY_CRITICAL_EXCEPTION();return ((OS_FLAG_GRP *)0);}#endifif (OSIntNesting > 0u)                          /* See if called from ISR ...                      */{*perr = OS_ERR_CREATE_ISR;                  /* ... can't CREATE from an ISR                    */return ((OS_FLAG_GRP *)0);}OS_ENTER_CRITICAL();pgrp = OSFlagFreeList;                          /* Get next free event flag                        */if (pgrp != (OS_FLAG_GRP *)0)                   /* See if we have event flag groups available      */{/* Adjust free list                                */OSFlagFreeList       = (OS_FLAG_GRP *)OSFlagFreeList->OSFlagWaitList;pgrp->OSFlagType     = OS_EVENT_TYPE_FLAG;  /* Set to event flag group type                    */pgrp->OSFlagFlags    = flags;               /* Set to desired initial value                    */pgrp->OSFlagWaitList = (void *)0;           /* Clear list of tasks waiting on flags            */
#if OS_FLAG_NAME_EN > 0upgrp->OSFlagName     = (INT8U *) (void *)"?";
#endifOS_EXIT_CRITICAL();*perr                = OS_ERR_NONE;}else{OS_EXIT_CRITICAL();*perr                = OS_ERR_FLAG_GRP_DEPLETED;}return (pgrp);                                  /* Return pointer to event flag group              */
}

事件标志组删除

#if OS_FLAG_DEL_EN > 0u
OS_FLAG_GRP  *OSFlagDel (OS_FLAG_GRP  *pgrp,INT8U         opt,INT8U        *perr)
{BOOLEAN       tasks_waiting;OS_FLAG_NODE *pnode;OS_FLAG_GRP  *pgrp_return;
#if OS_CRITICAL_METHOD == 3u                               /* Allocate storage for CPU status register */OS_CPU_SR     cpu_sr = 0u;
#endif
#ifdef OS_SAFETY_CRITICALif (perr == (INT8U *)0){OS_SAFETY_CRITICAL_EXCEPTION();return ((OS_FLAG_GRP *)0);}#endif
#if OS_ARG_CHK_EN > 0uif (pgrp == (OS_FLAG_GRP *)0)                          /* Validate 'pgrp'                          */{*perr = OS_ERR_FLAG_INVALID_PGRP;return (pgrp);}#endifif (OSIntNesting > 0u)                                 /* See if called from ISR ...               */{*perr = OS_ERR_DEL_ISR;                            /* ... can't DELETE from an ISR             */return (pgrp);}if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG)            /* Validate event group type                */{*perr = OS_ERR_EVENT_TYPE;return (pgrp);}OS_ENTER_CRITICAL();if (pgrp->OSFlagWaitList != (void *)0)                 /* See if any tasks waiting on event flags  */{tasks_waiting = OS_TRUE;                           /* Yes                                      */}else{tasks_waiting = OS_FALSE;                          /* No                                       */}switch (opt){case OS_DEL_NO_PEND:                               /* Delete group if no task waiting          */if (tasks_waiting == OS_FALSE){
#if OS_FLAG_NAME_EN > 0upgrp->OSFlagName     = (INT8U *) (void *)"?";
#endifpgrp->OSFlagType     = OS_EVENT_TYPE_UNUSED;pgrp->OSFlagWaitList = (void *)OSFlagFreeList; /* Return group to free list           */pgrp->OSFlagFlags    = (OS_FLAGS)0;OSFlagFreeList       = pgrp;OS_EXIT_CRITICAL();*perr                = OS_ERR_NONE;pgrp_return          = (OS_FLAG_GRP *)0;  /* Event Flag Group has been deleted        */}else{OS_EXIT_CRITICAL();*perr                = OS_ERR_TASK_WAITING;pgrp_return          = pgrp;}break;case OS_DEL_ALWAYS:                                /* Always delete the event flag group       */pnode = (OS_FLAG_NODE *)pgrp->OSFlagWaitList;while (pnode != (OS_FLAG_NODE *)0)            /* Ready ALL tasks waiting for flags        */{(void)OS_FlagTaskRdy (pnode, (OS_FLAGS)0, OS_STAT_PEND_ABORT);pnode = (OS_FLAG_NODE *)pnode->OSFlagNodeNext;}#if OS_FLAG_NAME_EN > 0upgrp->OSFlagName     = (INT8U *) (void *)"?";
#endifpgrp->OSFlagType     = OS_EVENT_TYPE_UNUSED;pgrp->OSFlagWaitList = (void *)OSFlagFreeList;/* Return group to free list                */pgrp->OSFlagFlags    = (OS_FLAGS)0;OSFlagFreeList       = pgrp;OS_EXIT_CRITICAL();if (tasks_waiting == OS_TRUE)                 /* Reschedule only if task(s) were waiting  */{OS_Sched();                               /* Find highest priority task ready to run  */}*perr = OS_ERR_NONE;pgrp_return          = (OS_FLAG_GRP *)0;      /* Event Flag Group has been deleted        */break;default:OS_EXIT_CRITICAL();*perr                = OS_ERR_INVALID_OPT;pgrp_return          = pgrp;break;}return (pgrp_return);
}
#endif

事件标志组获取/等待

OS_FLAGS  OSFlagPend (OS_FLAG_GRP  *pgrp,OS_FLAGS      flags,INT8U         wait_type,INT32U        timeout,INT8U        *perr)
{OS_FLAG_NODE  node;OS_FLAGS      flags_rdy;INT8U         result;INT8U         pend_stat;BOOLEAN       consume;
#if OS_CRITICAL_METHOD == 3u                               /* Allocate storage for CPU status register */OS_CPU_SR     cpu_sr = 0u;
#endif
#ifdef OS_SAFETY_CRITICALif (perr == (INT8U *)0){OS_SAFETY_CRITICAL_EXCEPTION();return ((OS_FLAGS)0);}#endif
#if OS_ARG_CHK_EN > 0uif (pgrp == (OS_FLAG_GRP *)0)                          /* Validate 'pgrp'                          */{*perr = OS_ERR_FLAG_INVALID_PGRP;return ((OS_FLAGS)0);}#endifif (OSIntNesting > 0u)                                 /* See if called from ISR ...               */{*perr = OS_ERR_PEND_ISR;                           /* ... can't PEND from an ISR               */return ((OS_FLAGS)0);}if (OSLockNesting > 0u)                                /* See if called with scheduler locked ...  */{*perr = OS_ERR_PEND_LOCKED;                        /* ... can't PEND when locked               */return ((OS_FLAGS)0);}if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG)            /* Validate event block type                */{*perr = OS_ERR_EVENT_TYPE;return ((OS_FLAGS)0);}result = (INT8U) (wait_type & OS_FLAG_CONSUME);if (result != (INT8U)0)                                /* See if we need to consume the flags      */{wait_type &= (INT8U)~ (INT8U)OS_FLAG_CONSUME;consume    = OS_TRUE;}else{consume    = OS_FALSE;}/*$PAGE*/OS_ENTER_CRITICAL();switch (wait_type){case OS_FLAG_WAIT_SET_ALL:                         /* See if all required flags are set        */flags_rdy = (OS_FLAGS) (pgrp->OSFlagFlags & flags);  /* Extract only the bits we want     */if (flags_rdy == flags)                       /* Must match ALL the bits that we want     */{if (consume == OS_TRUE)                   /* See if we need to consume the flags      */{pgrp->OSFlagFlags &= (OS_FLAGS)~flags_rdy;   /* Clear ONLY the flags we wanted    */}OSTCBCur->OSTCBFlagsRdy = flags_rdy;      /* Save flags that were ready               */OS_EXIT_CRITICAL();                       /* Yes, condition met, return to caller     */*perr                   = OS_ERR_NONE;return (flags_rdy);}else                                          /* Block task until events occur or timeout */{OS_FlagBlock (pgrp, &node, flags, wait_type, timeout);OS_EXIT_CRITICAL();}break;case OS_FLAG_WAIT_SET_ANY:flags_rdy = (OS_FLAGS) (pgrp->OSFlagFlags & flags);   /* Extract only the bits we want    */if (flags_rdy != (OS_FLAGS)0)                 /* See if any flag set                      */{if (consume == OS_TRUE)                   /* See if we need to consume the flags      */{pgrp->OSFlagFlags &= (OS_FLAGS)~flags_rdy;    /* Clear ONLY the flags that we got */}OSTCBCur->OSTCBFlagsRdy = flags_rdy;      /* Save flags that were ready               */OS_EXIT_CRITICAL();                       /* Yes, condition met, return to caller     */*perr                   = OS_ERR_NONE;return (flags_rdy);}else                                          /* Block task until events occur or timeout */{OS_FlagBlock (pgrp, &node, flags, wait_type, timeout);OS_EXIT_CRITICAL();}break;
#if OS_FLAG_WAIT_CLR_EN > 0ucase OS_FLAG_WAIT_CLR_ALL:                         /* See if all required flags are cleared    */flags_rdy = (OS_FLAGS)~pgrp->OSFlagFlags & flags;    /* Extract only the bits we want     */if (flags_rdy == flags)                       /* Must match ALL the bits that we want     */{if (consume == OS_TRUE)                   /* See if we need to consume the flags      */{pgrp->OSFlagFlags |= flags_rdy;       /* Set ONLY the flags that we wanted        */}OSTCBCur->OSTCBFlagsRdy = flags_rdy;      /* Save flags that were ready               */OS_EXIT_CRITICAL();                       /* Yes, condition met, return to caller     */*perr                   = OS_ERR_NONE;return (flags_rdy);}else                                          /* Block task until events occur or timeout */{OS_FlagBlock (pgrp, &node, flags, wait_type, timeout);OS_EXIT_CRITICAL();}break;case OS_FLAG_WAIT_CLR_ANY:flags_rdy = (OS_FLAGS)~pgrp->OSFlagFlags & flags;   /* Extract only the bits we want      */if (flags_rdy != (OS_FLAGS)0)                 /* See if any flag cleared                  */{if (consume == OS_TRUE)                   /* See if we need to consume the flags      */{pgrp->OSFlagFlags |= flags_rdy;       /* Set ONLY the flags that we got           */}OSTCBCur->OSTCBFlagsRdy = flags_rdy;      /* Save flags that were ready               */OS_EXIT_CRITICAL();                       /* Yes, condition met, return to caller     */*perr                   = OS_ERR_NONE;return (flags_rdy);}else                                          /* Block task until events occur or timeout */{OS_FlagBlock (pgrp, &node, flags, wait_type, timeout);OS_EXIT_CRITICAL();}break;
#endifdefault:OS_EXIT_CRITICAL();flags_rdy = (OS_FLAGS)0;*perr      = OS_ERR_FLAG_WAIT_TYPE;return (flags_rdy);}/*$PAGE*/OS_Sched();                                            /* Find next HPT ready to run               */OS_ENTER_CRITICAL();if (OSTCBCur->OSTCBStatPend != OS_STAT_PEND_OK)        /* Have we timed-out or aborted?            */{pend_stat                = OSTCBCur->OSTCBStatPend;OSTCBCur->OSTCBStatPend  = OS_STAT_PEND_OK;OS_FlagUnlink (&node);OSTCBCur->OSTCBStat      = OS_STAT_RDY;            /* Yes, make task ready-to-run              */OS_EXIT_CRITICAL();flags_rdy                = (OS_FLAGS)0;switch (pend_stat){case OS_STAT_PEND_ABORT:*perr = OS_ERR_PEND_ABORT;                /* Indicate that we aborted   waiting       */break;case OS_STAT_PEND_TO:default:*perr = OS_ERR_TIMEOUT;                   /* Indicate that we timed-out waiting       */break;}return (flags_rdy);}flags_rdy = OSTCBCur->OSTCBFlagsRdy;if (consume == OS_TRUE)                                /* See if we need to consume the flags      */{switch (wait_type){case OS_FLAG_WAIT_SET_ALL:case OS_FLAG_WAIT_SET_ANY:                     /* Clear ONLY the flags we got              */pgrp->OSFlagFlags &= (OS_FLAGS)~flags_rdy;break;
#if OS_FLAG_WAIT_CLR_EN > 0ucase OS_FLAG_WAIT_CLR_ALL:case OS_FLAG_WAIT_CLR_ANY:                     /* Set   ONLY the flags we got              */pgrp->OSFlagFlags |=  flags_rdy;break;
#endifdefault:OS_EXIT_CRITICAL();*perr = OS_ERR_FLAG_WAIT_TYPE;return ((OS_FLAGS)0);}}OS_EXIT_CRITICAL();*perr = OS_ERR_NONE;                                   /* Event(s) must have occurred              */return (flags_rdy);
}

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

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

相关文章

MySql分区

一、什么是分区 MySQL分区是一种数据库设计和管理技术,它允许你将表分割成独立的、具有特定规则的存储单元。每个分区可以独立地进行管理,包括备份、恢复和优化。分区的主要目的是提高查询性能、简化维护以及实现数据的更有效管理。 以下是MySQL分区的…

IDEA 集成 Docker 插件一键部署 SpringBoot 应用

目录 前言IDEA 安装 Docker 插件配置 Docker 远程服务器编写 DockerFileSpringBoot 项目部署配置SpringBoot 项目部署结语 前言 随着容器化技术的崛起,Docker成为了现代软件开发的关键工具。在Java开发中,Spring Boot是一款备受青睐的框架,然…

PCL 半径滤波剔除噪点(二)

目录 一、算法原理二、注意事项三、代码实现一、算法原理 PCL半径滤波是删除在输入的点云一定范围内没有达到足够多领域的所有数据点。通俗的讲:就是以一个点p给定一个范围r,领域点要求的个数为m,r若在这个点的r范围内部的个数大于m则保留,小于m则删除。因此,使用该算法时…

阎良区公益创投之“小飞机大梦想” 航模DIY主题活动

创造是人类探索迈出的第一步,科学是开启奇妙世界的金钥匙。为进一步提升“未来星”对科技知识的兴趣,培养他们的科学创新精神,11月16日,阎良区社会组织公益创投——“未来星”助力乡村留守儿童成长计划项目在阎良区聚宝小学开展“…

【淘宝API】商品详情+搜索商品列表接口

淘宝商品详情API接口可以使用淘宝开放平台提供的SDK或API来获取。这些接口可以用于获取商品的详细信息,如标题、价格、描述、图片等。 以下是使用淘宝开放平台API获取商品详情的步骤: 注册淘宝开放平台账号,并创建应用,获取应用…

【具身智能评估1】具身视觉语言规划(EVLP)仿真环境汇总

参考论文:Core Challenges in Embodied Vision-Language Planning 论文作者:Jonathan Francis, Nariaki Kitamura, Felix Labelle, Xiaopeng Lu, Ingrid Navarro, Jean Oh 论文原文:https://arxiv.org/abs/2106.13948 论文出处:Jo…

C#学习相关系列之Linq常用方法---排序(一)

一、构建数据 public class Student_1{public int ID { get; set; }public string Name { get; set; }public int Chinese { get; set; }public int Math { get; set; }public int English { get; set; }public override string ToString(){return string.Format("ID:{0},…

企业视频数字人有哪些应用场景

来做个数字人吧,帮我干点活吧。 国内的一些数字人: 腾讯智影 腾讯智影数字人是一种基于人工智能技术的数字人物形象,具有逼真的外观、语音和行为表现,可以应用于各种场景,如新闻播报、文娱推介、营销、教育等。 幻…

医院数字化LIS(检验信息系统)源码

临床检验信息管理系统(LIS)是利用计算机连接医疗设备,通过计算机信息处理技术,将医院检验科或实验室的临床检验数据进行自动收集、存储、处理、提取、传输和交换,满足所有授权用户的功能需求。 一、系统概述 1.LIS&am…

性能测试【第三篇】Jmeter的使用

线程数:10 ,设置10个并发 Ramp-Up时间(秒):所有线程在多少时间内启动,如果设置5,那么每秒启动2个线程 循环次数:请求的重复次数,如果勾选"永远"将一直发送请求 持续时间时间:设置场景运行的时间 启动延迟:设置场景延迟启动时间 响应断言 响应断言模式匹配规则 包括…

Qt QLable 字符过长省略

前言: 项目中常用到字符过长问题,Qt默认的省略并不好用,不是自己想要的; QFontMetri 可使用 QFontMetri 当text的像素宽度超过width,将返回字符串的一个省略版本取决于mode。否则将返回原字符串; mode…

解决STM32F429烧录程序后还需复位才能植入程序的bug

1.打开魔术棒,打开debug 2.打开setting 3.打开Flas Download 4.开启Reset and Run 5.点进去Pack选项页面,去掉enable

postgresql:记录表膨胀引起的io问题的处理

文章目录 1. io异常2.查看profile报告2.1 生成事发时间段的pgprofile2.2 查看报告 3.检查table是否膨胀4.执行vacuum full5.总结 1. io异常 iostat -x 1 20 Device r/s w/s rkB/s wkB/s rrqm/s wrqm/s %rrqm %wrqm r_await w_await aqu-sz rareq…

【数据结构】直接插入排序

👦个人主页:Weraphael ✍🏻作者简介:目前正在学习c和算法 ✈️专栏:数据结构 🐋 希望大家多多支持,咱一起进步!😁 如果文章有啥瑕疵 希望大佬指点一二 如果文章对你有帮助…

基于人工电场算法优化概率神经网络PNN的分类预测 - 附代码

基于人工电场算法优化概率神经网络PNN的分类预测 - 附代码 文章目录 基于人工电场算法优化概率神经网络PNN的分类预测 - 附代码1.PNN网络概述2.变压器故障诊街系统相关背景2.1 模型建立 3.基于人工电场优化的PNN网络5.测试结果6.参考文献7.Matlab代码 摘要:针对PNN神…

Stable Diffusion进阶玩法说明

之前章节介绍了Stable Diffusion的入门,介绍了文生图的魅力,可以生成很多漂亮的照片,非常棒 传送门: Stable Diffusion新手村-我们一起完成AI绘画-CSDN博客 那我们今天就进一步讲讲这个Stable Diffusion还能做些什么, …

C语言青蛙爬井(ZZULIOJ1072:青蛙爬井)

题目描述 有一口深度为high米的水井,井底有一只青蛙,它每天白天能够沿井壁向上爬up米,夜里则顺井壁向下滑down米,若青蛙从某个早晨开始向外爬,对于任意指定的high、up和down值(均为自然数)&…

电脑软件:推荐一款非常实用的固态硬盘优化工具

目录 一、软件简介 二、工作原理 三、功能介绍 3.1、优化SSD设置 3.2、查看驱动器信息 3.3、查看SMART数据 3.4、停用Windows事件日志记录 3.5、禁用Windows碎片整理 3.6、时间戳停用 3.7、禁用引导文件的碎片整理 3.8、关闭短名称 四、使用教程 4.1 安装说明 4.…

滚雪球学Java(09-3):Java中的逻辑运算符,你真的掌握了吗?

咦咦咦,各位小可爱,我是你们的好伙伴——bug菌,今天又来给大家普及Java SE相关知识点了,别躲起来啊,听我讲干货还不快点赞,赞多了我就有动力讲得更嗨啦!所以呀,养成先点赞后阅读的好…

【算法训练营】参数解析+跳石板

🌈欢迎来到Python专栏 🙋🏾‍♀️作者介绍:前PLA队员 目前是一名普通本科大三的软件工程专业学生 🌏IP坐标:湖北武汉 🍉 目前技术栈:C/C、Linux系统编程、计算机网络、数据结构、Mys…