aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/gna/issue664/tb_pkg.vhdl
blob: f7e59b998b88bc5ba08a501b356e8b44df489499 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
------------------------------------------------------------------
----                                                          ----
----  Content: testbench package                              ----
----                                                          ----
----  Author:  E. Theodore L. Omtzigt                         ----
----           theo@stillwater-sc.com                         ----
----                                                          ----
------------------------------------------------------------------
----                                                          ----
---- Copyright (C) 2017-2018                                  ----
----               E. Theodore L. Omtzigt                     ----
----               theo@stillwater-sc.com                     ----
----                                                          ----
------------------------------------------------------------------

---- A posit is a tapered floating point representation. To compute
---- with posits, the regime and exponent fields need to be consolidated.
---- This process generates a triple (sign, exponent, significant).
---- These triples are the input values to the arithmetic units.

library ieee;
use ieee.std_logic_1164.all;
use std.textio.all;

package tb_pkg is

	-- Procedure for clock generation
	procedure clk_gen(signal clk : out std_logic; constant FREQ : real);
	-- How to use
	--architecture sim of tb is
	--		  -- Clock frequency and signal
	--  signal clk_166 : std_logic;
	--  signal clk_125 : std_logic;
	--
	--begin
	--
	--  -- Clock generation with concurrent procedure call
	--  clk_gen(clk_166, 166.667E6);          -- 166.667 MHz clock
	--  clk_gen(clk_125, 125.000E6);          -- 125.000 MHz clock
	--
	--  -- Time resolution show
	--  assert FALSE report "Time resolution: " & time'image(time'succ(0 fs)) severity NOTE;
	--
	--end architecture;

	--- trackError
	function trackError(
		condition : boolean;
		message   : String;
		nrErrors  : integer
	) return integer;

end package;

package body tb_pkg is

	-- Procedure for clock generation
	procedure clk_gen(signal clk : out std_logic; constant FREQ : real) is
		constant PERIOD    : time := 1 sec / FREQ; -- Full period
		constant HIGH_TIME : time := PERIOD / 2; -- High time
		constant LOW_TIME  : time := PERIOD - HIGH_TIME; -- Low time; always >= HIGH_TIME
	begin
		-- Check the arguments
		assert (HIGH_TIME /= 0 fs) report "clk_plain: High time is zero; time resolution to large for frequency" severity FAILURE;
		-- Generate a clock cycle
		loop
			clk <= '1';
			wait for HIGH_TIME;
			clk <= '0';
			wait for LOW_TIME;
		end loop;
	end procedure;

	-- trackError
	function trackError(
		condition : boolean;
		message   : String;
		nrErrors  : integer) return integer is
		variable runningCount : integer;
	begin
		assert (condition) report message;
		if condition = FALSE then
			runningCount := nrErrors + 1;
		else
			runningCount := nrErrors;
		end if;
		return runningCount;
	end function;

end package body;