THE 80386 AND 80486 MICROPROCESSORS:SPECIAL 80386 REGISTERS.

SPECIAL 80386 REGISTERS

A new series of registers, not found in earlier Intel microprocessors, appears in the 80386 as control, debug, and test registers. Control registers CR0–CR3 control various features, DR0–DR7 facilitate debugging, and registers TR6 and TR7 are used to test paging and caching.

Control Registers

In addition to the EFLAGS and EIP as described earlier, there are other control registers found in the 80386. Control register 0 (CR0) is identical to the MSW (machine status word) found in the 80286 microprocessor, except that it is 32 bits wide instead of 16 bits wide. Additional control registers are CR1, CR2, and CR3.

Figure 17–14 illustrates the control register structure of the 80386. Control register CR1 is not used in the 80386, but is reserved for future products. Control register CR2 holds the linear page address of the last page accessed before a page fault interrupt. Finally, control register CR3 holds the base address of the page directory. The rightmost 12 bits of the 32-bit page table address contain zeros and combine with the remainder of the register to locate the start of the 4K- long page table.

The 80186, 80188, and 80286 Microprocessors-0426

Register CR0 contains a number of special control bits that are defined as follows in the 80386:

PG Selects page table translation of linear addresses into physical addresses when PG = 1. Page table translation allows any linear address to be assigned any physical memory location.

ET Selects the 80287 coprocessor when ET 0 or the 80387 coprocessor when ET l.

This bit was installed because there was no 80387 available when the 80386 first appeared. In most systems, ET is set to indicate that an 80387 is present in the system.

TS Indicates that the 80386 has switched tasks (in protected mode, changing the con- tents of TR places a 1 into TS). If TS 1, a numeric coprocessor instruction causes a type 7 (coprocessor not available) interrupt.

EM The emulate bit is set to cause a type 7 interrupt for each ESC instruction. (ESCape instructions are used to encode instructions for the 80387 coprocessor.) Once this feature was used to emulate interrupts with software, the function of the coprocessor. Emulation reduces the system cost, but it often requires at least 100 times longer to execute the emulated coprocessor instructions.

MP Is set to indicate that the arithmetic coprocessor is present in the system.

PE Is set to select the protected mode of operation for the 80386. It may also be cleared to reenter the real mode. This bit can only be set in the 80286. The 80286 could not return to real mode without a hardware reset, which precludes its use in most systems that use protected mode.

Debug and Test Registers

Figure 17–15 shows the sets of debug and test registers. The first four debug registers contain 32- bit linear breakpoint addresses. (A linear address is a 32-bit address generated by a microprocessor instruction that may or may not be the same as the physical address.) The breakpoint addresses, which may locate an instruction or datum, are constantly compared with the addresses generated by the program. If a match occurs, the 80386 will cause a type 1 interrupt (TRAP or

The 80186, 80188, and 80286 Microprocessors-0427

debug interrupt) to occur, if directed by debug registers DR6 and DR7. This feature is a much- expanded version of the basic trapping or tracing allowed with the earlier Intel microprocessors through the type 1 interrupt. The breakpoint addresses are very useful in debugging faulty soft- ware. The control bits in DR6 and DR7 are defined as follows:

BT If set (1), the debug interrupt was caused by a task switch.

BS If set, the debug interrupt was caused by the TF bit in the flag register.

BD If set, the debug interrupt was caused by an attempt to read the debug register with the GD bit set. The GD bit protects access to the debug registers.

B3–B0 Indicate which of the four debug breakpoint addresses caused the debug interrupt.

LEN Each of the four length fields pertains to each of the four breakpoint addresses

stored in DR0–DR3. These bits further define the size of access at the breakpoint address as 00 (byte), 01 (word), or 11 (doubleword).

RW Each of the four read/write fields pertains to each of the four breakpoint addresses stored in DR0–DR3. The RW field selects the cause of action that enabled a break- point address as 00 (instruction access), 01 (data write), and 11 (data read and write).

GD If set, GD prevents any read or write of a debug register by generating the debug interrupt. This bit is automatically cleared during the debug interrupt so that the debug registers can be read or changed, if needed.

GE If set, selects a global breakpoint address for any of the four breakpoint address registers.

LE If set, selects a local breakpoint address for any of the four breakpoint address registers.

The test registers, TR6 and TR7, are used to test the translation look-aside buffer (TLB). The TLB is used with the paging unit within the 80386. The TLB, which holds the most com- monly used page table address translations, reduces the number of memory reads required for looking up page translation addresses in the page translation tables. The TLB holds the most common 32 entries from the page table, and it is tested with the TR6 and TR7 test registers.

Test register TR6 holds the tag field (linear address) of the TLB, and TR7 holds the physi- cal address of the TLB. To write a TLB entry, perform the following steps:

1. Write TR7 for the desired physical address, PL, and REP values.

2. Write TR6 with the linear address, making sure that C = 0.

To read a TLB entry:

1. Write TR6 with the linear address, making sure that C = 1.

2. Read both TR6 and TR7. If the PL bit indicates a hit, then the desired values of TR6 and TR7

indicate the contents of the TLB.

The bits found in TR6 and TR7 indicate the following conditions:

V Shows that the entry in the TLB is valid.

D Indicates that the entry in the TLB is invalid or dirty.

U A bit for the TLB.

W Indicates that the area addressed by the TLB entry is writable.

C Selects a write (0) or immediate lookup (1) for the TLB.

PL Indicates a hit if a logic 1.

REP Selects which block of the TLB is written.

Refer to the section on memory management and the paging unit for more detail on the function of the TLB.

 

QUESTIONS AND PROBLEMS ON THE 80186, 80188, AND 80286 MICROPROCESSORS.

QUESTIONS AND PROBLEMS

1. List the differences between the 8086/8088 and the 80186/80188 microprocessors.

2. What hardware enhancements are added to the 80186/80188 that are not present in the 8086/8088?

3. The 80186/80188 is packaged in what types of integrated circuits?

4. If the 20 MHz crystal is connected to Xl and X2, what frequency signal is found at CLKOUT?

5. Describe the differences between the 80C188XL and the 80C188EB versions of the 80188 embedded controller.

6. The fan-out from any 80186/80188 pin is for a logic 0.

7. How many clocking periods are found in an 80186/80188 bus cycle?

8. What is the main difference between the 8086/8088 and 80186/80188 timing?

9. What is the importance of memory access time?

10. How much memory access time is allowed by the 80186/80188 if operated with a 10 MHz clock?

11. Where is the peripheral control block located after the 80186/80188 is reset?

12. Write the software required to move the peripheral control block to memory locations 10000H–100FFH.

13. Which interrupt vector is used by the INT0 pin on the 80186/80188 microprocessors?

14. How many interrupt vectors are available to the interrupt controller located within the

80186/80188 microprocessors?

15. Which two modes of operation are available to the interrupt controller?

16. What is the purpose of the interrupt control register?

17. Whenever an interrupt source is masked, the mask bit in the interrupt mask register is a logic.

18. What is the difference between the interrupt poll and interrupt poll status registers?

19. What is the purpose of the end-of-interrupt (EOI) register?

20. How many 16-bit timers are found within the 80186/80188?

21. Which timers have input and output pin connections?

22. Which timer connects to the system clock?

23. If two maximum-count compare registers are used with a timer, explain the operation of the timer.

24. What is the purpose of the INH timer control register bit?

25. What is the purpose of the P timer control register bit?

26. The timer control register bit ALT selects what type of operation for timers 0 and 1?

27. Explain how the timer output pins are used.

28. Develop a program that causes timer 1 to generate a continuous signal that is a logic 1 for 123 counts and a logic 0 for 23 counts.

29. Develop a program that causes timer 0 to generate a single pulse after 105 clock pulses on its input pin have occurred.

30. How many DMA channels are controlled by the DMA controller in the 80C186XL?

31. The DMA controller’s source and destination registers are each – bits wide.

32. How is the DMA channel started with software?

33. The chip selection unit (XL and EA) has pins to select memory devices.

34. The chip selection unit (XL and EA) has pins to select peripheral devices.

35. The last location of the upper memory block, as selected by the UCS pin, is location.

36. The middle memory chip selection pins (XL and EA) are programmed for a(n)

size and a block size.

37. The lower memory area, as selected by LCS, begins at address .

38. The internal wait state generator (EB and EC versions) is capable of inserting between zero and wait states.

39. Program register A8H (XL and EA) so that the mid-range memory block size is 128K bytes and a chip size of 32K.

40. What is the purpose of the EX bit in register A8H?

41. Develop the software required to program the GCS3 pin so that it selects memory from locations 20000H–2FFFFH and inserts two wait states.

42. Develop the software required to program the GCS4 pin so that it selects an I/O device for ports 1000H–103FH and inserts one wait state.

43. The 80286 microprocessor addresses bytes of physical memory.

44. When the memory manager is in use, the 80286 addresses bytes of virtual memory.

45. The instruction set of the 80286 is identical to the , except for the memory- management instructions.

46. What is the purpose of the VERR instruction?

47. What is the purpose of the LSL instruction?

48. What is an RTOS?

49. How are multiple threads handled with the RTOS?

50. Search the Internet for at least two different RTOSs and write a short report comparing them.

 

SUMMARY OF THE 80186, 80188, AND 80286 MICROPROCESSORS.

SUMMARY

1. The 80186/80188 microprocessors contain the same basic instruction set as the 8086/8088 microprocessors, except that a few additional instructions are added. The 80186/80188 are thus enhanced versions of the 8086/8088 microprocessors. The new instructions include PUSHA, POPA, INS, OUTS, BOUND, ENTER, LEAVE, and immediate multiplication and shift/rotate counts.

2. Hardware enhancements to the 80186/80188 include a clock generator, a programmable interrupt controller, three programmable timers, a programmable DMA controller, a programmable chip selection logic unit, a watchdog timer, a dynamic RAM refresh logic circuit, and additional features on various versions.

3. The clock generator allows the 80186/80188 to operate from an external TTL-level clock source, or from a crystal attached to the X1 (CLKIN) and X2 (OSCOUT) pins. The frequency

of the crystal is twice the operating frequency of the microprocessor. The 80186/80188

microprocessors are available in speeds of 6 to 20 MHz.

4. The programmable interrupt controller arbitrates all internal and external interrupt requests.

It is also capable of operating with two external 8259A interrupt controllers.

5. Three programmable timers are located within the 80186/80188. Each timer is a fully programmable, 16-bit counter used to generate wave-forms or count events. Two of the timers, timers 0 and 1, have external inputs and outputs. The third timer, timer 2, is clocked from the system clock and is used either to provide a clock for another timer or to request a DMA action.

6. The programmable DMA controller is a fully programmable, two-channel controller. DMA transfers are made between memory and I/O, I/O and I/O, or between memory locations. DMA requests occur from software, hardware, or the output of timer 2.

7. The programmable chip selection unit is an internal decoder that provides up to 13 output pins to select memory (6 pins) and I/O (7 pins). It also inserts 0 to 3 wait states, with or with-

out external READY synchronization. On the EB and EC versions, the number of waits can be programmed from 0 to 15 and 10 chip selection pins.

8. The only difference between the timing of the 80186/80188 and the 8086/8088 is that ALE appears one-half clock pulse earlier. Otherwise, the timing is identical.

9. The 6 MHz version of the 80186/80188 allows 417 ns of access time for the memory; the 8 MHz version allows 309 ns of access time.

10. The interna180186/80188 peripherals are programmed via a peripheral control block (PCB), initialized at I/O ports FF00H–FFFFH. The PCB may be moved to any area of memory or I/O by changing the contents of the PCB relocation register at initial I/O location FFFEH and FFFFH.

11. The 80286 is an 8086 that has been enhanced to include a memory-management unit (MMU). The 80286 is capable of addressing a 16M-byte physical memory space because of the management unit.

12. The 80286 contains the same instructions as the 80186/80188, except for a handful of additional instructions that control the memory-management unit.

13. Through the memory-management unit, the 80286 microprocessor addresses a virtual memory space of 1G bytes, as specified by the 16K descriptors stored in two descriptor tables.

 

THE 80186, 80188, AND 80286 MICROPROCESSORS:INTRODUCTION TO THE 80286.

INTRODUCTION TO THE 80286

The 80286 microprocessor is an advanced version of the 8086 microprocessor that was designed for multiuser and multitasking environments. The 80286 addresses 16M bytes of physical memory and 1G bytes of virtual memory by using its memory-management system. This section of the text introduces the 80286 microprocessor, which finds use in earlier AT-style personal computers that once pervaded the computer market and still find some applications. The 80286 is basically an 8086 that is optimized to execute instructions in fewer clocking periods than the 8086. The 80286 is also an enhanced version of the 8086 because it contains a memory manager. At this time, the 80286 no longer has a place in the personal computer system, but it does find applications in control systems as an embedded controller.

Hardware Features

Figure 16–29 shows the internal block diagram of the 80286 microprocessor. Note that like the 80186/80188, the 80286 does not incorporate internal peripherals; instead, it contains a memory- management unit (MMU) that is called the address unit in the block diagram.

The 80186, 80188, and 80286 Microprocessors-0410

The 80186, 80188, and 80286 Microprocessors-0411

As mentioned in Chapter 1, the 80286 operates in both the real and protected modes. In the real mode, the 80286 addresses a 1M-byte memory address space and is virtually identical to the 8086. In the protected mode, the 80286 addresses a 16M-byte memory space.

Figure 16–31 illustrates the basic 80286 microprocessor-based system. Notice that the clock is provided by the 82284 clock generator (similar to the 8284A) and the system control signals are provided by the 82288 system bus controller (similar to the 8288). Also, note the absence of the latch circuits used to demultiplex the 8086 address/data bus.

Additional Instructions

The 80286 has even more instructions than its predecessors. These extra instructions control the virtual memory system through the memory manager of the 80286. Table 16–9 lists the additional 80286 instructions with a comment about the purpose of each instruction. These instructions are the only new instructions added to the 80286. Note that the 80286 contains the new instructions added to the 80186/80188 such as INS, OUTS, BOUND, ENTER, LEAVE, PUSHA, POPA, and the immediate multiplication and immediate shift and rotate counts.

The 80186, 80188, and 80286 Microprocessors-0412

Following are descriptions of instructions not explained in the memory-management section. The instructions described here are special and only used for the conditions indicated.

CLTS The clear task-switched flag (CLTS) instruction clears the TS (task-switched) flag bit to a logic 0. If the TS flag bit is a logic 1 and the 80287 numeric coprocessor is used by the task, an interrupt occurs (vector type 7). This allows the function of the coprocessor to be emulated with software. The CLTS instruction is used in a system and is considered a privileged instruction because it can be executed only in the protected mode at privilege level 0. There is no set TS flag instruction; this is accomplished by writing a logic 1 to bit position 3 (TS) of the machine status word (MSW) by using the LMSW instruction.

LAR The load access rights (LAR) instruction reads the segment descriptor and places a copy of the access rights byte into a 16-bit register. An example is the LAR AX,BX instruction that loads AX with the access rights byte from the descriptor selected by the selector value found in BX. This instruction is used to get the access rights so that it can be checked before a program uses the segment of memory described by the descriptor.

LSL The load segment limit (LSL) instruction loads a user-specified register with the segment limit. For example, the LSL AX,BX instruction loads AX with the limit of the segment described by the descriptor selected by the selector in BX. This instruction is used to test the limit of a segment.

ARPL The adjust requested privilege level (ARPL) instruction is used to test a selector so that the privilege level of the requested selector is not violated. An example is ARPL AX,CX: AX contains the requested privilege level and CX contains the selector value to be used to access a descriptor. If the requested privilege level is of a lower priority than the descriptor under test, the zero flag is set. This may require that a program adjust the requested privilege level or indicate a privilege violation.

VERR The verify for read access (VERR) instruction verifies that a segment can be read.

Recall from Chapter 1 that a code segment can be read-protected. If the code segment can be read, the zero flag bit is set. The VERR AX instruction tests the descriptor selected by the AX register.

VERW The verify for write access (VERW) instruction is used to verify that a segment can be written. Recall from Chapter 1 that a data segment can be write-protected. If the data segment can be written, the zero flag bit is set.

The Virtual Memory Machine

A virtual memory machine is a machine that maps a larger memory space (1G bytes for the 80286) into a much smaller physical memory space (l6M bytes for the 80286), which allows a very large system to execute in smaller physical memory systems. This is accomplished by spooling the data and programs between the fixed disk memory system and the physical memory. Addressing a 1G-byte memory system is accomplished by the descriptors in the 80286 micro- processor. Each 80286 descriptor describes a 64K-byte memory segment and the 80286 allows 16K descriptors. This (64K × 16K) allows a maximum of 1G bytes of memory to be described for the system.

As mentioned in Chapter 1, descriptors describe the memory segment in the protected mode. The 80286 has descriptors that define codes, data, stack segments, interrupts, procedures, and tasks. Descriptor accesses are performed by loading a segment register with a selector in the protected mode. The selector accesses a descriptor that describes an area of the memory. Additional details on descriptors and their applications are defined in Chapter 1, and also Chapters 17, 18, and 19. Please refer to these chapters for a detailed view of the protected mode memory-management system.

 

THE 80186, 80188, AND 80286 MICROPROCESSORS:REAL-TIME OPERATING SYSTEMS (RTOS).

REAL-TIME OPERATING SYSTEMS (RTOS)

This section of the text describes the real-time operating system (RTOS). Interrupts are used to develop RTOSs because they are used in embedded applications of the microprocessor. All systems, from the simplest embedded application the most sophisticated system, must have an operating system.

What Is a Real-Time Operating System (RTOS)?

The RTOS is an operating system used in embedded applications that performs tasks in a predictable amount of time. Operating systems, like Windows, defer many tasks and do not guarantee their execution in a predictable time. The RTOS is much like any other operating system in that it contains the same basic sections. Figure 16–26 illustrates the basic structure of an operating system as it might be placed on an EPROM or flash memory device.

The 80186, 80188, and 80286 Microprocessors-0401

There are three components to all operating systems: (1) initialization, (2) the kernel, (3) data and procedures. If Example 16–5 (last section) is compared to the Figure 16–26, all three sections will be seen. The initialization section is used to program all hardware components in the system, load drivers specific to a system, and program the contents of the microprocessor’s registers. The kernel performs the basic system task, provides system calls or functions, and comprises the embedded system. The data and procedure section holds all procedures and any static data used by the operating system.

The RESET Section. The last part of the software in Example 16–5 shows the reset block of the RTOS. The ORG statement places the reset instructions at a location that is 16 bytes from the end of the memory device. In this case the EPROM is 32K bytes, which means it begins at 0000H and ends at 7FFFH. Recall that a 32K device has 15 address pins. The CS input selects the EPROM for location F8000H through FFFFFH in the system. The ORG statement in the pro- gram places the origin of the reset section at location 80F0H because all tiny model (.COM) pro- grams are assembled from offset address 100H even though the first byte of the program is the first byte stored in the file. Because of this bias, all the addresses on the EPROM must be adjusted by 100H as is the ORG statement.

clip_image003Only 16 bytes of memory exist for the reset instruction because the reset location is FFFF0H in the system. In this example there is only enough room to program the UCS starting address as F8000H before a jump to the start of the EPROM. Far jumps are not allowed in the tiny model, so it was forced by storing the actual hexadecimal opcode for a far jump (EAH).

Initialization Section. The initialization section of Example 16–5 begins in the reset block and continues at the start of the EPROM. If the initialization section is viewed, all of the programma- ble devices in the system are programmed and the segment registers are loaded. The initialization section also programs timer 2 so it causes an interrupt to the TIM2 procedure each millisecond. The TIM2 interrupt service procedure updates the clock once per second and is also the basis of precision time delays in the software.

The Kernel. The kernel in Example 16–5 is very short, because the system is incomplete and serves only as a test system. In this example all that the system does is display a sign-on message and display the time of day on the second line of the LCD. Once this is accomplished, the system ends at an infinite WHILE loop. All system programs are infinite loops unless they crash.

An Example System

Figure 16–27 illustrates a simple embedded system based on the 80188EB embedded micro- processor. This schematic depicts only the parts added to Figure 16–25 in order to read a temper- ature from the LM-70. This system contains a 2-line × 16 character-per-line LCD display that shows the time of day and the temperature. The system itself is stored on a small 32K × 8 EPROM. A 32K × 8 SRAM is included to act as a stack and store the time. A database holds the most recent temperatures and the times at which the temperatures were obtained.

The 80186, 80188, and 80286 Microprocessors-0402

The temperature sensor is located inside the LM70 digital temperature sensor manufactured by National Semiconductor Corporation for less than $1.00. The interface to the microprocessor is in serial format, and the converter has a resolution of 10 bits plus a sign bit. Figure 16–28 illustrates the pin-out of the LM70 temperature sensor.

The LM70 transfers data to and from the microprocessor through the SIO pin, which is a bidirectional serial data pin. Information is clocked through the SIO pin by the SC (clock) pin. The LM70 contains three 16-bit registers: the configuration register, the temperature sensor register, and the identification register. The configuration register selects either the shutdown mode (XXFFH) or continuous conversion mode (XX00). The temperature register contains the signed temperature in the leftmost 11 bits of the 16-bit data word. If the temperature is negative, it is in their respective complement forms. The identification register presents an 8100 when it is read.

When the temperature is read from the LM70, it is read in Celsius and each step is equal to 0.25°C. For example, if the temperature register is 0000 1100 100X XXXX or a value of 100 decimal, the temperature is 25.0°C.

Example 16–6 illustrates the software added to the operating system listed in Example 16–5. The system samples the temperatures once per minute and stores them in a circular queue along with the day and the time in hours and minutes. The day is a number that starts at zero when the system is initialized. The size of the queue has been set to 16K bytes, so the most recent 4,096 measurements can be stored. In this example the keyboard is not used, but some of the system calls are used to display the temperature on line 1 of the display. The real-time clock is also interrogated to determine the start of each minute so a sample can occur. The software in the listing replaces the software section in Example 16–5 where it states, “;System software placed here”. This software replaces the infinite WHILE loop in the example.

The LM70 is initialized by output 16 bits of 0s to it and then read by reading all 16 bits of the temperature. The reading of the LM70 is accomplished in the software by the TEMP procedure and initialization is by the INITT procedure.

The 80186, 80188, and 80286 Microprocessors-0403The 80186, 80188, and 80286 Microprocessors-0404

A Threaded System

At times an operating system is needed that can process multiple threads. Multiple threads are handled by the kernel using a real-time clock interrupt. One method for scheduling processes in a small RTOS is to use a time slice to switch between various processes. The basic time slice can be any duration and is somewhat dependent on the execution speed of the microprocessor. For example, in a system using a 100 MHz clock, many instructions will execute in one or two clocks on a modem microprocessor. Assuming the machine executes one instruction every two clocks and a time slice of 1 ms is chosen, the machine can execute about 50,000 instructions one time slice, which should be adequate for most systems. If a lower clock frequency is employed, then a time slice of 10 ms or even 100 ms is selected.

Each time slice is activated by a timer interrupt. The interrupt service procedure must look to the queue to determine if a task is available to execute, and if it is, it must start execution of the new task. If no new task is present, it must continue executing old tasks or enter an idle state and wait for a new task to be queued. The queue is circular and may contain any number of tasks for the system up to some finite limit. For example, it might be a small queue in a small system with 10 entries. The size is determined by the intended overall system needs and could be made larger or smaller.

Each scheduling queue entry must contain a pointer to the process (CS:IP) and the entire context state of the machine. Scheduling queue entries may also contain some form of a time-to- live entry in case of a deadlock, a priority entry, and an entry that can lengthen the slice activation time. In the following example, a priority entry or an entry to lengthen the amount of consecutive time slices allowed a program will not be used. The kernel will service processes strictly on a linear basis or on a round-robin fashion as they come from the queue.

To implement a scheduler for the embedded system, procedures, or macros, are implemented to start a new application, kill an application when it completes, and pause an application if it needs time to access I/O. Each of these macros accesses a scheduling queue located in the memory system at an available address such as 0500H. The scheduling queue uses the data structure in Example 16–7 to make creating the queue fairly easy, and it will have room for 10 entries. This scheduling queue allows us to start up to 10 processes at a time.

The 80186, 80188, and 80286 Microprocessors-0405

The data structure of Example 16–7 is copied into memory 10 times to complete the queue structure during system initialization; hence, it contains no active process at initialization. We also need a queue pointer initialized to 500H. The queue pointer is stored at location 4FEH in this example. Example 16–8 provides one possible initialization. This stores the data structure in the RAM with 10 copies beginning at 500H. This software assumes that a system clock of 32 MHz operates timer 2 used as a prescalar to divide the clock input (system clock divided by 8) of 4 MHz by 40,000. This causes the output of timer 2 to be 1 KHz (1.0 ms). Timer 1 is programmed to divide the timer 2 clock signal by 10 to generate an interrupt every 10 ms.

The 80186, 80188, and 80286 Microprocessors-0406

The NEW procedure (installed at INT 60H in Example 16–9) adds a process to the queue. It searches through the 10 entries until it finds a zero in the first byte (PRESENT), which indicates

that the entry is empty. If it finds an empty entry, it places the starting address of the process into RCS and RIP and a 0200H into the RFLAG location. A 200H in RFLAG makes sure that the interrupt is enabled when the process begins, which prevents the system from crashing. The NEW procedure waits, if 10 processes are already scheduled, until a process ends. Each process is also assigned stack space in 256-byte sections beginning at offset address 7600H, so the lowest process has stack space 7500H–75FFH, the next has stack space 7600H–76FFH, and so on. The assignment of a stack area could be allocated by a memory manager algorithm.

The 80186, 80188, and 80286 Microprocessors-0407

The PAUSE procedure is merely a call to the time slice procedure (INT 12H) that bails out of the process and returns control to the time slice procedure, prematurely ending the time slice for the process. This early out allows other processes to continue before returning to the current process.

The time slice interrupt service procedure for an 80188EB using a 10 ms time slice appears in Example 16–11. Because this is an interrupt service procedure, care has been taken to make it as efficient as possible. Example 16–11 illustrates the time slice procedure located at interrupt vector 12H for operation with timer 1 in the 80188EB microprocessor. Although not shown, this software assumes that timer 2 is used as a prescalar and timer 1 uses the signal from timer 2 to generate the 10 ms interrupt. The software also assumes that no other interrupt is in use in the system.

The 80186, 80188, and 80286 Microprocessors-0408The 80186, 80188, and 80286 Microprocessors-0409

 

THE 80186, 80188, AND 80286 MICROPROCESSORS:80C188EB EXAMPLE INTERFACE.

80C188EB EXAMPLE INTERFACE

Because the 80186/80188 microprocessors are designed as embedded controllers, this section of the text provides an example of such an application. The example illustrates simple memory and I/O attached to the 80C188EB microprocessor. It also lists the software required to program the 80C188EB and its internal registers after a system reset. Figure 16–24 illustrates the pin-out of the 80C188EB version of the 80188 microprocessor. Notice the differences between this version and the XL version presented earlier in the text.

The 80C188EB version contains some new features that were not present on earlier versions. These features include two I/O ports (P1 and P2) that are shared with other functions and two serial communications interfaces that are built into the processor. This version does not contain a DMA controller, as did the XL version.

The 80188EB can be interfaced with a small system designed to be used as a microprocessor trainer. The trainer illustrated in this text uses a 27256 EPROM for program storage, a 62256 SRAM for data storage, and an 8255 for a keyboard and LCD display interface. Figure 16–25 illustrates a small microprocessor trainer that is based on the 80C188EB microprocessor.

The 80186, 80188, and 80286 Microprocessors-0393

Memory is selected by the UCS pin for the 27C256 EPROM and the LCS pin for the 62256 SRAM; the GCS0 pin selects the 8255. The system software places the EPROM at memory addresses F8000H–FFFFFH; the SRAM at 00000H–07FFFH; and the 8255 at I/O ports 0000H–003FH (software uses ports 0, 1, 2, and 3). In this system, as is normally the case, we do not modify the address of the peripheral control block, which resides at I/O ports FF00H–FFFFH. Example 16–5 lists the software required to initialize the 80C188EB microprocessor. This example completely programs the 80C188EB and also the entire system. The software is discussed in the next section of this chapter.

The 80186, 80188, and 80286 Microprocessors-0394The 80186, 80188, and 80286 Microprocessors-0395The 80186, 80188, and 80286 Microprocessors-0396The 80186, 80188, and 80286 Microprocessors-0397The 80186, 80188, and 80286 Microprocessors-0398The 80186, 80188, and 80286 Microprocessors-0399The 80186, 80188, and 80286 Microprocessors-0400

 

THE 80186, 80188, AND 80286 MICROPROCESSORS:PROGRAMMING THE 80186/80188 ENHANCEMENTS.

PROGRAMMING THE 80186/80188 ENHANCEMENTS

This section provides detail on the programming and operation of the 80186/80188 enhancements of all versions (XL, EA, EB, and EC). The next section details the use of the 80C188EB in a system that uses many of the enhancements discussed here. The only new feature not discussed here is the clock generator, which is described in the previous section on architecture.

Peripheral Control Block

All internal peripherals are controlled by a set of 16-bit-wide registers located in the peripheral control block (PCB). The PCB (see Figure 16–6) is a set of 256 registers located in the I/O or memory space. Note that this set applies to the XL and EA versions. Later in this section, the EB and EC versions of the PCB are defined and described.

Whenever the 80186/80188 is reset, the peripheral control block is automatically located at the top of the I/O map (I/O addresses FF00H–FFFFH). In most cases, it stays in this area of I/O space, but the PCB may be relocated at any time to any other area of memory or I/O. Relocation is accomplished by changing the contents of the relocation register (see Figure 16–7) located at offset addresses FEH and FFH.

The relocation register is set to 20FFH when the 80186/80188 is reset. This locates the PCB at I/O addresses FF00H–FFFFH afterwards. To relocate the PCB, the user need only send a word OUT to I/O address FFFEH with a new bit pattern. For example, to relocate the PCB to

The 80186, 80188, and 80286 Microprocessors-0368The 80186, 80188, and 80286 Microprocessors-0369

memory locations 20000H–200FFH, send 1200H to I/O address FFFEH. Notice that M>IO is a logic 1 to select memory, and that 200H selects memory address 20000H as the base address of the PCB. Note that all accesses to the PCB must be word accesses because it is organized as 16-bit-wide registers. Example 16–1 shows the software required to relocate the PCB to memory locations 20000H–200FFH. Note that either an 8- or 16-bit output can be used to program the 80186; in the 80188, never use the OUT DX,AX instruction because it takes additional clocking periods to execute.

The 80186, 80188, and 80286 Microprocessors-0370

The EB and EC versions use a different address for programming the PCB location. Both versions have the PCB relocation register stored at offset XXA8H, instead of at offset XXFEH for the XL and EA versions. The bit pattern of these versions is the same as for the XL and EA versions, except that the RMX bit is missing.

Interrupts in the 80186/80188

The interrupts in the 80186/80188 are identical to the 8086/8088, except that additional interrupt vectors are defined for some of the internal devices. A complete listing of the reserved interrupt vectors appears in Table 16–3. The first five are identical to the 8086/8088.

The array BOUND instruction interrupt is requested if the boundary of an index register is outside the values set up in the memory. The unused opcode interrupt occurs whenever the 80186/80188 executes any undefined opcode. This is important if a program begins to run awry. Note that the unused opcode interrupt can be accessed by an instruction, but the assembler does not include it in the instruction set. On the Pentium Pro–Pentium 4 and some earlier Intel micro- processors, the 0F0BH or 0FB9H instruction will cause the program to call the procedure whose address is stored at the unused opcode interrupt vector.

The ESC opcode interrupt occurs if ESC opcodes D8H–DFH are executed. This occurs only if the ET (escape trap) bit of the relocation register is set. If an ESC interrupt occurs, the address stored on the stack by the interrupt points to the ESC instruction or to its segment over- ride prefix, if one is used.

The internal hardware interrupts must be enabled by the I flag bit and must be unmasked to function. The I flag bit is set (enabled) with STI and cleared (disabled) with CLI. The remaining internally decoded interrupts are discussed with the timers and DMA controller, later in this section.

Interrupt Controller

The interrupt controller inside the 80186/80188 is a sophisticated device. It has many interrupt inputs that arrive from the five external interrupt inputs, the DMA controller, and the three timers. Figure 16–8 provides a block diagram of the interrupt structure of the 80186/80188 interrupt

The 80186, 80188, and 80286 Microprocessors-0371

controller. This controller appears in the XL, EA, and EB versions, but the EC version contains the exact equivalent to a pair of 8259As, as found in Chapter 12. In the EB version, the DMA inputs are replaced with inputs from the serial unit for receive and transmit.

The interrupt controller operates in two modes: master and slave mode. The mode is selected by a bit in the interrupt control register (EB and EC versions) called the CAS bit. If the CAS bit is a logic 1, the interrupt controller connects to external 8259A programmable interrupt controllers (see Figure 16–9); if CAS is a logic 0, the internal interrupt controller is selected. In many cases, there are enough interrupts within the 80186/80188, so the slave mode is not

The 80186, 80188, and 80286 Microprocessors-0372

normally used. In the XL and EA versions, the master and slave modes are selected in the peripheral control register at offset address FEH.

This portion of the text does not detail the programming of the interrupt controller. Instead, it is limited to a discussion of the internal structure of the interrupt controller. The programming and application of the interrupt controller is discussed in the sections that describe the timer and DMA controller.

Interrupt Controller Registers. Figure 16–10 illustrates the interrupt controller’s registers. These registers are located in the peripheral control block beginning at offset address 22H. For the EC version, which is compatible with the 8259A, the interrupt controller ports are at offset addresses 00H and 02H for the master and ports 04H and 06H for the slave. In the EB version, the interrupt controller is programmed at offset address 02H. Note that the EB version has an additional interrupt input (INT4).

Slave Mode. When the interrupt controller operates in the slave mode, it uses up to two external 8259A programmable interrupt controllers for interrupt input expansion. Figure 16–9 shows how the external interrupt controllers connect to the 80186/80188 interrupt input pins for slave operation. Here, the INT0 and INT1 inputs are used as external connections to the interrupt request outputs of the 8259s, and INTA01INT22 and INTA11INT32 are used as interrupt acknowledge signals to the external controllers.

Interrupt Control Registers. There are interrupt control registers in both modes of operation, which each control a single interrupt source. Figure 16–11 depicts the binary bit pattern of each of these interrupt control registers. The mask bit enables (0) or disables (1) the interrupt input

The 80186, 80188, and 80286 Microprocessors-0373

represented by the control word, and the priority bits set the priority level of the interrupt source. The highest priority level is 000, and the lowest is 111. The CAS bit is used to enable slave or cascade mode (0 enables slave mode), and the SFNM bit selects the special fully nested mode. The SFNM allows the priority structure of the 8259A to be maintained.

Interrupt Request Register. The interrupt request register contains an image of the interrupt sources in each mode of operation. Whenever an interrupt is requested, the corresponding inter- rupt request bit becomes a logic 1, even if the interrupt is masked. The request is cleared when- ever the 80186/80188 acknowledges the interrupt. Figure 16–12 illustrates the binary bit pattern of the interrupt request register for both the master and slave modes.

Mask and Priority Mask Registers. The interrupt mask register has the same format as the interrupt register illustrated in Figure 16–12. If a source is masked (disabled), the corresponding bit of the interrupt mask register contains a logic 1; if enabled, it contains a logic 0. The interrupt mask register is read to determine which interrupt sources are masked and which are enabled. A source is masked by setting the source’s mask bit in its interrupt control register.

The priority mask register, illustrated in Figure 16–13, shows the priority of the interrupt currently being serviced by the 80186/80188. The level of the interrupt is indicated by priority bits P2–P0. Internally, these bits prevent an interrupt by a lower priority source. These bits are automatically set to the next lower level at the end of an interrupt, as issued by the 80186/80188.

In-Service Register. The in-service register has the same binary bit pattern as the request register of Figure 16–12. The bit that corresponds to the interrupt source is set if the 80186/80188 is currently acknowledging the interrupt. The bit is reset at the end of an interrupt.

The Poll and Poll Status Registers. Both the interrupt poll and interrupt poll status registers share the same binary bit patterns as those illustrated in Figure 16–14. These registers have a bit

The 80186, 80188, and 80286 Microprocessors-0374The 80186, 80188, and 80286 Microprocessors-0375

(INT REQ) that indicates an interrupt is pending. This bit is set if an interrupt is received with sufficient priority, and cleared when an interrupt is acknowledged. The S bits indicate the interrupt vector type number of the highest priority pending interrupt.

The poll and poll status registers may appear to be identical because they contain the same information. However, they differ in function. When the interrupt poll register is read, the interrupt is acknowledged. When the interrupt poll status register is read, no acknowledge is sent. These registers are used only in the master mode, not in the slave mode.

End-of-Interrupt Register. The end-of-interrupt (EOI) register causes the termination of an interrupt when written by a program. Figure 16–15 shows the contents of the EOI register for both the master and slave mode.

In the master mode, writing to the EOI register ends either a specific interrupt level (vector number) or whatever level is currently active (nonspecific). In the nonspecific mode, the NSPEC bit must be set before the EOI register is written to end a nonspecific interrupt. The nonspecific EOI clears the highest level interrupt bit in the in-service register. The specific EOI clears the selected bit in the in-service register, which informs the microprocessor that the interrupt has been serviced and another interrupt of the same type can be accepted. The nonspecific mode is used unless there is a special circumstance that requires a different order for interrupt acknowl- edges. If a specific EOI is required, the vector number is placed in the EOI command. For example, to clear the timer 2 interrupt the EOI command is 13H (vector for timer 2).

In the slave mode, the level of the interrupt to be terminated is written to the EOI register. The slave mode does not allow a nonspecific EOI.

Interrupt Status Register. The format of interrupt status register is depicted in Figure 16–16. In the master mode, T2–T0 indicates which timer (timer 0, timer 1, or timer 2) is causing an inter- rupt. This is necessary because all three timers have the same interrupt priority level. These bits are set when the timer requests an interrupt and are cleared when the interrupt is acknowledged. The DHLT (DMA halt) bit is only used in the master mode; when set, it stops a DMA action. Note that the interrupt status register is different for the EB version.

Interrupt Vector Register. The interrupt vector register is present only in the slave mode, and only in the XL and EA versions at offset address 20H. It is used to specify the most significant five bits of the interrupt vector type number. Figure 16–17 illustrates the format of this register.

Timers

The 80186/80188 microprocessors contain three fully programmable 16-bit timers and each is totally independent of the others. Two of the timers (timer 0 and timer 1) have input and output

The 80186, 80188, and 80286 Microprocessors-0376

pins that allow them to count external events or generate wave-forms. The third timer (timer 2) connects to the 80186/80188 clock. Timer 2 is used as a DMA request source, as a prescalar for other timers, or as a watchdog timer.

Figure 16–18 shows the internal structure of the timer unit. Notice that the timer unit contains one counting element that is responsible for updating all three counters. Each timer is actually a register that is rewritten from the counting element (a circuit that reads a value from a timer regis- ter and increments it before returning it). The counter element is also responsible for generating the outputs on the pins T0OUT and T1OUT, reading the T0IN and T1IN pins, and causing a DMA request

from the terminal count (TC) of timer 2 if timer 2 is programmed to request a DMA action.

Timer Register Operation. The timers are controlled by a block of registers in the peripheral control block (see Figure 16–19). Each timer has a count register, maximum-count register or

The 80186, 80188, and 80286 Microprocessors-0377

The 80186, 80188, and 80286 Microprocessors-0378

registers, and a control register. These registers may all be read or written at any time because the 80186/80188 microprocessors ensure that the contents never change during a read or write.

The timer count register contains a 16-bit number that is incremented whenever an input to the timer occurs. Timers 0 and 1 are incremented at the positive edge on an external input pin, every fourth 80186/80188 clock, or by the output of timer 2. Timer 2 is clocked on every fourth 80186/80188 clock pulse and has no other timing source. This means that in the 8 MHz version of the 80186/80188, timer 2 operates at 2 MHz, and the maximum counting frequency of timers 0 and 1 is 2 MHz. Figure 16–20 depicts these four clocking periods, which are not related to the bus timing.

Each timer has at least one maximum-count register, called a compare register (compare register A for timers 0 and 1), which is loaded with the maximum count of the count register to generate an output. Note that a timer is an up counter. Whenever the count register is equal to the maximum-count compare register, it is cleared to 0. With a maximum count of 0000H, the counter counts 65,536 times. For any other value, the timer counts the true value of the count. For example, if the maximum count is 0002H, the counter will count from 0 to 1 and then be cleared to 0—a modulus 2 counter has two states.

The 80186, 80188, and 80286 Microprocessors-0379

Timers 0 and 1 each have a second maximum-count compare register (compare register B) that is selected by the control register for the timer. Either maximum-count compare register A or both maximum-count compare registers A and B are used with these timers, as programmed by the ALT bit in the control register for the timer. When both maximum-count compare registers are used, the timer counts up to the value in maximum-count compare register A, clears to 0, and then counts up to the count in maximum-count compare register B. This process is then repeated. Using both maximum-count registers allows the timer to count up to 131,072.

The control register (refer to Figure 16–19) of each timer is 16 bits wide and specifies the operation of the timer. A definition of each control bit follows:

EN The enable bit allows the timer to start counting. If EN is cleared, the timer does not count; if it is set, the timer counts.

INH The inhibit bit allows a write to the timer control register to affect the enable bit (EN).

If INH is set, then the EN bit can be set or cleared to control the counting. If INH is cleared, EN is not affected by a write to the timer control register. This allows other features of the timer to be modified without enabling or disabling the timer.

INT The interrupt bit allows an interrupt to be generated by the timer. If INT is set, an interrupt will occur each time that the maximum count is reached in either maximum- count compare register. If this bit is cleared, no interrupt is generated. When the interrupt request is generated, it remains in force, even if the EN bit is cleared after the interrupt request.

RIU The register in use bit indicates which maximum-count, compare register is currently in use by the timer. If RIU is a logic 0, then maximum-count compare register A is in use. This bit is a read-only bit, and writes do not affect it.

MC The maximum count bit indicates that the timer has reached its maximum count.

This bit becomes a logic 1 when the timer reaches its maximum count and remains a logic 1 until the MC bit is cleared by writing a logic 0. This allows the maximum count to be detected by software.

RTG The retrigger bit is active only for external clocking (EXT = 0). The RTG bit is used only with timers 0 and 1 to select the operation of the timer input pins (T0IN and T1IN).

If RTG is a logic 0, the external input will cause the timer to count if it is a logic 1; the timer will hold its count (stop counting) if it is a logic 0. If RTG is a logic 1, the external input pin clears the timer count to 0000H each time a positive-edge occurs.

P The prescalar bit selects the clocking source for timers 0 and 1. If EXT = 0 and P = 0, the source is one fourth the system clock frequency. If P = 1, the source is timer 2.

EXT The external bit selects internal timing (EXT = 0) or external timing (EXT = 1). If EXT = 1, the timing source is applied to the T0IN or T1IN pins. In this mode, the timer increments after each positive-edge on the timer input pin. If EXT = 0, the clocking source is from one of the internal sources.

ALT The alternate bit selects single maximum-count mode (maximum-count compare register A) if a logic 0, or alternate maximum-count mode (maximum-count compare registers A and B) if a logic 1.

CONT The continuous bit selects continuous operation if a logic 1. In continuous operation, the counter automatically continues counting after it reaches its maximum count. If CONT is a logic 0, the timer will automatically stop counting and clear the EN bit. Note that whenever the 80186/80188 are reset, the timers are automatically disabled.

Timer Output Pin. Timers 0 and 1 have an output pin used to generate either square waves or pulses. To produce pulses, the timer is operated in single maximum-count mode (ALT = 0). In this mode, the output pin goes low for one clock period when the counter reaches its maximum count. By controlling the CONT bit in the control register, either a single pulse or continuous pulses can be generated.

To produce square waves or varying duty cycles, the alternate mode (ALT = 1) is selected. In this mode, the output pin is a logic 1 while maximum-count compare register A controls the timer; it is a logic 0 while maximum-count compare register B controls the timer. As with the single maximum-count mode, the timer can generate either a single square wave or continuous square waves. See Table 16–4 for the function of the ALT and CONT control bits.

Almost any duty cycle can be generated in the alternate mode. For example, suppose that a 10% duty cycle is required at a timer output pin. Maximum-count register A is loaded with a 10 and maximum-count register B is loaded with a 90 to produce an output that is a logic 1 for 10 clocks and a logic 0 for 90 clocks. This also divides the frequency of the timing source by a factor of 100.

Real-Time Clock Example. Many systems require the time of day. This is often called a real- time clock (RTC). A timer within the 80186/80188 can provide the timing source for software that maintains the time of day.

The hardware required for this application is not illustrated because all that is required is that the T1IN pin must be connected to +5.0 V through a pull-up resistor to enable timer 1. In the

example, timers 1 and 2 are used to generate a one-second interrupt that provides the software

with a timing source.

The software required to implement a real-time clock is listed in Examples 16–2 and 16–3. Example 16–2 illustrates the software required to initialize the timers. Example 16–3 shows an interrupt service procedure, which keeps time. There is another procedure in Example 16–3 that increments a BCD modulus counter. None of the software required to install the interrupt vector and set or display time of day is illustrated here.

The 80186, 80188, and 80286 Microprocessors-0380The 80186, 80188, and 80286 Microprocessors-0381

Timer 2 is programmed to divide by a factor of 20,000. This causes the clock (assuming a 2 MHz on the 8 MHz version of the 80186/80188) to be divided down to one pulse every 10 ms. The clock for timer 1 is derived internally from the timer 2 output. Timer 1 is programmed to divide the Timer 2 clock by 100 and generate a pulse once per second. The control register of timer 1 is programmed so that the one-second pulse internally generates an interrupt.

The interrupt service procedure is called once per second to keep time. The interrupt service procedure adds a one to the content of memory location SECONDS on each interrupt. Once every 60 seconds, the content of the next memory location (SECONDS + 1) is incremented. Finally, once per hour, the content of memory location SECONDS + 2 is incremented. The time is stored in these three consecutive memory locations in BCD, so the system software can easily access the time.

The 80186, 80188, and 80286 Microprocessors-0382The 80186, 80188, and 80286 Microprocessors-0383

DMA Controller

The DMA controller within the 80186/80188 has two fully independent DMA channels. Each has its own set of 20-bit address registers, so any memory or I/O location is accessible for a DMA transfer. In addition, each channel is programmable for auto-increment or auto-decrement to either source or destination registers. This controller is not available in the EB or EC versions. The EC version contains a modified four-channel DMA controller; the EB version contains no DMA controller. This text does not describe the DMA controller within the EC version.

Figure 16–21 illustrates the internal register structure of the DMA controller. These registers are located in the peripheral control block at offset addresses C0H–DFH.

The 80186, 80188, and 80286 Microprocessors-0384

Notice that both DMA channel register sets are identical; each channel contains a control word, a source and destination pointer, and a transfer count. The transfer count is 16 bits wide and allows unattended DMA transfers of bytes (80188/80186) and words (80186 only). Each time that a byte or word is transferred, the count is decremented by one until it reaches 0000H—the terminal count.

The source and destination pointers are each 20 bits wide, so DMA transfers can occur to any memory location or I/O address without concern for segment and offset addresses. If the source or destination address is an I/O port, bits A19–A16 must be 0000 or a malfunction may occur.

Channel Control Register. Each DMA channel contains its own channel control register (refer to Figure 16–21), which defines its operation. The leftmost six bits specify the operation of the source and destination registers. The M>IO bit indicates a memory or I/O location, DEC causes the pointer to be decremented, and INC causes the pointer to be incremented. If both the INC and DEC bits are 1, then the pointer is unchanged after each DMA transfer. Notice that memory-to- memory transfers are possible with this DMA controller.

The TC (terminal count) bit causes the DMA channel to stop transfers when the channel count register is decremented to 0000H. If this bit is a logic 1, the DMA controller continues to transfer data, even after the terminal count is reached.

The INT bit enables interrupts to the interrupt controller. If set, the INT bit causes an inter- rupt to be issued when the terminal count of the channel is reached.

The SYN bit selects the type of synchronization for the channel: 00 = no synchronization, 01 = source synchronization, and 10 = destination synchronization. When either unsynchronized or source synchronization is selected, data are transferred at the rate of 2M bytes per second. These two types of synchronization allow transfers to occur without interruption. If destination synchronization is selected, the transfer rate is slower (1.3M bytes per second), and the controller relinquishes control to the 80186/80188 after each DMA transfer.

The P bit selects the channel priority. If P = 1, the channel has the highest priority. If both channels have the same priority, the controller alternates transfers between channels.

The TRDQ bit enables DMA transfers from timer 2. If this bit is a logic 1, the DMA request originates from timer 2. This can prevent the DMA transfers from using all of the micro- processor’s time for the transfer.

The CHG>NOCHG bit determines whether START>STOP changes for a write to the con-

trol register. The START>STOP bit starts or stops the DMA transfer. To start a DMA transfer, both CHG>NOCHG and START>STOP are placed at a logic 1 level.

The BYTE>WORD selects whether the transfer is byte- or word-sized.

Sample Memory-to-Memory Transfer. The built-in DMA controller is capable of performing memory-to-memory transfers. The procedure used to program the controller and start the trans- fer is listed in Example 16–4.

The 80186, 80188, and 80286 Microprocessors-0385The 80186, 80188, and 80286 Microprocessors-0386

The procedure in Example 16–4 transfers data from the data segment location addressed by SI into the extra segment location addressed by DI. The number of bytes transferred is held in register CX. This operation is identical to the REP MOVSB instruction, but execution occurs at a much higher speed through the use of the DMA controller.

Chip Selection Unit

The chip selection unit simplifies the interface of memory and I/O to the 80186/80188. This unit contains programmable chip selection logic. In small- and medium-sized systems, no external decoder is required to select memory and I/O. Large systems, however, may still require external decoders. There are two forms of the chip selection unit; one form found in the XL and EA versions differs from the unit found in the EB and EC versions.

Memory Chip Selects. Six pins (XL and EA versions) or 10 pins (EB and EC versions) are used to select different external memory components in a small- or medium-sized 80186/80188-based system. The UCS (upper chip select) pin enables the memory device located in the upper portion of the memory map that is most often populated with ROM. This programmable pin allows the size of the ROM to be specified and the number of wait states required. Note that the ending address of the ROM is FFFFFH. The LCS (lower chip select) pin selects the memory device (usually a RAM) that begins at memory location 00000H. As with the UCS pin, the memory size and number of wait states are programmable. The remaining four or eight chip select pins select middle memory devices. The four pins in the XL and EA version 1MCS3 – MCS02 are programmed for both the starting (base) address and memory size. Note that all devices must be of the same size. The eight pins 1GCS7 – GCS02 in the EB and EC versions are programmed by size and also by starting address. These selection signals represent a memory device or an I/O device.

Peripheral Chip Selects. The 80186/80188 addresses up to seven external peripheral devices with pins PCS6 – PCS0 (in the XL and EA versions). The GCS pins are used in the EB and EC versions to select up to eight memory or I/O devices. The base I/O address is programmed at any 1K- byte interval with port address block sizes of 128 bytes (64 bytes on the EB and EC versions).

The 80186, 80188, and 80286 Microprocessors-0387

Programming the Chip Selection Unit for XL and EA Versions. The number of wait states in each section of the memory and the I/O are programmable. The 80186/80188 microprocessors have a built-in wait state generator that can introduce between 0 and 3 wait states (XL and EA version). Table 16–5 lists the logic levels required on bits R2–R0 in each programmable register to select various numbers of wait states. These three lines also select if an external READY signal is required to generate wait states. If READY is selected, the external READY signal is in parallel with the internal wait state generator. For example, if READY is a logic 0 for three clocking periods but the internal wait state generator is programmed to insert two wait states, three wait states are inserted.

Suppose that a 64K-byte EPROM is located at the top of the memory system and requires two wait states for proper operation. To select this device for this section of memory, the UCS pin is programmed for a memory range of F0000H–FFFFFH with two wait states. Figure 16–22

The 80186, 80188, and 80286 Microprocessors-0388The 80186, 80188, and 80286 Microprocessors-0389

lists the control registers for all memory and I/O selections in the peripheral control block at off- set addresses A0–A9H. Notice that the rightmost three bits of these control registers are from Table 16–5. The control register for the upper memory area is at location PCB offset address A0H. This 16-bit register is programmed with the starting address of the memory area (F0000H, in this case) and the number of wait states. Please note that the upper two bits of the address must be programmed as 00, and that only address bits A17–A10 are programmed into the control regis- ter. See Table 16–6 for examples illustrating the codes for various memory sizes. Because our example requires two wait states, the basic address is the same as in the table for a 64K device, except that the rightmost three bits are 110 instead of 100. The datum sent to the upper memory control register is 3006H.

Suppose that a 32K-byte SRAM that requires no waits and no READY input is located at the bottom of the memory system. To program the LCS pin to select this device, register A2 is loaded in exactly the same manner as register A0H. In this example, a 07FCH is sent to register A2H. Table 16–7 lists the programming values for the lower chip-selection output.

The central part of the memory is programmed via two registers: A6H and A8H. Register A6H programs the beginning or base address of the middle memory select lines 1MCS3 – MCS02 and number of waits. Register A8H defines the size of the block of memory and the individual memory device size (see Table 16–8). In addition to block size, the number of peripheral wait states are programmed as with other areas of memory. The EX (bit 7) and MS (bit 6) specify the peripheral selection lines, and will be discussed shortly.

For example, suppose that four 32K-byte SRAMs are added to the middle memory area, beginning at location 80000H and ending at location 9FFFFH with no wait states. To program the middle memory selection lines for this area of memory, we place the leftmost seven address bits in

The 80186, 80188, and 80286 Microprocessors-0390The 80186, 80188, and 80286 Microprocessors-0391

register A6H, with bits 8–3 containing logic 0s, and the rightmost three bits containing the ready control bits. For this example, register A6H is loaded with 8004H. Register A8H is programmed with 1F44H, assuming that EX = 0 and MS = 1 and no wait states and no READY are required for the peripherals.

Register A4H programs the peripheral chip selection pins 1PCS6 – PCS02 along with the EX and MS bits of register A8H. Register A4H holds the beginning or base address of the peripheral selection lines. The peripherals may be placed in memory or in the I/O map. If they are placed in the I/O map, A19–A16 of the port number must be 0000. Once the starting address is programmed on any 1K-byte I/O address boundary, the PCS pins are spaced at 128-byte intervals.

For example, if register A4H is programmed with a 0204H, with no waits and no READY synchronization, the memory address begins at 02000H or the I/O port begins at 2000H. In this case, the I/O ports are: PCS0 = 2000H, PCS1 = 2080H, PCS2 = 2100H, PCS3 = 2180H, PCS4 = 2200H, PCS5 = 2280H, and PCS5 = 2300H.

The MS bit of register A8H selects memory mapping or I/O mapping for the peripheral select pins. If MS is a logic 0, then the PCS lines are decoded in the memory map; if it is a logic 1, then the PCS lines are in the I/O map.

The EX bit selects the function of the PCS5 and PCS6 pins. If EX = 1, these PCS pins select I/O devices; if EX = 0, these pins provide the system with latched address lines A1 and A2. The A1 and A2 pins are used by some I/O devices to select internal registers and are provided for this purpose.

Programming the Chip Selection Unit for EB and EC Versions. As mentioned earlier, the EB and EC versions have a different chip selection unit. These newer versions of the 80186/80188 contain an upper and lower memory chip selection pin as do earlier versions, but they do not contain middle selection and peripheral selection pins. In place of the middle and peripheral chip selection pins, the EB and EC versions contain eight general chip selection pins 1GCS7 – GCS02 that select either a memory device or an I/O device.

Programming is also different because each of the chip selection pins contains a starting address register and an ending address register. See Figure 16–23 for the offset address of each pin and the contents of the start and end registers.

Notice that programming for the EB and EC versions of the 80186/80188 is much easier than for the earlier XL and EA versions. For example, to program the UCS pin for an address that begins at location F0000H and ends at location FFFFFH (64K bytes), the starting address register (offset = A4H) is programmed with F002H for a starting address of F0000H with two wait states. The ending address register (offset = A6H) is programmed with 000EH for an ending address of FFFFFH for memory with no external ready synchronization. The other chip selection pins are programmed in a similar fashion.

The 80186, 80188, and 80286 Microprocessors-0392

 

THE 80186, 80188, AND 80286 MICROPROCESSORS:80186/80188 ARCHITECTURE.

THE 80186, 80188, AND 80286 MICROPROCESSORS

INTRODUCTION

The Intel 80186/80188 and the 80286 are enhanced versions of the earlier versions of the 80X86 family of microprocessors. The 80186/80188 and 80286 are all 16-bit microprocessors that are upward-compatible to the 8086/8088. Even the hardware of these microprocessors is similar to the earlier versions. This chapter presents an overview of each microprocessor and points out the differences or enhancements that are present in each version. The first part of the chapter describes the 80186/80188 microprocessors, and the last part shows the 80286 microprocessor.

New to recent editions is expanded coverage of the 80186/80188 family. Intel has added four new versions of each of these embedded controllers to its lineup of microprocessors. Each is a CMOS version and is designated with a two-letter suffix: XL, EA, EB, and EC. The 80C186XL and 80C188XL models are most similar to the earlier 80186/80188 models.

CHAPTER OBJECTIVES

Upon completion of this chapter, you will be able to:

1. Describe the hardware and software enhancements of the 80186/80188 and the 80286 microprocessors as compared to the 8086/8088.

2. Detail the differences between the various versions of the 80186 and 80188 embedded controllers.

3. Interface the 80186/80188 and the 80286 to memory and I/O.

4. Develop software using the enhancements provided in these microprocessors.

5. Describe the operation of the memory management unit (MMU) within the 80286 microprocessor.

6. Define and detail the operation of a real-time operating system (RTOS).

80186/80188 ARCHITECTURE

The 80186 and 80188, like the 8086 and 8088, are nearly identical. The only difference between the 80186 and 80188 is the width of their data buses. The 80186 (like the 8086) contains a 16-bit data bus, while the 80188 (like the 8088) contains an 8-bit data bus. The internal register structure of the 80186/80188 is virtually identical to that of the 8086/8088. About the only difference is that the 80186/80188 contain additional reserved interrupt vectors and some very powerful built-in I/O features. The 80186 and 80188 are often called embedded controllers because of their applica- tion as a controller, not as a microprocessor-based computer.

Versions of the 80186/80188

As mentioned, the 80186 and 80188 are available in four different versions, which are all CMOS microprocessors. Table 16–1 lists each version and the major features provided. The 80C186XL and 80C188XL are the most basic versions of the 80186/80188; the 80C186EC and 80C188EC are the most advanced. This text details the 80C186XL/80C188XL, and then describes the addi- tional features and enhancements provided in the other versions.

80186 Basic Block Diagram

Figure 16–1 provides the block diagram of the 80188 microprocessor that generically represents all versions except for the enhancements and additional features outlined in Table 16–1. Notice that this microprocessor has a great deal more internal circuitry than the 8088. The block diagrams of the 80186 and 80188 are identical except for the prefetch queue, which is four bytes in the 80188 and six bytes in the 80186. Like the 8088, the 80188 contains a bus interface unit (BIU) and an execution unit (ED).

In addition to the BIU and ED, the 80186/80188 family contains a clock generator, a pro- grammable interrupt controller, programmable timers, a programmable DMA controller, and a programmable chip selection unit. These enhancements greatly increase the utility of the 80186/80188 and reduce the number of peripheral components required to implement a system. Many popular subsystems for the personal computer use the 80186/80188 microprocessors as

The 80186, 80188, and 80286 Microprocessors-0361

The 80186, 80188, and 80286 Microprocessors-0362

caching disk controllers, local area network (LAN) controllers, and so forth. The 80186/80188 also finds application in the cellular telephone network as a switcher.

Software for the 80186/80188 is identical to that for the 80286 microprocessor, without the memory management instructions. This means that the 80286-like instructions for immediate multiplication, immediate shift counts, string I/O, PUSHA, POPA, BOUND, ENTER, and LEAVE all function on the 80186/80188 microprocessors.

80186/80188 Basic Features

In this segment of the text, we introduce the enhancements of the 80186/80188 microprocessors or embedded controllers that apply to all versions except where noted, but we do not provide exclusive coverage. More details on the operation of each enhancement and details of each advanced version are provided later in the chapter.

Clock Generator. The internal clock generator replaces the external 8284A clock generator used with the 8086/8088 microprocessors. This reduces the component count in a system.

The internal clock generator has three pin connections: X1, X2, and CLKOUT (or on some versions: CLKIN, OSCOUT, and CLKOUT). The X1 (CLKIN) and X2 (OSCOUT) pins are connected to a crystal that resonates at twice the operating frequency of the microprocessor. In the 8 MHz version of the 80186/80188, a 16 MHz crystal is attached to X1 (CLKIN) and X2 (OSCOUT). The 80186/80188 is available in 6 MHz, 8 MHz, 12 MHz, 16 MHz, or 25 MHz versions.

The CLKOUT pin provides a system clock signal that is one half the crystal frequency, with a 50% duty cycle. The CLKOUT pin drives other devices in a system and provides a timing source to additional microprocessors in the system.

In addition to these external pins, the clock generator provides the internal timing for synchronizing the READY input pin, whereas in the 8086/8088 system, READY synchronization is provided by the 8284A clock generator.

Programmable Interrupt Controller. The programmable interrupt controller (PIC) arbitrates the internal and external interrupts and controls up to two external 8259A PICs. When an external 8259 is attached, the 80186/80188 microprocessors function as the master and the 8259 functions as the slave. The 80C186EC and 80C188EC models contain an 8259A-compatible interrupt controller in place of the one described here for the other versions (XL, EA, and EB).

If the PIC is operated without the external 8259, it has five interrupt inputs: INTO–INT3 and NMI. Note that the number of available interrupts depends on the version: The EB version has six interrupt inputs and the EC version has 16. This is an expansion from the two interrupt inputs available on the 8086/8088 microprocessors. In many systems, the five interrupt inputs are adequate.

Timers. The timer section contains three fully programmable l6-bit timers. Timers 0 and 1 generate waveforms for external use and are driven by either the master clock of the 80186/ 80188 or by an external clock. They are also used to count external events. The third timer, timer 2, is internal and clocked by the master clock. The output of timer 2 generates an interrupt after a specified number of clocks and can provide a clock to the other timers. Timer 2 can also be used as a watchdog timer because it can be programmed to interrupt the microprocessor after a certain length of time.

The 80C186EC and 80C188EC models have an additional timer called a watchdog. The watchdog timer is a 32-bit counter that is clocked internally by the CLKOUT signal (one half the crystal frequency). Each time the counter hits zero, it reloads and generates a pulse on the WDTOUT pin that is four CLKOUT periods wide. This output can be used for any purpose: It can be wired to the reset input to cause a reset or to the NMI input to cause an interrupt. Note that if it is connected to the reset or NMI inputs, it is periodically reprogrammed so that it never counts down to zero. The purpose of a watchdog timer is to reset or interrupt the system if the software goes awry.

Programmable DMA Unit. The programmable DMA unit contains two DMA channels or four DMA channels in the 80C186EC/80C188EC models. Each channel can transfer data between memory locations, between memory and I/O, or between I/O devices. This DMA controller is similar to the 8237 DMA controller discussed in Chapter 13. The main difference is that the 8237 DMA controller has four DMA channels, as does the EC model.

Programmable Chip Selection Unit. The chip selection is a built-in programmable memory and I/O decoder. It has six output lines to select memory, seven lines to select I/O on the XL and EA models, and 10 lines that select either memory or I/O on the EB and EC models.

On the XL and EA models, the memory selection lines are divided into three groups that select memory for the major sections of the 80186/80188 memory map. The lower memory select signal enables memory for the interrupt vectors, the upper memory select signal enables memory for reset, and the middle memory select signals enable up to four middle memory devices. The boundary of the lower memory begins at location 00000H and the boundary of the upper memory ends at location FFFFFH. The sizes of the memory areas are programmable, and wait states (0–3 waits) can be automatically inserted with the selection of an area of memory.

On the XL and EA models, each programmable I/O selection signal addresses a 128-byte block of I/O space. The programmable I/O area starts at a base I/O address programmed by the user, and all seven 128-byte blocks are contiguous.

On the EB and EC models, there is an upper and lower memory chip selection pin and eight general-purpose memory or I/O chip selection pins. Another difference is that from 0 to 15 wait states can be programmed in these two versions of the 80186/80188 embedded controllers.

Power Save/Power Down Feature. The power save feature allows the system clock to be divided by 4, 8, or 16 to reduce power consumption. The power-saving feature is started by soft- ware and exited by a hardware event such as an interrupt. The power down feature stops the clock completely, but it is not available on the XL version. The power down mode is entered by execution of an HLT instruction and is exited by any interrupt.

Refresh Control Unit. The refresh control unit generates the refresh row address at the interval programmed. The refresh control unit does not multiplex the address for the DRAM—this is still the responsibility of the system designer. The refresh address is provided to the memory system at the end of the programmed refresh interval, along with the RFSH control signal. The memory system must run a refresh cycle during the active time of the RFSH control signal. More on memory and refreshing is provided in the section that explains the chip selection unit.

Pin-Out

Figure 16–2 illustrates the pin-out of the 80C186XL microprocessor. Note that the 80C186XL is packaged in either a 68-pin leadless chip carrier (LCC) or in a pin grid array (PGA). The LCC package and PGA packages are illustrated in Figure 16–3.

Pin Definitions. The following list defines each 80C186XL pin and notes any differences between the 80C186XL and 80C188XL microprocessors. The enhanced versions are described later in this chapter.

VCC This is the system power supply connection for ±10%, +5.0 V.

VSS This is the system ground connection.

X1 and X2 The clock pins are generally connected to a fundamental-mode parallel resonant crystal that operates an internal crystal oscillator. An external clock signal may be connected to the X1 pin. The internal master clock operates at one half the external crystal or clock input signal. Note that these pins are labeled CLKIN (Xl) and OSCOUT (X2) on some versions of the 80186/80188.

The 80186, 80188, and 80286 Microprocessors-0363The 80186, 80188, and 80286 Microprocessors-0364

CLKOUT Clock out provides a timing signal to system peripherals at one half the clock input frequency with a 50% duty cycle.

RES

The reset input pin resets the 80186/80188. For a proper reset, the RES must be held low for at least 50 ms after power is applied. This pin is often connected to an RC circuit that generates a reset signal after power is applied. The reset location is identical to that of the 8086/8088 micro- processor—FFFF0H.

RESET The companion reset output pin (goes high for a reset) connects to system peripherals to initialize them whenever the RES input goes low.

TEST

This test pin connects to the BUSY output of the 80187 numeric coprocessor. The TEST pin is interrogated with the FWAIT or WAIT instruction.

Tin0 and Tin1 These pins are used as external clocking sources to timers 0 and 1.

Tout0 and Tout1 These pins provide the output signals from timers 0 and 1, which can be programmed to provide square waves or pulses.

DRQ0 and DRQ1 These pins are active-high-level triggered DMA request lines for DMA channels 0 and 1.

NMI This is a non-maskable interrupt input. It is positive edge-triggered and always active. When NMI is activated, it uses interrupt vector 2.

INT0, INT1, These are maskable interrupt inputs. They are active-high and are

INT2 / INTA0, and programmed as either level or edge-triggered. These pins are configureed

INT3 / INTA1

as four interrupt inputs if no external 8259 is present, or as two interrupt

inputs if the 8259A interrupt controller is present.

A19 / ONCE, A18, These are multiplexed address/status connections that provide the A17, and A16 address (A19–A16) and status (S6–S3). Status bits found on address pins A18–A16 have no system function and are used during manufacturing for

testing. The A19 pin is an input for the ONCE function on a reset. If ONCE is held low on a reset, the microprocessor enters a testing mode.

AD15–AD0 These are multiplexed address/data bus connections. During T1, the 80186 places A15–A0 on these pins; during T2, T3, and T4, the 80186 uses these pins as the data bus for signals D15–D0. Note that the 80188 has pins AD7–AD0 and A15–A8.

BHE

The bus high enable pin indicates (when a logic 0) that valid data are transferred through data bus connections D15–D8.

ALE Address latch enable is an output pin that contains ALE one-half clock cycle earlier than in the 8086. It is used to demultiplex the address/data and address/status buses. (Even though the status bits on A19–A16 are not used in the system, they must still be demultiplexed.)

WR The write pin causes data to be written to memory or I/O.

RD The read pin causes data to be read from memory or I/O.

ARDY The asynchronous READY input informs the 80186/80188 that the mem- ory or I/O is ready for the 80186/80188 to read or write data. If this pin is tied to +5.0 V, the microprocessor functions normally; if it is grounded, the microprocessor enters wait states.

SRDY The synchronous READY input is synchronized with the system clock to provide a relaxed timing for the ready input. Like ARDY, SRDY is tied to

+5.0 V for no wait states.

LOCK

The lock pin is an output controlled by the LOCK prefix. If an instruction is prefixed with LOCK, the LOCK pin becomes a logic 0 for the duration of the locked instruction.

S2, S1, and S0 These are status bits that provide the system with the type of bus transfer in effect. See Table 16–2 for the states of the status bits. The upper-memory chip select pin selects memory on the upper portion of the memory map.

UCS

The upper-memory chip select output is programmable to enable memory sizes of 1K to 256K bytes ending at location FFFFFH. Note that this pin is programmed differently on the EB and EC versions and enables memory between 1K and 1M long.

The 80186, 80188, and 80286 Microprocessors-0365

The lower-memory chip select pin enables memory beginning at location 00000H. This pin is programmed to select memory sizes from 1K to 256K bytes. Note that this pin functions differently for the EB and EC versions and enables memory between 1K and 1M bytes long.

The middle-memory chip select pins enable four middle memory devices. These pins are programmable to select an 8K to 512K byte block of memory, containing four devices. Note that these pins are not present on the EB and EC versions.

These are five different peripheral selection lines. Note that the lines are not present on the EB and EC versions.

PCS5>A1 and These are programmed as peripheral selection lines or as internally

PCS6>A2

DT>R DEN

latched address bits A2 and A1. These lines are not present on the EB and EC versions.

The data transmit/receive pin controls the direction of data bus buffers if attached to the system.

The data bus enable pin enables the external data bus buffers.

DC Operating Characteristics

It is necessary to know the DC operating characteristics before attempting to interface or operate the microprocessor. The 80C186/801C88 microprocessors require between 42 mA and 63 mA of power-supply current. Each output pin provides 3.0 mA of logic 0 current and -2 mA of logic 1 current.

80186/80188 Timing

The timing diagram for the 80186 is provided in Figure 16–4. Timing for the 80188 is identical except for the multiplexed address connection, which are AD7–AD0 instead of AD15–AD0, and the BHE, which does not exist on the 80188.

The basic timing for the 80186/80188 is composed of four clocking periods just as in the 8086/8088. A bus cycle for the 8 MHz version requires 500 ns, while the 16 MHz version requires 250 ns.

There are very few differences between the timing for the 80186/80188 and the 8086/8088. The most noticeable difference is that ALE appears one-half clock cycle earlier in the 80186/ 80188.

Memory Access Time. One of the more important points in any microprocessor’s timing diagram is the memory access time. Access time calculations for the 80186/80188 are identical to that of the 8086/8088. Recall that the access time is the time allotted to the memory and I/O to provide data to the microprocessor after the microprocessor sends the memory or I/O its address.

A close examination of the timing diagram reveals that the address appears on the address bus TCLAV time after the start of T1. TCLAV is listed as 44 ns for the 8 MHz version. (See Figure 16–5.)

Data are sampled from the data bus at the end of T3, but a setup time is required before the clock

defined as TDVCL. The times listed for TDVCL are 20 ns for both versions of the microprocessor.

Access time is therefore equal to three clocking periods minus both TCLAV and TDVCL. Access time for the 8 MHz microprocessor is 375 ns – 44 ns – 20 ns, or 311 ns. The access time for the 16 MHz version is calculated in the same manner, except that TCLAV is 25 ns and TDVCL is 15 ns.

The 80186, 80188, and 80286 Microprocessors-0366The 80186, 80188, and 80286 Microprocessors-0367

 

QUESTIONS AND PROBLEMS ON BUS INTERFACE.

QUESTIONS AND PROBLEMS

1. The letters ISA are an acronym for what phrase?

2. The ISA bus system supports what size data transfers?

3. Is the ISA bus interface often used for memory expansion?

4. Develop an ISA bus interface that is decoded at addresses 310H–313H. This interface must contain an 8255 accessed via these port addresses. (Don’t forget to buffer all inputs to the ISA bus card.)

5. Develop an ISA bus interface that decodes ports 0340H–0343H to control a single 8254 timer.

6. Develop a 32-bit PCI bus interface that adds a 27C256 EPROM at memory addresses FFFF0000H–FFFF7FFFH.

7. Given a 74LS244 buffer and a 74LS374 latch, develop an ISA bus interface that contains an 8-bit input port at I/O address 308H and an 8-bit output port at I/O address 30AH.

8. Create an ISA bus interface that allows four channels of analog output signals from 0 to 5.0 V each. These four channels must be decoded at I/O addresses 300H, 310H, 320H, and 330H. Also develop software that supports the four channels.

9. Redo question 8, but instead of four output channels, use four ADCs to create four analog input channels at the same addresses.

10. Using an 8254 timer or timers, develop a darkroom timer on an ISA bus card. Your timer must generate a logic 0 for 1/100-second intervals from 1/100 second to five minutes. Use the system clock of 8 MHz as a timing source. The software you develop must allow the user to select the time from the keyboard. The output signal from the timer must be a logic 0 for the duration of the selected time and must be passed through an inverter to enable a solid- state relay that controls the photographic enlarger.

11. Interface a 16550 UART to the personal computer through the PCI bus interface. Develop software that transmits and receives data at baud rates of 300, 1200, 9600, and 19,200. The UART must respond to I/O ports 1E3XH.

12. The ISA bus can transfer data that are wide at the rate of 8 MHz.

13. Describe how the address can be captured from the PCI bus.

14. What is the purpose of the configuration memory found on the PCI bus interface?

15. Define the term plug-and-play.

16. What is the purpose of the C>BE connection on the PCI bus system?

17. How is the BIOS tested for the PCI BIOS extension?

18. Develop a short program that interrogates the PCI bus, using the extension to the BIOS, and reads the 32-bit contents of configuration register 08H. For this problem, consider that the bus and unit numbers are 0000H.

19. What advantage does the PCI bus exhibit over the ISA bus?

20. How fast does the PCI Express bus transfer serial data?

21. What is a lane in a PCI Express interface?

22. The parallel port is decoded at which I/O addresses in a personal computer?

23. Can data be read from the parallel port?

24. The parallel port connecter found on the back of the computer has pins.

25. Most computers contain at least one serial communication port. What is this port called?

26. Develop a C++ function that sends the letters ABC through the serial port and continues to do so until the letters ABC are returned through the serial port. Show all functions needed to accomplish this, including any initialization.

27. Modify Example 15–9 so it sends a character string of any length.

28. Search the Internet and detail, in a short report, variants as used in the Visual Programming environment.

29. Can a USB device appear as a COM device?

30. What data rates are available for use on the USB?

31. How are data encoded on the USB?

32. What is the maximum cable length for use with the USB?

33. Will the USB ever replace the ISA bus?

34. How many device addresses are available on the USB?

35. What is NRZI encoding?

36. What is a stuffed bit?

37. If the following raw data are sent on the USB, draw the waveform of the signal found on the USB: (1100110000110011011010).

38. How long can a data packet be on the USB?

39. What is the purpose of the NAK and ACK tokens on the USB?

40. Describe the difference in data transfer rates on the PCI bus when compared with the AGP.

41. What is the transfer rate in a system using an 8X AGP video card?

42. What is the transfer rate of a PCI Express 16X video card?

43. On the Internet, locate a few video card manufacturers and find how much memory is avail- able on AGP video cards. List the manufacturers and the amount of memory on the cards.

44. Using the Internet, write a report that details any USB controller.

 

BUS INTERFACE:THE UNIVERSAL SERIAL BUS (USB).

THE UNIVERSAL SERIAL BUS (USB)

The universal serial bus (USB) has solved a problem with the personal computer system. The current PCI sound cards use the internal PC power supply, which generates a tremendous amount of noise. Because the USB allows the sound card to have its own power supply, the noise associated with the PC power supply can be eliminated, allowing for high-fidelity sound without 60 Hz hum. Other benefits are ease of user connection and access to up to 127 different connections through a four-connection serial cable. This interface is ideal for keyboards, sound cards, simple video-retrieval devices, and modems. Data transfer speeds are 480 Mbps for full-speed USB 2.0 operation, 11 Mbps for USB 1.1 compliant transfers, and 1.5 Mbps for slow-speed operation.

Cable lengths are limited to five meters maximum for the full-speed interface and three meters maximum for the low-speed interface. The maximum power available through these cables is rated at 100 mA and maximum current at 5.0 V. If the amount of current exceeds 100 mA, Windows will display a yellow exclamation point next to the device, indicating an overload condition.

The Connector

Figure 15–15 illustrates the pin-out of the USB connector. There are two types of connectors specified and both are in use. In either case, there are four pins on each connector, which contain the signals indicated in Table 15–10. As mentioned, the +5.0 V and ground signals can be used to power devices connected to the bus as long as the amount of current does not exceed 100 mA per device. The data signals are biphase signals. When +data are at 5.0 V, -data are at zero volts and vice versa.

USB Data

The data signals are biphase signals that are generated using a circuit such as the one illustrated in Figure 15–16. The line receiver is also illustrated in Figure 15–16. Placed on the transmission pair is a noise-suppression circuit that is available from Texas Instruments (SN75240). Once the

Bus Interface-0350

transceiver is in place, interfacing to the USB is complete. The 75773 integrated circuit from Texas Instruments functions as both the differential line driver and receiver for this schematic.

The next phase is learning how the signals interact on the USB. These signals allow data to be sent and received from the host computer system. The USB uses NRZI (non-return to zero, inverted) data encoding for transmitting packets. This encoding method does not change the signal level for the transmission of a logic 1, but the signal level is inverted for each change to a logic 0. Figure 15–17 illustrates a digital data stream and the USB signal produced using this encoding method.

The actual data transmitted includes sync bits using a method called bit stuffing. If a logic 1 is transmitted for more than 6 bits in a row, the bit stuffing technique adds an extra bit (logic 0) after six continuous 1s in a row. Because this lengthens the data stream, it is called bit stuffing. Figure 15–18 shows a bit-stuffed serial data stream and the algorithm used to create it from raw digital serial data. Bit stuffing ensures that the receiver can maintain synchronization for long strings of 1s. Data are always transmitted beginning with the least-significant bit first, followed by subsequent bits.

USB Commands

Now that the USB data format is understood, we will discuss the commands used to transfer data and select the receptor. To begin communications, the sync byte (80H) is transmitted first, fol- lowed by the packet identification byte (PID). The PID contains 8 bits, but only the rightmost 4 bits contain the type of packet that follows, if any. The leftmost 4 bits of the PID are the ones complementing the rightmost 4 bits. For example, if a command of 1000 is sent, the actual byte sent for the PID is 0111 1000. Table 15–11 shows the available 4-bit PIDs and their 8-bit codes. Notice that PIDs are used as token indicators, as data indicators, and for handshaking.

Bus Interface-0351Bus Interface-0352

Figure 15–19 lists the formats of the data, token, handshaking, and start-of-frame packets found on the USB. In the token packet, the ADDR (address field) contains the 7-bit address of the USB device. As mentioned earlier, there are up to 127 devices present on the USB at a time. The ENDP (endpoint) is a 4-bit number used by the USB. Endpoint 0000 is used for initialization; other endpoint numbers are unique to each USB device.

There are two types of CRC (cyclic redundancy checks) used on the USB: One is a 5-bit CRC and the other (used for data packets) is a 16-bit CRC. The 5-bit CRC is generated with the X5 + X2 + 1 polynomial; the 16-bit CRC is generated with the X16 + X15 + X2 + 1 polynomial.

When constructing circuitry to generate or detect the CRC, the plus signs represent Exclusive-

OR circuits. The CRC circuit or program is a serial checking mechanism. When using the 5-bit CRC, a residual of 01100 is received for no error in all five bits of the CRC and the data bits. With the 16-bit CRC, the residual is 1000000000001101 for no error.

Bus Interface-0353Bus Interface-0354

token back to the host. If the data and CRC are received correctly, the ACK is sent; if not, the NAK is sent. If the host receives a NAK token, it retransmits the data packet until the receiver finally receives it correctly. This method of data transfer is often called stop and wait flow control. The host must wait for the client to send an ACK or NAK before transferring additional data packets.

The USB Bus Node

National Semiconductor produces a USB bus interface that is fairly easy to interface to the micro- processor. Figure 15–20 illustrates the USBN9604 USB node. Connecting this device to a system using non-DMA access is accomplished by connecting the data bus to D0–D7, the control inputs RD, WR, and CS, and a 24 MHz fundamental crystal across the XIn and XOut pins. The USB bus connection is located on the D- and D+ pins. The simplest interface is achieved by connecting the two mode inputs to ground. This places the device into a nonmultiplexed parallel mode. In this mode the A0 pin is used to select address (1) or data (0). Figure 15–21 shows this connection to the microprocessor decodes at I/O port addresses 0300H (data) and 0301H (address).

The USBN9604 is a USB bus transceiver that can receive USB data and transmit USB data. This provides an interface point to the USB bus for a minimal cost of about two dollars.

Bus Interface-0355

Software for the USBN9604/3

The software presented here functions with the interface in Figure 15–21. Not provided is the driver software for the host system. Example 15–13 illustrates the code required to initialize the USB controller. The USBINT procedure sets the USB controller to use end point zero for data transfers.

Bus Interface-0356

Once the USB controller is initialized, data can be sent or received to the host system through the USB. To accomplish data transmission, the procedure illustrated in Example 15–14 is called to send a 1-byte packet using the TXD0 FIFO. This procedure uses the SEND macro listed in Example 15–13 to transfer the byte in BL through the USB to the host system.

Bus Interface-0357Bus Interface-0358

To receive data from the USB, two functions are required. One tests to see if data are avail- able and the other reads a byte from the USB and places it into the BL register. Both procedures are listed in Example 15–15. The STATUS procedure checks to see if data are in the receiver FIFO. If data are present, carry is set upon return and if no data are received, carry is cleared. The READS procedure retrieves a byte for the receiver FIFO and returns it in BL.

Bus Interface-0359