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

Subversion Repositories neorv32

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

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 11 zero_gravi
    cancel_i : in  std_ulogic; -- cancel current bus transaction
76 2 zero_gravi
    ack_o    : out std_ulogic; -- transfer acknowledge
77
    err_o    : out std_ulogic; -- transfer error
78
    -- wishbone interface --
79
    wb_adr_o : out std_ulogic_vector(31 downto 0); -- address
80
    wb_dat_i : in  std_ulogic_vector(31 downto 0); -- read data
81
    wb_dat_o : out std_ulogic_vector(31 downto 0); -- write data
82
    wb_we_o  : out std_ulogic; -- read/write
83
    wb_sel_o : out std_ulogic_vector(03 downto 0); -- byte enable
84
    wb_stb_o : out std_ulogic; -- strobe
85
    wb_cyc_o : out std_ulogic; -- valid cycle
86
    wb_ack_i : in  std_ulogic; -- transfer acknowledge
87
    wb_err_i : in  std_ulogic  -- transfer error
88
  );
89
end neorv32_wishbone;
90
 
91
architecture neorv32_wishbone_rtl of neorv32_wishbone is
92
 
93
  -- access control --
94
  signal int_imem_acc, int_imem_acc_real : std_ulogic;
95
  signal int_dmem_acc, int_dmem_acc_real : std_ulogic;
96
  signal int_boot_acc, int_io_acc        : std_ulogic;
97
  signal wb_access                       : std_ulogic;
98
 
99
  -- bus arbiter --
100
  signal wb_stb_ff0 : std_ulogic;
101
  signal wb_stb_ff1 : std_ulogic;
102
  signal wb_cyc_ff  : std_ulogic;
103
  signal wb_ack_ff  : std_ulogic;
104
  signal wb_err_ff  : std_ulogic;
105
 
106
begin
107
 
108
  -- Sanity Check ---------------------------------------------------------------------------
109
  -- -------------------------------------------------------------------------------------------
110
  sanity_check: process(clk_i)
111
  begin
112 11 zero_gravi
    if rising_edge(clk_i) then
113 2 zero_gravi
      if (INTERFACE_REG_STAGES > 2) then
114
        assert false report "NEORV32 CONFIG ERROR! Number of external memory interface buffer stages must be 0, 1 or 2." severity error;
115
      end if;
116
    end if;
117
  end process sanity_check;
118
 
119
 
120
  -- Access Control -------------------------------------------------------------------------
121
  -- -------------------------------------------------------------------------------------------
122
  -- access to internal IMEM or DMEM? --
123
  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';
124
  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';
125
  int_imem_acc_real <= int_imem_acc when (MEM_INT_IMEM_USE = true) else '0';
126
  int_dmem_acc_real <= int_dmem_acc when (MEM_INT_DMEM_USE = true) else '0';
127
  int_boot_acc <= '1' when (addr_i >= boot_base_c) else '0';
128
  int_io_acc   <= '1' when (addr_i >= io_base_c)   else '0';
129
 
130
  -- actual external bus access? --
131
  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);
132
 
133
 
134
  -- Bus Arbiter -----------------------------------------------------------------------------
135
  -- -------------------------------------------------------------------------------------------
136
  bus_arbiter: process(rstn_i, clk_i)
137
  begin
138
    if (rstn_i = '0') then
139
      wb_cyc_ff  <= '0';
140
      wb_stb_ff1 <= '0';
141
      wb_stb_ff0 <= '0';
142
      wb_ack_ff  <= '0';
143
      wb_err_ff  <= '0';
144
    elsif rising_edge(clk_i) then
145
      -- bus cycle --
146
      if (INTERFACE_REG_STAGES = 0) then
147
        wb_cyc_ff <= '0'; -- unused
148 11 zero_gravi
      else
149
        wb_cyc_ff <= (wb_cyc_ff or wb_access) and ((not wb_ack_i) or (not wb_err_i)) and (not cancel_i);
150 2 zero_gravi
      end if;
151
      -- bus strobe --
152
      wb_stb_ff1 <= wb_stb_ff0;
153
      wb_stb_ff0 <= wb_access;
154
      -- bus ack --
155
      wb_ack_ff <= wb_ack_i;
156
      -- bus err --
157
      wb_err_ff <= wb_err_i;
158
    end if;
159
  end process bus_arbiter;
160
 
161
  -- bus cycle --
162
  wb_cyc_o <= wb_access when (INTERFACE_REG_STAGES = 0) else wb_cyc_ff;
163
 
164
  -- bus_strobe: rising edge detector --
165
  wb_stb_o <= (wb_access and (not wb_stb_ff0)) when (INTERFACE_REG_STAGES = 0) else (wb_stb_ff0 and (not wb_stb_ff1));
166
 
167
  -- cpu ack --
168
  ack_o <= wb_ack_ff when (INTERFACE_REG_STAGES = 2) else wb_ack_i;
169
 
170
  -- cpu err --
171
  err_o <= wb_err_ff when (INTERFACE_REG_STAGES = 2) else wb_err_i;
172
 
173
 
174
  -- Bus Buffer -----------------------------------------------------------------------------
175
  -- -------------------------------------------------------------------------------------------
176
  interface_reg_level_zero:
177
  if (INTERFACE_REG_STAGES = 0) generate -- 0 register levels: direct connection
178
    data_o   <= wb_dat_i;
179
    wb_adr_o <= addr_i;
180
    wb_dat_o <= data_i;
181
    wb_sel_o <= ben_i;
182
    wb_we_o  <= wren_i;
183
  end generate;
184
 
185
  interface_reg_level_one:
186
  if (INTERFACE_REG_STAGES = 1) generate -- 1 register levels: buffer outgoing signals
187
    buffer_stages_one: process(clk_i)
188
    begin
189
      if rising_edge(clk_i) then
190 11 zero_gravi
        if (wb_cyc_ff = '0') 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 2 zero_gravi
      end if;
197
    end process buffer_stages_one;
198
    data_o <= wb_dat_i;
199
  end generate;
200
 
201
  interface_reg_level_two:
202
  if (INTERFACE_REG_STAGES = 2) generate -- 2 register levels: buffer incoming and outgoing signals
203
    buffer_stages_two: process(clk_i)
204
    begin
205
      if rising_edge(clk_i) then
206 11 zero_gravi
        if (wb_cyc_ff = '0') then
207
          wb_adr_o <= addr_i;
208
          wb_dat_o <= data_i;
209
          wb_sel_o <= ben_i;
210
          wb_we_o  <= wren_i;
211
          data_o   <= wb_dat_i;
212
        end if;
213 2 zero_gravi
      end if;
214
    end process buffer_stages_two;
215
  end generate;
216
 
217
 
218
end neorv32_wishbone_rtl;

powered by: WebSVN 2.1.0

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