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 27

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

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

powered by: WebSVN 2.1.0

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