OpenCores
URL https://opencores.org/ocsvn/fixed-point-sqrt/fixed-point-sqrt/trunk

Subversion Repositories fixed-point-sqrt

[/] [fixed-point-sqrt/] [trunk/] [tb/] [tb.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 djah
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.numeric_std.all;
4
use ieee.std_logic_textio.all;
5
use work.all;
6
 
7
library std;
8
use std.textio.all;
9
 
10
entity tb is
11
        generic (
12
                INFILE:         string := "sim/vectors.txt";
13
                OUTFILE:        string := "sim/results.txt"
14
        );
15
end entity tb;
16
 
17
architecture post_syn of tb is
18
 
19
        constant clock_period:time:=9 ns;
20
        constant input_hold:time:=20 ps;
21
 
22
        file vectorfile : text open read_mode is INFILE;
23
        file resfile    : text open write_mode is OUTFILE;
24
 
25
 
26
        signal clk      : std_ulogic:='0';
27
        signal res      : std_ulogic:='0';
28
        signal ARG      : unsigned(31 downto 0) := (others=>'0');
29
        signal Z        : unsigned(31 downto 0);
30
 
31
        component square_root is
32
                generic(
33
                        WIDTH   : positive := 32
34
                );
35
                port(
36
                        clk     : in std_logic;
37
                        res     : in std_logic;
38
                        ARG     : in unsigned (WIDTH-1 downto 0); -- must be between 0.5 and 1
39
                        Z       : out unsigned (WIDTH-1 downto 0)
40
                );
41
        end component;
42
 
43
begin
44
        -- clock
45
        clk<= not clk after clock_period/2;
46
 
47
        -- reset
48
        reset_proc: process is begin
49
                res <= '0';
50
                wait for 10 * clock_period;
51
                res <= '1' after input_hold;
52
                wait;
53
        end process reset_proc;
54
 
55
 
56
        -- DUT component instantiation (post synthesis)
57
        dut: square_root
58
                generic map(
59
                        WIDTH=>32
60
                )
61
                port map(
62
                        clk=>clk,
63
                        res=>res,
64
                        ARG=>ARG,
65
                        Z=>Z
66
                );
67
 
68
        -- stimuli generation
69
        stimuli: process
70
                variable debugline      : line;
71
                variable vectorline     : line;
72
                variable vectorvalid    : boolean;
73
                variable ARG_read       : bit_vector(31 downto 0);
74
                variable space          : character;
75
        begin
76
                ARG <= (others => '0');
77
 
78
                --after reset phase
79
                wait until res = '1';
80
                report "Reset deasserted" severity note;
81
 
82
                --wait other 10 clock cycles (just to be sure)
83
                for i in 0 to 10 loop
84
                        wait until clk = '1';
85
                end loop;
86
 
87
                --cycle through vector file
88
                while not endfile (vectorfile) loop
89
 
90
                        readline(vectorfile, vectorline);
91
 
92
                        read(vectorline, ARG_read, good => vectorvalid);
93
                        --debug: copy to stdout
94
                        --write(debugline, a_read);
95
                        --writeline(output, debugline);
96
 
97
                        --skip if comment
98
                        next when not vectorvalid;
99
 
100
                        -- put inputs after a delay to avoid hold violations on input FFs
101
                        wait until clk = '1';
102
                        ARG <= unsigned(to_stdlogicvector(ARG_read)) after input_hold;
103
 
104
                end loop;
105
 
106
                --let last clock cycle terminate
107
                wait until clk = '1';
108
 
109
                --let other 5 clock cycles terminate (to write last output file lines)
110
                for i in 0 to 5 loop
111
                        wait until clk = '1';
112
                end loop;
113
 
114
                --force simulation termination
115
                assert false report "Simulation completed (not a real failure)" severity failure;
116
 
117
                --never reached
118
                wait;
119
 
120
        end process stimuli;
121
 
122
        -- output evaluation
123
        eval: process
124
 
125
                variable outline        : line;
126
                variable Z_res          : bit_vector(31 downto 0);
127
                variable space          : character := ' ';
128
 
129
        begin
130
 
131
                --wait until reset deasserted
132
                wait until res = '1';
133
 
134
                --wait other 15 clock cycles (10 before input starts plus pipeline length)
135
                for i in 0 to 15 loop
136
                        wait until clk = '1';
137
                end loop;
138
 
139
                while true loop
140
 
141
                        -- clock cycle
142
                        wait until clk = '1';
143
 
144
                        Z_res := to_bitvector(std_logic_vector(Z));
145
 
146
                        -- write log to output file
147
                        write(outline, Z_res);
148
                        writeline(resfile, outline);
149
 
150
                end loop;
151
 
152
        end process eval;
153
 
154
end architecture post_syn;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.