Sub topic 1
I/O Interface Modules and Device Registers
A peripheral is a hardware device outside the CPU and main memory, such as a keyboard, disk controller, network adapter, or sensor. Peripherals operate at different speeds and use different data formats from the CPU. An I/O interface module connects the system bus to a peripheral and hides these device-specific details from the CPU.
The CPU communicates with the interface module rather than directly controlling every electrical signal of the device. The module contains registers that hold data, describe the device state, and control its operation.
Prerequisites
This chapter assumes that you understand the CPU, registers, memory, system buses, the instruction cycle, binary and hexadecimal numbers, and stack-based subroutine calls and returns.
Role of an I/O Interface Module
An interface module performs several related tasks:
- It provides registers that the CPU can read and write.
- It converts CPU bus operations into device-specific signals.
- It stores data temporarily when the CPU and device operate at different speeds.
- It reports device conditions, such as ready, busy, error, or end-of-transfer.
- It coordinates the timing of data transfers.
- It may generate an interrupt when the device needs CPU attention.
For example, a keyboard interface can receive a key code from the keyboard, store it in a data register, set a status bit indicating that data is ready, and notify the CPU. The CPU reads the interface registers instead of sampling the keyboard's electrical lines directly.
A typical interface contains three logical register types:
| Register type | Main purpose | Typical CPU operation |
|---|---|---|
| Data register | Holds data moving between the CPU and device | Read or write |
| Status register | Reports conditions such as ready, busy, or error | Read |
| Control register | Selects actions and enables features | Write |
The exact names and bit positions depend on the device. A status register might contain a READY bit, an ERROR bit, and a BUSY bit. A control register might contain an interrupt-enable bit, a reset bit, and a mode-selection field.
Data, Status, and Control Registers
The data register is the path for the actual value being transferred. For an input device, the interface writes incoming data into this register and the CPU reads it. For an output device, the CPU writes data into the register and the interface sends it to the device.
The status register describes what the interface can currently do. A READY bit commonly means that a new input value is available or that the device can accept output. A BUSY bit indicates that an operation is still in progress. An error bit may identify a transmission, parity, or device fault.
The control register receives commands from the CPU. Writing a one to an interrupt-enable bit might allow the interface to request service when data arrives. Other control fields can start an operation, clear an error, reset the device, or select a transfer mode.
Reading or writing a register can also have side effects. Reading a data register may remove the data-ready condition. Writing a control register may start a motor or begin a transfer. Therefore, register documentation is part of the hardware interface contract.
A Typical Data Transfer
Suppose a sensor interface receives a measurement. The sequence can be:
- The sensor sends a value to the interface.
- The interface stores the value in its data register.
- The interface sets its
READYstatus bit. - The CPU or another transfer mechanism notices that data is ready.
- The value is read from the data register.
- The interface clears
READY, either automatically or after an explicit acknowledgment.
The interface may also use a small buffer. A buffer is temporary storage that holds values while the producer and consumer operate at different rates. Without buffering, a fast device could overwrite a value before the CPU reads it, or a slow device could force the CPU to wait.
Register Access and Synchronization
The CPU must use the correct operation for each register. Reading a status register obtains information. Reading a data register consumes or acknowledges input on many devices. Writing a data register supplies output. Writing a control register changes device behavior.
Synchronization is necessary because the CPU and peripheral are independent agents. The CPU may execute millions of instructions while a peripheral is still completing one operation. The interface records the peripheral's state so that the CPU can determine whether it should continue, wait, or perform other work.
A common mistake is treating a status bit as permanent state. For example, READY = 1 may mean only that one unread value exists. After the data register is read, the bit may become zero. Another mistake is confusing a control bit with a status bit: the CPU writes a control bit to request an action, while it reads a status bit to observe the result.
Chapter Check
The interface module provides a stable software-visible boundary between the CPU and a device. Its data register carries values, its status register reports conditions, and its control register accepts commands. Later I/O techniques differ mainly in how the CPU learns that a transfer is possible and who moves larger amounts of data.
Exercise
A device has a data register and a status register with a READY bit. What does the CPU normally check before reading the data register, and why?
Show answer
It checks that READY is set. The bit indicates that the interface has an unread value. Reading before the device supplies valid data could return an invalid or old value.