/* * This is an example of how to use some of your computer's memory * as shared VXI memory. In other words, you can make a portion of * your computer's memory available for use by your VXI devices. * To share system memory, you must first configure your controller * for shared RAM in VXIedit. * * In VXIedit you specify the amount of shared memory you will request * from resman and in which address space you wish this memory to * be placed. After you run resman, the system will map cycles on the * VXI bus that fall within that range into the computer. * * When you start doing this, we must ensure that VXI accesses do not * write into portions of memory that are not being used by the operating * system. To do this you must ask the operating system to reserve some * memory for VXI accesses. The function we use for this is called * VXImemAlloc. VXImemAlloc reserves some system memory, and returns * two pointers to it. One pointer is the local address of that buffer. The other is the VXI address that corresponds to it. Other devices on the VXI backplane can use this VXIaddress to write into that buffer. * * Additionally, in a Windows environment, you must specify the * size of a shared memory pool in VXIedit. This pool is allocated and locked at the time Windows boots. Unless this is set to a positive value, VXImemAlloc will be unable to allocate any memory. Use the function VXImemFree() todeallocate any shared buffers you create. * * In some operating systems, you are not allowed to access this shared memory directly using the local pointer returned to us in VXImemAlloc. To access the shared memory we must use the function VXImemCopy. VXImemCopy instructs the operating system to copy the shared buffer into a local one that the application can access. * * More information on these functions and on the use of shared memory can befound in Chapter 8 entitled 'Local Resource Access Functions' of the NI-VXI Software Reference Manual and in Application Note XX entitiled XX */ #include "nivxi.h" #include #include #include #include main() { INT16 ret; UINT32 size, i; /* size of the shared buffer in bytes */ UINT8 * shared_buffer; /* local pointer to the shared buffer */ UINT32 vxi_address; /* VXI address of the shared buffer */ UINT8 * local_buffer; /* pointer to local buffer if we * need to use VXImemCopy */ UINT16 dir; /* direction of VXImemCopy */ ret = InitVXIlibrary(); /* Begin by openning the VXI library */ if (ret < 0) { exit(-1); } /* Allocate the shared buffer */ size = 0x100; ret = VXImemAlloc(size, &shared_buffer, &vxi_address); if (ret < 0) /* check for errors */ { /*Could not allocate memory. Close and exit*/ printf("Could not allocate memory ret = %d\n", ret); printf("Check VXIedit to make sure you have configured shared memory.\n"); printf("Try sharing all of system RAM and using a pool of 1024K\n"); CloseVXIlibrary(); exit(-1); } else if (ret == 0) { /* If ret == 0, the OS is allowing us to access the shared * buffer directly */ printf("\nHex dump of the shared memory buffer: \n"); for (i=0; i