1 Star 0 Fork 4

hk77cn / Learn_FreeRTOS_with_ESP32

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

Learning-FreeRTOS-with-esp32

什么是 RTOS

其本质上是运行在小型嵌入式设备上的特殊软件-系统软件。如同手机的安卓系统软件、windows 系统软件。

RTOS VS 裸机系统

传统的裸机程序(无操作系统)其内部是一个前后台系统,其中前台程序主要是中断服务程序组成,管理系统标识,后台程序为一个主循环,通过一遍一遍地查询系统标识,执行对应的代码块:

在裸机系统中经常存在下面的问题:

case1: 触发 isr1 后就会执行 code2,即便 isr2 发生,也要先执行完 code2 ,再执行 code3,对 code3 的实时响应造成影响。

case2: 在执行 code3 时,若 isr1 发生,系统不能及时地切换到其他 code,需要重新轮询到对应的系统标识后才能执行对应的 code,CPU 没有及时用到重要的事情上。

因此,裸机系统的缺点是,CPU 利用率底,各个事件的实时性差、缺乏规范的通信组件、开发者必须以轮询、前后台响应的思路进行编程,往往需要彻底地了解整个系统才能写出合适的代码(与硬件的隔离性差),开发难度大。

RTOS(Real Time Operating System, 实时操作系统简称RTOS,是一种通用的、规范的任务管理框架,用于控制任务的运行和任务之间、任务与中断之间的合作关系。通过 RTOS,程序可以兼容复杂的系统组件,用户也不必理解设备硬件的全部知识就可以快捷地调用设备的各种功能,实现系统集成。

RTOS 操作系统的核心功能是:自动管理 CPU 的使用权,最大化 CPU 的利用率,使得操作系统内的每个任务(进程\线程)都能在一定时间内及时的获取 CPU 的使用权,就像多个任务“同时在运行”一样:

以在手机上看小说和听音乐为例子,逻机系统更适合实现先看小说、再听音乐这种简单的逻辑,而带操作系统的设备则更容易实现边听音乐边看小说的逻辑。再以拍照+美颜为例,逻机系统更适合先拍照再把图片进行美颜的逻辑,而带操作系统的设备则更容易实现拍照时直接将美颜效果呈现在屏幕上的逻辑,因为后者可以使用RTOS提供的通信组件将数据实时地传递给美颜的处理程序。

RTOS 提供了哪些功能

RTOS 提供了任务管理、资源访问控制、消息通信、存储管理、低功耗管理等的功能:

通过 RTOS 将提供系统管理的功能,开发者只需调用相关的 API 就可以立即知道系统的情况,创建执行特定功能的代码、代码之间的通信、集成复杂的协议栈,开发复用性高的代码都将变得简单。

为什么要学习 FreeRTOS

FreeRTOS 是非常流行的多任务操作系统。相比其他 RTOS 操作系统,FreeRTOS 具有用户多、免费、组件丰富的优点。通过学习这一典型的操作系统,可以融会贯通地掌握其他 RTOS 系统,对更高级的操作系统如 linux 的学习也是很有帮助的。

为什么使用 ESP32

ESP32 便宜且功能丰富,除了可以学习标准的 FreeRTOS 功能外,乐鑫还开发了 FreeRTOS 的更多功能,如 RingBuffer,双核结构下 FreeRTOS 的使用等。除此之外,使用 ESP32 还可以学习各种外设和网络通信的知识。开源生态也不错,示例代码和开发人员众多。

课程介绍

该课程以问题案例为核心,以实际开发需求为案例,循序渐进地讲述开发过程中可能面临哪些问题及需求。通过实践代码,掌握编程思想。目前规划的内容可分为下述几点:

更新计划

普普通通打工入,准备日更至少一篇(共计约七十篇)。2022 年底前更新完毕。

写这些也是为了督促自己学习总结,和各位工程师同学互勉。

使用说明

关于硬件:任意一款 ESP32 开发板+若干杜邦线即可。

关于软件:思考再三,还是使用 C 语言进行开发。作商用的项目,把设备的性能挖掘到极致,还得是 C 语言这把锋利的小刀。

编译环境安装教程

本课程的示例均基于乐鑫开源的开发环境 ESP-IDF\v4.4 进行演示。关于编译环境的搭建,你可以参考:

  1. ESO-IDF 编程指南-Get Start

  2. ESP-IDF 国内 gitee 网站

  3. ESP-IDF 论坛 建议使用 ubuntu 的开发环境,因为 ubuntu 下编译的更快。

    建立开发环境后,向编译 hello_world 一样进入各个示例编译程序运行,并观察 log 信息就可以了。

参考资源

  1. FreeRTOS 官方开发者指南
  2. FreeRTOS 官方 API 说明文档
  3. 乐鑫 FreeRTOS API 说明新增特性说明
  4. 我的博客
  5. 我的代码

获取代码

  1. 点击代码仓库页面的克隆/下载按钮,下载压缩包获取代码更新:

  2. 使用 git 获取代码更新 如果你已经熟悉使用 git,可以执行下述命令获取仓库代码:

git clone https://gitee.com/yx_wang/learn_freertos_with_esp32

后续你可以使用下述命令获取更新:

git pull origin master

如果你还不熟悉如何使用 git,我建议你谷歌\百度一下如何安装 git,如何使用 git。熟悉 git 对于提高技术人员的技术水平非常有帮助,一开始你不需要了解 git 的方方面面,边用边学就可以了。

学习建议

  1. 学会利用网络,随时查看相关函数的说明、用法、注意事项。
  2. 参考博客的说明进行思考,编译运行程序、并尝试改写程序验证自己的想法。
  3. 如何使用 API 并不重要,认真体会每个组件、每个问题、每次改进所涉及的因与果,形成自己的编程心得。
  4. 真正地掌握一个知识是需要努力和汗水的,极少有可以让你轻松掌握的知识。坚持看完整个示例,你的系统编程思维、C语言知识都会得到锻炼!!!

注意事项

  1. 在学习该课程前,请至少保证已经熟悉 C 语言的基本用法,如果没有请暂停课程的学习,先补充基本的C 语言知识,再开始学习。
  2. 请确保你真的尝试了解过什么是 RTOS,比如百度或者谷歌它。
  3. 建议你使用一块真的开发板来学习嵌入式相关的知识。

Liceance

Apache-2.0,转载及复制需保留证书和作者。

参与贡献

  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

基于 ESP32 学习使用 FreeRTOS 的各种原生功能、派生功能,了解双核设备 ESP32 中的 FreeRTOS。以问题与需求为案例展示如何在实际开发中使用 FreeRTOS,并阐述驱动编程、系统编程的思维与方法。仅为了对自己的学习做总结,并与诸位工程师同学共勉,欢迎交流学习。 展开 收起
C/C++
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C/C++
1
https://gitee.com/hk77cn/learn_freertos_with_esp32.git
git@gitee.com:hk77cn/learn_freertos_with_esp32.git
hk77cn
learn_freertos_with_esp32
Learn_FreeRTOS_with_ESP32
master

搜索帮助