Lab 5

Purpose: Introduction to Device Drivers in Linux

Reading:
Sections 9.1, 9.2, and 11.13 of the SA-1100 Developer's Manual
CerfBoard Evironment for 466.
Chapter 3 of "Linux Device Drivers, 2nd Edition" (Covers 2.4.x kernels)

Objectives:
For this lab, you are to develop and install a simple (interrupt driven) Linux Device Driver on the CerfBoard's Linux OS for an ultrasonic range finder device. You will need to learn about: The good stuff:

Install your sonar onto the CerfBoard System. The CerfBoard has its own power supply, but MAKE SURE TO CONNECT THE SONAR AND CERF GROUNDS TOGETHER BEFORE TURNING ON POWER!! Refer to the CerfBoard hardware documentation and to the StrongARM documentation.  Pick two pins that are available on Port0 or Port1 of the Cerf break-out-board that correspond to GPIO pins on the sa1100. Connect INIT to one of these pins and connect ECHO to the other. Make sure to check the output enable and port direction settings of the DIP switch on the Intrinsyc break-out-board.


Guide to using the Cerfboard

Setup:
  1. Plug in the power to J2 on the breakout board (the large board). Looking at the board with the three serial ports on the left, the power switch is on the top edge, near the middle. J2 is to the left of the power switch.
  2. Plug in an ethernet cable into the ethernet port on the CerfBoard (the little board). The ethernet port is at the top-left of the board.
  3. Plug in a serial cable to serial port 3 on the breakout board. This is the bottom serial port in the row of three. Plug the other end of the cable into COM1 [default] or COM2 of your PC.
On your PC
  1. Run TeraTerm (or HyperTerminal) using the following settings:
    • Port: COM1 (or COM2)
    • Baud: 38400
    • Parity: none
    • Data bits: 8
    • Stop bits: 1
    • Flow control: None
  2. Power up the CerfBoard. Wait for the CerfLinux login: prompt.
  3. Log in as root (no password needed!)

Compiling your module
  rocket.cs.washington.edu is the compile server. Most of your work will be done here, and then transferred to the cerfboard for testing.
  1. ssh from your desktop machine to rocket.cs.washington.edu, with your group's username (should look like cse466_<letter>) and password.
  2. Grab a copy of the template file. This can be found at /home/cse466/template.c, or here. An example command would be cp /home/cse466/template.c ~/template.c. If you name the file something besides template.c, use that name in the steps below (instead of template.*).
        The kernel source is a slightly patched version of the 2.4.1 kernel. It can be found at /home/cse466/linux on rocket.
  3. Compile your driver module using arm-linux-gcc -Wall -O2 -c template.c
Loading/unloading the module
  1. Log in to the Cerfboard as described above
  2. Create the device file for your device driver, using the command mknod /dev/sonar0 c major_version_number 0.

    mknod creates a special file, in this case a character special file (that's the c option). We don't care about the minor version number, so arbitrarily choose 0.
    major_version_number is the number in the #define directive in your driver module. The major version number in Linux is essentially an index by which the operating system can refer to drivers. It does not have anything to do with the particular release version of the driver. Indeed major version numbers can be assigned dynamically (thus avoiding conflicts) but we are not going to take this approach.

  3. FTP your driver module template.o from rocket to the cerfboard.
  4. Load the driver by running insmod template.o.
  5. Make sure the driver is loaded by running lsmod.
  6. Test the driver's read function by executing cat /dev/sonar0
  7. Test the driver's write function by executing echo Test Message > /dev/sonar0
  8. Unload your driver by running rmmod template
  9. Repeat steps 3-8 as necessary.

Other items of interest:
  1. User space applications are compiled with arm-linux-gcc -o <output-file> <input-file>
  2. Move user space applications to the CerfBoard using FTP as above.
  3. The CerfBoards are running a web server. Your files go in /root/html and /root/cgi-bin. CGI support is pretty much limited to shell scripts and compiled C programs. You can find your IP address by running ifconfig.

GPIO Hints

The kernel defines macros to make GPIO programming easier:

Edge triggering:

IRQs:

Breakout Board:

Device Driver Code