VMIVME: GE Fanuc VMEbus Extensions Driver

Contents:

Abstract
Installation
Loading and Unloading the Module
Using Module Parameters
Creating the device file
Writing Applications Using the VMIVME Driver

Abstract

The vmivme driver is a loadable Linux device driver module for GE Fanuc VMEbus single board computers (SBCs).

This document describes installation and usage of the vmivme driver for GE Fanuc SBCs.

This driver only supports access to the VMEbus extension registers. To access the VMEbus, you will need a VMEbus bridge device driver. GE Fanuc supplies VMEbus bridge drivers to support GE Fanuc SBCs. Other organizations such as the VMELinux project and the Linux Labs project supply alternate VMEbus bridge drivers.

Note: It is not necessary to install and use this driver if you are using a VMEbus driver supplied by GE Fanuc.

This document assumes that you have some knowledge of the Linux operating system and C programming for POSIX/UNIX machines.

Installation

Building

Warning: Linux kernel source code must be installed to build the driver module.

To use the vmivme driver, it must first be compiled (built) into executable code and installed. The next code listing illustrates how to compile and install the vmivme driver.

Code listing 1: Compiling and Installing the VMIVME Driver

// From the vmivme base directory execute:
sh$ make
sh# make install

Verifying the Installation

If the project is built and installed correctly, you should have the following file installed on your system:

Code listing 2: Verify the Installation

// This is the driver module.  Make sure you use `uname -r`, not 'uname -r'.
sh$ ls /lib/modules/`uname -r`/extra/
vmivme.ko
// This is the header file for use by calling applications
sh$ ls /usr/include/linux/vmivme.h
vmivme.h

Loading and Unloading the Module

Use the modprobe command to load the driver module by entering modprobe vmivme.

Use the lsmod command command to verify that the module loaded successfully. When you enter lsmod, the module name vmivme should appear in the output.

To unload the module, enter modprobe -r vmivme.

Using Module Parameters

To use module parameters, add them to the /etc/modules.conf file or specify them on the insmod or modprobe command line.

The following parameters are defined for the vmivme driver:

  • comm - Value of the command register.

Warning: Module parameters can be passed in using insmod, but insmod does not read parameters from /etc/modules.conf.

Creating the device file

To access the vmivme driver, we need a character special device file. The major device number is 10 (This is the major number of the miscellaneous device driver). The minor number is dynamically allocated and output to the file /proc/misc.

Code listing 3: Creating the device file

// Create the device file using the minor number from /proc/misc
sh$ cat /proc/misc
 63 vmivme
135 rtc
  1 psaux
134 apm_bios

sh# mknod /dev/vmivme c 10 63

Dynamically allocating the minor number has the unfortunate side-effect that the minor number may change from time to time making the device inaccesable until the minor number is corrected. An alternative is to set the minor number to a fixed value. This can be done by modifying the Makefile.

Code listing 4: Setting the device minor number in the Makefile

// To set the minor number edit the following line in the Makefile

DEVMINOR:=255   # 255 means dynamically allocate a minor number

// Then create the device file where MINOR_NUMBER is the calue you've shoosen
sh# mknod /dev/vmivme c 10 MINOR_NUMBER

Warning: If you choose a fixed minor number, make sure it does not conflict with the minor number of any other device using the miscellaneous device driver interface (major number 10). You may want to look at /usr/include/linux/miscdevice.h before choosing a number.

Writing Applications Using the VMIVME Driver

The vmivme driver supports the following standard Linux system calls:

  • open
  • close
  • ioctl

The ioctl commands are defined in the header file /usr/include/linux/vmivme.h. The following ioctl commands are supported:

  • VMIVME_MEC_ENABLE - Enable master endian conversion
  • VMIVME_MEC_DISABLE - Disable master endian conversion
  • VMIVME_SEC_ENABLE - Enable slave endian conversion
  • VMIVME_SEC_DISABLE - Disable slave endian conversion

Here is an example application that uses the vmivme driver to turn VMEbus endian conversion on and off.

Code listing 5: An application that uses the vmivme driver

// This source code is included in the test directory.
// The file is called vmivme_endian.c


/*
 * Test the VMEbus endian conversion
 *
 * Compile command: cc vmivme_endian.c -o vmivme_endian
 */


#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <linux/vmivme.h>


/*===========================================================================
 * Main routine
 */
int
main (int argc, char **argv)
{
  int fd, c, rval = 0;

  if (0 > (fd = open ("/dev/vmivme", O_RDWR)))
    {
      perror ("open");
      return (-1);
    }

  while (-1 != (c = getopt (argc, argv, "m:s:")))
    {
      switch (c)
        {
        case 'm':              /* Master endian conversion */
          if (strtol (optarg, NULL, 0)) /* no-zero value means enable */
            {
              if (0 > ioctl (fd, VMIVME_MEC_ENABLE))
                {
                  perror ("ioctl");
                  rval = -1;
                }
            }
          else
            {
              if (0 > ioctl (fd, VMIVME_MEC_DISABLE))
                {
                  perror ("ioctl");
                  rval = -1;
                }
            }
          break;
        case 's':              /* Slave endian conversion */
          if (strtol (optarg, NULL, 0)) /* non-zero value means enable */
            {
              if (0 > ioctl (fd, VMIVME_SEC_ENABLE))
                {
                  perror ("ioctl");
                  rval = -1;
                }
            }
          else                  /*  0 means disable */
            {
              if (0 > ioctl (fd, VMIVME_SEC_DISABLE))
                {
                  perror ("ioctl");
                  rval = -1;
                }
            }
          break;
        default:
          fprintf (stderr, "USAGE: vmivme_endian [-m value][-s value]");
        }
    }

  if (0 > close (fd))
    {
      perror ("close");
      rval = -1;
    }

  return (rval);
}

// To compile the application run:
sh$ cc vmivme_endian.c -o vmivme_endian
// If you have not already done so, load the driver.
sh# modprobe vmivme
// Both master and slave endian conversion are on by default.
sh$ vmivme_endian -m0  // turn off master endian conversion
sh$ vmivme_endian -m1  // turn on master endian conversion
sh$ vmivme_endian -s0  // turn off slave endian conversion
sh$ vmivme_endian -s1  // turn on slave endian conversion


Copyright 2005 GE Fanuc. Questions, Comments, Corrections? Email support.embeddedsystems@gefanuc.com.