linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* mmap
@ 2006-01-05  6:16 Brett McNerney
  0 siblings, 0 replies; 2+ messages in thread
From: Brett McNerney @ 2006-01-05  6:16 UTC (permalink / raw)
  To: linuxppc-embedded

[-- Attachment #1: Type: text/plain, Size: 1785 bytes --]

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;

}

 


[-- Attachment #2: Type: text/html, Size: 9811 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* RE: mmap
@ 2006-01-05 10:03 Fillod Stephane
  0 siblings, 0 replies; 2+ messages in thread
From: Fillod Stephane @ 2006-01-05 10:03 UTC (permalink / raw)
  To: Brett McNerney; +Cc: linuxppc-embedded

Brett McNerney wrote:
[...]
>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.

Ah, this is the first one of 2006. Happy new year!
Your question is a linuxppc-embedded FAQ, coming at least every 3 months
here.
It is documented in Denx's FAQ[1], and accessible through shorter
URL[2].
For more information, please follow this thread[3] (not ppc specific
actually).
A good book of C language about what are pointers and how scanf works
might=20
help too in case of confusion :-)

[1]
http://www.denx.de/twiki/bin/view/PPCEmbedded/DeviceDrivers#Section_Acce
ssingPeripheralsFromUserSpace
[2] http://tinyurl.com/6c7th
[3] http://lists.linuxppc.org/linuxppc-embedded/200403/msg00059.html

Regards,
--=20
Stephane

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-01-05 10:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-05  6:16 mmap Brett McNerney
  -- strict thread matches above, loose matches on Subject: below --
2006-01-05 10:03 mmap Fillod Stephane

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).