CAMAC Front-End Documentation : Software Description : General Class Library : Interfacing with PCI devices
Previous: "Action" Classes
Next: Logging Messages

2.1.2. Interfacing with PCI devices

Since the PCI bus was designed by Intel for Intel processors, it is "little-endian". Wind River decided to run VxWorks on the PowerPC in "big-endian" mode. This means that PCI communications will have to have a translation done in order for the data to be properly read and written. VxWorks provides functions and macros to do this, but they're tucked away in a header file in a specialized location. Rather than include this esoteric header file in every source file and learn the macros and functions, three classes have been developed to hide this interface: PciByte, PciWord, and PciLong.

These classes are very easy to use:

2.1.2.1. Creating the objects

The constructors for the objects take a PCI-based address. There is no need to find the PCI base address; the objects add the base to the specified offset.

// Creating a byte-addressable PCI variable
// at PCI offset 0x2000.

PciByte myDevice(0x2000);

In the above example, a device called myDevice is created. It will provide byte-wide access at PCI offset 0x2000.

2.1.2.2. Writing to the objects

All three objects define an assignment operator so writing to the devices uses a very natural syntax:

// Writing 0xff to the PCI port.

myDevice = 0xff;

2.1.2.3. Reading the objects

All three classes define typecast operators so reading the devices also uses a natural syntax:

// Is the device zeroed out?

if (myDevice == 0)
    printf("We are at zero.\n");

2.1.2.4. Caveats

Although these objects provide read/write capabilities, the underlying hardware may not support both forms of access. If you try to access a device in an incorrect way, you may get a bus error. At the bare minimum, you won't get the results you'd expect.

If you want to enforce read-only or write-only behaviour, you could derive a class that disables one form of access. For example, a read-only 16-bit port could be created by the following:

class PciWordReadOnly : public PciWord {
 private:
    PciWordReadOnly& operator= (unsigned short);

 public:
    PciWordReadOnly(unsigned short* addr) : PciWord(addr) {}
};

By moving the assignment operator into the private region, we effectively remove access to it.

If these classes becomes common, we could add them to the library.


CAMAC Front-End Documentation : Software Description : General Class Library : Interfacing with PCI devices
Previous: "Action" Classes
Next: Logging Messages

Security, Privacy, Legal