11.07.2015 Views

IAR PowerPac RTOS User Guide

IAR PowerPac RTOS User Guide

IAR PowerPac RTOS User Guide

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

PRIORITY-CONTROLLED SCHEDULING ALGORITHMIn real-world applications, different tasks require different response times. For example, in an application that controlsa motor, a keyboard, and a display, the motor usually requires faster reaction time than the keyboard and display. Whilethe display is being updated, the motor needs to be controlled. This makes preemptive multitasking a must. Roundrobinmight work, but because it cannot guarantee a specific reaction time, an improved algorithm should be used.In priority-controlled scheduling, every task is assigned a priority. The order of execution depends on this priority. Therule is very simple:Note:The scheduler activates the task that has the highest priority of all tasks in the READY state.This means that every time a task with higher priority than the active task gets ready, it immediately becomes the activetask. However, the scheduler can be switched off in sections of a program where task switches are prohibited, knownas critical regions.<strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> uses a priority-controlled scheduling algorithm with round-robin between tasks of identicalpriority. One hint at this point: round-robin scheduling is a nice feature because you do not have to think about whetherone task is more important than another. Tasks with identical priority cannot block each other for longer than theirtimeslices. But round-robin scheduling also costs time if two or more tasks of identical priority are ready and no taskof higher priority is ready, because it will constantly switch between the identical-priority tasks. It is more efficient toassign a different priority to each task, which will avoid unnecessary task switches.PRIORITY INVERSIONThe rule to go by for the scheduler is:Activate the task that has the highest priority of all tasks in the READY state.But what happens if the highest-priority task is blocked because it is waiting for a resource owned by a lower-prioritytask? According to the above rule, it would wait until the low-priority-task becomes active again and releases theresource.The other rule is: No rule without exception.To avoid this kind of situation, the low-priority task that is blocking the highest-priority task gets assigned the highestpriority until it releases the resource, unblocking the task which originally had highest priority. This is known aspriority inversion.Communication between tasksIn a multitasking (multithreaded) program, multiple tasks work completely separately. Because they all work in thesame application, it will sometimes be necessary for them to exchange information with each other.GLOBAL VARIABLESThe easiest way to do this is by using global variables. In certain situations, it can make sense for tasks to communicatevia global variables, but most of the time this method has various disadvantages.For example, if you want to synchronize a task to start when the value of a global variable changes, you have to pollthis variable, wasting precious calculation time and power, and the reaction time depends on how often you poll.COMMUNICATION MECHANISMSWhen multiple tasks work with one another, they often have to:● exchange data,● synchronize with another task, or● make sure that a resource is used by no more than one task at a time.For these purposes <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> offers mailboxes, queues, semaphores and events.16<strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong>for ARM CoresPP<strong>RTOS</strong>-2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!