Root/cap_keyboard/src/user_space/jz47xx_mmap.c

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
17void *
18jz_mmap (off_t address)
19{
20  int fd;
21
22  void *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 = (void *) mmap (0, getpagesize (), PROT_READ | PROT_WRITE, MAP_SHARED, fd, address);
31
32  if (pio == (void *) -1)
33    {
34      fprintf (stderr, "Cannot mmap.\n");
35      return 0;
36    }
37
38  return pio;
39}
40
41void *
42jz_fpga_map (off_t address)
43{
44  int fd;
45
46  void *fpga;
47
48  if ((fd = open ("/dev/mem", O_RDWR | O_SYNC)) == -1)
49    {
50      fprintf (stderr, "Cannot open /dev/mem.\n");
51      return 0;
52    }
53
54  fpga = (void *) mmap (0, FPGA_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, address);
55
56  if (fpga == (void *) -1)
57    {
58      fprintf (stderr, "Cannot mmap.\n");
59      return 0;
60    }
61
62  return fpga;
63}
64
65

Archive Download this file

Branches:
master



interactive