ChibiOS简介1/5

本文介绍了ChibiOS系统的设计原则,包括其优雅、快速、小巧且静态的特点。详细讲述了实时系统概念,如硬实时、软实时和非实时系统,以及ChibiOS中的任务管理、优先级、调度、中断处理和同步机制。

1. 源由

作为后续研读Ardupilot的ChibiOS的垫脚石,先了解下ChibiOS系统。


Ardupilot ChibiOS项目: https://github.com/ArduPilot/ChibiOS

Artery(AT32) porting项目: //Artery官网没有相关porting动作,不过开源github有相关项目。

2. ChibiOS基础知识1/5

2.1 Chapter 1 - Introduction

2.1.1 Priciple(设计原则)

  • Elegant
  • Fast
  • Small
  • Static

2.1.2 Fundamental requirements(基本需求)

  • Focus for code elegance and consistency, it must be a pleasure to work with the code.
  • Fully, unambiguously static.
  • Short code paths for all operations, it has to be really fast.
  • Compact.
  • Feature complete.
  • Strong abstraction.

2.2 Chapter 2 - Real Time Systems Concepts

2.2.1 System(系统)

A complex systems can always be decomposed in a set of elementary processes connected in a network, the system has a set of input and output signals, we can still consider them events and reactions but on a system level. A system can also have a global state, information that can optionally be accessed by the various processes in the system.

在这里插入图片描述

2.2.2 Classification(分类)

  • Non Real Time(非实时). A non real time system is a system where there are no deadlines involved. Non realtime systems could be described as follow:

“A non real time system is a system where the programmed reaction to an event will certainly happen sometime in the future”.

  • Soft Real Time(软实时). A Soft Real Time (SRT) system is a system where not meeting a deadline can have undesirable but not catastrophic effects, a performance degradation for example. Such systems could be described as follow:

“A soft real time system is a system where the programmed reaction to an event is almost always completed within a known finite time”.

  • Hard Real Time(硬实时). An Hard Real Time (HRT) system is a system where not meeting a deadline can have catastrophic effects. Hard realtime systems require a much more strict definition and could be described as follow:

“An hard real time system is a system where the programmed reaction to an event is guaranteed to be completed within a known finite time”.

2.2.3 Jitter(抖动)

Processes never react in a constant time, at a sufficiently small time scale any physical process is bound to have jitter. Unbounded or not assessed jitter is not compatible with an hard realtime system.

在这里插入图片描述

2.3 Chapter 3 - Embedded RTOSes

2.3.1 Priorities(优先级)

  • Static Priorities are usually assigned statically and cannot be changed at runtime.

  • Modifiable Priorities allow for priority to change at runtime in order to implement particular scheduling strategies.
    在这里插入图片描述

2.3.2 Scheduling(调度)

The scheduling rule is very simple: in any instant, the task being executed is the ready task with the highest priority level. This is true for both tasks and ISRs in the proposed model.

2.3.3 Interrupts(中断)

Interrupts trigger directly ISRs which in turn can wakeup tasks.

在这里插入图片描述在这里插入图片描述Note: If interrupts processing is an important requirement for your system then you should look for an RTOS/core combination able to efficiently handle nested interrupts on a dedicated interrupts stack.

2.3.4 Tasks and Threads(任务和线程)

Tasks are the fundamental entities in an RTOS environment. A task can be seen as a virtual CPU inside the system with its own registers bank and stack area. Tasks are scheduled by the RTOS based on their priority as described before. Some RTOSes, like ChibiOS for example, use the term threads for their tasks.

在这里插入图片描述

2.3.5 Task Types(任务类型)

  • Periodic Tasks, a periodic task is a task triggered periodically with a fixed time interval. The task is mostly waiting and becomes ready for execution when its internal timer triggers it. The task then performs a brief action and returns to the waiting state.

  • Non-periodic Tasks, this kind of tasks are triggered by an external event, for example an ISR, and are thus not periodic. After performing its programmed action the task returns to the waiting state.

  • Continuous Tasks, tasks should never take the CPU indefinitely, a task running an empty loop would not allow the execution of tasks at lower priority level. The rule is that tasks should wait for events, do their programmed action and then go back to waiting for events. If there are tasks that never release the CPU resource then those must be placed at lowest priority level in the system.

2.3.6 Synchronization(同步)

Usually tasks can use areas of memory as shared data, usually also called Shared Resources, the concurrent access to resources can lead to corruption of said data because the operations performed by tasks may be not atomic.

2.3.7 Atomic Operations(原子操作)

The safest approach is to consider everything not atomic. Failure to understand atomicity and implement proper mutual exclusion is the recipe for disaster, errors are usually random in nature and very hard to detect and debug. Ideally the problem must be resolved in the analysis and design phases by carefully defining the shared resources and defining correct protocols for concurrent access.

Most RTOSes have a specific API for handling of critical sections, the right approach is to use the RTOS-provided API and not make assumptions about how critical sections are or should be implemented. A good RTOS should take care about the best implementation on any given architecture.

2.3.8 Critical Sections(临界区域)

Critical Sections (or critical zones) are probably the most simple and common way to make a non-atomic sequence of code behave atomically.

3. 参考资料

【1】ArduPilot开源飞控系统之简单介绍
【2】Ardupilot开源飞控之ChibiOS简介
【3】 ChibiOS官方文档

ChibiOS 项目编译过程中,如果出现类似 `no rule to make target chcore.c` 的错误提示,通常表示 Makefile 无法找到构建该源文件的合适规则。这种情况可能由多种原因导致: 1. **文件路径配置错误** ChibiOS 的 Makefile 系统依赖于特定的目录结构和变量定义。如果 `chcore.c` 文件所在的目录未被正确包含在 Makefile 的 `VPATH` 或 `vpath` 指令中,则编译系统无法找到该文件。确保 Makefile 中已正确设置 `CHIBIOS`、`PORT_DIR` 和 `MCU_DIR` 等变量,并且指向正确的目录结构[^1]。 2. **源文件未正确添加到构建系统** 在 ChibiOS 中,`chcore.c` 是与特定架构相关的内核核心文件,通常位于 `os/ports/ARMCMx` 或类似路径下。若该文件未被加入到 `Makefile` 或 `rules.mk` 的源文件列表(如 `CSRC`)中,则构建系统不会为其生成编译规则。请检查 `Makefile` 中的 `CSRC` 变量是否包含 `$(CHIBIOS)/os/ports/ARMCMx/chcore.c`[^1]。 3. **编译器规则缺失或配置错误** ChibiOS 使用通用规则来编译 `.c` 文件为 `.o` 文件。如果这些规则未正确定义或被意外覆盖,可能导致系统无法生成特定目标文件。检查 `rules.mk` 或 `common.mk` 中是否包含以下类似规则: ```makefile $(OBJDIR)/%.o: %.c $(CC) $(CFLAGS) -c $< -o $@ ``` 确保该规则适用于 `chcore.c` 所在的目录结构和编译器配置[^1]。 4. **文件缺失或路径错误** 若 `chcore.c` 文件本身缺失或路径配置错误,也可能导致此错误。请确认 `chcore.c` 是否确实存在于预期路径中,并且文件名拼写正确。例如,在 ARM Cortex-M 系列端口下,该文件通常位于 `os/ports/ARMCMx/chcore.c`[^1]。 5. **构建环境配置问题** 如果构建环境缺少必要的依赖库或头文件路径配置不正确,也可能导致构建失败。例如,某些系统级头文件(如 `sys/types.h`)缺失会导致编译器无法正常工作[^3]。确保系统中已安装必要的开发库和头文件。 --- ### 示例:ChibiOS Makefile 片段 以下是一个典型的 ChibiOS Makefile 片段,用于定义 ARMCMx 架构下的源文件和规则: ```makefile # ChibiOS 根目录 CHIBIOS = ../ChibiOS_21.11.0 # 架构和MCU配置 PORT_DIR = $(CHIBIOS)/os/ports/ARMCMx MCU_DIR = $(CHIBIOS)/os/ports/ARMCMx/STM32 # 源文件 CSRC = main.c \ $(CHIBIOS)/os/kernel/src/chsys.c \ $(CHIBIOS)/os/kernel/src/chdebug.c \ $(CHIBIOS)/os/kernel/src/chtrace.c \ $(CHIBIOS)/os/ports/ARMCMx/chcore.c \ $(MCU_DIR)/chcore_stm32.c # 编译规则 $(OBJDIR)/%.o: %.c $(CC) $(CFLAGS) -c $< -o $@ ``` --- ### 解决步骤建议: - 确认 `chcore.c` 文件存在,并且路径在 Makefile 中正确引用。 - 检查 Makefile 中的 `CSRC` 列表是否包含该文件。 - 确保编译规则适用于该文件路径。 - 验证构建环境是否具备所有必要的头文件和依赖库。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值