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

Subversion Repositories neorv32

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

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 70 zero_gravi
-- # 64-bit general purpose parallel input & output port unit. Input/outputs are split into two    #
5
-- # 32-bit memory-mapped registers each.                                                          #
6 2 zero_gravi
-- # ********************************************************************************************* #
7
-- # BSD 3-Clause License                                                                          #
8
-- #                                                                                               #
9 70 zero_gravi
-- # Copyright (c) 2022, 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 70 zero_gravi
    err_o  : out std_ulogic; -- transfer error
56 2 zero_gravi
    -- parallel io --
57 61 zero_gravi
    gpio_o : out std_ulogic_vector(63 downto 0);
58
    gpio_i : in  std_ulogic_vector(63 downto 0)
59 2 zero_gravi
  );
60
end neorv32_gpio;
61
 
62
architecture neorv32_gpio_rtl of neorv32_gpio is
63
 
64
  -- IO space: module base address --
65
  constant hi_abb_c : natural := index_size_f(io_size_c)-1; -- high address boundary bit
66
  constant lo_abb_c : natural := index_size_f(gpio_size_c); -- low address boundary bit
67
 
68
  -- access control --
69
  signal acc_en : std_ulogic; -- module access enable
70
  signal addr   : std_ulogic_vector(31 downto 0); -- access address
71 66 zero_gravi
  signal wren   : std_ulogic; -- word write enable
72
  signal rden   : std_ulogic; -- read enable
73 2 zero_gravi
 
74
  -- accessible regs --
75 70 zero_gravi
  signal din_hi,  din_lo  : std_ulogic_vector(31 downto 0); -- r/-: parallel input hi/lo
76
  signal dout_hi, dout_lo : std_ulogic_vector(31 downto 0); -- r/w: parallel output hi/lo
77 2 zero_gravi
 
78
begin
79
 
80
  -- Access Control -------------------------------------------------------------------------
81
  -- -------------------------------------------------------------------------------------------
82
  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';
83
  addr   <= gpio_base_c(31 downto lo_abb_c) & addr_i(lo_abb_c-1 downto 2) & "00"; -- word aligned
84 66 zero_gravi
  wren   <= acc_en and wren_i;
85
  rden   <= acc_en and rden_i;
86 2 zero_gravi
 
87
 
88
  -- Read/Write Access ----------------------------------------------------------------------
89
  -- -------------------------------------------------------------------------------------------
90
  rw_access: process(clk_i)
91
  begin
92
    if rising_edge(clk_i) then
93 61 zero_gravi
      -- bus handshake --
94 70 zero_gravi
      ack_o <= (wren and addr(3)) or rden;
95
      err_o <= wren and (not addr(3)); -- INPUT registers are read only!
96 61 zero_gravi
 
97 2 zero_gravi
      -- write access --
98 66 zero_gravi
      if (wren = '1') then
99 61 zero_gravi
        if (addr = gpio_out_lo_addr_c) then
100
          dout_lo <= data_i;
101 2 zero_gravi
        end if;
102 61 zero_gravi
        if (addr = gpio_out_hi_addr_c) then
103
          dout_hi <= data_i;
104
        end if;
105 2 zero_gravi
      end if;
106 61 zero_gravi
 
107 70 zero_gravi
      -- input buffer (prevent metastability) --
108 61 zero_gravi
      din_lo <= gpio_i(31 downto 00);
109
      din_hi <= gpio_i(63 downto 32);
110
 
111 2 zero_gravi
      -- read access --
112
      data_o <= (others => '0');
113 66 zero_gravi
      if (rden = '1') then
114
        case addr(3 downto 2) is
115
          when "00"   => data_o <= din_lo;
116
          when "01"   => data_o <= din_hi;
117
          when "10"   => data_o <= dout_lo;
118
          when others => data_o <= dout_hi;
119 61 zero_gravi
        end case;
120 2 zero_gravi
      end if;
121 61 zero_gravi
 
122 2 zero_gravi
    end if;
123
  end process rw_access;
124
 
125
  -- output --
126 61 zero_gravi
  gpio_o <= dout_hi & dout_lo;
127 2 zero_gravi
 
128
 
129
end neorv32_gpio_rtl;

powered by: WebSVN 2.1.0

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