物联网与嵌入式系统概论-week3- Hardware and Software-Lesson3: Operating Systems
This series of articles are the study notes of "An Introduction to Programming the Internet of Things", by Prof. Harris, Department of Computer Science, University of California, Irvine. This article is week 3, Lessen 3: Operating Systems.
3. Lesson 3:Operating Systems
3.1 Lecture 3.1 Operating Systems
3.1.1 Flow chart of a application working on a operation system
There's a user at the top, whose using some application. By application we mean the actual program. So you've compiled the program and that application, that's the application code. Do we know that application code would connect directly to the hardware. So it'd go straight from the application to the hardware. No operating system at all. And the application directly controls the hardware. But in say Raspberry Pi or more complicated IoTdevice, you would have something like what you see here where the user attacks the application. The application code actually may not directly connect to the hardware, it communicates with the operating system. So, it makes calls from the operating system and it's requesting hardware service and then the operating system manages the hardware most directly.
3.1.2 Operation system
(1) Manages other programs
Windows, iOS, Linux, etc
(2) Allow many program to be executed together
One thing about an operating system is that it allows you to have not only one application but many applications. Soyou can run lots of different applications at one time, and the operating system itself manages the hardware.Without an operating system you can only run one programat a time.
(3) Incorporates a nice user interface
A nice user interface so often, now, how nice a user interface really depends on the operating system. If you look at a desktopor a laptop Windows, iOS, Linux, something like that, they will have a very nice user interface. Graphic user interface, GUI, you can double-click on something. Double-click on a file, it'll open it up, that sort of thing. That's a full-on operating system. The operating systems that you find in an IoT device, they're much smaller and stripped back. They're not going to have, not likely to have any graphical user interface or anything like that, but they will have a user interface, a command line.
(4) Needs processing power and memory
And it needs processing power. So one thing about operating systems is that operating system itself is a big program. It's a big program that's running in addition to the actual programs that you want to run on your IoT device. So, it's going to consume clock cycles. There are some clock cycles that are spent doing operating system tasks. Some memory that's spent storing the operating system data. Things like this. So, the operating system itself takes up resources so you have to make a decision whether you need one or not. Because it's going to cost you resources, which means cost you money.
(5) Slows downthe system, makes development easier
It slows down the system because while the processor is working on the operating system, doing executing the operating system code, it can't be executing your actual application. So it slows thing sdown. And so as a result, when you use an operating system, you generally need a faster processor. That's why, if you look at an Arduino which is running at maybe 8MHz, something like that, usually don't support an operating system with that. But if you run Raspberry Pi and you've got like 1Gz, then it's okay to support an operating system, because it has enough clock cycles that you can do that.
3.1.2 Operation system example
3.2 Lecture 3.2 Task Support
3.2.1 Multiple Tasks
- Assume that one microcontroller is being used
- At least four different tasks must be performed
(1) send video data: continuous while a useris connected
(2) service motion buttons: whenever button is pressed, may last seconds
(3) detect obstacles: continuous at all times
(4) auto brake: whenever obstacle is detected, may last second
- Detect and auto brake cannot occur together
- 3 tasks may need to occur concurrently
So I just talking about how they can happen together, you get detect and auto brake cannot occur together. So if you detect, then you auto brake. They don't happen together, but everything else can happen concurrently. So in a situation like this, you need to have multiple things running at the same time. Multiple tasks being performed at the sametime. Now you could write a relatively complicated program that does all these things at once and checks. While you're sending video data, it's also checking to see if a button is pressed, it's also checking for collisions and so on. But an operating system makes this easier, because you can write each one of these tasks as a separate task and then let the operating system inter-mix them. You can write one piece of code that just sends video data. Another piece that serves as motion buttons, another that takes obstacles. Another one that does auto brake and then you can give them the operating system and the operating system will make sure that they all run at the same time. You don't have to as a programmer, you can write things separately. You can write the sending video data code separately from the servicing motion button code and the operating system can interweave them for you and that relieves a lot of burden for the programmer. So the main job of an operating system is to support a process or a task abstraction.
3.2.2 Process/Task Support
(1) Main job of an OS is to support the Process (Task)
(2) A processis a instantiation of a program;
It must have access to:
- The CPU
- Ther resource: I/O, ADC, timers, network,etc.
(3) OS must manage resources
- Give processes fair access to the CPU
- Give processes access to resources