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

Subversion Repositories neorv32

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

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

powered by: WebSVN 2.1.0

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