Using VISA to Perform Low-Level Register Accesses

NI-VISA

Using VISA to Perform Low-Level Register Accesses

The first LLA operation you need to call to access a device register is the viMapAddress() operation, which sets up the hardware window and obtains the appropriate pointer to access the specified address space. The viMapAddress() operation first programs the hardware to map local CPU addresses to hardware addresses as described in the previous section. In addition, it returns a pointer that you can use to access the registers.

The following code is an example of programming the VXI hardware to access A16 space.

status = viMapAddress(instr, VI_A16_SPACE, 0, 0x40, VI_FALSE, VI_NULL, &address);

This sample code sets up the hardware to map A16 space, starting at offset 0 for 0x40 bytes, and returns the pointer to the window in address. Remember that the offset is relative to the base address of the device we are talking to through the instr session, not from the base of A16 space itself. Therefore, offset 0 does not mean address 0 in A16 space, but rather the starting point of the device's A16 memory. You can ignore the VI_FALSE and VI_NULL parameters for the most part because they are reserved for definition by a future version of VISA.

If you call viMap Address() on an INSTR session with an address space the device does not support, or an offset or size greater than the device's memory range, then the VISA driver will not map the memory and will return an error.

Note  To access the device registers through a VXI MEMACC session, you need to provide the absolute VXIbus addresses (base address for device + register offset in device address space).

If you need more than a single map for a device, you must open a second session to the device, because VISA currently supports only a single map per session. There is very low overhead in having two sessions because sessions themselves do not take much memory. However, you need to keep track of two session handles. Notice that this is different from the maximum number of windows you can have on a system. The hardware for the controller you are using may have a limit on the number of unique windows it can support.

When you are finished with the window or need to change the mapping to another address or address space, you must first unmap the window using the viUnmapAddress() operation. All you need to specify is which session you used to perform the map.

status = viUnmapAddress(instr);