RTOS in Microcontrollers

In the previous article, I have introduced you about RTOS, it’s advantages and why we use them. In this article, I am going to dig a little deep into RTOS specifically into the Microcontroller. Let’s get started.

Need for RTOS in Microcontrollers

When we go into the history of microcontrollers, they were designed to perform one task only. Microcontrollers now are much more enhanced than they were used to be and are capable to perform much more complex tasks. Therefore we need an Operating System to help us do this.

Now, most microcontrollers are still not able to handle full fledge operating systems and that’s why we need RTOS. 

How RTOS executes in Microcontrollers

Since most microcontrollers are not able to perform multiple tasks simultaneously. It perform any task in the process described below-

Ready Mode

The task is in ready mode. It can now be executed. Whether to execute it or not depends on the priority of the task.

Execution Mode

The task is in execution mode. It means the CPU is executing the task. The CPU can not perform any other task while executing the current task. Even if the task of higher priority comes in Ready mode, the CPU will complete the current task before switching the task.

Block Mode

After completing the task, the CPU puts the task in the block mode along with the time before it switches back to ready mode. Below the picture demonstrating the above process.

Now, there are more challenges to use RTOS in embedded systems. For example- what if there are two tasks want to utilize the same resource?

In this case, you want to protect the resource for one task until the execution of the task is complete. For this mechanism, there is something called semaphore and mutex. There is an incredible article written about it describing these two. I recommend it reading-

https://barrgroup.com/Embedded-Systems/How-To/RTOS-Mutex-Semaphore

Now that you understand about RTOS, it’s concepts and how they are used in embedded systems. Next up is implementing it. I am going to use an RTOS kernel called FreeRTOS. We are going to develop some applications using that. This is it for this article, if you have any doubts or queries, feel free to ask it in the comment section. If you want to know more about RTOS refer this article

Leave a Comment

Your email address will not be published. Required fields are marked *

Share This
Scroll to Top