Quote:
Originally Posted by sunr2007
yes u can use tat memory by using mmap () system call by using the /dev/mem/ interface . but u will not get good performance . u should use mmap() only when u dont av any other choice. to use mmap u should declare something like this
#define MAP_SIZE 4096
#define MAP_MASK (MAP_SIZE-1)
off_t target=0xFFFFF43C; //the physical address which u should know.
and use mmap() similar to below.
map_base=mmap(0,MAP_SIZE,PROT_READ|PROT_WRITE,MAP_SHARED,fd1,target & ~ MAP_MASK);
if(map_base == (void *) -1)
{
perror("map_base"); exit(-1);
}
the above i have used for ARM 9 based AT91SAM9261
or best is u can convert this to kernel space by using a mofule. tat way ur performance will be better.
warm regards,
Ravi Kulkarni.
|
Thanks a lot Ravi for the reply. I tried mmap, the way you told me, on my desktop computer first but I could not write to the mapped memory. mmap() returns a valid pointer and I can read the data at that pointer. It always shows FF. When I write at it by assigning a new value, the data at that location doesn't change and it remains FF. What could be wrong? the code that I ran is
///////////////////////////////////////////
#include <stdio.h>
#include <sys/mman.h>
#include <fcntl.h>
#define MAP_SIZE 4096
#define MAP_MASK (MAP_SIZE-1)
off_t target = 0xD000F000;
int main(void)
{
int fd1;
char *map_base;
if((fd1=open("/dev/mem",O_RDWR))==0) {
perror("Error openning file /dev/mem");
return -1;
}
map_base = (char *)mmap(0,MAP_SIZE,PROT_READ|PROT_WRITE,MAP_SHARED,fd1,target&~MAP_MASK);
if(map_base == (void *)-1) {
perror("Error mapping");
return -2;
}
printf("Value at map_base before writing is %2X\n",map_base[0]);
map_base[0] = 1; //***This should alter the value at this memory location***
printf("Value at map_base after writing is %2X\n",map_base[0]);
//***This should print 1 but it prints FF***
return 0;
}
////////////////////////////////////
Regards,
Atif Shabir
.