simple access to mem mapped peripheral

Matthias Fuchs matthias.fuchs at esd-electronics.com
Thu Oct 4 20:07:21 EST 2001


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/





More information about the Linuxppc-embedded mailing list