1 |
2 |
pela |
----------------------------------------------------------------------
|
2 |
|
|
---- ----
|
3 |
|
|
---- PlTbUtils Components ----
|
4 |
|
|
---- ----
|
5 |
|
|
---- This file is part of the PlTbUtils project ----
|
6 |
|
|
---- http://opencores.org/project,pltbutils ----
|
7 |
|
|
---- ----
|
8 |
|
|
---- Description: ----
|
9 |
|
|
---- PlTbUtils is a collection of functions, procedures and ----
|
10 |
|
|
---- components for easily creating stimuli and checking response ----
|
11 |
|
|
---- in automatic self-checking testbenches. ----
|
12 |
|
|
---- ----
|
13 |
|
|
---- pltbutils_comp.vhd (this file) defines testbench components. ----
|
14 |
|
|
---- ----
|
15 |
|
|
---- ----
|
16 |
|
|
---- To Do: ----
|
17 |
|
|
---- - ----
|
18 |
|
|
---- ----
|
19 |
|
|
---- Author(s): ----
|
20 |
97 |
pela |
---- - Per Larsson, pela.opencores@gmail.com ----
|
21 |
2 |
pela |
---- ----
|
22 |
|
|
----------------------------------------------------------------------
|
23 |
|
|
---- ----
|
24 |
107 |
pela |
---- Copyright (C) 2013-2020 Authors and OPENCORES.ORG ----
|
25 |
2 |
pela |
---- ----
|
26 |
|
|
---- This source file may be used and distributed without ----
|
27 |
|
|
---- restriction provided that this copyright statement is not ----
|
28 |
|
|
---- removed from the file and that any derivative work contains ----
|
29 |
|
|
---- the original copyright notice and the associated disclaimer. ----
|
30 |
|
|
---- ----
|
31 |
|
|
---- This source file is free software; you can redistribute it ----
|
32 |
|
|
---- and/or modify it under the terms of the GNU Lesser General ----
|
33 |
|
|
---- Public License as published by the Free Software Foundation; ----
|
34 |
|
|
---- either version 2.1 of the License, or (at your option) any ----
|
35 |
|
|
---- later version. ----
|
36 |
|
|
---- ----
|
37 |
|
|
---- This source is distributed in the hope that it will be ----
|
38 |
|
|
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
|
39 |
|
|
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
|
40 |
|
|
---- PURPOSE. See the GNU Lesser General Public License for more ----
|
41 |
|
|
---- details. ----
|
42 |
|
|
---- ----
|
43 |
|
|
---- You should have received a copy of the GNU Lesser General ----
|
44 |
|
|
---- Public License along with this source; if not, download it ----
|
45 |
|
|
---- from http://www.opencores.org/lgpl.shtml ----
|
46 |
|
|
---- ----
|
47 |
|
|
----------------------------------------------------------------------
|
48 |
|
|
|
49 |
|
|
----------------------------------------------------------------------
|
50 |
|
|
-- pltbutils_clkgen
|
51 |
|
|
-- Creates a clock for use in a testbech.
|
52 |
7 |
pela |
-- A non-inverted as well as an inverted output is available,
|
53 |
|
|
-- use one or both depending on if you need a single-ended or
|
54 |
|
|
-- differential clock.
|
55 |
2 |
pela |
-- The clock stops when input port stop_sim goes '1'.
|
56 |
|
|
-- This makes the simulator stop (unless there are other infinite
|
57 |
|
|
-- processes running in the simulation).
|
58 |
|
|
----------------------------------------------------------------------
|
59 |
|
|
library ieee;
|
60 |
|
|
use ieee.std_logic_1164.all;
|
61 |
|
|
|
62 |
|
|
entity pltbutils_clkgen is
|
63 |
|
|
generic (
|
64 |
7 |
pela |
G_PERIOD : time := 10 ns;
|
65 |
|
|
G_INITVALUE : std_logic := '0'
|
66 |
2 |
pela |
);
|
67 |
|
|
port (
|
68 |
|
|
clk_o : out std_logic;
|
69 |
7 |
pela |
clk_n_o : out std_logic;
|
70 |
2 |
pela |
stop_sim_i : in std_logic
|
71 |
|
|
);
|
72 |
|
|
end entity pltbutils_clkgen;
|
73 |
|
|
|
74 |
|
|
architecture bhv of pltbutils_clkgen is
|
75 |
|
|
constant C_HALF_PERIOD : time := G_PERIOD / 2;
|
76 |
7 |
pela |
signal clk : std_logic := G_INITVALUE;
|
77 |
2 |
pela |
begin
|
78 |
|
|
|
79 |
7 |
pela |
clk <= not clk and not stop_sim_i after C_HALF_PERIOD;
|
80 |
|
|
clk_o <= clk;
|
81 |
|
|
clk_n_o <= not clk;
|
82 |
2 |
pela |
|
83 |
|
|
end architecture bhv;
|
84 |
|
|
|
85 |
|
|
|
86 |
107 |
pela |
----------------------------------------------------------------------
|
87 |
|
|
-- pltbutils_time_measure
|
88 |
|
|
-- Measures high-time, low-time and period of a signal, usually a
|
89 |
|
|
-- clock.
|
90 |
|
|
-- Setting G_VERBOSITY to at least 20 reports measures times.
|
91 |
|
|
-- Set G_RPT_LABEL to a prefix used in reports, typically the name
|
92 |
|
|
-- of the signal being measured.
|
93 |
|
|
----------------------------------------------------------------------
|
94 |
|
|
library ieee;
|
95 |
|
|
use ieee.std_logic_1164.all;
|
96 |
|
|
|
97 |
|
|
entity pltbutils_time_measure is
|
98 |
|
|
generic (
|
99 |
|
|
G_VERBOSITY : integer := 0;
|
100 |
|
|
G_RPT_LABEL : string := "pltbutils_time_measure"
|
101 |
|
|
);
|
102 |
|
|
port (
|
103 |
|
|
t_hi_o : out time; -- High time
|
104 |
|
|
t_lo_o : out time; -- Low time
|
105 |
|
|
t_per_o : out time; -- Period time
|
106 |
|
|
s_i : in std_logic -- Signal to measure
|
107 |
|
|
);
|
108 |
|
|
end entity pltbutils_time_measure;
|
109 |
|
|
|
110 |
|
|
architecture bhv of pltbutils_time_measure is
|
111 |
|
|
signal t_hi : time := 0 ns;
|
112 |
|
|
signal t_lo : time := 0 ns;
|
113 |
|
|
signal t_per : time := 0 ns;
|
114 |
|
|
begin
|
115 |
|
|
|
116 |
|
|
measure_p : process (s_i)
|
117 |
|
|
variable last_rising_edge : time := -1 ns;
|
118 |
|
|
variable last_falling_edge : time := -1 ns;
|
119 |
|
|
begin
|
120 |
|
|
if rising_edge(s_i) then
|
121 |
|
|
if last_falling_edge >= 0 ns then
|
122 |
|
|
t_lo <= now - last_falling_edge;
|
123 |
|
|
end if;
|
124 |
|
|
if last_rising_edge >= 0 ns then
|
125 |
|
|
t_per <= now - last_rising_edge;
|
126 |
|
|
end if;
|
127 |
|
|
last_rising_edge := now;
|
128 |
|
|
end if;
|
129 |
|
|
|
130 |
|
|
if falling_edge(s_i) then
|
131 |
|
|
if last_rising_edge >= 0 ns then
|
132 |
|
|
t_hi <= now - last_rising_edge;
|
133 |
|
|
end if;
|
134 |
|
|
last_falling_edge := now;
|
135 |
|
|
end if;
|
136 |
|
|
end process measure_p;
|
137 |
|
|
|
138 |
|
|
assert not (G_VERBOSITY > 20 and t_lo'event)
|
139 |
|
|
report G_RPT_LABEL & ": t_lo=" & time'image(t_lo)
|
140 |
|
|
severity note;
|
141 |
|
|
|
142 |
|
|
assert not (G_VERBOSITY > 20 and t_hi'event)
|
143 |
|
|
report G_RPT_LABEL & ": t_hi=" & time'image(t_hi)
|
144 |
|
|
severity note;
|
145 |
|
|
|
146 |
|
|
assert not (G_VERBOSITY > 20 and t_per'event)
|
147 |
|
|
report G_RPT_LABEL & ": t_hi=" & time'image(t_per)
|
148 |
|
|
severity note;
|
149 |
|
|
|
150 |
|
|
t_hi_o <= t_hi;
|
151 |
|
|
t_lo_o <= t_lo;
|
152 |
|
|
t_per_o <= t_per;
|
153 |
|
|
|
154 |
|
|
end architecture bhv;
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
----------------------------------------------------------------------
|
158 |
|
|
-- pltbutils_diff_check
|
159 |
|
|
-- Checks that the negative half of a diff pair is the
|
160 |
|
|
-- always the complement of the positive half.
|
161 |
|
|
-- Setting G_VERBOSITY to at least 100 reports number of diff errors.
|
162 |
|
|
-- Set G_RPT_LABEL to a prefix used in reports, typically the name
|
163 |
|
|
-- of the signal being measured.
|
164 |
|
|
----------------------------------------------------------------------
|
165 |
|
|
library ieee;
|
166 |
|
|
use ieee.std_logic_1164.all;
|
167 |
|
|
|
168 |
|
|
entity pltbutils_diff_check is
|
169 |
|
|
generic (
|
170 |
|
|
G_VERBOSITY : integer := 0;
|
171 |
|
|
G_RPT_LABEL : string := "pltbutils_diff_check"
|
172 |
|
|
);
|
173 |
|
|
port (
|
174 |
|
|
diff_error_o : out std_logic; -- High when diff error detected
|
175 |
|
|
diff_errors_o : out integer; -- Number of diff errors detected
|
176 |
|
|
s_i : in std_logic; -- Pos half of diff pair to check
|
177 |
|
|
s_n_i : in std_logic := '0'; -- Neg half of diff pair to check
|
178 |
|
|
rst_errors_i : in std_logic := '0' -- High resets diff error counter
|
179 |
|
|
);
|
180 |
|
|
end entity pltbutils_diff_check;
|
181 |
|
|
|
182 |
|
|
architecture bhv of pltbutils_diff_check is
|
183 |
|
|
constant C_INTEGER_MAX : integer := (2**30) + ((2**30)-1); -- Equals (2**31)-1 without overflowing;
|
184 |
|
|
signal diff_error : std_logic := '0';
|
185 |
|
|
signal diff_errors : integer := 0;
|
186 |
|
|
begin
|
187 |
|
|
|
188 |
|
|
diff_check_p : process (s_i, s_n_i, rst_errors_i)
|
189 |
|
|
-- TODO: allow a small (configurable) timing tolerance between edges of s_i and s_n_i
|
190 |
|
|
begin
|
191 |
|
|
if s_i /= not s_n_i then
|
192 |
|
|
diff_error <= '1';
|
193 |
|
|
if diff_errors < C_INTEGER_MAX then
|
194 |
|
|
diff_errors <= diff_errors + 1;
|
195 |
|
|
end if;
|
196 |
|
|
else
|
197 |
|
|
diff_error <= '0';
|
198 |
|
|
end if;
|
199 |
|
|
if rst_errors_i = '1' then
|
200 |
|
|
diff_errors <= 0;
|
201 |
|
|
end if;
|
202 |
|
|
end process diff_check_p;
|
203 |
|
|
|
204 |
|
|
assert not (G_VERBOSITY > 100 and diff_errors'event)
|
205 |
|
|
report G_RPT_LABEL & ": diff_errors=" & integer'image(diff_errors)
|
206 |
|
|
severity note;
|
207 |
|
|
|
208 |
|
|
diff_error_o <= diff_error;
|
209 |
|
|
diff_errors_o <= diff_errors;
|
210 |
|
|
|
211 |
|
|
end architecture bhv;
|
212 |
|
|
|
213 |
|
|
|