PlTbUtils  1.3
PlTbUtils is a collection of functions, procedures and components for easily creating stimuli and checking response in automatic self-checking testbenches.
pltbutils_comp.vhd
Go to the documentation of this file.
1 
33 
34 library ieee;
35  use ieee.std_logic_1164.all;
36 
63  generic (
64  G_PERIOD : time := 10 ns;
65  G_INITVALUE : std_logic := '0'
66  );
67  port (
68  clk_o : out std_logic;
69  clk_n_o : out std_logic;
70  stop_sim_i : in std_logic
71  );
72 end entity pltbutils_clkgen;
73 
74 architecture bhv of pltbutils_clkgen is
75 
76  constant C_HALF_PERIOD : time := G_PERIOD / 2;
77  signal clk : std_logic := G_INITVALUE;
78 
79 begin
80 
81  clk <= not clk and not stop_sim_i after C_HALF_PERIOD;
82  clk_o <= clk;
83  clk_n_o <= not clk;
84 
85 end architecture bhv;
86 
87 
88 library ieee;
89  use ieee.std_logic_1164.all;
90 
116  generic (
117  G_VERBOSITY : integer := 0;
118  G_RPT_LABEL : string := "pltbutils_time_measure"
119  );
120  port (
121  t_hi_o : out time;
122  t_lo_o : out time;
123  t_per_o : out time;
124  s_i : in std_logic
125  );
126 end entity pltbutils_time_measure;
127 
128 architecture bhv of pltbutils_time_measure is
129  signal t_hi : time := 0 ns;
130  signal t_lo : time := 0 ns;
131  signal t_per : time := 0 ns;
132 begin
133 
134  measure_p : process (s_i)
135  variable last_rising_edge : time := -1 ns;
136  variable last_falling_edge : time := -1 ns;
137  begin
138  if rising_edge(s_i) then
139  if last_falling_edge >= 0 ns then
140  t_lo <= now - last_falling_edge;
141  end if;
142  if last_rising_edge >= 0 ns then
143  t_per <= now - last_rising_edge;
144  end if;
145  last_rising_edge := now;
146  end if;
147 
148  if falling_edge(s_i) then
149  if last_rising_edge >= 0 ns then
150  t_hi <= now - last_rising_edge;
151  end if;
152  last_falling_edge := now;
153  end if;
154  end process measure_p;
155 
156  assert not (G_VERBOSITY > 20 and t_lo'event)
157  report G_RPT_LABEL & ": t_lo=" & time'image(t_lo)
158  severity note;
159 
160  assert not (G_VERBOSITY > 20 and t_hi'event)
161  report G_RPT_LABEL & ": t_hi=" & time'image(t_hi)
162  severity note;
163 
164  assert not (G_VERBOSITY > 20 and t_per'event)
165  report G_RPT_LABEL & ": t_hi=" & time'image(t_per)
166  severity note;
167 
168  t_hi_o <= t_hi;
169  t_lo_o <= t_lo;
170  t_per_o <= t_per;
171 
172 end architecture bhv;
173 
174 library ieee;
175  use ieee.std_logic_1164.all;
176 
203  generic (
204  G_VERBOSITY : integer := 0;
205  G_RPT_LABEL : string := "pltbutils_diff_check"
206  );
207  port (
208  diff_error_o : out std_logic;
209  diff_errors_o : out integer;
210  s_i : in std_logic;
211  s_n_i : in std_logic := '0';
212  rst_errors_i : in std_logic := '0'
213  );
214 end entity pltbutils_diff_check;
215 
216 architecture bhv of pltbutils_diff_check is
217  constant C_INTEGER_MAX : integer := (2**30) + ((2**30)-1); -- Equals (2**31)-1 without overflowing;
218  signal diff_error : std_logic := '0';
219  signal diff_errors : integer := 0;
220 begin
221 
222  diff_check_p : process (s_i, s_n_i, rst_errors_i)
223  -- TODO: allow a small (configurable) timing tolerance between edges of s_i and s_n_i
224  begin
225  if s_i /= not s_n_i then
226  diff_error <= '1';
227  if diff_errors < C_INTEGER_MAX then
228  diff_errors <= diff_errors + 1;
229  end if;
230  else
231  diff_error <= '0';
232  end if;
233  if rst_errors_i = '1' then
234  diff_errors <= 0;
235  end if;
236  end process diff_check_p;
237 
238  assert not (G_VERBOSITY > 100 and diff_errors'event)
239  report G_RPT_LABEL & ": diff_errors=" & integer'image(diff_errors)
240  severity note;
241 
244 
245 end architecture bhv;
std_logic := G_INITVALUE clk
time := G_PERIOD/ 2 C_HALF_PERIOD
Creates a clock for use in a testbench.
out clk_n_o std_logic
Inverted clock for differential clocks.
out clk_o std_logic
Clock output.
in stop_sim_i std_logic
Stops the clock when '1'.
G_PERIOD time := 10 ns
Clock period.
G_INITVALUE std_logic := '0'
Initial value of the clock.
std_logic := '0' diff_error
integer :=( 2** 30)+(( 2** 30)- 1) C_INTEGER_MAX
Checks that the negative half of a diff pair is the always the complement of the positive half.
in s_n_i std_logic := '0'
Neg half of diff pair to check.
out diff_errors_o integer
Number of diff errors detected.
G_RPT_LABEL string := "pltbutils_diff_check"
in s_i std_logic
Pos half of diff pair to check.
out diff_error_o std_logic
High when diff error detected.
G_VERBOSITY integer := 0
in rst_errors_i std_logic := '0'
High resets diff error counter.
Measures high-time, low-time and period of a signal, usually a clock.
out t_hi_o time
High time.
G_RPT_LABEL string := "pltbutils_time_measure"
in s_i std_logic
Signal to measure.
out t_per_o time
Period time.
out t_lo_o time
Low time.