Root/Examples/ADC/Test-QT-src/jz47xx_mmap.cpp

Source at commit 9d578912b727722b22319832985451a79ec35747 created 13 years 27 days ago.
By Juan64Bits, Updating prototype of SIE code generator.
1/*
2 * JZ47xx GPIO lines
3 *
4 * Written 2010 by Andres Calderon andres.calderon@emqbit.com
5 */
6
7#include <stdio.h>
8#include <sys/mman.h>
9#include <fcntl.h>
10#include <stdlib.h>
11#include <termios.h>
12#include <unistd.h>
13
14#include <jz47xx_mmap.h>
15
16
17unsigned int *
18jz_mmap (off_t address)
19{
20  int fd;
21
22  unsigned int *pio;
23
24  if ((fd = open ("/dev/mem", O_RDWR | O_SYNC)) == -1)
25    {
26      fprintf (stderr, "Cannot open /dev/mem.\n");
27      return 0;
28    }
29
30  pio = (unsigned int *) mmap (0, getpagesize (), PROT_READ | PROT_WRITE, MAP_SHARED, fd, address);
31
32  if (pio == (unsigned int *) -1)
33    {
34      fprintf (stderr, "Cannot mmap.\n");
35      return 0;
36    }
37
38  return pio;
39}
40

Archive Download this file

Branches:
master



interactive