/********************************************************* * This code is designed to run in CVI. It * * demonstrates low level VXI functions by doing the * * following calls to read the configuration registers * * from logical address 0. Flow of code is: * * * * 1) VXIinReg() to read the offset specified by user. * * 2) VXIin() to read same register as VXIinReg() * * 3) VXImove() to read all 4 read-able config registers * *********************************************************/ #include #include #include static char ch; static int regstr, offset, width; static UINT32 address, length, dstaddr, srcaddr; static NIVXI_STATUS Status; static UINT16 value, reg, dstparms, srcparms, accessparms, move_buffer[4]; static INT16 la; void main () { if ( InitVXIlibrary() ) //This function must be called to use VXI functions. { printf ("Unable to Initialize VXI library... exiting"); exit (0); } Cls(); /* * First we need to find out what offset the user wants. We will * store this choice in "offset". */ printf ("What configuration register would you like to read? (0-3) >> "); scanf ("%d",®str); offset = 2 * regstr; /* * also need to find out what LA the user wants to read from */ printf ("What logical address should I read from? >> "); scanf ("%d", &la); /* * Next do VXIinReg(). Parameters are as follows: * * la: logical address of device we want to read from. * reg: configuration register we want to read. * value: data read from operation. */ reg = offset; //offset was set by user. Notice that //this is **NOT** the ABSOLUTE address in A16. Status = VXIinReg (la, reg, &value); if (Status) { // An error occurred printf ("Error in VXIinReg. Status = %d\n", Status); } else //transfer successful, so print result to user. { printf ("Value from VXIinReg = 0x%x\n", value); } /* Now do the same operation by using VXIin(). parameters are: * * accessparms: access priviledges, address space, etc. * address: absolute address within A16, A24, or A32 space. * width: 1=byte, 2=word, 3=long word. * value: data resulting from operation. */ accessparms = 0x1; //A16, non-privilidged data address = 0xC000 + offset; //absolute address to read width = 2; //read a word Status = VXIin (accessparms, address, width, &value); if (Status) { // An error occurred printf ("Error in VXIin. Status = %d\n", Status); } else { printf ("Value from VXIin = 0x%x\n", value); } /* * Now do VXImove. Parameters are as follow: * * srcparms: which address space to use as the source of * the move operation. * srcaddr: address offset within the source address space. * dstparms: address space to use as the destination * of the move operation. * dstaddr: address offset within the destination address space. * length: number of elements to move. * width: size of each element to move. */ srcparms = 0x1; //source is A16 space. srcaddr = 0xC000; //begin move at A16 address 0xC000. dstparms = 0x0; //destination is a local buffer. length = 4; //move 4 elements. width = 2; //move each element as a word. dstaddr = (UINT32)move_buffer; //typecast pointer to UINT32 to //pass array beginning address. Status = VXImove (srcparms, srcaddr, dstparms, dstaddr, length, width); if (Status) { // An error occurred printf ("Error in VXImove. Status = %d\n", Status); } else { //VXImove was successful, print results printf ("\nData from VXImove follows:\n"); printf ("Register 0 = 0x%x\n", move_buffer[0]); printf ("Register 1 = 0x%x\n", move_buffer[1]); printf ("Register 2 = 0x%x\n", move_buffer[2]); printf ("Register 3 = 0x%x\n", move_buffer[3]); } printf (""); getchar (); scanf ("%c", &ch); //wait for user to hit a key to quit CloseVXIlibrary(); //close VXI library. }