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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [rtl/] [core/] [neorv32_wishbone.vhd] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 zero_gravi
-- #################################################################################################
2
-- # << NEORV32 - External Bus Interface (WISHBONE) >>                                             #
3
-- # ********************************************************************************************* #
4
-- # The interface is either unregistered (INTERFACE_REG_STAGES = 0), only outgoing signals are    #
5
-- # registered (INTERFACE_REG_STAGES = 1) or incoming and outgoing signals are registered         #
6
-- # (INTERFACE_REG_STAGES = 2).                                                                   #
7
-- #                                                                                               #
8
-- # All bus accesses from the CPU, which do not target the internal IO region, the internal boot- #
9
-- # loader or the internal instruction & data memories (if implemented), are delegated via this   #
10
-- # Wishbone gateway to the external bus interface.                                               #
11
-- # ********************************************************************************************* #
12
-- # BSD 3-Clause License                                                                          #
13
-- #                                                                                               #
14
-- # Copyright (c) 2020, Stephan Nolting. All rights reserved.                                     #
15
-- #                                                                                               #
16
-- # Redistribution and use in source and binary forms, with or without modification, are          #
17
-- # permitted provided that the following conditions are met:                                     #
18
-- #                                                                                               #
19
-- # 1. Redistributions of source code must retain the above copyright notice, this list of        #
20
-- #    conditions and the following disclaimer.                                                   #
21
-- #                                                                                               #
22
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
23
-- #    conditions and the following disclaimer in the documentation and/or other materials        #
24
-- #    provided with the distribution.                                                            #
25
-- #                                                                                               #
26
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
27
-- #    endorse or promote products derived from this software without specific prior written      #
28
-- #    permission.                                                                                #
29
-- #                                                                                               #
30
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
31
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
32
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
33
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
34
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
35
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
36
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
37
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
38
-- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
39
-- # ********************************************************************************************* #
40
-- # The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting #
41
-- #################################################################################################
42
 
43
library ieee;
44
use ieee.std_logic_1164.all;
45
use ieee.numeric_std.all;
46
 
47
library neorv32;
48
use neorv32.neorv32_package.all;
49
 
50
entity neorv32_wishbone is
51
  generic (
52
    INTERFACE_REG_STAGES : natural := 2; -- number of interface register stages (0,1,2)
53
    -- Memory configuration: Instruction memory --
54
    MEM_ISPACE_BASE      : std_ulogic_vector(31 downto 0) := x"00000000"; -- base address of instruction memory space
55
    MEM_ISPACE_SIZE      : natural := 8*1024; -- total size of instruction memory space in byte
56
    MEM_INT_IMEM_USE     : boolean := true;   -- implement processor-internal instruction memory
57
    MEM_INT_IMEM_SIZE    : natural := 8*1024; -- size of processor-internal instruction memory in bytes
58
    -- Memory configuration: Data memory --
59
    MEM_DSPACE_BASE      : std_ulogic_vector(31 downto 0) := x"80000000"; -- base address of data memory space
60
    MEM_DSPACE_SIZE      : natural := 4*1024; -- total size of data memory space in byte
61
    MEM_INT_DMEM_USE     : boolean := true;   -- implement processor-internal data memory
62
    MEM_INT_DMEM_SIZE    : natural := 4*1024  -- size of processor-internal data memory in bytes
63
  );
64
  port (
65
    -- global control --
66
    clk_i    : in  std_ulogic; -- global clock line
67
    rstn_i   : in  std_ulogic; -- global reset line, low-active
68
    -- host access --
69
    addr_i   : in  std_ulogic_vector(31 downto 0); -- address
70
    rden_i   : in  std_ulogic; -- read enable
71
    wren_i   : in  std_ulogic; -- write enable
72
    ben_i    : in  std_ulogic_vector(03 downto 0); -- byte write enable
73
    data_i   : in  std_ulogic_vector(31 downto 0); -- data in
74
    data_o   : out std_ulogic_vector(31 downto 0); -- data out
75
    ack_o    : out std_ulogic; -- transfer acknowledge
76
    err_o    : out std_ulogic; -- transfer error
77
    -- wishbone interface --
78
    wb_adr_o : out std_ulogic_vector(31 downto 0); -- address
79
    wb_dat_i : in  std_ulogic_vector(31 downto 0); -- read data
80
    wb_dat_o : out std_ulogic_vector(31 downto 0); -- write data
81
    wb_we_o  : out std_ulogic; -- read/write
82
    wb_sel_o : out std_ulogic_vector(03 downto 0); -- byte enable
83
    wb_stb_o : out std_ulogic; -- strobe
84
    wb_cyc_o : out std_ulogic; -- valid cycle
85
    wb_ack_i : in  std_ulogic; -- transfer acknowledge
86
    wb_err_i : in  std_ulogic  -- transfer error
87
  );
88
end neorv32_wishbone;
89
 
90
architecture neorv32_wishbone_rtl of neorv32_wishbone is
91
 
92
  -- access control --
93
  signal int_imem_acc, int_imem_acc_real : std_ulogic;
94
  signal int_dmem_acc, int_dmem_acc_real : std_ulogic;
95
  signal int_boot_acc, int_io_acc        : std_ulogic;
96
  signal wb_access                       : std_ulogic;
97
 
98
  -- bus arbiter --
99
  signal wb_stb_ff0 : std_ulogic;
100
  signal wb_stb_ff1 : std_ulogic;
101
  signal wb_cyc_ff  : std_ulogic;
102
  signal wb_ack_ff  : std_ulogic;
103
  signal wb_err_ff  : std_ulogic;
104
 
105
begin
106
 
107
  -- Sanity Check ---------------------------------------------------------------------------
108
  -- -------------------------------------------------------------------------------------------
109
  sanity_check: process(clk_i)
110
  begin
111
    if rising_edge(clk_i) then -- just for simulation
112
      if (INTERFACE_REG_STAGES > 2) then
113
        assert false report "NEORV32 CONFIG ERROR! Number of external memory interface buffer stages must be 0, 1 or 2." severity error;
114
      end if;
115
    end if;
116
  end process sanity_check;
117
 
118
 
119
  -- Access Control -------------------------------------------------------------------------
120
  -- -------------------------------------------------------------------------------------------
121
  -- access to internal IMEM or DMEM? --
122
  int_imem_acc <= '1' when (addr_i >= MEM_ISPACE_BASE) and (addr_i < std_ulogic_vector(unsigned(MEM_ISPACE_BASE) + MEM_INT_IMEM_SIZE)) else '0';
123
  int_dmem_acc <= '1' when (addr_i >= MEM_DSPACE_BASE) and (addr_i < std_ulogic_vector(unsigned(MEM_DSPACE_BASE) + MEM_INT_DMEM_SIZE)) else '0';
124
  int_imem_acc_real <= int_imem_acc when (MEM_INT_IMEM_USE = true) else '0';
125
  int_dmem_acc_real <= int_dmem_acc when (MEM_INT_DMEM_USE = true) else '0';
126
  int_boot_acc <= '1' when (addr_i >= boot_base_c) else '0';
127
  int_io_acc   <= '1' when (addr_i >= io_base_c)   else '0';
128
 
129
  -- actual external bus access? --
130
  wb_access <= (not int_imem_acc_real) and (not int_dmem_acc_real) and (not int_boot_acc) and (not int_io_acc) and (wren_i or rden_i);
131
 
132
 
133
  -- Bus Arbiter -----------------------------------------------------------------------------
134
  -- -------------------------------------------------------------------------------------------
135
  bus_arbiter: process(rstn_i, clk_i)
136
  begin
137
    if (rstn_i = '0') then
138
      wb_cyc_ff  <= '0';
139
      wb_stb_ff1 <= '0';
140
      wb_stb_ff0 <= '0';
141
      wb_ack_ff  <= '0';
142
      wb_err_ff  <= '0';
143
    elsif rising_edge(clk_i) then
144
      -- bus cycle --
145
      if (INTERFACE_REG_STAGES = 0) then
146
        wb_cyc_ff <= '0'; -- unused
147
      elsif (INTERFACE_REG_STAGES = 1) then
148
        wb_cyc_ff <= wb_access and ((not wb_ack_i) or (not wb_err_i));
149
      elsif (INTERFACE_REG_STAGES = 2) then
150
        wb_cyc_ff <= wb_access and ((not wb_ack_ff) or (not wb_err_ff));
151
      end if;
152
      -- bus strobe --
153
      wb_stb_ff1 <= wb_stb_ff0;
154
      wb_stb_ff0 <= wb_access;
155
      -- bus ack --
156
      wb_ack_ff <= wb_ack_i;
157
      -- bus err --
158
      wb_err_ff <= wb_err_i;
159
    end if;
160
  end process bus_arbiter;
161
 
162
  -- bus cycle --
163
  wb_cyc_o <= wb_access when (INTERFACE_REG_STAGES = 0) else wb_cyc_ff;
164
 
165
  -- bus_strobe: rising edge detector --
166
  wb_stb_o <= (wb_access and (not wb_stb_ff0)) when (INTERFACE_REG_STAGES = 0) else (wb_stb_ff0 and (not wb_stb_ff1));
167
 
168
  -- cpu ack --
169
  ack_o <= wb_ack_ff when (INTERFACE_REG_STAGES = 2) else wb_ack_i;
170
 
171
  -- cpu err --
172
  err_o <= wb_err_ff when (INTERFACE_REG_STAGES = 2) else wb_err_i;
173
 
174
 
175
  -- Bus Buffer -----------------------------------------------------------------------------
176
  -- -------------------------------------------------------------------------------------------
177
  interface_reg_level_zero:
178
  if (INTERFACE_REG_STAGES = 0) generate -- 0 register levels: direct connection
179
    data_o   <= wb_dat_i;
180
    wb_adr_o <= addr_i;
181
    wb_dat_o <= data_i;
182
    wb_sel_o <= ben_i;
183
    wb_we_o  <= wren_i;
184
  end generate;
185
 
186
  interface_reg_level_one:
187
  if (INTERFACE_REG_STAGES = 1) generate -- 1 register levels: buffer outgoing signals
188
    buffer_stages_one: process(clk_i)
189
    begin
190
      if rising_edge(clk_i) then
191
        wb_adr_o <= addr_i;
192
        wb_dat_o <= data_i;
193
        wb_sel_o <= ben_i;
194
        wb_we_o  <= wren_i;
195
      end if;
196
    end process buffer_stages_one;
197
    data_o <= wb_dat_i;
198
  end generate;
199
 
200
  interface_reg_level_two:
201
  if (INTERFACE_REG_STAGES = 2) generate -- 2 register levels: buffer incoming and outgoing signals
202
    buffer_stages_two: process(clk_i)
203
    begin
204
      if rising_edge(clk_i) then
205
        wb_adr_o <= addr_i;
206
        wb_dat_o <= data_i;
207
        wb_sel_o <= ben_i;
208
        wb_we_o  <= wren_i;
209
        data_o   <= wb_dat_i;
210
      end if;
211
    end process buffer_stages_two;
212
  end generate;
213
 
214
 
215
end neorv32_wishbone_rtl;

powered by: WebSVN 2.1.0

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