Motorola MCP750 Specifications Page 176

  • Download
  • Add to my manuals
  • Print
  • Page
    / 344
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 175
D
evice Driver Programming
11-2
Linked lists, state fields, and other data structures used by the driver
Global variables
Hardware registers
As indicated in the previous section, the mechanisms that can be used are spin locks, sleep
locks, and synchronization variables.
When multithreading a driver, the first step is to check the areas of the program level code
that raise IPL. These areas are protecting device driver structures from being corrupted by
program level/interrupt level interactions. A driver's program-level code can, for example,
be adding a message to a queue while its interrupt-level code is attempting to remove a
message from the same queue. The program-level code might be similar to the following:
message_qp = message_Q;
message_qp->next = new_message_p;
The interrupt-level code might be similar to the following:
message_qp = message_Q;
message_Q = message_qp->next;
If an interrupt occurs between the two lines of code at program level and then the two lines
of code are executed at interrupt level, the new message added at program level is lost. To
prevent this problem from occurring, the queue structures can be protected by using the
LOCK and UNLOCK facilities (see the “Spin Locks” section, p. 11-5). The program-level
code can be changed as follows:
old_ipl = LOCK(Q_lock, plhi);
message_qp = message_Q;
message_qp->next = new_message_p;
UNLOCK(Q_lock, old_ipl);
The interrupt-level code can be changed as follows:
old_ipl = LOCK(Q_lock, plhi);
message_qp = message_Q;
message_Q = message_qp->next;
UNLOCK(Q_lock, old_ipl);
By using the spin locks, you protect program level from interrupt level and interrupt level
from program level.
Any areas of code that raise the IPL to protect code must be protected via a spin lock. The
spin lock must be locked at both program and interrupt level. Simply raising the IPL is not
good enough protection because raising the IPL does not prevent an interrupt from occur-
ring on another CPU.
The next step in multithreading a driver is to look at the data structures that the driver uses.
The most common data structures that need coordination are linked lists and state fields.
Any time items are added or removed from linked lists the operation must be protected.
State fields are often bit fields that are set to indicate a current condition in the driver. The
setting and resetting of these bits is often done because of asynchronous events. Changes
to these state fields must be protected as well as checks on the state field. If the execution
Page view 175
1 2 ... 171 172 173 174 175 176 177 178 179 180 181 ... 343 344

Comments to this Manuals

No comments