OpenCores
URL https://opencores.org/ocsvn/mips_enhanced/mips_enhanced/trunk

Subversion Repositories mips_enhanced

[/] [mips_enhanced/] [trunk/] [grlib-gpl-1.0.19-b3188/] [lib/] [openchip/] [gpio/] [apbgpio.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimamali
----------------------------------------------------------------------------
2
--  This file is a part of the GRLIB VHDL IP LIBRARY
3
--  Copyright (C) 2004 GAISLER RESEARCH
4
--
5
--  This program is free software; you can redistribute it and/or modify
6
--  it under the terms of the GNU General Public License as published by
7
--  the Free Software Foundation; either version 2 of the License, or
8
--  (at your option) any later version.
9
--
10
--  See the file COPYING for the full details of the license.
11
--
12
-----------------------------------------------------------------------------
13
-- Entity:      gpio
14
-- File:        apbgpio.vhd
15
-- Author:      Antti Lukats, OpenChip
16
-- Description: General Purpose I/O
17
--
18
------------------------------------------------------------------------------
19
 
20
library ieee;
21
use ieee.std_logic_1164.all;
22
library grlib;
23
use grlib.amba.all;
24
use grlib.stdlib.all;
25
use grlib.devices.all;
26
 
27
library openchip;
28
use openchip.gpio.all;
29
 
30
--pragma translate_off
31
use std.textio.all;
32
--pragma translate_on
33
 
34
entity apbgpio is
35
  generic (
36
    pindex  : integer := 0;
37
    paddr   : integer := 0;
38
    pmask   : integer := 16#fff#;
39
    pirq    : integer := 0);
40
  port (
41
    rst    : in  std_ulogic;
42
    clk    : in  std_ulogic;
43
    apbi   : in  apb_slv_in_type;
44
    apbo   : out apb_slv_out_type;
45
    gpioi  : in  gpio_in_type;
46
    gpioo  : out gpio_out_type);
47
end;
48
 
49
architecture rtl of apbgpio is
50
 
51
constant REVISION : integer := 0;
52
 
53
constant pconfig : apb_config_type := (
54
 
55
  1 => apb_iobar(paddr, pmask));
56
 
57
type gpioregs is record
58
  outreg        :  std_logic_vector(31 downto 0); -- Output Latch
59
  dirreg        :  std_logic_vector(31 downto 0); -- Direction Register
60
  inreg         :  std_logic_vector(31 downto 0); -- Input Latch
61
  irq           :  std_ulogic;  -- interrupt (internal), not used
62
end record;
63
 
64
signal r, rin : gpioregs;
65
 
66
begin
67
 
68
  comb : process(rst, r, apbi, gpioi )
69
 
70
  variable rdata : std_logic_vector(31 downto 0);
71
  variable irq   : std_logic_vector(NAHBIRQ-1 downto 0);
72
  variable v : gpioregs;
73
 
74
  begin
75
    v := r;
76
    v.inreg := gpioi.d_in;
77
 
78
    irq := (others => '0');
79
    --irq(pirq) := r.irq;
80
    v.irq := '0';
81
    rdata := (others => '0');
82
 
83
-- read/write registers
84
 
85
    case apbi.paddr(3 downto 2) is
86
    when "00" =>
87
      rdata(31 downto 0) := r.inreg;  -- read IO pin
88
    when "01" =>
89
      rdata(31 downto 0) := r.dirreg; -- read back of direction reg ?
90
    when others =>
91
    end case;
92
 
93
    if (apbi.psel(pindex) and apbi.penable and apbi.pwrite) = '1' then
94
      case apbi.paddr(3 downto 2) is
95
      when "00" =>
96
        v.outreg := apbi.pwdata(31 downto 0);
97
      when "01" =>
98
        v.dirreg := apbi.pwdata(31 downto 0);
99
      when others =>
100
      end case;
101
    end if;
102
 
103
-- reset operation
104
 
105
    if rst = '0' then
106
      v.outreg := (others => '0');
107
      v.dirreg := (others => '0');
108
    end if;
109
 
110
-- update registers
111
 
112
    rin <= v;
113
 
114
-- drive outputs
115
 
116
 
117
    gpioo.d_out <= r.outreg;
118
    gpioo.t_out <= r.dirreg;
119
 
120
    apbo.prdata <= rdata;
121
    apbo.pirq <= irq;
122
    apbo.pindex <= pindex;
123
 
124
  end process;
125
 
126
  apbo.pconfig <= pconfig;
127
 
128
  regs : process(clk)
129
  begin
130
    if rising_edge(clk) then
131
      r <= rin;
132
    end if;
133
  end process;
134
 
135
-- pragma translate_off
136
    bootmsg : report_version
137
    generic map ("apbgpio" & tost(pindex) &
138
        ": Generic GPIO rev " & tost(REVISION) & ", irq " & tost(pirq));
139
-- pragma translate_on
140
 
141
end;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.