1
|
|
2
|
-- Copyright (C) 1996 Morgan Kaufmann Publishers, Inc
|
3
|
|
4
|
-- This file is part of VESTs (Vhdl tESTs).
|
5
|
|
6
|
-- VESTs is free software; you can redistribute it and/or modify it
|
7
|
-- under the terms of the GNU General Public License as published by the
|
8
|
-- Free Software Foundation; either version 2 of the License, or (at
|
9
|
-- your option) any later version.
|
10
|
|
11
|
-- VESTs is distributed in the hope that it will be useful, but WITHOUT
|
12
|
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
13
|
-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
14
|
-- for more details.
|
15
|
|
16
|
-- You should have received a copy of the GNU General Public License
|
17
|
-- along with VESTs; if not, write to the Free Software Foundation,
|
18
|
-- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
|
20
|
-- ---------------------------------------------------------------------
|
21
|
--
|
22
|
-- $Id: ch_21_fg_21_03.vhd,v 1.2 2001-10-26 16:29:37 paw Exp $
|
23
|
-- $Revision: 1.2 $
|
24
|
--
|
25
|
-- ---------------------------------------------------------------------
|
26
|
|
27
|
-- code from book (in text)
|
28
|
|
29
|
entity random_source is
|
30
|
generic ( min, max : natural;
|
31
|
seed : natural;
|
32
|
interval : delay_length );
|
33
|
port ( number : out natural );
|
34
|
end entity random_source;
|
35
|
|
36
|
-- end code from book
|
37
|
|
38
|
|
39
|
architecture fudged of random_source is
|
40
|
begin
|
41
|
|
42
|
process is
|
43
|
variable next_number : natural := seed;
|
44
|
begin
|
45
|
if next_number > max then
|
46
|
next_number := min;
|
47
|
end if;
|
48
|
number <= next_number;
|
49
|
next_number := next_number + 1;
|
50
|
wait for interval;
|
51
|
end process;
|
52
|
|
53
|
end architecture fudged;
|
54
|
|
55
|
|
56
|
|
57
|
entity test_bench is
|
58
|
end entity test_bench;
|
59
|
|
60
|
|
61
|
-- code from book
|
62
|
|
63
|
architecture random_test of test_bench is
|
64
|
|
65
|
subtype bv11 is bit_vector(10 downto 0);
|
66
|
|
67
|
function natural_to_bv11 ( n : natural ) return bv11 is
|
68
|
variable result : bv11 := (others => '0');
|
69
|
variable remaining_digits : natural := n;
|
70
|
begin
|
71
|
for index in result'reverse_range loop
|
72
|
result(index) := bit'val(remaining_digits mod 2);
|
73
|
remaining_digits := remaining_digits / 2;
|
74
|
exit when remaining_digits = 0;
|
75
|
end loop;
|
76
|
return result;
|
77
|
end function natural_to_bv11;
|
78
|
|
79
|
signal stimulus_vector : bv11;
|
80
|
-- . . .
|
81
|
|
82
|
begin
|
83
|
|
84
|
stimulus_generator : entity work.random_source
|
85
|
generic map ( min => 0, max => 2**10 - 1, seed => 0,
|
86
|
interval => 100 ns )
|
87
|
port map ( natural_to_bv11(number) => stimulus_vector );
|
88
|
|
89
|
-- . . .
|
90
|
|
91
|
end architecture random_test;
|
92
|
|
93
|
-- end code from book
|