Section 18.5 I/O Ports
The CPU communicates with an I/O device through I/O ports. The specific port is specified by a value on the address bus. There are two ways to distinguish an I/O port address from a physical memory address:- Port-mappedI/O
Also called Isolated I/O. Uses a separate address space to identify the port address and special instructions to read from or write to the port. The distinction between the two addressing spaces is made in the control bus.
- Memory-mappedI/O
Uses a portion of the regular address space for the ports and regular load and store instructions to read from or write to the port.
Open the device.
Write to or read from the device.
Close the device.
stdout
—standard output, typically the monitor (terminal window).stdin
—standard input, typically the keyboard.stderr
—standard error, typically the monitor (terminal window).
write
system call to write to stdout
and read from stdin
. When you quit the program, the operating system automatically closes these devices. The device drivers for the monitor and keyboard are executing at the EL1 exception level, so they can access the ports (memory addresses) for each of these I/O devices. One of the main purposes of a device driver is to deal with the timing of the I/O device to ensure that the input or output is synchronized with its use by the application program.
The Raspberry Pi has a General Purpose Input/Output (GPIO) device connected to a set of pins that you can connect with various electronic devices. We will see how to program the GPIO in Chapter 19.