Root/Examples/sram_gpio/src/jz_init_sram.c

1/* SAKC FPGA/SRAM interface test
2
3Copyright (C) 2010 Carlos Camargo cicamargoba@unal.edu.co
4                               Andres Calderon andres.calderon@emqbit.com
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
19
20#include <stdio.h>
21#include <unistd.h>
22#include <stdlib.h>
23
24#include "jz47xx_gpio.h"
25#include "jz47xx_mmap.h"
26
27#define CS2_PORT JZ_GPIO_PORT_B
28#define CS2_PIN 26
29
30int
31main ()
32{
33  int i;
34  JZ_PIO *pio;
35  int *virt_addr;
36
37  // Set GPIOB26 as part of External Memory Controller
38  pio = jz_gpio_map (CS2_PORT);
39  jz_gpio_as_func (pio, CS2_PIN, 0);
40
41  virt_addr = (int *) jz_mmap (0x13010000) + 0x18;
42
43  if (*virt_addr != 0xFFF7700)
44    { // 0 WS, 8 bits
45      *virt_addr = 0xFFF7700;
46      printf ("Configuring CS2 8 bits \n");
47    }
48  else
49    printf ("CS3, already configured\n");
50
51  virt_addr = (int *) jz_fpga_map (0x15000000);
52
53  printf ("Writing Memory..\n");
54
55  for (i = 0; i < 0xff; i++)
56      virt_addr[i] = i;
57
58  printf ("Reading Memory..\n");
59  for (i = 0; i < 0xff; i++){
60    printf("W:%X, R:%X\n", i, virt_addr[i]);
61  }
62
63  return 0;
64}
65

Archive Download this file

Branches:
master



interactive