MapPhysicalMemory

int MapPhysicalMemory (unsigned int physAddress, unsigned int numBytes, void *ptrToMappedAddr, int *mapHandle);

Purpose

Maps a physical address to a pointer that you can use in your program like any other C pointer.

For example, you can read or write an area of physical memory by incrementing the pointer after each access.

In cases where you cannot transfer all your data at once, MapPhysicalMemory provides better performance than ReadFromPhysicalMemory or WriteToPhysicalMemory. There is a significant performance penalty to mapping and unmapping physical memory. If you call ReadFromPhysicalMemory or WriteToPhysicalMemory on each access, you map and unmap the memory each time.

When you no longer need the pointer, call UnMapPhysicalMemory on the handle mapHandle returns.

Note    MapPhysicalMemory requires the LabWindows/CVI low-level support driver. LabWindows/CVI loads the driver at startup if it is on disk. You can check whether LabWindows/CVI loaded the driver at startup by calling CVILowLevelSupportDriverLoaded.
Note    MapPhysicalMemory does not check the validity of the physical address.

Example

int physAddr = 0xB000;
int numBytes = 0x1000;
int *physMemPtr;
int mapHandle;
int data, i;
if ( ! MapPhysicalMemory (physAddr, numBytes, &physMemPtr, &mapHandle))

{
/* report error */
}

else

{
for (i=0; i < numBytes/sizeof(int); i++)

{
/* <determine data to write> */
*physMemPtr++ = data;
}

UnMapPhysicalMemory (mapHandle);
}

Parameters

Input
Name Type Description
physAddress unsigned integer Physical address to map into user memory.

No restrictions exist on the address, which can be below or above 1 MB.
numBytes unsigned integer Number of bytes of physical memory to map.
Output
Name Type Description
ptrToMappedAddr any type of pointer The mapped physical address.

Pass a pointer by reference as this parameter.
mapHandle integer The handle that you pass to the UnMapPhysicalMemory function to unmap the physical memory.

Return Value

Name Type Description
status integer Indicates whether the function succeeded.

Code Description
1 Success.
0 numBytes is 0, memory allocation failed, the operating system reported an error, or the low-level support driver is not loaded.