CS 100 (Learn)CS 100 (Web)Module 02


Peripherals

The last category of hardware is peripherals, which covers every piece of hardware and physical device other than the CPU, primary memory and secondary storage. Peripherals that you commonly interact with are:

Peripherals that you may use, but don't directly interact with are:

In the very early days of computing, peripherals were very complicated and it required a lot of customized hardware and software to get a peripheral to "talk" to the CPU.

A piece of software designed to let the hardware talk to the operating system is known as a device driver or simply driver. They are called a "driver" for similar historical reasons that we still refer to flash drives as "drives". To give you a basic idea of how peripherals work, we will describe the basics of how a mouse (event-based) and a camera (polling) work.

There is a special piece of hardware connected to your mouse that is completely dedicated to waiting for a mouse event to occur. This hardware sits outside of the CPU, but it has a connection to the CPU that we can imagine as a tiny "alarm bell" that can "wake up" the CPU. This hardware can also talk to the primary memory and put some information in a dedicated location. When a mouse event happens (either you move the mouse or you click a button) the hardware gets really excited (it was waiting a really long time) and puts the mouse information into primary memory (e.g., "the mouse was moved a tiny bit to the right"). The hardware then "rings the bell" and "wakes up" the CPU. The operating system then stops whatever it was doing (it is called an interruption) and uses dedicated software (the driver) to read in and properly interpret the information (e.g., "the mouse was moved a tiny bit to the right"). The operating system might then run some software to move the mouse cursor right a bit on the screen, or if you're playing a game, to tell that game that your elvish warrior is now looking a little bit more to the right. All of this occurs within a microsecond. Your computer is constantly being interrupted by event driven peripherals (touch screens, mice, keyboards) so it can properly respond to the events.

Using our analogy with Cooper and his desk, imagine that in that room there is another person (Evan) watching to see if someone moves the mouse. If Evan sees that the mouse was moved, he puts a special code on a piece of paper and then puts that paper on Cooper's desk. He then rings a bell or slaps Cooper to let him know that a mouse event happened. Cooper then stops what he was doing and looks at another piece of paper on his desk (the device driver) that helps him interpret Evan's code. Cooper now realizes that the mouse has moved and writes on other pieces of paper accordingly. Cooper then resumes whatever he was doing before.

The alternative to event-based peripherals are polling peripherals such as your camera. There is dedicated hardware like with the mouse, but the "alarm bell" works the other way around. In the case of polling-based peripherals, the operating system decides when it wants information from your peripheral and tells it to "wake up" and gather the information. So if you decide you want to take a picture, the operating system asks the camera (via the device driver) "what do you see now?" and then the camera puts some data in primary memory for the operating system to grab. When you want to take a movie, the operating system says "what do you see now?" "what do you see now?" typically 30 or 60 times per second. In the case of your display, it works similarly but instead it says "this is what you display now" "this is what you display now" 60 times per second.

Returning again to our analogy with Cooper, in this situation there is again someone else in the room (Polly) who controls the camera. When Cooper needs a picture taken with the camera, he taps Polly on the shoulder and then tells her to take a picture and where to put it on the desk. Cooper then goes back to whatever work he was doing. Polly would then take a picture, put it on Cooper's desk, and then put a note somewhere on the desk letting Cooper know the picture has been taken. Cooper would be periodically looking for that note, and when he sees it he knows the picture is ready and he can do something with it.

We briefly mentioned the screen/display, but it fits in our analogy quite nicely. Cooper dedicates a region of his desk to correspond to whatever is to be displayed on the screen. Every 60 seconds, he taps another person (Dennis) on the shoulder, and Dennis grabs the information from Cooper's desk and displays it on the screen.

To put it all together, consider this sequence of events. Evan slaps Cooper to let him know that the mouse button was clicked. Cooper then consults some of his pages and realizes that the mouse was over the "take picture" button. Cooper taps Polly on the shoulder and tells her to take a picture and then Cooper resumes his other work. Cooper sees the note that Polly is done, so he then takes the picture and copies it into the special display region of the desk. Cooper then taps Dennis on the shoulder and Dennis updates the display so the user can see the picture taken with the camera. To help put things in perspective, it may help to remember that Cooper is hundreds or even thousands of times faster than Evan, Polly and Dennis: to them, Cooper looks like the flash and is just a blur.

Polling peripherals are becoming increasingly more common, partly because they consume less power. We used the mouse as an example of an event-based peripheral, but modern mice are often polled "did the mouse just move?" "did the mouse just move?" "did the mouse just move?".

Modern operating systems are equipped with numerous device drivers so you can connect a wide variety of devices. The USB (Universal Serial Bus) standard was a great leap forward in standardizing how peripherals (and secondary storage devices) connect to computer.

Year after year, computers are being equipped with more and more peripherals. Can you imagine early computing pioneers envisioning that a GPS would connect to the computer? Why would you need a GPS when the computer weighed several tons and took up an entire room?