Page 377 - ARM Based Microcontroller Projects Using MBED
P. 377

CHAPTER
                                                15







                              Mbed RTOS Projects









                                           15.1 OVERVIEW


              Real-time operating system (RTOS) is very powerful extension to the Mbed operating sys-
            tem as it allows multiple tasks to run on the processor. There are many applications such as
            the Internet of Things (IOT) where it may be required to run multiple tasks, usually indepen-
            dent of each other on the same processor. In this chapter we shall be looking at the basic prin-
            ciples of RTOS in general and then develop several projects using the Mbed RTOS functions.
            In a RTOS the processor responds to external events very fast and in an orderly manner,
            switching between different tasks as governed by the scheduling algorithm used.




                                      15.2 TASK SCHEDULING


              Tasks can be defined to be small self-contained codes that usually run independent of each
            other in a program. For example in a multidigit 7-segment display application it is required to
            refresh the display frequently. This process can be implemented as a task independent of the
            other codes running in the program. Another example may be, suppose that it is required to
            flash an LED every second in a program. At the same time it may be required to check the
            status of a push-button switch and take appropriate actions when the button is pressed. In
            such applications we can either use interrupts to process different tasks, or use a multitasking
            approach if the programming language that we are using supports it. In multitasking ap-
            proach the LED flashing code can run as an independent task and we can have another task
            to check the status of the button. Although the processor can execute only one task at any time,
            the scheduling algorithms used in multitasking operating systems switch between different
            tasks quickly so that it seems that different tasks execute at the same time.
              Scheduling is the fundamental concept in multitasking systems. Basically, there are two
            scheduling algorithms: nonpreemptive and preemptive. It is important to know the difference
            between the two algorithms and this is described briefly in the following subsections.




                                                   363
            ARM-based Microcontroller Projects Using mbed                # 2019 Elsevier Ltd. All rights reserved.
            https://doi.org/10.1016/B978-0-08-102969-5.00015-X
   372   373   374   375   376   377   378   379   380   381   382