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官方文檔

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/213261.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/213261.shtml
英文地址,請注明出處:http://en.pswp.cn/news/213261.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

爬蟲解析——Xpath的安裝及使用(五)

目錄 一、Xpath插件的安裝 二、安裝 lxml 三、Xpath解析文件 1.解析本地文件 &#xff08;1&#xff09;導入本地文件 &#xff08;2&#xff09;解析本地文件 2.服務器文件解析 &#xff08;1&#xff09;獲取網頁源碼 &#xff08;2&#xff09;解析服務器響應文件 …

力扣373. 查找和最小的 K 對數字

優先隊列 思路&#xff1a; 使用下標 (x, y) 標識數值對&#xff0c;x 為第一個數組的下標&#xff0c;y 為第二個數組的下標&#xff1b;所以 k 個數值對 x 的范圍屬于 [0, min(k, m)]&#xff0c;m 為第一個數組的 size&#xff1b;數值對 (x, y) &#xff0c;那么下一個比其…

TailwindCSS 如何處理RTL布局模式

背景 TikTok作為目前全世界最受歡迎的APP&#xff0c;需要考慮兼容全世界各個地區的本地化語言和閱讀習慣。其中對于阿拉伯語、波斯語等語言的閱讀書寫習慣是從右向左的&#xff0c;在前端有一個專有名字RTL模式&#xff0c;即Right-to-Left。 其中以阿拉伯語作為第一語言的人…

C# 獲取windows 系統開關機時間

關機時間&#xff0c;引用&#xff1a;https://www.coder.work/article/1589448 public static DateTime GetLastSystemShutdown() { string sKey "System\CurrentControlSet\Control\Windows"; Microsoft.Win32.RegistryKey key …

建立個人學習觀|地鐵上的自習室

作者&#xff1a;向知 如果大家有機會來北京&#xff0c;可以來看看工作日早上八九點鐘&#xff0c;15 號線從那座叫“順義”的城市通向“望京”的地鐵&#xff0c;你在那上面&#xff0c;能看到明明白白的&#xff0c;人們奔向夢想的模樣。 一、地鐵上的自習室 我在來北京之前…

華為數據之道學習筆記】3-5 規則數據治理

在業務規則管理方面&#xff0c;華為經常面對“各種業務場景業務規則不同&#xff0c;記不住&#xff0c;找不到”“大量規則在政策、流程等文件中承載&#xff0c;難以遵守”“各國規則均不同&#xff0c;IT能否一國一策、快速上線”等問題。 規則數據是結構化描述業務規則變量…

【算法集訓】基礎數據結構:三、鏈表

鏈表就是將所有數據都用一個鏈子串起來&#xff0c;其中鏈表也有多種形式&#xff0c;包含單向鏈表、雙向鏈表等&#xff1b; 現在畢竟還是基礎階段&#xff0c;就先學習單鏈表吧&#xff1b; 鏈表用頭結點head表示一整個鏈表&#xff0c;每個鏈表的節點包含當前節點的值val和下…

2024 年頂級的 Android 系統修復軟件與方法

您是否正在尋找可以修復 PC 上 Android 操作系統的工具&#xff1f;這是我們精選的最好的 Android 系統修復軟件&#xff01; Android 是世界著名的智能手機操作系統。全世界有數百萬人使用這個操作系統&#xff0c;這使得它安全可靠。然而&#xff0c;這仍然不能使它完美無缺…

048:利用vue-video-player播放m3u8

第048個 查看專欄目錄: VUE ------ element UI 專欄目標 在vue和element UI聯合技術棧的操控下&#xff0c;本專欄提供行之有效的源代碼示例和信息點介紹&#xff0c;做到靈活運用。 &#xff08;1&#xff09;提供vue2的一些基本操作&#xff1a;安裝、引用&#xff0c;模板使…

普冉(PUYA)單片機開發筆記(6): 呼吸燈

概述 上一篇的實驗中&#xff0c;分別正確地配置了 TIM16 和 TIM1&#xff0c;TIM16 的中斷服務程序中每隔 500ms 翻轉板載 LED 一次&#xff1b;TIM1 的 CHANNEL_1 用于輸出一個固定占空比的 PWM 信號。這一次我們進一小步&#xff1a;使用 TIM16 的中斷設置 TIM1 CHANNEL_1 …

MyBatis進階之分頁和延遲加載

文章目錄 分頁1. RowBounds 分頁2. PageHelper 分頁3. PageInfo 對象屬性描述 延遲加載立即加載激進式延遲加載真-延遲加載 分頁 Mybatis 中實現分頁功能有 3 種途徑&#xff1a; RowBounds 分頁&#xff08;不建議使用&#xff09;Example 分頁&#xff08;簡單情況可用)Pag…

關于對向量檢索研究的一些學習資料整理

官方學習資料 主要是的學習資料是&#xff0c; 官方文檔 和官方博客。相關文章還是挺多 挺不錯的 他們更新也比較及時。有最新的東西 都會更新出來。es scdn官方博客 這里簡單列一些&#xff0c;還有一些其他的&#xff0c;大家自己感興趣去看。 什么是向量數據庫 Elasticse…

文件加密軟件哪個最好用 好用的文件加密軟件推薦

一說到文件加密軟件&#xff0c;可能大家都會去搜一些不知名的軟件來&#xff0c;但是選擇這種加密軟件&#xff0c;最好還是要看一些資質的。 資質不好的&#xff0c;可能加密過后你自己也打不開文件&#xff0c;&#xff08;ps&#xff1a;我自己就遇到過這種情況&#xff09…

【華為OD機試python】分蘋果【2023 B卷|100分】

【華為OD機試】-真題 !!點這里!! 【華為OD機試】真題考點分類 !!點這里 !! 題目描述 A、B兩個人把蘋果分為兩堆,A希望按照他的計算規則等分蘋果, 他的計算規則是按照二進制加法計算,并且不計算進位 12+5=9(1100 + 0101 = 9), B的計算規則是十進制加法,包括正常進位,…

基于Java SSM框架高校校園點餐訂餐系統項目【項目源碼+論文說明】計算機畢業設計

基于java的SSM框架高校校園點餐訂餐系統演示 摘要 21世紀的今天&#xff0c;隨著社會的不斷發展與進步&#xff0c;人們對于信息科學化的認識&#xff0c;已由低層次向高層次發展&#xff0c;由原來的感性認識向理性認識提高&#xff0c;管理工作的重要性已逐漸被人們所認識&a…

(一)Java 基礎語法

目錄 一. 前言 二. Hello World 三. Java 語法 3.1. 基本語法 3.2. Java 標識符 3.3. Java 修飾符 3.4. Java 變量 3.5. Java 數組 3.6. Java 枚舉 3.7. Java 關鍵字 3.8. Java 注釋 3.9. Java 空行 3.10. Java 繼承 3.11. Java 接口&#xff08;interface&#…

Oracle(2-14)User-Managed Incomplete Recovery

文章目錄 一、基礎知識1、Incomplete Recovery Overview 不完全恢復概述2、Situations Requiring IR 需要不完全恢復的情況3、Types of IR 不完全恢復的類型4、IR Guidelines 不完全恢復指南5、User-Managed Procedures 用戶管理程序6、RECOVER Command Overview 恢復命令概述7…

算法訓練營Day8(字符串)

344.反轉字符串 344. 反轉字符串 - 力扣&#xff08;LeetCode&#xff09; class Solution {public void reverseString(char[] s) {for(int i 0,j s.length-1;i< s.length/2 ; i,j--){swap(s,i,j);}}public void swap(char[] s,int i,int j ){char temp s[i];s[i] s[j]…

Python數據科學視頻講解:Python注釋

2.3 Python注釋 視頻為《Python數據科學應用從入門到精通》張甜 楊維忠 清華大學出版社一書的隨書贈送視頻講解2.3節內容。本書已正式出版上市&#xff0c;當當、京東、淘寶等平臺熱銷中&#xff0c;搜索書名即可。內容涵蓋數據科學應用的全流程&#xff0c;包括數據科學應用和…

20231210原始編譯NanoPC-T4(RK3399)開發板的Android10的SDK

20231210原始編譯NanoPC-T4(RK3399)開發板的Android10的SDK 2023/12/10 17:27 rootrootrootroot-X99-Turbo:~$ rootrootrootroot-X99-Turbo:~$ mkdir nanopc-t4 rootrootrootroot-X99-Turbo:~$ rootrootrootroot-X99-Turbo:~$ rootrootrootroot-X99-Turbo:~$ cd nanopc-t4/ …