ChibiOS简介2/5

2023-12-11 12:28
文章标签 简介 chibios

本文主要是介绍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】 ChibiOS官方文档

这篇关于ChibiOS简介2/5的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/480682

相关文章

ASIO网络调试助手之一:简介

多年前,写过几篇《Boost.Asio C++网络编程》的学习文章,一直没机会实践。最近项目中用到了Asio,于是抽空写了个网络调试助手。 开发环境: Win10 Qt5.12.6 + Asio(standalone) + spdlog 支持协议: UDP + TCP Client + TCP Server 独立的Asio(http://www.think-async.com)只包含了头文件,不依

业务协同平台--简介

一、使用场景         1.多个系统统一在业务协同平台定义协同策略,由业务协同平台代替人工完成一系列的单据录入         2.同时业务协同平台将执行任务推送给pda、pad等执行终端,通知各人员、设备进行作业执行         3.作业过程中,可设置完成时间预警、作业节点通知,时刻了解作业进程         4.做完再给你做过程分析,给出优化建议         就问你这一套下

容器编排平台Kubernetes简介

目录 什么是K8s 为什么需要K8s 什么是容器(Contianer) K8s能做什么? K8s的架构原理  控制平面(Control plane)         kube-apiserver         etcd         kube-scheduler         kube-controller-manager         cloud-controlle

【Tools】AutoML简介

摇来摇去摇碎点点的金黄 伸手牵来一片梦的霞光 南方的小巷推开多情的门窗 年轻和我们歌唱 摇来摇去摇着温柔的阳光 轻轻托起一件梦的衣裳 古老的都市每天都改变模样                      🎵 方芳《摇太阳》 AutoML(自动机器学习)是一种使用机器学习技术来自动化机器学习任务的方法。在大模型中的AutoML是指在大型数据集上使用自动化机器学习技术进行模型训练和优化。

SaaS、PaaS、IaaS简介

云计算、云服务、云平台……现在“云”已成了一个家喻户晓的概念,但PaaS, IaaS 和SaaS的区别估计还没有那么多的人分得清,下面就分别向大家普及一下它们的基本概念: SaaS 软件即服务 SaaS是Software-as-a-Service的简称,意思是软件即服务。随着互联网技术的发展和应用软件的成熟, 在21世纪开始兴起的一种完全创新的软件应用模式。 它是一种通过Internet提供

LIBSVM简介

LIBSVM简介 支持向量机所涉及到的数学知识对一般的化学研究者来说是比较难的,自己编程实现该算法难度就更大了。但是现在的网络资源非常发达,而且国际上的科学研究者把他们的研究成果已经放在网络上,免费提供给用于研究目的,这样方便大多数的研究者,不必要花费大量的时间理解SVM算法的深奥数学原理和计算机程序设计。目前有关SVM计算的相关软件有很多,如LIBSVM、mySVM、SVMLight等,这些

urllib与requests爬虫简介

urllib与requests爬虫简介 – 潘登同学的爬虫笔记 文章目录 urllib与requests爬虫简介 -- 潘登同学的爬虫笔记第一个爬虫程序 urllib的基本使用Request对象的使用urllib发送get请求实战-喜马拉雅网站 urllib发送post请求 动态页面获取数据请求 SSL证书验证伪装自己的爬虫-请求头 urllib的底层原理伪装自己的爬虫-设置代理爬虫coo

新一代车载(E/E)架构下的中央计算载体---HPC软件架构简介

老规矩,分享一段喜欢的文字,避免自己成为高知识低文化的工程师: 屏蔽力是信息过载时代一个人的特殊竞争力,任何消耗你的人和事,多看一眼都是你的不对。非必要不费力证明自己,无利益不试图说服别人,是精神上的节能减排。 无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事.而不是让内心的烦躁、焦虑、毁掉你本就不多的热情和定力。 时间不知不觉中,快要来到夏末秋初。一年又过去了一大半,成

AI学习指南深度学习篇-带动量的随机梯度下降法简介

AI学习指南深度学习篇 - 带动量的随机梯度下降法简介 引言 在深度学习的广阔领域中,优化算法扮演着至关重要的角色。它们不仅决定了模型训练的效率,还直接影响到模型的最终表现之一。随着神经网络模型的不断深化和复杂化,传统的优化算法在许多领域逐渐暴露出其不足之处。带动量的随机梯度下降法(Momentum SGD)应运而生,并被广泛应用于各类深度学习模型中。 在本篇文章中,我们将深入探讨带动量的随

OpenGL ES学习总结:基础知识简介

什么是OpenGL ES? OpenGL ES (为OpenGL for Embedded System的缩写) 为适用于嵌入式系统的一个免费二维和三维图形库。 为桌面版本OpenGL 的一个子集。 OpenGL ES管道(Pipeline) OpenGL ES 1.x 的工序是固定的,称为Fix-Function Pipeline,可以想象一个带有很多控制开关的机器,尽管加工