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