47 Star 204 Fork 37

零中断延迟的RTOS / CosyOS

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

logo 温馨舒适的操作系统、零中断延迟的操作系统 :grey_exclamation:

Author languge license version star fork

  • CosyOS QQ交流群:303421780.

公告

  • CosyOS-II 自 V2.1.0 版本开始,采用尤为高效的任务调度算法,任务调度与切换性能大幅提升!
  • CosyOS-II 现已支持 Cortex-M 系列全部内核,M0/M0+/M23/M3/M4/M33/M7。
  • CosyOS 取得重大技术突破,现已升级至 CosyOS-II,代码风格焕然一新,说明文档持续更新中。原有 CosyOS-I 停止更新维护,但仍提供技术支持。

序言

  • 近年来,随着RTOS的普及及在嵌入式设备中的广泛应用,以关闭总中断等方式来保护临界段所带来的危害性(丢失响应、处理延误)正日益凸显出来,其中以高速通讯接收丢帧、高速捕获丢失脉冲等中断丢失响应现象最为紧要和普遍。
  • 有些RTOS,肆意关闭总中断,且未能提供“最大关闭中断时间”等核心关键参数,实时性已无从谈起。据统计,已经有越来越多的用户均对此表达了不满,并对RTOS中断响应的实时性提出了要求,希望高优先级中断能够实时抢占、零中断延迟。
  • 随着时代的发展、科技的进步,零中断延迟已经成为可能,RTOS正悄然的面临着一场时代的变革... ...
  • 2023年,CosyOS 应运而生!

简介

CosyOS是一款来自中国的开源实时操作系统,从经典的8051内核,到流行的Arm Cortex-M内核,均可实现全局不关总中断、零中断延迟,适用于对系统实时性及中断响应速度有较高要求的场合。
CosyOS以零中断延迟为宗旨,突破创新为方针,简单易用为原则。

CosyOS-实时运行模型

  • 中断层 【用户中断按中断优先级实时抢占、零中断延迟】
    • 用户中断
      -> 中断本地服务的执行
      -> 中断挂起服务的装载
  • 服务层 【内核服务】
    • SysTick [minpri]
      -> 软件RTC/定时器计数
      -> 恢复定时任务
      -> 调用定时钩子/滴答钩子(滴答服务的执行)
    • PendSV [minpri]
      -> 中断挂起服务的执行
      -> 任务调度/切换
    • 任务临界区 [关闭SysTick/PendSV]
      -> 任务服务的执行
  • 任务层 【不同优先级的任务抢占式调度,相同优先级的任务时间片轮转调度】
    • Taskmgr[maxpri]
    • Debugger[maxpri]
    • Starter[maxpri-1]
    • 一般用户任务[maxpri-1 ~ minpri+1:1]
    • 用户空闲任务[minpri:0]
    • 系统空闲任务[minpri:0]

零中断延迟基本原理

  • 服务层中,SysTick、PendSV、任务临界区,三者间是互斥访问的。换言之,整个服务层是一个大临界区(服务层临界区)。
  • 所有内核服务(中断本地服务除外),均在 “服务层临界区” 执行,从而保证服务的 “操作流” 不会被打断。
  • 中断本地服务采用互斥访问机制。

初体验

下面,让我们来初步体验一下CosyOS的易用性。

CosyOS一步创建任务示例:

任务名称 任务优先级 任务栈大小 安全运行时 私信
demo1_task 1级 128字节 0,无限长 0,无私信
demo2_task 2级 256字节 9个时间片 3个参数

注1:安全运行时是CosyOS的安全关键技术,可防止某任务长期独占或超时使用处理器。
注2:私信是CosyOS独创的一种任务间通信方式,可用来实现信号、事件、消息等功能。

# 创建demo1_task
uCreateTask(demo1_task, 1, 128, 0, 0)
{
    uSendTaskMsg(demo2_task) "hello", 999, 3.14); // 发送私信至demo2_task
    uDelay_ms(100); // 阻塞延时100ms
    uEndTasking; // 所有任务线程的最后一句代码
}
# 创建demo2_task
uCreateTask(demo2_task, 2, 256, 9, 3)(char *p, int a, float b)
{
    if(uRecvTaskMsg(500)){ // 接收私信,超时时间为500个滴答周期,返回真则接收成功
        /* 使用私信(读取p、a、b)*/
    }
    uEndTasking;
}
# 启动钩子
void start_hook(void)
{
    uStartTask(demo1_task, 0); // 启动demo1_task并置任务的初始状态为就绪状态
    uStartTask(demo2_task, 1); // 启动demo2_task并置任务的初始状态为挂起状态
}

您有没有眼前一亮呢?CosyOS创建一个任务竟如此简单,通过调用API“uCreateTask”,输入各项参数并直接写任务代码即可(已集成用于任务循环的while(1),用户可不必再写循环)。下一步就是在启动钩子中启动任务,任务便可参与调度并运行了。
CosyOS还开创性的把任务形参用做私信,私信参数(数量、名称、类型)可随意定义,与普通函数定义形参如出一辙。其它应用也都有着异曲同工之妙,即无论做什么事,都尽可能做到简化流程一步完成,最大程度的降低开发者的工作量,给开发者创造一个温馨舒适的开发环境。

突破创新

  • 实现了所有内核全局不关总中断(零中断延迟),保证了中断的实时响应
  • 独家技术实现系统服务的可重入,使51彻底摆脱可重入栈、全面提速
  • 针对51做了高度的性能优化,使51迸发出蓬勃生机、熠熠生辉
  • 251支持MSP、PSP两种栈模式,其中PSP模式可使任务的切换效率等同于Cortex-M
  • 定时服务(软件定时器中断),包括定时中断任务/钩子、定时查询任务/钩子,优先级都可由用户灵活配置
  • 软件RTC,支持设置时间和获取时间,可替代硬件RTC
  • 独创的飞信,极简类型、极速通信,是线程间通信的利器
  • 独创的私信,随意定义,灵活多变,便于多条消息的传递
  • 消息邮箱,每个邮箱在创建时,都可定义自己的数据类型,极大的丰富了邮件的形式,方便了线程间消息的传递
  • 消息队列,支持静态队列和动态队列,传输模式支持FIFO、LIFO,采用高效的指针引用方式
  • 事件标志组,声明标志组的同时定义标志位,不同标志组的标志位可以重名,对标志组和标志位的访问通过组名和位名来实现,极大的方便了标志组的应用
  • 全局变量访问,支持在任意任务和中断中对全局变量的安全访问,而不必担心重入的发生
  • 安全关键技术,有多项安全关键技术,如中断挂起服务空间隔离、安全运行时,可靠性高
  • 任务栈监控,拥有多项任务栈监控措施,可提前预判任务栈溢出的风险

因循守旧

  • 完全开源的免版税、确定性的RTOS
  • 任务调度支持抢占式调度、时间片轮转调度
  • 用户任务数量不限,且每个任务都可以有255级优先级(0~254)
  • 简洁高效的代码,极低的硬件资源占用,使CosyOS可轻松应用于各种小型MCU
  • 任务管理器,可实时监控各任务的运行,便于开发者急时发现设计中存在的潜在问题
    任务管理器
    —————————— CosyOS-任务管理器 ——————————

支持内核

CosyOS现支持8051、80251、Cortex-M等内核,未来会陆续添加对其它内核的支持。

编译环境

CosyOS是在keil C51、C251、MDK-Arm编译器下开发的,对其支持最好。
未来,将会陆续优化调整对其它编译器的支持。

文件说明

名称 描述
System CosyOS的内核文件
ur_api.h:用户API
sv_:系统服务文件
os_:其它内核文件
Config CosyOS的配置文件
syscfg.h:系统配置文件
mcucfg_:MCU配置文件
Hook CosyOS的系统钩子
CosyOS已经为用户创建好了六个系统钩子函数,
分别位于各自的同名文件中,用户直接写代码即可。

文档中心

CosyOS原理与应用

开发流程

API用户参考手册

参与贡献

  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request

CosyOS现征集试用者,可免费获得作者的一对一在线指导,您有什么疑问、意见或建议都可以提出来!

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

CosyOS是一款来自中国的开源实时操作系统,从经典的8051内核,到流行的Arm Cortex-M内核,均可实现全局不关总中断、零中断延迟,适用于对系统实时性及中断响应速度有较高要求的场合。QQ交流群:303421780. 展开 收起
C
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C
1
https://gitee.com/cosyos/cosyos.git
git@gitee.com:cosyos/cosyos.git
cosyos
cosyos
CosyOS
master

搜索帮助