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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.74/] [rtl/] [vlib/] [rlink/] [tb/] [tb_rlink.vhd] - Blame information for rev 38

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 37 wfjm
-- $Id: tb_rlink.vhd 807 2016-09-17 07:49:26Z mueller $
2 2 wfjm
--
3 37 wfjm
-- Copyright 2007-2016 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 9 wfjm
-- Module Name:    tb_rlink - sim
16
-- Description:    Test bench for rlink_core
17 2 wfjm
--
18
-- Dependencies:   simlib/simclk
19 17 wfjm
--                 simlib/simclkcnt
20 37 wfjm
--                 genlib/tb/clkdivce_tb
21
--                 rbus/rbd_tester
22 9 wfjm
--                 tbd_rlink_gen [UUT]
23 2 wfjm
--
24 9 wfjm
-- To test:        rlink_core     (via tbd_rlink_direct)
25
--                 rlink_base     (via tbd_rlink_serport)
26
--                 rlink_serport  (via tbd_rlink_serport)
27 2 wfjm
--
28
-- Target Devices: generic
29 37 wfjm
-- Tool versions:  xst 8.2-14.7; viv 2016.2; ghdl 0.18-0.33
30 9 wfjm
--
31 2 wfjm
-- Revision History: 
32
-- Date         Rev Version  Comment
33 37 wfjm
-- 2016-09-10   806   4.1.1  use clkdivce_tb
34 27 wfjm
-- 2014-10-12   596   4.1    use readgen_ea; add get_cmd_ea; labo instead of stat
35
--                           add txblk,rxblk,rxrbeg,rxrend,rxcbs,anmsg commands
36
-- 2014-08-28   588   4.0    now rlink v4 iface -> txcac has 16 bit; 4 bit STAT
37
-- 2014-08-15   583   3.5    rb_mreq addr now 16 bit; adopt txca,txcad,txcac
38 17 wfjm
-- 2011-12-23   444   3.1    use new simclk/simclkcnt
39 13 wfjm
-- 2011-11-19   427   3.0.7  fix crc8_update_tbl usage; now numeric_std clean
40 9 wfjm
-- 2010-12-29   351   3.0.6  use new rbd_tester addr 111100xx (from 111101xx)
41
-- 2010-12-26   348   3.0.5  use simbus to export clkcycle (for tbd_..serport)
42
-- 2010-12-23   347   3.0.4  use rb_mon, rlink_mon directly; rename CP_*->RL_*
43
-- 2010-12-22   346   3.0.3  add .rlmon and .rbmon commands
44
-- 2010-12-21   345   3.0.2  rename commands .[rt]x... to [rt]x...;
45
--                           add .[rt]x(idle|attn) cmds; remove 'bbbbbbbb' cmd
46
-- 2010-12-12   344   3.0.1  add .attn again; add .txbad, .txoof; ren oob->oof
47
-- 2010-12-05   343   3.0    rri->rlink renames; port to rbus V3 protocol;
48
--                           use rbd_tester instead of sim target;
49 2 wfjm
-- 2010-06-06   302   2.5    use sop/eop framing instead of soc+chaining
50
-- 2010-06-03   299   2.2.2  new init encoding (WE=0/1 int/ext);use sv_ prefix
51
--                           for shared variables 
52
-- 2010-05-02   287   2.2.1  ren CE_XSEC->CE_INT,RP_STAT->RB_STAT,AP_LAM->RB_LAM
53
--                           drop RP_IINT signal from interfaces
54
-- 2010-04-03   274   2.2    add CE_USEC in tbd_rri_gen interface
55
-- 2009-03-14   197   2.1    remove records in interface to allow _ssim usage
56
-- 2008-08-24   162   2.0    with new rb_mreq/rb_sres interface
57
-- 2008-03-24   129   1.1.2  CLK_CYCLE now 31 bits
58
-- 2008-01-20   112   1.1.1  rename clkgen->clkdivce
59
-- 2007-11-24    98   1.1    add RP_IINT support, add checkmiss_tx to test
60
--                           for missing responses
61
-- 2007-10-26    92   1.0.2  add DONE timestamp at end of execution
62
-- 2007-10-12    88   1.0.1  avoid ieee.std_logic_unsigned, use cast to unsigned
63
-- 2007-09-09    81   1.0    Initial version 
64
------------------------------------------------------------------------------
65 9 wfjm
-- command set:
66
--   .reset                               assert RESET for 1 clk
67 27 wfjm
--   .rlmon ien                           enable rlink monitor (9 bit)
68
--   .rlbmo ien                           enable rlink monitor (8 bit)
69 9 wfjm
--   .rbmon ien                           enable rbus monitor
70 27 wfjm
--   .wait  n                             wait n clks
71
--   .iowt  n                             wait n clks for rlink i/o; auto-extend
72
--   .attn  dat(16)                       pulse attn lines with dat
73
--
74
-- - high level ---
75
--   anmsg apat                           attn notify message
76
--   sop                                  start packet
77
--   eop                                  end packet
78
--   rreg  seq  addr  data  stat          rreg cmd
79
--   wreg  seq  addr  data  stat          wreg cmd
80
--   init  seq  addr  data  stat          init cmd
81
--   attn  seq        data  stat          attn cmd
82
--   labo  seq        data  stat          labo cmd
83
--   rblks seq  addr  nblk  data  stat    rblk cmd (with seq)
84
--   wblks seq  addr  nblk  data  stat    wblk cmd (with seq)
85
--   rblkd seq  addr  ndone  stat         rblk cmd (with data list)
86
--   wblkd seq  addr  ndone  stat         wblk cmd (with data list)
87
--   .dclr                                clear data list
88
--   .dwrd  data                          add word to data list
89
--   .dseq  nblk  data                    add sequence to data list
90
--
91
-- - low level ---
92
--   txcrc                                send crc
93
--   txbad                                send bad (inverted) crc
94
--   txc    cmd(8)                        send cmd - crc
95
--   txca   cmd(8) addr(16)               send cmd - al ah - crcl crch
96
--   txcad  cmd(8) addr(16) dat(16)       send cmd - al ah - dl dh - crcl crch
97
--   txcac  cmd(8) addr(16) cnt(16)       send cmd - al ah - cl ch - crcl crch
98
--   txoof  dat(9)                        send out-of-frame symbol
99
--   rxcrc                                expect crc
100
--   rxcs   cmd(8) stat(8)                expect cmd - stat - crcl crch
101
--   rxcds  cmd(8) dat(16) stat(8)        expect cmd - dl dh - stat - crcl crch
102
--   rxcbs  cmd(8)  dat(8) stat(8)        expect cmd - dl - stat - crcl crch
103
--   rxrbeg cmd(8) cnt(16)                expect cmd - cl ch 
104
--   rxrend dcnt(16)                      expect dcl dch - stat - crcl crch
105
--   rxoof  dat(9)                        expect out-of-frame symbol
106
--
107
-- - raw level ---
108 9 wfjm
--   txsop                                send <sop>
109
--   txeop                                send <eop>
110
--   txnak                                send <nak>
111
--   txattn                               send <attn>
112 27 wfjm
--   tx8    dat(8)                        send  8 bit value
113
--   tx16   dat(16)                       send 16 bit value
114
--   txblk  n start                       send n 16 values
115 9 wfjm
--   rxsop                                reset rx list; expect sop
116
--   rxeop                                expect <eop>
117
--   rxnak                                expect <nak>
118
--   rxattn                               expect <attn>
119 27 wfjm
--   rx8    dat(8)                        expect  8 bit value
120
--   rx16   dat(16)                       expect 16 bit value
121
--   rxblk  n start                       expect n 16 values
122 9 wfjm
--
123
------------------------------------------------------------------------------
124 2 wfjm
 
125
library ieee;
126
use ieee.std_logic_1164.all;
127 13 wfjm
use ieee.numeric_std.all;
128 2 wfjm
use ieee.std_logic_textio.all;
129
use std.textio.all;
130
 
131
use work.slvtypes.all;
132
use work.genlib.all;
133
use work.comlib.all;
134 9 wfjm
use work.rblib.all;
135
use work.rbdlib.all;
136
use work.rlinklib.all;
137 2 wfjm
use work.simlib.all;
138 27 wfjm
use work.simbus.all;
139 2 wfjm
 
140 9 wfjm
entity tb_rlink is
141
end tb_rlink;
142 2 wfjm
 
143 9 wfjm
architecture sim of tb_rlink is
144 2 wfjm
 
145 27 wfjm
  constant d_f_cflag   : integer := 8;                -- d9: comma flag
146
  subtype  d_f_data   is integer range  7 downto  0;  -- d9: data field
147
 
148
  subtype  f_byte1    is integer range 15 downto 8;
149
  subtype  f_byte0    is integer range  7 downto 0;
150
 
151 2 wfjm
  signal CLK : slbit := '0';
152
  signal CE_USEC : slbit := '0';
153
  signal CE_MSEC : slbit := '0';
154
  signal RESET : slbit := '0';
155 9 wfjm
  signal RL_DI : slv9 := (others=>'0');
156
  signal RL_ENA : slbit := '0';
157
  signal RL_BUSY : slbit := '0';
158
  signal RL_DO : slv9 := (others=>'0');
159
  signal RL_VAL : slbit := '0';
160
  signal RL_HOLD : slbit := '0';
161
  signal RB_MREQ_aval : slbit := '0';
162
  signal RB_MREQ_re : slbit := '0';
163 2 wfjm
  signal RB_MREQ_we : slbit := '0';
164
  signal RB_MREQ_initt: slbit := '0';
165 27 wfjm
  signal RB_MREQ_addr : slv16 := (others=>'0');
166 2 wfjm
  signal RB_MREQ_din : slv16 := (others=>'0');
167
  signal RB_SRES_ack : slbit := '0';
168
  signal RB_SRES_busy : slbit := '0';
169
  signal RB_SRES_err : slbit := '0';
170
  signal RB_SRES_dout : slv16 := (others=>'0');
171 9 wfjm
  signal RB_LAM_TBENCH : slv16 := (others=>'0');
172
  signal RB_LAM_TESTER : slv16 := (others=>'0');
173 2 wfjm
  signal RB_LAM : slv16 := (others=>'0');
174 27 wfjm
  signal RB_STAT : slv4 := (others=>'0');
175 2 wfjm
  signal TXRXACT : slbit := '0';
176 9 wfjm
 
177
  signal RB_MREQ : rb_mreq_type := rb_mreq_init;
178
  signal RB_SRES : rb_sres_type := rb_sres_init;
179 2 wfjm
 
180
  signal CLK_STOP : slbit := '0';
181 17 wfjm
  signal CLK_CYCLE : integer := 0;
182 2 wfjm
 
183 27 wfjm
  constant rxlist_size  : positive := 4096;  -- size of rxlist
184
  constant txlist_size  : positive := 4096;  -- size of txlist
185
  constant datlist_size : positive := 2048;  -- size of datlist
186
 
187 2 wfjm
  constant slv9_zero  : slv9  := (others=>'0');
188
  constant slv16_zero : slv16 := (others=>'0');
189
 
190 27 wfjm
  type rxlist_array_type  is array (0 to rxlist_size-1)  of slv9;
191
  type txlist_array_type  is array (0 to txlist_size-1)  of slv9;
192
  type datlist_array_type is array (0 to datlist_size-1) of slv16;
193
 
194
  shared variable sv_rxlist : rxlist_array_type := (others=>slv9_zero);
195 2 wfjm
  shared variable sv_nrxlist : natural := 0;
196
  shared variable sv_rxind : natural := 0;
197
 
198 37 wfjm
  constant clock_period : Delay_length :=  20 ns;
199
  constant clock_offset : Delay_length := 200 ns;
200
  constant setup_time : Delay_length :=  5 ns;
201
  constant c2out_time : Delay_length := 10 ns;
202 2 wfjm
 
203 9 wfjm
component tbd_rlink_gen is              -- rlink, generic tb design interface
204 2 wfjm
  port (
205
    CLK  : in slbit;                    -- clock
206 9 wfjm
    CE_INT : in slbit;                  -- rlink ito time unit clock enable
207 2 wfjm
    CE_USEC : in slbit;                 -- 1 usec clock enable
208
    RESET  : in slbit;                  -- reset
209 9 wfjm
    RL_DI : in slv9;                    -- rlink: data in
210
    RL_ENA : in slbit;                  -- rlink: data enable
211
    RL_BUSY : out slbit;                -- rlink: data busy
212
    RL_DO : out slv9;                   -- rlink: data out
213
    RL_VAL : out slbit;                 -- rlink: data valid
214
    RL_HOLD : in slbit;                 -- rlink: data hold
215
    RB_MREQ_aval : out slbit;           -- rbus: request - aval
216
    RB_MREQ_re : out slbit;             -- rbus: request - re
217 2 wfjm
    RB_MREQ_we : out slbit;             -- rbus: request - we
218
    RB_MREQ_initt: out slbit;           -- rbus: request - init; avoid name coll
219 27 wfjm
    RB_MREQ_addr : out slv16;           -- rbus: request - addr
220 2 wfjm
    RB_MREQ_din : out slv16;            -- rbus: request - din
221
    RB_SRES_ack : in slbit;             -- rbus: response - ack
222
    RB_SRES_busy : in slbit;            -- rbus: response - busy
223
    RB_SRES_err : in slbit;             -- rbus: response - err
224
    RB_SRES_dout : in slv16;            -- rbus: response - dout
225
    RB_LAM : in slv16;                  -- rbus: look at me
226 27 wfjm
    RB_STAT : in slv4;                  -- rbus: status flags
227 2 wfjm
    TXRXACT : out slbit                 -- txrx active flag
228
  );
229
end component;
230
 
231
begin
232
 
233 17 wfjm
  CLKGEN : simclk
234 2 wfjm
    generic map (
235
      PERIOD => clock_period,
236
      OFFSET => clock_offset)
237
    port map (
238
      CLK       => CLK,
239
      CLK_STOP  => CLK_STOP
240
    );
241
 
242 17 wfjm
  CLKCNT : simclkcnt port map (CLK => CLK, CLK_CYCLE => CLK_CYCLE);
243
 
244 37 wfjm
  CLKDIV : entity work.clkdivce_tb
245 2 wfjm
    generic map (
246
      CDUWIDTH => 6,
247
      USECDIV  => 4,
248 17 wfjm
      MSECDIV  => 5)
249 2 wfjm
    port map (
250
      CLK     => CLK,
251
      CE_USEC => CE_USEC,
252
      CE_MSEC => CE_MSEC
253
    );
254
 
255 9 wfjm
  RB_MREQ.aval <= RB_MREQ_aval;
256
  RB_MREQ.re   <= RB_MREQ_re;
257
  RB_MREQ.we   <= RB_MREQ_we;
258
  RB_MREQ.init <= RB_MREQ_initt;
259
  RB_MREQ.addr <= RB_MREQ_addr;
260
  RB_MREQ.din  <= RB_MREQ_din;
261
 
262
  RB_SRES_ack   <= RB_SRES.ack;
263
  RB_SRES_busy  <= RB_SRES.busy;
264
  RB_SRES_err   <= RB_SRES.err;
265
  RB_SRES_dout  <= RB_SRES.dout;
266
 
267
  RBTEST : rbd_tester
268
    generic map (
269 27 wfjm
      RB_ADDR => slv(to_unsigned(16#ffe0#,16)))
270 2 wfjm
    port map (
271 9 wfjm
      CLK      => CLK,
272
      RESET    => '0',
273
      RB_MREQ  => RB_MREQ,
274
      RB_SRES  => RB_SRES,
275
      RB_LAM   => RB_LAM_TESTER,
276
      RB_STAT  => RB_STAT
277
    );
278
 
279
  RB_LAM <= RB_LAM_TESTER or RB_LAM_TBENCH;
280
 
281
  UUT : tbd_rlink_gen
282
    port map (
283 2 wfjm
      CLK          => CLK,
284
      CE_INT       => CE_MSEC,
285
      CE_USEC      => CE_USEC,
286
      RESET        => RESET,
287 9 wfjm
      RL_DI        => RL_DI,
288
      RL_ENA       => RL_ENA,
289
      RL_BUSY      => RL_BUSY,
290
      RL_DO        => RL_DO,
291
      RL_VAL       => RL_VAL,
292
      RL_HOLD      => RL_HOLD,
293
      RB_MREQ_aval => RB_MREQ_aval,
294
      RB_MREQ_re   => RB_MREQ_re,
295 2 wfjm
      RB_MREQ_we   => RB_MREQ_we,
296
      RB_MREQ_initt=> RB_MREQ_initt,
297
      RB_MREQ_addr => RB_MREQ_addr,
298
      RB_MREQ_din  => RB_MREQ_din,
299
      RB_SRES_ack  => RB_SRES_ack,
300
      RB_SRES_busy => RB_SRES_busy,
301
      RB_SRES_err  => RB_SRES_err,
302
      RB_SRES_dout => RB_SRES_dout,
303
      RB_LAM       => RB_LAM,
304
      RB_STAT      => RB_STAT,
305
      TXRXACT      => TXRXACT
306
    );
307
 
308
  proc_stim: process
309 9 wfjm
    file fstim : text open read_mode is "tb_rlink_stim";
310 2 wfjm
    variable iline : line;
311
    variable oline : line;
312 9 wfjm
    variable ien   : slbit := '0';
313 27 wfjm
    variable icmd  : slv8  := (others=>'0');
314
    variable iaddr : slv16 := (others=>'0');
315
    variable icnt  : slv16 := (others=>'0');
316
    variable ibabo : slv8  := (others=>'0');
317
    variable istat : slv8  := (others=>'0');
318 9 wfjm
    variable iattn : slv16 := (others=>'0');
319 2 wfjm
    variable idata : slv16 := (others=>'0');
320 27 wfjm
    variable idat8 : slv8  := (others=>'0');
321 9 wfjm
    variable ioof  : slv9 := (others=>'0');
322 27 wfjm
    variable iblkval : slv16 := (others=>'0');
323
    variable iblkmsk : slv16 := (others=>'0');
324
    variable nblk  : natural := 1;
325
    variable ndone : natural := 1;
326
    variable rxlabo : boolean := false;
327 2 wfjm
    variable ok : boolean;
328
    variable dname : string(1 to 6) := (others=>' ');
329
    variable idelta : integer := 0;
330
    variable iowait : integer := 0;
331 27 wfjm
    variable txcrc,rxcrc : slv16 := (others=>'0');
332
    variable txlist : txlist_array_type := (others=>slv9_zero);
333 2 wfjm
    variable ntxlist : natural := 0;
334 27 wfjm
    variable datlist : datlist_array_type := (others=>slv16_zero);
335
    variable ndatlist : natural := 0;
336
 
337
    -- read command line  helpers ------------------------------------
338
    procedure get_cmd_ea (              -- ---- get_cmd_ea -----------
339
      L : inout line;
340
      icmd : out slv8)  is
341
      variable cname : string(1 to 4) := (others=>' ');
342
      variable ival : natural;
343
      variable ok : boolean;
344
      variable cmd : slv3;
345
      variable dat : slv8;
346 2 wfjm
    begin
347 27 wfjm
      readword_ea(L, cname);
348
      ival := 0;
349
      readoptchar(L, ',', ok);
350
      if ok then
351
        readint_ea(L, ival, 0, 31);
352
      end if;
353
      case cname is
354
        when  "rreg" => cmd := c_rlink_cmd_rreg;
355
        when  "rblk" => cmd := c_rlink_cmd_rblk;
356
        when  "wreg" => cmd := c_rlink_cmd_wreg;
357
        when  "wblk" => cmd := c_rlink_cmd_wblk;
358
        when  "labo" => cmd := c_rlink_cmd_labo;
359
        when  "attn" => cmd := c_rlink_cmd_attn;
360
        when  "init" => cmd := c_rlink_cmd_init;
361
        when others =>
362
          report "unknown cmd code" severity failure;
363
      end case;
364
      dat := (others=>'0');
365
      dat(c_rlink_cmd_rbf_seq)  := slv(to_unsigned(ival,5));
366
      dat(c_rlink_cmd_rbf_code) := cmd;
367
      icmd := dat;
368
    end procedure get_cmd_ea;
369
 
370
    procedure get_seq_ea (              -- ---- get_seq_ea -----------
371
      L : inout line;
372
      code : in slv3;
373
      icmd : out slv8)  is
374
      variable ival : natural;
375
      variable dat : slv8;
376
    begin
377
      readint_ea(L, ival, 0, 31);
378
      dat := (others=>'0');
379
      dat(c_rlink_cmd_rbf_seq)  := slv(to_unsigned(ival,5));
380
      dat(c_rlink_cmd_rbf_code) := code;
381
      icmd := dat;
382
    end procedure get_seq_ea;
383
 
384
    -- tx helpers ----------------------------------------------------
385
    procedure do_tx9 (data : in slv9)  is -- ---- do_tx9 -------------
386
    begin
387
      txlist(ntxlist) := data;
388 2 wfjm
      ntxlist := ntxlist + 1;
389 27 wfjm
    end procedure do_tx9;
390
 
391
    procedure do_tx8 (data : in slv8)  is -- ---- do_tx8 -------------
392
    begin
393
      do_tx9('0' & data);
394
      txcrc := crc16_update_tbl(txcrc, data);
395 2 wfjm
    end procedure do_tx8;
396
 
397 27 wfjm
    procedure do_tx16 (data : in slv16)  is -- ---- do_tx16 ----------
398 2 wfjm
    begin
399 27 wfjm
      do_tx8(data( f_byte0));
400
      do_tx8(data(f_byte1));
401 2 wfjm
    end procedure do_tx16;
402
 
403 27 wfjm
    procedure do_txcrc is               -- ---- do_txcrc -------------
404 2 wfjm
    begin
405 27 wfjm
      do_tx9('0' & txcrc(f_byte0));
406
      do_tx9('0' & txcrc(f_byte1));
407
    end procedure do_txcrc;
408
 
409
    procedure do_txsop is               -- ---- do_txsop -------------
410
    begin
411
      do_tx9(c_rlink_dat_sop);
412
      txcrc := (others=>'0');
413
    end procedure do_txsop;
414 2 wfjm
 
415 27 wfjm
    procedure do_txeop is               -- ---- do_txeop -------------
416 2 wfjm
    begin
417 27 wfjm
      do_tx9(c_rlink_dat_eop);
418
    end procedure do_txeop;
419 2 wfjm
 
420 27 wfjm
    procedure do_txc (icmd  : in slv8) is -- ---- do_txc -------------
421 2 wfjm
    begin
422 27 wfjm
      do_tx8(icmd);
423
      do_txcrc;
424
    end procedure do_txc;
425
 
426
    procedure do_txca (                 -- ---- do_txca --------------
427
      icmd  : in slv8;
428
      iaddr : in slv16) is
429
    begin
430
      do_tx8(icmd);
431
      do_tx16(iaddr);
432
      do_txcrc;
433
    end procedure do_txca;
434
 
435
    procedure do_txcad (                -- ---- do_txcad -------------
436
      icmd  : in slv8;
437
      iaddr : in slv16;
438
      idata : in slv16) is
439
    begin
440
      do_tx8(icmd);
441
      do_tx16(iaddr);
442
      do_tx16(idata);
443
      do_txcrc;
444
    end procedure do_txcad;
445
 
446
    procedure do_txblks (               -- ---- do_txblks ------------
447
      nblk  : in natural;
448
      start : in slv16) is
449
      variable idata : slv16;
450
    begin
451
      idata := start;
452
      for i in 1 to nblk loop
453
        do_tx16(idata);
454
        idata := slv(unsigned(idata) + 1);
455
      end loop;
456
    end procedure do_txblks;
457
 
458
    -- rx helpers ----------------------------------------------------
459
    procedure checkmiss_rx is           -- ---- checkmiss_rx ---------
460
    begin
461 2 wfjm
      if sv_rxind < sv_nrxlist then
462
        for i in sv_rxind to sv_nrxlist-1 loop
463 17 wfjm
          writetimestamp(oline, CLK_CYCLE, ": moni ");
464 27 wfjm
          write(oline, string'("             FAIL MISSING DATA="));
465
          write(oline, sv_rxlist(i)(d_f_cflag));
466 2 wfjm
          write(oline, string'(" "));
467 27 wfjm
          write(oline, sv_rxlist(i)(f_byte0));
468 2 wfjm
          writeline(output, oline);
469
        end loop;
470
 
471
      end if;
472
    end procedure checkmiss_rx;
473
 
474 27 wfjm
    procedure do_rx9 (data : in slv9)  is -- ---- do_rx9 -------------
475
    begin
476
      sv_rxlist(sv_nrxlist) := data;
477
      sv_nrxlist := sv_nrxlist + 1;
478
    end procedure do_rx9;
479
 
480
    procedure do_rx8 (data : in slv8)  is -- ---- do_rx8 -------------
481
    begin
482
      if not rxlabo then
483
        do_rx9('0' & data);
484
        rxcrc := crc16_update_tbl(rxcrc, data);
485
      end if;
486
    end procedure do_rx8;
487
 
488
    procedure do_rx16 (data : in slv16)  is -- ---- do_rx16 ----------
489
    begin
490
      do_rx8(data(f_byte0));
491
      do_rx8(data(f_byte1));
492
    end procedure do_rx16;
493
 
494
    procedure do_rxattn is              -- ---- do_rxattn ------------
495
    begin
496
      do_rx9(c_rlink_dat_attn);
497
      rxcrc := (others=>'0');
498
    end procedure do_rxattn;
499
 
500
    procedure do_rxcrc is               -- ---- do_rxcrc -------------
501
    begin
502
      if not rxlabo then
503
        do_rx9('0' & rxcrc(f_byte0));
504
        do_rx9('0' & rxcrc(f_byte1));
505
      end if;
506
    end procedure do_rxcrc;
507
 
508
    procedure do_rxsop is               -- ---- do_rxsop -------------
509
    begin
510
      checkmiss_rx;
511
      sv_nrxlist := 0;
512
      sv_rxind   := 0;
513
      rxcrc      := (others=>'0');
514
      do_rx9(c_rlink_dat_sop);
515
    end procedure do_rxsop;
516
 
517
    procedure do_rxeop is               -- ---- do_rxeop -------------
518
    begin
519
      do_rx9(c_rlink_dat_eop);
520
    end procedure do_rxeop;
521
 
522
    procedure do_rxcs (                 -- ---- do_rxcs ----------
523
      icmd  : in slv8;
524
      istat : in slv8) is
525
    begin
526
      do_rx8(icmd);
527
      do_rx8(istat);
528
      do_rxcrc;
529
    end procedure do_rxcs;
530
 
531
    procedure do_rxcds (                -- ---- do_rxcds ----------
532
      icmd  : in slv8;
533
      idata : in slv16;
534
      istat : in slv8) is
535
    begin
536
      do_rx8(icmd);
537
      do_rx16(idata);
538
      do_rx8(istat);
539
      do_rxcrc;
540
    end procedure do_rxcds;
541
 
542
    procedure do_rxcbs (                -- ---- do_rxcbs ----------
543
      icmd  : in slv8;
544
      ibabo : in slv8;
545
      istat : in slv8) is
546
    begin
547
      do_rx8(icmd);
548
      do_rx8(ibabo);
549
      do_rx8(istat);
550
      do_rxcrc;
551
    end procedure do_rxcbs;
552
 
553
    procedure do_rxrbeg (              -- ---- do_rxrbeg -------------
554
      icmd  : in slv8;
555
      nblk  : in natural) is
556
    begin
557
      do_rx8(icmd);
558
      do_rx16(slv(to_unsigned(nblk,16)));
559
    end procedure do_rxrbeg;
560
 
561
    procedure do_rxrend (              -- ---- do_rxrend -------------
562
      nblk  : in natural;
563
      istat  : in slv8) is
564
    begin
565
      do_rx16(slv(to_unsigned(nblk,16)));
566
      do_rx8(istat);
567
      do_rxcrc;
568
    end procedure do_rxrend;
569
 
570
    procedure do_rxblks (               -- ---- do_rxblks ------------
571
      nblk  : in natural;
572
      start : in slv16) is
573
      variable idata : slv16;
574
    begin
575
      idata := start;
576
      for i in 1 to nblk loop
577
        do_rx16(idata);
578
        idata := slv(unsigned(idata) + 1);
579
      end loop;
580
    end procedure do_rxblks;
581
 
582 2 wfjm
  begin
583 27 wfjm
 
584
    SB_CNTL <= (others=>'0');
585
 
586 2 wfjm
    wait for clock_offset - setup_time;
587
 
588
    file_loop: while not endfile(fstim) loop
589
 
590
      readline (fstim, iline);
591
 
592
      readcomment(iline, ok);
593
      next file_loop when ok;
594
 
595 9 wfjm
      readword(iline, dname, ok);
596
 
597 2 wfjm
      if ok then
598
        case dname is
599
          when ".reset" =>              -- .reset 
600
            write(oline, string'(".reset"));
601
            writeline(output, oline);
602
            RESET <= '1';
603
            wait for clock_period;
604
            RESET <= '0';
605
            wait for 9*clock_period;
606
 
607 9 wfjm
          when ".rlmon" =>              -- .rlmon
608
            read_ea(iline, ien);
609 27 wfjm
            SB_CNTL(sbcntl_sbf_rlmon) <= ien;
610 9 wfjm
            wait for 2*clock_period;      -- wait for monitor to start
611
 
612 27 wfjm
          when ".rlbmo" =>              -- .rlbmo
613
            read_ea(iline, ien);
614
            SB_CNTL(sbcntl_sbf_rlbmon) <= ien;
615
            wait for 2*clock_period;      -- wait for monitor to start
616
 
617 9 wfjm
          when ".rbmon" =>              -- .rbmon
618
            read_ea(iline, ien);
619 27 wfjm
            SB_CNTL(sbcntl_sbf_rbmon) <= ien;
620 9 wfjm
            wait for 2*clock_period;      -- wait for monitor to start
621
 
622 2 wfjm
          when ".wait " =>              -- .wait
623
            read_ea(iline, idelta);
624
            wait for idelta*clock_period;
625
 
626
          when ".iowt " =>              -- .iowt
627
            read_ea(iline, iowait);
628
            idelta := iowait;
629
            while idelta > 0 loop       -- until time has expired
630 27 wfjm
              if TXRXACT = '1' then       -- if any io activity
631
                idelta := iowait;         -- restart timer
632 2 wfjm
              else
633 27 wfjm
                idelta := idelta - 1;     -- otherwise count down time
634 2 wfjm
              end if;
635
              wait for clock_period;
636
            end loop;
637
 
638
          when ".attn " =>              -- .attn
639
            read_ea(iline, iattn);
640 9 wfjm
            RB_LAM_TBENCH <= iattn;       -- pulse attn lines
641
            wait for clock_period;        -- for 1 clock
642
            RB_LAM_TBENCH <= (others=>'0');
643 2 wfjm
 
644 9 wfjm
          when "txsop " =>              -- txsop   send sop
645 27 wfjm
            do_txsop;
646 9 wfjm
          when "txeop " =>              -- txeop   send eop
647 27 wfjm
            do_txeop;
648 9 wfjm
 
649
          when "txnak " =>              -- txnak   send nak
650 27 wfjm
            do_tx9(c_rlink_dat_nak);
651 9 wfjm
          when "txattn" =>              -- txattn  send attn
652 27 wfjm
            do_tx9(c_rlink_dat_attn);
653 9 wfjm
 
654
          when "tx8   " =>              -- tx8     send 8 bit value
655 27 wfjm
            readgen_ea(iline, idat8, 2);
656
            do_tx8(idat8);
657 9 wfjm
          when "tx16  " =>              -- tx16    send 16 bit value
658 27 wfjm
            readgen_ea(iline, idata, 2);
659 2 wfjm
            do_tx16(idata);
660 9 wfjm
 
661 27 wfjm
          when "txblk " =>              -- txblk   send n 16 bit values
662
            read_ea(iline, nblk);
663
            readgen_ea(iline, idata, 2);
664
            do_txblks(nblk, idata);
665
 
666 9 wfjm
          when "txcrc " =>              -- txcrc   send crc  
667 27 wfjm
            do_txcrc;
668
 
669
          when "txbad " =>              -- txbad   send bad crc
670
            do_tx9('0' & (not txcrc(f_byte0)));
671
            do_tx9('0' & (not txcrc(f_byte1)));
672 2 wfjm
 
673 9 wfjm
          when "txc   " =>              -- txc     send: cmd crc
674 27 wfjm
            get_cmd_ea(iline, icmd);
675
            do_txc(icmd);
676 2 wfjm
 
677 9 wfjm
          when "txca  " =>              -- txc     send: cmd addr crc
678 27 wfjm
            get_cmd_ea(iline, icmd);
679
            readgen_ea(iline, iaddr, 2);
680
            do_txca(icmd, iaddr);
681 2 wfjm
 
682 9 wfjm
          when "txcad " =>              -- txc     send: cmd addr data crc
683 27 wfjm
            get_cmd_ea(iline, icmd);
684
            readgen_ea(iline, iaddr, 2);
685
            readgen_ea(iline, idata, 2);
686
            do_txcad(icmd, iaddr, idata);
687 2 wfjm
 
688 9 wfjm
          when "txcac " =>              -- txc     send: cmd addr cnt crc
689 27 wfjm
            get_cmd_ea(iline, icmd);
690
            readgen_ea(iline, iaddr, 2);
691
            readgen_ea(iline, icnt, 2);
692
            do_txcad(icmd, iaddr, icnt);
693 2 wfjm
 
694 9 wfjm
          when "txoof " =>              -- txoof   send out-of-frame symbol
695 27 wfjm
            readgen_ea(iline, txlist(0), 2);
696 9 wfjm
            ntxlist := 1;
697
 
698
          when "rxsop " =>              -- rxsop   expect sop
699 27 wfjm
            do_rxsop;
700 9 wfjm
          when "rxeop " =>              -- rxeop   expect eop
701 27 wfjm
            do_rxeop;
702
 
703 9 wfjm
          when "rxnak " =>              -- rxnak   expect nak
704 27 wfjm
            do_rx9(c_rlink_dat_nak);
705 9 wfjm
          when "rxattn" =>              -- rxattn  expect attn
706 27 wfjm
            do_rxattn;
707 9 wfjm
 
708
          when "rx8   " =>              -- rx8     expect 8 bit value
709 27 wfjm
            readgen_ea(iline, idat8, 2);
710
            do_rx8(idat8);
711 9 wfjm
          when "rx16  " =>              -- rx16    expect 16 bit value
712 27 wfjm
            readgen_ea(iline, idata, 2);
713 2 wfjm
            do_rx16(idata);
714 9 wfjm
 
715 27 wfjm
          when "rxblk " =>              -- rxblk   expect n 16 bit values
716
            read_ea(iline, nblk);
717
            readgen_ea(iline, idata, 2);
718
            do_rxblks(nblk, idata);
719
 
720 9 wfjm
          when "rxcrc " =>              -- rxcrc   expect crc
721 27 wfjm
            do_rxcrc;
722 2 wfjm
 
723 9 wfjm
          when "rxcs  " =>              -- rxcs    expect: cmd stat crc
724 27 wfjm
            get_cmd_ea(iline, icmd);
725
            readgen_ea(iline, istat, 2);
726
            do_rxcs(icmd, istat);
727 2 wfjm
 
728 9 wfjm
          when "rxcds " =>              -- rxcsd   expect: cmd data stat crc
729 27 wfjm
            get_cmd_ea(iline, icmd);
730
            readgen_ea(iline, idata, 2);
731
            readgen_ea(iline, istat, 2);
732
            do_rxcds(icmd, idata, istat);
733 2 wfjm
 
734 27 wfjm
          when "rxcbs " =>              -- rxcsd   expect: cmd babo stat crc
735
            get_cmd_ea(iline, icmd);
736
            readgen_ea(iline, ibabo, 2);
737
            readgen_ea(iline, istat, 2);
738
            do_rxcbs(icmd, ibabo, istat);
739 2 wfjm
 
740 27 wfjm
          when "rxrbeg" =>              -- rxrbeg  expect: cmd - cl ch
741
            get_cmd_ea(iline, icmd);
742
            read_ea(iline, nblk);
743
            do_rxrbeg(icmd, nblk);
744
 
745
          when "rxrend" =>              -- rxrend  expect: dcl dch - stat - crc
746
            read_ea(iline, nblk);
747
            readgen_ea(iline, istat, 2);
748
            do_rxrend(nblk, istat);
749
 
750 9 wfjm
          when "rxoof " =>              -- rxoof   expect: out-of-frame symbol
751 27 wfjm
            readgen_ea(iline, ioof, 2);
752 9 wfjm
            sv_rxlist(sv_nrxlist) := ioof;
753 2 wfjm
            sv_nrxlist := sv_nrxlist + 1;
754
 
755 27 wfjm
          when "anmsg " =>              -- anmsg
756
            readgen_ea(iline, idata, 2);               -- apat
757
            do_rxattn;
758
            do_rx16(idata);
759
            do_rxcrc;
760
            do_rxeop;
761
 
762
          when "sop   " =>              -- sop
763
            do_rxsop;
764
            do_txsop;
765
            rxlabo := false;
766
          when "eop   " =>              -- eop
767
            do_rxeop;
768
            do_txeop;
769
 
770
          when "rreg  " =>              -- rreg   seq  addr  data  stat
771
            get_seq_ea(iline, c_rlink_cmd_rreg, icmd); -- seq
772
            readgen_ea(iline, iaddr, 2);               -- addr
773
            readgen_ea(iline, idata, 2);               -- data
774
            readgen_ea(iline, istat, 2);               -- stat
775
            do_rxcds(icmd, idata, istat);   -- rx: cmd dl sh stat ccsr
776
            do_txca (icmd, iaddr);          -- tx: cmd al ah ccsr
777
 
778
          when "wreg  " =>              -- wreg  seq  addr  data  stat
779
            get_seq_ea(iline, c_rlink_cmd_wreg, icmd); -- seq
780
            readgen_ea(iline, iaddr, 2);               -- addr
781
            readgen_ea(iline, idata, 2);               -- data
782
            readgen_ea(iline, istat, 2);               -- stat
783
            do_rxcs (icmd, istat);          -- rx: cmd stat ccsr
784
            do_txcad(icmd, iaddr, idata);   -- tx: cmd al ah dl dh ccsr
785
 
786
          when "init  " =>              -- init  seq  addr  data  stat
787
            get_seq_ea(iline, c_rlink_cmd_init, icmd); -- seq
788
            readgen_ea(iline, iaddr, 2);               -- addr
789
            readgen_ea(iline, idata, 2);               -- data
790
            readgen_ea(iline, istat, 2);               -- stat
791
            do_rxcs (icmd, istat);          -- rx: cmd stat ccsr
792
            do_txcad(icmd, iaddr, idata);   -- tx: cmd al ah dl dh ccsr
793
 
794
          when "attn  " =>              -- attn  seq  data  stat
795
            get_seq_ea(iline, c_rlink_cmd_attn, icmd); -- seq
796
            readgen_ea(iline, idata, 2);               -- data
797
            readgen_ea(iline, istat, 2);               -- stat
798
            do_rxcds (icmd, idata, istat);  -- rx: cmd dl dh stat ccsr
799
            do_txc   (icmd);                -- tx: cmd ccsr
800
 
801
          when "labo  " =>              -- labo  seq  babo  stat
802
            get_seq_ea(iline, c_rlink_cmd_labo, icmd); -- seq
803
            readgen_ea(iline, ibabo, 2);               -- babo
804
            readgen_ea(iline, istat, 2);               -- stat
805
            do_rxcbs (icmd, ibabo, istat);  -- rx: cmd dl stat ccsr
806
            do_txc   (icmd);                -- tx: cmd ccsr
807
            rxlabo := ibabo /= x"00";       -- set rxlabo flag
808
 
809
          when "rblks " =>              -- rblks seq  addr  nblk  data  stat
810
            get_seq_ea(iline, c_rlink_cmd_rblk, icmd); -- seq
811
            readgen_ea(iline, iaddr, 2);               -- addr
812
            read_ea(iline, nblk);                      -- nblk
813
            readgen_ea(iline, idata, 2);               -- start
814
            readgen_ea(iline, istat, 2);               -- stat
815
            do_rxrbeg(icmd, nblk);                --rx: cmd cl ch
816
            do_rxblks(nblk, idata);               --     nblk*(dl dh)
817
            do_rxrend(nblk, istat);               --     dcl dch stat ccrc
818
            do_txcad(icmd, iaddr,                 -- tx: cmd al ah cl ch ccrc
819
                     slv(to_unsigned(nblk,16)));
820
 
821
          when "wblks " =>              -- wblks seq  addr  nblk  data  stat
822
            get_seq_ea(iline, c_rlink_cmd_wblk, icmd); -- seq
823
            readgen_ea(iline, iaddr, 2);               -- addr
824
            read_ea(iline, nblk);                      -- nblk
825
            readgen_ea(iline, idata, 2);               -- start
826
            readgen_ea(iline, istat, 2);               -- stat
827
            do_rxcds(icmd,                        -- rx: cmd dcl dch stat ccsr
828
                     slv(to_unsigned(nblk,16)),
829
                     istat);
830
            do_txcad(icmd, iaddr,                 -- tx: cmd al ah cl ch ccrc
831
                     slv(to_unsigned(nblk,16)));
832
            do_txblks(nblk, idata);               --     nblk*(dl dh)
833
            do_txcrc;                             --     dcrc
834
 
835
          when "rblkd " =>              -- rblkd seq  addr  ndone  stat 
836
            get_seq_ea(iline, c_rlink_cmd_rblk, icmd); -- seq
837
            readgen_ea(iline, iaddr, 2);               -- addr
838
            read_ea(iline, ndone);                     -- ndone
839
            readgen_ea(iline, istat, 2);               -- stat
840
            do_rxrbeg(icmd, ndatlist);            --rx: cmd cl ch
841
            for i in 0 to ndatlist-1 loop
842
              do_rx16(datlist(i));                --    nblk*(dl dh)
843
            end loop;  -- i
844
            do_rxrend(ndone, istat);              --     dcl dch stat ccrc
845
            do_txcad(icmd, iaddr,                 -- tx: cmd al ah cl ch ccrc
846
                     slv(to_unsigned(ndatlist,16)));
847
 
848
          when "wblkd " =>              -- wblkd seq  addr  ndone  stat
849
            get_seq_ea(iline, c_rlink_cmd_wblk, icmd); -- seq
850
            readgen_ea(iline, iaddr, 2);               -- addr
851
            read_ea(iline, ndone);                     -- ndone
852
            readgen_ea(iline, istat, 2);               -- stat
853
            do_rxcds(icmd,                        -- rx: cmd dcl dch stat ccsr
854
                     slv(to_unsigned(ndone,16)),
855
                     istat);
856
            do_txcad(icmd, iaddr,                 -- tx: cmd al ah cl ch ccrc
857
                     slv(to_unsigned(ndatlist,16)));
858
            for i in 0 to ndatlist-1 loop
859
              do_tx16(datlist(i));                --    nblk*(dl dh)
860
            end loop;  -- i
861
            do_txcrc;                             --     dcrc
862
 
863
          when ".dclr " =>              -- .dclr
864
            ndatlist := 0;
865
 
866
          when ".dwrd " =>              -- .dwrd data
867
            readgen_ea(iline, idata, 2);
868
            datlist(ndatlist) := idata;
869
            ndatlist := ndatlist + 1;
870
 
871
          when ".dseq " =>              -- .dseq nblk start
872
            read_ea(iline, nblk);
873
            readgen_ea(iline, idata, 2);
874
            for i in 1 to nblk loop
875
              datlist(ndatlist) := idata;
876
              ndatlist := ndatlist + 1;
877
              idata := slv(unsigned(idata) + 1);
878
            end loop;
879
 
880 9 wfjm
          when others =>                -- bad command
881
            write(oline, string'("?? unknown command: "));
882 2 wfjm
            write(oline, dname);
883
            writeline(output, oline);
884
            report "aborting" severity failure;
885
        end case;
886
 
887
      else
888 9 wfjm
        report "failed to find command" severity failure;
889 2 wfjm
      end if;
890
 
891 27 wfjm
      testempty_ea(iline);
892 2 wfjm
      next file_loop when ntxlist=0;
893
 
894
      for i in 0 to ntxlist-1 loop
895
 
896 9 wfjm
        RL_DI <= txlist(i);
897
        RL_ENA <= '1';
898 2 wfjm
 
899 17 wfjm
        writetimestamp(oline, CLK_CYCLE, ": stim");
900 27 wfjm
        write(oline, txlist(i)(d_f_cflag), right, 3);
901
        write(oline, txlist(i)(d_f_data), right, 9);
902
        if txlist(i)(d_f_cflag) = '1' then
903 2 wfjm
          case txlist(i) is
904 9 wfjm
            when c_rlink_dat_sop =>
905 2 wfjm
              write(oline, string'(" (sop) "));
906 9 wfjm
            when c_rlink_dat_eop =>
907 2 wfjm
              write(oline, string'(" (eop) "));
908 9 wfjm
            when c_rlink_dat_nak =>
909 2 wfjm
              write(oline, string'(" (nak) "));
910 9 wfjm
            when c_rlink_dat_attn =>
911 2 wfjm
              write(oline, string'(" (attn)"));
912
            when others =>
913
              write(oline, string'(" (????)"));
914
          end case;
915
        end if;
916
        writeline(output, oline);
917
 
918
        wait for clock_period;
919 9 wfjm
        while RL_BUSY = '1' loop
920 2 wfjm
          wait for clock_period;
921
        end loop;
922 9 wfjm
        RL_ENA <= '0';
923 2 wfjm
 
924
      end loop;  -- i
925
 
926
      ntxlist := 0;
927
 
928
    end loop; -- file fstim
929
 
930
    wait for 50*clock_period;
931
 
932
    checkmiss_rx;
933 17 wfjm
    writetimestamp(oline, CLK_CYCLE, ": DONE ");
934 2 wfjm
    writeline(output, oline);
935
 
936
    CLK_STOP <= '1';
937
 
938
    wait;                               -- suspend proc_stim forever
939
                                        -- clock is stopped, sim will end
940
 
941
  end process proc_stim;
942
 
943
 
944
  proc_moni: process
945
    variable oline : line;
946
  begin
947
 
948
    loop
949 13 wfjm
      wait until rising_edge(CLK);
950 2 wfjm
      wait for c2out_time;
951
 
952 9 wfjm
      if RL_VAL = '1' then
953 17 wfjm
        writetimestamp(oline, CLK_CYCLE, ": moni");
954 27 wfjm
        write(oline, RL_DO(d_f_cflag), right, 3);
955
        write(oline, RL_DO(d_f_data), right, 9);
956
        if RL_DO(d_f_cflag) = '1' then
957 9 wfjm
          case RL_DO is
958
            when c_rlink_dat_sop =>
959 2 wfjm
              write(oline, string'(" (sop) "));
960 9 wfjm
            when c_rlink_dat_eop =>
961 2 wfjm
              write(oline, string'(" (eop) "));
962 9 wfjm
            when c_rlink_dat_nak =>
963 2 wfjm
              write(oline, string'(" (nak) "));
964 9 wfjm
            when c_rlink_dat_attn =>
965 2 wfjm
              write(oline, string'(" (attn)"));
966
            when others =>
967
              write(oline, string'(" (????)"));
968
          end case;
969
        end if;
970
        if sv_nrxlist > 0 then
971
          write(oline, string'("  CHECK"));
972
          if sv_rxind < sv_nrxlist then
973 9 wfjm
            if RL_DO = sv_rxlist(sv_rxind) then
974 2 wfjm
              write(oline, string'(" OK"));
975
            else
976
              write(oline, string'(" FAIL, exp="));
977 27 wfjm
              write(oline, sv_rxlist(sv_rxind)(d_f_cflag), right, 2);
978
              write(oline, sv_rxlist(sv_rxind)(d_f_data),  right, 9);
979 2 wfjm
            end if;
980
            sv_rxind := sv_rxind + 1;
981
          else
982
            write(oline, string'(" FAIL, UNEXPECTED"));
983
          end if;
984
        end if;
985
        writeline(output, oline);
986
      end if;
987
 
988
    end loop;
989
 
990
  end process proc_moni;
991
 
992
end sim;

powered by: WebSVN 2.1.0

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