Page 96 - The Art of Designing Embedded Systems
P. 96

Real  Time Means Right Now!  83






























           ter programs faster, and the RTOS is probably the most important way to
           partition code in the time dimension.
                At its simplest level, an RTOS is a context switcher. You break your
           application into multiple tasks and allow the RTOS to execute the tasks in
           a manner determined by its scheduling algorithm. A round-robin scheduler
           typically allocates more or less fixed chunks of time to the tasks, execut-
           ing each one for a few milliseconds or so before suspending it and going
           to the next ready task in the queue. In this way all tasks get their fair shot
           at some CPU time.
                Another sort of scheduler is one using RMA-rate  monotonic analy-
           sis. If the CPU is not completely performance bound, it’s sometimes pos-
           sible to guarantee hard real-time response by giving each task a priority
           inversely proportional to the task’s period.
                Regardless  of  scheduling  mechanism,  all RTOSs include priority
           schemes so you can statically and dynamically cause the context switcher
           to allocate more or less time to tasks. Important or time-critical activities
           get first shot at running. Less important housekeeping tasks run only as
           time allows. Your code sets the priorities; the RTOS takes care of starting
           and running the tasks.
                If context switching were the only benefit of  an RTOS, then none
           would be more than a few hundred bytes in size. Novice users all too often
           miss the importance of the sophisticated messaging mechanisms that are a
           standard part of all commercial operating systems. Queues and mailboxes
           let tasks communicate safely.
   91   92   93   94   95   96   97   98   99   100   101