/* This example illustrates how to use high level VXI calls * to access indivdual registers and memory locations in * the VXI shared address space. The functions used are: * VXIin - reads a byte, word, or long_word from A16, A24, or A32 space * VXIout - writes a byte, word, or long_word to A16, A24, or A32 space * * More information about these functions can be found in * Chapter 7, 'High 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 address; /* VXI address within space secified in access_parms */ UINT16 width; /* wdith 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 VXIin and VXIout 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 */ address = 0xC000L; /* Read Register 0 of Logical Addres 0 * To calculate the base of a device's * configuration space use: * address = 0xC000 + (LA * 64) */ width = 2; /* Read one word */ /* Read value at 0xC000 which is the manufacturer's id register */ ret = VXIin(access_parms, address, width, &value); if (ret < 0) { printf("Return: %d", ret); CloseVXIlibrary(); /* Access Failed. Close and exit */ exit(-1); } printf("\nValue at %x in A16 space is: %x", address, value); address += 2; /* Now read Model Id register at 0xC002 */ ret = VXIin(access_parms, address, width, &value); printf("\nValue at %x in A16 space is: %x", address, value); ret = VXIinReg(0, 2, &value); /* Read register 2 from logical address 0 */ printf("\nReading same register with VXIinReg instead of VXIin\n"); printf("\nValue at register offset 2 is: %x\n", value); ret = VXIinReg(0, 6, &oldvalue); /*Read offset register from LA 0 */ ret = VXIoutReg(0, 6, 0x8000); /* Change offset register to 0x8000. */ /* Same write using VXIout: * ret = VXIout(access_parms, 0xC006, width, 0x8000); */ printf("\nReplaced %x in offset register with 0x8000", oldvalue); /* Put the old value of the register back */ ret = VXIout(access_parms, 0xC006, width, oldvalue); ret = CloseVXIlibrary(); printf("\nPress any key to exit..."); while (!_kbhit()); return 0; }