Subject: Re: simple access to mem mapped peripheral

From: Matthias Fuchs <[email-masked]>
Date: Thu, 04 Oct 2001 12:07:21 +0200

Hi Pierre,

thanks. mmap is working fine for my problem ! I wonder why lseek'ing and
reading does not work.

Matthias

Pierre AUBERT wrote:

> I think that you can try the mmap function :
>
>     int mmap_fd;
>
>     /* Open the memory device and mmap the chip registers     */
>     if ((mmap_fd = open("/dev/mem", O_RDWR)) < 0 ) {
>         perror("open(/dev/mem)");
>         exit(1);
>     }
>     ptr = (chip_register *)mmap(NULL, CHIP_MEM_SIZE,
>                           (PROT_READ|PROT_WRITE),
>                           MAP_SHARED, mmap_fd, CHIP_PHYSICAL_ADDRESS);
>     if ( ((int)ptr) < 0 ) {
>         perror("mmap()");
>         close(mmap_fd);
>         exit(1);
>     }
>     else {
>
>         /* Read and write your chip registers ... */
>
>         munmap (ptr, CHIP_MEM_SIZE);
>         close(mmap_fd);
>     }
>

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/