Initial commit
This commit is contained in:
		
							
								
								
									
										58
									
								
								Libs/RiscV_test/NEORV32_test/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								Libs/RiscV_test/NEORV32_test/README.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,58 @@ | ||||
| # Simulation Source Folder | ||||
|  | ||||
|  | ||||
| ## [simple](simple) | ||||
|  | ||||
| Simple testbench for the NEORV32 Processor and script for simulation using GHDL. | ||||
|  | ||||
| - [`ghdl.setup.sh`](simple/ghdl.setup.sh) | ||||
| - [`ghdl.run.sh`](simple/ghdl.run.sh) | ||||
| - [`ghdl.sh`](simple/ghdl.sh) | ||||
| - [`neorv32_tb.simple.vhd`](simple/neorv32_tb.simple.vhd) | ||||
| - [`neorv32_imem.simple.vhd`](simple/neorv32_imem.simple.vhd): memory component optimized for simulation. | ||||
| - [`neorv32_imem.iram.simple.vhd`](simple/neorv32_imem.iram.simple.vhd) | ||||
| - [`uart_rx.simple.vhd`](simple/uart_rx.simple.vhd) | ||||
|  | ||||
|  | ||||
| ## VUnit testbench | ||||
|  | ||||
| VUnit testbench for the NEORV32 Processor. | ||||
|  | ||||
| - [`run.py`](run.py) | ||||
| - [`neorv32_tb.vhd`](neorv32_tb.vhd) | ||||
| - [`uart_rx_pkg.vhd`](uart_rx_pkg.vhd) | ||||
| - [`uart_rx.vhd`](uart_rx.vhd) | ||||
|  | ||||
|  | ||||
| ## [`run_riscv_arch_test.sh`](run_riscv_arch_test.sh): NEORV32 RISC-V Architecture Test Framework | ||||
|  | ||||
| This script tests the NEORV32 Processor for RISC-V compatibility using the | ||||
| [official RISC-V architecture test suite v2+](https://github.com/riscv/riscv-arch-test). | ||||
| The core's HDL sources are *simulated* using `GHDL` to provide a virtual execution platform for the test framework: | ||||
|  | ||||
| * `rv32i_m/C` - compressed instructions | ||||
| * `rv32i_m/I` - base ISA | ||||
| * `rv32i_m/M` - hardware integer multiplication and division | ||||
| * `rv32i_m/privilege` - privileged architecture | ||||
| * `rv32i_m/Zifencei` - instruction stream synchronization (for example for self-modifying code) | ||||
|  | ||||
| :warning: The RISC-V GCC toolchain (`riscv{32|64}-unknown-elf`) is required for program compilation, and the simulation | ||||
|   depends on `simple/ghdl_sim.sh`. | ||||
|  | ||||
| To execute all the supported tests open a terminal and run [`./sim/run_riscv_arch_test.sh`](run_riscv_arch_test.sh), | ||||
| which does the following: | ||||
|  | ||||
| * Make a local copy of the NEORV32 `rtl` folder in `work/`, to keep the project's core files clean. | ||||
| * Clone (as `git submodule`) the [riscv-arch-test repository](https://github.com/riscv/riscv-arch-test) into `sw/isa-test/riscv-arch-test`. | ||||
| * Install (copy) the custom `neorv32` test target from `sw/isa-test/port-neorv32` to the | ||||
| test suite's target folder `work/riscv-arch-test/riscv-target/neorv32`. | ||||
| * Run the actual tests. | ||||
|  | ||||
| :warning: Simulating all the test cases takes quite some time. Some tests use an optimised description of IMEM | ||||
|   (`neorv32_imem.simple.vhd`), but others require the original because they execute self-modifying code. | ||||
|  | ||||
| :warning: If the simulation of a test does not generate any signature output at all or if the signature is truncated, | ||||
| try increasing the simulation time by modiying the `SIM_TIME` variable when calling the test makefiles in `run_riscv_arch_test.sh`. | ||||
|  | ||||
| More datails regarding the actual simulation process can be found in the | ||||
| [target's `README`](../sw/riscv-arch-test/port-neorv32/framework_v2.0/riscv-target/neorv32/README.md). | ||||
							
								
								
									
										685
									
								
								Libs/RiscV_test/NEORV32_test/neorv32_tb.vhd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										685
									
								
								Libs/RiscV_test/NEORV32_test/neorv32_tb.vhd
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,685 @@ | ||||
| -- ################################################################################################# | ||||
| -- # << NEORV32 - Default Processor Testbench >>                                                   # | ||||
| -- # ********************************************************************************************* # | ||||
| -- # The processor is configured to use a maximum of functional units (for testing purpose).       # | ||||
| -- # Use the "User Configuration" section to configure the testbench according to your needs.      # | ||||
| -- # See NEORV32 data sheet for more information.                                                  # | ||||
| -- # ********************************************************************************************* # | ||||
| -- # BSD 3-Clause License                                                                          # | ||||
| -- #                                                                                               # | ||||
| -- # Copyright (c) 2021, Stephan Nolting. All rights reserved.                                     # | ||||
| -- #                                                                                               # | ||||
| -- # Redistribution and use in source and binary forms, with or without modification, are          # | ||||
| -- # permitted provided that the following conditions are met:                                     # | ||||
| -- #                                                                                               # | ||||
| -- # 1. Redistributions of source code must retain the above copyright notice, this list of        # | ||||
| -- #    conditions and the following disclaimer.                                                   # | ||||
| -- #                                                                                               # | ||||
| -- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     # | ||||
| -- #    conditions and the following disclaimer in the documentation and/or other materials        # | ||||
| -- #    provided with the distribution.                                                            # | ||||
| -- #                                                                                               # | ||||
| -- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  # | ||||
| -- #    endorse or promote products derived from this software without specific prior written      # | ||||
| -- #    permission.                                                                                # | ||||
| -- #                                                                                               # | ||||
| -- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   # | ||||
| -- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               # | ||||
| -- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    # | ||||
| -- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     # | ||||
| -- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE # | ||||
| -- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    # | ||||
| -- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     # | ||||
| -- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  # | ||||
| -- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            # | ||||
| -- # ********************************************************************************************* # | ||||
| -- # The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting # | ||||
| -- ################################################################################################# | ||||
|  | ||||
| library vunit_lib; | ||||
| context vunit_lib.vunit_context; | ||||
| context vunit_lib.com_context; | ||||
| context vunit_lib.vc_context; | ||||
|  | ||||
| library ieee; | ||||
| use ieee.std_logic_1164.all; | ||||
| use ieee.numeric_std.all; | ||||
| use ieee.math_real.all; | ||||
|  | ||||
| library neorv32; | ||||
| use neorv32.neorv32_package.all; | ||||
| use neorv32.neorv32_application_image.all; -- this file is generated by the image generator | ||||
| use std.textio.all; | ||||
|  | ||||
| library osvvm; | ||||
| use osvvm.RandomPkg.all; | ||||
|  | ||||
| use work.uart_rx_pkg.all; | ||||
|  | ||||
| entity neorv32_tb is | ||||
|   generic (runner_cfg : string := runner_cfg_default; | ||||
|            ci_mode : boolean := false); | ||||
| end neorv32_tb; | ||||
|  | ||||
| architecture neorv32_tb_rtl of neorv32_tb is | ||||
|  | ||||
|   -- User Configuration --------------------------------------------------------------------- | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   -- general -- | ||||
|   constant ext_imem_c              : boolean := false; -- false: use and boot from proc-internal IMEM, true: use and boot from external (initialized) simulated IMEM (ext. mem A) | ||||
|   constant ext_dmem_c              : boolean := false; -- false: use proc-internal DMEM, true: use external simulated DMEM (ext. mem B) | ||||
|   constant imem_size_c             : natural := 16*1024; -- size in bytes of processor-internal IMEM / external mem A | ||||
|   constant dmem_size_c             : natural := 8*1024; -- size in bytes of processor-internal DMEM / external mem B | ||||
|   constant f_clock_c               : natural := 100000000; -- main clock in Hz | ||||
|   constant baud0_rate_c            : natural := 19200; -- simulation UART0 (primary UART) baud rate | ||||
|   constant baud1_rate_c            : natural := 19200; -- simulation UART1 (secondary UART) baud rate | ||||
|   -- simulated external Wishbone memory A (can be used as external IMEM) -- | ||||
|   constant ext_mem_a_base_addr_c   : std_ulogic_vector(31 downto 0) := x"00000000"; -- wishbone memory base address (external IMEM base) | ||||
|   constant ext_mem_a_size_c        : natural := imem_size_c; -- wishbone memory size in bytes | ||||
|   constant ext_mem_a_latency_c     : natural := 8; -- latency in clock cycles (min 1, max 255), plus 1 cycle initial delay | ||||
|   -- simulated external Wishbone memory B (can be used as external DMEM) -- | ||||
|   constant ext_mem_b_base_addr_c   : std_ulogic_vector(31 downto 0) := x"80000000"; -- wishbone memory base address (external DMEM base) | ||||
|   constant ext_mem_b_size_c        : natural := dmem_size_c; -- wishbone memory size in bytes | ||||
|   constant ext_mem_b_latency_c     : natural := 8; -- latency in clock cycles (min 1, max 255), plus 1 cycle initial delay | ||||
|   -- simulated external Wishbone memory C (can be used to simulate external IO access) -- | ||||
|   constant ext_mem_c_base_addr_c   : std_ulogic_vector(31 downto 0) := x"F0000000"; -- wishbone memory base address (default begin of EXTERNAL IO area) | ||||
|   constant ext_mem_c_size_c        : natural := 64; -- wishbone memory size in bytes | ||||
|   constant ext_mem_c_latency_c     : natural := 3; -- latency in clock cycles (min 1, max 255), plus 1 cycle initial delay | ||||
|   -- simulation interrupt trigger -- | ||||
|   constant irq_trigger_base_addr_c : std_ulogic_vector(31 downto 0) := x"FF000000"; | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|  | ||||
|   -- internals - hands off! -- | ||||
|   constant int_imem_c       : boolean := not ext_imem_c; | ||||
|   constant int_dmem_c       : boolean := not ext_dmem_c; | ||||
|   constant uart0_baud_val_c : real := real(f_clock_c) / real(baud0_rate_c); | ||||
|   constant uart1_baud_val_c : real := real(f_clock_c) / real(baud1_rate_c); | ||||
|   constant t_clock_c        : time := (1 sec) / f_clock_c; | ||||
|  | ||||
|   -- generators -- | ||||
|   signal clk_gen, rst_gen : std_ulogic := '0'; | ||||
|  | ||||
|   -- uart -- | ||||
|   signal uart0_txd : std_ulogic; -- local loop-back | ||||
|   signal uart0_cts : std_ulogic; -- local loop-back | ||||
|   signal uart1_txd : std_ulogic; -- local loop-back | ||||
|   signal uart1_cts : std_ulogic; -- local loop-back | ||||
|  | ||||
|   -- gpio -- | ||||
|   signal gpio : std_ulogic_vector(63 downto 0); | ||||
|  | ||||
|   -- twi -- | ||||
|   signal twi_scl, twi_sda : std_logic; | ||||
|  | ||||
|   -- spi -- | ||||
|   signal spi_data : std_ulogic; | ||||
|  | ||||
|   -- irq -- | ||||
|   signal msi_ring, mei_ring : std_ulogic; | ||||
|  | ||||
|   -- Wishbone bus -- | ||||
|   type wishbone_t is record | ||||
|     addr  : std_ulogic_vector(31 downto 0); -- address | ||||
|     wdata : std_ulogic_vector(31 downto 0); -- master write data | ||||
|     rdata : std_ulogic_vector(31 downto 0); -- master read data | ||||
|     we    : std_ulogic; -- write enable | ||||
|     sel   : std_ulogic_vector(03 downto 0); -- byte enable | ||||
|     stb   : std_ulogic; -- strobe | ||||
|     cyc   : std_ulogic; -- valid cycle | ||||
|     ack   : std_ulogic; -- transfer acknowledge | ||||
|     err   : std_ulogic; -- transfer error | ||||
|     tag   : std_ulogic_vector(02 downto 0); -- request tag | ||||
|     lock  : std_ulogic; -- exclusive access request | ||||
|   end record; | ||||
|   signal wb_cpu, wb_mem_a, wb_mem_b, wb_mem_c, wb_irq : wishbone_t; | ||||
|  | ||||
|   -- Wishbone access latency type -- | ||||
|   type ext_mem_read_latency_t is array (0 to 255) of std_ulogic_vector(31 downto 0); | ||||
|  | ||||
|   -- exclusive access / reservation -- | ||||
|   signal ext_mem_c_atomic_reservation : std_ulogic := '0'; | ||||
|  | ||||
|   -- simulated external memory c (IO) -- | ||||
|   signal ext_ram_c : mem32_t(0 to ext_mem_c_size_c/4-1); -- uninitialized, used to simulate external IO | ||||
|  | ||||
|   -- simulated external memory bus feedback type -- | ||||
|   type ext_mem_t is record | ||||
|     rdata  : ext_mem_read_latency_t; | ||||
|     acc_en : std_ulogic; | ||||
|     ack    : std_ulogic_vector(ext_mem_a_latency_c-1 downto 0); | ||||
|   end record; | ||||
|   signal ext_mem_a, ext_mem_b, ext_mem_c : ext_mem_t; | ||||
|  | ||||
|   -- stream link interface - local echo -- | ||||
|   signal slink_dat : sdata_8x32_t; | ||||
|   signal slink_val : std_ulogic_vector(7 downto 0); | ||||
|   signal slink_rdy : std_ulogic_vector(7 downto 0); | ||||
|  | ||||
|   signal slink_transmitter_dat, slink_receiver_dat : sdata_8x32_t; | ||||
|   signal slink_transmitter_val, slink_receiver_val : std_ulogic_vector(7 downto 0); | ||||
|   signal slink_transmitter_rdy, slink_receiver_rdy : std_ulogic_vector(7 downto 0); | ||||
|  | ||||
|   constant uart0_rx_logger : logger_t := get_logger("UART0.RX"); | ||||
|   constant uart1_rx_logger : logger_t := get_logger("UART1.RX"); | ||||
|   constant uart0_rx_handle : uart_rx_t := new_uart_rx(uart0_baud_val_c, uart0_rx_logger); | ||||
|   constant uart1_rx_handle : uart_rx_t := new_uart_rx(uart1_baud_val_c, uart1_rx_logger); | ||||
|  | ||||
|   type axi_stream_master_vec_t is array(integer range <>) of axi_stream_master_t; | ||||
|   type axi_stream_slave_vec_t is array(integer range <>) of axi_stream_slave_t; | ||||
|  | ||||
|   impure function init_slink_transmitters return axi_stream_master_vec_t is | ||||
|     variable result : axi_stream_master_vec_t(slink_transmitter_val'range); | ||||
|   begin | ||||
|     for idx in result'range loop | ||||
|       result(idx) := new_axi_stream_master( | ||||
|         data_length => slink_transmitter_dat(idx)'length, | ||||
|         stall_config => new_stall_config(0.05, 1, 10) | ||||
|       ); | ||||
|     end loop; | ||||
|  | ||||
|     return result; | ||||
|   end; | ||||
|  | ||||
|   impure function init_slink_receivers return axi_stream_slave_vec_t is | ||||
|     variable result : axi_stream_slave_vec_t(slink_receiver_val'range); | ||||
|   begin | ||||
|     for idx in result'range loop | ||||
|       result(idx) := new_axi_stream_slave( | ||||
|         data_length => slink_receiver_dat(idx)'length, | ||||
|         stall_config => new_stall_config(0.05, 1, 10) | ||||
|       ); | ||||
|     end loop; | ||||
|  | ||||
|     return result; | ||||
|   end; | ||||
|  | ||||
|   constant slink_transmitters : axi_stream_master_vec_t := init_slink_transmitters; | ||||
|   constant slink_receivers : axi_stream_slave_vec_t := init_slink_receivers; | ||||
|  | ||||
| begin | ||||
|   test_runner : process | ||||
|     variable msg : msg_t; | ||||
|     variable rnd : RandomPType; | ||||
|     variable value : std_logic_vector(slink_transmitter_dat(0)'range); | ||||
|   begin | ||||
|     test_runner_setup(runner, runner_cfg); | ||||
|  | ||||
|     rnd.InitSeed(test_runner'path_name); | ||||
|  | ||||
|     -- Show passing checks for UART0 on the display (stdout) | ||||
|     show(uart0_rx_logger, display_handler, pass); | ||||
|     show(uart1_rx_logger, display_handler, pass); | ||||
|  | ||||
|     if ci_mode then | ||||
|       check_uart(net, uart0_rx_handle, nul & nul); | ||||
|     else | ||||
|       check_uart(net, uart0_rx_handle, "Blinking LED demo program" & cr & lf); | ||||
|     end if; | ||||
|  | ||||
|     if ci_mode then | ||||
|       -- No need to send the full expectation in one big chunk | ||||
|       check_uart(net, uart1_rx_handle, nul & nul); | ||||
|       check_uart(net, uart1_rx_handle, "0/46" & cr & lf); | ||||
|     end if; | ||||
|  | ||||
|     -- Apply some random data on each SLINK inputs and expect it to | ||||
|     -- be echoed by the CPU. No blocking. Let the SLINK transmitters | ||||
|     -- and receivers do this work in parallel. | ||||
|     for idx in slink_transmitters'range loop | ||||
|       for iter in 1 to 100 loop | ||||
|         value := rnd.RandSlv(value'length); | ||||
|  | ||||
|         -- SLINK is AXI Stream compatible so the SLINK transmitters and | ||||
|         -- and receivers are AXI Stream master and slave verification components (VCs). | ||||
|         -- The full-featured AXI Stream verification component interface (VCI) is used | ||||
|         -- but the AXI stream VCs also implements the basic stream VCI which also works | ||||
|         -- for simple transactions like these. To use that interface for pushing data | ||||
|         -- the AXI Steam VC must be "cast" to a basic stream VC using "as_stream" | ||||
|         -- | ||||
|         -- push_stream(net, as_stream(slink_transmitters(idx)), value); | ||||
|  | ||||
|         push_axi_stream(net, slink_transmitters(idx), value); | ||||
|         check_axi_stream(net, slink_receivers(idx), value, blocking => false); | ||||
|       end loop; | ||||
|     end loop; | ||||
|  | ||||
|     -- Wait until all expected data has been received | ||||
|     -- | ||||
|     -- wait_until_idle can take the VC actor as argument but | ||||
|     -- the more abstract view is that wait_until_idle is part | ||||
|     -- of the sync VCI and to use it a VC must be cast | ||||
|     -- to a sync VC | ||||
|     wait_until_idle(net, as_sync(uart0_rx_handle)); | ||||
|     wait_until_idle(net, as_sync(uart1_rx_handle)); | ||||
|     for idx in slink_receivers'range loop | ||||
|       wait_until_idle(net, as_sync(slink_receivers(idx))); | ||||
|     end loop; | ||||
|  | ||||
|     -- Wait a bit more if some extra unexpected data is produced. If so, | ||||
|     -- uart_rx will fail | ||||
|     wait for (20 * (1e9 / baud0_rate_c)) * ns; | ||||
|  | ||||
|     test_runner_cleanup(runner); | ||||
|   end process; | ||||
|  | ||||
|   -- In case we get stuck waiting there is a watchdog timeout to terminate and fail the | ||||
|   -- testbench | ||||
|   test_runner_watchdog(runner, 50 ms); | ||||
|  | ||||
|   -- Clock/Reset Generator ------------------------------------------------------------------ | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   clk_gen <= not clk_gen after (t_clock_c/2); | ||||
|   rst_gen <= '0', '1' after 60*(t_clock_c/2); | ||||
|  | ||||
|  | ||||
|   -- The Core of the Problem ---------------------------------------------------------------- | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   neorv32_top_inst: neorv32_top | ||||
|   generic map ( | ||||
|     -- General -- | ||||
|     CLOCK_FREQUENCY              => f_clock_c,     -- clock frequency of clk_i in Hz | ||||
|     HW_THREAD_ID                 => 0,             -- hardware thread id (hartid) (32-bit) | ||||
|     INT_BOOTLOADER_EN            => false,         -- boot configuration: true = boot explicit bootloader; false = boot from int/ext (I)MEM | ||||
|     -- On-Chip Debugger (OCD) -- | ||||
|     ON_CHIP_DEBUGGER_EN          => true,          -- implement on-chip debugger | ||||
|     -- RISC-V CPU Extensions -- | ||||
|     CPU_EXTENSION_RISCV_A        => true,          -- implement atomic extension? | ||||
|     CPU_EXTENSION_RISCV_B        => true,          -- implement bit-manipulation extension? | ||||
|     CPU_EXTENSION_RISCV_C        => true,          -- implement compressed extension? | ||||
|     CPU_EXTENSION_RISCV_E        => false,         -- implement embedded RF extension? | ||||
|     CPU_EXTENSION_RISCV_M        => true,          -- implement muld/div extension? | ||||
|     CPU_EXTENSION_RISCV_U        => true,          -- implement user mode extension? | ||||
|     CPU_EXTENSION_RISCV_Zfinx    => true,          -- implement 32-bit floating-point extension (using INT reg!) | ||||
|     CPU_EXTENSION_RISCV_Zicsr    => true,          -- implement CSR system? | ||||
|     CPU_EXTENSION_RISCV_Zicntr   => true,          -- implement base counters? | ||||
|     CPU_EXTENSION_RISCV_Zihpm    => true,          -- implement hardware performance monitors? | ||||
|     CPU_EXTENSION_RISCV_Zifencei => true,          -- implement instruction stream sync.? | ||||
|     -- Extension Options -- | ||||
|     FAST_MUL_EN                  => false,         -- use DSPs for M extension's multiplier | ||||
|     FAST_SHIFT_EN                => false,         -- use barrel shifter for shift operations | ||||
|     CPU_CNT_WIDTH                => 64,            -- total width of CPU cycle and instret counters (0..64) | ||||
|     -- Physical Memory Protection (PMP) -- | ||||
|     PMP_NUM_REGIONS              => 8,             -- number of regions (0..64) | ||||
|     PMP_MIN_GRANULARITY          => 64*1024,       -- minimal region granularity in bytes, has to be a power of 2, min 8 bytes | ||||
|     -- Hardware Performance Monitors (HPM) -- | ||||
|     HPM_NUM_CNTS                 => 12,            -- number of implemented HPM counters (0..29) | ||||
|     HPM_CNT_WIDTH                => 40,            -- total size of HPM counters (0..64) | ||||
|     -- Internal Instruction memory -- | ||||
|     MEM_INT_IMEM_EN              => int_imem_c ,   -- implement processor-internal instruction memory | ||||
|     MEM_INT_IMEM_SIZE            => imem_size_c,   -- size of processor-internal instruction memory in bytes | ||||
|     -- Internal Data memory -- | ||||
|     MEM_INT_DMEM_EN              => int_dmem_c,    -- implement processor-internal data memory | ||||
|     MEM_INT_DMEM_SIZE            => dmem_size_c,   -- size of processor-internal data memory in bytes | ||||
|     -- Internal Cache memory -- | ||||
|     ICACHE_EN                    => true,          -- implement instruction cache | ||||
|     ICACHE_NUM_BLOCKS            => 8,             -- i-cache: number of blocks (min 2), has to be a power of 2 | ||||
|     ICACHE_BLOCK_SIZE            => 64,            -- i-cache: block size in bytes (min 4), has to be a power of 2 | ||||
|     ICACHE_ASSOCIATIVITY         => 2,             -- i-cache: associativity / number of sets (1=direct_mapped), has to be a power of 2 | ||||
|     -- External memory interface -- | ||||
|     MEM_EXT_EN                   => true,          -- implement external memory bus interface? | ||||
|     MEM_EXT_TIMEOUT              => 256,           -- cycles after a pending bus access auto-terminates (0 = disabled) | ||||
|     -- Stream link interface -- | ||||
|     SLINK_NUM_TX                 => 8,             -- number of TX links (0..8) | ||||
|     SLINK_NUM_RX                 => 8,             -- number of TX links (0..8) | ||||
|     SLINK_TX_FIFO                => 4,             -- TX fifo depth, has to be a power of two | ||||
|     SLINK_RX_FIFO                => 1,             -- RX fifo depth, has to be a power of two | ||||
|     -- External Interrupts Controller (XIRQ) -- | ||||
|     XIRQ_NUM_CH                  => 32,            -- number of external IRQ channels (0..32) | ||||
|     XIRQ_TRIGGER_TYPE            => (others => '1'), -- trigger type: 0=level, 1=edge | ||||
|     XIRQ_TRIGGER_POLARITY        => (others => '1'), -- trigger polarity: 0=low-level/falling-edge, 1=high-level/rising-edge  | ||||
|     -- Processor peripherals -- | ||||
|     IO_GPIO_EN                   => true,          -- implement general purpose input/output port unit (GPIO)? | ||||
|     IO_MTIME_EN                  => true,          -- implement machine system timer (MTIME)? | ||||
|     IO_UART0_EN                  => true,          -- implement primary universal asynchronous receiver/transmitter (UART0)? | ||||
|     IO_UART0_RX_FIFO             => 32,            -- RX fifo depth, has to be a power of two, min 1 | ||||
|     IO_UART0_TX_FIFO             => 32,            -- TX fifo depth, has to be a power of two, min 1 | ||||
|     IO_UART1_EN                  => true,          -- implement secondary universal asynchronous receiver/transmitter (UART1)? | ||||
|     IO_UART1_RX_FIFO             => 1,             -- RX fifo depth, has to be a power of two, min 1 | ||||
|     IO_UART1_TX_FIFO             => 1,             -- TX fifo depth, has to be a power of two, min 1 | ||||
|     IO_SPI_EN                    => true,          -- implement serial peripheral interface (SPI)? | ||||
|     IO_TWI_EN                    => true,          -- implement two-wire interface (TWI)? | ||||
|     IO_PWM_NUM_CH                => 30,            -- number of PWM channels to implement (0..60); 0 = disabled | ||||
|     IO_WDT_EN                    => true,          -- implement watch dog timer (WDT)? | ||||
|     IO_TRNG_EN                   => false,         -- trng cannot be simulated | ||||
|     IO_CFS_EN                    => true,          -- implement custom functions subsystem (CFS)? | ||||
|     IO_CFS_CONFIG                => (others => '0'), -- custom CFS configuration generic | ||||
|     IO_CFS_IN_SIZE               => 32,            -- size of CFS input conduit in bits | ||||
|     IO_CFS_OUT_SIZE              => 32,            -- size of CFS output conduit in bits | ||||
|     IO_NEOLED_EN                 => true,          -- implement NeoPixel-compatible smart LED interface (NEOLED)? | ||||
|     IO_NEOLED_TX_FIFO            => 8,             -- NEOLED TX FIFO depth, 1..32k, has to be a power of two | ||||
|     IO_GPTMR_EN                  => true           -- implement general purpose timer (GPTMR)? | ||||
|   ) | ||||
|   port map ( | ||||
|     -- Global control -- | ||||
|     clk_i          => clk_gen,         -- global clock, rising edge | ||||
|     rstn_i         => rst_gen,         -- global reset, low-active, async | ||||
|     -- JTAG on-chip debugger interface (available if ON_CHIP_DEBUGGER_EN = true) -- | ||||
|     jtag_trst_i    => '1',             -- low-active TAP reset (optional) | ||||
|     jtag_tck_i     => '0',             -- serial clock | ||||
|     jtag_tdi_i     => '0',             -- serial data input | ||||
|     jtag_tdo_o     => open,            -- serial data output | ||||
|     jtag_tms_i     => '0',             -- mode select | ||||
|     -- Wishbone bus interface (available if MEM_EXT_EN = true) -- | ||||
|     wb_tag_o       => wb_cpu.tag,      -- request tag | ||||
|     wb_adr_o       => wb_cpu.addr,     -- address | ||||
|     wb_dat_i       => wb_cpu.rdata,    -- read data | ||||
|     wb_dat_o       => wb_cpu.wdata,    -- write data | ||||
|     wb_we_o        => wb_cpu.we,       -- read/write | ||||
|     wb_sel_o       => wb_cpu.sel,      -- byte enable | ||||
|     wb_stb_o       => wb_cpu.stb,      -- strobe | ||||
|     wb_cyc_o       => wb_cpu.cyc,      -- valid cycle | ||||
|     wb_lock_o      => wb_cpu.lock,     -- exclusive access request | ||||
|     wb_ack_i       => wb_cpu.ack,      -- transfer acknowledge | ||||
|     wb_err_i       => wb_cpu.err,      -- transfer error | ||||
|     -- Advanced memory control signals (available if MEM_EXT_EN = true) -- | ||||
|     fence_o        => open,            -- indicates an executed FENCE operation | ||||
|     fencei_o       => open,            -- indicates an executed FENCEI operation | ||||
|     -- TX stream interfaces (available if SLINK_NUM_TX > 0) -- | ||||
|     slink_tx_dat_o => slink_dat,       -- output data | ||||
|     slink_tx_val_o => slink_val,       -- valid output | ||||
|     slink_tx_rdy_i => slink_rdy,       -- ready to send | ||||
|     -- RX stream interfaces (available if SLINK_NUM_RX > 0) -- | ||||
|     slink_rx_dat_i => slink_dat,       -- input data | ||||
|     slink_rx_val_i => slink_val,       -- valid input | ||||
|     slink_rx_rdy_o => slink_rdy,       -- ready to receive | ||||
|     -- GPIO (available if IO_GPIO_EN = true) -- | ||||
|     gpio_o         => gpio,            -- parallel output | ||||
|     gpio_i         => gpio,            -- parallel input | ||||
|     -- primary UART0 (available if IO_UART0_EN = true) -- | ||||
|     uart0_txd_o    => uart0_txd,       -- UART0 send data | ||||
|     uart0_rxd_i    => uart0_txd,       -- UART0 receive data | ||||
|     uart0_rts_o    => uart0_cts,       -- hw flow control: UART0.RX ready to receive ("RTR"), low-active, optional | ||||
|     uart0_cts_i    => uart0_cts,       -- hw flow control: UART0.TX allowed to transmit, low-active, optional | ||||
|     -- secondary UART1 (available if IO_UART1_EN = true) -- | ||||
|     uart1_txd_o    => uart1_txd,       -- UART1 send data | ||||
|     uart1_rxd_i    => uart1_txd,       -- UART1 receive data | ||||
|     uart1_rts_o    => uart1_cts,       -- hw flow control: UART1.RX ready to receive ("RTR"), low-active, optional | ||||
|     uart1_cts_i    => uart1_cts,       -- hw flow control: UART1.TX allowed to transmit, low-active, optional | ||||
|     -- SPI (available if IO_SPI_EN = true) -- | ||||
|     spi_sck_o      => open,            -- SPI serial clock | ||||
|     spi_sdo_o      => spi_data,        -- controller data out, peripheral data in | ||||
|     spi_sdi_i      => spi_data,        -- controller data in, peripheral data out | ||||
|     spi_csn_o      => open,            -- SPI CS | ||||
|     -- TWI (available if IO_TWI_EN = true) -- | ||||
|     twi_sda_io     => twi_sda,         -- twi serial data line | ||||
|     twi_scl_io     => twi_scl,         -- twi serial clock line | ||||
|     -- PWM (available if IO_PWM_NUM_CH > 0) -- | ||||
|     pwm_o          => open,            -- pwm channels | ||||
|     -- Custom Functions Subsystem IO -- | ||||
|     cfs_in_i       => (others => '0'), -- custom CFS inputs | ||||
|     cfs_out_o      => open,            -- custom CFS outputs | ||||
|     -- NeoPixel-compatible smart LED interface (available if IO_NEOLED_EN = true) -- | ||||
|     neoled_o       => open,            -- async serial data line | ||||
|     -- System time -- | ||||
|     mtime_i        => (others => '0'), -- current system time from ext. MTIME (if IO_MTIME_EN = false) | ||||
|     mtime_o        => open,            -- current system time from int. MTIME (if IO_MTIME_EN = true) | ||||
|     -- External platform interrupts (available if XIRQ_NUM_CH > 0) -- | ||||
|     xirq_i         => gpio(31 downto 0), -- IRQ channels | ||||
|     -- CPU Interrupts -- | ||||
|     mtime_irq_i    => '0',             -- machine software interrupt, available if IO_MTIME_EN = false | ||||
|     msw_irq_i      => msi_ring,        -- machine software interrupt | ||||
|     mext_irq_i     => mei_ring         -- machine external interrupt | ||||
|   ); | ||||
|  | ||||
|   -- TWI termination (pull-ups) -- | ||||
|   twi_scl <= 'H'; | ||||
|   twi_sda <= 'H'; | ||||
|  | ||||
|   uart0_checker: entity work.uart_rx | ||||
|     generic map (uart0_rx_handle) | ||||
|     port map ( | ||||
|       clk => clk_gen, | ||||
|       uart_txd => uart0_txd); | ||||
|  | ||||
|   uart1_checker: entity work.uart_rx | ||||
|     generic map (uart1_rx_handle) | ||||
|     port map ( | ||||
|       clk => clk_gen, | ||||
|       uart_txd => uart1_txd); | ||||
|  | ||||
|   slink_transmitters_gen: for idx in slink_transmitters'range generate | ||||
|     slink_transmitter : entity vunit_lib.axi_stream_master | ||||
|       generic map( | ||||
|         master => slink_transmitters(idx) | ||||
|       ) | ||||
|       port map( | ||||
|         aclk => clk_gen, | ||||
|         tvalid => slink_transmitter_val(idx), | ||||
|         tready => slink_transmitter_rdy(idx), | ||||
|         std_ulogic_vector(tdata) => slink_transmitter_dat(idx) | ||||
|       ); | ||||
|   end generate; | ||||
|  | ||||
|   slink_receivers_gen: for idx in slink_receivers'range generate | ||||
|   begin | ||||
|     slink_receiver : entity vunit_lib.axi_stream_slave | ||||
|       generic map( | ||||
|         slave => slink_receivers(idx) | ||||
|       ) | ||||
|       port map( | ||||
|         aclk => clk_gen, | ||||
|         tvalid => slink_receiver_val(idx), | ||||
|         tready => slink_receiver_rdy(idx), | ||||
|         tdata => std_logic_vector(slink_receiver_dat(idx)) | ||||
|       ); | ||||
|   end generate; | ||||
|  | ||||
|   -- TODO: connect these to the CPU SLINK interface once the | ||||
|   -- loopback SW has been implemented | ||||
|   temporary_connection : for idx in slink_transmitters'range generate | ||||
|     slink_receiver_val(idx) <= slink_transmitter_val(idx); | ||||
|     slink_transmitter_rdy(idx) <= slink_receiver_rdy(idx); | ||||
|     slink_receiver_dat(idx) <= slink_transmitter_dat(idx); | ||||
|   end generate; | ||||
|  | ||||
|  | ||||
|   -- Wishbone Fabric ------------------------------------------------------------------------ | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   -- CPU broadcast signals -- | ||||
|   wb_mem_a.addr  <= wb_cpu.addr; | ||||
|   wb_mem_a.wdata <= wb_cpu.wdata; | ||||
|   wb_mem_a.we    <= wb_cpu.we; | ||||
|   wb_mem_a.sel   <= wb_cpu.sel; | ||||
|   wb_mem_a.tag   <= wb_cpu.tag; | ||||
|   wb_mem_a.cyc   <= wb_cpu.cyc; | ||||
|   wb_mem_a.lock  <= wb_cpu.lock; | ||||
|  | ||||
|   wb_mem_b.addr  <= wb_cpu.addr; | ||||
|   wb_mem_b.wdata <= wb_cpu.wdata; | ||||
|   wb_mem_b.we    <= wb_cpu.we; | ||||
|   wb_mem_b.sel   <= wb_cpu.sel; | ||||
|   wb_mem_b.tag   <= wb_cpu.tag; | ||||
|   wb_mem_b.cyc   <= wb_cpu.cyc; | ||||
|   wb_mem_b.lock  <= wb_cpu.lock; | ||||
|  | ||||
|   wb_mem_c.addr  <= wb_cpu.addr; | ||||
|   wb_mem_c.wdata <= wb_cpu.wdata; | ||||
|   wb_mem_c.we    <= wb_cpu.we; | ||||
|   wb_mem_c.sel   <= wb_cpu.sel; | ||||
|   wb_mem_c.tag   <= wb_cpu.tag; | ||||
|   wb_mem_c.cyc   <= wb_cpu.cyc; | ||||
|   wb_mem_c.lock  <= wb_cpu.lock; | ||||
|  | ||||
|   wb_irq.addr    <= wb_cpu.addr; | ||||
|   wb_irq.wdata   <= wb_cpu.wdata; | ||||
|   wb_irq.we      <= wb_cpu.we; | ||||
|   wb_irq.sel     <= wb_cpu.sel; | ||||
|   wb_irq.tag     <= wb_cpu.tag; | ||||
|   wb_irq.cyc     <= wb_cpu.cyc; | ||||
|  | ||||
|   -- CPU read-back signals (no mux here since peripherals have "output gates") -- | ||||
|   wb_cpu.rdata <= wb_mem_a.rdata or wb_mem_b.rdata or wb_mem_c.rdata or wb_irq.rdata; | ||||
|   wb_cpu.ack   <= wb_mem_a.ack   or wb_mem_b.ack   or wb_mem_c.ack   or wb_irq.ack; | ||||
|   wb_cpu.err   <= wb_mem_a.err   or wb_mem_b.err   or wb_mem_c.err   or wb_irq.err; | ||||
|  | ||||
|   -- peripheral select via STROBE signal -- | ||||
|   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'; | ||||
|   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'; | ||||
|   wb_mem_c.stb <= wb_cpu.stb when (wb_cpu.addr >= ext_mem_c_base_addr_c) and (wb_cpu.addr < std_ulogic_vector(unsigned(ext_mem_c_base_addr_c) + ext_mem_c_size_c)) else '0'; | ||||
|   wb_irq.stb   <= wb_cpu.stb when (wb_cpu.addr =  irq_trigger_base_addr_c) else '0'; | ||||
|  | ||||
|  | ||||
|   -- Wishbone Memory A (simulated external IMEM) -------------------------------------------- | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   generate_ext_imem: | ||||
|   if ext_imem_c generate | ||||
|     ext_mem_a_access: process(clk_gen) | ||||
|       variable ext_ram_a : mem32_t(0 to ext_mem_a_size_c/4-1) := mem32_init_f(application_init_image, ext_mem_a_size_c/4); -- initialized, used to simulate external IMEM | ||||
|     begin | ||||
|       if rising_edge(clk_gen) then | ||||
|         -- control -- | ||||
|         ext_mem_a.ack(0) <= wb_mem_a.cyc and wb_mem_a.stb; -- wishbone acknowledge | ||||
|  | ||||
|         -- write access -- | ||||
|         if ((wb_mem_a.cyc and wb_mem_a.stb and wb_mem_a.we) = '1') then -- valid write access | ||||
|           for i in 0 to 3 loop | ||||
|             if (wb_mem_a.sel(i) = '1') then | ||||
|               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); | ||||
|             end if; | ||||
|           end loop; -- i | ||||
|         end if; | ||||
|  | ||||
|         -- read access -- | ||||
|         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 | ||||
|         -- virtual read and ack latency -- | ||||
|         if (ext_mem_a_latency_c > 1) then | ||||
|           for i in 1 to ext_mem_a_latency_c-1 loop | ||||
|             ext_mem_a.rdata(i) <= ext_mem_a.rdata(i-1); | ||||
|             ext_mem_a.ack(i)   <= ext_mem_a.ack(i-1) and wb_mem_a.cyc; | ||||
|           end loop; | ||||
|         end if; | ||||
|  | ||||
|         -- bus output register -- | ||||
|         wb_mem_a.err <= '0'; | ||||
|         if (ext_mem_a.ack(ext_mem_a_latency_c-1) = '1') and (wb_mem_a.cyc = '1') and (wb_mem_a.ack = '0') then | ||||
|           wb_mem_a.rdata <= ext_mem_a.rdata(ext_mem_a_latency_c-1); | ||||
|           wb_mem_a.ack   <= '1'; | ||||
|         else | ||||
|           wb_mem_a.rdata <= (others => '0'); | ||||
|           wb_mem_a.ack   <= '0'; | ||||
|         end if; | ||||
|       end if; | ||||
|     end process ext_mem_a_access; | ||||
|   end generate; | ||||
|  | ||||
|   generate_ext_imem_false: | ||||
|   if (ext_imem_c = false) generate | ||||
|     wb_mem_a.rdata <= (others => '0'); | ||||
|     wb_mem_a.ack   <= '0'; | ||||
|     wb_mem_a.err   <= '0'; | ||||
|   end generate; | ||||
|  | ||||
|  | ||||
|   -- Wishbone Memory B (simulated external DMEM) -------------------------------------------- | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   ext_mem_b_access: process(clk_gen) | ||||
|     variable ext_ram_b : mem32_t(0 to ext_mem_b_size_c/4-1) := (others => (others => '0')); -- zero, used to simulate external DMEM | ||||
|   begin | ||||
|     if rising_edge(clk_gen) then | ||||
|       -- control -- | ||||
|       ext_mem_b.ack(0) <= wb_mem_b.cyc and wb_mem_b.stb; -- wishbone acknowledge | ||||
|  | ||||
|       -- write access -- | ||||
|       if ((wb_mem_b.cyc and wb_mem_b.stb and wb_mem_b.we) = '1') then -- valid write access | ||||
|         for i in 0 to 3 loop | ||||
|           if (wb_mem_b.sel(i) = '1') then | ||||
|             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); | ||||
|           end if; | ||||
|         end loop; -- i | ||||
|       end if; | ||||
|  | ||||
|       -- read access -- | ||||
|       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 | ||||
|       -- virtual read and ack latency -- | ||||
|       if (ext_mem_b_latency_c > 1) then | ||||
|         for i in 1 to ext_mem_b_latency_c-1 loop | ||||
|           ext_mem_b.rdata(i) <= ext_mem_b.rdata(i-1); | ||||
|           ext_mem_b.ack(i)   <= ext_mem_b.ack(i-1) and wb_mem_b.cyc; | ||||
|         end loop; | ||||
|       end if; | ||||
|  | ||||
|       -- bus output register -- | ||||
|       wb_mem_b.err <= '0'; | ||||
|       if (ext_mem_b.ack(ext_mem_b_latency_c-1) = '1') and (wb_mem_b.cyc = '1') and (wb_mem_b.ack = '0') then | ||||
|         wb_mem_b.rdata <= ext_mem_b.rdata(ext_mem_b_latency_c-1); | ||||
|         wb_mem_b.ack   <= '1'; | ||||
|       else | ||||
|         wb_mem_b.rdata <= (others => '0'); | ||||
|         wb_mem_b.ack   <= '0'; | ||||
|       end if; | ||||
|     end if; | ||||
|   end process ext_mem_b_access; | ||||
|  | ||||
|  | ||||
|   -- Wishbone Memory C (simulated external IO) ---------------------------------------------- | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   ext_mem_c_access: process(clk_gen) | ||||
|   begin | ||||
|     if rising_edge(clk_gen) then | ||||
|       -- control -- | ||||
|       ext_mem_c.ack(0) <= wb_mem_c.cyc and wb_mem_c.stb; -- wishbone acknowledge | ||||
|  | ||||
|       -- write access -- | ||||
|       if ((wb_mem_c.cyc and wb_mem_c.stb and wb_mem_c.we) = '1') then -- valid write access | ||||
|         for i in 0 to 3 loop | ||||
|           if (wb_mem_c.sel(i) = '1') then | ||||
|             ext_ram_c(to_integer(unsigned(wb_mem_c.addr(index_size_f(ext_mem_c_size_c/4)+1 downto 2))))(7+i*8 downto 0+i*8) <= wb_mem_c.wdata(7+i*8 downto 0+i*8); | ||||
|           end if; | ||||
|         end loop; -- i | ||||
|       end if; | ||||
|  | ||||
|       -- read access -- | ||||
|       ext_mem_c.rdata(0) <= ext_ram_c(to_integer(unsigned(wb_mem_c.addr(index_size_f(ext_mem_c_size_c/4)+1 downto 2)))); -- word aligned | ||||
|       -- virtual read and ack latency -- | ||||
|       if (ext_mem_c_latency_c > 1) then | ||||
|         for i in 1 to ext_mem_c_latency_c-1 loop | ||||
|           ext_mem_c.rdata(i) <= ext_mem_c.rdata(i-1); | ||||
|           ext_mem_c.ack(i)   <= ext_mem_c.ack(i-1) and wb_mem_c.cyc; | ||||
|         end loop; | ||||
|       end if; | ||||
|  | ||||
|       -- EXCLUSIVE bus access ----------------------------------------------------- | ||||
|       -- ----------------------------------------------------------------------------- | ||||
|       -- Since there is only one CPU in this design, the exclusive access reservation in THIS memory CANNOT fail. | ||||
|       -- However, this memory module is used to simulated failing LR/SC accesses. | ||||
|       if ((wb_mem_c.cyc and wb_mem_c.stb) = '1') then -- valid access | ||||
|         ext_mem_c_atomic_reservation <= wb_mem_c.lock; -- make reservation | ||||
|       end if; | ||||
|       -- ----------------------------------------------------------------------------- | ||||
|  | ||||
|       -- bus output register -- | ||||
|       if (ext_mem_c.ack(ext_mem_c_latency_c-1) = '1') and (wb_mem_c.cyc = '1') and (wb_mem_c.ack = '0') then | ||||
|         wb_mem_c.rdata <= ext_mem_c.rdata(ext_mem_c_latency_c-1); | ||||
|         wb_mem_c.ack   <= '1'; | ||||
|         wb_mem_c.err   <= ext_mem_c_atomic_reservation; -- issue a bus error if there is an exclusive access request | ||||
|       else | ||||
|         wb_mem_c.rdata <= (others => '0'); | ||||
|         wb_mem_c.ack   <= '0'; | ||||
|         wb_mem_c.err   <= '0'; | ||||
|       end if; | ||||
|     end if; | ||||
|   end process ext_mem_c_access; | ||||
|  | ||||
|  | ||||
|   -- Wishbone IRQ Triggers ------------------------------------------------------------------ | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   irq_trigger: process(rst_gen, clk_gen) | ||||
|   begin | ||||
|     if (rst_gen = '0') then | ||||
|       msi_ring <= '0'; | ||||
|       mei_ring <= '0'; | ||||
|     elsif rising_edge(clk_gen) then | ||||
|       -- bus interface -- | ||||
|       wb_irq.rdata <= (others => '0'); | ||||
|       wb_irq.ack   <= wb_irq.cyc and wb_irq.stb and wb_irq.we and and_reduce_f(wb_irq.sel); | ||||
|       wb_irq.err   <= '0'; | ||||
|       -- trigger RISC-V platform IRQs -- | ||||
|       if ((wb_irq.cyc and wb_irq.stb and wb_irq.we and and_reduce_f(wb_irq.sel)) = '1') then | ||||
|         msi_ring <= wb_irq.wdata(03); -- machine software interrupt | ||||
|         mei_ring <= wb_irq.wdata(11); -- machine software interrupt | ||||
|       end if; | ||||
|     end if; | ||||
|   end process irq_trigger; | ||||
|  | ||||
|  | ||||
| end neorv32_tb_rtl; | ||||
							
								
								
									
										36
									
								
								Libs/RiscV_test/NEORV32_test/run.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								Libs/RiscV_test/NEORV32_test/run.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,36 @@ | ||||
| #!/usr/bin/env python3 | ||||
|  | ||||
| from pathlib import Path | ||||
| from vunit import VUnit, VUnitCLI | ||||
|  | ||||
| cli = VUnitCLI() | ||||
| cli.parser.add_argument( | ||||
|     "--ci-mode", | ||||
|     action="store_true", | ||||
|     default=False, | ||||
|     help="Enable special settings used by the CI", | ||||
| ) | ||||
| args = cli.parse_args() | ||||
|  | ||||
| PRJ = VUnit.from_args(args=args) | ||||
| PRJ.add_com() | ||||
| PRJ.add_verification_components() | ||||
| PRJ.add_osvvm() | ||||
|  | ||||
| ROOT = Path(__file__).parent | ||||
|  | ||||
| NEORV32 = PRJ.add_library("neorv32") | ||||
| NEORV32.add_source_files([ | ||||
|     ROOT / "*.vhd", | ||||
|     ROOT / ".." / "rtl" / "**" / "*.vhd", | ||||
|     # In VUnit <=v4.5.0, the glob search is not recursive, | ||||
|     # hence subdir 'mem' is not picked by the previous pattern | ||||
|     ROOT / ".." / "rtl" / "core" / "mem" / "*.vhd" | ||||
| ]) | ||||
|  | ||||
| NEORV32.test_bench("neorv32_tb").set_generic("ci_mode", args.ci_mode) | ||||
|  | ||||
| PRJ.set_sim_option("disable_ieee_warnings", True) | ||||
| PRJ.set_sim_option("ghdl.sim_flags", ["--max-stack-alloc=256"]) | ||||
|  | ||||
| PRJ.main() | ||||
							
								
								
									
										63
									
								
								Libs/RiscV_test/NEORV32_test/run_riscv_arch_test.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								Libs/RiscV_test/NEORV32_test/run_riscv_arch_test.sh
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,63 @@ | ||||
| #!/usr/bin/env bash | ||||
|  | ||||
| # Abort if any command returns != 0 | ||||
| set -e | ||||
|  | ||||
| cd $(dirname "$0") | ||||
|  | ||||
| header() { | ||||
|   echo "--------------------------------------------------------------------------" | ||||
|   echo "> $@..." | ||||
|   echo "--------------------------------------------------------------------------" | ||||
| } | ||||
|  | ||||
| RISCV_PREFIX="${RISCV_PREFIX:-riscv32-unknown-elf-}" | ||||
|  | ||||
| header "Checking RISC-V GCC toolchain" | ||||
| "$RISCV_PREFIX"gcc -v | ||||
|  | ||||
| header "Checking 'riscv-arch-test' GitHub repository (submodule)" | ||||
| git submodule update --init | ||||
|  | ||||
| header "Copying neorv32 test-target into riscv-arch-test framework" | ||||
| ( | ||||
|   cd ../sw/isa-test | ||||
|   target_device='riscv-arch-test/riscv-target/neorv32' | ||||
|   if [ -d "$target_device" ]; then rm -rf "$target_device"; fi | ||||
|   cp -vr port-neorv32 "$target_device" | ||||
| ) | ||||
|  | ||||
| header "Making local copy of NEORV32 'rtl' and 'sim' folders" | ||||
|  | ||||
| export NEORV32_LOCAL_RTL=${NEORV32_LOCAL_RTL:-$(pwd)/work} | ||||
|  | ||||
| rm -rf "$NEORV32_LOCAL_RTL" | ||||
| cp -r ../rtl "$NEORV32_LOCAL_RTL" | ||||
|  | ||||
| header "Starting RISC-V architecture tests" | ||||
|  | ||||
| ./simple/ghdl.setup.sh | ||||
|  | ||||
| # work in progress FIXME | ||||
| printf "\n\e[1;33mWARNING! 'rv32e/*' tests are work in progress! \e[0m\n\n" | ||||
|  | ||||
| makeArgs="-C $(pwd)/../sw/isa-test/riscv-arch-test NEORV32_ROOT=$(pwd)/.. XLEN=32 RISCV_TARGET=neorv32" | ||||
| makeTargets='clean build run verify' | ||||
|  | ||||
| [ -n "$1" ] && SUITES="$@" || SUITES='I C M privilege Zifencei' | ||||
|  | ||||
| for suite in $SUITES; do | ||||
|   case "$suite" in | ||||
|     I) make --silent $makeArgs SIM_TIME=850us RISCV_DEVICE=I $makeTargets;; | ||||
|     C) make --silent $makeArgs SIM_TIME=400us RISCV_DEVICE=C $makeTargets;; | ||||
|     M) make --silent $makeArgs SIM_TIME=800us RISCV_DEVICE=M $makeTargets;; | ||||
|     privilege) make --silent $makeArgs SIM_TIME=200us RISCV_DEVICE=privilege $makeTargets;; | ||||
|     Zifencei) make --silent $makeArgs SIM_TIME=200us RISCV_DEVICE=Zifencei RISCV_TARGET_FLAGS=-DNEORV32_NO_DATA_INIT $makeTargets;; | ||||
|  | ||||
|     rv32e_C) make --silent $makeArgs SIM_TIME=200us RISCV_DEVICE=../rv32e_unratified/C $makeTargets;; | ||||
|     rv32e_E) make --silent $makeArgs SIM_TIME=200us RISCV_DEVICE=../rv32e_unratified/E $makeTargets;; | ||||
|     rv32e_M) make --silent $makeArgs SIM_TIME=200us RISCV_DEVICE=../rv32e_unratified/M $makeTargets;; | ||||
|   esac | ||||
| done | ||||
|  | ||||
| printf "\nRISC-V architecture tests completed successfully" | ||||
							
								
								
									
										40
									
								
								Libs/RiscV_test/NEORV32_test/simple/ghdl.run.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								Libs/RiscV_test/NEORV32_test/simple/ghdl.run.sh
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,40 @@ | ||||
| #!/usr/bin/env bash | ||||
|  | ||||
| set -e | ||||
|  | ||||
| cd $(dirname "$0") | ||||
|  | ||||
| echo "Tip: Compile application with USER_FLAGS+=-DUART[0/1]_SIM_MODE to auto-enable UART[0/1]'s simulation mode (redirect UART output to simulator console)." | ||||
|  | ||||
| # Prepare simulation output files for UART0 and UART 1 | ||||
| # - Testbench receiver log file (neorv32.testbench_uart?.out) | ||||
| # - Direct simulation output (neorv32.uart?.sim_mode.[text|data].out) | ||||
| for uart in 0 1; do | ||||
|   for item in \ | ||||
|     testbench_uart"$uart" \ | ||||
|     uart"$uart".sim_mode.text \ | ||||
|     uart"$uart".sim_mode.data; do | ||||
|     touch neorv32."$item".out | ||||
|     chmod 777 neorv32."$item".out | ||||
|   done | ||||
| done | ||||
|  | ||||
| GHDL="${GHDL:-ghdl}" | ||||
|  | ||||
| $GHDL -m --work=neorv32 --workdir=build neorv32_tb_simple | ||||
|  | ||||
| GHDL_RUN_ARGS="${@:---stop-time=10ms}" | ||||
| echo "Using simulation runtime args: $GHDL_RUN_ARGS"; | ||||
|  | ||||
| runcmd="$GHDL -r --work=neorv32 --workdir=build neorv32_tb_simple \ | ||||
|   --max-stack-alloc=0 \ | ||||
|   --ieee-asserts=disable \ | ||||
|   --assert-level=error $GHDL_RUN_ARGS" | ||||
|  | ||||
| if [ -n "$GHDL_DEVNULL" ]; then | ||||
|   $runcmd >> /dev/null | ||||
| else | ||||
|   $runcmd | ||||
| fi | ||||
|  | ||||
| cat neorv32.uart0.sim_mode.text.out | grep "CPU TEST COMPLETED SUCCESSFULLY!" | ||||
							
								
								
									
										18
									
								
								Libs/RiscV_test/NEORV32_test/simple/ghdl.setup.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								Libs/RiscV_test/NEORV32_test/simple/ghdl.setup.sh
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| #!/usr/bin/env bash | ||||
|  | ||||
| set -e | ||||
|  | ||||
| cd $(dirname "$0") | ||||
|  | ||||
| NEORV32_LOCAL_RTL=${NEORV32_LOCAL_RTL:-../../rtl} | ||||
|  | ||||
| mkdir -p build | ||||
|  | ||||
| ghdl -i --work=neorv32 --workdir=build \ | ||||
|   "$NEORV32_LOCAL_RTL"/core/*.vhd \ | ||||
|   "$NEORV32_LOCAL_RTL"/core/mem/*.vhd \ | ||||
|   "$NEORV32_LOCAL_RTL"/processor_templates/*.vhd \ | ||||
|   "$NEORV32_LOCAL_RTL"/system_integration/*.vhd \ | ||||
|   "$NEORV32_LOCAL_RTL"/test_setups/*.vhd \ | ||||
|   neorv32_tb.simple.vhd \ | ||||
|   uart_rx.simple.vhd | ||||
							
								
								
									
										14
									
								
								Libs/RiscV_test/NEORV32_test/simple/ghdl.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								Libs/RiscV_test/NEORV32_test/simple/ghdl.sh
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| #!/usr/bin/env bash | ||||
|  | ||||
| # `GHDL` is used to check all VHDL files for syntax errors and to simulate the default testbench. The previously | ||||
| # installed CPU test program is executed and the console output (UART0 primary UART) is dumped to a text file. After the | ||||
| # simulation has finished, the text file is searched for a specific string. If the string is found, the CPU test was | ||||
| # successful. | ||||
|  | ||||
| # Abort if any command returns != 0 | ||||
| set -e | ||||
|  | ||||
| cd $(dirname "$0") | ||||
|  | ||||
| ./ghdl.setup.sh | ||||
| ./ghdl.run.sh | ||||
							
								
								
									
										136
									
								
								Libs/RiscV_test/NEORV32_test/simple/neorv32_imem.iram.simple.vhd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										136
									
								
								Libs/RiscV_test/NEORV32_test/simple/neorv32_imem.iram.simple.vhd
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,136 @@ | ||||
| -- ################################################################################################# | ||||
| -- # << NEORV32 - Processor-internal instruction memory (IMEM) >>                                  # | ||||
| -- # ********************************************************************************************* # | ||||
| -- # This version is intended for SIMULATION ONLY!                                                 # | ||||
| -- # It implements the IMEM as pre-initialized RAM.                                                # | ||||
| -- # ********************************************************************************************* # | ||||
| -- # BSD 3-Clause License                                                                          # | ||||
| -- #                                                                                               # | ||||
| -- # Copyright (c) 2021, Stephan Nolting. All rights reserved.                                     # | ||||
| -- #                                                                                               # | ||||
| -- # Redistribution and use in source and binary forms, with or without modification, are          # | ||||
| -- # permitted provided that the following conditions are met:                                     # | ||||
| -- #                                                                                               # | ||||
| -- # 1. Redistributions of source code must retain the above copyright notice, this list of        # | ||||
| -- #    conditions and the following disclaimer.                                                   # | ||||
| -- #                                                                                               # | ||||
| -- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     # | ||||
| -- #    conditions and the following disclaimer in the documentation and/or other materials        # | ||||
| -- #    provided with the distribution.                                                            # | ||||
| -- #                                                                                               # | ||||
| -- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  # | ||||
| -- #    endorse or promote products derived from this software without specific prior written      # | ||||
| -- #    permission.                                                                                # | ||||
| -- #                                                                                               # | ||||
| -- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   # | ||||
| -- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               # | ||||
| -- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    # | ||||
| -- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     # | ||||
| -- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE # | ||||
| -- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    # | ||||
| -- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     # | ||||
| -- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  # | ||||
| -- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            # | ||||
| -- # ********************************************************************************************* # | ||||
| -- # The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting # | ||||
| -- ################################################################################################# | ||||
|  | ||||
| library ieee; | ||||
| use ieee.std_logic_1164.all; | ||||
| use ieee.numeric_std.all; | ||||
|  | ||||
| library neorv32; | ||||
| use neorv32.neorv32_package.all; | ||||
| use neorv32.neorv32_application_image.all; -- this file is generated by the image generator | ||||
|  | ||||
| architecture neorv32_imem_rtl of neorv32_imem is | ||||
|  | ||||
|   -- IO space: module base address -- | ||||
|   constant hi_abb_c : natural := 31; -- high address boundary bit | ||||
|   constant lo_abb_c : natural := index_size_f(IMEM_SIZE); -- low address boundary bit | ||||
|  | ||||
|   -- local signals -- | ||||
|   signal acc_en : std_ulogic; | ||||
|   signal rdata  : std_ulogic_vector(31 downto 0); | ||||
|   signal rden   : std_ulogic; | ||||
|   signal addr   : std_ulogic_vector(index_size_f(IMEM_SIZE/4)-1 downto 0); | ||||
|  | ||||
|   -- ---------------------------------------------------- -- | ||||
|   -- << SIMULATION ONLY!!! >> IMEM as pre-initialized RAM -- | ||||
|   -- ---------------------------------------------------- -- | ||||
|  | ||||
|   -- application (image) size in bytes -- | ||||
|   constant imem_app_size_c : natural := (application_init_image'length)*4; | ||||
|  | ||||
|   -- RAM - initialized with executable code -- | ||||
|   signal mem_ram : mem32_t(0 to IMEM_SIZE/4-1) := mem32_init_f(application_init_image, IMEM_SIZE/4); | ||||
|  | ||||
|   -- read data -- | ||||
|   signal mem_ram_rd : std_ulogic_vector(31 downto 0); | ||||
|  | ||||
| begin | ||||
|  | ||||
|   -- Sanity Checks -------------------------------------------------------------------------- | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   assert false report "NEORV32 PROCESSOR CONFIG NOTE: Implementing processor-internal [SIM-only!] IMEM as RAM (" & natural'image(IMEM_SIZE) & | ||||
|   " bytes), pre-initialized with application (" & natural'image(imem_app_size_c) & " bytes)." severity note; | ||||
|   -- | ||||
|   assert not (imem_app_size_c > IMEM_SIZE) report "NEORV32 PROCESSOR CONFIG ERROR: Application (image = " & natural'image(imem_app_size_c) & | ||||
|   " bytes) does not fit into processor-internal IMEM (" & natural'image(IMEM_SIZE) & " bytes)!" severity error; | ||||
|  | ||||
|  | ||||
|   -- Access Control ------------------------------------------------------------------------- | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   acc_en <= '1' when (addr_i(hi_abb_c downto lo_abb_c) = IMEM_BASE(hi_abb_c downto lo_abb_c)) else '0'; | ||||
|   addr   <= addr_i(index_size_f(IMEM_SIZE/4)+1 downto 2); -- word aligned | ||||
|  | ||||
|  | ||||
|   -- Implement IMEM as pre-initialized RAM -------------------------------------------------- | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   mem_access: process(clk_i) | ||||
|   begin | ||||
|     if rising_edge(clk_i) then | ||||
|       if (acc_en = '1') then | ||||
|         if (wren_i = '1') and (ben_i(0) = '1') then -- byte 0 | ||||
|           mem_ram(to_integer(unsigned(addr)))(07 downto 00) <= data_i(07 downto 00); | ||||
|         else | ||||
|           mem_ram_rd(07 downto 00) <= mem_ram(to_integer(unsigned(addr)))(07 downto 00); | ||||
|         end if; | ||||
|         if (wren_i = '1') and (ben_i(1) = '1') then -- byte 1 | ||||
|           mem_ram(to_integer(unsigned(addr)))(15 downto 08) <= data_i(15 downto 08); | ||||
|         else | ||||
|           mem_ram_rd(15 downto 08) <= mem_ram(to_integer(unsigned(addr)))(15 downto 08); | ||||
|         end if; | ||||
|         if (wren_i = '1') and (ben_i(2) = '1') then -- byte 2 | ||||
|           mem_ram(to_integer(unsigned(addr)))(23 downto 16) <= data_i(23 downto 16); | ||||
|         else | ||||
|           mem_ram_rd(23 downto 16) <= mem_ram(to_integer(unsigned(addr)))(23 downto 16); | ||||
|         end if; | ||||
|         if (wren_i = '1') and (ben_i(3) = '1') then -- byte 3 | ||||
|           mem_ram(to_integer(unsigned(addr)))(31 downto 24) <= data_i(31 downto 24); | ||||
|         else | ||||
|           mem_ram_rd(31 downto 24) <= mem_ram(to_integer(unsigned(addr)))(31 downto 24); | ||||
|         end if; | ||||
|       end if; | ||||
|     end if; | ||||
|   end process mem_access; | ||||
|  | ||||
|   -- read data -- | ||||
|   rdata <= mem_ram_rd; | ||||
|  | ||||
|  | ||||
|   -- Bus Feedback --------------------------------------------------------------------------- | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   bus_feedback: process(clk_i) | ||||
|   begin | ||||
|     if rising_edge(clk_i) then | ||||
|       rden  <= acc_en and rden_i; | ||||
|       ack_o <= acc_en and (rden_i or wren_i); | ||||
|     end if; | ||||
|   end process bus_feedback; | ||||
|  | ||||
|   -- output gate -- | ||||
|   data_o <= rdata when (rden = '1') else (others => '0'); | ||||
|  | ||||
|  | ||||
| end neorv32_imem_rtl; | ||||
							
								
								
									
										95
									
								
								Libs/RiscV_test/NEORV32_test/simple/neorv32_imem.simple.vhd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								Libs/RiscV_test/NEORV32_test/simple/neorv32_imem.simple.vhd
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,95 @@ | ||||
| -- ################################################################################################# | ||||
| -- # << NEORV32 - Processor-internal instruction memory (IMEM) >>                                  # | ||||
| -- # ********************************************************************************************* # | ||||
| -- # This version is intended for SIMULATION ONLY!                                                 # | ||||
| -- # It only allows an implementation as ROM and is initialized using "application_init_image".    # | ||||
| -- # Optimized for simulation to allow LARGE read-only IMEMs.                                      # | ||||
| -- # ********************************************************************************************* # | ||||
| -- # BSD 3-Clause License                                                                          # | ||||
| -- #                                                                                               # | ||||
| -- # Copyright (c) 2021, Stephan Nolting. All rights reserved.                                     # | ||||
| -- #                                                                                               # | ||||
| -- # Redistribution and use in source and binary forms, with or without modification, are          # | ||||
| -- # permitted provided that the following conditions are met:                                     # | ||||
| -- #                                                                                               # | ||||
| -- # 1. Redistributions of source code must retain the above copyright notice, this list of        # | ||||
| -- #    conditions and the following disclaimer.                                                   # | ||||
| -- #                                                                                               # | ||||
| -- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     # | ||||
| -- #    conditions and the following disclaimer in the documentation and/or other materials        # | ||||
| -- #    provided with the distribution.                                                            # | ||||
| -- #                                                                                               # | ||||
| -- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  # | ||||
| -- #    endorse or promote products derived from this software without specific prior written      # | ||||
| -- #    permission.                                                                                # | ||||
| -- #                                                                                               # | ||||
| -- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   # | ||||
| -- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               # | ||||
| -- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    # | ||||
| -- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     # | ||||
| -- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE # | ||||
| -- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    # | ||||
| -- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     # | ||||
| -- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  # | ||||
| -- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            # | ||||
| -- # ********************************************************************************************* # | ||||
| -- # The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting # | ||||
| -- ################################################################################################# | ||||
|  | ||||
| library ieee; | ||||
| use ieee.std_logic_1164.all; | ||||
| use ieee.numeric_std.all; | ||||
|  | ||||
| library neorv32; | ||||
| use neorv32.neorv32_package.all; | ||||
| use neorv32.neorv32_application_image.all; -- this file is generated by the image generator | ||||
|  | ||||
| architecture neorv32_imem_rtl of neorv32_imem is | ||||
|  | ||||
|   -- IO space: module base address -- | ||||
|   constant hi_abb_c : natural := 31; -- high address boundary bit | ||||
|   constant lo_abb_c : natural := index_size_f(IMEM_SIZE); -- low address boundary bit | ||||
|  | ||||
|   -- local signals -- | ||||
|   signal acc_en : std_ulogic; | ||||
|   signal rdata  : std_ulogic_vector(31 downto 0); | ||||
|   signal rden   : std_ulogic; | ||||
|   signal addr   : std_ulogic_vector(index_size_f(IMEM_SIZE/4)-1 downto 0); | ||||
|  | ||||
| begin | ||||
|  | ||||
|   -- Sanity Checks -------------------------------------------------------------------------- | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   assert not (IMEM_AS_IROM = false) report "NEORV32 PROCESSOR CONFIG ERROR! Simulation-optimized IMEM can only be used as pre-initialized ROM!" severity error; | ||||
|  | ||||
|  | ||||
|   -- Access Control ------------------------------------------------------------------------- | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   acc_en <= '1' when (addr_i(hi_abb_c downto lo_abb_c) = IMEM_BASE(hi_abb_c downto lo_abb_c)) else '0'; | ||||
|   addr   <= addr_i(index_size_f(IMEM_SIZE/4)+1 downto 2); -- word aligned | ||||
|  | ||||
|  | ||||
|   -- Memory Access -------------------------------------------------------------------------- | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   imem_file_access: process(clk_i) | ||||
|     variable addr_v : integer; | ||||
|   begin | ||||
|     if rising_edge(clk_i) then | ||||
|       rden  <= acc_en and rden_i; | ||||
|       ack_o <= acc_en and (rden_i or wren_i); | ||||
|       if (acc_en = '1') then -- reduce switching activity when not accessed | ||||
|         addr_v := to_integer(unsigned(addr)); | ||||
|         if (addr_v > application_init_image'length) then | ||||
|           rdata <= (others => '0'); | ||||
|         else | ||||
|           rdata <= application_init_image(addr_v); | ||||
|         end if; | ||||
|       end if; | ||||
|     end if; | ||||
|   end process imem_file_access; | ||||
|  | ||||
|   -- output gate -- | ||||
|   data_o <= rdata when (rden = '1') else (others => '0'); | ||||
|  | ||||
|  | ||||
| end neorv32_imem_rtl; | ||||
							
								
								
									
										554
									
								
								Libs/RiscV_test/NEORV32_test/simple/neorv32_tb.simple.vhd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										554
									
								
								Libs/RiscV_test/NEORV32_test/simple/neorv32_tb.simple.vhd
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,554 @@ | ||||
| -- ################################################################################################# | ||||
| -- # << NEORV32 - Default Processor Testbench >>                                                   # | ||||
| -- # ********************************************************************************************* # | ||||
| -- # The processor is configured to use a maximum of functional units (for testing purpose).       # | ||||
| -- # Use the "User Configuration" section to configure the testbench according to your needs.      # | ||||
| -- # See NEORV32 data sheet for more information.                                                  # | ||||
| -- # ********************************************************************************************* # | ||||
| -- # BSD 3-Clause License                                                                          # | ||||
| -- #                                                                                               # | ||||
| -- # Copyright (c) 2021, Stephan Nolting. All rights reserved.                                     # | ||||
| -- #                                                                                               # | ||||
| -- # Redistribution and use in source and binary forms, with or without modification, are          # | ||||
| -- # permitted provided that the following conditions are met:                                     # | ||||
| -- #                                                                                               # | ||||
| -- # 1. Redistributions of source code must retain the above copyright notice, this list of        # | ||||
| -- #    conditions and the following disclaimer.                                                   # | ||||
| -- #                                                                                               # | ||||
| -- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     # | ||||
| -- #    conditions and the following disclaimer in the documentation and/or other materials        # | ||||
| -- #    provided with the distribution.                                                            # | ||||
| -- #                                                                                               # | ||||
| -- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  # | ||||
| -- #    endorse or promote products derived from this software without specific prior written      # | ||||
| -- #    permission.                                                                                # | ||||
| -- #                                                                                               # | ||||
| -- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   # | ||||
| -- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               # | ||||
| -- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    # | ||||
| -- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     # | ||||
| -- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE # | ||||
| -- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    # | ||||
| -- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     # | ||||
| -- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  # | ||||
| -- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            # | ||||
| -- # ********************************************************************************************* # | ||||
| -- # The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting # | ||||
| -- ################################################################################################# | ||||
|  | ||||
| library ieee; | ||||
| use ieee.std_logic_1164.all; | ||||
| use ieee.numeric_std.all; | ||||
| use ieee.math_real.all; | ||||
|  | ||||
| library neorv32; | ||||
| use neorv32.neorv32_package.all; | ||||
| use neorv32.neorv32_application_image.all; -- this file is generated by the image generator | ||||
| use std.textio.all; | ||||
|  | ||||
| entity neorv32_tb_simple is | ||||
|   generic ( | ||||
|     CPU_EXTENSION_RISCV_A        : boolean := true; | ||||
|     CPU_EXTENSION_RISCV_B        : boolean := true; | ||||
|     CPU_EXTENSION_RISCV_C        : boolean := true; | ||||
|     CPU_EXTENSION_RISCV_E        : boolean := false; | ||||
|     CPU_EXTENSION_RISCV_M        : boolean := true; | ||||
|     CPU_EXTENSION_RISCV_U        : boolean := true; | ||||
|     CPU_EXTENSION_RISCV_Zicsr    : boolean := true; | ||||
|     CPU_EXTENSION_RISCV_Zifencei : boolean := true; | ||||
|     EXT_IMEM_C                   : boolean := false;   -- false: use and boot from proc-internal IMEM, true: use and boot from external (initialized) simulated IMEM (ext. mem A) | ||||
|     MEM_INT_IMEM_SIZE            : natural := 16*1024  -- size in bytes of processor-internal IMEM / external mem A | ||||
|   ); | ||||
| end neorv32_tb_simple; | ||||
|  | ||||
| architecture neorv32_tb_simple_rtl of neorv32_tb_simple is | ||||
|  | ||||
|   -- User Configuration --------------------------------------------------------------------- | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   -- general -- | ||||
|   constant ext_dmem_c              : boolean := false;     -- false: use proc-internal DMEM, true: use external simulated DMEM (ext. mem B) | ||||
|   constant dmem_size_c             : natural := 8*1024;    -- size in bytes of processor-internal DMEM / external mem B | ||||
|   constant f_clock_c               : natural := 100000000; -- main clock in Hz | ||||
|   constant baud0_rate_c            : natural := 19200; -- simulation UART0 (primary UART) baud rate | ||||
|   constant baud1_rate_c            : natural := 19200; -- simulation UART1 (secondary UART) baud rate | ||||
|   -- simulated external Wishbone memory A (can be used as external IMEM) -- | ||||
|   constant ext_mem_a_base_addr_c   : std_ulogic_vector(31 downto 0) := x"00000000"; -- wishbone memory base address (external IMEM base) | ||||
|   constant ext_mem_a_size_c        : natural := MEM_INT_IMEM_SIZE; -- wishbone memory size in bytes | ||||
|   constant ext_mem_a_latency_c     : natural := 8; -- latency in clock cycles (min 1, max 255), plus 1 cycle initial delay | ||||
|   -- simulated external Wishbone memory B (can be used as external DMEM) -- | ||||
|   constant ext_mem_b_base_addr_c   : std_ulogic_vector(31 downto 0) := x"80000000"; -- wishbone memory base address (external DMEM base) | ||||
|   constant ext_mem_b_size_c        : natural := dmem_size_c; -- wishbone memory size in bytes | ||||
|   constant ext_mem_b_latency_c     : natural := 8; -- latency in clock cycles (min 1, max 255), plus 1 cycle initial delay | ||||
|   -- simulated external Wishbone memory C (can be used to simulate external IO access) -- | ||||
|   constant ext_mem_c_base_addr_c   : std_ulogic_vector(31 downto 0) := x"F0000000"; -- wishbone memory base address (default begin of EXTERNAL IO area) | ||||
|   constant ext_mem_c_size_c        : natural := 64; -- wishbone memory size in bytes | ||||
|   constant ext_mem_c_latency_c     : natural := 3;  -- latency in clock cycles (min 1, max 255), plus 1 cycle initial delay | ||||
|   -- simulation interrupt trigger -- | ||||
|   constant irq_trigger_base_addr_c : std_ulogic_vector(31 downto 0) := x"FF000000"; | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|  | ||||
|   -- internals - hands off! -- | ||||
|   constant int_imem_c       : boolean := not EXT_IMEM_C; | ||||
|   constant int_dmem_c       : boolean := not ext_dmem_c; | ||||
|   constant uart0_baud_val_c : real := real(f_clock_c) / real(baud0_rate_c); | ||||
|   constant uart1_baud_val_c : real := real(f_clock_c) / real(baud1_rate_c); | ||||
|   constant t_clock_c        : time := (1 sec) / f_clock_c; | ||||
|  | ||||
|   -- generators -- | ||||
|   signal clk_gen, rst_gen : std_ulogic := '0'; | ||||
|  | ||||
|   -- text.io -- | ||||
|   file file_uart0_tx_out : text open write_mode is "neorv32.testbench_uart0.out"; | ||||
|  | ||||
|   -- uart -- | ||||
|   signal uart0_txd : std_ulogic; -- local loop-back | ||||
|   signal uart0_cts : std_ulogic; -- local loop-back | ||||
|   signal uart1_txd : std_ulogic; -- local loop-back | ||||
|   signal uart1_cts : std_ulogic; -- local loop-back | ||||
|  | ||||
|   -- gpio -- | ||||
|   signal gpio : std_ulogic_vector(63 downto 0); | ||||
|  | ||||
|   -- twi -- | ||||
|   signal twi_scl, twi_sda : std_logic; | ||||
|  | ||||
|   -- spi -- | ||||
|   signal spi_data : std_ulogic; | ||||
|  | ||||
|   -- irq -- | ||||
|   signal msi_ring, mei_ring : std_ulogic; | ||||
|  | ||||
|   -- Wishbone bus -- | ||||
|   type wishbone_t is record | ||||
|     addr  : std_ulogic_vector(31 downto 0); -- address | ||||
|     wdata : std_ulogic_vector(31 downto 0); -- master write data | ||||
|     rdata : std_ulogic_vector(31 downto 0); -- master read data | ||||
|     we    : std_ulogic; -- write enable | ||||
|     sel   : std_ulogic_vector(03 downto 0); -- byte enable | ||||
|     stb   : std_ulogic; -- strobe | ||||
|     cyc   : std_ulogic; -- valid cycle | ||||
|     ack   : std_ulogic; -- transfer acknowledge | ||||
|     err   : std_ulogic; -- transfer error | ||||
|     tag   : std_ulogic_vector(02 downto 0); -- request tag | ||||
|     lock  : std_ulogic; -- exclusive access request | ||||
|   end record; | ||||
|   signal wb_cpu, wb_mem_a, wb_mem_b, wb_mem_c, wb_irq : wishbone_t; | ||||
|  | ||||
|   -- Wishbone access latency type -- | ||||
|   type ext_mem_read_latency_t is array (0 to 255) of std_ulogic_vector(31 downto 0); | ||||
|  | ||||
|   -- exclusive access / reservation -- | ||||
|   signal ext_mem_c_atomic_reservation : std_ulogic := '0'; | ||||
|  | ||||
|   -- simulated external memory c (IO) -- | ||||
|   signal ext_ram_c : mem32_t(0 to ext_mem_c_size_c/4-1); -- uninitialized, used to simulate external IO | ||||
|  | ||||
|   -- simulated external memory bus feedback type -- | ||||
|   type ext_mem_t is record | ||||
|     rdata  : ext_mem_read_latency_t; | ||||
|     acc_en : std_ulogic; | ||||
|     ack    : std_ulogic_vector(ext_mem_a_latency_c-1 downto 0); | ||||
|   end record; | ||||
|   signal ext_mem_a, ext_mem_b, ext_mem_c : ext_mem_t; | ||||
|  | ||||
|   -- stream link interface - local echo -- | ||||
|   signal slink_dat : sdata_8x32_t; | ||||
|   signal slink_val : std_ulogic_vector(7 downto 0); | ||||
|   signal slink_rdy : std_ulogic_vector(7 downto 0); | ||||
|  | ||||
| begin | ||||
|  | ||||
|   -- Clock/Reset Generator ------------------------------------------------------------------ | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   clk_gen <= not clk_gen after (t_clock_c/2); | ||||
|   rst_gen <= '0', '1' after 60*(t_clock_c/2); | ||||
|  | ||||
|  | ||||
|   -- The Core of the Problem ---------------------------------------------------------------- | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   neorv32_top_inst: neorv32_top | ||||
|   generic map ( | ||||
|     -- General -- | ||||
|     CLOCK_FREQUENCY              => f_clock_c,     -- clock frequency of clk_i in Hz | ||||
|     HW_THREAD_ID                 => 0,             -- hardware thread id (hartid) (32-bit) | ||||
|     INT_BOOTLOADER_EN            => false,         -- boot configuration: true = boot explicit bootloader; false = boot from int/ext (I)MEM | ||||
|     -- On-Chip Debugger (OCD) -- | ||||
|     ON_CHIP_DEBUGGER_EN          => true,          -- implement on-chip debugger | ||||
|     -- RISC-V CPU Extensions -- | ||||
|     CPU_EXTENSION_RISCV_A        => CPU_EXTENSION_RISCV_A,  -- implement atomic extension? | ||||
|     CPU_EXTENSION_RISCV_B        => CPU_EXTENSION_RISCV_B,  -- implement bit-manipulation extension? | ||||
|     CPU_EXTENSION_RISCV_C        => CPU_EXTENSION_RISCV_C,  -- implement compressed extension? | ||||
|     CPU_EXTENSION_RISCV_E        => CPU_EXTENSION_RISCV_E,  -- implement embedded RF extension? | ||||
|     CPU_EXTENSION_RISCV_M        => CPU_EXTENSION_RISCV_M,  -- implement muld/div extension? | ||||
|     CPU_EXTENSION_RISCV_U        => CPU_EXTENSION_RISCV_U,  -- implement user mode extension? | ||||
|     CPU_EXTENSION_RISCV_Zfinx    => true,          -- implement 32-bit floating-point extension (using INT reg!) | ||||
|     CPU_EXTENSION_RISCV_Zicsr    => CPU_EXTENSION_RISCV_Zicsr,     -- implement CSR system? | ||||
|     CPU_EXTENSION_RISCV_Zicntr   => true,          -- implement base counters? | ||||
|     CPU_EXTENSION_RISCV_Zihpm    => true,          -- implement hardware performance monitors? | ||||
|     CPU_EXTENSION_RISCV_Zifencei => CPU_EXTENSION_RISCV_Zifencei,  -- implement instruction stream sync.? | ||||
|     CPU_EXTENSION_RISCV_Zmmul    => false,         -- implement multiply-only M sub-extension? | ||||
|     -- Extension Options -- | ||||
|     FAST_MUL_EN                  => false,         -- use DSPs for M extension's multiplier | ||||
|     FAST_SHIFT_EN                => false,         -- use barrel shifter for shift operations | ||||
|     CPU_CNT_WIDTH                => 64,            -- total width of CPU cycle and instret counters (0..64) | ||||
|     -- Physical Memory Protection (PMP) -- | ||||
|     PMP_NUM_REGIONS              => 8,             -- number of regions (0..64) | ||||
|     PMP_MIN_GRANULARITY          => 64*1024,       -- minimal region granularity in bytes, has to be a power of 2, min 8 bytes | ||||
|     -- Hardware Performance Monitors (HPM) -- | ||||
|     HPM_NUM_CNTS                 => 12,            -- number of implemented HPM counters (0..29) | ||||
|     HPM_CNT_WIDTH                => 40,            -- total size of HPM counters (0..64) | ||||
|     -- Internal Instruction memory -- | ||||
|     MEM_INT_IMEM_EN              => int_imem_c ,   -- implement processor-internal instruction memory | ||||
|     MEM_INT_IMEM_SIZE            => MEM_INT_IMEM_SIZE,   -- size of processor-internal instruction memory in bytes | ||||
|     -- Internal Data memory -- | ||||
|     MEM_INT_DMEM_EN              => int_dmem_c,    -- implement processor-internal data memory | ||||
|     MEM_INT_DMEM_SIZE            => dmem_size_c,   -- size of processor-internal data memory in bytes | ||||
|     -- Internal Cache memory -- | ||||
|     ICACHE_EN                    => true,          -- implement instruction cache | ||||
|     ICACHE_NUM_BLOCKS            => 8,             -- i-cache: number of blocks (min 2), has to be a power of 2 | ||||
|     ICACHE_BLOCK_SIZE            => 64,            -- i-cache: block size in bytes (min 4), has to be a power of 2 | ||||
|     ICACHE_ASSOCIATIVITY         => 2,             -- i-cache: associativity / number of sets (1=direct_mapped), has to be a power of 2 | ||||
|     -- External memory interface -- | ||||
|     MEM_EXT_EN                   => true,          -- implement external memory bus interface? | ||||
|     MEM_EXT_TIMEOUT              => 256,           -- cycles after a pending bus access auto-terminates (0 = disabled) | ||||
|     -- Stream link interface -- | ||||
|     SLINK_NUM_TX                 => 8,             -- number of TX links (0..8) | ||||
|     SLINK_NUM_RX                 => 8,             -- number of TX links (0..8) | ||||
|     SLINK_TX_FIFO                => 4,             -- TX fifo depth, has to be a power of two | ||||
|     SLINK_RX_FIFO                => 1,             -- RX fifo depth, has to be a power of two | ||||
|     -- External Interrupts Controller (XIRQ) -- | ||||
|     XIRQ_NUM_CH                  => 32,            -- number of external IRQ channels (0..32) | ||||
|     XIRQ_TRIGGER_TYPE            => (others => '1'), -- trigger type: 0=level, 1=edge | ||||
|     XIRQ_TRIGGER_POLARITY        => (others => '1'), -- trigger polarity: 0=low-level/falling-edge, 1=high-level/rising-edge | ||||
|     -- Processor peripherals -- | ||||
|     IO_GPIO_EN                   => true,          -- implement general purpose input/output port unit (GPIO)? | ||||
|     IO_MTIME_EN                  => true,          -- implement machine system timer (MTIME)? | ||||
|     IO_UART0_EN                  => true,          -- implement primary universal asynchronous receiver/transmitter (UART0)? | ||||
|     IO_UART0_RX_FIFO             => 32,            -- RX fifo depth, has to be a power of two, min 1 | ||||
|     IO_UART0_TX_FIFO             => 32,            -- TX fifo depth, has to be a power of two, min 1 | ||||
|     IO_UART1_EN                  => true,          -- implement secondary universal asynchronous receiver/transmitter (UART1)? | ||||
|     IO_UART1_RX_FIFO             => 1,             -- RX fifo depth, has to be a power of two, min 1 | ||||
|     IO_UART1_TX_FIFO             => 1,             -- TX fifo depth, has to be a power of two, min 1 | ||||
|     IO_SPI_EN                    => true,          -- implement serial peripheral interface (SPI)? | ||||
|     IO_TWI_EN                    => true,          -- implement two-wire interface (TWI)? | ||||
|     IO_PWM_NUM_CH                => 30,            -- number of PWM channels to implement (0..60); 0 = disabled | ||||
|     IO_WDT_EN                    => true,          -- implement watch dog timer (WDT)? | ||||
|     IO_TRNG_EN                   => false,         -- trng cannot be simulated | ||||
|     IO_CFS_EN                    => true,          -- implement custom functions subsystem (CFS)? | ||||
|     IO_CFS_CONFIG                => (others => '0'), -- custom CFS configuration generic | ||||
|     IO_CFS_IN_SIZE               => 32,            -- size of CFS input conduit in bits | ||||
|     IO_CFS_OUT_SIZE              => 32,            -- size of CFS output conduit in bits | ||||
|     IO_NEOLED_EN                 => true,          -- implement NeoPixel-compatible smart LED interface (NEOLED)? | ||||
|     IO_NEOLED_TX_FIFO            => 8,             -- NEOLED TX FIFO depth, 1..32k, has to be a power of two | ||||
|     IO_GPTMR_EN                  => true           -- implement general purpose timer (GPTMR)? | ||||
|   ) | ||||
|   port map ( | ||||
|     -- Global control -- | ||||
|     clk_i          => clk_gen,         -- global clock, rising edge | ||||
|     rstn_i         => rst_gen,         -- global reset, low-active, async | ||||
|     -- JTAG on-chip debugger interface (available if ON_CHIP_DEBUGGER_EN = true) -- | ||||
|     jtag_trst_i    => '1',             -- low-active TAP reset (optional) | ||||
|     jtag_tck_i     => '0',             -- serial clock | ||||
|     jtag_tdi_i     => '0',             -- serial data input | ||||
|     jtag_tdo_o     => open,            -- serial data output | ||||
|     jtag_tms_i     => '0',             -- mode select | ||||
|     -- Wishbone bus interface (available if MEM_EXT_EN = true) -- | ||||
|     wb_tag_o       => wb_cpu.tag,      -- request tag | ||||
|     wb_adr_o       => wb_cpu.addr,     -- address | ||||
|     wb_dat_i       => wb_cpu.rdata,    -- read data | ||||
|     wb_dat_o       => wb_cpu.wdata,    -- write data | ||||
|     wb_we_o        => wb_cpu.we,       -- read/write | ||||
|     wb_sel_o       => wb_cpu.sel,      -- byte enable | ||||
|     wb_stb_o       => wb_cpu.stb,      -- strobe | ||||
|     wb_cyc_o       => wb_cpu.cyc,      -- valid cycle | ||||
|     wb_lock_o      => wb_cpu.lock,     -- exclusive access request | ||||
|     wb_ack_i       => wb_cpu.ack,      -- transfer acknowledge | ||||
|     wb_err_i       => wb_cpu.err,      -- transfer error | ||||
|     -- Advanced memory control signals (available if MEM_EXT_EN = true) -- | ||||
|     fence_o        => open,            -- indicates an executed FENCE operation | ||||
|     fencei_o       => open,            -- indicates an executed FENCEI operation | ||||
|     -- TX stream interfaces (available if SLINK_NUM_TX > 0) -- | ||||
|     slink_tx_dat_o => slink_dat,       -- output data | ||||
|     slink_tx_val_o => slink_val,       -- valid output | ||||
|     slink_tx_rdy_i => slink_rdy,       -- ready to send | ||||
|     -- RX stream interfaces (available if SLINK_NUM_RX > 0) -- | ||||
|     slink_rx_dat_i => slink_dat,       -- input data | ||||
|     slink_rx_val_i => slink_val,       -- valid input | ||||
|     slink_rx_rdy_o => slink_rdy,       -- ready to receive | ||||
|     -- GPIO (available if IO_GPIO_EN = true) -- | ||||
|     gpio_o         => gpio,            -- parallel output | ||||
|     gpio_i         => gpio,            -- parallel input | ||||
|     -- primary UART0 (available if IO_UART0_EN = true) -- | ||||
|     uart0_txd_o    => uart0_txd,       -- UART0 send data | ||||
|     uart0_rxd_i    => uart0_txd,       -- UART0 receive data | ||||
|     uart0_rts_o    => uart0_cts,       -- hw flow control: UART0.RX ready to receive ("RTR"), low-active, optional | ||||
|     uart0_cts_i    => uart0_cts,       -- hw flow control: UART0.TX allowed to transmit, low-active, optional | ||||
|     -- secondary UART1 (available if IO_UART1_EN = true) -- | ||||
|     uart1_txd_o    => uart1_txd,       -- UART1 send data | ||||
|     uart1_rxd_i    => uart1_txd,       -- UART1 receive data | ||||
|     uart1_rts_o    => uart1_cts,       -- hw flow control: UART1.RX ready to receive ("RTR"), low-active, optional | ||||
|     uart1_cts_i    => uart1_cts,       -- hw flow control: UART1.TX allowed to transmit, low-active, optional | ||||
|     -- SPI (available if IO_SPI_EN = true) -- | ||||
|     spi_sck_o      => open,            -- SPI serial clock | ||||
|     spi_sdo_o      => spi_data,        -- controller data out, peripheral data in | ||||
|     spi_sdi_i      => spi_data,        -- controller data in, peripheral data out | ||||
|     spi_csn_o      => open,            -- SPI CS | ||||
|     -- TWI (available if IO_TWI_EN = true) -- | ||||
|     twi_sda_io     => twi_sda,         -- twi serial data line | ||||
|     twi_scl_io     => twi_scl,         -- twi serial clock line | ||||
|     -- PWM (available if IO_PWM_NUM_CH > 0) -- | ||||
|     pwm_o          => open,            -- pwm channels | ||||
|     -- Custom Functions Subsystem IO -- | ||||
|     cfs_in_i       => (others => '0'), -- custom CFS inputs | ||||
|     cfs_out_o      => open,            -- custom CFS outputs | ||||
|     -- NeoPixel-compatible smart LED interface (available if IO_NEOLED_EN = true) -- | ||||
|     neoled_o       => open,            -- async serial data line | ||||
|     -- System time -- | ||||
|     mtime_i        => (others => '0'), -- current system time from ext. MTIME (if IO_MTIME_EN = false) | ||||
|     mtime_o        => open,            -- current system time from int. MTIME (if IO_MTIME_EN = true) | ||||
|     -- External platform interrupts (available if XIRQ_NUM_CH > 0) -- | ||||
|     xirq_i         => gpio(31 downto 0), -- IRQ channels | ||||
|     -- CPU Interrupts -- | ||||
|     mtime_irq_i    => '0',             -- machine software interrupt, available if IO_MTIME_EN = false | ||||
|     msw_irq_i      => msi_ring,        -- machine software interrupt | ||||
|     mext_irq_i     => mei_ring         -- machine external interrupt | ||||
|   ); | ||||
|  | ||||
|   -- TWI termination (pull-ups) -- | ||||
|   twi_scl <= 'H'; | ||||
|   twi_sda <= 'H'; | ||||
|  | ||||
|  | ||||
|   -- UART Simulation Receiver --------------------------------------------------------------- | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   uart0_checker: entity work.uart_rx_simple | ||||
|   generic map ( | ||||
|     name => "uart0", | ||||
|     uart_baud_val_c => uart0_baud_val_c | ||||
|   ) | ||||
|   port map ( | ||||
|     clk => clk_gen, | ||||
|     uart_txd => uart0_txd | ||||
|   ); | ||||
|  | ||||
|   uart1_checker: entity work.uart_rx_simple | ||||
|   generic map ( | ||||
|     name => "uart1", | ||||
|     uart_baud_val_c => uart1_baud_val_c | ||||
|   ) | ||||
|   port map ( | ||||
|     clk => clk_gen, | ||||
|     uart_txd => uart1_txd | ||||
|   ); | ||||
|  | ||||
|  | ||||
|   -- Wishbone Fabric ------------------------------------------------------------------------ | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   -- CPU broadcast signals -- | ||||
|   wb_mem_a.addr  <= wb_cpu.addr; | ||||
|   wb_mem_a.wdata <= wb_cpu.wdata; | ||||
|   wb_mem_a.we    <= wb_cpu.we; | ||||
|   wb_mem_a.sel   <= wb_cpu.sel; | ||||
|   wb_mem_a.tag   <= wb_cpu.tag; | ||||
|   wb_mem_a.cyc   <= wb_cpu.cyc; | ||||
|   wb_mem_a.lock  <= wb_cpu.lock; | ||||
|  | ||||
|   wb_mem_b.addr  <= wb_cpu.addr; | ||||
|   wb_mem_b.wdata <= wb_cpu.wdata; | ||||
|   wb_mem_b.we    <= wb_cpu.we; | ||||
|   wb_mem_b.sel   <= wb_cpu.sel; | ||||
|   wb_mem_b.tag   <= wb_cpu.tag; | ||||
|   wb_mem_b.cyc   <= wb_cpu.cyc; | ||||
|   wb_mem_b.lock  <= wb_cpu.lock; | ||||
|  | ||||
|   wb_mem_c.addr  <= wb_cpu.addr; | ||||
|   wb_mem_c.wdata <= wb_cpu.wdata; | ||||
|   wb_mem_c.we    <= wb_cpu.we; | ||||
|   wb_mem_c.sel   <= wb_cpu.sel; | ||||
|   wb_mem_c.tag   <= wb_cpu.tag; | ||||
|   wb_mem_c.cyc   <= wb_cpu.cyc; | ||||
|   wb_mem_c.lock  <= wb_cpu.lock; | ||||
|  | ||||
|   wb_irq.addr    <= wb_cpu.addr; | ||||
|   wb_irq.wdata   <= wb_cpu.wdata; | ||||
|   wb_irq.we      <= wb_cpu.we; | ||||
|   wb_irq.sel     <= wb_cpu.sel; | ||||
|   wb_irq.tag     <= wb_cpu.tag; | ||||
|   wb_irq.cyc     <= wb_cpu.cyc; | ||||
|  | ||||
|   -- CPU read-back signals (no mux here since peripherals have "output gates") -- | ||||
|   wb_cpu.rdata <= wb_mem_a.rdata or wb_mem_b.rdata or wb_mem_c.rdata or wb_irq.rdata; | ||||
|   wb_cpu.ack   <= wb_mem_a.ack   or wb_mem_b.ack   or wb_mem_c.ack   or wb_irq.ack; | ||||
|   wb_cpu.err   <= wb_mem_a.err   or wb_mem_b.err   or wb_mem_c.err   or wb_irq.err; | ||||
|  | ||||
|   -- peripheral select via STROBE signal -- | ||||
|   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'; | ||||
|   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'; | ||||
|   wb_mem_c.stb <= wb_cpu.stb when (wb_cpu.addr >= ext_mem_c_base_addr_c) and (wb_cpu.addr < std_ulogic_vector(unsigned(ext_mem_c_base_addr_c) + ext_mem_c_size_c)) else '0'; | ||||
|   wb_irq.stb   <= wb_cpu.stb when (wb_cpu.addr =  irq_trigger_base_addr_c) else '0'; | ||||
|  | ||||
|  | ||||
|   -- Wishbone Memory A (simulated external IMEM) -------------------------------------------- | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   generate_ext_imem: | ||||
|   if (EXT_IMEM_C = true) generate | ||||
|     ext_mem_a_access: process(clk_gen) | ||||
|       variable ext_ram_a : mem32_t(0 to ext_mem_a_size_c/4-1) := mem32_init_f(application_init_image, ext_mem_a_size_c/4); -- initialized, used to simulate external IMEM | ||||
|     begin | ||||
|       if rising_edge(clk_gen) then | ||||
|         -- control -- | ||||
|         ext_mem_a.ack(0) <= wb_mem_a.cyc and wb_mem_a.stb; -- wishbone acknowledge | ||||
|  | ||||
|         -- write access -- | ||||
|         if ((wb_mem_a.cyc and wb_mem_a.stb and wb_mem_a.we) = '1') then -- valid write access | ||||
|           for i in 0 to 3 loop | ||||
|             if (wb_mem_a.sel(i) = '1') then | ||||
|               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); | ||||
|             end if; | ||||
|           end loop; -- i | ||||
|         end if; | ||||
|  | ||||
|         -- read access -- | ||||
|         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 | ||||
|         -- virtual read and ack latency -- | ||||
|         if (ext_mem_a_latency_c > 1) then | ||||
|           for i in 1 to ext_mem_a_latency_c-1 loop | ||||
|             ext_mem_a.rdata(i) <= ext_mem_a.rdata(i-1); | ||||
|             ext_mem_a.ack(i)   <= ext_mem_a.ack(i-1) and wb_mem_a.cyc; | ||||
|           end loop; | ||||
|         end if; | ||||
|  | ||||
|         -- bus output register -- | ||||
|         wb_mem_a.err <= '0'; | ||||
|         if (ext_mem_a.ack(ext_mem_a_latency_c-1) = '1') and (wb_mem_a.cyc = '1') and (wb_mem_a.ack = '0') then | ||||
|           wb_mem_a.rdata <= ext_mem_a.rdata(ext_mem_a_latency_c-1); | ||||
|           wb_mem_a.ack   <= '1'; | ||||
|         else | ||||
|           wb_mem_a.rdata <= (others => '0'); | ||||
|           wb_mem_a.ack   <= '0'; | ||||
|         end if; | ||||
|       end if; | ||||
|     end process ext_mem_a_access; | ||||
|   end generate; | ||||
|  | ||||
|   generate_ext_imem_false: | ||||
|   if (EXT_IMEM_C = false) generate | ||||
|     wb_mem_a.rdata <= (others => '0'); | ||||
|     wb_mem_a.ack   <= '0'; | ||||
|     wb_mem_a.err   <= '0'; | ||||
|   end generate; | ||||
|  | ||||
|  | ||||
|   -- Wishbone Memory B (simulated external DMEM) -------------------------------------------- | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   ext_mem_b_access: process(clk_gen) | ||||
|     variable ext_ram_b : mem32_t(0 to ext_mem_b_size_c/4-1) := (others => (others => '0')); -- zero, used to simulate external DMEM | ||||
|   begin | ||||
|     if rising_edge(clk_gen) then | ||||
|       -- control -- | ||||
|       ext_mem_b.ack(0) <= wb_mem_b.cyc and wb_mem_b.stb; -- wishbone acknowledge | ||||
|  | ||||
|       -- write access -- | ||||
|       if ((wb_mem_b.cyc and wb_mem_b.stb and wb_mem_b.we) = '1') then -- valid write access | ||||
|         for i in 0 to 3 loop | ||||
|           if (wb_mem_b.sel(i) = '1') then | ||||
|             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); | ||||
|           end if; | ||||
|         end loop; -- i | ||||
|       end if; | ||||
|  | ||||
|       -- read access -- | ||||
|       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 | ||||
|       -- virtual read and ack latency -- | ||||
|       if (ext_mem_b_latency_c > 1) then | ||||
|         for i in 1 to ext_mem_b_latency_c-1 loop | ||||
|           ext_mem_b.rdata(i) <= ext_mem_b.rdata(i-1); | ||||
|           ext_mem_b.ack(i)   <= ext_mem_b.ack(i-1) and wb_mem_b.cyc; | ||||
|         end loop; | ||||
|       end if; | ||||
|  | ||||
|       -- bus output register -- | ||||
|       wb_mem_b.err <= '0'; | ||||
|       if (ext_mem_b.ack(ext_mem_b_latency_c-1) = '1') and (wb_mem_b.cyc = '1') and (wb_mem_b.ack = '0') then | ||||
|         wb_mem_b.rdata <= ext_mem_b.rdata(ext_mem_b_latency_c-1); | ||||
|         wb_mem_b.ack   <= '1'; | ||||
|       else | ||||
|         wb_mem_b.rdata <= (others => '0'); | ||||
|         wb_mem_b.ack   <= '0'; | ||||
|       end if; | ||||
|     end if; | ||||
|   end process ext_mem_b_access; | ||||
|  | ||||
|  | ||||
|   -- Wishbone Memory C (simulated external IO) ---------------------------------------------- | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   ext_mem_c_access: process(clk_gen) | ||||
|   begin | ||||
|     if rising_edge(clk_gen) then | ||||
|       -- control -- | ||||
|       ext_mem_c.ack(0) <= wb_mem_c.cyc and wb_mem_c.stb; -- wishbone acknowledge | ||||
|  | ||||
|       -- write access -- | ||||
|       if ((wb_mem_c.cyc and wb_mem_c.stb and wb_mem_c.we) = '1') then -- valid write access | ||||
|         for i in 0 to 3 loop | ||||
|           if (wb_mem_c.sel(i) = '1') then | ||||
|             ext_ram_c(to_integer(unsigned(wb_mem_c.addr(index_size_f(ext_mem_c_size_c/4)+1 downto 2))))(7+i*8 downto 0+i*8) <= wb_mem_c.wdata(7+i*8 downto 0+i*8); | ||||
|           end if; | ||||
|         end loop; -- i | ||||
|       end if; | ||||
|  | ||||
|       -- read access -- | ||||
|       ext_mem_c.rdata(0) <= ext_ram_c(to_integer(unsigned(wb_mem_c.addr(index_size_f(ext_mem_c_size_c/4)+1 downto 2)))); -- word aligned | ||||
|       -- virtual read and ack latency -- | ||||
|       if (ext_mem_c_latency_c > 1) then | ||||
|         for i in 1 to ext_mem_c_latency_c-1 loop | ||||
|           ext_mem_c.rdata(i) <= ext_mem_c.rdata(i-1); | ||||
|           ext_mem_c.ack(i)   <= ext_mem_c.ack(i-1) and wb_mem_c.cyc; | ||||
|         end loop; | ||||
|       end if; | ||||
|  | ||||
|       -- EXCLUSIVE bus access ----------------------------------------------------- | ||||
|       -- ----------------------------------------------------------------------------- | ||||
|       -- Since there is only one CPU in this design, the exclusive access reservation in THIS memory CANNOT fail. | ||||
|       -- However, this memory module is used to simulated failing LR/SC accesses. | ||||
|       if ((wb_mem_c.cyc and wb_mem_c.stb) = '1') then -- valid access | ||||
|         ext_mem_c_atomic_reservation <= wb_mem_c.lock; -- make reservation | ||||
|       end if; | ||||
|       -- ----------------------------------------------------------------------------- | ||||
|  | ||||
|       -- bus output register -- | ||||
|       if (ext_mem_c.ack(ext_mem_c_latency_c-1) = '1') and (wb_mem_c.cyc = '1') and (wb_mem_c.ack = '0') then | ||||
|         wb_mem_c.rdata <= ext_mem_c.rdata(ext_mem_c_latency_c-1); | ||||
|         wb_mem_c.ack   <= '1'; | ||||
|         wb_mem_c.err   <= ext_mem_c_atomic_reservation; -- issue a bus error if there is an exclusive access request | ||||
|       else | ||||
|         wb_mem_c.rdata <= (others => '0'); | ||||
|         wb_mem_c.ack   <= '0'; | ||||
|         wb_mem_c.err   <= '0'; | ||||
|       end if; | ||||
|     end if; | ||||
|   end process ext_mem_c_access; | ||||
|  | ||||
|  | ||||
|   -- Wishbone IRQ Triggers ------------------------------------------------------------------ | ||||
|   -- ------------------------------------------------------------------------------------------- | ||||
|   irq_trigger: process(rst_gen, clk_gen) | ||||
|   begin | ||||
|     if (rst_gen = '0') then | ||||
|       msi_ring <= '0'; | ||||
|       mei_ring <= '0'; | ||||
|     elsif rising_edge(clk_gen) then | ||||
|       -- bus interface -- | ||||
|       wb_irq.rdata <= (others => '0'); | ||||
|       wb_irq.ack   <= wb_irq.cyc and wb_irq.stb and wb_irq.we and and_reduce_f(wb_irq.sel); | ||||
|       wb_irq.err   <= '0'; | ||||
|       -- trigger RISC-V platform IRQs -- | ||||
|       if ((wb_irq.cyc and wb_irq.stb and wb_irq.we and and_reduce_f(wb_irq.sel)) = '1') then | ||||
|         msi_ring <= wb_irq.wdata(03); -- machine software interrupt | ||||
|         mei_ring <= wb_irq.wdata(11); -- machine software interrupt | ||||
|       end if; | ||||
|     end if; | ||||
|   end process irq_trigger; | ||||
|  | ||||
|  | ||||
| end neorv32_tb_simple_rtl; | ||||
							
								
								
									
										77
									
								
								Libs/RiscV_test/NEORV32_test/simple/uart_rx.simple.vhd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								Libs/RiscV_test/NEORV32_test/simple/uart_rx.simple.vhd
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,77 @@ | ||||
| library ieee; | ||||
| use ieee.std_logic_1164.all; | ||||
| use ieee.numeric_std.all; | ||||
| use ieee.math_real.all; | ||||
|  | ||||
| use std.textio.all; | ||||
|  | ||||
| entity uart_rx_simple is | ||||
|   generic ( | ||||
|     name : string; | ||||
|     uart_baud_val_c : real); | ||||
|  | ||||
|   port ( | ||||
|     clk : in std_ulogic; | ||||
|     uart_txd : in std_ulogic | ||||
|     ); | ||||
| end entity; | ||||
|  | ||||
| architecture a of uart_rx_simple is | ||||
|   signal uart_rx_sync : std_ulogic_vector(04 downto 0) := (others => '1'); | ||||
|   signal uart_rx_busy : std_ulogic := '0'; | ||||
|   signal uart_rx_sreg : std_ulogic_vector(08 downto 0) := (others => '0'); | ||||
|   signal uart_rx_baud_cnt : real; | ||||
|   signal uart_rx_bitcnt : natural; | ||||
|  | ||||
|   file file_uart_tx_out : text open write_mode is "neorv32.testbench_" & name & ".out"; | ||||
|  | ||||
| begin | ||||
|   uart_rx_console : process(clk) | ||||
|     variable i : integer; | ||||
|     variable l : line; | ||||
|   begin | ||||
|     -- "UART" -- | ||||
|     if rising_edge(clk) then | ||||
|       -- synchronizer -- | ||||
|       uart_rx_sync <= uart_rx_sync(3 downto 0) & uart_txd; | ||||
|       -- arbiter -- | ||||
|       if (uart_rx_busy = '0') then  -- idle | ||||
|         uart_rx_busy <= '0'; | ||||
|         uart_rx_baud_cnt <= round(0.5 * uart_baud_val_c); | ||||
|         uart_rx_bitcnt <= 9; | ||||
|         if (uart_rx_sync(4 downto 1) = "1100") then  -- start bit? (falling edge) | ||||
|           uart_rx_busy <= '1'; | ||||
|         end if; | ||||
|       else | ||||
|         if (uart_rx_baud_cnt <= 0.0) then | ||||
|           if (uart_rx_bitcnt = 1) then | ||||
|             uart_rx_baud_cnt <= round(0.5 * uart_baud_val_c); | ||||
|           else | ||||
|             uart_rx_baud_cnt <= round(uart_baud_val_c); | ||||
|           end if; | ||||
|           if (uart_rx_bitcnt = 0) then | ||||
|             uart_rx_busy <= '0';  -- done | ||||
|             i := to_integer(unsigned(uart_rx_sreg(8 downto 1))); | ||||
|  | ||||
|             if (i < 32) or (i > 32+95) then  -- printable char? | ||||
|               report name & ".tx: (" & integer'image(i) & ")";  -- print code | ||||
|             else | ||||
|               report name & ".tx: " & character'val(i);  -- print ASCII | ||||
|             end if; | ||||
|  | ||||
|             if (i = 10) then  -- Linux line break | ||||
|               writeline(file_uart_tx_out, l); | ||||
|             elsif (i /= 13) then  -- Remove additional carriage return | ||||
|               write(l, character'val(i)); | ||||
|             end if; | ||||
|           else | ||||
|             uart_rx_sreg <= uart_rx_sync(4) & uart_rx_sreg(8 downto 1); | ||||
|             uart_rx_bitcnt <= uart_rx_bitcnt - 1; | ||||
|           end if; | ||||
|         else | ||||
|           uart_rx_baud_cnt <= uart_rx_baud_cnt - 1.0; | ||||
|         end if; | ||||
|       end if; | ||||
|     end if; | ||||
|   end process uart_rx_console; | ||||
| end architecture; | ||||
							
								
								
									
										119
									
								
								Libs/RiscV_test/NEORV32_test/uart_rx.vhd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										119
									
								
								Libs/RiscV_test/NEORV32_test/uart_rx.vhd
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,119 @@ | ||||
| library ieee; | ||||
| use ieee.std_logic_1164.all; | ||||
| use ieee.numeric_std.all; | ||||
| use ieee.math_real.all; | ||||
|  | ||||
| use std.textio.all; | ||||
|  | ||||
| library vunit_lib; | ||||
| context vunit_lib.vunit_context; | ||||
| context vunit_lib.com_context; | ||||
| context vunit_lib.vc_context; | ||||
|  | ||||
| use work.uart_rx_pkg.all; | ||||
|  | ||||
| entity uart_rx is | ||||
|   generic (handle : uart_rx_t); | ||||
|   port ( | ||||
|     clk : in std_ulogic; | ||||
|     uart_txd : in std_ulogic | ||||
|     ); | ||||
| end entity; | ||||
|  | ||||
| architecture a of uart_rx is | ||||
|   signal uart_rx_sync : std_ulogic_vector(04 downto 0) := (others => '1'); | ||||
|   signal uart_rx_busy : std_ulogic := '0'; | ||||
|   signal uart_rx_sreg : std_ulogic_vector(08 downto 0) := (others => '0'); | ||||
|   signal uart_rx_baud_cnt : real; | ||||
|   signal uart_rx_bitcnt : natural; | ||||
|  | ||||
|   file file_uart_tx_out : text open write_mode is "neorv32.testbench_" & get_name(handle.p_logger) & ".out"; | ||||
|   constant checker : checker_t := new_checker(handle.p_logger); | ||||
|   constant character_queue : queue_t := new_queue; | ||||
|  | ||||
| begin | ||||
|   control : process | ||||
|     variable request_msg, reply_msg : msg_t; | ||||
|     variable msg_type : msg_type_t; | ||||
|  | ||||
|     procedure put_characters_in_queue(s : string) is | ||||
|     begin | ||||
|       for idx in s'range loop | ||||
|         push(character_queue, s(idx)); | ||||
|       end loop; | ||||
|     end procedure put_characters_in_queue; | ||||
|   begin | ||||
|     receive(net, handle.p_actor, request_msg); | ||||
|     msg_type := message_type(request_msg); | ||||
|  | ||||
|     -- Standard handling of standard wait_for_time messages = wait for the given time | ||||
|     -- before proceeeding | ||||
|     handle_wait_for_time(net, msg_type, request_msg); | ||||
|  | ||||
|     if msg_type = check_uart_msg then | ||||
|       put_characters_in_queue(pop(request_msg)); | ||||
|  | ||||
|     -- Custom handling of standard wait_until_idle message | ||||
|     elsif msg_type = wait_until_idle_msg then | ||||
|       while not is_empty(character_queue) loop | ||||
|         wait until rising_edge(clk); | ||||
|       end loop; | ||||
|       reply_msg := new_msg(wait_until_idle_reply_msg); | ||||
|       reply(net, request_msg, reply_msg); | ||||
|  | ||||
|     else | ||||
|       unexpected_msg_type(msg_type); | ||||
|     end if; | ||||
|   end process; | ||||
|  | ||||
|   uart_rx_console : process(clk) | ||||
|     variable i : integer; | ||||
|     variable l : line; | ||||
|     variable expected_character : character; | ||||
|   begin | ||||
|     -- "UART" -- | ||||
|     if rising_edge(clk) then | ||||
|       -- synchronizer -- | ||||
|       uart_rx_sync <= uart_rx_sync(3 downto 0) & uart_txd; | ||||
|       -- arbiter -- | ||||
|       if (uart_rx_busy = '0') then  -- idle | ||||
|         uart_rx_busy <= '0'; | ||||
|         uart_rx_baud_cnt <= round(0.5 * handle.p_baud_val); | ||||
|         uart_rx_bitcnt <= 9; | ||||
|         if (uart_rx_sync(4 downto 1) = "1100") then  -- start bit? (falling edge) | ||||
|           uart_rx_busy <= '1'; | ||||
|         end if; | ||||
|       else | ||||
|         if (uart_rx_baud_cnt <= 0.0) then | ||||
|           if (uart_rx_bitcnt = 1) then | ||||
|             uart_rx_baud_cnt <= round(0.5 * handle.p_baud_val); | ||||
|           else | ||||
|             uart_rx_baud_cnt <= round(handle.p_baud_val); | ||||
|           end if; | ||||
|           if (uart_rx_bitcnt = 0) then | ||||
|             uart_rx_busy <= '0';  -- done | ||||
|             i := to_integer(unsigned(uart_rx_sreg(8 downto 1))); | ||||
|  | ||||
|             if is_empty(character_queue) then | ||||
|               check_failed(checker, "Extra characters received"); | ||||
|             else | ||||
|               expected_character := pop(character_queue); | ||||
|               check_equal(checker, character'val(i), expected_character); | ||||
|             end if; | ||||
|  | ||||
|             if (i = 10) then  -- Linux line break | ||||
|               writeline(file_uart_tx_out, l); | ||||
|             elsif (i /= 13) then  -- Remove additional carriage return | ||||
|               write(l, character'val(i)); | ||||
|             end if; | ||||
|           else | ||||
|             uart_rx_sreg <= uart_rx_sync(4) & uart_rx_sreg(8 downto 1); | ||||
|             uart_rx_bitcnt <= uart_rx_bitcnt - 1; | ||||
|           end if; | ||||
|         else | ||||
|           uart_rx_baud_cnt <= uart_rx_baud_cnt - 1.0; | ||||
|         end if; | ||||
|       end if; | ||||
|     end if; | ||||
|   end process uart_rx_console; | ||||
| end architecture; | ||||
							
								
								
									
										60
									
								
								Libs/RiscV_test/NEORV32_test/uart_rx_pkg.vhd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								Libs/RiscV_test/NEORV32_test/uart_rx_pkg.vhd
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,60 @@ | ||||
| library vunit_lib; | ||||
| context vunit_lib.vunit_context; | ||||
| context vunit_lib.com_context; | ||||
| use vunit_lib.sync_pkg.all; | ||||
|  | ||||
| package uart_rx_pkg is | ||||
|   constant check_uart_msg : msg_type_t := new_msg_type("check_uart"); | ||||
|  | ||||
|   type uart_rx_t is record | ||||
|     p_baud_val : real; | ||||
|     p_logger : logger_t; | ||||
|     p_actor : actor_t; | ||||
|   end record; | ||||
|  | ||||
|   impure function new_uart_rx( | ||||
|     baud_val : real; | ||||
|     logger : logger_t := null_logger; | ||||
|     actor : actor_t := null_actor) return uart_rx_t; | ||||
|  | ||||
|   function as_sync(handle : uart_rx_t) return sync_handle_t; | ||||
|  | ||||
|   procedure check_uart( | ||||
|     signal net : inout network_t; | ||||
|     constant handle : in uart_rx_t; | ||||
|     constant data : in string); | ||||
| end package uart_rx_pkg; | ||||
|  | ||||
| package body uart_rx_pkg is | ||||
|   constant uart_rx_logger  : logger_t  := get_logger("neorv32_lib:uart_rx_pkg"); | ||||
|  | ||||
|   impure function new_uart_rx( | ||||
|     baud_val : real; | ||||
|     logger : logger_t := null_logger; | ||||
|     actor : actor_t := null_actor) return uart_rx_t is | ||||
|     variable result : uart_rx_t; | ||||
|   begin | ||||
|     result.p_baud_val := baud_val; | ||||
|     result.p_logger := logger when logger /= null_logger else uart_rx_logger; | ||||
|     result.p_actor := actor when actor /= null_actor else new_actor; | ||||
|  | ||||
|     return result; | ||||
|   end; | ||||
|  | ||||
|   function as_sync(handle : uart_rx_t) return sync_handle_t is | ||||
|   begin | ||||
|     return handle.p_actor; | ||||
|   end; | ||||
|  | ||||
|   procedure check_uart( | ||||
|     signal net : inout network_t; | ||||
|     constant handle : in uart_rx_t; | ||||
|     constant data : in string) is | ||||
|     variable msg : msg_t; | ||||
|   begin | ||||
|     msg := new_msg(check_uart_msg); | ||||
|     push(msg, data); | ||||
|     send(net, handle.p_actor, msg); | ||||
|   end; | ||||
|  | ||||
| end package body uart_rx_pkg; | ||||
		Reference in New Issue
	
	Block a user