ChibiOS简介2/5

ChibiOS简介2/5

  • 1. 源由
  • 2. ChibiOS基础知识2/5
    • 2.4 Chapter 4 - ChibiOS General Architecture
      • 2.4.1 The Big Picture(总体框图)
      • 2.4.2 Embedded Components(嵌入式组件)
      • 2.4.3 Application Model(应用模型)
      • 2.4.4 Code(代码)
        • 2.4.4.1 Application(应用代码)
        • 2.4.4.2 Startup Code(启动代码)
        • 2.4.4.3 ChibiOS/RT
        • 2.4.4.4 ChibiOS/HAL
    • 2.5 Chapter 5 - Introduction to the RT Kernel
      • 2.5.1 Designed Concepts(设计概念)
      • 2.5.2 Coding Conventions(编码约定)
        • 2.5.2.1 Code Style
        • 2.5.2.2 Naming Conventions
      • 2.5.3 Architecture
      • 2.5.4 System States
      • 2.5.5 API Classes
      • 2.5.6 Thread Working Areas
      • 2.5.7 Thread States
    • 2.6 Chapter 6 - RT System Layer
  • 3. 参考资料

1. 源由

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


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

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

  • https://github.com/dron0gus/artery
  • https://github.com/dron0gus/ChibiOS

2. ChibiOS基础知识2/5

2.4 Chapter 4 - ChibiOS General Architecture

2.4.1 The Big Picture(总体框图)

在这里插入图片描述

2.4.2 Embedded Components(嵌入式组件)

  • RT, the RTOS scheduler. RT is a very high performance RTOS with a complete set of features and small footprint. It is what we cover in this book.
  • NIL, an alternate RTOS. NIL is compatible with RT but its internal architecture is completely different, It is designed for minimal code size.
  • OSLIB, an RTOS extension library. It sits on top of RT or NIL and adds an incredible set of higher level services.
  • HAL, the Hardware Abstraction Layer enclosing abstract drivers for most common peripherals.
  • SB, an extension for RT or NIL offering isolated sandboxes where to run “unsafe” code. The code in the sandbox is unable to crash the whole system.

2.4.3 Application Model(应用模型)

Single Application with Multiple Threads. This means:

  1. The runtime environment is trusted, the application does not need to defend from itself. Non-trusted code can be handled using the SB subsystem.
  2. Multiple threads are part of the application and share the address space. There is no protection between thread and thread and no virtualization.
  3. Application and Operating System are linked together into a single memory image, a single program.
  4. There is no concept of “loading an application”.

2.4.4 Code(代码)

2.4.4.1 Application(应用代码)

It is the user code, ChibiOS provides a simple template of main() function, everything else starts from there.

2.4.4.2 Startup Code(启动代码)

In ChibiOS the startup code is provided with the OS and is located under ./os/common/startup for the various supported architectures and compilers, scatter files and everything else is required for system startup are also provided.

  1. Core initialization.
  2. Stacks initialization.
  3. C Runtime initialization.
  4. Calling the main() function.
2.4.4.3 ChibiOS/RT

The RT scheduler kernel which is divided in two internal layers:

  • RT Portable Kernel. It is the part of the RTOS kernel which is architecture and compiler independent. The RT code is located under ./os/rt.
  • RT Port Layer. It is the part of the RTOS kernel specific for one architecture and one or more compilers. The RT port code is located under ./os/common/ports.
2.4.4.4 ChibiOS/HAL

HAL is the acronym for Hardware Abstraction Layer, a set of device drivers for the peripherals most commonly found in micro-controllers. The HAL is split in several layers:

  • HAL API Layer. This layer contains a series of portable device drivers. The HAL portable code is located under ./os/hal.
  • HAL Port Layer. This is the device driver implementations for a specific micro-controller or family of micro-controllers. The HAL port code is located under ./os/hal/ports.
  • HAL Board Layer. This module contains all details of a specific board mounting the micro-controller. Board level initialization is performed in this module. The HAL boards code is located under ./os/hal/boards.
  • HAL OSAL Layer. This is the Operating System Abstraction Layer. The HAL has to use some RTOS services in order to implement its functionality. The access to the RTOS services is done through this abstraction layer in order to not lock the HAL to a specific RTOS. The HAL OSAL code is located under ./os/hal/osal.

2.5 Chapter 5 - Introduction to the RT Kernel

2.5.1 Designed Concepts(设计概念)

  1. 【fast】It must be fast, execution efficiency is the main requirement.
  2. 【size】The code must be optimized for size unless this conflicts with point 1.
  3. 【RTOS】The kernel must offer a complete set of RTOS features unless this conflicts with requirement 1.
  4. 【safe】It must be intrinsically safe. Primitives with dangerous corner cases are simply not allowed. The rule is to guide the user to choose a safe approach if possible.
  5. 【robust】The code base must be elegant, consistent, readable and rules-driven.
  6. 【handy】This may be subjective but working with the code must be a pleasant experience.

2.5.2 Coding Conventions(编码约定)

这是一个好习惯,是一种研发工程师的素质体现。

2.5.2.1 Code Style

The K&R style (Kernighan & Ritchie Style), this is a small subset:

  • Tabs are forbidden.
  • Non UTF-8 characters are forbidden.
  • C++ style comments are forbidden.
  • Indentation is 2 spaces.
  • Multiple empty lines are forbidden.
  • Insertion of empty lines is regulated.
  • The code is written in “code blocks”, blocks are composed by:

An empty line.
A comment describing the block. The comment can be on a single or multiple lines.
One or more code lines.
Comments on the same line of statements are allowed but not encouraged.

  • Files are all derived from templates.
  • No spaces at the end of lines.
2.5.2.2 Naming Conventions

API Functions
The name of a function meant to be an API is always composed as follow:

ch<subsystem><verb>[<extra>][Timeout][<I|S|X>]() 

Where:

  • ch. Identifies an ChibiOS/RT API.
  • <subsystem> Identifies the subsystem of the kernel where this function belongs. This part also identifies the object type on which the function operates. For example “Sem” indicates that the function operates on a semaphore_t object which is passed by pointer as first parameter.
  • <verb> The action performed by this function.
  • <extra> The extra part of the name or other context information.
  • [Timeout]. If the function is able to stop the execution of the invoking thread and has a time-out capability.
  • <I|S|X>. Optional function class attributes. This attribute, if present, strictly defines the system state compatible with the API function. The “API Classes” section will describe the relationship between function classes and the system state.

Variables, Fields and Structures
Names must be fully written in lower case, underscore is used as separator.

Types
Simple or structured type follow the same convention, the symbol must be written all in lower case, underscore is used as separator and an “_t” is added at the end.

examples:
thread_t, semaphore_t.

Macros
Macros are written fully in upper case. A “CH_” prefix is encouraged but not enforced. A common prefix for grouped macros is mandatory.

examples:
CH_IRQ_EPILOGUE(), THD_FUNCTION().

2.5.3 Architecture

All kernel services are build around the central scheduler module. The scheduler exports a low level API that allows to build virtually any kind of synchronization primitive, other modules are built using the scheduler services and have no interactions.
在这里插入图片描述

2.5.4 System States

One important concept in ChibiOS/RT are the so called System States, the global behavior of the system is regulated by an high level state machine:
在这里插入图片描述

The states have a strong meaning and must be understood in order to utilize the RTOS correctly:

  • Init. This state represents the execution of code before the RTOS is initialized using chSysInit(). The only kind of OS functions that can be called in the “Init” state are object initializers.
  • Thread. This state represents the RTOS executing one of its threads. Normal APIs can be called in this state.
  • Suspended. In this state all the OS-IRQs are disabled but Fast-IRQs are still served.
  • Disabled. In this state all interrupt sources are disabled.
  • S-Locked. This is the state of critical sections in thread context.
  • I-Locked. This is the state of critical sections in ISR context.
  • IRQ WAIT. When the system has no threads ready for execution it enters a state where it just waits for interrupts. This state can be mapped on a low power state of the host architecture.
  • ISR. This state represents the execution of ISR code.

There are some additional states not directly related to the RTOS activity but still important from the system point of view:

在这里插入图片描述

  • Fast ISR. This state represents the execution of ISR code of a fast IRQ source.
  • NMI. This state represents the execution of ISR code of a non-maskable interrupt source.

2.5.5 API Classes

  • Normal Functions, Normal functions have no suffix and can only be invoked from the “Thread” state unless the documentation of the function states further restrictions or defines a special context.
  • S-Class Functions, Functions with suffix “S” can only be invoked from the “S-Locked” state, this means that this class of functions are meant to be called in a thread-level critical section. This class of functions can reschedule internally if required.
  • I-Class Functions, Functions with suffix “I” can be called either in the “I-Locked” state and in the “S-Locked” state. Both ISR-level and thread-level critical sections are compatible with this class. Note that this class of functions never reschedule internally, if called from “S-Locked” state an explicit reschedule must be performed.
  • X-Class Functions, This class of functions has no special requirements and can be called from any context where API functions can be called: “Thread”, “S-Locked” and “I-Locked”.
  • Special Functions, Special functions have no specific suffix but have special execution requirements specified in their documentation.
  • Object Initializers, This kind of functions are meant for objects initialization and can be used in any context, even before the kernel is initialized. Initialized objects themselves are “passive” until referred by some other function. Note that most kernel objects have also static initializers, macros that allocate objects and initialize them using a static variable initialization.

2.5.6 Thread Working Areas

In ChibiOS/RT threads occupy a single, contiguous region of memory called Thread Working Area. Working areas can be statically or dynamically allocated and are always aligned using the same alignment required for stack pointers.

在这里插入图片描述

2.5.7 Thread States

During their life cycle threads go through several states, the state machine is regulated by the API and events in the kernel:
在这里插入图片描述Note that in ChibiOS/RT there are multiple sleeping states that are indicated on the diagram as a single state. Each synchronization object has its own sleeping states, this is done in order to understand on which kind of object the thread is sleeping on.

2.6 Chapter 6 - RT System Layer

The System Layer is the most fundamental part of the RT kernel, it lies just above the port layers and provides a series of important services:

  • Initialization.
  • Abnormal Termination.
  • Interrupts Handling.
  • Critical Sections.
  • Power Management.
  • Realtime Counter.

This service handles the system initialization: chSysInit() //Starts the RT kernel. This function must be called once from the main() function.

3. 参考资料

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

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

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

相关文章

Vue之数据绑定

在我们Vue当中有两种数据绑定的方法 1.单向绑定 2.双向绑定 让我为大家介绍一下吧&#xff01; 1、单向绑定(v-bind) 数据只能从data流向页面 举个例子&#xff1a; <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"…

【Kubernetes】持久化存储emptyDir/hostPath/nfs/PVC

k8s持久化存储 一、为什么做持久化存储&#xff1f;二、k8s持久化存储&#xff1a;emptyDir三、k8s持久化存储&#xff1a;hostPath四、k8s持久化存储&#xff1a;nfs4.1、搭建nfs服务4.2、挂载nfs共享目录 五、k8s持久化存储&#xff1a; PVC5.1、什么是PV5.2、什么是PVC5.3、…

使用shell脚本将一台虚拟机上面数据分发到其他虚拟机上面

目录 1&#xff0c;功能2&#xff0c;注意点3&#xff0c;shell脚本介绍4&#xff0c;bash内容 1&#xff0c;功能 使用shell脚本将一台虚拟机上面数据分发到其他虚拟机上面。 2&#xff0c;注意点 需要修改的地方&#xff1a;hadoop250 hadoop251 hadoop252 hadoop253 hado…

普冉(PUYA)单片机开发笔记(4): 配置通用定时器

概述 在前几篇开发笔记中&#xff0c;从 PY32F003 的一个厂家标准例程开始&#xff0c;实现了中断式无阻塞串口收发、对开发板 LED3 的亮/灭控制&#xff0c;时钟系统的初始化和时钟选择。在此基础上&#xff0c;今天做一下定时器的应用实验。事先考虑以下几个问题&#xff1a…

使用Git进行版本控制

参考&#xff1a;《Python编程从入门到实践》 前言1、安装、配置 Git1.1 在Linux系统中安装Git1.2 在OS X系统中安装Git1.3 在Windows系统中安装Git1.4 配置Git 2、创建项目3、忽略文件4、初始化仓库5、检查状态6、将文件加入到仓库中7、执行提交8、查看提交历史 前言 版本控制…

回顾【数学基础】找出断层,继续前进, 使用chatGPT学习并解决实际问题:微积分

已经学过的算术、代数、几何。跳过。 从微积分开始 想象一下&#xff0c;你在画一条曲线&#xff0c;或者在一个大草地上奔跑。微积分就是一种数学工具&#xff0c;帮助我们了解这条曲线的形状&#xff0c;或者你奔跑的方式。 微分&#xff08;就像研究曲线上的每一小点&…

基于SSM超市订单管理系统(Java毕业设计)

大家好&#xff0c;我是DeBug&#xff0c;很高兴你能来阅读&#xff01;作为一名热爱编程的程序员&#xff0c;我希望通过这些教学笔记与大家分享我的编程经验和知识。在这里&#xff0c;我将会结合实际项目经验&#xff0c;分享编程技巧、最佳实践以及解决问题的方法。无论你是…

16ASM 数据传送指令 算数运算指令

目录 指令种类 数据传送指令 通用传送指令 堆栈操作指令 标志寄存器进出堆栈指令 地址传送指令 算术运算指令 加法减法指令 乘法除法指令 指令种类 数据传送类指令 通用数据传送指令&#xff1a;MOV &#xff0c;XCHG&#xff0c;XLAT堆栈传送指令&#xff1a;PUSH&a…

嵌入式开发按怎样的路线学习较好?

嵌入式开发按怎样的路线学习较好&#xff1f; 在开始前我有一些资料&#xff0c;是我根据自己从业十年经验&#xff0c;熬夜搞了几个通宵&#xff0c;精心整理了一份「嵌入式从专业入门到高级教程工具包」&#xff0c;点个关注&#xff0c;全部无偿共享给大家&#xff01;&…

甄知燕千云与汉得智能制造深度集成,革新智能化提单服务

当今&#xff0c;以数字技术为代表的新一轮科技革命和产业变革加速推进&#xff0c;全球正迈向数字化新时代。在数字化转型浪潮下&#xff0c;企业必须主动顺应时代潮流&#xff0c;抓住机遇&#xff0c;迎接挑战。在数字技术和解决方案的驱动下&#xff0c;推动企业提升效率、…

超级实用的防止商品超卖的 7 种实现方式,非常好用!

高并发场景在现场的日常工作中很常见&#xff0c;特别是在互联网公司中&#xff0c;这篇文章就来通过秒杀商品来模拟高并发的场景。 本文环境&#xff1a; SpringBoot 2.5.7 MySQL 8.0 X MybatisPlus Swagger2.9.2 模拟工具&#xff1a; Jmeter 模拟场景&#xff1a; 减库…

【华为鸿蒙系统学习】- HarmonyOS4.0开发|自学篇

​ &#x1f308;个人主页: Aileen_0v0 &#x1f525;热门专栏: 华为鸿蒙系统学习|计算机网络|数据结构与算法 &#x1f4ab;个人格言:"没有罗马,那就自己创造罗马~" 目录 HarmonyOS 4.0 技术介绍&#xff1a; HarmonyOS三大特征&#xff1a; 1.实现硬件互助&#…