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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.6/] [rtl/] [vlib/] [serport/] [tb/] [tb_serport_uart_rx.vhd] - Blame information for rev 19

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

Line No. Rev Author Line
1 19 wfjm
-- $Id: tb_serport_uart_rx.vhd 476 2013-01-26 22:23:53Z mueller $
2 2 wfjm
--
3 13 wfjm
-- Copyright 2007-2011 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4 2 wfjm
--
5
-- This program is free software; you may redistribute and/or modify it under
6
-- the terms of the GNU General Public License as published by the Free
7
-- Software Foundation, either version 2, or at your option any later version.
8
--
9
-- This program is distributed in the hope that it will be useful, but
10
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
-- for complete details.
13
--
14
------------------------------------------------------------------------------
15
-- Module Name:    tb_serport_uart_rx - sim
16
-- Description:    Test bench for serport_uart_rx
17
--
18
-- Dependencies:   simlib/simclk
19 17 wfjm
--                 simlib/simclkcnt
20 2 wfjm
--                 tbd_serport_uart_rx [UUT]
21
--
22
-- To test:        serport_uart_rx
23
--
24
-- Target Devices: generic
25
--
26
-- Verified (with tb_serport_uart_rx_stim.dat):
27
-- Date         Rev  Code  ghdl  ise          Target     Comment
28
-- 2007-11-02    93  _tsim 0.26  8.2.03 I34   xc3s1000   d:ok
29
-- 2007-10-21    91  _ssim 0.26  8.1.03 I27   xc3s1000   c:ok (63488 cl 15.21s)
30
-- 2007-10-21    91  -     0.26  -            -          c:ok (63488 cl  7.12s)
31
--
32
-- Revision History: 
33
-- Date         Rev Version  Comment
34 17 wfjm
-- 2011-12-23   444   1.1    use new simclk/simclkcnt
35 13 wfjm
-- 2011-10-22   417   1.0.3  now numeric_std clean
36 2 wfjm
-- 2010-04-24   281   1.0.2  use direct instatiation for tbd_
37
-- 2008-03-24   129   1.0.1  CLK_CYCLE now 31 bits
38
-- 2007-10-21    91   1.0    Initial version 
39
------------------------------------------------------------------------------
40
 
41
library ieee;
42
use ieee.std_logic_1164.all;
43 13 wfjm
use ieee.numeric_std.all;
44 2 wfjm
use ieee.std_logic_textio.all;
45
use std.textio.all;
46
 
47
use work.slvtypes.all;
48
use work.simlib.all;
49 19 wfjm
use work.serportlib.all;
50 2 wfjm
 
51
entity tb_serport_uart_rx is
52
end tb_serport_uart_rx;
53
 
54
architecture sim of tb_serport_uart_rx is
55
 
56
  signal CLK :  slbit := '0';
57
  signal RESET :  slbit := '0';
58 13 wfjm
  signal CLKDIV : slv5 := slv(to_unsigned(15, 5));
59 2 wfjm
  signal RXSD :  slbit := '1';
60
  signal RXDATA : slv8 := (others=>'0');
61
  signal RXVAL :  slbit := '0';
62
  signal RXERR  : slbit := '0';
63
  signal RXACT : slbit := '0';
64
 
65
  signal CLK_STOP : slbit := '0';
66 17 wfjm
  signal CLK_CYCLE : integer := 0;
67 2 wfjm
 
68
  signal N_MON_VAL : slbit := '0';
69
  signal N_MON_ERR : slbit := '0';
70
  signal N_MON_DAT : slv8 := (others=>'0');
71
  signal R_MON_VAL_1 : slbit := '0';
72
  signal R_MON_ERR_1 : slbit := '0';
73
  signal R_MON_DAT_1 : slv8 := (others=>'0');
74
  signal R_MON_VAL_2 : slbit := '0';
75
  signal R_MON_ERR_2 : slbit := '0';
76
  signal R_MON_DAT_2 : slv8 := (others=>'0');
77
 
78
  constant clock_period : time :=  20 ns;
79
  constant clock_offset : time := 200 ns;
80
  constant setup_time : time :=  5 ns;
81
  constant c2out_time : time := 10 ns;
82
 
83
begin
84
 
85 17 wfjm
  CLKGEN : simclk
86 2 wfjm
    generic map (
87
      PERIOD => clock_period,
88
      OFFSET => clock_offset)
89
    port map (
90
      CLK       => CLK,
91
      CLK_STOP  => CLK_STOP
92
    );
93 17 wfjm
 
94
  CLKCNT : simclkcnt port map (CLK => CLK, CLK_CYCLE => CLK_CYCLE);
95 2 wfjm
 
96
  UUT : entity work.tbd_serport_uart_rx
97
    port map (
98
      CLK    => CLK,
99
      RESET  => RESET,
100
      CLKDIV => CLKDIV,
101
      RXSD   => RXSD,
102
      RXDATA => RXDATA,
103
      RXVAL  => RXVAL,
104
      RXERR  => RXERR,
105
      RXACT  => RXACT
106
    );
107
 
108
 
109
  proc_stim: process
110
    file fstim : text open read_mode is "tb_serport_uart_rx_stim";
111
    variable iline : line;
112
    variable oline : line;
113
    variable idelta : integer := 0;
114
    variable itxdata : slv8 := (others=>'0');
115
    variable irxval  : slbit := '0';
116
    variable irxerr  : slbit := '0';
117
    variable irxdata : slv8 := (others=>'0');
118
    variable ok : boolean;
119
    variable dname : string(1 to 6) := (others=>' ');
120
    variable irate : integer := 16;
121
 
122
    type bit_10_array_type  is array (0 to 9) of slbit;
123
    type int_10_array_type  is array (0 to 9) of integer;
124
    variable valpuls : bit_10_array_type := (others=>'0');
125
    variable delpuls : int_10_array_type := (others=>0);
126
    variable npuls : integer := 0;
127
 
128
  begin
129
 
130
    wait for clock_offset - setup_time;
131
 
132
    file_loop: while not endfile(fstim) loop
133
 
134
      readline (fstim, iline);
135
 
136
      readcomment(iline, ok);
137
      next file_loop when ok;
138
 
139
      readword(iline, dname, ok);
140
      if ok then
141
        case dname is
142
          when ".reset" =>              -- .reset 
143
            write(oline, string'(".reset"));
144
            writeline(output, oline);
145
            RESET <= '1';
146
            wait for clock_period;
147
            RESET <= '0';
148
            wait for 9*clock_period;
149
 
150
          when ".wait " =>              -- .wait 
151
            read_ea(iline, idelta);
152
            wait for idelta*clock_period;
153
 
154
          when ".rate " =>              -- .rate 
155
            idelta := 0;
156
            while RXACT='1' loop          -- ensure that uart isn't active
157
              wait for clock_period;
158
              idelta := idelta + 1;
159
              exit when idelta>3000;
160
            end loop;
161
            read_ea(iline, irate);
162
            wait for 2*clock_period;
163 13 wfjm
            CLKDIV <= slv(to_unsigned(irate-1, CLKDIV'length));
164 2 wfjm
            wait for 2*clock_period;
165
 
166
          when ".xrate" =>              -- .xrate 
167
            read_ea(iline, irate);
168
 
169
          when "puls  " =>              -- puls
170
            writetimestamp(oline, CLK_CYCLE, ": puls ");
171
 
172
            read_ea(iline, irxval);
173
            read_ea(iline, irxerr);
174
            read_ea(iline, irxdata);
175
 
176
            npuls := 0;
177
            for i in valpuls'range loop
178
              testempty(iline, ok);
179
              if ok then
180
                exit;
181
              end if;
182
              read_ea(iline, valpuls(i));
183
              read_ea(iline, delpuls(i));
184
              assert delpuls(i)>0
185
                report "assert puls length > 0" severity failure;
186
              npuls := npuls + 1;
187
              write(oline, valpuls(i), right, 3);
188
              write(oline, delpuls(i), right, 3);
189
            end loop;  -- i
190
            writeline(output, oline);
191
 
192
            if npuls > 0 then
193
              N_MON_VAL <= irxval;
194
              N_MON_ERR <= irxerr;
195
              N_MON_DAT <= irxdata;
196
              for i in 0 to npuls-1 loop
197
                RXSD <= valpuls(i);
198
                wait for clock_period;
199
                N_MON_VAL <= '0';
200
                wait for (delpuls(i)-1)*clock_period;
201
              end loop;  -- i
202
            end if;
203
 
204
          when "send  " =>              -- send  
205
            read_ea(iline, idelta);
206
            read_ea(iline, itxdata);
207
 
208
            RXSD <= '1';
209
            wait for idelta*clock_period;
210
 
211
            writetimestamp(oline, CLK_CYCLE, ": send ");
212
            write(oline, itxdata, right, 10);
213
            writeline(output, oline);
214
 
215
            N_MON_VAL <= '1';
216
            N_MON_ERR <= '0';
217
            N_MON_DAT <= itxdata;
218
 
219
            RXSD <= '0';                      -- start bit
220
            wait for clock_period;
221
            N_MON_VAL <= '0';
222
            wait for (irate-1)*clock_period;
223
            RXSD <= '1';
224
 
225
            for i in itxdata'reverse_range loop -- transmit lsb first
226
              RXSD <= itxdata(i);             -- data bit
227
              wait for irate*clock_period;
228
            end loop;
229
 
230
            RXSD <= '1';                      -- stop bit
231
            wait for irate*clock_period;
232
 
233
          when others =>                -- unknown command
234
            write(oline, string'("?? unknown command: "));
235
            write(oline, dname);
236
            writeline(output, oline);
237
            report "aborting" severity failure;
238
        end case;
239
 
240
      else
241
        report "failed to find command" severity failure;
242
 
243
      end if;
244
 
245
      testempty_ea(iline);
246
    end loop;  -- file_loop: 
247
 
248
    idelta := 0;
249
    while RXACT='1' loop
250
      wait for clock_period;
251
      idelta := idelta + 1;
252
      exit when idelta>3000;
253
    end loop;
254
 
255
    writetimestamp(oline, CLK_CYCLE, ": DONE ");
256
    writeline(output, oline);
257
 
258
    wait for 12*irate*clock_period;
259
 
260
    CLK_STOP <= '1';
261
 
262
    wait;                               -- suspend proc_stim forever
263
                                        -- clock is stopped, sim will end
264
 
265
  end process proc_stim;
266
 
267
 
268
  proc_moni: process
269
    variable oline : line;
270
  begin
271
 
272
    loop
273 13 wfjm
      wait until rising_edge(CLK);
274 2 wfjm
 
275
      if R_MON_VAL_1 = '1' then
276
        if R_MON_VAL_2 = '1' then
277
          writetimestamp(oline, CLK_CYCLE, ": moni ");
278
          write(oline, string'("  FAIL MISSING ERR="));
279
          write(oline, R_MON_ERR_2);
280
          write(oline, string'("  DATA="));
281
          write(oline, R_MON_DAT_2);
282
          writeline(output, oline);
283
        end if;
284
        R_MON_VAL_2 <= R_MON_VAL_1;
285
        R_MON_ERR_2 <= R_MON_ERR_1;
286
        R_MON_DAT_2 <= R_MON_DAT_1;
287
      end if;
288
 
289
      R_MON_VAL_1 <= N_MON_VAL;
290
      R_MON_ERR_1 <= N_MON_ERR;
291
      R_MON_DAT_1 <= N_MON_DAT;
292
 
293
      if RXVAL='1' or RXERR='1' then
294
        writetimestamp(oline, CLK_CYCLE, ": moni ");
295
        write(oline, RXDATA, right, 10);
296
        if RXERR = '1' then
297
          write(oline, string'("  RXERR=1"));
298
        end if;
299
 
300
        if R_MON_VAL_2 = '0' then
301
          write(oline, string'("  FAIL UNEXPECTED"));
302
        else
303
          write(oline, string'("  CHECK"));
304
          R_MON_VAL_2 <= '0';
305
 
306
          if R_MON_ERR_2 = '0' then
307
            if R_MON_DAT_2 = RXDATA and
308
               RXERR='0' then
309
              write(oline, string'("  OK"));
310
            else
311
              write(oline, string'("  FAIL"));
312
            end if;
313
 
314
          else
315
            if RXERR = '1' then
316
              write(oline, string'("  OK"));
317
            else
318
              write(oline, string'("  FAIL, RXERR=1 expected"));
319
            end if;
320
 
321
          end if;
322
 
323
        end if;
324
 
325
        writeline(output, oline);
326
      end if;
327
 
328
    end loop;
329
 
330
  end process proc_moni;
331
 
332
end sim;

powered by: WebSVN 2.1.0

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