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

Subversion Repositories neorv32

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

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 31 zero_gravi
-- # (INTERFACE_REG_STAGES = 2). This interface supports classic/standard Wishbone transactions    #
7
-- # (WB_PIPELINED_MODE = false) and also pipelined transactions for improved timing               #
8
-- # (WB_PIPELINED_MODE = true).                                                                   #
9 23 zero_gravi
-- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
10 2 zero_gravi
-- # All bus accesses from the CPU, which do not target the internal IO region, the internal boot- #
11 23 zero_gravi
-- # loader or the internal instruction or data memories (if implemented), are delegated via this  #
12 2 zero_gravi
-- # Wishbone gateway to the external bus interface.                                               #
13
-- # ********************************************************************************************* #
14
-- # BSD 3-Clause License                                                                          #
15
-- #                                                                                               #
16
-- # Copyright (c) 2020, Stephan Nolting. All rights reserved.                                     #
17
-- #                                                                                               #
18
-- # Redistribution and use in source and binary forms, with or without modification, are          #
19
-- # permitted provided that the following conditions are met:                                     #
20
-- #                                                                                               #
21
-- # 1. Redistributions of source code must retain the above copyright notice, this list of        #
22
-- #    conditions and the following disclaimer.                                                   #
23
-- #                                                                                               #
24
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
25
-- #    conditions and the following disclaimer in the documentation and/or other materials        #
26
-- #    provided with the distribution.                                                            #
27
-- #                                                                                               #
28
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
29
-- #    endorse or promote products derived from this software without specific prior written      #
30
-- #    permission.                                                                                #
31
-- #                                                                                               #
32
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
33
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
34
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
35
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
36
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
37
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
38
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
39
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
40
-- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
41
-- # ********************************************************************************************* #
42
-- # The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting #
43
-- #################################################################################################
44
 
45
library ieee;
46
use ieee.std_logic_1164.all;
47
use ieee.numeric_std.all;
48
 
49
library neorv32;
50
use neorv32.neorv32_package.all;
51
 
52
entity neorv32_wishbone is
53
  generic (
54
    INTERFACE_REG_STAGES : natural := 2; -- number of interface register stages (0,1,2)
55 31 zero_gravi
    WB_PIPELINED_MODE    : boolean := false; -- false: classic/standard wishbone mode, true: pipelined wishbone mode
56 23 zero_gravi
    -- Internal instruction memory --
57 2 zero_gravi
    MEM_INT_IMEM_USE     : boolean := true;   -- implement processor-internal instruction memory
58
    MEM_INT_IMEM_SIZE    : natural := 8*1024; -- size of processor-internal instruction memory in bytes
59 23 zero_gravi
    -- Internal data memory --
60 2 zero_gravi
    MEM_INT_DMEM_USE     : boolean := true;   -- implement processor-internal data memory
61
    MEM_INT_DMEM_SIZE    : natural := 4*1024  -- size of processor-internal data memory in bytes
62
  );
63
  port (
64
    -- global control --
65
    clk_i    : in  std_ulogic; -- global clock line
66
    rstn_i   : in  std_ulogic; -- global reset line, low-active
67
    -- host access --
68
    addr_i   : in  std_ulogic_vector(31 downto 0); -- address
69
    rden_i   : in  std_ulogic; -- read enable
70
    wren_i   : in  std_ulogic; -- write enable
71
    ben_i    : in  std_ulogic_vector(03 downto 0); -- byte write enable
72
    data_i   : in  std_ulogic_vector(31 downto 0); -- data in
73
    data_o   : out std_ulogic_vector(31 downto 0); -- data out
74 11 zero_gravi
    cancel_i : in  std_ulogic; -- cancel current bus transaction
75 2 zero_gravi
    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 23 zero_gravi
  signal int_boot_acc                    : std_ulogic;
96 2 zero_gravi
  signal wb_access                       : std_ulogic;
97 23 zero_gravi
  signal wb_access_ff, wb_access_ff_ff   : std_ulogic;
98
  signal rb_en                           : std_ulogic;
99 2 zero_gravi
 
100
  -- bus arbiter --
101 31 zero_gravi
  signal wb_we_ff   : std_ulogic;
102 2 zero_gravi
  signal wb_stb_ff0 : std_ulogic;
103
  signal wb_stb_ff1 : std_ulogic;
104
  signal wb_cyc_ff  : std_ulogic;
105
  signal wb_ack_ff  : std_ulogic;
106
  signal wb_err_ff  : std_ulogic;
107
 
108 31 zero_gravi
  -- wishbone mode: standard / pipelined --
109
  signal stb_int_std  : std_ulogic;
110
  signal stb_int_pipe : std_ulogic;
111
 
112 23 zero_gravi
  -- data read-back --
113
  signal wb_rdata : std_ulogic_vector(31 downto 0);
114
 
115 2 zero_gravi
begin
116
 
117
  -- Sanity Check ---------------------------------------------------------------------------
118
  -- -------------------------------------------------------------------------------------------
119 23 zero_gravi
  assert (INTERFACE_REG_STAGES <= 2) report "NEORV32 CONFIG ERROR! Number of external memory interface buffer stages must be 0, 1 or 2." severity error;
120
  assert (INTERFACE_REG_STAGES /= 0) report "NEORV32 CONFIG WARNING! External memory interface without register stages is still experimental for peripherals with more than 1 cycle latency." severity warning;
121 2 zero_gravi
 
122
 
123
  -- Access Control -------------------------------------------------------------------------
124
  -- -------------------------------------------------------------------------------------------
125
  -- access to internal IMEM or DMEM? --
126 31 zero_gravi
  int_imem_acc <= '1' when (addr_i(31 downto index_size_f(MEM_INT_IMEM_SIZE)) = imem_base_c(31 downto index_size_f(MEM_INT_IMEM_SIZE))) else '0';
127
  int_dmem_acc <= '1' when (addr_i(31 downto index_size_f(MEM_INT_DMEM_SIZE)) = dmem_base_c(31 downto index_size_f(MEM_INT_DMEM_SIZE))) else '0';
128 2 zero_gravi
  int_imem_acc_real <= int_imem_acc when (MEM_INT_IMEM_USE = true) else '0';
129
  int_dmem_acc_real <= int_dmem_acc when (MEM_INT_DMEM_USE = true) else '0';
130 31 zero_gravi
 
131
  -- access to internal BOOTROM or IO devices? --
132 23 zero_gravi
  int_boot_acc <= '1' when (addr_i >= boot_rom_base_c) else '0'; -- this also covers access to the IO space
133 31 zero_gravi
--int_boot_acc <= '1' when (addr_i(31 downto index_size_f(2*boot_rom_max_size_c)) = boot_rom_base_c(31 downto index_size_f(2*boot_rom_max_size_c))) else '0'; -- this also covers access to the IO space
134 23 zero_gravi
--int_io_acc   <= '1' when (addr_i >= io_base_c) else '0';
135 2 zero_gravi
 
136
  -- actual external bus access? --
137 23 zero_gravi
  wb_access <= (not int_imem_acc_real) and (not int_dmem_acc_real) and (not int_boot_acc) and (wren_i or rden_i);
138 2 zero_gravi
 
139
 
140
  -- Bus Arbiter -----------------------------------------------------------------------------
141
  -- -------------------------------------------------------------------------------------------
142
  bus_arbiter: process(rstn_i, clk_i)
143
  begin
144
    if (rstn_i = '0') then
145 31 zero_gravi
      wb_we_ff        <= '0';
146 23 zero_gravi
      wb_cyc_ff       <= '0';
147
      wb_stb_ff1      <= '0';
148
      wb_stb_ff0      <= '0';
149
      wb_ack_ff       <= '0';
150
      wb_err_ff       <= '0';
151
      wb_access_ff    <= '0';
152
      wb_access_ff_ff <= '0';
153 2 zero_gravi
    elsif rising_edge(clk_i) then
154 31 zero_gravi
      -- read/write --
155
      wb_we_ff <= (wb_we_ff or wren_i) and wb_access and (not wb_ack_i) and (not wb_err_i) and (not cancel_i);
156 2 zero_gravi
      -- bus cycle --
157
      if (INTERFACE_REG_STAGES = 0) then
158
        wb_cyc_ff <= '0'; -- unused
159 11 zero_gravi
      else
160 23 zero_gravi
        wb_cyc_ff <= (wb_cyc_ff or wb_access) and (not wb_ack_i) and (not wb_err_i) and (not cancel_i);
161 2 zero_gravi
      end if;
162
      -- bus strobe --
163
      wb_stb_ff1 <= wb_stb_ff0;
164
      wb_stb_ff0 <= wb_access;
165
      -- bus ack --
166
      wb_ack_ff <= wb_ack_i;
167
      -- bus err --
168
      wb_err_ff <= wb_err_i;
169 23 zero_gravi
      -- access still active? --
170
      wb_access_ff_ff <= wb_access_ff;
171
      if (wb_access = '1') then
172
        wb_access_ff <= '1';
173
      elsif ((wb_ack_i or wb_err_i or cancel_i) = '1') then
174
        wb_access_ff <= '0';
175
      end if;
176 2 zero_gravi
    end if;
177
  end process bus_arbiter;
178
 
179 31 zero_gravi
  -- valid bus cycle --
180 2 zero_gravi
  wb_cyc_o <= wb_access when (INTERFACE_REG_STAGES = 0) else wb_cyc_ff;
181
 
182 31 zero_gravi
  -- bus strobe --
183
  stb_int_std  <= wb_access when (INTERFACE_REG_STAGES = 0) else wb_cyc_ff; -- same as wb_cyc
184
  stb_int_pipe <= (wb_access and (not wb_stb_ff0)) when (INTERFACE_REG_STAGES = 0) else (wb_stb_ff0 and (not wb_stb_ff1)); -- wb_access rising edge detector
185
  --
186
  wb_stb_o <= stb_int_std when (WB_PIPELINED_MODE = false) else stb_int_pipe; -- standard or pipelined mode
187 2 zero_gravi
 
188
  -- cpu ack --
189
  ack_o <= wb_ack_ff when (INTERFACE_REG_STAGES = 2) else wb_ack_i;
190
 
191
  -- cpu err --
192
  err_o <= wb_err_ff when (INTERFACE_REG_STAGES = 2) else wb_err_i;
193
 
194 23 zero_gravi
  -- cpu read-data --
195
  rb_en  <= wb_access_ff_ff when (INTERFACE_REG_STAGES = 2) else wb_access_ff;
196
  data_o <= wb_rdata when (rb_en = '1') else (others => '0');
197 2 zero_gravi
 
198 23 zero_gravi
 
199 2 zero_gravi
  -- Bus Buffer -----------------------------------------------------------------------------
200
  -- -------------------------------------------------------------------------------------------
201
  interface_reg_level_zero:
202
  if (INTERFACE_REG_STAGES = 0) generate -- 0 register levels: direct connection
203 23 zero_gravi
    wb_rdata <= wb_dat_i;
204 2 zero_gravi
    wb_adr_o <= addr_i;
205
    wb_dat_o <= data_i;
206
    wb_sel_o <= ben_i;
207 31 zero_gravi
    wb_we_o  <= wren_i or wb_we_ff;
208 2 zero_gravi
  end generate;
209
 
210
  interface_reg_level_one:
211
  if (INTERFACE_REG_STAGES = 1) generate -- 1 register levels: buffer outgoing signals
212
    buffer_stages_one: process(clk_i)
213
    begin
214
      if rising_edge(clk_i) then
215 11 zero_gravi
        if (wb_cyc_ff = '0') then
216
          wb_adr_o <= addr_i;
217
          wb_dat_o <= data_i;
218
          wb_sel_o <= ben_i;
219 31 zero_gravi
          wb_we_o  <= wren_i or wb_we_ff;
220 11 zero_gravi
        end if;
221 2 zero_gravi
      end if;
222
    end process buffer_stages_one;
223 23 zero_gravi
    wb_rdata <= wb_dat_i;
224 2 zero_gravi
  end generate;
225
 
226
  interface_reg_level_two:
227
  if (INTERFACE_REG_STAGES = 2) generate -- 2 register levels: buffer incoming and outgoing signals
228
    buffer_stages_two: process(clk_i)
229
    begin
230
      if rising_edge(clk_i) then
231 11 zero_gravi
        if (wb_cyc_ff = '0') then
232
          wb_adr_o <= addr_i;
233
          wb_dat_o <= data_i;
234
          wb_sel_o <= ben_i;
235 31 zero_gravi
          wb_we_o  <= wren_i or wb_we_ff;
236 11 zero_gravi
        end if;
237 23 zero_gravi
        if (wb_ack_i = '1') then
238
          wb_rdata <= wb_dat_i;
239
        end if;
240 2 zero_gravi
      end if;
241
    end process buffer_stages_two;
242
  end generate;
243
 
244
 
245
end neorv32_wishbone_rtl;

powered by: WebSVN 2.1.0

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