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

Subversion Repositories yac

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

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 7 feddischso
   constant XY_WIDTH    : natural := 8;
84
   constant A_WIDTH     : natural := 8;
85
   constant GUARD_BITS  : natural := 2;
86
   constant RM_GAIN     : natural := 3;
87 2 feddischso
   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
begin
121
 
122
 
123
   -- --
124
   -- clock and reset 
125
   --
126
   nrst           <= not rst;
127
   clk_gen : process
128
   begin
129
      clk  <= '1';
130
      wait for clk_T/2;
131
      clk  <= '0';
132
      wait for clk_T/2;
133
   end process;
134
   rst_gen  : process
135
   begin
136
      rst   <= '1';
137
      wait for clk_T * 10;
138
      rst   <= '0';
139
      wait;
140
   end process;
141
 
142
 
143
 
144 7 feddischso
 
145 2 feddischso
   dut : cordic_iterative_int
146
   generic map (
147
      XY_WIDTH       => XY_WIDTH  ,
148
      A_WIDTH        => A_WIDTH   ,
149
      GUARD_BITS     => GUARD_BITS,
150
      RM_GAIN        => RM_GAIN
151
          )
152
   port map(
153
      clk         => clk         ,
154
      rst         => rst         ,
155
      en          => en          ,
156
      start       => start       ,
157
      done        => done        ,
158
      mode_i      => mode_i      ,
159
      x_i         => x_i         ,
160
      y_i         => y_i         ,
161
      a_i         => a_i         ,
162
      x_o         => x_o         ,
163
      y_o         => y_o         ,
164
      a_o         => a_o
165
       );
166
 
167
 
168
 
169
  --
170
  -- 
171
  --
172
  stims_p : process
173
 
174
      file     test_pattern_file    : text;
175
      file     error_pattern_file   : text;
176
      variable file_status          : file_open_status;
177
      variable input_line           : line;
178
      variable input_line_bak       : line;
179
      variable good                 : boolean;
180
 
181
      type values_t is array ( 0 to 7 ) of integer;
182
      variable tmp_value : values_t;
183
 
184
      variable x_ex                 : std_logic_vector( x_o'range );
185
      variable y_ex                 : std_logic_vector( y_o'range );
186
      variable a_ex                 : std_logic_vector( a_o'range );
187
      variable err_cnt              : integer := 0;
188
      variable stim_cnt             : integer := 0;
189
  begin
190 7 feddischso
 
191 2 feddischso
    err_cnt := 0;
192
 
193
    --
194
    -- open file
195
    --
196
    file_open( file_status, test_pattern_file, stim_file, READ_MODE );
197
    if file_status /= open_ok then
198
       report "unable to open input stimulation file, please use cordic_iterative_test.m to create stimulation file" severity error;
199
       stop( -1 );
200
    end if;
201
    file_open( file_status, error_pattern_file,  err_file, WRITE_MODE );
202
    if file_status /= open_ok then
203
       report "unable to open output error file" severity error;
204
       stop( -1 );
205
    end if;
206
 
207
    -- wait some cycles
208
    x_i     <= ( others => '0' );
209
    y_i     <= ( others => '0' );
210
    a_i     <= ( others => '0' );
211
    mode_i  <= ( others => '0' );
212
    start   <= '0';
213
    wait for clk_T * 20;
214
 
215
    wait until clk'event and clk='1';
216
 
217
    while ( not endfile( test_pattern_file ) )loop
218
 
219
        wait until en='1';
220
        wait for clk_T;
221
 
222
 
223
        -- read line and extract values
224
        readline( test_pattern_file, input_line );
225
        input_line_bak := new string'( input_line.ALL );
226
        for i in 0 to 6 loop
227
           read( input_line, tmp_value(i), good );
228
           --report "rd: "& integer'image( i ) & " : " & integer'image( tmp_value( i ) );
229
        end loop;
230
 
231
        -- assign values to DUT
232
        x_i    <= std_logic_vector( to_signed  ( tmp_value(0), x_i'length    ) );
233
        y_i    <= std_logic_vector( to_signed  ( tmp_value(1), y_i'length    ) );
234
        a_i    <= std_logic_vector( to_signed  ( tmp_value(2), a_i'length    ) );
235
        x_ex   := std_logic_vector( to_signed  ( tmp_value(3), x_ex'length   ) );
236
        y_ex   := std_logic_vector( to_signed  ( tmp_value(4), y_ex'length   ) );
237
        a_ex   := std_logic_vector( to_signed  ( tmp_value(5), a_ex'length   ) );
238
        mode_i <= std_logic_vector( to_unsigned( tmp_value(6), mode_i'length ) );
239
        -- start the DUT and wait, until the DUT is done
240
        start <= '1';
241
        wait for clk_T;
242
        start <= '0';
243
 
244
        wait until done = '1';
245
        wait until clk'event and clk='1';
246
        stim_cnt := stim_cnt+1;
247
 
248
        if x_ex /= x_o or
249
           y_ex /= y_o or
250
           a_ex /= a_o then
251
           assert x_ex = x_o report
252
                 integer'image( stim_cnt ) & ": Serial Cordic Failed: expected x result:"
253 7 feddischso
                 & integer'image( tmp_value(3) ) & ", but got:"
254
                 & integer'image( to_integer( signed( x_o ) ) );
255 2 feddischso
           assert y_ex = y_o report
256
                 integer'image( stim_cnt ) &   ": Serial Cordic Failed: expected y result:"
257 7 feddischso
                 & integer'image( tmp_value(4) ) & ", but got:"
258
                 & integer'image( to_integer( signed( y_o ) ) );
259 2 feddischso
           assert a_ex = a_o report
260
                 integer'image( stim_cnt ) &   ": Serial Cordic Failed: expected a result:"
261 3 feddischso
                 & integer'image( tmp_value(5) ) & ", but got:"
262 7 feddischso
                 & integer'image( to_integer( signed( a_o ) ) );
263 2 feddischso
            err_cnt := err_cnt + 1;
264
         writeline( error_pattern_file, input_line_bak );
265
 
266
        end if;
267 7 feddischso
 
268 2 feddischso
        wait for CLK_T * 5;
269
 
270
    end loop;
271
    report "====>>>> Serial Cordic Verification Result:" & integer'image( err_cnt ) & " of " & integer'image( stim_cnt ) & " tests failed";
272
    stop( 0 );
273
  end process stims_p;
274
 
275
 
276
 
277
 
278
   en_test : process
279
   begin
280
      en <= '0';
281
      wait for clk_T * 10;
282
      en <= '1';
283
      wait for clk_T * 1000;
284 7 feddischso
 
285 2 feddischso
   end process;
286
 
287
 
288
end architecture IMP;
289
 
290
 
291
 
292
 

powered by: WebSVN 2.1.0

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