About UsResearchOpportunities
PublicationsResourcesSite Map
ECE385 Lab1

ECE385 Lab Pages - Lab 1 Prep Notes

This lab introduces some of the fundamental concepts involved with connecting devices to the ISA bus. A solderless ISA prototyping card will be used in conjunction with a number of ICs which you should come equipped with. Here is the shopping list which can be purchased from vendors on this vendors list. There are three main components to lab 1; the first is putting together the board (building a new device by wiring it up), the second is writing a kernel-space device driver for your parallel port device. The third is using a kernel space device driver to extend the operating system so that it makes use of the new device you have built.

See also http://wearcam.org/ece385/lecture6/index.htm (which is just a symbolic link to http://wearcam.org/ece385/lecture6/lab2.htm) for more info.

Generally we use bare solderless breadboards signed out to each group

Larger - 64 kBytes
largest - 260 kBytes

Looking for adventure?

Alternatively or additionally, students can purchase their own ordinary breadboards, and plug into the solderless breadboards by way of a ribbon cable:
|  Pin No.  |    ISA Signal    |   Pin No.  |    ISA Signal    |
|     1     |        A0        |      2     |      VCC         |
|     3     |        A1        |      4     |      N/A         |
|     5     |        A2        |      6     |      N/A         |
|     7     |        A5        |      8     |      N/A         |
|     9     |        A6        |     10     |      N/A         |
|    11     |        A7        |     12     |      N/A         |
|    13     |        A8        |     14     |      N/A         |
|    15     |        A9        |     16     |      N/A         |
|    17     |        AEN       |     18     |      N/A         |
|    19     |        IOR       |     20     |      N/A         |
|    21     |        IOW       |     22     |      N/A         |
|    23     |        N/A       |     24     |      N/A         |
|    25     |        D0        |     26     |      N/A         |
|    27     |        D1        |     28     |      N/A         |
|    29     |        D2        |     30     |      N/A         |
|    31     |        D3        |     32     |      N/A         |
|    33     |        D4        |     34     |      N/A         |
|    35     |        D5        |     36     |      N/A         |
|    37     |        D6        |     38     |      N/A         |
|    39     |        D7        |     40     |      GND         |

A satisfactory breadboard is available from Active Surplus (As of Thurs. September 28th, 2000, Chris who works at Active reports that there are 27 in stock), which has 5 distribution strips and 3 terminal strips.

Other kinds of breadboards available from various vendors are also suitable.

If you decide to be adventurous and do your own breadboard (rather than, or in addition to, using the one we provide in the lab) here is a useful diagram

available also in PostScript or Proprietary Data Format (PDF) This diagram is layed out with the 40 pin header for our "ISA over IDE cable" idea. The data/address registers, power, ground, etc are all positioned on the sides of the diagram coresponding to their locations on the card.

If not looking for adventure:

However, the ISA breadboard is much easier, if you want to get the lab done quickly.

It is preferable to have a breadboard wired up prior to class unless a student is exceptionally skilled in art of wiring to wire it up in class. This diagram:

(click to enlarge) is the simplified diagram that was shown in class, and makes it easy to understand how the device will work, once you wire it up.

Wiring the board

This updated diagram

(click for PostScript) with minor changes incorporated into it, also shows the wiring of the devices as they actually might appear, and suggests one possible way of laying out the devices.

The ISA bus has a relatively simple timing diagram which is worth examining in detail to understand the device you're building. The pinouts of the ICs used in the lab are available here.

The pitfalls in this section are as follows: don't get lost in the wires, and don't rush. It's better to be patient and build the board properly than hurry and make mistakes. Divide the labour appropriately; have one team member strip wires while the other wires, while the third checks and makes sure no mistakes are being made.

There are eight dip switches connected to the databus through a 74LS244 and eight LEDs connected from the data bus with a 74LS373. The eight dip switches provide something for you to read, and the eight LEDs provide something for you to write to. Thus the device allows you to test both reading from and writing to IO address 240.

At this point, you can modify your code from lab 0 to work with the ISA card. This provides an initial test of the wiring. Remember that you are no longer addressing addres 0x378.


Solderless breadboard with most components installed
Should take 60 minutes to assemble.

larger - 73 kBytes
largest - 299 kBytes

Closeup of above

larger - 114 kBytes
largest - 398 kBytes

Mostly completed board installed in wearcomp

larger - 114 kBytes
largest - 398 kBytes

Writing the kernel-space device driver for the parallel port

One resource which may help out tremendously in this lab and this course is:

The online O'Reilly Device Driver Book

Assuming you are using a 2.0, 2.2 or 2.4 series kernel, the device driver book should answer most of the questions you may have about writing device drivers. The next two parts of this lab are simply to write kernel-space device drivers to write (and possibly read) from the parallel port and the ISA card you have wired. If you followed the wiring diagrams above, the ISA card should be wired to read/write data from address 0x240. The parallel port is usually mapped to the address 0x378. Given all of this information, it should relatively easy to write the device drivers to complete this lab.

Writing "Hello World" device driver

Online, you will find several versions of a "hello world" device driver. To save you a bit of time, i've put one here.

#define MODULE
#include < linux/module.h >

int init_module (void) /* Loads a module in the kernel */
      printk("Hello kernel \\n");
      return 0;
void cleanup_module(void) /* Removes module from kernel */
      printk("GoodBye Kernel \\n");

Compiling the module

# gcc -c hello.c
# insmod hello.o

The output is:

Hello kernel

If you type:
# rmmod hello.o

The output is:

GoodBye Kernel

Didn't see the output???

Generally the output is not directed to the terminal. Rather, it is output to the system log. To see the system log, use the command dmesg, the last two lines of the output should be the output you were looking for.

If you have decided to use a 2.6 series kernel

If you are adventurous and using a 2.6 series kernel, the process or building a module is slightly different. Also, the hello world source code changes a bit. This is covered in sufficient detail at http://linuxdevices.com/articles/AT4389927951.html.

However, to be fair i'll condense what you need here.

Writing "Hello World" device driver for a 2.6 series kernel

The source code for "Hello code" is:

#include < linux/init.h >
#include < linux/module.h >
#include < linux/kernel.h >

static int hello_init(void)
      printk(KERN_ALERT "Hello, world\n");
      return 0;

static void hello_exit(void)
      printk(KERN_ALERT "Goodbye, world\n");

Compiling a 2.6 kernel module

The stucture of kernel modules has changed significantly in 2.6 series kernels. It is no longer possible to type gcc -c to compile a module. The article mention explains this in fair detail. However, if you just want to test out the program quickly:

Create a makefile in which the contents only has:
obj-m := module.o

Then type:
make -C /usr/src/linux SUBDIRS=$PWD modules

Note: in order for this command to work you must have you 2.6 kernel source symbolically linked to /usr/src/linux (you must also have your kernel source). You can still use insmod to load the module, however your kernel module will be called module.ko. You should be able to see this in your directory.

Also Note: insmod changed from version 2.4 The consequence of this is that you must apt-get install module-init-utils to acquire the necessary version of insmod.

Writing a Kernel-space parallel port driver

Read chapter 3 of the online device drivers book, pay particular attention to "File Operations", and the read and write subsections. It would probably pay to read the first two chapters as well (most of which is fairly light reading).

Download pport.c. You will notice most of the code is filled in, with the exception of the bodies of module_read and module_write. It's up to you to fill out these functions. It should be reasonably straight-ahead with the help of the device drivers book. I will be posting a complete driver after the wednesday lab.

From reading the device drivers book and from previous lectures, you know that the kernel communicates to users through the filesystem. In particular, the module will communicate to the user through the /dev directory. We must create device nodes in this directory. To do this, first insmod your driver, then type:

cat /proc/devices

to get the major number assigned to the device

then type:

mknod /dev/pport0 c MY_MAJOR_NUMBER 0
mknod /dev/pport1 c MY_MAJOR_NUMBER 1
where MY_MAJOR_NUMBER is the major number you got assigned.

Now set the permissions for the device files:

chgrp sys /dev/pport0
chgrp sys /dev/pport1
chmod 666 /dev/pport0
chmod 666 /dev/pport1

You can try out you code by echoing to the /dev/pport files
echo -n -e "\377" > /dev/pport0

Writing a Kernel-space ISA driver

Once you have written a parallel port driver, copy the file and rename it to something appropriate to be an ISA driver. Modify the code to be an ISA driver (involves changing the address location you are accessing, it's no longer 0x378). You can try out the the device by echoing to the device file.

Now, you may open the device and communicate to it just as you would a regular file. For example, you may use fopen, fread, etc., to communicate with the device from any c program.

Why were two pport device files created?

You may be wondering why two pport device files were created with mknod. To this point you have most likely only been writing to /dev/pport0. Modify your code so that is you write to /dev/pport0, you get inverted output, and if you write to /dev/pport1, you get non-inverted output. The online device driver book can help you tremendously with this task. There are several other online references which will turn up on searches.


Activity Mark
Demonstrate a working ISA board from user space (with outb and inb).
Demonstrate module_read working with your kernel-space device driver.
Demonstrate module_write working with your kernel-space device driver.
Demonstrate your working ISA driver on your newly wired ISA device.
Modify the device driver to allow either inverting or non-inverting output by writing to either /dev/pport0 (inverting) or /dev/pport1 (non-inverting).
Bonus points: implement a true kernelspace pushbroom that includes a pwm feature. This will be judged for general "coolness" and up to 2 bonus points may be awarded at the discretion of the TA.