跟讀練習: Introduction to RTOS Part 1 - What is a Real-Time Operating System (RTOS)? | Digi-Key Electronics - 通過影片學習英語口語
選擇練習模式
每種模式都會開啟全屏練習室。
119 句
如果句子過短或過長,請點選 Edit 進行調整。
1
A real-time operating system, or RTOS, is very much like any other operating system with a few important differences.
2
Over the next few videos, I'd like to talk about those differences and how to get started using free RTOS.
3
We'll go over tasks, threads, prioritization, memory management, and intertask communication.
4
Let's get started.
5
An operating system is a piece of software that runs on a computer or microcontroller that accomplishes a number of important functions.
6
First, it is in charge of scheduling background tasks and user applications.
7
In most operating systems, dozens of background processes are executing at the same time,
8
and you probably have several applications open on your phone or computer right now.
9
The operating system figures out how to give slices of time to each of these processes
10
so that everything appears to be happening concurrently.
11
Second, it manages a number of virtual resources like files, libraries, and folders, allowing applications and processes to access them when needed.
12
Third, they can manage or provide device drivers for your system.
13
These drivers allow the system to read and write from an external disk, respond to keyboard and mouse input or draw graphics on your monitor.
14
You're probably familiar with general purpose operating systems like Windows Mac OS and Linux iOS and Android also fall into this category.
15
Most general purpose operating systems are designed with human interaction as the most important feature.
16
So the scheduler is designed to prioritize such tasks
17
that may mean some timing deadlines can be missed or pushed back and a little lag in responsiveness,
18
especially if it's not really noticed by a human, is acceptable.
19
Additionally, the scheduler is often non-deterministic, which means we can't know exactly which task will execute when and for how long.
20
If you're making something that requires an OS and strict timing deadlines, like a medical device or engine controller,
21
missing a deadline to say fire a spark plug would be catastrophic.
22
This is where a real-time operating system or RTOS can save the day.
23
Most RTOS's offer many of the same functions as general purpose operating systems
24
but they are designed so that the scheduler can guarantee meeting timing deadlines on the tasks.
25
While some RTOS's might provide high-level device drivers,
26
you'll usually see things intended for microcontrollers like Wi-Fi and Bluetooth stacks or simple LCD drivers.
27
You can also find bare bones RTOS's that provide just a scheduler.
28
With these, you'll need to import or write your own file systems and device drivers.
29
Note that while most RTOS's provide methods for meeting timing deadlines, that's not the only reason to use an RTOS in your project.
30
The ability to run multiple tasks concurrently can be a lifesaver as we'll see in a moment.
31
If you've written programs for microcontrollers, including Arduino, you're probably familiar with this kind of structure.
32
When your program starts, it performs some setup functions
33
and then it executes your tasks in a round robin fashion inside a while forever loop.
34
These tasks might read from sensors, perform some calculations based on those readings, and then say display something on a gorgeous LED display.
35
This type of simple programming architecture is known as a super loop.
36
It's incredibly easy to implement, has very little overhead, and is great when you only need to accomplish a handful of tasks on your microcontroller. In fact,
37
there's nothing wrong with the super loop for the vast majority
38
of simple microcontroller projects you're usually better off with this type of program flow as it saves on CPU cycles and memory
39
and it's much easier to debug than using an RTOS you
40
might even have created a couple of interrupts to break the
41
flow of execution to handle an external event like a button push or perform some action at specific timed intervals
42
If you need to meet strict timing deadlines for one or two tasks,
43
you might be better off using just interrupt service routines to accomplish those tasks with precise timing.
44
In my experience, if you need to meet a timing deadline of less than about one millisecond, your best bet is an interrupt anyway.
45
If you're trying to do something with an interval of less than a few hundred nanoseconds, you either need an incredibly fast processor,
46
or it's time to start looking at custom hardware like an FPGA.
47
Now, the unfortunate thing about this super loop architecture is that you cannot execute tasks concurrently.
48
If task two starts taking a long time and task three is your update display task, you'll start to experience some lag.
49
Similarly, if you're polling for user input like from a serial terminal or reading a sensor, you might miss data if other tasks take too long.
50
To fix that, we can use the concept of running multiple tasks at the same time.
51
On a multi-core processor, this is actually physically possible.
52
However, since many microcontrollers only have one core, the CPU time needs to be split up among the tasks.
53
We can also give higher priority to some tasks so that they happen sooner or take more CPU time.
54
For example, if we prioritize the user input task, users will likely experience less lag,
55
but it might mean background tasks take longer to execute.
56
We'll talk more about time slicing and prioritization in a future video.
57
Note the terminology used here.
58
A task is any piece of work we want to get done in code.
59
A thread is a unit of CPU utilization with its own program counter and set of memory.
60
A process is an instance of a computer program that's being executed.
61
Usually a process will have one or more threads used to accomplish tasks.
62
Threads within a process will often share resources like heap memory and can pass resources to each other.
63
You'll often find that in our toss is capable of handling only one process, but a general purpose OS can run many processes.
64
Note that in free our toss, the term task is used to mean something closer to a thread and you'll often see these terms used interchangeably.
65
Because of this, I will use the term task
66
when referring to units of CPU utilization so
67
that it makes sense within the free our toss ecosystem interrupts still work within an RTOS
68
so long as they have a higher priority than any of
69
the tasks they will stop code execution for all tasks run your interrupt service routine
70
and return execution to where it left off you can have more than one interrupt
71
but we won't get into handling nested interrupts which can get nasty
72
if you're writing code for a simple 8
73
or 16-bit microcontroller with 2 kilobytes of ram you're probably best sticking with the super loop approach
74
and using the inexpensive controller to do only a a handful of tasks.
75
While you can get a simple scheduler to run on such a device,
76
the memory and CPU overhead of switching tasks would not leave you with many resources left for your actual program.
77
People have ported free RTOS to the Arduino Uno.
78
It's definitely a good way to tinker around with it, but I don't know how ultimately useful it is.
79
As you move into more and more powerful microcontrollers, it becomes much more viable to run in RTOS as you've got clock cycles
80
and memory to spare for things like a scheduler.
81
While you can still run a bare metal super loop on something like an ESP32,
82
I usually find that the whole reason I bought something with that much computing power is to run several concurrent tasks.
83
Which brings me to the ultimate question of, why would you want an RTOS?
84
There are a number of reasons, but the best one that comes to mind is for when you need to do several things concurrently currently.
85
An ESP 32 is capable of handling user input, reading and writing to an SD card, controlling hardware, and crunching numbers all at the same time.
86
The big one for something like this is the wireless stack.
87
These libraries require large amounts of RAM and processing power.
88
They also need to respond to events from the network in a short amount of time, which means using an RTOS can be a massive help in this case.
89
It can help you divide up these different features into individual tasks.
90
An RTOS can be great if you're part of a team working on a larger project.
91
You can divide up the tasks among the team members, knowing that each one will run concurrently.
92
There will be some overhead and debugging to make sure everything works together though.
93
Over the next few videos, I'll go over important RTOS concepts like prioritization and resource management.
94
We'll practice these concepts by implementing small demo projects in Free RTOS on the ESP32.
95
The reason I chose Free RTOS for this series is because it's currently the most popular real-time operating system for IoT devices,
96
as shown by this 2018 survey from the Eclipse Foundation.
97
While Linux still reigns supreme for most of these devices, it and Windows are general purpose operating systems, with the exception of RT Linux.
98
You can see that the bare metal super loop architecture is still quite popular and an acceptable solution to many problems.
99
FreeRTOS is also free and open source, making it easy for you to try out.
100
Note that as of 2017, Amazon has taken over maintenance of the FreeRTOS project.
101
I also recommend keeping an eye on the Zephyr project as
102
it's a relative newcomer to the field backed by the Linux Foundation.
103
The ESP32 is a powerful IoT microcontroller that's packed with features.
104
Also, you can find inexpensive ESP32 development boards.
105
Any of them should work for this series as long as they have an associated Arduino package.
106
I know some of you will balk at the idea of using Arduino for our coding, but hear me out.
107
Most embedded programmers and electronics tinkerers will have some experience with Arduino, and if not, it's easy to learn.
108
Because of that, it creates a level playing field for anyone wanting to try out RTOS concepts.
109
I don't need to teach a vendor tool or chip-specific libraries on top of trying to teach free RTOS.
110
Because the ESP32 runs a modified version of FreeRTOS out of the box, there is hardly any setup involved in creating tasks in Arduino.
111
Almost every code example you see, including task management, semaphores, mutexes, and so on, can easily be ported to your own build system.
112
I'll try to point out where the ESPRTOS differs from vanilla FreeRTOS.
113
An RTOS may not be the right answer to every firmware problem you run across, but sometimes it is the right tool for the job,
114
especially when you need to do things like run concurrent tasks and meet timing deadlines.
115
At the end of most of these videos, I'll issue you a challenge,
116
and I encourage you to try it out on your own ESP32 or whatever device you're running free RTOS on.
117
I'll then post a link to my solution so that you can see how your solution compares.
118
In the next video I'll show you how to get started with free RTOS
119
and create your own task to blink an LED.
同頻道
FOR YOU
推薦影片
本課的詞彙與口語要點
這段影片共有 119 個句子、1889 個單詞可供跟讀。 講話部分時長為 11:17。 說話人語速自然,每分鐘約 167 個詞,接近日常對話。 只有 78% 的單詞屬於英語最常用的 3,000 詞,詞彙難度較高。
影片中的重點詞彙
影片中 15 個值得學習的單詞,附發音和釋義:
| 單詞 | 發音 | 釋義 |
|---|---|---|
| deadline 名詞 | /ˈdɛdˌlaɪn/ | 截止日期, 限期 |
| loop 名詞 | /luːp/ | 圈, 環 /環 |
| interrupt 動詞 | /ˌɪntəˈɹʌpt/ | 打斷 /打斷, 插嘴 |
| execute 動詞 | /ˈɛksɪˌkjuːt/ | 處決 /處決, 處死 /處死 |
| thread 名詞 | /ˈθɹɛd/ | 線 /線 |
| resource 名詞 | /ɹɪˈzɔːs/ | 資源 /資源 |
| input 名詞 | /ˈɪnpʊt/ | 輸入 /輸入 |
| accomplish 動詞 | /əˈkɑm.plɪʃ/ | 達到 /達到 |
| architecture 名詞 | /ˈɑː.kɪˌtɛk.t͡ʃə/ | 建築 /建築, 建築學 /建築學 |
| execution 名詞 | /ˌɛk.sɪˈkjuː.ʃən/ | 執行 /執行, 實行 /實行 |
| overhead 名詞 | /ˈəʊvəˌhɛd/ | 間接費用 /間接費用 |
| toss 動詞 | /tɔs/ | 拋 /拋 |
| priority 名詞 | /pɹaɪˈɒɹɪti/ | 優先權 /優先權, 更重要的事 |
| routine 名詞 | /ɹuˈtin/ | 常規 /常規, 慣例 /慣例 |
| hardware 名詞 | /ˈhɑɹdˌwɛɹ/ | 硬體, 硬體 /硬體 |
影片中出現的短語動詞
| 單詞 | 釋義 |
|---|---|
| try out 動詞 | 試用 /試用 |
| figure out 動詞 | 弄清楚 |
| point out 動詞 | 指, 指出 |
| take over 動詞 | 接管, 接手 |
影片中的語法
說話人最常用的結構,並附上影片中的原話:
| 結構 | 影片中的用法 |
|---|---|
| 被動語態 be + 過去分詞 — 強調發生了什麼,而不是誰做的 | are designed · is designed · can be missed |
| 現在完成時 have/has + 過去分詞 — 過去發生但與現在仍有關聯的事 | you've written · have created · have ported |
| 定語從句 who / which + 從句 — 補充說明人或事物 | deterministic, which means · interrupts which can · time, which means |
需要注意的發音
說話人用了 31 次縮略和弱讀形式,例如 you're, I'll, you'll。請按聽到的簡短形式來說。
- “sh” 和 “zh” 音: accomplish /əˈkɑm.plɪʃ/, execution /ˌɛk.sɪˈkjuː.ʃən/, exception /əkˈsɛpʃən/, interaction /ˌɪn.təˈɹæk.ʃən/, calculation /ˌkælkjuˈleɪʃn̩/
- 長單詞——注意重音位置: architecture /ˈɑː.kɪˌtɛk.t͡ʃə/, execution /ˌɛk.sɪˈkjuː.ʃən/, priority /pɹaɪˈɒɹɪti/, incredibly /ɪŋˈkɹɛdɪbli/, acceptable /əkˈsɛp.tə.bəl/
如何用這段影片練習
- 先完整聽一遍影片,不要開口,記下不認識的單詞。
- 先用 0.75 倍速逐句跟讀,熟練之後再回到正常速度。
- 錄下自己的聲音並與原聲對比,特別注意 deadline, loop, interrupt 這類單詞。
什麼是跟讀法?
跟讀法 (Shadowing) 是一種有科學依據的語言學習技巧,最初開發用於專業口譯員的培訓,並由多語言者Alexander Arguelles博士普及。這個方法簡單而強大:您在聽英語母語原聲的同時立即大聲重複——就像是一個延遲1-2秒緊跟說話者的影子。與被動聽力或語法練習不同,跟讀法強迫您的大腦和口腔肌肉同時處理並模模擬實的講話模式。研究表明它能顯著提高發音準確性,語調,節奏,連讀,聽力理解和口語流利度——使其成為雅思口語備考和真實英語交流最有效的方法之一。













