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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sim/] [neorv32_tb.vhd] - Blame information for rev 38

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

Line No. Rev Author Line
1 2 zero_gravi
-- #################################################################################################
2 36 zero_gravi
-- # << NEORV32 - Default Testbench >>                                                             #
3 2 zero_gravi
-- # ********************************************************************************************* #
4 3 zero_gravi
-- # This testbench provides a virtual UART receiver connected to the processor's uart_txd_o       #
5 36 zero_gravi
-- # signal. The received chars are shown in the simulator console and also written to a file      #
6 38 zero_gravi
-- # ("neorv32.testbench_uart.out").                                                               #
7
-- #                                                                                               #
8
-- # Furthermore, this testbench provides two external memories (ext_mem_a and ext_mem_b) coupled  #
9
-- # via Wishbone. ext_mem_a is initialized with the application_init_image and can be used as     #
10
-- # external boot memory (external IMEM).                                                         #
11
-- # ext_mem_b is a small uninitialized memory that can be uased as external memory-mapped IO.     #
12
-- #                                                                                               #
13
-- # Use the "User Configuration" section to configure the testbench according to your need.       #
14 3 zero_gravi
-- # ********************************************************************************************* #
15 2 zero_gravi
-- # BSD 3-Clause License                                                                          #
16
-- #                                                                                               #
17
-- # Copyright (c) 2020, Stephan Nolting. All rights reserved.                                     #
18
-- #                                                                                               #
19
-- # Redistribution and use in source and binary forms, with or without modification, are          #
20
-- # permitted provided that the following conditions are met:                                     #
21
-- #                                                                                               #
22
-- # 1. Redistributions of source code must retain the above copyright notice, this list of        #
23
-- #    conditions and the following disclaimer.                                                   #
24
-- #                                                                                               #
25
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
26
-- #    conditions and the following disclaimer in the documentation and/or other materials        #
27
-- #    provided with the distribution.                                                            #
28
-- #                                                                                               #
29
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
30
-- #    endorse or promote products derived from this software without specific prior written      #
31
-- #    permission.                                                                                #
32
-- #                                                                                               #
33
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
34
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
35
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
36
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
37
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
38
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
39
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
40
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
41
-- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
42
-- # ********************************************************************************************* #
43
-- # The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting #
44
-- #################################################################################################
45
 
46
library ieee;
47
use ieee.std_logic_1164.all;
48
use ieee.numeric_std.all;
49
use ieee.math_real.all;
50
 
51
library neorv32;
52
use neorv32.neorv32_package.all;
53 30 zero_gravi
use neorv32.neorv32_application_image.all; -- this file is generated by the image generator
54 2 zero_gravi
use std.textio.all;
55
 
56
entity neorv32_tb is
57
end neorv32_tb;
58
 
59
architecture neorv32_tb_rtl of neorv32_tb is
60
 
61
  -- User Configuration ---------------------------------------------------------------------
62
  -- -------------------------------------------------------------------------------------------
63 38 zero_gravi
  -- general --
64
  constant boot_external_c       : boolean := false; -- false: boot from proc-internal IMEM, true: boot from (initialized) simulated ext. mem A
65
  constant imem_size_c           : natural := 16*1024; -- size in bytes of processor-internal IMEM / external mem A
66
  constant f_clock_c             : natural := 100000000; -- main clock in Hz
67
  -- UART --
68
  constant baud_rate_c           : natural := 19200; -- standard UART baudrate
69
  -- simulated external Wishbone memory A (can be used as external IMEM) --
70
  constant ext_mem_a_base_addr_c : std_ulogic_vector(31 downto 0) := x"00000000"; -- wishbone memory base address (IMEM base)
71
  constant ext_mem_a_size_c      : natural := imem_size_c; -- wishbone memory size in bytes
72
  constant ext_mem_a_latency_c   : natural := 8; -- latency in clock cycles (min 1, max 255), plus 1 cycle initiali delay
73
  -- simulated external Wishbone memory B (can be used as external IO) --
74
  constant ext_mem_b_base_addr_c : std_ulogic_vector(31 downto 0) := x"F0000000"; -- wishbone memory base address (default begin of EXTERNAL IO area)
75
  constant ext_mem_b_size_c      : natural := 64; -- wishbone memory size in bytes
76
  constant ext_mem_b_latency_c   : natural := 3; -- latency in clock cycles (min 1, max 255), plus 1 cycle initiali delay
77 2 zero_gravi
  -- -------------------------------------------------------------------------------------------
78
 
79 38 zero_gravi
  -- internals - hands off! --
80
  constant boot_imem_c : boolean := not boot_external_c;
81
 
82 3 zero_gravi
  -- text.io --
83
  file file_uart_tx_out : text open write_mode is "neorv32.testbench_uart.out";
84 2 zero_gravi
 
85
  -- internal configuration --
86 38 zero_gravi
  constant baud_val_c : real := real(f_clock_c) / real(baud_rate_c);
87
  constant t_clock_c  : time := (1 sec) / f_clock_c;
88 2 zero_gravi
 
89
  -- generators --
90
  signal clk_gen, rst_gen : std_ulogic := '0';
91
 
92
  -- simulation uart receiver --
93
  signal uart_txd         : std_ulogic;
94
  signal uart_rx_sync     : std_ulogic_vector(04 downto 0) := (others => '1');
95
  signal uart_rx_busy     : std_ulogic := '0';
96
  signal uart_rx_sreg     : std_ulogic_vector(08 downto 0) := (others => '0');
97
  signal uart_rx_baud_cnt : real;
98
  signal uart_rx_bitcnt   : natural;
99
 
100
  -- gpio --
101 22 zero_gravi
  signal gpio : std_ulogic_vector(31 downto 0);
102 2 zero_gravi
 
103
  -- twi --
104
  signal twi_scl, twi_sda : std_logic;
105
 
106
  -- spi --
107
  signal spi_data : std_logic;
108
 
109
  -- Wishbone bus --
110
  type wishbone_t is record
111
    addr  : std_ulogic_vector(31 downto 0); -- address
112
    wdata : std_ulogic_vector(31 downto 0); -- master write data
113
    rdata : std_ulogic_vector(31 downto 0); -- master read data
114
    we    : std_ulogic; -- write enable
115
    sel   : std_ulogic_vector(03 downto 0); -- byte enable
116
    stb   : std_ulogic; -- strobe
117
    cyc   : std_ulogic; -- valid cycle
118
    ack   : std_ulogic; -- transfer acknowledge
119
    err   : std_ulogic; -- transfer error
120 36 zero_gravi
    tag   : std_ulogic_vector(2 downto 0); -- tag
121 2 zero_gravi
  end record;
122 38 zero_gravi
  signal wb_cpu, wb_mem_a, wb_mem_b : wishbone_t;
123 2 zero_gravi
 
124 38 zero_gravi
  -- Wishbone memories --
125
  type ext_mem_a_ram_t is array (0 to ext_mem_a_size_c/4-1) of std_ulogic_vector(31 downto 0);
126
  type ext_mem_b_ram_t is array (0 to ext_mem_b_size_c/4-1) of std_ulogic_vector(31 downto 0);
127
  type ext_mem_read_latency_t is array (0 to 255) of std_ulogic_vector(31 downto 0);
128 30 zero_gravi
 
129
  -- init function --
130
  -- impure function: returns NOT the same result every time it is evaluated with the same arguments since the source file might have changed
131 38 zero_gravi
  impure function init_wbmem(init : application_init_image_t) return ext_mem_a_ram_t is
132
    variable mem_v : ext_mem_a_ram_t;
133 30 zero_gravi
  begin
134
    mem_v := (others => (others => '0'));
135
    for i in 0 to init'length-1 loop -- init only in range of source data array
136
        mem_v(i) := init(i);
137
    end loop; -- i
138
    return mem_v;
139
  end function init_wbmem;
140
 
141 38 zero_gravi
  -- external memory components --
142
  signal ext_ram_a : ext_mem_a_ram_t := init_wbmem(application_init_image); -- initialized, used to simulate external instruction boot memory
143
  signal ext_ram_b : ext_mem_b_ram_t; -- uninitialized, used to simulate external IO
144 30 zero_gravi
 
145 38 zero_gravi
  type ext_mem_t is record
146
    rdata  : ext_mem_read_latency_t;
147 23 zero_gravi
    acc_en : std_ulogic;
148 38 zero_gravi
    ack    : std_ulogic_vector(ext_mem_a_latency_c-1 downto 0);
149 23 zero_gravi
  end record;
150 38 zero_gravi
  signal ext_mem_a, ext_mem_b : ext_mem_t;
151 2 zero_gravi
 
152
begin
153
 
154
  -- Clock/Reset Generator ------------------------------------------------------------------
155
  -- -------------------------------------------------------------------------------------------
156
  clk_gen <= not clk_gen after (t_clock_c/2);
157
  rst_gen <= '0', '1' after 60*(t_clock_c/2);
158
 
159
 
160
  -- CPU Core -------------------------------------------------------------------------------
161
  -- -------------------------------------------------------------------------------------------
162
  neorv32_top_inst: neorv32_top
163
  generic map (
164
    -- General --
165 38 zero_gravi
    CLOCK_FREQUENCY              => f_clock_c,     -- clock frequency of clk_i in Hz
166 8 zero_gravi
    BOOTLOADER_USE               => false,         -- implement processor-internal bootloader?
167 36 zero_gravi
    USER_CODE                    => x"12345678",   -- custom user code
168
    HW_THREAD_ID                 => x"00000000",   -- hardware thread id (hartid)
169 2 zero_gravi
    -- RISC-V CPU Extensions --
170 8 zero_gravi
    CPU_EXTENSION_RISCV_C        => true,          -- implement compressed extension?
171
    CPU_EXTENSION_RISCV_E        => false,         -- implement embedded RF extension?
172
    CPU_EXTENSION_RISCV_M        => true,          -- implement muld/div extension?
173 15 zero_gravi
    CPU_EXTENSION_RISCV_U        => true,          -- implement user mode extension?
174 8 zero_gravi
    CPU_EXTENSION_RISCV_Zicsr    => true,          -- implement CSR system?
175
    CPU_EXTENSION_RISCV_Zifencei => true,          -- implement instruction stream sync.?
176 19 zero_gravi
    -- Extension Options --
177
    FAST_MUL_EN                  => false,         -- use DSPs for M extension's multiplier
178 34 zero_gravi
    FAST_SHIFT_EN                => false,         -- use barrel shifter for shift operations
179 15 zero_gravi
    -- Physical Memory Protection (PMP) --
180
    PMP_USE                      => true,          -- implement PMP?
181
    PMP_NUM_REGIONS              => 4,             -- number of regions (max 16)
182 16 zero_gravi
    PMP_GRANULARITY              => 14,            -- minimal region granularity (1=8B, 2=16B, 3=32B, ...) default is 64k
183 23 zero_gravi
    -- Internal Instruction memory --
184 38 zero_gravi
    MEM_INT_IMEM_USE             => boot_imem_c,   -- implement processor-internal instruction memory
185
    MEM_INT_IMEM_SIZE            => imem_size_c,   -- size of processor-internal instruction memory in bytes
186 8 zero_gravi
    MEM_INT_IMEM_ROM             => false,         -- implement processor-internal instruction memory as ROM
187 23 zero_gravi
    -- Internal Data memory --
188 8 zero_gravi
    MEM_INT_DMEM_USE             => true,          -- implement processor-internal data memory
189
    MEM_INT_DMEM_SIZE            => 8*1024,        -- size of processor-internal data memory in bytes
190 23 zero_gravi
    -- External memory interface --
191 8 zero_gravi
    MEM_EXT_USE                  => true,          -- implement external memory bus interface?
192 2 zero_gravi
    -- Processor peripherals --
193 8 zero_gravi
    IO_GPIO_USE                  => true,          -- implement general purpose input/output port unit (GPIO)?
194
    IO_MTIME_USE                 => true,          -- implement machine system timer (MTIME)?
195
    IO_UART_USE                  => true,          -- implement universal asynchronous receiver/transmitter (UART)?
196
    IO_SPI_USE                   => true,          -- implement serial peripheral interface (SPI)?
197
    IO_TWI_USE                   => true,          -- implement two-wire interface (TWI)?
198
    IO_PWM_USE                   => true,          -- implement pulse-width modulation unit (PWM)?
199
    IO_WDT_USE                   => true,          -- implement watch dog timer (WDT)?
200 23 zero_gravi
    IO_TRNG_USE                  => false,         -- DEFAULT TRNG CONFIG CANNOT BE SIMULATED!
201 34 zero_gravi
    IO_CFU0_USE                  => true,          -- implement custom functions unit 0 (CFU0)?
202
    IO_CFU1_USE                  => true           -- implement custom functions unit 1 (CFU1)?
203 2 zero_gravi
  )
204
  port map (
205
    -- Global control --
206 34 zero_gravi
    clk_i       => clk_gen,         -- global clock, rising edge
207
    rstn_i      => rst_gen,         -- global reset, low-active, async
208 2 zero_gravi
    -- Wishbone bus interface --
209 36 zero_gravi
    wb_tag_o    => wb_cpu.tag,      -- tag
210 34 zero_gravi
    wb_adr_o    => wb_cpu.addr,     -- address
211
    wb_dat_i    => wb_cpu.rdata,    -- read data
212
    wb_dat_o    => wb_cpu.wdata,    -- write data
213
    wb_we_o     => wb_cpu.we,       -- read/write
214
    wb_sel_o    => wb_cpu.sel,      -- byte enable
215
    wb_stb_o    => wb_cpu.stb,      -- strobe
216
    wb_cyc_o    => wb_cpu.cyc,      -- valid cycle
217
    wb_ack_i    => wb_cpu.ack,      -- transfer acknowledge
218
    wb_err_i    => wb_cpu.err,      -- transfer error
219 12 zero_gravi
    -- Advanced memory control signals --
220 34 zero_gravi
    fence_o     => open,            -- indicates an executed FENCE operation
221
    fencei_o    => open,            -- indicates an executed FENCEI operation
222 2 zero_gravi
    -- GPIO --
223 34 zero_gravi
    gpio_o      => gpio,            -- parallel output
224
    gpio_i      => gpio,            -- parallel input
225 2 zero_gravi
    -- UART --
226 34 zero_gravi
    uart_txd_o  => uart_txd,        -- UART send data
227
    uart_rxd_i  => uart_txd,        -- UART receive data
228 2 zero_gravi
    -- SPI --
229 34 zero_gravi
    spi_sck_o   => open,            -- SPI serial clock
230
    spi_sdo_o   => spi_data,        -- controller data out, peripheral data in
231
    spi_sdi_i   => spi_data,        -- controller data in, peripheral data out
232
    spi_csn_o   => open,            -- SPI CS
233 2 zero_gravi
    -- TWI --
234 34 zero_gravi
    twi_sda_io  => twi_sda,         -- twi serial data line
235
    twi_scl_io  => twi_scl,         -- twi serial clock line
236 2 zero_gravi
    -- PWM --
237 34 zero_gravi
    pwm_o       => open,            -- pwm channels
238 2 zero_gravi
    -- Interrupts --
239 34 zero_gravi
    mtime_irq_i => '0',             -- machine software interrupt, available if IO_MTIME_USE = false
240
    msw_irq_i   => '0',             -- machine software interrupt
241
    mext_irq_i  => '0'              -- machine external interrupt
242 2 zero_gravi
  );
243
 
244 36 zero_gravi
  -- TWI termination (pull-ups) --
245 2 zero_gravi
  twi_scl <= 'H';
246
  twi_sda <= 'H';
247
 
248
 
249
  -- Console UART Receiver ------------------------------------------------------------------
250
  -- -------------------------------------------------------------------------------------------
251
  uart_rx_console: process(clk_gen)
252 3 zero_gravi
    variable i : integer;
253
    variable l : line;
254 2 zero_gravi
  begin
255
    -- "UART" --
256
    if rising_edge(clk_gen) then
257
      -- synchronizer --
258
      uart_rx_sync <= uart_rx_sync(3 downto 0) & uart_txd;
259
      -- arbiter --
260
      if (uart_rx_busy = '0') then -- idle
261
        uart_rx_busy     <= '0';
262
        uart_rx_baud_cnt <= round(0.5 * baud_val_c);
263
        uart_rx_bitcnt   <= 9;
264
        if (uart_rx_sync(4 downto 1) = "1100") then -- start bit? (falling edge)
265
          uart_rx_busy <= '1';
266
        end if;
267
      else
268 38 zero_gravi
        if (uart_rx_baud_cnt <= 0.0) then
269 2 zero_gravi
          if (uart_rx_bitcnt = 1) then
270
            uart_rx_baud_cnt <= round(0.5 * baud_val_c);
271
          else
272
            uart_rx_baud_cnt <= round(baud_val_c);
273
          end if;
274
          if (uart_rx_bitcnt = 0) then
275
            uart_rx_busy <= '0'; -- done
276
            i := to_integer(unsigned(uart_rx_sreg(8 downto 1)));
277
 
278 3 zero_gravi
            if (i < 32) or (i > 32+95) then -- printable char?
279 33 zero_gravi
              report "NEORV32_TB_UART.TX: (" & integer'image(i) & ")"; -- print code
280 2 zero_gravi
            else
281 33 zero_gravi
              report "NEORV32_TB_UART.TX: " & character'val(i); -- print ASCII
282 2 zero_gravi
            end if;
283
 
284
            if (i = 10) then -- Linux line break
285 3 zero_gravi
              writeline(file_uart_tx_out, l);
286 2 zero_gravi
            elsif (i /= 13) then -- Remove additional carriage return
287 3 zero_gravi
              write(l, character'val(i));
288 2 zero_gravi
            end if;
289
          else
290
            uart_rx_sreg   <= uart_rx_sync(4) & uart_rx_sreg(8 downto 1);
291
            uart_rx_bitcnt <= uart_rx_bitcnt - 1;
292
          end if;
293
        else
294
          uart_rx_baud_cnt <= uart_rx_baud_cnt - 1.0;
295
        end if;
296
      end if;
297
    end if;
298
  end process uart_rx_console;
299
 
300
 
301 38 zero_gravi
  -- Wishbone Fabric ------------------------------------------------------------------------
302 2 zero_gravi
  -- -------------------------------------------------------------------------------------------
303 38 zero_gravi
  -- CPU broadcast signals --
304
  wb_mem_a.addr  <= wb_cpu.addr;
305
  wb_mem_b.addr  <= wb_cpu.addr;
306
  wb_mem_a.wdata <= wb_cpu.wdata;
307
  wb_mem_b.wdata <= wb_cpu.wdata;
308
  wb_mem_a.we    <= wb_cpu.we;
309
  wb_mem_b.we    <= wb_cpu.we;
310
  wb_mem_a.sel   <= wb_cpu.sel;
311
  wb_mem_b.sel   <= wb_cpu.sel;
312
  wb_mem_a.tag   <= wb_cpu.tag;
313
  wb_mem_b.tag   <= wb_cpu.tag;
314
  wb_mem_a.cyc   <= wb_cpu.cyc;
315
  wb_mem_b.cyc   <= wb_cpu.cyc;
316
 
317
  -- CPU read-back signals (no mux here since peripherals have "output gates") --
318
  wb_cpu.rdata <= wb_mem_a.rdata or wb_mem_b.rdata;
319
  wb_cpu.ack   <= wb_mem_a.ack   or wb_mem_b.ack;
320
  wb_cpu.err   <= wb_mem_a.err   or wb_mem_b.err;
321
 
322
  -- peripheral select via STROBE signal --
323
  wb_mem_a.stb <= wb_cpu.stb when (wb_cpu.addr >= ext_mem_a_base_addr_c) and (wb_cpu.addr < std_ulogic_vector(unsigned(ext_mem_a_base_addr_c) + ext_mem_a_size_c)) else '0';
324
  wb_mem_b.stb <= wb_cpu.stb when (wb_cpu.addr >= ext_mem_b_base_addr_c) and (wb_cpu.addr < std_ulogic_vector(unsigned(ext_mem_b_base_addr_c) + ext_mem_b_size_c)) else '0';
325
 
326
 
327
  -- Wishbone Memory A (simulated external memory) ------------------------------------------
328
  -- -------------------------------------------------------------------------------------------
329
  ext_mem_a_access: process(clk_gen)
330 23 zero_gravi
  begin
331
    if rising_edge(clk_gen) then
332
      -- control --
333 38 zero_gravi
      ext_mem_a.ack(0) <= wb_mem_a.cyc and wb_mem_a.stb; -- wishbone acknowledge
334
 
335 23 zero_gravi
      -- write access --
336 38 zero_gravi
      if ((wb_mem_a.cyc and wb_mem_a.stb and wb_mem_a.we) = '1') then -- valid write access
337 23 zero_gravi
        for i in 0 to 3 loop
338 38 zero_gravi
          if (wb_mem_a.sel(i) = '1') then
339
            ext_ram_a(to_integer(unsigned(wb_mem_a.addr(index_size_f(ext_mem_a_size_c/4)+1 downto 2))))(7+i*8 downto 0+i*8) <= wb_mem_a.wdata(7+i*8 downto 0+i*8);
340 23 zero_gravi
          end if;
341
        end loop; -- i
342 2 zero_gravi
      end if;
343 38 zero_gravi
 
344 23 zero_gravi
      -- read access --
345 38 zero_gravi
      ext_mem_a.rdata(0) <= ext_ram_a(to_integer(unsigned(wb_mem_a.addr(index_size_f(ext_mem_a_size_c/4)+1 downto 2)))); -- word aligned
346 23 zero_gravi
      -- virtual read and ack latency --
347 38 zero_gravi
      if (ext_mem_a_latency_c > 1) then
348
        for i in 1 to ext_mem_a_latency_c-1 loop
349
          ext_mem_a.rdata(i) <= ext_mem_a.rdata(i-1);
350
          ext_mem_a.ack(i)   <= ext_mem_a.ack(i-1) and wb_mem_a.cyc;
351 23 zero_gravi
        end loop;
352
      end if;
353 38 zero_gravi
 
354
      -- bus output register --
355
      wb_mem_a.err <= '0';
356
      if (ext_mem_a.ack(ext_mem_a_latency_c-1) = '1') and (wb_mem_b.cyc = '1') then
357
        wb_mem_a.rdata <= ext_mem_a.rdata(ext_mem_a_latency_c-1);
358
        wb_mem_a.ack   <= '1';
359
      else
360
        wb_mem_a.rdata <= (others => '0');
361
        wb_mem_a.ack   <= '0';
362
      end if;
363 23 zero_gravi
    end if;
364 38 zero_gravi
  end process ext_mem_a_access;
365 2 zero_gravi
 
366
 
367 38 zero_gravi
  -- Wishbone Memory B (simulated external memory) ------------------------------------------
368
  -- -------------------------------------------------------------------------------------------
369
  ext_mem_b_access: process(clk_gen)
370
  begin
371
    if rising_edge(clk_gen) then
372
      -- control --
373
      ext_mem_b.ack(0) <= wb_mem_b.cyc and wb_mem_b.stb; -- wishbone acknowledge
374 2 zero_gravi
 
375 38 zero_gravi
      -- write access --
376
      if ((wb_mem_b.cyc and wb_mem_b.stb and wb_mem_b.we) = '1') then -- valid write access
377
        for i in 0 to 3 loop
378
          if (wb_mem_b.sel(i) = '1') then
379
            ext_ram_b(to_integer(unsigned(wb_mem_b.addr(index_size_f(ext_mem_b_size_c/4)+1 downto 2))))(7+i*8 downto 0+i*8) <= wb_mem_b.wdata(7+i*8 downto 0+i*8);
380
          end if;
381
        end loop; -- i
382
      end if;
383 3 zero_gravi
 
384 38 zero_gravi
      -- read access --
385
      ext_mem_b.rdata(0) <= ext_ram_b(to_integer(unsigned(wb_mem_b.addr(index_size_f(ext_mem_b_size_c/4)+1 downto 2)))); -- word aligned
386
      -- virtual read and ack latency --
387
      if (ext_mem_b_latency_c > 1) then
388
        for i in 1 to ext_mem_b_latency_c-1 loop
389
          ext_mem_b.rdata(i) <= ext_mem_b.rdata(i-1);
390
          ext_mem_b.ack(i)   <= ext_mem_b.ack(i-1) and wb_mem_b.cyc;
391
        end loop;
392
      end if;
393
 
394
      -- bus output register --
395
      wb_mem_b.err <= '0';
396
      if (ext_mem_b.ack(ext_mem_b_latency_c-1) = '1') and (wb_mem_b.cyc = '1') then
397
        wb_mem_b.rdata <= ext_mem_b.rdata(ext_mem_b_latency_c-1);
398
        wb_mem_b.ack   <= '1';
399
      else
400
        wb_mem_b.rdata <= (others => '0');
401
        wb_mem_b.ack   <= '0';
402
      end if;
403
    end if;
404
  end process ext_mem_b_access;
405
 
406
 
407 2 zero_gravi
end neorv32_tb_rtl;

powered by: WebSVN 2.1.0

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