Download Embedded Multitasking with small - innovated

Transcript
Basic Embedded Programming Concepts 103
priority manager to set the system’s priorities. Such a complicated system
is seldom required in embedded programming, but some method for
shifting emphasis from one task to another is needed for the system to
adapt to the changing needs of the system.
Timing Control
The final requirement for real-time multitasking is timing control. It is
responsible for the timing of the task’s execution. Now, this may sound
like just a variation on the priority manager, and the timing control does
interact with the priority manager to do its job. But, while the priority
manager determines which tasks are next, it is the timing control that
determines the order of execution, setting when the task executes.
The distinction between the roles can be somewhat fuzzy. However,
the main point to remember is that the timing control determines when
a task is executed, and it is the priority control that determines if the
task is executed.
Balancing the requirements of the timing control and the priority
manager is seldom simple nor easy. After all, real-time systems often
have multiple asynchronous tasks, operating at different rates, interacting with each other and the asynchronous real world. However, careful
design and thorough testing can produce a system with a reasonable
balance between timing and priorities. In fact, much of the system-level
design in Chapters 3 and 4 will deal specifically with determining and
managing these often-conflicting requirements.
Operating Systems
To better understand the requirements of multitasking, let’s take a look
at how two different types of operating systems handle multitasking.
The two types of operating system are preemptive and cooperative. Both
utilize a context switcher to swap one task for another; the difference
is the event that triggers the context switch. A preemptive operating
system typically uses a timer-driven interrupt, which calls the context
switcher through the interrupt service routine. A cooperative operating
system relies on subroutine calls by the task to periodically invoke the
context switcher. Both systems employ the stack to capture and retrieve
the return address; it is just the method that differs. However, as we