Transitioning from bare-metal (front-back architecture) software development to using a Real-Time Operating System (RTOS) can be a challenging task. However, there are many advantages to using an RTOS, such as simplifying application integration and supporting task preemption scheduling. This becomes meaningful when developers use complex 32-bit microcontrollers and have sufficient Flash and RAM space. Many 32-bit applications require the use of USB, TCP/IP, and file systems, which are very difficult to develop in bare-metal applications, and most third-party middleware is designed to integrate seamlessly with RTOS.1. Time-Slice Round-Robin Scheduling The implementation of front-back systems is usually based on polling scheduling techniques, which is a very natural way to write software; you simply add new code to the super loop, equivalent to adding a new task. The polling scheduling strategy in RTOS allows multiple tasks to be assigned the same priority level. The scheduler monitors task time based on the clock, and tasks at the relevant priority are executed according to the first-come, first-served principle, where once the allocated time slice is up, even if the current task is not completed, the task will pass CPU time to the next task. In the next allocated time period, that task will continue executing from where it stopped. Common RTOS, such as μC/OS-III (Cs/OS3) and FreeRTOS, support time-slice round-robin algorithms. In FreeRTOS, the time slice length for each task is fixed at one time tick; while in μC/OS-III, the time slice length for each task can be variable and specified at task creation.2. Priority-Based Cooperative Scheduling In RTOS, cooperative scheduling is a non-preemptive scheduling method based on priority. Tasks are sorted by priority and are event-driven; once the running task completes, or the task actively calls OS services to relinquish the CPU, only the highest-priority ready task can gain CPU access.
3. Preemptive Scheduling RTOS ensures real-time performance through preemptive scheduling. To guarantee task responsiveness, in the preemptive scheduling strategy, as soon as a higher-priority task is ready, the currently running lower-priority task will be switched out. Through preemption, the running task is forced to relinquish the processor, even if the task has not completed its work.
RTOS can typically be configured to use many deterministic scheduling algorithms to ensure that task deadlines are met. For example, FreeRTOS and μC/OS-III support both preemptive and time-slice round-robin scheduling methods.4. Conclusion RTOS is a powerful tool for embedded software developers. In RTOS applications, each task has its own task control block, which contains parameters such as stack, priority, and ID. Each task can be viewed as a separate application. RTOS also provides a variety of synchronization and communication tools, such as semaphores, mutexes, and message queues, simplifying application development. However, task switching consumes CPU time; even on 32-bit processors, RTOS can incur time losses. Task switching takes more time than interrupts. If it is a very small application but needs to make full use of processor resources, in this case, the feasibility of RTOS needs to be carefully considered. Each scheduling algorithm has its pros and cons, and understanding commonly used RTOS scheduling algorithms can help us make appropriate choices.
END
Source: Micron TechnologyCopyright belongs to the original author. If there is any infringement, please contact for deletion.▍Recommended ReadingThe Highest Realm of Anonymous in C LanguageWhat Aspects of Microcontrollers Cannot Replace PLCs?Words Most Easily Misread by Programmers, I Exploded When I Heard Status
→ Follow for more updates ←