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

Subversion Repositories w11

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 17 wfjm
-- $Id: simlib.vhd 444 2011-12-25 10:04:58Z mueller $
2 2 wfjm
--
3 13 wfjm
-- Copyright 2006-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:    simlib - sim
16
-- Description:    Support routines for test benches
17
--
18
-- Dependencies:   -
19
-- Test bench:     -
20
-- Target Devices: generic
21 13 wfjm
-- Tool versions:  xst 8.2, 9.1, 9.2, 12.1, 13.1; ghdl 0.18-0.29
22 8 wfjm
--
23 2 wfjm
-- Revision History: 
24
-- Date         Rev Version  Comment
25 17 wfjm
-- 2011-12-23   444   2.0    drop CLK_CYCLE from simclk,simclkv; use integer for
26
--                           simclkcnt(CLK_CYCLE),writetimestamp(clkcyc);
27 13 wfjm
-- 2011-11-18   427   1.3.8  now numeric_std clean
28 9 wfjm
-- 2010-12-22   346   1.3.7  rename readcommand -> readdotcomm
29 8 wfjm
-- 2010-11-13   338   1.3.6  add simclkcnt; xx.x ns time in writetimestamp()
30 2 wfjm
-- 2008-03-24   129   1.3.5  CLK_CYCLE now 31 bits
31
-- 2008-03-02   121   1.3.4  added readempty (to discard rest of line)
32
-- 2007-12-27   106   1.3.3  added simclk2v
33
-- 2007-12-15   101   1.3.2  add read_ea(time), readtagval[_ea](std_logic)
34
-- 2007-10-12    88   1.3.1  avoid ieee.std_logic_unsigned, use cast to unsigned
35
-- 2007-08-28    76   1.3    added writehex and writegen
36
-- 2007-08-10    72   1.2.2  remove entity simclk, put into separate source
37
-- 2007-08-03    71   1.2.1  readgen, readtagval, readtagval2: add base arg
38
-- 2007-07-29    70   1.2    readtagval2: add tag=- support; add readword_ea,
39
--                           readoptchar, writetimestamp
40
-- 2007-07-28    69   1.1.1  rename readrest -> testempty; add readgen
41
--                           use readgen in readtagval() and readtagval2()
42
-- 2007-07-22    68   1.1    add readrest, readtagval, readtagval2
43
-- 2007-06-30    62   1.0.1  remove clock_period ect constant defs
44
-- 2007-06-14    56   1.0    Initial version (renamed from pdp11_sim.vhd)
45
------------------------------------------------------------------------------
46
 
47
library ieee;
48
use ieee.std_logic_1164.all;
49 13 wfjm
use ieee.numeric_std.all;
50 2 wfjm
use ieee.std_logic_textio.all;
51
use std.textio.all;
52
 
53
use work.slvtypes.all;
54
 
55
package simlib is
56
 
57
constant null_char : character := character'val(0);            -- '\0'
58
constant null_string : string(1 to 1) := (others=>null_char);  -- "\0"
59
 
60
procedure readwhite(                    -- read over white space
61
  L: inout line);                       -- line
62
 
63
procedure readoct(                      -- read slv in octal base (arb. length)
64
  L: inout line;                        -- line
65
  value: out std_logic_vector;          -- value to be read
66
  good: out boolean);                   -- success flag
67
 
68
procedure readhex(                      -- read slv in hex base (arb. length)
69
  L: inout line;                        -- line
70
  value: out std_logic_vector;          -- value to be read
71
  good: out boolean);                   -- success flag
72
 
73
procedure readgen(                      -- read slv generic base
74
  L: inout line;                        -- line
75
  value: out std_logic_vector;          -- value to be read
76
  good: out boolean;                    -- success flag
77
  base: in integer:= 2);                -- default base
78
 
79
procedure readcomment(
80
  L: inout line;
81
  good: out boolean);
82
 
83 9 wfjm
procedure readdotcomm(
84 2 wfjm
  L: inout line;
85
  name: out string;
86
  good: out boolean);
87
 
88
procedure readword(
89
  L: inout line;
90
  name: out string;
91
  good: out boolean);
92
 
93
procedure readoptchar(
94
  L: inout line;
95
  char: in character;
96
  good: out boolean);
97
 
98
procedure readempty(
99
  L: inout line);
100
 
101
procedure testempty(
102
  L: inout line;
103
  good: out boolean);
104
 
105
procedure testempty_ea(
106
  L: inout line);
107
 
108
procedure read_ea(
109
  L: inout line;
110
  value: out integer);
111
procedure read_ea(
112
  L: inout line;
113
  value: out time);
114
 
115
procedure read_ea(
116
  L: inout line;
117
  value: out std_logic);
118
procedure read_ea(
119
  L: inout line;
120
  value: out std_logic_vector);
121
 
122
procedure readoct_ea(
123
  L: inout line;
124
  value: out std_logic_vector);
125
 
126
procedure readhex_ea(
127
  L: inout line;
128
  value: out std_logic_vector);
129
 
130
procedure readgen_ea(
131
  L: inout line;
132
  value: out std_logic_vector;
133
  base: in integer:= 2);
134
 
135
procedure readword_ea(
136
  L: inout line;
137
  name: out string);
138
 
139
procedure readtagval(
140
  L: inout line;
141
  tag: in string;
142
  match: out boolean;
143
  val: out std_logic_vector;
144
  good: out boolean;
145
  base: in integer:= 2);
146
procedure readtagval_ea(
147
  L: inout line;
148
  tag: in string;
149
  match: out boolean;
150
  val: out std_logic_vector;
151
  base: in integer:= 2);
152
 
153
procedure readtagval(
154
  L: inout line;
155
  tag: in string;
156
  match: out boolean;
157
  val: out std_logic;
158
  good: out boolean);
159
procedure readtagval_ea(
160
  L: inout line;
161
  tag: in string;
162
  match: out boolean;
163
  val: out std_logic);
164
 
165
procedure readtagval2(
166
  L: inout line;
167
  tag: in string;
168
  match: out boolean;
169
  val1: out std_logic_vector;
170
  val2: out std_logic_vector;
171
  good: out boolean;
172
  base: in integer:= 2);
173
procedure readtagval2_ea(
174
  L: inout line;
175
  tag: in string;
176
  match: out boolean;
177
  val1: out std_logic_vector;
178
  val2: out std_logic_vector;
179
  base: in integer:= 2);
180
 
181
procedure writeoct(                     -- write slv in octal base (arb. length)
182
  L: inout line;                        -- line
183
  value: in std_logic_vector;           -- value to be written
184
  justified: in side:=right;            -- justification (left/right)
185
  field: in width:=0);                  -- field width
186
 
187
procedure writehex(                     -- write slv in hex base (arb. length)
188
  L: inout line;                        -- line
189
  value: in std_logic_vector;           -- value to be written
190
  justified: in side:=right;            -- justification (left/right)
191
  field: in width:=0);                  -- field width
192
 
193
procedure writegen(                     -- write slv in generic base (arb. lth)
194
  L: inout line;                        -- line
195
  value: in std_logic_vector;           -- value to be written
196
  justified: in side:=right;            -- justification (left/right)
197
  field: in width:=0;                   -- field width
198
  base: in integer:= 2);                -- default base
199
 
200
procedure writetimestamp(
201
  L: inout line;
202 17 wfjm
  clkcyc: in integer;
203 2 wfjm
  str : in string := null_string);
204
 
205
-- ----------------------------------------------------------------------------
206
 
207
component simclk is                   -- test bench clock generator
208
  generic (
209
    PERIOD : time := 20 ns;           -- clock period
210
    OFFSET : time := 200 ns);         -- clock offset (first up transition)
211
  port (
212
    CLK  : out slbit;                 -- clock
213
    CLK_STOP : in slbit               -- clock stop trigger
214
  );
215
end component;
216
 
217
component simclkv is                  -- test bench clock generator
218
                                      --  with variable periods
219
  port (
220
    CLK  : out slbit;                 -- clock
221
    CLK_PERIOD : in time;             -- clock period
222
    CLK_HOLD : in slbit;              -- if 1, hold clocks in 0 state
223
    CLK_STOP : in slbit               -- clock stop trigger
224
  );
225
end component;
226
 
227 8 wfjm
component simclkcnt is                -- test bench system clock cycle counter
228
  port (
229
    CLK  : in slbit;                  -- clock
230 17 wfjm
    CLK_CYCLE  : out integer          -- clock cycle number
231 8 wfjm
  );
232
end component;
233
 
234 2 wfjm
end package simlib;
235
 
236
-- ----------------------------------------------------------------------------
237
 
238
package body simlib is
239
 
240
procedure readwhite(                  -- read over white space
241
  L: inout line) is                   -- line
242
  variable ch : character;
243
begin
244
  while L'length>0 loop
245
    ch := L(L'left);
246
    exit when (ch/=' ' and ch/=HT);
247
    read(L,ch);
248
  end loop;
249
 
250
end procedure readwhite;
251
 
252
-- -------------------------------------
253
 
254
procedure readoct(                      -- read slv in octal base (arb. length)
255
  L: inout line;                        -- line 
256
  value: out std_logic_vector;          -- value to be read
257
  good: out boolean) is                 -- success flag
258
 
259
  variable nibble : std_logic_vector(2 downto 0);
260
  variable sum : std_logic_vector(31 downto 0);
261
  variable ndig : integer;              -- number of digits
262
  variable ok : boolean;
263
  variable ichar : character;
264
 
265
begin
266
 
267
  assert not value'ascending(1)
268
    report "readoct called with ascending range"
269
    severity failure;
270
  assert value'length<=32
271
    report "readoct called with value'length > 32"
272
    severity failure;
273
 
274
  readwhite(L);
275
 
276
  ndig := 0;
277
  sum := (others=>'U');
278
 
279
  while L'length>0 loop
280
    ok := true;
281
    case L(L'left) is
282
      when '0' => nibble := "000";
283
      when '1' => nibble := "001";
284
      when '2' => nibble := "010";
285
      when '3' => nibble := "011";
286
      when '4' => nibble := "100";
287
      when '5' => nibble := "101";
288
      when '6' => nibble := "110";
289
      when '7' => nibble := "111";
290
      when 'u'|'U' => nibble := "UUU";
291
      when 'x'|'X' => nibble := "XXX";
292
      when 'z'|'Z' => nibble := "ZZZ";
293
      when '-' => nibble := "---";
294
      when others => ok := false;
295
    end case;
296
 
297
    exit when not ok;
298
    read(L,ichar);
299
    ndig := ndig + 1;
300
    sum(sum'left downto 3) := sum(sum'left-3 downto 0);
301
    sum(2 downto 0) := nibble;
302
  end loop;
303
 
304
  ok := ndig>0;
305
  value := sum(value'range);
306
  good := ok;
307
 
308
end procedure readoct;
309
 
310
-- -------------------------------------
311
 
312
procedure readhex(                      -- read slv in hex base (arb. length)
313
  L: inout line;                        -- line
314
  value: out std_logic_vector;          -- value to be read
315
  good: out boolean) is                 -- success flag
316
 
317
  variable nibble : std_logic_vector(3 downto 0);
318
  variable sum : std_logic_vector(31 downto 0);
319
  variable ndig : integer;              -- number of digits
320
  variable ok : boolean;
321
  variable ichar : character;
322
 
323
begin
324
 
325
  assert not value'ascending(1)
326
    report "readhex called with ascending range"
327
    severity failure;
328
  assert value'length<=32
329
    report "readhex called with value'length > 32"
330
    severity failure;
331
 
332
  readwhite(L);
333
 
334
  ndig := 0;
335
  sum := (others=>'U');
336
 
337
  while L'length>0 loop
338
    ok := true;
339
    case L(L'left) is
340
      when '0'     => nibble := "0000";
341
      when '1'     => nibble := "0001";
342
      when '2'     => nibble := "0010";
343
      when '3'     => nibble := "0011";
344
      when '4'     => nibble := "0100";
345
      when '5'     => nibble := "0101";
346
      when '6'     => nibble := "0110";
347
      when '7'     => nibble := "0111";
348
      when '8'     => nibble := "1000";
349
      when '9'     => nibble := "1001";
350
      when 'a'|'A' => nibble := "1010";
351
      when 'b'|'B' => nibble := "1011";
352
      when 'c'|'C' => nibble := "1100";
353
      when 'd'|'D' => nibble := "1101";
354
      when 'e'|'E' => nibble := "1110";
355
      when 'f'|'F' => nibble := "1111";
356
      when 'u'|'U' => nibble := "UUUU";
357
      when 'x'|'X' => nibble := "XXXX";
358
      when 'z'|'Z' => nibble := "ZZZZ";
359
      when '-'     => nibble := "----";
360
      when others  => ok := false;
361
    end case;
362
 
363
    exit when not ok;
364
    read(L,ichar);
365
    ndig := ndig + 1;
366
    sum(sum'left downto 4) := sum(sum'left-4 downto 0);
367
    sum(3 downto 0) := nibble;
368
  end loop;
369
 
370
  ok := ndig>0;
371
  value := sum(value'range);
372
  good := ok;
373
 
374
end procedure readhex;
375
 
376
-- -------------------------------------
377
 
378
procedure readgen(                    -- read slv generic base
379 13 wfjm
  L: inout line;                      -- line
380
  value: out std_logic_vector;        -- value to be read
381
  good: out boolean;                  -- success flag
382
  base: in integer := 2) is           -- default base
383 2 wfjm
 
384
  variable nibble : std_logic_vector(3 downto 0);
385
  variable sum : std_logic_vector(31 downto 0);
386
  variable lbase : integer;           -- local base
387
  variable cbase : integer;           -- current base
388
  variable ok : boolean;
389
  variable ivalue : integer;
390
  variable ichar : character;
391 13 wfjm
 
392 2 wfjm
begin
393
 
394
  assert not value'ascending(1)
395
    report "readgen called with ascending range"
396
    severity failure;
397
  assert value'length<=32
398
    report "readgen called with value'length > 32"
399
    severity failure;
400
  assert base=2 or base=8 or base=10 or base=16
401
    report "readgen base not 2,8,10, or 16"
402
    severity failure;
403
 
404
  readwhite(L);
405
 
406
  cbase := base;
407
  lbase := 0;
408
  ok := true;
409
 
410
  if L'length >= 2 then
411
    if L(L'left+1) = '"' then
412
      case L(L'left) is
413
        when 'b'|'B' => lbase :=  2;
414
        when 'o'|'O' => lbase :=  8;
415
        when 'd'|'D' => lbase := 10;
416
        when 'x'|'X' => lbase := 16;
417
        when others => ok := false;
418
      end case;
419
    end if;
420
    if lbase /= 0 then
421
      read(L, ichar);
422
      read(L, ichar);
423
      cbase := lbase;
424
    end if;
425
  end if;
426
 
427
  if ok then
428
    case cbase is
429
      when  2 => read(L, value, ok);
430
      when  8 => readoct(L, value, ok);
431
      when 16 => readhex(L, value, ok);
432
      when 10 =>
433
        read(L, ivalue, ok);
434 13 wfjm
        -- the following if allows to enter negative integers, e.g. -1 for all-1
435
        if ivalue >= 0 then
436
          value := slv(to_unsigned(ivalue, value'length));
437
        else
438
          value := slv(to_signed(ivalue, value'length));
439
        end if;
440 2 wfjm
      when others => null;
441
    end case;
442
  end if;
443
 
444
  if ok and lbase/=0 then
445
    if L'length>0 and  L(L'left)='"' then
446
      read(L, ichar);
447
    else
448
      ok := false;
449
    end if;
450
  end if;
451
 
452
  good := ok;
453
 
454
end procedure readgen;
455
 
456
-- -------------------------------------
457
 
458
procedure readcomment(
459
  L: inout line;
460
  good: out boolean) is
461
  variable ichar : character;
462
begin
463
 
464
  readwhite(L);
465
 
466
  good := true;
467
  if L'length > 0 then
468
    good := false;
469
    if L(L'left) = '#' then
470
      good := true;
471
    elsif L(L'left) = 'C' then
472
      good := true;
473
      writeline(output, L);
474
    end if;
475
  end if;
476
 
477
end procedure readcomment;
478
 
479
-- -------------------------------------
480
 
481 9 wfjm
procedure readdotcomm(
482 2 wfjm
  L: inout line;
483
  name: out string;
484
  good: out boolean) is
485
begin
486
 
487
  for i in name'range loop
488
    name(i) := ' ';
489
  end loop;
490
  good := false;
491
 
492
  if L'length>0 and L(L'left)='.' then
493
    readword(L, name, good);
494
  end if;
495
 
496 9 wfjm
end procedure readdotcomm;
497 2 wfjm
 
498
-- -------------------------------------
499
 
500
procedure readword(
501
  L: inout line;
502
  name: out string;
503
  good: out boolean) is
504
 
505
  variable ichar : character;
506
  variable ind : integer;
507
 
508
begin
509
 
510
  assert name'ascending(1)
511
    report "readword called with descending range for name"
512
    severity failure;
513
 
514
  readwhite(L);
515
 
516
  for i in name'range loop
517
    name(i) := ' ';
518
  end loop;
519
  ind := name'left;
520
 
521
  while L'length>0 and ind<=name'right loop
522
    ichar := L(L'left);
523
    exit when ichar=' ' or ichar=',' or ichar='|';
524
    read(L,ichar);
525
    name(ind) := ichar;
526
    ind := ind + 1;
527
  end loop;
528
 
529
  good := ind /= name'left;             -- ok if one non-blank found
530
 
531
end procedure readword;
532
 
533
-- -------------------------------------
534
 
535
procedure readoptchar(
536
  L: inout line;
537
  char: in character;
538
  good: out boolean) is
539
 
540
  variable ichar : character;
541
 
542
begin
543
 
544
  good := false;
545
  if L'length > 0 then
546
    if L(L'left) = char then
547
      read(L, ichar);
548
      good := true;
549
    end if;
550
  end if;
551
 
552
end procedure readoptchar;
553
 
554
-- -------------------------------------
555
 
556
procedure readempty(
557
  L: inout line) is
558
 
559
  variable ch : character;
560
 
561
begin
562
 
563
  while L'length>0 loop               -- anything left ?
564
    read(L,ch);                         -- read and discard it
565
  end loop;
566
 
567
end procedure readempty;
568
 
569
-- -------------------------------------
570
 
571
procedure testempty(
572
  L: inout line;
573
  good: out boolean) is
574
 
575
begin
576
 
577
  readwhite(L);                       -- discard white space
578
  good := true;                       -- good if now empty
579
 
580
  if L'length > 0 then                -- anything left ?
581
    good := false;                    -- assume bad
582
    if L'length >= 2 and              -- check for "--"
583
      L(L'left)='-' and L(L'left+1)='-' then
584
      good := true;                   -- in that case comment -> good
585
    end if;
586
  end if;
587
 
588
end procedure testempty;
589
 
590
-- -------------------------------------
591
 
592
procedure testempty_ea(
593
  L: inout line) is
594
 
595
  variable ok : boolean := false;
596
 
597
begin
598
 
599
  testempty(L, ok);
600
  assert ok report "extra chars in """ & L.all & """" severity failure;
601
 
602
end procedure testempty_ea;
603
 
604
-- -------------------------------------
605
 
606
procedure read_ea(
607
  L: inout line;
608
  value: out integer) is
609
 
610
  variable ok : boolean := false;
611
 
612
begin
613
 
614
  read(L, value, ok);
615
  assert ok report "read(integer) conversion error in """ &
616
                   L.all & """" severity failure;
617
 
618
end procedure read_ea;
619
 
620
-- -------------------------------------
621
 
622
procedure read_ea(
623
  L: inout line;
624
  value: out time) is
625
 
626
  variable ok : boolean := false;
627
 
628
begin
629
 
630
  read(L, value, ok);
631
  assert ok report "read(time) conversion error in """ &
632
                   L.all & """" severity failure;
633
 
634
end procedure read_ea;
635
 
636
-- -------------------------------------
637
 
638
procedure read_ea(
639
  L: inout line;
640
  value: out std_logic) is
641
 
642
  variable ok : boolean := false;
643
 
644
begin
645
 
646
  read(L, value, ok);
647
  assert ok report "read(std_logic) conversion error in """ &
648
                   L.all & """" severity failure;
649
 
650
end procedure read_ea;
651
 
652
-- -------------------------------------
653
 
654
procedure read_ea(
655
  L: inout line;
656
  value: out std_logic_vector) is
657
 
658
  variable ok : boolean := false;
659
 
660
begin
661
 
662
  read(L, value, ok);
663
  assert ok report "read(std_logic_vector) conversion error in """ &
664
                   L.all & """" severity failure;
665
 
666
end procedure read_ea;
667
 
668
-- -------------------------------------
669
 
670
procedure readoct_ea(
671
  L: inout line;
672
  value: out std_logic_vector) is
673
 
674
  variable ok : boolean := false;
675
 
676
begin
677
 
678
  readoct(L, value, ok);
679
  assert ok report "readoct() conversion error in """ &
680
                   L.all & """" severity failure;
681
 
682
end procedure readoct_ea;
683
 
684
-- -------------------------------------
685
 
686
procedure readhex_ea(
687
  L: inout line;
688
  value: out std_logic_vector) is
689
 
690
  variable ok : boolean := false;
691
 
692
begin
693
 
694
  readhex(L, value, ok);
695
  assert ok report "readhex() conversion error in """ &
696
                   L.all & """" severity failure;
697
 
698
end procedure readhex_ea;
699
 
700
-- -------------------------------------
701
 
702
procedure readgen_ea(
703
  L: inout line;
704
  value: out std_logic_vector;
705
  base: in integer := 2) is
706
 
707
  variable ok : boolean := false;
708
 
709
begin
710
 
711
  readgen(L, value, ok, base);
712
  assert ok report "readgen() conversion error in """ &
713
                   L.all & """" severity failure;
714
 
715
end procedure readgen_ea;
716
 
717
-- -------------------------------------
718
 
719
procedure readword_ea(
720
  L: inout line;
721
  name: out string) is
722
 
723
  variable ok : boolean := false;
724
 
725
begin
726
 
727
  readword(L, name, ok);
728
  assert ok report "readword() read error in """ &
729
                   L.all & """" severity failure;
730
 
731
end procedure readword_ea;
732
 
733
-- -------------------------------------
734
 
735
procedure readtagval(
736
  L: inout line;
737
  tag: in string;
738
  match: out boolean;
739
  val: out std_logic_vector;
740
  good: out boolean;
741
  base: in integer:= 2) is
742
 
743
  variable itag : string(tag'range);
744
  variable ichar : character;
745
  variable imatch : boolean;
746
 
747
begin
748
 
749
  readwhite(L);
750
 
751
  for i in val'range loop
752
    val(i) := '0';
753
  end loop;
754
  good := true;
755
  imatch := false;
756
 
757
  if L'length > tag'length then
758
    imatch := L(L'left to L'left+tag'length-1) = tag and
759
              L(L'left+tag'length) = '=';
760
    if imatch then
761
      read(L, itag);
762
      read(L, ichar);
763
      readgen(L, val, good, base);
764
    end if;
765
  end if;
766
  match := imatch;
767
 
768
end procedure readtagval;
769
 
770
-- -------------------------------------
771
 
772
procedure readtagval_ea(
773
  L: inout line;
774
  tag: in string;
775
  match: out boolean;
776
  val: out std_logic_vector;
777
  base: in integer:= 2) is
778
 
779
  variable ok : boolean := false;
780
 
781
begin
782
  readtagval(L, tag, match, val, ok, base);
783
  assert ok report "readtagval(std_logic_vector) conversion error in """ &
784
                   L.all & """" severity failure;
785
end procedure readtagval_ea;
786
 
787
-- -------------------------------------
788
 
789
procedure readtagval(
790
  L: inout line;
791
  tag: in string;
792
  match: out boolean;
793
  val: out std_logic;
794
  good: out boolean) is
795
 
796
  variable itag : string(tag'range);
797
  variable ichar : character;
798
  variable imatch : boolean;
799
 
800
begin
801
 
802
  readwhite(L);
803
 
804
  val := '0';
805
  good := true;
806
  imatch := false;
807
 
808
  if L'length > tag'length then
809
    imatch := L(L'left to L'left+tag'length-1) = tag and
810
              L(L'left+tag'length) = '=';
811
    if imatch then
812
      read(L, itag);
813
      read(L, ichar);
814
      read(L, val, good);
815
    end if;
816
  end if;
817
  match := imatch;
818
 
819
end procedure readtagval;
820
 
821
-- -------------------------------------
822
 
823
procedure readtagval_ea(
824
  L: inout line;
825
  tag: in string;
826
  match: out boolean;
827
  val: out std_logic) is
828
 
829
  variable ok : boolean := false;
830
 
831
begin
832
  readtagval(L, tag, match, val, ok);
833
  assert ok report "readtagval(std_logic) conversion error in """ &
834
                   L.all & """" severity failure;
835
end procedure readtagval_ea;
836
 
837
-- -------------------------------------
838
 
839
procedure readtagval2(
840
  L: inout line;
841
  tag: in string;
842
  match: out boolean;
843
  val1: out std_logic_vector;
844
  val2: out std_logic_vector;
845
  good: out boolean;
846
  base: in integer:= 2) is
847
 
848
  variable itag : string(tag'range);
849
  variable imatch : boolean;
850
  variable igood : boolean;
851
  variable ichar : character;
852
  variable ok : boolean;
853
 
854
begin
855
 
856
  readwhite(L);
857
 
858
  for i in val1'range loop            -- zero val1
859
    val1(i) := '0';
860
  end loop;
861
  for i in val2'range loop            -- zero val2
862
    val2(i) := '0';
863
  end loop;
864
  igood := true;
865
  imatch := false;
866
 
867
  if L'length > tag'length then       -- check for tag
868
    imatch := L(L'left to L'left+tag'length-1) = tag and
869
              L(L'left+tag'length) = '=';
870
 
871
    if imatch then                      -- if found
872
      read(L, itag);                    -- remove tag
873
      read(L, ichar);                   -- remove =
874
 
875
      igood := false;
876
      readoptchar(L, '-', ok);          -- check for tag=-
877
      if ok then
878
        for i in val2'range loop        -- set mask to all 1 (ignore)
879
          val2(i) := '1';
880
        end loop;
881
        igood := true;
882
      else                              -- here if tag=bit[,bit]
883
        readgen(L, val1, igood, base);  -- read val1
884
        if igood then
885
          readoptchar(L, ',', ok);      -- check(and remove) ,
886
          if ok then
887
            readgen(L, val2, igood, base); -- and read val2
888
          end if;
889
        end if;
890
      end if;
891
    end if;
892
  end if;
893
 
894
  match := imatch;
895
  good := igood;
896
 
897
end procedure readtagval2;
898
 
899
-- -------------------------------------
900
 
901
procedure readtagval2_ea(
902
  L: inout line;
903
  tag: in string;
904
  match: out boolean;
905
  val1: out std_logic_vector;
906
  val2: out std_logic_vector;
907
  base: in integer:= 2) is
908
 
909
  variable ok : boolean := false;
910
 
911
begin
912
  readtagval2(L, tag, match, val1, val2, ok, base);
913
  assert ok report "readtagval2() conversion error in """ &
914
                   L.all & """" severity failure;
915
end procedure readtagval2_ea;
916
 
917
-- -------------------------------------
918
 
919
procedure writeoct(                     -- write slv in octal base (arb. length)
920
  L: inout line;                        -- line
921
  value: in std_logic_vector;           -- value to be written
922
  justified: in side:=right;            -- justification (left/right)
923
  field: in width:=0) is                -- field width
924
 
925
  variable nbit : integer;              -- number of bits
926
  variable ndig : integer;              -- number of digits
927
  variable iwidth : integer;
928
  variable ioffset : integer;
929
  variable nibble : std_logic_vector(2 downto 0);
930
  variable ochar : character;
931
 
932
begin
933
 
934
  assert not value'ascending(1)
935
    report "writeoct called with ascending range"
936
    severity failure;
937
 
938
  nbit := value'length(1);
939
  ndig := (nbit+2)/3;
940
  iwidth := nbit mod 3;
941
  if iwidth = 0 then
942
    iwidth := 3;
943
  end if;
944
  ioffset := value'left(1) - iwidth+1;
945
  if justified=right and field>ndig then
946
    for i in ndig+1 to field loop
947
      write(L,' ');
948
    end loop;  -- i
949
  end if;
950
  for i in 0 to ndig-1 loop
951
    nibble := "000";
952
    nibble(iwidth-1 downto 0) := value(ioffset+iwidth-1 downto ioffset);
953
    ochar := ' ';
954
    for i in nibble'range loop
955
      case nibble(i) is
956
        when 'U' => ochar := 'U';
957
        when 'X' => ochar := 'X';
958
        when 'Z' => ochar := 'Z';
959
        when '-' => ochar := '-';
960
        when others => null;
961
      end case;
962
    end loop;  -- i
963
    if ochar = ' ' then
964 13 wfjm
      write(L,to_integer(unsigned(nibble)));
965 2 wfjm
    else
966
      write(L,ochar);
967
    end if;
968
    iwidth := 3;
969
    ioffset := ioffset - 3;
970
  end loop;  -- i
971
  if justified=left and field>ndig then
972
    for i in ndig+1 to field loop
973
      write(L,' ');
974
    end loop;  -- i
975
  end if;
976
end procedure writeoct;
977
 
978
-- -------------------------------------
979
 
980
procedure writehex(                     -- write slv in hex base (arb. length)
981
  L: inout line;                        -- line
982
  value: in std_logic_vector;           -- value to be written
983
  justified: in side:=right;            -- justification (left/right)
984
  field: in width:=0) is                -- field width
985
 
986
  variable nbit : integer;              -- number of bits
987
  variable ndig : integer;              -- number of digits
988
  variable iwidth : integer;
989
  variable ioffset : integer;
990
  variable nibble : std_logic_vector(3 downto 0);
991
  variable ochar : character;
992
  variable hextab : string(1 to 16) := "0123456789abcdef";
993
 
994
begin
995
 
996
  assert not value'ascending(1)
997
    report "writehex called with ascending range"
998
    severity failure;
999
 
1000
  nbit := value'length(1);
1001
  ndig := (nbit+3)/4;
1002
  iwidth := nbit mod 4;
1003
  if iwidth = 0 then
1004
    iwidth := 4;
1005
  end if;
1006
  ioffset := value'left(1) - iwidth+1;
1007
  if justified=right and field>ndig then
1008
    for i in ndig+1 to field loop
1009
      write(L,' ');
1010
    end loop;  -- i
1011
  end if;
1012
  for i in 0 to ndig-1 loop
1013
    nibble := "0000";
1014
    nibble(iwidth-1 downto 0) := value(ioffset+iwidth-1 downto ioffset);
1015
    ochar := ' ';
1016
    for i in nibble'range loop
1017
      case nibble(i) is
1018
        when 'U' => ochar := 'U';
1019
        when 'X' => ochar := 'X';
1020
        when 'Z' => ochar := 'Z';
1021
        when '-' => ochar := '-';
1022
        when others => null;
1023
      end case;
1024
    end loop;  -- i
1025
    if ochar = ' ' then
1026 13 wfjm
      write(L,hextab(to_integer(unsigned(nibble))+1));
1027 2 wfjm
    else
1028
      write(L,ochar);
1029
    end if;
1030
    iwidth := 4;
1031
    ioffset := ioffset - 4;
1032
  end loop;  -- i
1033
  if justified=left and field>ndig then
1034
    for i in ndig+1 to field loop
1035
      write(L,' ');
1036
    end loop;  -- i
1037
  end if;
1038
end procedure writehex;
1039
 
1040
-- -------------------------------------
1041
 
1042
procedure writegen(                     -- write slv in generic base (arb. lth)
1043
  L: inout line;                        -- line
1044
  value: in std_logic_vector;           -- value to be written
1045
  justified: in side:=right;            -- justification (left/right)
1046
  field: in width:=0;                   -- field width
1047
  base: in integer:=2) is               -- default base
1048
 
1049
begin
1050
 
1051
  case base is
1052
    when  2 => write(L, value, justified, field);
1053
    when  8 => writeoct(L, value, justified, field);
1054
    when 16 => writehex(L, value, justified, field);
1055
    when others => report "writegen base not 2,8, or 16"
1056
                     severity failure;
1057
  end case;
1058
 
1059
end procedure writegen;
1060
 
1061
-- -------------------------------------
1062
 
1063
procedure writetimestamp(
1064
  L: inout line;
1065 17 wfjm
  clkcyc: in integer;
1066 2 wfjm
  str: in string := null_string) is
1067
 
1068 8 wfjm
  variable t_nsec  : integer := 0;
1069
  variable t_psec  : integer := 0;
1070
  variable t_dnsec : integer := 0;
1071
 
1072 2 wfjm
begin
1073
 
1074 8 wfjm
  t_nsec  := now / 1 ns;
1075
  t_psec  := (now - t_nsec * 1 ns) / 1 ps;
1076
  t_dnsec := t_psec/100;
1077
 
1078
  -- write(L, now, right, 12);
1079
  write(L, t_nsec, right, 8);
1080
  write(L,'.');
1081
  write(L, t_dnsec, right, 1);
1082
  write(L, string'(" ns"));
1083
 
1084 17 wfjm
  write(L, clkcyc, right, 7);
1085 2 wfjm
  if str /= null_string then
1086
    write(L, str);
1087
  end if;
1088
 
1089
end procedure writetimestamp;
1090
 
1091
end package body simlib;
1092
 

powered by: WebSVN 2.1.0

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