ChibiOS简介4/5

ChibiOS简介4/5

  • 1. 源由
  • 2. ChibiOS基础知识4/5
    • 2.13 Chapter 13 - RT Synchronous Messages
      • 2.13.1 Basic concepts
      • 2.13.2 APIs
    • 2.14 Chapter 14 - RT Events
      • 2.14.1 Basic concepts
        • 2.14.1.1 Events
        • 2.14.1.2 Operations
      • 2.14.2 APIs
    • 2.15 Chapter 15 - RT Debug
      • 2.15.1 Compile Time Checks
      • 2.15.2 Runtime Checks
      • 2.15.3 Kernel Statistics
      • 2.15.4 System State Checks
      • 2.15.5 Functions Parameters Checks
      • 2.15.6 System Assertions
      • 2.15.7 Trace Buffer
      • 2.15.8 Stack Overflow Checks
      • 2.15.9 Working Area Fill
      • 2.15.10 Threads Profiling
  • 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基础知识4/5

2.13 Chapter 13 - RT Synchronous Messages

2.13.1 Basic concepts

  • Synchronous Messages are a unique feature of ChibiOS/RT that allows to create client/server architectures into an embedded system. RT implements in its inner scheduler layer a message-passing mechanism, when a context switch is performed a message is always passed between the thread being switched out and the one being switched in. The message is exchanged with almost no overhead. This inner mechanism is used to implement the Synchronous Messages high level functionality.

  • Client and Servers, When using synchronous messages there are two kind of threads: clients and servers.

Clients are threads that start a transaction by sending a message to a server thread then wait for a response message.

Servers are threads that wait for a transaction start from a client, once a message is received the server processes it and finally send a response message to the client. Servers are able to handle one message at time but can also handle multiple messages from different clients and to returns answers in an arbitrary order.

在这里插入图片描述

  • Messages are always signed scalars with type msg_t. This type is guaranteed to be cast-able to/from data pointers. Clients can send simple encoded messages but also pointers to structures representing complex transactions.

There are three predefined messages used internally to the RT kernel:

  1. MSG_OK. Defined as 0 is a generic acknowledge message.
  2. MSG_TIMEOUT. Defined as -1 is the message sent in case of timeouts.
  3. MSG_RESET. Defined as -2 is the message sent to inform of an object reset condition.

Note: It is assumed that pointers with values 0, -1 and -2 to not be valid pointers. Also note that there are no dedicated objects involved, the exchange is done directly between threads, each thread has its own queue of incoming messages.

  • Message Passing, In this scenario there are multiple threads in the system that never share data, everything is done by exchanging messages. Each thread represents a service, the other threads can request the service by sending a message.

在这里插入图片描述

2.13.2 APIs

Function NameDescription
chMsgSend()Sends a message to the specified thread.
chMsgWait()Waits for a message and returns a pointer to the sender thread.
chMsgGet()Retrieves the message after exiting from chMsgWait().
chMsgRelease()Returns an answer to the specified sender and releases it.
chMsgIsPendingI()Evaluates to true if there is a message waiting in the queue.

2.14 Chapter 14 - RT Events

2.14.1 Basic concepts

2.14.1.1 Events
  • Event Sources are the objects that broadcast events to system.
  • Event Flags, Events also carry information, the information is encoded as Event Flags, a mask of flags of type eventflags_t are broadcasted by sources together with the event itself.
  • Event Listeners, On each event source one or more event listeners can be registered, each event listener is linked to a single thread.
  • Events Masks, A set of pending events at thread level is called an Events Mask and has type eventmask_t, this type has must not be confused with event flags.
2.14.1.2 Operations
  • Registering
    The register operation is performed by a thread in order to become a listener of an event source, the association is mediated by an event listener object as follow:
PROCEDURE register(source, listener, events, wflags)LET listener.flags = 0LET listener.wflags = wflagsLET listener.events = eventsLET listener.thread = current_threadsource.listeners = source.listeners + listener
END
  • Waiting for Events
    The wait operation allows a thread to check for pending events or wait for them if none:
FUNCTION wait(events)LET current_thread.ewmask = eventsIF current_thread.epending AND current_thread.ewmask = 0WAITENDRETURN current_thread.epending AND current_thread.ewmask
END
  • Broadcasting
    The broadcast operation notifies all the registered threads that an event occurred on an Event Source, it is quite complex:
PROCEDURE broadcast(source, flags)FOR EACH source.listeners AS listenerLET listener.flags = listener.flags OR flagsIF (listener.flags AND listener.wflags) <> 0LET listener.thread.epending = listener.thread.epending OR listener.eventsIF listener.thread.epending AND listener.thread.ewmask <> 0WAKEUP listener.threadENDENDEND
END
  • Simplified Events
    There is also another way to use events without recurring to event sources and listeners. A thread can directly signal another thread. In this scenario there is no decoupling between sources and threads, specific threads or ISRs signal specific threads with a mask of event flags. The targeted object is directly the thread handling the event.
PROCEDURE signal(thread, events)LET thread.epending = thread.epending OR eventsIF thread.epending AND thread.ewmask <> 0WAKEUP threadEND
END

2.14.2 APIs

Function NameDescription
EVENTSOURCE_DECL()Event sources static initializer
EVENT_MASK()Translates from an event identifier to an event mask
chEvtObjectInit()Initializes an event source object of type event_source_t
chEvtRegister()Registers the current thread on an event source by assigning it an event identifier
chEvtRegisterMask()Registers the current thread on an event source by assigning it a mask of events
chEvtRegisterMaskWithFlags()Registers the current thread on an event source by assigning it a mask of events and a set of flags
chEvtUnregister()Unregisters the current thread from an event source
chEvtGetAndClearEvents()Returns the events pending for the current thread
chEvtAddEvents()Adds a mask of events to the current thread
chEvtSignal()Adds a mask of events to the specified thread
chEvtSignalI()Adds a mask of events to the specified thread (I-Class variant)
chEvtBroadcast()Performs the broadcast operation on an event source with no flags
chEvtBroadcastI()Performs the broadcast operation on an event source with no flags (I-Class variant)
chEvtBroadcastFlags()Performs the broadcast operation on an event source and adds the specified flags to event listeners
chEvtBroadcastFlagsI()Performs the broadcast operation on an event source and adds the specified flags to event listeners (I-Class variant)
chEvtGetAndClearFlags()Returns the event flags pending in the specified event listener
chEvtGetAndClearFlagsI()Returns the event flags pending in the specified event listener (I-Class variant)
chEvtWaitOne()Waits for exactly one of the specified events
chEvtWaitAny()Waits for any of the specified events
chEvtWaitAll()Waits for all the specified events
chEvtWaitOneTimeout()Waits for exactly one of the specified events with timeout
chEvtWaitAnyTimeout()Waits for any of the specified events with timeout
chEvtWaitAllTimeout()Waits for all the specified events with timeout
chEvtIsListeningI()Verifies if there is at least one listener registered on the event source (I-Class variant)
chEvtDispatch()Calls the functions associated with an events mask

2.15 Chapter 15 - RT Debug

ChibiOS/RT provides a comprehensive set of debug options meant to assist the developer during the system implementation and debug phase. All the debug options are reachable into the kernel configuration file chconf.h, each project has its own copy of this file.

2.15.1 Compile Time Checks

Configuration errors are, by design, detected at compile time, the system headers include logic checks that result in compilation errors in case of a wrong configuration.

2.15.2 Runtime Checks

Most debug options operate at runtime in order to catch design or programming errors. If a problem is detected then the system is stopped into the function chSysHalt() and the global variable ch.dbg_panic_msg points to an error message string.

2.15.3 Kernel Statistics

The debug option CH_DBG_STATISTICS enables support for kernel statistics. Statistics include:

  • Number of served IRQs.
  • Number of context switches.
  • Time measurement of thread-level critical sections: best, worst, last cases are stored.
  • Time measurement of ISR-level critical sections: best, worst, last cases are stored.
  • For each thread the following counters are kept:
  1. Longest execution time.
  2. Shortest execution time.
  3. Last execution time.
  4. Cumulative execution time.

Times are measured using the realtime counter and are clock cycle accurate. The ChibiOS/RT Eclipse plugin is able to show the runtime statistics of the application under debug.

2.15.4 System State Checks

The debug option CH_DBG_SYSTEM_STATE_CHECK enables an unique ChibiOS/RT, the System State Checker. This option is able to detect any call protocol violation, calling OS APIs out of the proper context is one of the greatest sources of hard to detect problems and random crashes.

2.15.5 Functions Parameters Checks

The debug option CH_DBG_ENABLE_CHECKS enables the parameters checks at API level. This option is able to detect application errors causing the application to pass invalid parameters to the RTOS, a typical example are NULL pointers passed where a reference to a valid object is expected. It is advisable to keep this option enabled through the whole development process. Safety concerns may require to keep this kind of checks in place also in the final code as a defensive measure.

2.15.6 System Assertions

The debug option CH_DBG_ENABLE_ASSERTS enables system-wide integrity checks on the RTOS data structures. The system is also checked for unexpected runtime situations. It is advisable to keep this option enabled through the whole development process. Safety concerns may require to keep this kind of checks in place also in the final code as a defensive measure.

2.15.7 Trace Buffer

The option CH_DBG_TRACE_MASK is an “or” of various option flags, each option selects an event to be traced:

  • CH_DBG_TRACE_MASK_NONE. No events traced by default (but tracing can be activated at runtime for any event).
  • CH_DBG_TRACE_MASK_SWITCH. Context switches are traced by default.
  • CH_DBG_TRACE_MASK_ISR. ISR enter and leave events are traced by default.
  • CH_DBG_TRACE_MASK_HALT. The halt event is traced, of course it is the last event recorded.
  • CH_DBG_TRACE_MASK_USER. User events are recorded. Application code can trace events using the chDbgWriteTrace() API.
  • CH_DBG_TRACE_MASK_SLOW. All events are enabled except IRQ-related ones.
  • CH_DBG_TRACE_MASK_ALL. All events are enabled.
  • CH_DBG_TRACE_MASK_DISABLED. The trace subsystem is removed entirely from the OS image.

The trace buffer stores the last N context switch operations. It can be used to determine the sequence of operations that lead to an halt condition. The option CH_DBG_TRACE_BUFFER_SIZE allows to change the size of the trace buffer, the default is 128 entries.

2.15.8 Stack Overflow Checks

The debug option CH_DBG_ENABLE_STACK_CHECK enables checks on stack overflow conditions. The implementation of the detection is port-dependent and can be implemented differently in each port or even be not supported at all. The most common implementation is to check the stack position when a context switch is about to be performed, if the calculated new stack position overflows the stack limit then the system is halted. Safety concerns may require to keep this kind of checks in place also in the final code as a defensive measure.

2.15.9 Working Area Fill

The debug option CH_DBG_FILL_THREADS fills the threads working area with a fixed 0x55 pattern before the thread is executed, this allows to calculate the effective stack usage by the various threads. The ChibiOS/RT Eclipse plugin is able to calculate the unused stack size for each thread if this option is enabled. Optimizations of the unused stacks should only be performed:

  • At development end.
  • With all other debug options disabled or in their final settings.
  • Using the final compiler version.
  • Using the final compiler options.

Use case in optimizing stacks because different compiler options or compiler version can change stack sizes dramatically and there is the risk of introducing errors not easily detected in the final code (with checks disabled).

2.15.10 Threads Profiling

The debug option CH_DBG_THREADS_PROFILING enables a system tick counter in each thread, after a long execution time relative values of the counters indicate the relative “weight” of all threads. This option has been superseded by CH_DBG_STATISTICS and is not compatible with the tick-less mode.

3. 参考资料

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

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

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

相关文章

without explicit opt-in, is unsupported. Switch Maven repository ‘maven8

Using insecure protocols with repositories, without explicit opt-in, is unsupported. Switch Maven repository maven8 大概意思是 不支持对存储库使用不安全的协议.看下maven库&#xff0c;把http开头的改成https就好了。

B站武sir-django教程(1)

day15 初识Django Python知识点&#xff1a;函数、面向对象。前端开发&#xff1a;HTML、CSS、JavaScript、jQuery、BootStrap。MySQL数据库。Python的Web框架&#xff1a; Flask&#xff0c;自身短小精悍 第三方组件。Django&#xff0c;内部已集成了很多组件 第三方组件。…

Restormer技术点小结

1. 解决cnn的不足&#xff1a; 1&#xff09;感受野有限 2&#xff09;输入尺寸固定 2. 解决transform的不足&#xff1a; 1&#xff09;计算复杂度随着空间分辨率的增加而二次增长 3. 优势结构&#xff1a;MDTA(Multi-Dconv Head Transposed Attention)和GDFN( Gated-Dco…

Sentinel使用详解

组件简介 Sentinel是阿里开源的一套用于服务容错的综合性解决方案。它以流量为切入点&#xff0c;从流量控制、熔断降级、系统负载保护等多个维度来保护服务的稳定性。Sentinel承接了阿里巴巴近10年的双十一大促流量的核心场景&#xff0c;例如秒杀、消息削峰填谷、集群流量控…

C语言 内存操作函数 +内存分区

内存操作函数 memset() //memset 函数将指定内存区域 ptr 开始的 num 个字节设置为 value。 void *memset(void *ptr, int value, size_t num);参数&#xff1a;ptr&#xff1a;指向要填充的内存区域的指针。value&#xff1a;要填充的值&#xff0c;以整数形式传递。num&…

20-11版本AUTOSAR_PRS_LogAndTraceProtocol文档翻译

1简介和概述 本协议规范规定了AUTOSAR协议Dlt的格式、消息序列和语义。 该协议允许将诊断、日志和跟踪信息发送到通信总线上。 因此&#xff0c;Dlt模块从应用程序或其他软件模块收集调试信息&#xff0c;向调试信息添加元数据&#xff0c;并将其发送到通信总线。 此外&#x…

软件设计师——信息安全(一)

&#x1f4d1;前言 本文主要是【信息安全】——软件设计师——信息安全的文章&#xff0c;如果有什么需要改进的地方还请大佬指出⛺️ &#x1f3ac;作者简介&#xff1a;大家好&#xff0c;我是听风与他&#x1f947; ☁️博客首页&#xff1a;CSDN主页听风与他 &#x1f304…

华为OD试题五(数列描述、矩阵最大值、数据分类)

1. 数列描述 示例代码&#xff1a; # 核心 从第一项 推 第N项目 # 第一项 a0 1 # 推到 第N项 N 4 def fun(a0):# 计算每一项的具体值result left 0cursor 0while cursor < len(a0):if a0[cursor] ! a0[left]:count cursor -leftresult "{}{}".format(str(…

面相对象开发的原则

1、开闭原则 对修改关闭&#xff0c;对扩展打开。 2、里氏替换原则 子类继承父类的方法时&#xff0c;不可重写父类的方法。 如果重写了父类的方法会导致整个继承体系比较差&#xff0c;特别是运用多态比较平凡时&#xff0c;程序运行出错概率较大。 如果出现了违背“里氏替换…

计网Lesson9 - 链路协议和网络概述

文章目录 数据链路层协议Ethernet V2标准Ethernet V2帧格式Ethernet V2帧长度标准以太网帧 MAC 帧协议 PPP 协议PPP 概述PPP 帧 网络层网络层的设计选择 数据链路层协议 Ethernet V2标准 Ethernet V2帧格式 以太网帧格式说明&#xff1a; 6 6 6 字节目标地址 6 6 6 字节源地…

【LeetCode每日一题】1904. 你完成的完整对局数

给你两个字符串 startTime 和 finishTime &#xff0c;均符合 "HH:MM" 格式&#xff0c;分别表示你 进入 和 退出 游戏的确切时间&#xff0c;请计算在整个游戏会话期间&#xff0c;你完成的 完整对局的对局数 。 如果 finishTime 早于 startTime &#xff0c;这表示…

verilog基础,连续赋值之组合逻辑

连续赋值语句可以完成任意组合逻辑&#xff0c;本节对基本的逻辑电路进行测试分析&#xff0c;主要包含一下内容&#xff1a; 1. 反相器 2. 与门 3.与非门 4.或门 5.或非门 6.异或门 7.同或门 verilog实现逻辑操作的算符如下 // ~ .... Invert a single-bit signal…

「Leetcode」滑动窗口—长度最小的子数组

&#x1f4bb;文章目录 &#x1f4c4;题目✏️题目解析 & 思路&#x1f4d3;总结 &#x1f4c4;题目 209. 长度最小的子数组 给定一个含有 n 个正整数的数组和一个正整数 target 。 找出该数组中满足其总和大于等于 target 的长度最小的 连续子数组 [numsl, numsl1, …,…

【UE 材质】角色触碰空气墙效果

效果 步骤 1. 新建一个工程&#xff0c;创建一个Basic关卡&#xff0c;添加一个第三人称游戏资源到内容浏览器 2. 新建一个材质参数集&#xff0c;这里命名为“MPC_Vector” 打开“MPC_Vector”&#xff0c;添加一个向量参数 3. 新建一个材质&#xff0c;这里命名为“M_Wall”…

力扣每日一题:2132. 用邮票贴满网格图(2023-12-14)

力扣每日一题 题目&#xff1a;2132. 用邮票贴满网格图 日期&#xff1a;2023-12-14 用时&#xff1a;38 m 32 s 思路&#xff1a;使用前缀和&#xff0b;差分&#xff0c;只是往常是一维&#xff0c;现在变二维了&#xff0c;原理差不多 时间&#xff1a;22ms 内存&#xff1…

运行和部署若依分离版前端

一、运行 一、用vscode打开 二、安装依赖 # 建议不要直接使用 cnpm 安装依赖&#xff0c;会有各种诡异的 bug。可以通过如下操作解决 npm 下载速度慢的问题 npm install --registryhttps://registry.npmmirror.com# 启动服务 npm run dev浏览器访问 http://localhost:80二、部…

数据库的优化

1、创建index索引&#xff1b; 2、减少select * 的使用&#xff0c;具体一点&#xff0c;全取会增加web服务器的负担&#xff1b; 3、explain select&#xff1a;显示了mysql如何使用索引来处理select语句以及连接表&#xff1b; 4、度多使用varchar/nvarchar&#xff0c;变长…

深入解析,录制视频的软件推荐(3款)

在信息时代&#xff0c;视频成为了传递信息、分享经验的重要媒介。为了创作出更具吸引力和实用性的视频&#xff0c;选择合适的录制工具显得至关重要。本文将深入介绍3款录制视频的软件&#xff0c;通过本文&#xff0c;您将深入了解这3款软件的使用方法&#xff0c;以满足不同…

JRT文件服务实现

网站与客户端打印和导出方面已经无大碍了&#xff0c;今天抽时间整整文件服务&#xff0c;文件服务设计可以查看下面连接。原理一样&#xff0c;代码会有些变化。 文件服务设计 首先实现文件服务的服务端&#xff0c;就是一个业务脚本&#xff0c;用来接收上传、移动和删除文件…

往上走^^

欢迎来到程序小院 往上走 玩法&#xff1a;转动的圆球&#xff0c;点击固定到上方的圆中即可往上走一步&#xff0c;转动超过上面圆即游戏结束&#xff0c; 往上走一步加1分&#xff0c;快去往上走吧^^。开始游戏https://www.ormcc.com/play/gameStart/218 html <canvas wi…