Page 259 - Embedded Microprocessor Systems Real World Design
P. 259
the FIFO buffer is not empty but blocked from doing anything because the output
interface is not ready for the next byte. The RTOSbased system software in this
case might deem the output task not ready (suspended) and replace it with a task
that checks for output ready. When the output is ready, the check-for-output-ready
task removes itself and deems the output task ready. Of course, this makes sense
only if the output checker task takes less time to execute than the normal output
task takes to check for output ready or if suspending the output task frees up the
output interface for another device to use. The output device might be ready for
one kind of data but not ready for another, so it can be used by another process
instead of sitting idle.
Once given control, a task may run until it is finished or until it finds that it
cannot execute further, like the output task condition just mentioned. In either
case, the task transfers control back to the RTOS, which then passes control to the
next task in sequence. In this respect, the RTOSbased system is like any sequential
execution system, with the added ability to remove tasks from the sequence of
execution. When a task is activated, the priority may be set at the same time,
depending on the specific RTOS used.
Event-Driven Scheduling
The practice of adding and removing tasks from the task list based on changing
circumstances is called event-driven scheduling and, with preemptive scheduling, is
the method used in many, if not most, RTOSbased systems. Preemptive schedul-
ing more closely models the real world; you might plan to go to work today, but a
fender bender on the way will change your priorities, at least until the police report
is finished, Once you get to work, you might have scheduled a project meeting, but
an emergency staff meeting called by your boss takes priority.
In a preemptive, event-driven system, an event such as an interrupt or a task may
determine that some other task needs to be activated. It may do this, for example,
by setting a semaphore or placing data in a mailbox. The task, which was previously
set up to be activated by the RTOS when this event occurred, is activated if it has
a higher priority than the current task. If the protocol converter were preemptively
scheduled, the priority might look like this:
Receive processing (highest priority)
XOFF processing
XON processing
Output processing (lowest priority)
A single interrupt, generated by a byte in the serial input register, might drive
the system. The receive task might ask to be activated when a particular semaphore
240 Embedded Microprocessor Systems