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

Subversion Repositories w11

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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