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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [rtl/] [core/] [neorv32_gpio.vhd] - Blame information for rev 9

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 zero_gravi
-- #################################################################################################
2
-- # << NEORV32 - General Purpose Parallel Input/Output Port (GPIO) >>                             #
3
-- # ********************************************************************************************* #
4
-- # 16-bit parallel input & output unit. Any pin-change (HI->LO or LO->HI) triggers the IRQ.      #
5
-- # ********************************************************************************************* #
6
-- # BSD 3-Clause License                                                                          #
7
-- #                                                                                               #
8
-- # Copyright (c) 2020, Stephan Nolting. All rights reserved.                                     #
9
-- #                                                                                               #
10
-- # Redistribution and use in source and binary forms, with or without modification, are          #
11
-- # permitted provided that the following conditions are met:                                     #
12
-- #                                                                                               #
13
-- # 1. Redistributions of source code must retain the above copyright notice, this list of        #
14
-- #    conditions and the following disclaimer.                                                   #
15
-- #                                                                                               #
16
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
17
-- #    conditions and the following disclaimer in the documentation and/or other materials        #
18
-- #    provided with the distribution.                                                            #
19
-- #                                                                                               #
20
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
21
-- #    endorse or promote products derived from this software without specific prior written      #
22
-- #    permission.                                                                                #
23
-- #                                                                                               #
24
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
25
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
26
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
27
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
28
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
29
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
30
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
31
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
32
-- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
33
-- # ********************************************************************************************* #
34
-- # The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting #
35
-- #################################################################################################
36
 
37
library ieee;
38
use ieee.std_logic_1164.all;
39
use ieee.numeric_std.all;
40
 
41
library neorv32;
42
use neorv32.neorv32_package.all;
43
 
44
entity neorv32_gpio is
45
  port (
46
    -- host access --
47
    clk_i  : in  std_ulogic; -- global clock line
48
    addr_i : in  std_ulogic_vector(31 downto 0); -- address
49
    rden_i : in  std_ulogic; -- read enable
50
    wren_i : in  std_ulogic; -- write enable
51
    ben_i  : in  std_ulogic_vector(03 downto 0); -- byte write enable
52
    data_i : in  std_ulogic_vector(31 downto 0); -- data in
53
    data_o : out std_ulogic_vector(31 downto 0); -- data out
54
    ack_o  : out std_ulogic; -- transfer acknowledge
55
    -- parallel io --
56
    gpio_o : out std_ulogic_vector(15 downto 0);
57
    gpio_i : in  std_ulogic_vector(15 downto 0);
58
    -- interrupt --
59
    irq_o  : out std_ulogic
60
  );
61
end neorv32_gpio;
62
 
63
architecture neorv32_gpio_rtl of neorv32_gpio is
64
 
65
  -- IO space: module base address --
66
  constant hi_abb_c : natural := index_size_f(io_size_c)-1; -- high address boundary bit
67
  constant lo_abb_c : natural := index_size_f(gpio_size_c); -- low address boundary bit
68
 
69
  -- access control --
70
  signal acc_en : std_ulogic; -- module access enable
71
  signal addr   : std_ulogic_vector(31 downto 0); -- access address
72
 
73
  -- accessible regs --
74
  signal din  : std_ulogic_vector(15 downto 0); -- r/w
75
  signal dout : std_ulogic_vector(15 downto 0); -- r/w
76
 
77
  -- misc --
78
  signal in_buf, din2 : std_ulogic_vector(15 downto 0);
79
 
80
begin
81
 
82
  -- Access Control -------------------------------------------------------------------------
83
  -- -------------------------------------------------------------------------------------------
84
  acc_en <= '1' when (addr_i(hi_abb_c downto lo_abb_c) = gpio_base_c(hi_abb_c downto lo_abb_c)) else '0';
85
  addr   <= gpio_base_c(31 downto lo_abb_c) & addr_i(lo_abb_c-1 downto 2) & "00"; -- word aligned
86
 
87
 
88
  -- Read/Write Access ----------------------------------------------------------------------
89
  -- -------------------------------------------------------------------------------------------
90
  rw_access: process(clk_i)
91
  begin
92
    if rising_edge(clk_i) then
93
      ack_o <= acc_en and (rden_i or wren_i);
94
      -- write access --
95
      if ((acc_en and wren_i) = '1') then
96
        if (addr = gpio_out_addr_c) then
97
          for i in 0 to 1 loop
98
            if (ben_i(i) = '1') then
99
              dout(7+i*8 downto 0+i*8) <= data_i(7+i*8 downto 0+i*8);
100
            end if;
101
          end loop;
102
        end if;
103
      end if;
104
      -- read access --
105
      data_o <= (others => '0');
106
      if ((acc_en and rden_i) = '1') then
107
        if (addr = gpio_in_addr_c) then
108
          data_o(15 downto 0) <= din;
109
        else -- gpio_out_addr_c
110
          data_o(15 downto 0) <= dout;
111
        end if;
112
      end if;
113
    end if;
114
  end process rw_access;
115
 
116
  -- output --
117
  gpio_o <= dout;
118
 
119
 
120
  -- IRQ Detector ------------------------------------------------------------
121
  -- -----------------------------------------------------------------------------
122
  irq_detector: process(clk_i)
123
  begin
124
    if rising_edge(clk_i) then
125
      -- input synchronizer --
126
      in_buf <= gpio_i;
127
      din    <= in_buf;
128
      din2   <= din;
129
      -- IRQ --
130
      irq_o <= or_all_f(din xor din2); -- any transition triggers an interrupt
131
    end if;
132
  end process irq_detector;
133
 
134
 
135
end neorv32_gpio_rtl;

powered by: WebSVN 2.1.0

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