NI does not actively maintain this document.
This content provides support for older products and technology, so you may notice outdated links or obsolete information about operating systems or other relevant products.
This tutorial explains how to program a device using Chip Objects.
A Chip Object is a C++ class which simplifies register level programming (RLP). Chip Objects are part of the Measurement Hardware Driver Development Kit (MHDDK) and make RLP easier. They treat each register as a collection of register fields, and let the RLP example or driver read and write register fields instead of manually calculating hexadecimal register values. This document gives a cursory overview of using a Chip Object.
Chip Objects link to a tAddressSpace and the device's iBus. There are several iBus examples already made (including Windows, Linux, and others), so you may not need to make an iBus for your target OS platform. If you need to make an iBus, refer to How to Make an iBus.
Chip Objects rely heavily on inline function calls. They have been compiled with Visual C++ 9.0 and GCC, however they use C++ features conservatively and should compile on most other C++ compilers. GCC 2.96 inefficiently compiles inline functions, while later versions compile inline functions much faster while using much less memory. If a Chip Object takes several minutes to compile, consider upgrading to a newer version of the compiler.
A Chip Object needs both an iBus and a tAddressSpace. An iBus tells it which board to use, and the tAddressSpace tells it which BAR to use:
iBus* bus = NULL;
tAddressSpace deviceSpace;
t671x* board = NULL;
bus = acquireBoard("PXI::7::4::INSTR");
deviceSpace = bus->createAddressSpace(kPCI_BAR1);
board = new t671x(deviceSpace);
Several Chip Objects can be used together as long as they don't talk to the same registers on the device. For instance, a PCI-6602 has two TIO ASICs (one at offset 0x000, the other at offset 0x800). Each TIO can have its own Chip Object:
deviceSpace = bus->createAddressSpace(kPCI_BAR1);
tio = new tTIO(deviceSpace);
tio2 = new tTIO(deviceSpace);
tio2.setAddressOffset(0x800);
The Chip Object should be deleted once all register accesses are finished:
delete board;
bus->destroyAddressSpace(deviceSpace);
releaseBoard(bus);
Chip Objects provide four methods for each register field. They can also work with an entire register, instead of just one field at a time.
readFieldName();
Reads the register from the device, saves the value of the register in a "soft copy" for later reference, and returns the value of the field.
softcopy = read(registerAddress);
return desired_field_of_softcopy;
writeFieldName(value);
Reads the "soft copy" of the register, sets the specified field of the "soft copy" to the new value, then writes the value to the device.
softcopy = softcopy & FieldMask;
softcopy = softcopy | (value << FieldShift);
write(registerAddress, softcopy);
getFieldName();
Reads the "soft copy" of the register and returns the specified field.
return desired_field_of_softcopy;
setFieldName(value);
Reads the "soft copy" of the register, and then sets the specified field of the "soft copy" to its new value.
softcopy = softcopy & FieldMask;
softcopy = softcopy | (value << FieldShift);
There are three ways to program a register with more than one field:
Strobe bits and fields are cleared from the softcopy after they are written to the device, which avoids writing the strobe bits every time the register is accessed.