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 13

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

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

powered by: WebSVN 2.1.0

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