mmap
Brett McNerney
mcnernbm at notes.udayton.edu
Thu Jan 5 17:16:29 EST 2006
I have been trying to work with mmap to read and write to a custom hardware
module on a Xilinx virtex 4 board with linux running on the ppc. But I have
gotten many different errors. But the main one I am seeing is segmentation
error. Below is the code I am using. The device has a 256 address size
specified in the Xilinx tools and the base address I set in the Xilinx tools
was 0x81000000. Am I doing something wrong in the code? Any help would be
greatly appreciated as we have decided to try this method instead of using a
driver built into the kernel as this allows us some more flexibility. Also
the hardware module I am using for testing contains 3 hardware registers
which adds two of the registers and returns the result in the third one.
I am open for other options on how I can do this other then mmap. And am
still not against a driver built into the kernel if someone has a an example
I could see and can explain how to add it in so it builds into the kernel
since I have had no success on that either and have tried a couple different
tutorials I found online with no success.
Thanks for any help anyone can provide.
Brett
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
int main(void) {
int fd;
int *p;
fd = open("/dev/mem, O_RDWR);
p = (int *)mmap(0, 256, PROT_READ|PROT_WRITE,
MAP_PRIVATE, fd, 0x81000000);
if (p == MAP_FAILED) {
printf("Err: cannot access adder!/n");
return -1;
}
printf("input two numbers: ");
scanf("%d", &p);
scanf("%d", &p+1);
printf("%d + %d = %d\n", *p, *(p+1), *(p+2));
munmap(p,256);
close(fd);
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ozlabs.org/pipermail/linuxppc-embedded/attachments/20060105/f9fc9893/attachment.htm
More information about the Linuxppc-embedded
mailing list