Hi, Habr!
Today I will talk about such an interesting thing as a real-time operating system (RTOS). I'm not sure that it will be interesting for experienced programmers, but I think beginners will like it.
What is RTOS?
If we look at Wikipedia, we will see as many as 4 definitions.
In short, the RTOS is an operating system that reacts to external events in a certain period of time. From here we can understand the main purpose of the RTOS - devices that require a quick response to events (but in no case do not confuse the work of the RTOS with interruptions).
Why do we need it?
There are quite a few reasons for this.
First, the RTOS supports multitasking, semaphore process priorities and more.
Secondly, it is very light and requires almost no resources.
Third, we can get all of the above on almost any hardware (for example, FreeRTOS runs even on 8-bit AtMega).
And fourthly: just play around and have fun.
Review of 3 known RTOS.
Attention: my personal opinion goes further.
')
FreeRTOS
One of the most popular RTOS to date. Ported to a huge amount of iron.
Official site .
pros
1) Free
2) Ported to a large amount of iron
3) Powerful functionality
4) There are various libraries: graphics, internet and more.
5) Good documentation.
Minuses
1) A rather complicated process of porting to a new hardware.
Conclusion: This is a really professional RTOS with good documentation. It will be good for a beginner if there is already a port on his hardware.
KeilRTX
Until recently, this RTOS was commercial, but has recently become open. Works only on arm architecture.
Official site .
pros
1) Free
2) It is easy to port to new hardware (within the arm architecture).
3) There are various libraries: graphics, Internet and more.
Minuses
1) Working on Keil with her is almost impossible.
2) A bit of truncated functionality
3) Only arm is supported.
4) (on personal experience) Loses to many RTOS in speed.
Conclusion: ideal for novice and small projects.
uc / os
Powerful commercial RTOS.
Site .
pros
1) A huge number of functions and libraries.
2) Supports a lot of iron
Minuses
1) Commercial.
2) Difficult to use.
Conclusion: to call it a RTOS for a newbie can be a stretch.
Other interesting RTOS
RTLinux RTOS based on the usual Linux.
QNX Unix based RTOS.
Features of development using RTOS
Well, first you need to understand the following: RTOS is not Windows. It can not be installed. This system is simply compiled with your program.
When writing programs with RTOS, functions in their usual sense are not used. Instead of functions, processes (or tasks) are used. The difference is that processes, unlike functions, are infinite cycles and never end (unless someone or he kills him - that is, unloads from memory).
If several processes are involved, the RTOS switches them, giving out machine time and resources in turn. This is where the concept of process priority arises; if two processes need machine time at a time, then the RTOS will give it to the one who has more priority.
In RTOS there are special delay functions, so that the time was not wasted by the delay time of one process, the second one is performed.
Now let's talk about such a thing as a semaphore, this is such a thing that controls the access of a process to the resources of an application. For each resource there is a marker - when a process needs a resource - it takes it and uses this resource. If there is no marker, the process will have to wait until it is returned. I will give an example: different processes send information on one UART. If there were no semaphore, they would send bytes in turn and it would be a mess. And so the first process took a marker on the UART sent a message and gave it to the second (and so - indefinitely).
Additional libraries of RTOS.
Often, RTOSs offer various libraries to work with, for example, with graphics, the Internet, etc. They are really comfortable and do not disdain to use them. However, remember that without the RTOS for which they were written, they will not work.
Here are some examples:
For RTX
graphics internet file systemIn the second (and, probably, the last) part we will talk about mutexes, message buffers and practice using them.