|
| 1 | +-- This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +-- License, v. 2.0. If a copy of the MPL was not distributed with this file, |
| 3 | +-- You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 | +-- |
| 5 | +-- Copyright (c) 2014-2019, Lars Asplund lars.anders.asplund@gmail.com |
| 6 | + |
| 7 | +-- This testbench is a Minimum Working Example (MWE) of VUnit's resources to read/write data from a buffer |
| 8 | +-- allocated in a foreign C application, and to verify AXI4-Stream components. Data is sent to an AXI4-Stream |
| 9 | +-- Slave. The AXI4-Stream Slave is expected to be connected to an AXI4-Stream Master either directly or |
| 10 | +-- (preferredly) through a FIFO, thus composing a loopback. Therefore, as data is pushed to the AXI4-Stream |
| 11 | +-- Slave interface, the output is read from the AXI4-Stream Master interface and it is saved back to the buffer |
| 12 | +-- shared with the software application. |
| 13 | + |
| 14 | +library ieee; |
| 15 | +context ieee.ieee_std_context; |
| 16 | + |
| 17 | +library vunit_lib; |
| 18 | +context vunit_lib.vunit_context; |
| 19 | +context vunit_lib.vc_context; |
| 20 | + |
| 21 | +use work.pkg_c; |
| 22 | +use work.pkg_c.all; |
| 23 | + |
| 24 | +entity tb_c_axis_loop is |
| 25 | + generic ( |
| 26 | + runner_cfg : string; |
| 27 | + tb_path : string |
| 28 | + ); |
| 29 | +end entity; |
| 30 | + |
| 31 | +architecture tb of tb_c_axis_loop is |
| 32 | + -- Simulation constants |
| 33 | + |
| 34 | + constant clk_period : time := 20 ns; |
| 35 | + constant stream_length : integer := get_param(0); |
| 36 | + constant data_width : natural := get_param(1); |
| 37 | + constant fifo_depth : natural := get_param(2); |
| 38 | + |
| 39 | + -- AXI4Stream Verification Components |
| 40 | + |
| 41 | + constant m_axis : axi_stream_master_t := new_axi_stream_master(data_length => data_width); |
| 42 | + constant s_axis : axi_stream_slave_t := new_axi_stream_slave(data_length => data_width); |
| 43 | + |
| 44 | + constant ibuffer: pkg_c.memory_t := pkg_c.new_memory(0); |
| 45 | + constant obuffer: pkg_c.memory_t := pkg_c.new_memory(1); |
| 46 | + |
| 47 | + -- tb signals and variables |
| 48 | + |
| 49 | + signal clk, rst, rstn : std_logic := '0'; |
| 50 | + signal start, sent, saved : boolean := false; |
| 51 | + |
| 52 | +begin |
| 53 | + |
| 54 | + clk <= not clk after (clk_period/2); |
| 55 | + rstn <= not rst; |
| 56 | + |
| 57 | + main: process |
| 58 | + procedure run_test is begin |
| 59 | + info("Init test"); |
| 60 | + wait until rising_edge(clk); start <= true; |
| 61 | + wait until rising_edge(clk); start <= false; |
| 62 | + wait until (sent and saved and rising_edge(clk)); |
| 63 | + info("Test done"); |
| 64 | + end procedure; |
| 65 | + begin |
| 66 | + test_runner_setup(runner, runner_cfg); |
| 67 | + while test_suite loop |
| 68 | + if run("test") then |
| 69 | + rst <= '1'; |
| 70 | + wait for 15*clk_period; |
| 71 | + rst <= '0'; |
| 72 | + run_test; |
| 73 | + end if; |
| 74 | + end loop; |
| 75 | + test_runner_cleanup(runner); |
| 76 | + wait; |
| 77 | + end process; |
| 78 | + |
| 79 | +-- |
| 80 | + |
| 81 | + stimuli: process |
| 82 | + variable last : std_logic; |
| 83 | + begin |
| 84 | + sent <= false; |
| 85 | + wait until start and rising_edge(clk); |
| 86 | + |
| 87 | + for y in 0 to stream_length-1 loop |
| 88 | + wait until rising_edge(clk); |
| 89 | + push_axi_stream(net, m_axis, pkg_c.read_word(ibuffer, 4*y, 4) , tlast => '0'); |
| 90 | + end loop; |
| 91 | + |
| 92 | + info("m_I sent!"); |
| 93 | + |
| 94 | + wait until rising_edge(clk); |
| 95 | + sent <= true; |
| 96 | + wait; |
| 97 | + end process; |
| 98 | + |
| 99 | + save: process |
| 100 | + variable o : std_logic_vector(31 downto 0); |
| 101 | + variable last : std_logic:='0'; |
| 102 | + begin |
| 103 | + saved <= false; |
| 104 | + wait until start and rising_edge(clk); |
| 105 | + wait for 50*clk_period; |
| 106 | + |
| 107 | + for y in 0 to stream_length-1 loop |
| 108 | + pop_axi_stream(net, s_axis, tdata => o, tlast => last); |
| 109 | + pkg_c.write_word(obuffer, 4*y, o); |
| 110 | + end loop; |
| 111 | + |
| 112 | + info("m_O read!"); |
| 113 | + |
| 114 | + wait until rising_edge(clk); |
| 115 | + saved <= true; |
| 116 | + wait; |
| 117 | + end process; |
| 118 | + |
| 119 | +-- |
| 120 | + |
| 121 | + uut_vc: entity work.tb_vc_axis_loop |
| 122 | + generic map ( |
| 123 | + m_axis => m_axis, |
| 124 | + s_axis => s_axis, |
| 125 | + data_width => data_width, |
| 126 | + fifo_depth => fifo_depth |
| 127 | + ) |
| 128 | + port map ( |
| 129 | + clk => clk, |
| 130 | + rstn => rstn |
| 131 | + ); |
| 132 | + |
| 133 | +end architecture; |
0 commit comments