View topic - I try to use mmap() to access dual port ram but not work

I try to use mmap() to access dual port ram but not work

anything that doesn't fit to other groups.

I try to use mmap() to access dual port ram but not work

Postby watcharin » Tue Oct 14, 2003 1:38 pm

I try to use mmap() function to access dual port ram but not work. data is not correct, which my c code is

long *x, *y;

main ()
{
fd = shm_open(" /botts",O_RDWR|O_CREAT, 0777);
x = mmap(0x0800,1024*1024,
PROT_NOCACHE|PROT_READ|PROT_WRITE,
MAP_SHARED|MAP_PHYS,fd,0);

y = (long *)(0x0804);
printf( " address %6.6X\n",y);
printf( " data %d\n",*y);
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
on Dos version i use

y = (long *)(MK_FP(0x0800,0x0804));
printf( " address %6.6X\n",y);
printf( " data %d\n",*y);


How to correct it based on QNX 6.2
watcharin
New Member
 
Posts: 8
Joined: Wed Sep 10, 2003 10:20 pm

Postby xtang » Wed Oct 15, 2003 3:54 pm

x = mmap_device_memory(0, 1024 * 1024,
PROT_NOCACHE|PROT_READ|PROT_WRITE,
0, 0x0800);
if (x != (long *)MAP_FAILED) {
y = (long *)((char *)x + 4);
printf(" address %6.6X\n", y);
printf(" data %d\n", *y);
}


-xtang
xtang
QNX Master
 
Posts: 313
Joined: Thu Jul 18, 2002 5:01 pm

Postby mario » Wed Oct 15, 2003 4:04 pm

A little more info. QNX is based on virtual addressing, Mmaping insertes in your virtual address space the physical memory location you specify. But that doesn't mean you can access it by specifying the physical address. Mmap returns a virtual pointer to the physical memory, and it can only be reference through that address, which is 99% of the time no the same as the physical address.

You program probably crashed (SIGSEGV) because you tried to access memory that was not in your virtual space.

That being said 0x800 sounds like a weird address to me (assuming it's a PC). I don't recall what MK_FP exaclty does but from memory 0x800 for segment and 0x804 for data equal to physical address (0x8804) not 0x800.

- Mario
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am


Return to General Programming

Who is online

Users browsing this forum: No registered users and 2 guests