From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ms-smtp-02-eri0.ohiordc.rr.com (ms-smtp-02-smtplb.ohiordc.rr.com [65.24.5.136]) by ozlabs.org (Postfix) with ESMTP id 523DC68921 for ; Thu, 5 Jan 2006 17:16:39 +1100 (EST) Received: from lilmac (cpe-71-67-143-210.woh.res.rr.com [71.67.143.210]) by ms-smtp-02-eri0.ohiordc.rr.com (8.12.10/8.12.7) with ESMTP id k056GWXX024532 for ; Thu, 5 Jan 2006 01:16:36 -0500 (EST) From: "Brett McNerney" To: Date: Thu, 5 Jan 2006 01:16:29 -0500 Message-ID: <000c01c611bf$92d5f900$0202a8c0@lilmac> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_000D_01C61195.A9FFF100" Subject: mmap List-Id: Linux on Embedded PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , This is a multi-part message in MIME format. ------=_NextPart_000_000D_01C61195.A9FFF100 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 #include #include #include #include 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; } ------=_NextPart_000_000D_01C61195.A9FFF100 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

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 =3D open("/dev/mem, O_RDWR);

      p =3D (int *)mmap(0, 256, = PROT_READ|PROT_WRITE,

           &= nbsp;           &n= bsp;      MAP_PRIVATE, fd, 0x81000000);

      if (p =3D=3D MAP_FAILED) = {

            = printf("Err: cannot access adder!/n");

            = return = -1;

      }

      printf("input two numbers: ");

      scanf("%d", &p);

      scanf("%d", &p+1);

      printf("%d + %d =3D %d\n", *p, *(p+1), *(p+2));

      = munmap(p,256);

      = close(fd);

      return = 0;

}

 

------=_NextPart_000_000D_01C61195.A9FFF100--