How to access physical memory locations in C++

QNX 6.x…

Can anyone provide sample C++ code to access an absolute memory address?

This won’t work because it yields the data at location 0x100 in the virtual
address space of the process, correct?

unsigned char *ptr = 0x100; // address 0x100
unsigned char chr;
chr = *ptr;

Thanks,

Bill
Cincinnati, OH USA

Look at the docs on examples for using mmap(). This will translate a physical address to a virtual one.

Rick…

Here is some code in C that I used to map dual-ported ram into memory.
The length of the mapped memory is DPRAM_MAPLEN and the physical address is DPRAM_PHYS.
If sucessful it sets a global ptr ‘dpram’ to the base of the mapped area.
Then I use this pointer for i/o. (I range-check the pointer when accessing the data as well)

/*****************************************
*

  • Init the memory mapped between the PC104 space and DPRAM

*/
int init_dpram_io( void )
{

void *ptr;

ptr =	mmap_device_memory( 0, DPRAM_MAPLEN, (PROT_READ | PROT_WRITE | PROT_NOCACHE), 0, DPRAM_PHYS );
if( ptr == MAP_FAILED )
{
	printf( "Failed\n" );
	return 1;
}
else
{
	dpram = (unsigned char *)(ptr);
}

return 0;

}

Hope this helps.

Ian