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

Subversion Repositories yac

[/] [yac/] [trunk/] [rtl/] [vhdl/] [cordic_iterative_tb.vhd] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 feddischso
----------------------------------------------------------------------------
2
----                                                                    ----
3
----  File           : cordic_iterative_tb.vhd                          ----
4
----  Project        : YAC (Yet Another CORDIC Core)                    ----
5
----  Creation       : Feb. 2014                                        ----
6
----  Limitations    :                                                  ----
7
----  Synthesizer    :                                                  ----
8
----  Target         :                                                  ----
9
----                                                                    ----
10
----  Author(s):     : Christian Haettich                               ----
11
----  Email          : feddischson@opencores.org                        ----
12
----                                                                    ----
13
----                                                                    ----
14
-----                                                                  -----
15
----                                                                    ----
16
----  Description                                                       ----
17
----        VHDL Testbench                                              ----
18
----                                                                    ----
19
----                                                                    ----
20
----                                                                    ----
21
-----                                                                  -----
22
----                                                                    ----
23
----  TODO                                                              ----
24
----        Some documentation                                          ----
25
----                                                                    ----
26
----                                                                    ----
27
----                                                                    ----
28
----                                                                    ----
29
----------------------------------------------------------------------------
30
----                                                                    ----
31
----                  Copyright Notice                                  ----
32
----                                                                    ----
33
---- This file is part of YAC - Yet Another CORDIC Core                 ----
34
---- Copyright (c) 2014, Author(s), All rights reserved.                ----
35
----                                                                    ----
36
---- YAC is free software; you can redistribute it and/or               ----
37
---- modify it under the terms of the GNU Lesser General Public         ----
38
---- License as published by the Free Software Foundation; either       ----
39
---- version 3.0 of the License, or (at your option) any later version. ----
40
----                                                                    ----
41
---- YAC is distributed in the hope that it will be useful,             ----
42
---- but WITHOUT ANY WARRANTY; without even the implied warranty of     ----
43
---- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  ----
44
---- Lesser General Public License for more details.                    ----
45
----                                                                    ----
46
---- You should have received a copy of the GNU Lesser General Public   ----
47
---- License along with this library. If not, download it from          ----
48
---- http://www.gnu.org/licenses/lgpl                                   ----
49
----                                                                    ----
50
----------------------------------------------------------------------------
51
 
52
 
53
 
54
LIBRARY ieee;
55
USE ieee.std_logic_1164.ALL;
56
use ieee.numeric_std.ALL;
57
 
58
library std;
59
use std.textio.all;     -- for reading/writing from/to files
60
use std.env.all;        -- for finish()
61
 
62
library work;
63
 
64
 
65
entity cordic_iterative_tb is
66
 
67
end entity cordic_iterative_tb;
68
 
69
 
70
architecture IMP of cordic_iterative_tb is
71
 
72
 
73
   constant FRQ_MULT_VALUE          : integer :=18;
74
 
75
   constant stim_file : string := "../../c_octave/tb_data.txt";
76
   constant err_file  : string := "./error_out.txt";
77
 
78
   constant clk_T       : time := 5 ns;
79
   signal clk           : std_logic;
80
   signal rst           : std_logic;
81
   signal nrst          : std_logic;
82
 
83
   constant XY_WIDTH    : natural := 25;
84
   constant A_WIDTH     : natural := 25;
85
   constant GUARD_BITS  : natural :=  2;
86
   constant RM_GAIN     : natural :=  5;
87
   component cordic_iterative_int is
88
   generic(
89
      XY_WIDTH    : natural := 12;
90
      A_WIDTH     : natural := 12;
91
      GUARD_BITS  : natural :=  2;
92
      RM_GAIN     : natural :=  4
93
          );
94
   port(
95
      clk, rst  : in  std_logic;
96
      en        : in  std_logic;
97
      start     : in  std_logic;
98
      done      : out std_logic;
99
      mode_i    : in  std_logic_vector( 4-1 downto 0 );
100
      x_i       : in  std_logic_vector( XY_WIDTH-1  downto 0 );
101
      y_i       : in  std_logic_vector( XY_WIDTH-1  downto 0 );
102
      a_i       : in  std_logic_vector( A_WIDTH+2-1 downto 0 );
103
      x_o       : out std_logic_vector( XY_WIDTH+GUARD_BITS-1  downto 0 );
104
      y_o       : out std_logic_vector( XY_WIDTH+GUARD_BITS-1  downto 0 );
105
      a_o       : out std_logic_vector( A_WIDTH+2-1 downto 0 )
106
       );
107
   end component cordic_iterative_int;
108
   signal en        : std_logic;
109
   signal start     : std_logic;
110
   signal done      : std_logic;
111
   signal mode_i    : std_logic_vector( 4-1 downto 0 );
112
   signal x_i       : std_logic_vector( XY_WIDTH-1  downto 0 );
113
   signal y_i       : std_logic_vector( XY_WIDTH-1  downto 0 );
114
   signal a_i       : std_logic_vector( A_WIDTH+2-1 downto 0 );
115
   signal x_o       : std_logic_vector( XY_WIDTH+GUARD_BITS-1  downto 0 );
116
   signal y_o       : std_logic_vector( XY_WIDTH+GUARD_BITS-1  downto 0 );
117
   signal a_o       : std_logic_vector( A_WIDTH+2-1 downto 0 );
118
 
119
 
120
 
121
begin
122
 
123
 
124
   -- --
125
   -- clock and reset 
126
   --
127
   nrst           <= not rst;
128
   clk_gen : process
129
   begin
130
      clk  <= '1';
131
      wait for clk_T/2;
132
      clk  <= '0';
133
      wait for clk_T/2;
134
   end process;
135
   rst_gen  : process
136
   begin
137
      rst   <= '1';
138
      wait for clk_T * 10;
139
      rst   <= '0';
140
      wait;
141
   end process;
142
 
143
 
144
 
145
 
146
   dut : cordic_iterative_int
147
   generic map (
148
      XY_WIDTH       => XY_WIDTH  ,
149
      A_WIDTH        => A_WIDTH   ,
150
      GUARD_BITS     => GUARD_BITS,
151
      RM_GAIN        => RM_GAIN
152
          )
153
   port map(
154
      clk         => clk         ,
155
      rst         => rst         ,
156
      en          => en          ,
157
      start       => start       ,
158
      done        => done        ,
159
      mode_i      => mode_i      ,
160
      x_i         => x_i         ,
161
      y_i         => y_i         ,
162
      a_i         => a_i         ,
163
      x_o         => x_o         ,
164
      y_o         => y_o         ,
165
      a_o         => a_o
166
       );
167
 
168
 
169
 
170
  --
171
  -- 
172
  --
173
  stims_p : process
174
 
175
      file     test_pattern_file    : text;
176
      file     error_pattern_file   : text;
177
      variable file_status          : file_open_status;
178
      variable input_line           : line;
179
      variable input_line_bak       : line;
180
      variable good                 : boolean;
181
 
182
      type values_t is array ( 0 to 7 ) of integer;
183
      variable tmp_value : values_t;
184
 
185
      variable x_ex                 : std_logic_vector( x_o'range );
186
      variable y_ex                 : std_logic_vector( y_o'range );
187
      variable a_ex                 : std_logic_vector( a_o'range );
188
      variable err_cnt              : integer := 0;
189
      variable stim_cnt             : integer := 0;
190
  begin
191
 
192
    err_cnt := 0;
193
 
194
    --
195
    -- open file
196
    --
197
    file_open( file_status, test_pattern_file, stim_file, READ_MODE );
198
    if file_status /= open_ok then
199
       report "unable to open input stimulation file, please use cordic_iterative_test.m to create stimulation file" severity error;
200
       stop( -1 );
201
    end if;
202
    file_open( file_status, error_pattern_file,  err_file, WRITE_MODE );
203
    if file_status /= open_ok then
204
       report "unable to open output error file" severity error;
205
       stop( -1 );
206
    end if;
207
 
208
    -- wait some cycles
209
    x_i     <= ( others => '0' );
210
    y_i     <= ( others => '0' );
211
    a_i     <= ( others => '0' );
212
    mode_i  <= ( others => '0' );
213
    start   <= '0';
214
    wait for clk_T * 20;
215
 
216
    wait until clk'event and clk='1';
217
 
218
    while ( not endfile( test_pattern_file ) )loop
219
 
220
 
221
        wait until en='1';
222
        wait for clk_T;
223
 
224
 
225
        -- read line and extract values
226
        readline( test_pattern_file, input_line );
227
        input_line_bak := new string'( input_line.ALL );
228
        for i in 0 to 6 loop
229
           read( input_line, tmp_value(i), good );
230
           --report "rd: "& integer'image( i ) & " : " & integer'image( tmp_value( i ) );
231
        end loop;
232
 
233
        -- assign values to DUT
234
        x_i    <= std_logic_vector( to_signed  ( tmp_value(0), x_i'length    ) );
235
        y_i    <= std_logic_vector( to_signed  ( tmp_value(1), y_i'length    ) );
236
        a_i    <= std_logic_vector( to_signed  ( tmp_value(2), a_i'length    ) );
237
        x_ex   := std_logic_vector( to_signed  ( tmp_value(3), x_ex'length   ) );
238
        y_ex   := std_logic_vector( to_signed  ( tmp_value(4), y_ex'length   ) );
239
        a_ex   := std_logic_vector( to_signed  ( tmp_value(5), a_ex'length   ) );
240
        mode_i <= std_logic_vector( to_unsigned( tmp_value(6), mode_i'length ) );
241
        -- start the DUT and wait, until the DUT is done
242
        start <= '1';
243
        wait for clk_T;
244
        start <= '0';
245
 
246
        wait until done = '1';
247
        wait until clk'event and clk='1';
248
        stim_cnt := stim_cnt+1;
249
 
250
        if x_ex /= x_o or
251
           y_ex /= y_o or
252
           a_ex /= a_o then
253
           assert x_ex = x_o report
254 3 feddischso
<<<<<<< HEAD
255 2 feddischso
                 integer'image( stim_cnt ) & ": Serial Cordic Failed: expected x result:"
256
                 & integer'image( tmp_value(5) ) & ", but got:"
257
                 & integer'image( to_integer( signed( x_ex ) ) );
258
           assert y_ex = y_o report
259
                 integer'image( stim_cnt ) &   ": Serial Cordic Failed: expected y result:"
260
                 & integer'image( tmp_value(6) ) & ", but got:"
261
                 & integer'image( to_integer( signed( y_ex ) ) );
262
           assert a_ex = a_o report
263
                 integer'image( stim_cnt ) &   ": Serial Cordic Failed: expected a result:"
264 3 feddischso
=======
265
                   " Serial Cordic Failed: expected x result:"
266
                 & integer'image( tmp_value(5) ) & ", but got:"
267
                 & integer'image( to_integer( signed( x_ex ) ) );
268
           assert y_ex = y_o report
269
                   " Serial Cordic Failed: expected y result:"
270
                 & integer'image( tmp_value(6) ) & ", but got:"
271
                 & integer'image( to_integer( signed( y_ex ) ) );
272
           assert a_ex = a_o report
273
                   " Serial Cordic Failed: expected a result:"
274
>>>>>>> initial commit
275 2 feddischso
                 & integer'image( tmp_value(7) ) & ", but got:"
276
                 & integer'image( to_integer( signed( a_ex ) ) );
277
            err_cnt := err_cnt + 1;
278
         writeline( error_pattern_file, input_line_bak );
279
 
280
        end if;
281
 
282
        wait for CLK_T * 5;
283
 
284
    end loop;
285
    report "====>>>> Serial Cordic Verification Result:" & integer'image( err_cnt ) & " of " & integer'image( stim_cnt ) & " tests failed";
286
    stop( 0 );
287
  end process stims_p;
288
 
289
 
290
 
291
 
292
   en_test : process
293
   begin
294
      en <= '0';
295
      wait for clk_T * 10;
296
      en <= '1';
297
      wait for clk_T * 1000;
298
 
299
   end process;
300
 
301
 
302
end architecture IMP;
303
 
304
 
305
 
306
 

powered by: WebSVN 2.1.0

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