/* This example illustrates how to use low level VXI calls * to access indivdual registers and memory locations in * the VXI shared address space. The functions used are: * VXIpeek - reads a byte, word, or long_word from A16, A24, or A32 space * VXIpoke - writes a byte, word, or long_word to A16, A24, or A32 space * MapVXIAddress - maps a portion of the local address space to a portion of * the VXI address space. * * More information about these functions can be found in * Chapter 6, 'Low Level VXIbus Access Functions', in the * NI-VXI Software Reference Manual. */ #include "nivxi.h" #include #include #include main() { INT16 ret; /* Return value from function */ UINT16 access_parms; /* Access parameters - see below*/ UINT32 vxi_address; /* VXI address within space secified in access_parms */ INT32 timo = 5000L; /* Specifies Timeout for MapVXIAddress */ UINT32 window; /* Identifier returned by MapVXIAddress for * window of local address space we just mapped*/ UINT16 * local_address; /* local address returned by MapVXIAddress. * This is a pointer to local memory that is * now being mapped out onto the VXI bus.*/ UINT16 width; /* width of transfer in bytes * 1 = Byte * 2 = Word * 4 = Long Word */ UINT16 value, oldvalue; /* value at location specified by address * declare value as a UINT16 if width is set * to two - word. If width were 1, declare * value as a UINT8. If width were 4, declare * value as a UINT32. */ /* The variable access_parms is a bit vector that * tells MapVXIAddress what address space we * will be accessing. * If bits 0,1 == 01 - That specifies A16 space * If bits 0,1 == 10 - That specifies A24 space * If bits 0,1 == 11 - That specifies A32 space * * The other bits specity other information about the transfer. * Refer to the NI-VXI Software Reference Manual for more * information on them. */ ret = InitVXIlibrary(); /* Always begin by opening the VXI library */ if (ret < 0) /* Check for errors during open */ { exit(-1); /* If we got here, we couldn't open the library */ } access_parms = 1; /* Set for A16 space access */ vxi_address = 0xC000; /* Read Register 0 of Logical Addres 0 * To calculate the base of a device's * configuration space use: * address = 0xC000 + (LA * 64) */ /* Now we map part of local space to part of A16 space by * calling MapVXIAddress */ local_address = (UINT16 *) MapVXIAddress(access_parms, vxi_address, timo, &window, &ret); if (ret < 0 || local_address == NULL) /* check for errors */ { printf("Return is %d, Address is %x\n", ret, local_address); /* If we got here, an error occured in MapVXIAddress. Close and Exit */ CloseVXIlibrary(); exit(-1); } width = 2; /* Read one word */ /* Using the local pointer, read the value in the register */ VXIpeek(local_address, width, &value); printf("\nValue in C000: %x", value); /* Read the value in the offset register too */ local_address += 3; /* Increment our address by 3 words */ VXIpeek(local_address, width, &oldvalue); printf("\nValue in C006: %x. Let's replace that with 0x8000", oldvalue); VXIpoke(local_address, width, 0x8000); VXIpeek(local_address, width, &value); printf("\nNow address C006 reads %x. Now restore the old value.",value); VXIpoke(local_address, width, oldvalue); ret = CloseVXIlibrary(); printf("\nPress any key to exit..."); while (!kbhit()); return 0; }