Root/Software/sie_cg/templates/basic/jz47xx_mmap.cpp

1/*
2 * JZ47xx GPIO lines
3 *
4 * Written 2010 by Andres Calderon andres.calderon@emqbit.com
5 */
6
7#include "jz47xx_mmap.h"
8
9unsigned int *
10jz_mmap (off_t address)
11{
12  int fd;
13
14  unsigned int *pio;
15
16  if ((fd = open ("/dev/mem", O_RDWR | O_SYNC)) == -1)
17    {
18      fprintf (stderr, "Cannot open /dev/mem.\n");
19      return 0;
20    }
21
22  pio = (unsigned int *) mmap (0, getpagesize (), PROT_READ | PROT_WRITE, MAP_SHARED, fd, address);
23
24  if (pio == (unsigned int *) -1)
25    {
26      fprintf (stderr, "Cannot mmap.\n");
27      return 0;
28    }
29
30  return pio;
31}
32
33

Archive Download this file

Branches:
master



interactive