OpenCores
URL https://opencores.org/ocsvn/kvcordic/kvcordic/trunk

Subversion Repositories kvcordic

[/] [kvcordic/] [trunk/] [bench/] [vhdl/] [cordic_tb.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 kavi
-- File automatically generated by "cdfg2hdl".
2
-- Filename: cordic_tb.vhd
3
-- Date: 08 November 2010 11:05:42 AM
4
-- Author: Nikolaos Kavvadias (C) 2009, 2010
5
 
6
library IEEE, STD;
7
use STD.textio.all;
8
use WORK.std_logic_textio.all;
9
use IEEE.numeric_std.all;
10
use WORK.cordic_cdt_pkg.all;
11
use IEEE.std_logic_1164.all;
12
 
13
entity cordic_tb is
14
end cordic_tb;
15
 
16
architecture tb_arch of cordic_tb is
17
  component cordic
18
    port (
19
      clk : in std_logic;
20
      reset : in std_logic;
21
      start : in std_logic;
22
      direction : in std_logic_vector(15 downto 0);
23
      mode : in std_logic_vector(15 downto 0);
24
      xin : in std_logic_vector(15 downto 0);
25
      yin : in std_logic_vector(15 downto 0);
26
      zin : in std_logic_vector(15 downto 0);
27
      xout : out std_logic_vector(15 downto 0);
28
      yout : out std_logic_vector(15 downto 0);
29
      zout : out std_logic_vector(15 downto 0);
30
      done : out std_logic;
31
      ready : out std_logic
32
    );
33
  end component;
34
  signal clk : std_logic;
35
  signal reset : std_logic;
36
  signal start : std_logic;
37
  signal direction : std_logic_vector(15 downto 0);
38
  signal mode : std_logic_vector(15 downto 0);
39
  signal xin : std_logic_vector(15 downto 0);
40
  signal yin : std_logic_vector(15 downto 0);
41
  signal zin : std_logic_vector(15 downto 0);
42
  signal xout : std_logic_vector(15 downto 0);
43
  signal yout : std_logic_vector(15 downto 0);
44
  signal zout : std_logic_vector(15 downto 0);
45
  signal done : std_logic;
46
  signal ready : std_logic;
47
  -- Profiling signals
48
  signal ncycles : integer;
49
  -- Constant declarations
50
  constant CLK_PERIOD : time := 10 ns;
51
  -- Declare test data file and results file
52
  file TestDataFile: text open read_mode is "cordic_test_data.txt";
53
  file ResultsFile: text open write_mode is "cordic_alg_test_results.txt";
54
begin
55
  uut : cordic
56
    port map (
57
      clk => clk,
58
      reset => reset,
59
      start => start,
60
      direction => direction,
61
      mode => mode,
62
      xin => xin,
63
      yin => yin,
64
      zin => zin,
65
      xout => xout,
66
      yout => yout,
67
      zout => zout,
68
      ready => ready,
69
      done => done
70
    );
71
 
72
  CLK_GEN_PROC: process(clk)
73
  begin
74
    if (clk = 'U') then
75
      clk <= '1';
76
    else
77
      clk <= not clk after CLK_PERIOD/2;
78
    end if;
79
  end process CLK_GEN_PROC;
80
 
81
  RESET_START_STIM: process
82
  begin
83
    reset <= '1';
84
    start <= '0';
85
    wait for CLK_PERIOD;
86
    reset <= '0';
87
    start <= '1';
88
    wait for 536870911*CLK_PERIOD;
89
  end process RESET_START_STIM;
90
 
91
  PROFILING: process(clk, reset, done)
92
  begin
93
    if (reset = '1' or done = '1') then
94
      ncycles <= 0;
95
    elsif (clk = '1' and clk'EVENT) then
96
      ncycles <= ncycles + 1;
97
    end if;
98
  end process PROFILING;
99
 
100
  CORDIC_BENCH: process
101
    variable direction_v : signed(15 downto 0);
102
    variable direction_v_vec : std_logic_vector(15 downto 0);
103
    variable mode_v : signed(15 downto 0);
104
    variable mode_v_vec : std_logic_vector(15 downto 0);
105
    variable xin_v : signed(15 downto 0);
106
    variable xin_v_vec : std_logic_vector(15 downto 0);
107
    variable yin_v : signed(15 downto 0);
108
    variable yin_v_vec : std_logic_vector(15 downto 0);
109
    variable zin_v : signed(15 downto 0);
110
    variable zin_v_vec : std_logic_vector(15 downto 0);
111
    variable xout_v, xout_ref : signed(15 downto 0);
112
    variable xout_v_vec, xout_ref_vec : std_logic_vector(15 downto 0);
113
    variable yout_v, yout_ref : signed(15 downto 0);
114
    variable yout_v_vec, yout_ref_vec : std_logic_vector(15 downto 0);
115
    variable zout_v, zout_ref : signed(15 downto 0);
116
    variable zout_v_vec, zout_ref_vec : std_logic_vector(15 downto 0);
117
    variable ncycles_v: integer;
118
    variable TestData, BufLine: line;
119
    variable Passed: std_logic := '1';
120
  begin
121
    while not endfile(TestDataFile) loop
122
      -- Read test data from file
123
      readline(TestDataFile, TestData);
124
      hread(TestData, direction_v_vec);
125
      direction <= direction_v_vec;
126
      hread(TestData, mode_v_vec);
127
      mode <= mode_v_vec;
128
      hread(TestData, xin_v_vec);
129
      xin <= xin_v_vec;
130
      hread(TestData, yin_v_vec);
131
      yin <= yin_v_vec;
132
      hread(TestData, zin_v_vec);
133
      zin <= zin_v_vec;
134
      hread(TestData, xout_ref_vec);
135
      xout_ref := SIGNED(xout_ref_vec);
136
      hread(TestData, yout_ref_vec);
137
      yout_ref := SIGNED(yout_ref_vec);
138
      hread(TestData, zout_ref_vec);
139
      zout_ref := SIGNED(zout_ref_vec);
140
      wait until done = '1';
141
      xout_v := signed(xout);
142
      yout_v := signed(yout);
143
      zout_v := signed(zout);
144
      -- Test CORDIC algorithm
145
      if (
146
          (xout_v /= xout_ref) or
147
          (yout_v /= yout_ref) or
148
          (zout_v /= zout_ref)
149
      ) then
150
        Passed := '0';
151
        write(Bufline, string'("CORDIC error: direction="));
152
        hwrite(Bufline, STD_LOGIC_VECTOR(direction));
153
        write(Bufline, string'("CORDIC error: mode="));
154
        hwrite(Bufline, STD_LOGIC_VECTOR(mode));
155
        write(Bufline, string'("CORDIC error: xin="));
156
        hwrite(Bufline, STD_LOGIC_VECTOR(xin));
157
        write(Bufline, string'("CORDIC error: yin="));
158
        hwrite(Bufline, STD_LOGIC_VECTOR(yin));
159
        write(Bufline, string'("CORDIC error: zin="));
160
        hwrite(Bufline, STD_LOGIC_VECTOR(zin));
161
        write(Bufline, string'(" xout="));
162
        hwrite(Bufline, STD_LOGIC_VECTOR(xout_v));
163
        write(Bufline, string'(" xout_ref="));
164
        hwrite(Bufline, STD_LOGIC_VECTOR(xout_ref));
165
        write(Bufline, string'(" yout="));
166
        hwrite(Bufline, STD_LOGIC_VECTOR(yout_v));
167
        write(Bufline, string'(" yout_ref="));
168
        hwrite(Bufline, STD_LOGIC_VECTOR(yout_ref));
169
        write(Bufline, string'(" zout="));
170
        hwrite(Bufline, STD_LOGIC_VECTOR(zout_v));
171
        write(Bufline, string'(" zout_ref="));
172
        hwrite(Bufline, STD_LOGIC_VECTOR(zout_ref));
173
        writeline(ResultsFile, Bufline);
174
      else
175
        write(Bufline, string'(" direction="));
176
        hwrite(Bufline, STD_LOGIC_VECTOR(direction));
177
        write(Bufline, string'(" mode="));
178
        hwrite(Bufline, STD_LOGIC_VECTOR(mode));
179
        write(Bufline, string'(" xin="));
180
        hwrite(Bufline, STD_LOGIC_VECTOR(xin));
181
        write(Bufline, string'(" yin="));
182
        hwrite(Bufline, STD_LOGIC_VECTOR(yin));
183
        write(Bufline, string'(" zin="));
184
        hwrite(Bufline, STD_LOGIC_VECTOR(zin));
185
        write(Bufline, string'(" xout="));
186
        hwrite(Bufline, STD_LOGIC_VECTOR(xout));
187
        write(Bufline, string'(" xout_ref="));
188
        hwrite(Bufline, STD_LOGIC_VECTOR(xout_ref));
189
        write(Bufline, string'(" yout="));
190
        hwrite(Bufline, STD_LOGIC_VECTOR(yout));
191
        write(Bufline, string'(" yout_ref="));
192
        hwrite(Bufline, STD_LOGIC_VECTOR(yout_ref));
193
        write(Bufline, string'(" zout="));
194
        hwrite(Bufline, STD_LOGIC_VECTOR(zout));
195
        write(Bufline, string'(" zout_ref="));
196
        hwrite(Bufline, STD_LOGIC_VECTOR(zout_ref));
197
        writeline(ResultsFile, Bufline);
198
        ncycles_v := ncycles;
199
        write(Bufline, string'("CORDIC OK: Number of cycles="));
200
        write(Bufline, ncycles_v);
201
        writeline(ResultsFile, Bufline);
202
      end if;
203
    end loop;
204
    if (Passed = '1') then
205
      write(Bufline, string'("CORDIC algorithm test has passed"));
206
      writeline(ResultsFile, Bufline);
207
      -- Automatic end of the current simulation.
208
      assert false
209
        report "End simulation time reached"
210
        severity failure;
211
    end if;
212
    wait for CLK_PERIOD;
213
  end process CORDIC_BENCH;
214
 
215
end tb_arch;

powered by: WebSVN 2.1.0

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