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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.6/] [rtl/] [vlib/] [serport/] [tb/] [tb_serport_uart_rxtx.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_rxtx.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_rxtx - sim
16
-- Description:    Test bench for serport_uart_rxtx
17
--
18
-- Dependencies:   simlib/simclk
19
--                 tbd_serport_uart_rxtx [UUT]
20
--
21
-- To test:        serport_uart_rxtx
22
--
23
-- Target Devices: generic
24
--
25
-- Verified (with tb_serport_uart_rxtx_stim.dat):
26
-- Date         Rev  Code  ghdl  ise          Target     Comment
27
-- 2007-11-02    93  _tsim 0.26  8.2.03 I34   xc3s1000   d:ok
28
-- 2007-10-21    91  _ssim 0.26  8.1.03 I27   xc3s1000   c:ok
29
-- 2007-10-21    91  -     0.26  -            -          c:ok
30
-- 2007-10-14    89  -     0.26  -            -          c:ok
31
-- 2007-10-12    88  _ssim 0.26  8.1.03 I27   xc3s1000   c:ok
32
-- 2007-10-12    88  -     0.26  -            -          c:ok
33
--
34
-- Revision History: 
35
-- Date         Rev Version  Comment
36 17 wfjm
-- 2011-12-23   444   1.2    use new simclk/simclkcnt
37 13 wfjm
-- 2011-10-22   417   1.1.3  now numeric_std clean
38 2 wfjm
-- 2010-04-24   281   1.1.2  use direct instatiation for tbd_
39
-- 2008-03-24   129   1.1.1  CLK_CYCLE now 31 bits
40
-- 2007-10-21    91   1.1    now use 'send' command, self-checking (FAIL's)
41
-- 2007-10-12    88   1.0.1  avoid ieee.std_logic_unsigned, use cast to unsigned
42
-- 2007-08-27    76   1.0    Initial version 
43
------------------------------------------------------------------------------
44
 
45
library ieee;
46
use ieee.std_logic_1164.all;
47 13 wfjm
use ieee.numeric_std.all;
48 2 wfjm
use ieee.std_logic_textio.all;
49
use std.textio.all;
50
 
51
use work.slvtypes.all;
52
use work.simlib.all;
53 19 wfjm
use work.serportlib.all;
54 2 wfjm
 
55
entity tb_serport_uart_rxtx is
56
end tb_serport_uart_rxtx;
57
 
58
architecture sim of tb_serport_uart_rxtx is
59
 
60
  signal CLK :  slbit := '0';
61
  signal RESET :  slbit := '0';
62 13 wfjm
  signal CLKDIV : slv13 := slv(to_unsigned(15, 13));
63 2 wfjm
  signal RXDATA : slv8 := (others=>'0');
64
  signal RXVAL :  slbit := '0';
65
  signal RXERR  : slbit := '0';
66
  signal RXACT : slbit := '0';
67
  signal TXSD : slbit := '0';
68
  signal TXDATA : slv8 := (others=>'0');
69
  signal TXENA :  slbit := '0';
70
  signal TXBUSY : slbit := '0';
71
 
72
  signal CLK_STOP : slbit := '0';
73 17 wfjm
  signal CLK_CYCLE : integer := 0;
74 2 wfjm
 
75
  signal N_MON_VAL : slbit := '0';
76
  signal N_MON_DAT : slv8 := (others=>'0');
77
  signal R_MON_VAL_1 : slbit := '0';
78
  signal R_MON_DAT_1 : slv8 := (others=>'0');
79
  signal R_MON_VAL_2 : slbit := '0';
80
  signal R_MON_DAT_2 : slv8 := (others=>'0');
81
 
82
  constant clock_period : time :=  20 ns;
83
  constant clock_offset : time := 200 ns;
84
  constant setup_time : time :=  5 ns;
85
  constant c2out_time : time := 10 ns;
86
 
87
begin
88
 
89 17 wfjm
  CLKGEN : simclk
90 2 wfjm
    generic map (
91
      PERIOD => clock_period,
92
      OFFSET => clock_offset)
93
    port map (
94
      CLK       => CLK,
95
      CLK_STOP  => CLK_STOP
96
    );
97
 
98 17 wfjm
  CLKCNT : simclkcnt port map (CLK => CLK, CLK_CYCLE => CLK_CYCLE);
99
 
100 2 wfjm
  UUT : entity work.tbd_serport_uart_rxtx
101
    port map (
102
      CLK    => CLK,
103
      RESET  => RESET,
104
      CLKDIV => CLKDIV,
105
      RXSD   => TXSD,
106
      RXDATA => RXDATA,
107
      RXVAL  => RXVAL,
108
      RXERR  => RXERR,
109
      RXACT  => RXACT,
110
      TXSD   => TXSD,
111
      TXDATA => TXDATA,
112
      TXENA  => TXENA,
113
      TXBUSY => TXBUSY
114
    );
115
 
116
 
117
  proc_stim: process
118
    file fstim : text open read_mode is "tb_serport_uart_rxtx_stim";
119
    variable iline : line;
120
    variable oline : line;
121
    variable idelta : integer := 0;
122
    variable itxdata : slv8 := (others=>'0');
123
    variable ok : boolean;
124
    variable dname : string(1 to 6) := (others=>' ');
125
    variable irate : integer := 16;
126
 
127
  begin
128
 
129
    wait for clock_offset - setup_time;
130
 
131
    file_loop: while not endfile(fstim) loop
132
 
133
      readline (fstim, iline);
134
 
135
      readcomment(iline, ok);
136
      next file_loop when ok;
137
 
138
      readword(iline, dname, ok);
139
      if ok then
140
        case dname is
141
          when ".reset" =>              -- .reset 
142
            write(oline, string'(".reset"));
143
            writeline(output, oline);
144
            RESET <= '1';
145
            wait for clock_period;
146
            RESET <= '0';
147
            wait for 9*clock_period;
148
 
149
          when ".wait " =>              -- .wait 
150
            read_ea(iline, idelta);
151
            wait for idelta*clock_period;
152
 
153
          when ".rate " =>              -- .rate 
154
            read_ea(iline, irate);
155 13 wfjm
            CLKDIV <= slv(to_unsigned(irate-1, 13));
156 2 wfjm
 
157
          when "send  " =>              -- send
158
            read_ea(iline, idelta);
159
            read_ea(iline, itxdata);
160
 
161
            while TXBUSY='1' loop
162
              wait for clock_period;
163
            end loop;
164
 
165
            wait for idelta*clock_period;
166
 
167
            writetimestamp(oline, CLK_CYCLE, ": send ");
168
            write(oline, itxdata, right, 10);
169
            writeline(output, oline);
170
 
171
            TXDATA <= itxdata;
172
            TXENA  <= '1';
173
            N_MON_VAL <= '1';
174
            N_MON_DAT <= itxdata;
175
 
176
            wait for clock_period;
177
            TXENA  <= '0';
178
            N_MON_VAL <= '0';
179
 
180
          when others =>                -- unknown command
181
            write(oline, string'("?? unknown command: "));
182
            write(oline, dname);
183
            writeline(output, oline);
184
            report "aborting" severity failure;
185
        end case;
186
 
187
      else
188
        report "failed to find command" severity failure;
189
 
190
      end if;
191
 
192
      testempty_ea(iline);
193
    end loop;   -- file_loop
194
 
195
    idelta := 0;
196
    while TXBUSY='1' or RXACT='1' loop
197
      wait for clock_period;
198
      idelta := idelta + 1;
199
      exit when idelta>3000;
200
    end loop;
201
 
202
    writetimestamp(oline, CLK_CYCLE, ": DONE ");
203
    writeline(output, oline);
204
 
205
    wait for 12*irate*clock_period;
206
 
207
    CLK_STOP <= '1';
208
 
209
    wait;                               -- suspend proc_stim forever
210
                                        -- clock is stopped, sim will end
211
 
212
  end process proc_stim;
213
 
214
 
215
  proc_moni: process
216
    variable oline : line;
217
  begin
218
 
219
    loop
220 13 wfjm
      wait until rising_edge(CLK);
221 2 wfjm
 
222
      if R_MON_VAL_1 = '1' then
223
        if R_MON_VAL_2 = '1' then
224
          writetimestamp(oline, CLK_CYCLE, ": moni ");
225
          write(oline, string'("  FAIL MISSING DATA="));
226
          write(oline, R_MON_DAT_2);
227
          writeline(output, oline);
228
        end if;
229
        R_MON_VAL_2 <= R_MON_VAL_1;
230
        R_MON_DAT_2 <= R_MON_DAT_1;
231
      end if;
232
 
233
      R_MON_VAL_1 <= N_MON_VAL;
234
      R_MON_DAT_1 <= N_MON_DAT;
235
 
236
      if RXVAL='1' or RXERR='1' then
237
        writetimestamp(oline, CLK_CYCLE, ": moni ");
238
        write(oline, RXDATA, right, 10);
239
        if RXERR = '1' then
240
          write(oline, string'("  RXERR=1"));
241
        end if;
242
 
243
        if R_MON_VAL_2 = '0' then
244
          write(oline, string'("  FAIL UNEXPECTED"));
245
        else
246
          write(oline, string'("  CHECK"));
247
          R_MON_VAL_2 <= '0';
248
 
249
          if R_MON_DAT_2 = RXDATA and
250
            RXERR='0' then
251
            write(oline, string'("  OK"));
252
          else
253
            write(oline, string'("  FAIL"));
254
          end if;
255
 
256
        end if;
257
 
258
        writeline(output, oline);
259
      end if;
260
 
261
    end loop;
262
 
263
  end process proc_moni;
264
 
265
end sim;

powered by: WebSVN 2.1.0

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