Root/Software/sie_cg/templates/basic (copy)/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
33void
34jz_cs2_init()
35{
36    JZ_PIO *pio;
37
38    pio = jz_gpio_map (CS2_PORT);
39    jz_gpio_as_func (pio, CS2_PIN, 0);
40
41    virt_addr = (JZ_REG *) (jz_mmap(0x13010000) + 0x18);
42
43    if (*virt_addr != 0x0FFF7700)
44    {
45        *virt_addr = 0x0FFF7700;
46        printf ("ADC: Configuring CS2 8 bits and 0 WS: %08X\n", *virt_addr);
47    }
48    else
49        printf ("ADC: CS2, already configured: %08X\n", *virt_addr);
50
51    virt_addr = (JZ_REG *) jz_mmap (0x14000000);
52}
53
54

Archive Download this file

Branches:
master



interactive