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

Subversion Repositories neorv32

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

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

powered by: WebSVN 2.1.0

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