# CMSIS-RTOS

**CMSIS-RTOS** 是 Arm 为 Cortex-M 微控制器发布的标准化实时操作系统应用编程接口，其定义是一个通用 API 层，用于对接已有的 RTOS 内核，而非内核本身。<sup>[1](https://arm-software.github.io/CMSIS_5/develop/RTOS/html/group__CMSIS__RTOS.html)</sup> 它有两个版本：最初的 CMSIS-RTOS API 版本 1，在头文件 cmsis_os.h 中声明；以及扩展后的 CMSIS-RTOS2（API v2），在 cmsis_os2.h 中声明。<sup>[2](https://arm-software.github.io/CMSIS_5/latest/RTOS/html/index.html)</sup><sup> • </sup><sup>[3](https://arm-software.github.io/CMSIS_5/RTOS2/html/index.html)</sup> 针对该 API 编写的程序使用标准 C/C++ 构造，可用 ARMCC、GCC 或 IAR 编译器编译。<sup>[2](https://arm-software.github.io/CMSIS_5/latest/RTOS/html/index.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 它是什么 | 一个位于已有 RTOS 内核之上的通用 RTOS API 层，而非内核；合规性通过设计实现，或通过在已有 RTOS 之上加一层适配层实现<sup>[1](https://arm-software.github.io/CMSIS_5/develop/RTOS/html/group__CMSIS__RTOS.html)</sup><sup> • </sup><sup>[4](https://sbesc.lisha.ufsc.br/sbesc2014/dl214)</sup> |
| 起源 | CMSIS v1.0 由 Arm 于 2008 年定义；2012 年发布的 CMSIS v3.0 加入了 CMSIS-RTOS；CMSIS v4 于 2014 年 2 月 28 日跟进<sup>[4](https://sbesc.lisha.ufsc.br/sbesc2014/dl214)</sup> |
| 两个 API 版本 | 版本 1 在 cmsis_os.h 中；版本 2 在 cmsis_os2.h 中，并带有一个翻译层，允许二者在同一应用中混用<sup>[2](https://arm-software.github.io/CMSIS_5/latest/RTOS/html/index.html)</sup><sup> • </sup><sup>[3](https://arm-software.github.io/CMSIS_5/RTOS2/html/index.html)</sup> |
| 参考实现 | Keil RTX 版本 5（RTX5），一个面向 Cortex-M 和 Cortex-A 设备的内核，以 CMSIS-RTOS2 作为其原生接口实现，同时也提供 v1 API<sup>[5](https://documentation-service.arm.com/static/679b91d53f2a9a07789ee7b3?token=)</sup><sup> • </sup><sup>[6](https://arm-software.github.io/CMSIS_5/RTOS2/html/os2MigrationGuide.html)</sup> |
| 其他实现 | CMSIS-FreeRTOS 将 FreeRTOS-Kernel 11.2.0 适配到 CMSIS-RTOS2；Silicon Labs 随附专有内核并带有 CMSIS-RTOS2 层<sup>[7](https://github.com/arm-software/cmsis-freertos)</sup><sup> • </sup><sup>[8](https://www.silabs.com/software-and-tools/rtos)</sup> |
| 实测开销 | 2014 年一项基于瑞尔斯通的对比未发现性能损失：在 72 MHz 的 Cortex-M3 上，RTX 实现得分为 172.3 瑞尔斯通/秒，商用内核为 176.8，自由开源内核为 88.3<sup>[4](https://sbesc.lisha.ufsc.br/sbesc2014/dl214)</sup> |
| 在 CMSIS 6 中的状态 | CMSIS-RTOS（v1）已弃用并在 CMSIS 6.0.0 中移除，RTX5 移入单独的 CMSIS-RTX 包<sup>[9](https://newreleases.io/project/github/ARM-software/CMSIS_6/release/v6.0.0)</sup> |

## 目的与设计

CMSIS-RTOS 由 Arm 定义，旨在提高微控制器应用之间的可移植性。其公开目标是：促进基于标准化 RTOS API 构建中间件，降低并发应用开发者的学习曲线，并提高并发嵌入式软件的可移植性。<sup>[4](https://sbesc.lisha.ufsc.br/sbesc2014/dl214)</sup> 该标准面向 Arm Cortex-M 系列 32 位 RISC 微控制器——这一类系统没有内存管理单元，实现的是多线程并发模型；这一范围与 POSIX 标准适用的范围不同。<sup>[4](https://sbesc.lisha.ufsc.br/sbesc2014/dl214)</sup>

由于该 API 是位于已有内核之上的一层，RTOS 可以通过原生实现该 API 来合规，也可以通过适配层来合规。CMSIS-RTOS2 文档指出，当对象使用动态内存分配时，源代码或库在迁移到另一个 CMSIS-RTOS2 实现时无需修改，这就是实践中的可移植性机制。<sup>[10](https://arm-software.github.io/CMSIS_5/5.9.0/RTOS2/html/group__CMSIS__RTOS.html)</sup>

## API 版本 1 的功能

版本 1 API 将服务分为内核信息与控制、线程管理、通用等待函数、定时器管理，以及线程间通信与资源共享。<sup>[1](https://arm-software.github.io/CMSIS_5/develop/RTOS/html/group__CMSIS__RTOS.html)</sup> 线程在抢占式调度器下以准并行方式运行，API 定义了线程状态 RUNNING、READY、BLOCKED、TERMINATED 和 INACTIVE。<sup>[11](https://arm-software.github.io/CMSIS_6/main/RTOS2/group__CMSIS__RTOS__ThreadMgmt.html)</sup>

通信与同步原语有各自的规则：<sup>[4](https://sbesc.lisha.ufsc.br/sbesc2014/dl214)</sup>

- **互斥量**：用于线程间的互斥，因此不能由中断服务程序（ISR）使用。锁定它的线程拥有所有权，其他线程不得释放它；实现可以包含优先级继承，即所有者继承在互斥量上阻塞的线程中的最高优先级。
- **信号量**：创建时赋予初始值 1 或更大，可由 ISR 释放，没有所有权或优先级继承的概念。当计数为 0 时，从 ISR 发起的等待会立即返回错误码。
- **消息队列**：存储整数或指针的副本，大小在创建时固定；线程在队列满或空时以可选超时阻塞，而 ISR 则收到错误码而非阻塞。
- **邮件队列**：存放任意大小的消息，消息存储在内存池中，队列只保存指向池块的指针。
- **内存池**：由 RTOS 管理的一组固定大小块；分配从不阻塞，无可用块时返回错误码。
- **信号**：由其他线程或 ISR 置位或复位的二进制标志；一个线程最多可拥有 31 个标志，并可挂起自身等待某个特定标志或一组标志。

定时服务包括 osDelay（将线程挂起若干毫秒），以及创建为单次或周期性并带回调函数的软件定时器。<sup>[4](https://sbesc.lisha.ufsc.br/sbesc2014/dl214)</sup>

## CMSIS-RTOS2

CMSIS-RTOS2 为基于 Arm Cortex 处理器的设备提供通用 RTOS 接口，并定义了一个实现可以扩展的最小功能集。它解决了 v1 未覆盖的需求：动态对象创建不再需要静态内存（静态缓冲区变为可选），支持具有安全与非安全执行状态的 Armv8-M 架构，为多核系统中的消息传递做出安排，完整支持 C++ 运行时环境，以及提供在 ABI 兼容编译器之间二进制兼容的 C 接口。<sup>[3](https://arm-software.github.io/CMSIS_5/RTOS2/html/index.html)</sup>

在源码层面可以看到若干变化。函数 osXxxxNew 取代了 v1 中用于创建和销毁对象的 osXxxxCreate 函数；C 函数 main 不再作为线程启动（这在 v1 中是可选的）；返回 osEvent 的函数已被替换。<sup>[3](https://arm-software.github.io/CMSIS_5/RTOS2/html/index.html)</sup> 一个翻译层允许 v1 和 v2 调用在同一应用内混用，从而实现渐进迁移。<sup>[3](https://arm-software.github.io/CMSIS_5/RTOS2/html/index.html)</sup><sup> • </sup><sup>[6](https://arm-software.github.io/CMSIS_5/RTOS2/html/os2MigrationGuide.html)</sup>

v2 中的线程优先级是从 osPriorityIdle（1）到 osPriorityISR（56）的数值，按命名组（Low、BelowNormal、Normal、AboveNormal、High、Realtime）组织，每组有八个子级别。<sup>[11](https://arm-software.github.io/CMSIS_6/main/RTOS2/group__CMSIS__RTOS__ThreadMgmt.html)</sup> 线程可以以可加入或分离模式创建，也可以以特权或非特权处理器模式创建，且线程管理函数不能从 ISR 调用。<sup>[11](https://arm-software.github.io/CMSIS_6/main/RTOS2/group__CMSIS__RTOS__ThreadMgmt.html)</sup>

## 实现

参考实现是 CMSIS-RTOS RTX。Keil RTX5 是一个面向 Arm Cortex-M 和 Cortex-A 设备的实时内核，以 CMSIS-RTOS2 API 作为其原生接口实现，并提供 v1 和 v2 两层 API，使应用可以在二者之间逐步过渡。<sup>[5](https://documentation-service.arm.com/static/679b91d53f2a9a07789ee7b3?token=)</sup><sup> • </sup><sup>[6](https://arm-software.github.io/CMSIS_5/RTOS2/html/os2MigrationGuide.html)</sup> RTX5 支持轮转线程切换，即相同优先级的线程以通常几毫秒长的时间片共享 CPU 时间。<sup>[12](https://github.com/ARM-software/CMSIS_5/blob/develop/CMSIS/DoxyGen/RTOS2/src/cmsis_os2.txt)</sup>

Arm 还发布了 CMSIS-FreeRTOS，这是将 FreeRTOS-Kernel 版本 11.2.0 适配到 CMSIS-RTOS2 的软件包；FreeRTOS 内核文件采用 MIT 许可，仓库其余部分为 Apache 2.0。<sup>[7](https://github.com/arm-software/cmsis-freertos)</sup> 其示例项目既涵盖普通 Cortex-M 目标，也涵盖使用 TrustZone 安全/非安全执行的应用。<sup>[13](https://arm-software.github.io/CMSIS-FreeRTOS/v11.2.0/page_example_projects.html)</sup> [Silicon Labs](https://www.edgepedia.org/zh/silicon-labs) 在 Simplicity Studio 中随附其专有内核并带有 CMSIS-RTOS2 层。<sup>[8](https://www.silabs.com/software-and-tools/rtos)</sup>

## 性能

首个公开发表的定量评估在 SBESC 2014 上展示，并于 2016 年在《国际嵌入式系统杂志》上扩展发表，其问题是：符合该标准是否会带来性能损失。巴拉那联邦技术大学的 道格拉斯·P. B. 勒诺（Douglas P. B. Renaux）在一款具有 32 KB 闪存、8 KB RAM 和 72 MHz 时钟的 Cortex-M3 微控制器上，使用 IAR EWARM v7.2 编译，将 CMSIS-RTOS RTX v4.7 实现与商用 X Real-Time Kernel v2.1 及一个自由开源内核进行基准测试，采用源自瑞尔斯通的基准，测量任务切换、信号量传递、消息传输、内存分配、从 ISR 激活任务以及中断延迟。<sup>[4](https://sbesc.lisha.ufsc.br/sbesc2014/dl214)</sup><sup> • </sup><sup>[14](https://www.inderscience.com/info/e_inarticle.php?artid=80389)</sup>

RTX 实现得分为 172.3 瑞尔斯通/秒，商用内核为 176.8，自由开源内核为 88.3；任一单项测量中的最大差异为 3.45:1，三个内核的中断延迟均测得 0.32 微秒，因为优先级高于内核的中断从不被禁用。结论是，所评估的 CMSIS-RTOS 实现与其他两类 RTOS 相比没有性能损失。<sup>[4](https://sbesc.lisha.ufsc.br/sbesc2014/dl214)</sup>

## 在 CMSIS 6 中弃用

CMSIS 6.0.0 发行说明将 CMSIS-RTOS 列为已弃用并移除，RTX5 移入单独的 CMSIS-RTX 包；基础 ARM::CMSIS 6.0.0 包不再包含主版本 5 所附带的完整软件组件集。<sup>[9](https://newreleases.io/project/github/ARM-software/CMSIS_6/release/v6.0.0)</sup> CMSIS-RTOS2 API 本身在 CMSIS 6 中延续，其中线程管理、互斥量管理及其他函数组仍为 Cortex-M 和 Cortex-A 设备保留文档。<sup>[11](https://arm-software.github.io/CMSIS_6/main/RTOS2/group__CMSIS__RTOS__ThreadMgmt.html)</sup>

## References

1. [CMSIS-RTOS API, CMSIS 5 documentation, Arm Ltd.](https://arm-software.github.io/CMSIS_5/develop/RTOS/html/group__CMSIS__RTOS.html)
2. [CMSIS-RTOS Main Page (Version 1.03), CMSIS 5 documentation, Arm Ltd.](https://arm-software.github.io/CMSIS_5/latest/RTOS/html/index.html)
3. [CMSIS-RTOS2 Main Page (Version 2.1.3), CMSIS 5 documentation, Arm Ltd.](https://arm-software.github.io/CMSIS_5/RTOS2/html/index.html)
4. [Douglas P. B. Renaux et al. (2014). Comparative Performance Evaluation of CMSIS-RTOS. SBESC 2014.](https://sbesc.lisha.ufsc.br/sbesc2014/dl214)
5. [Arm Keil MDK Getting Started Guide, Arm Ltd.](https://documentation-service.arm.com/static/679b91d53f2a9a07789ee7b3?token=)
6. [RTX Migration Guide, CMSIS 5 documentation, Arm Ltd.](https://arm-software.github.io/CMSIS_5/RTOS2/html/os2MigrationGuide.html)
7. [ARM-software/CMSIS-FreeRTOS: FreeRTOS adaptation for CMSIS-RTOS Version 2, GitHub](https://github.com/arm-software/cmsis-freertos)
8. [Real-Time Operating Systems (RTOS), Silicon Labs](https://www.silabs.com/software-and-tools/rtos)
9. [ARM-software/CMSIS_6 v6.0.0 release notes, GitHub](https://newreleases.io/project/github/ARM-software/CMSIS_6/release/v6.0.0)
10. [CMSIS-RTOS API v2, CMSIS 5.9.0 documentation, Arm Ltd.](https://arm-software.github.io/CMSIS_5/5.9.0/RTOS2/html/group__CMSIS__RTOS.html)
11. [CMSIS-RTOS2: Thread Management, CMSIS 6 documentation, Arm Ltd.](https://arm-software.github.io/CMSIS_6/main/RTOS2/group__CMSIS__RTOS__ThreadMgmt.html)
12. [CMSIS_5 RTOS2 source documentation (cmsis_os2.txt), GitHub](https://github.com/ARM-software/CMSIS_5/blob/develop/CMSIS/DoxyGen/RTOS2/src/cmsis_os2.txt)
13. [CMSIS-FreeRTOS: Example Projects, Arm Ltd.](https://arm-software.github.io/CMSIS-FreeRTOS/v11.2.0/page_example_projects.html)
14. [Performance evaluation of CMSIS-RTOS: benchmarks and comparison, International Journal of Embedded Systems Vol. 8 No. 5/6 (2016)](https://www.inderscience.com/info/e_inarticle.php?artid=80389)

---
*Initially written Oct 15, 2026 · Edited: Oct 25, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 计算机硬件 › Embedded & soft processors › Embedded systems › Embedded operating systems and software platforms

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/cmsis-rtos

English original: https://www.edgepedia.org/cmsis-rtos
