1 |
2 |
sinx |
----------------------------------------------------------------------
|
2 |
|
|
---- ----
|
3 |
|
|
---- VHDL Wishbone TESTBENCH ----
|
4 |
|
|
---- ----
|
5 |
|
|
---- This file is part of the vhdl_wb_tb project ----
|
6 |
4 |
sinx |
---- https://opencores.org/project/vhdl_wb_tb ----
|
7 |
2 |
sinx |
---- ----
|
8 |
4 |
sinx |
---- This file contains the highest (top) module for simulation. ----
|
9 |
|
|
---- Like tb_top it instantiates the core_top module and ----
|
10 |
|
|
---- provides parameters/generics. Where the top module provides ----
|
11 |
|
|
---- parameters for synthesis this file provides parameters for ----
|
12 |
|
|
---- simulation. ----
|
13 |
|
|
---- ----
|
14 |
2 |
sinx |
---- It instantiates the design under test (DUT), instantiates ----
|
15 |
|
|
---- the stimulator module for test vector generation, ----
|
16 |
|
|
---- instantiates the verifier module for result comparison, ----
|
17 |
|
|
---- instantiates the test case top (testcase_top) bfm, ----
|
18 |
|
|
---- interconnects all three components, generates DUT-external ----
|
19 |
|
|
---- clocks and resets. ----
|
20 |
|
|
---- ----
|
21 |
|
|
---- To Do: ----
|
22 |
|
|
---- - ----
|
23 |
|
|
---- ----
|
24 |
|
|
---- Author(s): ----
|
25 |
4 |
sinx |
---- - Sinx, sinx@opencores.org ----
|
26 |
2 |
sinx |
---- ----
|
27 |
|
|
----------------------------------------------------------------------
|
28 |
4 |
sinx |
---- SVN information
|
29 |
|
|
----
|
30 |
|
|
---- $URL: $
|
31 |
|
|
---- $Revision: $
|
32 |
|
|
---- $Date: $
|
33 |
|
|
---- $Author: $
|
34 |
|
|
---- $Id: $
|
35 |
2 |
sinx |
----------------------------------------------------------------------
|
36 |
|
|
---- ----
|
37 |
|
|
---- Copyright (C) 2018 Authors and OPENCORES.ORG ----
|
38 |
|
|
---- ----
|
39 |
|
|
---- This source file may be used and distributed without ----
|
40 |
|
|
---- restriction provided that this copyright statement is not ----
|
41 |
|
|
---- removed from the file and that any derivative work contains ----
|
42 |
|
|
---- the original copyright notice and the associated disclaimer. ----
|
43 |
|
|
---- ----
|
44 |
|
|
---- This source file is free software; you can redistribute it ----
|
45 |
|
|
---- and/or modify it under the terms of the GNU Lesser General ----
|
46 |
|
|
---- Public License as published by the Free Software Foundation; ----
|
47 |
|
|
---- either version 2.1 of the License, or (at your option) any ----
|
48 |
|
|
---- later version. ----
|
49 |
|
|
---- ----
|
50 |
|
|
---- This source is distributed in the hope that it will be ----
|
51 |
|
|
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
|
52 |
|
|
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
|
53 |
|
|
---- PURPOSE. See the GNU Lesser General Public License for more ----
|
54 |
|
|
---- details. ----
|
55 |
|
|
---- ----
|
56 |
|
|
---- You should have received a copy of the GNU Lesser General ----
|
57 |
|
|
---- Public License along with this source; if not, download it ----
|
58 |
|
|
---- from http://www.opencores.org/lgpl.shtml ----
|
59 |
|
|
---- ----
|
60 |
|
|
----------------------------------------------------------------------
|
61 |
|
|
|
62 |
|
|
-- library -----------------------------------------------------------
|
63 |
|
|
library ieee;
|
64 |
|
|
use ieee.std_logic_1164.all;
|
65 |
|
|
use ieee.numeric_std.all;
|
66 |
|
|
library work;
|
67 |
|
|
use work.convert_pkg.all;
|
68 |
|
|
use work.wishbone_pkg.all;
|
69 |
|
|
use work.wishbone_bfm_pkg.all;
|
70 |
|
|
|
71 |
|
|
-- entity ------------------------------------------------------------
|
72 |
|
|
entity tb_top is
|
73 |
|
|
-- empty entity, since this is the simulation top and all test cases are defined
|
74 |
|
|
-- in the tc_xxx files.
|
75 |
|
|
end entity tb_top;
|
76 |
|
|
|
77 |
4 |
sinx |
-- architecture ------------------------------------------------------
|
78 |
2 |
sinx |
architecture rtl of tb_top is
|
79 |
4 |
sinx |
-----------------------------------------------------------------------------
|
80 |
5 |
sinx |
constant wb_clock_period_g : time := 20.0 ns; -- 50 mhz
|
81 |
2 |
sinx |
-----------------------------------------------------------------------------
|
82 |
5 |
sinx |
signal wb_bfm_out_s : wishbone_bfm_master_out_t; -- from testcase_top
|
83 |
|
|
signal wb_bfm_in_s : wishbone_bfm_master_in_t; -- to testcase_top
|
84 |
2 |
sinx |
|
85 |
5 |
sinx |
signal wb_master_out_s : wishbone_master_out_t; -- from wb_decoder
|
86 |
|
|
signal wb_master_in_s : wishbone_master_in_t; -- to wb_decoder
|
87 |
2 |
sinx |
|
88 |
|
|
constant number_of_wb_slaves_c : integer := 2;
|
89 |
5 |
sinx |
signal wb_slaves_in_s : wishbone_slave_in_array_t (number_of_wb_slaves_c-1 downto 0);
|
90 |
|
|
signal wb_slaves_out_s : wishbone_slave_out_array_t (number_of_wb_slaves_c-1 downto 0);
|
91 |
2 |
sinx |
|
92 |
5 |
sinx |
signal wb_clock_s : std_logic := '0';
|
93 |
|
|
signal wb_clock_locked_s : std_logic := '0';
|
94 |
|
|
signal wb_reset_p1_s : std_logic := '1';
|
95 |
|
|
signal wb_reset_p2_s : std_logic := '1';
|
96 |
|
|
signal wb_reset_s : std_logic := '1';
|
97 |
2 |
sinx |
|
98 |
|
|
constant number_of_stimulus_signals_c : integer := 8;
|
99 |
|
|
constant number_of_verify_signals_c : integer := 8;
|
100 |
5 |
sinx |
signal stimulus_s : std_logic_vector(number_of_stimulus_signals_c-1 downto 0);
|
101 |
|
|
signal verify_s : std_logic_vector(number_of_verify_signals_c-1 downto 0);
|
102 |
2 |
sinx |
-----------------------------------------------------------------------------
|
103 |
4 |
sinx |
begin
|
104 |
2 |
sinx |
-----------------------------------------------------------------------------
|
105 |
|
|
--clocks---------------------------------------------------------------------
|
106 |
|
|
wb_clock_generator : process -- required for test bench wb bus; 50mhz is standard
|
107 |
|
|
begin
|
108 |
5 |
sinx |
wb_clock_s <= '0';
|
109 |
|
|
wait for wb_clock_period_g/2;
|
110 |
|
|
wb_clock_s <= '1';
|
111 |
|
|
wait for wb_clock_period_g/2;
|
112 |
|
|
wb_clock_locked_s <= '1';
|
113 |
2 |
sinx |
end process;
|
114 |
|
|
-----------------------------------------------------------------------------
|
115 |
|
|
synchronize_reset_proc : process(all)
|
116 |
|
|
begin
|
117 |
5 |
sinx |
if (wb_clock_locked_s = '0') then
|
118 |
|
|
wb_reset_p1_s <= '1';
|
119 |
|
|
wb_reset_p2_s <= '1';
|
120 |
|
|
elsif (rising_edge(wb_clock_s)) then
|
121 |
|
|
wb_reset_p1_s <= '0'; -- or tc_reset_s;
|
122 |
|
|
wb_reset_p2_s <= wb_reset_p1_s;
|
123 |
2 |
sinx |
end if;
|
124 |
|
|
end process;
|
125 |
5 |
sinx |
wb_reset_s <= wb_reset_p2_s;
|
126 |
2 |
sinx |
-----------------------------------------------------------------------------
|
127 |
|
|
-- instance of test case "player"; runs tc_xxxx modules
|
128 |
4 |
sinx |
tc_top_inst : entity work.tc_top
|
129 |
2 |
sinx |
port map (
|
130 |
5 |
sinx |
wb_o => wb_bfm_out_s,
|
131 |
|
|
wb_i => wb_bfm_in_s
|
132 |
2 |
sinx |
);
|
133 |
|
|
-----------------------------------------------------------------------------
|
134 |
|
|
-- splits the test case wb bus for all stimulation and verifier modules.
|
135 |
5 |
sinx |
-- decodes the given bits (decoded_address_msb_g:decoded_address_lsb_g) and#
|
136 |
|
|
-- compares them to 0..n, with n=(number_of_ports_g-1)
|
137 |
2 |
sinx |
proc_readdata_decoder : process (all)
|
138 |
|
|
begin
|
139 |
5 |
sinx |
wb_bfm_in_s.dat <= (others => 'U');
|
140 |
|
|
wb_bfm_in_s.ack <= '1';
|
141 |
|
|
wb_bfm_in_s.clk <= wb_clock_s;
|
142 |
|
|
wb_bfm_in_s.int <= '0';
|
143 |
|
|
wb_bfm_in_s.rst <= wb_reset_s;
|
144 |
2 |
sinx |
for I in number_of_wb_slaves_c-1 downto 0 loop
|
145 |
5 |
sinx |
wb_slaves_in_s(I) <= work.wishbone_pkg.wb_master_out_idle_c; -- default values are init (idle) values
|
146 |
|
|
wb_slaves_in_s(I).clk <= wb_clock_s;
|
147 |
|
|
wb_slaves_in_s(I).rst <= wb_reset_s OR wb_bfm_out_s.rst;
|
148 |
|
|
if ( wb_bfm_out_s.adr(31 downto 28) = to_std_logic_vector(I,4)) then -- decode the upper nibble for module decoding
|
149 |
|
|
wb_bfm_in_s.dat <= wb_slaves_out_s(I).dat;
|
150 |
|
|
wb_bfm_in_s.ack <= wb_slaves_out_s(I).ack;
|
151 |
|
|
wb_slaves_in_s(I).dat <= wb_bfm_out_s.dat;
|
152 |
|
|
wb_slaves_in_s(I).tgd <= wb_bfm_out_s.tgd;
|
153 |
|
|
wb_slaves_in_s(I).adr <= wb_bfm_out_s.adr;
|
154 |
|
|
wb_slaves_in_s(I).cyc <= wb_bfm_out_s.cyc;
|
155 |
|
|
wb_slaves_in_s(I).lock <= wb_bfm_out_s.lock;
|
156 |
|
|
wb_slaves_in_s(I).sel <= wb_bfm_out_s.sel;
|
157 |
|
|
wb_slaves_in_s(I).stb <= wb_bfm_out_s.stb;
|
158 |
|
|
wb_slaves_in_s(I).tga <= wb_bfm_out_s.tga;
|
159 |
|
|
wb_slaves_in_s(I).tgc <= wb_bfm_out_s.tgc;
|
160 |
|
|
wb_slaves_in_s(I).we <= wb_bfm_out_s.we;
|
161 |
2 |
sinx |
end if;
|
162 |
|
|
end loop;
|
163 |
|
|
end process;
|
164 |
|
|
-----------------------------------------------------------------------------
|
165 |
|
|
-- instance of design under test
|
166 |
|
|
core_top_inst : entity work.core_top
|
167 |
|
|
generic map(
|
168 |
5 |
sinx |
number_of_in_signals_g => number_of_stimulus_signals_c,
|
169 |
|
|
number_of_out_signals_g => number_of_verify_signals_c
|
170 |
2 |
sinx |
)
|
171 |
|
|
port map(
|
172 |
5 |
sinx |
clock_i => wb_clock_s,
|
173 |
|
|
reset_i => wb_reset_s,
|
174 |
|
|
signals_i => stimulus_s,
|
175 |
|
|
signals_o => verify_s
|
176 |
2 |
sinx |
);
|
177 |
|
|
-----------------------------------------------------------------------------
|
178 |
|
|
-- instance of stimulator
|
179 |
|
|
stimulator_inst : entity work.stimulator
|
180 |
|
|
generic map(
|
181 |
5 |
sinx |
number_of_signals_g => number_of_stimulus_signals_c
|
182 |
2 |
sinx |
)
|
183 |
|
|
port map(
|
184 |
5 |
sinx |
wb_i => wb_slaves_in_s(0),
|
185 |
|
|
wb_o => wb_slaves_out_s(0),
|
186 |
|
|
signals_o => stimulus_s
|
187 |
2 |
sinx |
);
|
188 |
|
|
-----------------------------------------------------------------------------
|
189 |
|
|
-- instance of stimulator
|
190 |
|
|
verifier_inst : entity work.verifier
|
191 |
|
|
generic map(
|
192 |
5 |
sinx |
number_of_signals_g => number_of_verify_signals_c
|
193 |
2 |
sinx |
)
|
194 |
|
|
port map(
|
195 |
5 |
sinx |
wb_i => wb_slaves_in_s(1),
|
196 |
|
|
wb_o => wb_slaves_out_s(1),
|
197 |
|
|
signals_i => verify_s
|
198 |
2 |
sinx |
);
|
199 |
|
|
-----------------------------------------------------------------------------
|
200 |
4 |
sinx |
end rtl;
|
201 |
|
|
----------------------------------------------------------------------
|
202 |
|
|
---- end of file ----
|
203 |
|
|
----------------------------------------------------------------------
|