In This Article
What is Programmed IO (PIO)?
Programmed Input/Output, or PIO, refers to the specific mode of data transfer between one device and another, typically using the processor of the computer and not the memory or DMA.
- Programmed IO is the specific process to transfer data. It is typically initiated and monitored by the CPU of the computer and is usually under the control of the driver software for accessing device registers or memory.
- In this mode of data transfer, an exchange of data happens between the I/O module and the processor, where the processor carries out a program which gives it the direct control of the I/O operation.
- Programmed IO wastes a lot of CPU power, and so it dips the output of it and the system since it is busy directing and monitoring the whole operation and is kept away from doing other essential and related tasks.
- This mode of data transfer is pretty simple and easy to program and understand. There is no need for interrupts, interrupt hardware support or initialization of the stack since all is done and controlled by the CPU.
- Programmed IO is used by many devices and systems such as the Advanced Technology Attachment interface, the legacy serial and MIDI ports, the PS/2 keyboard and mouse ports, and older network interfaces, to name a few.
Understanding Programmed IO (PIO)
Programmed IO uses the processor of the system to transfer data between devices instead of using the DMA or memory. That is why it is a relatively slower process as compared with Interrupt Driven IO.
This is done by the CPU by executing a particular program that allows it to have direct control over the entire operation.
Typically, the processor has to wait until the I/O operation is over after issuing the command to the I/O module. If it is faster, this results in costly wastage of COU power and time.
The I/O module in Programmed I/O performs the action requested and subsequently sets the correct bits in the status register of the I/O. Apart from that, it does not perform any other action, not even alerting the processor.
Typically, the PIO mode needs a lot of CPU overhead to function because it not only needs to configure a data transaction but also transfer the data.
However, DMA could not replace Programmed IO completely due to the fact that it needs simple digital logic to be implemented.
It is still a useful method today to transfer data and is typically used in specific settings where there is no need for high data transfer rates, such as in the embedded systems or with the Field Programmable Gate Array (FPGA) chips.
Using Programmed IO in these settings does not cause any significant performance loss.
There are different versions or modes of Programmed IO. Each of them supports a varied data transfer rate and the Advanced Technology Attachment standard. Here is the list summarized for you:
- PIO Mode 0 allows a maximum data transfer rate of 3.3 MB/s and supports the ATA-1 standard with a minimum cycle time of 600 ns.
- PIO Mode 1 allows a maximum data transfer rate of 5.2 MB/s and supports the ATA-1 standard with a minimum cycle time of 383 ns.
- PIO Mode 2 allows a maximum data transfer rate of 8.3 MB/s and supports the ATA-1 standard with a minimum cycle time of 240 ns.
- PIO Mode 3 allows a maximum data transfer rate of 11.1 MB/s and supports the ATA-2 standard with a minimum cycle time of 180 ns.
- PIO Mode 4 allows a maximum data transfer rate of 16.7 MB/s and supports the ATA-2 standard with a minimum cycle time of 120 ns.
Remember, there is no PIO Mode 5 or anything beyond PIO Mode 4, and there are no plans for it either, though some hardware and computer manufacturers advertise that their Basic Input Output System (BIOS) will support PIO Mode 5.
However, a PIO Mode 5 was planned with an operational speed of 22 MB/s, but it was not applied on hard disks.
This is because the system would be crippled by the long wait times due to the high operational rate of PIO Mode 5. While no hard drive was built to support PIO 5, the DMA standard finally obviated it.
So, PIO Mode 5 is not suitable for the ATA standard but it can be used with the CompactFlash cards if they are linked to ATA through the CF-to-ATA adapters. These advanced timing modes perform as follows:
- PIO Mode 5 allows a maximum data transfer rate of 20 MB/s and supports the CompactFlash 2.0 standard with a minimum cycle time of 100 ns.
- PIO Mode 6 allows a maximum data transfer rate of 25 MB/s and supports the CompactFlash 2.0 standard with a minimum cycle time of 80 ns.
The operation of the CPU involves several stages and includes:
- Detecting the device status
- Issuing a command to the I/O module
- Sending the read or write command
- Transferring the data
- Monitoring the entire process
The processor also performs the job of pulling out data from the main memory of the system for output and also storing it there for input.
The input data transfer in Programmed IO mode happens in the following ways:
- When the device is ready, each input received is read. This state is reflected in the status register by a bit.
- The program tests the status bit repeatedly and waits until all of the targeted bits are read from the data input device.
- The program gets into the non-waiting or busy state only when the device is ready, or else, it maintains its wait state.
The output data transfer in Programmed IO mode happens in pretty much the same way and as follows:
- When the device is ready to receive the bits, each output is written. Here, the output buffer or the output register is typically empty.
- The program tests the status bits repeatedly and waits until all of the targeted bits are written to the device to get the ready status.
- The program gets into the non-waiting or busy state only when the device is ready, or else, it keeps on waiting.
There are basically four different types of I/O commands used during the execution of the I/O-related instructions by the processor while issuing an address specifying the specific I/O module. These are:
- Control – This command is used to activate the peripheral device and tell it what it needs to do. These commands are typically tailored according to the specific type of exterior device.
- Test – This command is used for testing the different status conditions of the peripheral device of interest and the I/O module. This command helps the processor to know whether or not the particular peripheral device is switched on, is ready to be used, has the most recent I/O operation completed, and if there were any errors occurred.
- Read – This specific command actually allows the I/O module to find a data item, which is usually a byte or a word, from the peripheral device and place it in the internal buffer so that the processor can get it when it requests the I/O module to place it on the data bus.
- Write – This command helps the I/O module to take the data item from the data bus and transmit it to the peripheral device subsequently.
There is a very close communication between the commands used and the instructions followed in Programmed IO. This is what happens in this process:
- The processor typically encounters the I/O instructions that are issued by the main memory of the system to it.
- In order to carry out these instructions, the processor, in turn, issues the I/O commands to the corresponding I/O device.
It is a simple one-to-one connection, where, ideally, the I/O instructions are typically mapped onto the I/O command.
Typically, according to the peripheral devices addresses, the I/O instructions can be customized as well.
Also, when the CPU, the I/O module, and the main memory all share one common bus, addressing is achieved in two specific ways. These are:
- Memory-mapped I/O
- Isolated I/O
In memory-mapped I/O, the CPU uses one single address space to access the memory and I/O. This eventually means that the processor uses the following:
- The same data
- The same address
- The same control bus
Therefore, the machine instruction addresses are also the same for both the I/O and the memory.
On the other hand, in the isolated I/O method, just as the name suggests, the address space for both the memory and that of the I/O is isolated.
However, the CPU uses the same data and address line for the I/O devices and the memory, but it uses a separate control line for the two.
This eventually means that there is a larger set of I/O instructions in the memory-mapped I/O as compared to that of the isolated I/O.
Therefore, in a Programmed IO mode, a program is written for every I/O operation or I/O transfer to perform the task instead of using interrupts as in DMA and Interrupted I/O.
Programmed IO Example
One of the most common examples of a computer device using Programmed I/O is the Advanced Technology Attachment (ATA) interface, though this specific interface can also be used in several different Direct Memory Access (DMA) modes.
Apart from that, there are also several other older devices used in a computer system that use Programmed IO as well. The list includes, but is not limited to:
- The legacy serial ports
- The legacy parallel ports that are not in the Enhanced Capability Port (ECP) mode
- The PS/2 keyboard and mouse ports
- The legacy Musical Instrument Digital Interface (MIDI) and joystick ports
- The interval timer
- Older network interfaces
- Simple to use
- Little hardware support required
- Wait time
- Waste of CPU power and resources
Programmed IO Vs Interrupt Driven IO
- In Programmed IO, the data transfer process is initiated after a request for an I/O transfer is made and the program carries out the instructions stored in it. On the other hand, in Interrupt Driven IO, the data transfer is initiated after an interrupt command is issued to the Central Processing Unit (CPU).
- In Programmed IO the CPU stays in the loop in order to know whether or not the peripheral device is ready to make a data transfer. It also has to monitor the device continuously. On the other hand, there is no such need in the case of Interrupt Driven IO since the interrupt command sent to the CPU interrupts the process if the device is not ready.
- Additional workload on the CPU during the data transfer process in the case of Programmed IO results in wastage of CPU cycles, thereby reducing the efficiency of the system. On the other hand, there is no such wastage in the case of Interrupt Drive IO, making it more efficient since the CPU is not needlessly busy.
- In Programmed IO, the CPU has to wait until the data transfer process is complete and cannot do any other work but to monitor the process. On the other hand, in the case of Interrupt Driven IO, the CPU can engage in performing other essential activities.
- The Programmed IO module is much slower in comparison to the Interrupt Driven module.
- The Programmed IO system is very easy to understand and program, but in comparison, the Interrupt Driven IO is quite difficult to understand and is tricky to program, especially if you are using a low-level language.
- The Programmed IO mode may degrade the performance of the system significantly. On the other hand, while using the Interrupt Driven IO, the system performance will be enhanced to a considerable extent.
- As for the Programmed IO, it does not need any interrupt hardware support to be implemented. On the other hand, an Interrupt Driven IO essentially needs to use interrupt hardware support for its implementation.
- The interrupt status is not important to consider while implementing Programmed IO. On the other hand, Interrupt Driven IO needs the interrupt to be enabled in order to start the data transfer process.
- In Programmed IO, there is no need to initialize the stack, but in comparison, Interrupt Driven IO needs such initialization for processing.
- The performance output of the system is lowered in Programmed IO when there are a large number of I/O devices connected to the system. On the other hand, in the case of Interrupt driven IO, the output of the system does not depend on the number of devices attached to it.
- In Programmed I/O all devices need to ‘ask’ each other whether or not there is any need to communicate with the processor. On the other hand, in an Interrupt Driven IO, the processor does not need to check with the device whether it needs its service or not.
- The checking by the CPU in Programmed IO is done by a constant polling cycle, which keeps the processor busy. On the other hand, in Interrupt Driven IO the processor is informed by using an external asynchronous input.
Ideally, with Programmed I/O mode of data transfer, the CPU of the computer is in control of the data exchange between it and the I/O module.
It is the simplest I/O mode where all is done by the CPU.
Though Direct Memory Access is more commonly used, PIO mode is still used today where speed is not the top priority.