Shadowing Practice: Introduction to RTOS Part 1 - What is a Real-Time Operating System (RTOS)? | Digi-Key Electronics - Learn English Speaking with Video

Creating lesson...
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.

Vocabulary and speaking notes for this lesson

This video has 119 sentences and 1889 words to shadow. The speech runs for 11:17. The speaker talks at a natural 167 words per minute, close to everyday conversation. Only 78% of the words are among the 3,000 most common in English, so the vocabulary is demanding.

Key vocabulary in this video

15 words from the video worth learning, with pronunciation and meaning:

WordPronunciationMeaning
deadline noun/ˈdɛdˌlaɪn/A time limit in the form of a date on or before which something must be completed.
loop noun/luːp/A length of thread, line or rope that is doubled over to make an opening.
interrupt verb/ˌɪntəˈɹʌpt/To disturb or halt (an ongoing process or action, or the person performing it) by interfering suddenly, especially by speaking.
execute verb/ˈɛksɪˌkjuːt/To kill, especially as punishment for a capital crime.
thread noun/ˈθɹɛd/A cord formed by spinning or twisting together textile fibers or filaments into one or more continuous strands, typically used in needlework.
resource noun/ɹɪˈzɔːs/Something that one uses to achieve an objective, e.g. raw materials or personnel.
input noun/ˈɪnpʊt/The act or process of putting in; infusion.
accomplish verb/əˈkɑm.plɪʃ/To finish successfully.
architecture noun/ˈɑː.kɪˌtɛk.t͡ʃə/The art and science of designing and managing the construction of buildings and other structures, particularly if they are well proportioned and decorated.
execution noun/ˌɛk.sɪˈkjuː.ʃən/The act, manner or style of executing (actions, maneuvers, performances).
overhead noun/ˈəʊvəˌhɛd/The expense of a business not directly assigned to goods or services provided.
toss verb/tɔs/To throw with an initial upward direction.
priority noun/pɹaɪˈɒɹɪti/An item's relative importance.
incredibly adverb/ɪŋˈkɹɛdɪbli/In an incredible manner; not to be believed.
routine noun/ɹuˈtin/A course of action to be followed regularly; a standard procedure.

Phrasal verbs you will hear

WordMeaning
go over verbTo look at carefully; to scrutinize; to analyze.
try out verbTo test (something) to see how it works or whether it is suitable.
figure out verbTo come to understand; to discover or find a solution; to deduce.
leave off verbTo omit.
point out verbTo identify among a group of similar subjects, or in a scene where the subject might not be readily seen or noticed, with a gesture of the body.
push back verbTo refute or argue against a position or an accusation; to express one's own view on a situation.
run across verbTo cross by running.
split up verbCease to be together, break apart from the group.

Grammar in this video

The structures the speaker uses most, with the exact words from the video:

StructureIn the video
Passive voice be + past participle — the focus is on what happens, not who does itare designed · is designed · can be missed
Present perfect have/has + past participle — a past action that still matters nowyou've written · have created · have ported
Relative clauses who / which + clause — extra information about a person or thingdeterministic, which means · interrupts which can · time, which means

Pronunciation to watch

The speaker uses 31 contractions and reduced forms, such as you're, I'll, you'll. Say them the short way, as you hear them.

  • The “sh” and “zh” sounds: accomplish /əˈkɑm.plɪʃ/, execution /ˌɛk.sɪˈkjuː.ʃən/, exception /əkˈsɛpʃən/, interaction /ˌɪn.təˈɹæk.ʃən/, calculation /ˌkælkjuˈleɪʃn̩/
  • Long words — get the stress right: 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/

How to practise with this video

  1. Listen to the whole video once without speaking and note the words you do not know.
  2. Start at 0.75× speed, shadow it sentence by sentence, then go back to normal speed once it feels easy.
  3. Record yourself and compare with the original, paying attention to words like deadline, loop, interrupt.

What is the Shadowing Technique?

Shadowing is a science-backed language learning technique originally developed for professional interpreter training and popularized by polyglot Dr. Alexander Arguelles. The method is simple but powerful: you listen to native English audio and immediately repeat it out loud — like a shadow following the speaker with just a 1–2 second delay. Unlike passive listening or grammar drills, shadowing forces your brain and mouth muscles to simultaneously process and reproduce real speech patterns. Research shows it significantly improves pronunciation accuracy, intonation, rhythm, connected speech, listening comprehension, and speaking fluency — making it one of the most effective methods for IELTS Speaking preparation and real-world English communication.

Shadowing technique: read the full step-by-step guide →