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

Subversion Repositories pltbutils

[/] [pltbutils/] [trunk/] [src/] [vhdl/] [pltbutils_func_pkg.vhd] - Blame information for rev 6

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

Line No. Rev Author Line
1 2 pela
----------------------------------------------------------------------
2
----                                                              ----
3
---- PlTbUtils Fuctions and Procedures Package                    ----
4
----                                                              ----
5
---- This file is part of the PlTbUtils project                   ----
6
---- http://opencores.org/project,pltbutils                       ----
7
----                                                              ----
8
---- Description:                                                 ----
9
---- PlTbUtils is a collection of functions, procedures and       ----
10
---- components for easily creating stimuli and checking response ----
11
---- in automatic self-checking testbenches.                      ----
12
----                                                              ----
13
---- This file defines fuctions and procedures for controlling    ----
14
---- stimuli to a DUT and checking response.                      ----
15
----                                                              ----
16
---- To Do:                                                       ----
17
---- -                                                            ----
18
----                                                              ----
19
---- Author(s):                                                   ----
20
---- - Per Larsson, pela@opencores.org                            ----
21
----                                                              ----
22
----------------------------------------------------------------------
23
----                                                              ----
24
---- Copyright (C) 2013 Authors and OPENCORES.ORG                 ----
25
----                                                              ----
26
---- This source file may be used and distributed without         ----
27
---- restriction provided that this copyright statement is not    ----
28
---- removed from the file and that any derivative work contains  ----
29
---- the original copyright notice and the associated disclaimer. ----
30
----                                                              ----
31
---- This source file is free software; you can redistribute it   ----
32
---- and/or modify it under the terms of the GNU Lesser General   ----
33
---- Public License as published by the Free Software Foundation; ----
34
---- either version 2.1 of the License, or (at your option) any   ----
35
---- later version.                                               ----
36
----                                                              ----
37
---- This source is distributed in the hope that it will be       ----
38
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ----
39
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ----
40
---- PURPOSE. See the GNU Lesser General Public License for more  ----
41
---- details.                                                     ----
42
----                                                              ----
43
---- You should have received a copy of the GNU Lesser General    ----
44
---- Public License along with this source; if not, download it   ----
45
---- from http://www.opencores.org/lgpl.shtml                     ----
46
----                                                              ----
47
----------------------------------------------------------------------
48
library ieee;
49
use ieee.std_logic_1164.all;
50
use ieee.numeric_std.all;
51
use std.textio.all;
52
use std.env.all; -- VHDL-2008
53
use work.txt_util.all;
54
use work.pltbutils_type_pkg.all; -- Use for VHDL-2002, comment out for VHDL-93
55
 
56
package pltbutils_func_pkg is
57
 
58
  -- See the package body for a description of the functions and procedures.
59
  constant C_PLTBUTILS_STRLEN  : natural := 80;
60
  constant C_PLTBUTILS_TIMEOUT : time    := 10 sec;
61
  constant C_WAIT_BEFORE_STOP_TIME : time := 1 us;
62
 
63
  -- Counters for number of checks and number of errors
64
  -- VHDL-2002:
65
  shared variable v_pltbutils_test_num  : pltbutils_p_integer_t;
66
  shared variable v_pltbutils_test_name : pltbutils_p_string_t;
67
  shared variable v_pltbutils_info      : pltbutils_p_string_t;
68
  shared variable v_pltbutils_chk_cnt   : pltbutils_p_integer_t;
69
  shared variable v_pltbutils_err_cnt   : pltbutils_p_integer_t;
70
  shared variable v_pltbutils_stop_sim  : pltbutils_p_std_logic_t;
71
  -- VHDL-1993:
72
  --shared variable v_pltbutils_test_num  : natural := 0;
73
  --shared variable v_pltbutils_test_name : string(1 to C_PLTBUTILS_STRLEN) := (others => ' ');
74
  --shared variable v_pltbutils_info      : string(1 to C_PLTBUTILS_STRLEN) := (others => ' ');
75
  --shared variable v_pltbutils_chk_cnt   : natural := 0;
76
  --shared variable v_pltbutils_err_cnt   : natural := 0;
77
  --shared variable v_pltbutils_stop_sim  : std_logic := '0';
78
 
79
  -- Global status- and control signal
80
  type pltbutils_sc_t is
81
    record
82
      test_num  : natural;
83
      test_name : string(1 to C_PLTBUTILS_STRLEN);
84
      info      : string(1 to C_PLTBUTILS_STRLEN);
85
      chk_cnt   : natural;
86
      err_cnt   : natural;
87
      stop_sim  : std_logic;
88
    end record;
89
  signal pltbutils_sc : pltbutils_sc_t;
90
 
91
  -- startsim 
92
  procedure startsim(
93
    constant testcase_name      : in    string;
94
    signal   pltbutils_sc       : out   pltbutils_sc_t
95
  );
96
 
97
  -- endsim
98
  procedure endsim(
99
    signal   pltbutils_sc        : out pltbutils_sc_t;
100
    constant show_success_fail   : in   boolean := false;
101
    constant force               : in boolean := false
102
  );
103
 
104
  -- testname
105
  procedure testname(
106
    constant num                : in    integer := -1;
107
    constant name               : in    string;
108
    signal   pltbutils_sc       : out   pltbutils_sc_t
109
  );
110
  procedure testname(
111
    constant name               : in    string;
112
    signal   pltbutils_sc       : out   pltbutils_sc_t
113
  );
114
 
115
  -- print, printv, print2
116
  procedure print(
117 6 pela
    constant active             : in    boolean;
118 2 pela
    signal   s                  : out   string;
119
    constant txt                : in    string
120
  );
121 6 pela
  procedure print(
122
    signal   s                  : out   string;
123
    constant txt                : in    string
124
  );
125 2 pela
  procedure printv(
126 6 pela
    constant active             : in    boolean;
127 2 pela
    variable s                  : out   string;
128
    constant txt                : in    string
129
  );
130
  procedure printv(
131 6 pela
    variable s                  : out   string;
132
    constant txt                : in    string
133
  );
134
  procedure printv(
135
    constant active             : in    boolean;
136 2 pela
    variable s                  : inout pltbutils_p_string_t;
137
    constant txt                : in    string
138
  );
139 6 pela
  procedure printv(
140
    variable s                  : inout pltbutils_p_string_t;
141
    constant txt                : in    string
142
  );
143 2 pela
  procedure print(
144 6 pela
    constant active             : in    boolean;
145 2 pela
    signal   pltbutils_sc       : out   pltbutils_sc_t;
146
    constant txt                : in    string
147
  );
148 6 pela
  procedure print(
149
    signal   pltbutils_sc       : out   pltbutils_sc_t;
150
    constant txt                : in    string
151
  );
152 2 pela
  procedure print2(
153 6 pela
    constant active             : in    boolean;
154 2 pela
    signal   s                  : out   string;
155
    constant txt                : in    string
156
  );
157
  procedure print2(
158 6 pela
    signal   s                  : out   string;
159
    constant txt                : in    string
160
  );
161
  procedure print2(
162
    constant active             : in    boolean;
163 2 pela
    signal   pltbutils_sc       : out   pltbutils_sc_t;
164
    constant txt                : in    string
165
  );
166 6 pela
  procedure print2(
167
    signal   pltbutils_sc       : out   pltbutils_sc_t;
168
    constant txt                : in    string
169
  );
170 2 pela
 
171
  -- waitclks
172
  procedure waitclks(
173
    constant N                  : in    natural;
174
    signal   clk                : in    std_logic;
175
    signal   pltbutils_sc       : out   pltbutils_sc_t;
176
    constant falling            : in    boolean := false;
177
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
178
  );
179
 
180 6 pela
  -- waitsig
181
  procedure waitsig(
182
    signal   s                  : in    integer;
183
    constant value              : in    integer;
184
    signal   clk                : in    std_logic;
185
    signal   pltbutils_sc       : out   pltbutils_sc_t;
186
    constant falling            : in    boolean := false;
187
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
188
  );
189
  procedure waitsig(
190
    signal   s                  : in    std_logic;
191
    constant value              : in    std_logic;
192
    signal   clk                : in    std_logic;
193
    signal   pltbutils_sc       : out   pltbutils_sc_t;
194
    constant falling            : in    boolean := false;
195
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
196
  );
197
  procedure waitsig(
198
    signal   s                  : in    std_logic;
199
    constant value              : in    integer;
200
    signal   clk                : in    std_logic;
201
    signal   pltbutils_sc       : out   pltbutils_sc_t;
202
    constant falling            : in    boolean := false;
203
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
204
  );
205
  procedure waitsig(
206
    signal   s                  : in    std_logic_vector;
207
    constant value              : in    std_logic_vector;
208
    signal   clk                : in    std_logic;
209
    signal   pltbutils_sc       : out   pltbutils_sc_t;
210
    constant falling            : in    boolean := false;
211
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
212
  );
213
  procedure waitsig(
214
    signal   s                  : in    std_logic_vector;
215
    constant value              : in    integer;
216
    signal   clk                : in    std_logic;
217
    signal   pltbutils_sc       : out   pltbutils_sc_t;
218
    constant falling            : in    boolean := false;
219
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
220
  );
221
  procedure waitsig(
222
    signal   s                  : in    unsigned;
223
    constant value              : in    unsigned;
224
    signal   clk                : in    std_logic;
225
    signal   pltbutils_sc       : out   pltbutils_sc_t;
226
    constant falling            : in    boolean := false;
227
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
228
  );
229
  procedure waitsig(
230
    signal   s                  : in    unsigned;
231
    constant value              : in    integer;
232
    signal   clk                : in    std_logic;
233
    signal   pltbutils_sc       : out   pltbutils_sc_t;
234
    constant falling            : in    boolean := false;
235
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
236
  );
237
  procedure waitsig(
238
    signal   s                  : in    signed;
239
    constant value              : in    signed;
240
    signal   clk                : in    std_logic;
241
    signal   pltbutils_sc       : out   pltbutils_sc_t;
242
    constant falling            : in    boolean := false;
243
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
244
  );
245
  procedure waitsig(
246
    signal   s                  : in    signed;
247
    constant value              : in    integer;
248
    signal   clk                : in    std_logic;
249
    signal   pltbutils_sc       : out   pltbutils_sc_t;
250
    constant falling            : in    boolean := false;
251
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
252
  );
253
 
254 2 pela
  -- check
255
  procedure check(
256
    constant rpt                : in    string;
257
    constant data               : in    integer;
258
    constant expected           : in    integer;
259
    signal   pltbutils_sc       : out   pltbutils_sc_t
260
  );
261
  procedure check(
262
    constant rpt                : in    string;
263
    constant data               : in    std_logic;
264
    constant expected           : in    std_logic;
265
    signal   pltbutils_sc       : out   pltbutils_sc_t
266
  );
267
  procedure check(
268
    constant rpt                : in    string;
269
    constant data               : in    std_logic;
270
    constant expected           : in    integer;
271
    signal   pltbutils_sc       : out   pltbutils_sc_t
272
  );
273
  procedure check(
274
    constant rpt                : in    string;
275
    constant data               : in    std_logic_vector;
276
    constant expected           : in    std_logic_vector;
277
    signal   pltbutils_sc       : out   pltbutils_sc_t
278
  );
279
  procedure check(
280
    constant rpt                : in    string;
281
    constant data               : in    std_logic_vector;
282
    constant expected           : in    std_logic_vector;
283
    constant mask               : in    std_logic_vector;
284
    signal   pltbutils_sc       : out   pltbutils_sc_t
285
  );
286
  procedure check(
287
    constant rpt                : in    string;
288
    constant data               : in    std_logic_vector;
289
    constant expected           : in    integer;
290
    signal   pltbutils_sc       : out   pltbutils_sc_t
291
  );
292
  procedure check(
293
    constant rpt                : in    string;
294
    constant data               : in    std_logic_vector;
295
    constant expected           : in    integer;
296
    constant mask               : in    std_logic_vector;
297
    signal   pltbutils_sc       : out   pltbutils_sc_t
298
  );
299
  procedure check(
300
    constant rpt                : in    string;
301
    constant data               : in    unsigned;
302
    constant expected           : in    unsigned;
303
    signal   pltbutils_sc       : out   pltbutils_sc_t
304
  );
305
  procedure check(
306
    constant rpt                : in    string;
307
    constant data               : in    unsigned;
308
    constant expected           : in    integer;
309
    signal   pltbutils_sc       : out   pltbutils_sc_t
310
  );
311
  procedure check(
312
    constant rpt                : in    string;
313
    constant data               : in    signed;
314
    constant expected           : in    signed;
315
    signal   pltbutils_sc       : out   pltbutils_sc_t
316
  );
317
  procedure check(
318
    constant rpt                : in    string;
319
    constant data               : in    signed;
320
    constant expected           : in    integer;
321
    signal   pltbutils_sc       : out   pltbutils_sc_t
322
  );
323
  procedure check(
324
    constant rpt                : in    string;
325
    constant expr               : in    boolean;
326
    signal   pltbutils_sc       : out   pltbutils_sc_t
327
  );
328
 
329
  -- pltbutils internal procedure(s), do not call from user's code
330
  procedure pltbutils_sc_update(
331
    signal pltbutils_sc : out pltbutils_sc_t
332
  );
333
 
334
end package pltbutils_func_pkg;
335
 
336
package body pltbutils_func_pkg is
337
 
338
  ----------------------------------------------------------------------------
339
  -- startsim
340
  --
341
  -- procedure startsim(
342
  --   constant testcase_name      : in    string;
343
  --   signal   pltbutils_sc       : out   pltbutils_sc_t
344
  -- )
345
  --
346
  -- Displays a message at start of simulation message, and initializes
347
  -- PlTbUtils' global status and control signal.
348
  -- Call startsim() only once.
349
  --
350
  -- Arguments:
351
  --   testcase_name            Name of the test case, e.g. "tc1".
352
  --
353
  --   pltbutils_sc             PlTbUtils' global status- and control signal.
354
  --                            Must be set to pltbutils_sc.
355
  --
356
  -- NOTE:
357
  -- The start-of-simulation message is not only intended to be informative
358
  -- for humans. It is also intended to be searched for by scripts,
359
  -- e.g. for collecting results from a large number of regression tests.
360
  -- For this reason, the message must be consistent and unique.
361
  --
362
  -- DO NOT MODIFY the message "--- START OF SIMULATION ---".
363
  -- DO NOT OUTPUT AN IDENTICAL MESSAGE anywhere else.
364
  --
365
  -- Example:
366
  -- startsim("tc1", pltbutils_sc);
367
  ----------------------------------------------------------------------------
368
  procedure startsim(
369
    constant testcase_name      : in    string;
370
    signal   pltbutils_sc       : out   pltbutils_sc_t
371
  ) is
372
    variable dummy : integer;
373
  begin
374
    printv(v_pltbutils_info, testcase_name);
375
    print(lf & "--- START OF SIMULATION ---");
376
    print("Testcase: " & testcase_name);
377
    print(time'image(now));
378
    -- VHDL-2002:
379
    v_pltbutils_stop_sim.clr;
380
    v_pltbutils_test_num.clr;
381
    v_pltbutils_test_name.set("START OF SIMULATION");
382
    v_pltbutils_chk_cnt.clr;
383
    v_pltbutils_err_cnt.clr;
384
    pltbutils_sc_update(pltbutils_sc);
385
    -- VHDL-1993:
386
    --v_pltbutils_stop_sim := '0';
387
    --v_pltbutils_test_num := 0;
388
    --printv(v_pltbutils_test_name, "START OF SIMULATION");
389
    --v_pltbutils_chk_cnt := 0;
390
    --v_pltbutils_err_cnt := 0;
391
    --pltbutils_sc_update(pltbutils_sc);
392
  end procedure startsim;
393
 
394
  ----------------------------------------------------------------------------
395
  -- endsim
396
  --
397
  -- procedure endsim(
398
  --   signal   pltbutils_sc       : out pltbutils_sc_t;
399
  --   constant show_success_fail  : in  boolean := false;
400
  --   constant force              : in  boolean := false
401
  -- )
402
  --
403
  -- Displays a message at end of simulation message, presents the simulation
404
  -- results, and stops the simulation. 
405
  -- Call endsim() it only once.
406
  --
407
  -- Arguments: 
408
  --   pltbutils_sc             PlTbUtils' global status- and control signal.
409
  --                            Must be set to pltbutils_sc.
410
  --
411
  --   show_success_fail        If true, endsim() shows "*** SUCCESS ***", 
412
  --                            "*** FAIL ***", or "*** NO CHECKS ***".
413
  --                            Optional, default is false.
414
  --
415
  --   force                    If true, forces the simulation to stop using an
416
  --                            assert failure statement. Use this option only
417
  --                            if the normal way of stopping the simulation
418
  --                            doesn't work (see below).
419
  --                            Optional, default is false.
420
  --
421
  -- The testbench should be designed so that all clocks stop when endsim()
422
  -- sets the signal stop_sim to '1'. This should stop the simulator.
423
  -- In some cases, that doesn't work, then set the force argument to true, which
424
  -- causes a false assert failure, which should stop the simulator.
425
  -- Scripts searching transcript logs for errors and failures, should ignore
426
  -- the failure with "--- FORCE END OF SIMULATION ---" as part of the report.
427
  --
428
  -- NOTE:
429
  -- The end-of-simulation messages and success/fail messages are not only
430
  -- intended to be informative for humans. They are also intended to be
431
  -- searched for by scripts, e.g. for collecting results from a large number
432
  -- of regression tests.
433
  -- For this reason, the message must be consistent and unique.
434
  --
435
  -- DO NOT MODIFY the messages "--- END OF SIMULATION ---", 
436
  -- "*** SUCCESS ***", "*** FAIL ***", "*** NO CHECKS ***".
437
  -- DO NOT OUTPUT IDENTICAL MESSAGES anywhere else.
438
  --
439
  -- Examples:
440
  -- endsim(pltbutils_sc);
441
  -- endsim(pltbutils_sc, true);
442
  -- endsim(pltbutils_sc, true, true);
443
  ----------------------------------------------------------------------------
444
  procedure endsim(
445
    signal   pltbutils_sc       : out pltbutils_sc_t;
446
    constant show_success_fail  : in  boolean := false;
447
    constant force              : in  boolean := false
448
  ) is
449
    variable l : line;
450
  begin
451
    printv(v_pltbutils_info, "");
452
    print(lf & "--- END OF SIMULATION ---");
453
    print("Note: the results presented below are based on the PlTbUtil's check() procedure calls.");
454
    print("      The design may contain more errors, for which there are no check() calls.");
455
    write(l, now, right, 14);
456
    writeline(output, l);
457
    write(l, v_pltbutils_chk_cnt.value, right, 11); -- VHDL-2002
458
    --write(l, v_pltbutils_chk_cnt, right, 11); -- VHDL-1993
459
    write(l, string'(" Checks"));
460
    writeline(output, l);
461
    write(l, v_pltbutils_err_cnt.value, right, 11); -- VHDL-2002
462
    --write(l, v_pltbutils_chk_cnt, right, 11); -- VHDL-1993
463
    write(l, string'(" Errors"));
464
    writeline(output, l);
465
 
466
    if show_success_fail then
467
       if v_pltbutils_err_cnt.value = 0 and v_pltbutils_chk_cnt.value > 0 then -- VHDL-2002
468
       --if v_pltbutils_err_cnt = 0 and v_pltbutils_chk_cnt > 0 then -- VHDL-1993
469
        print("*** SUCCESS ***");
470
      elsif v_pltbutils_chk_cnt.value > 0 then -- VHDL-2002
471
      --elsif v_pltbutils_chk_cnt > 0 then -- VHDL-1993
472
        print("*** FAIL ***");
473
      else
474
        print("*** NO CHECKS ***");
475
      end if;
476
    end if;
477
    -- VHDL-2002:
478
    v_pltbutils_stop_sim.set('1');
479
    v_pltbutils_test_num.clr;
480
    v_pltbutils_test_name.set("END OF SIMULATION");
481
    -- VHDL-1993:
482
    --v_pltbutils_stop_sim := '1';
483
    --v_pltbutils_test_num := 0;
484
    --printv(v_pltbutils_test_name, "END OF SIMULATION");
485
    pltbutils_sc_update(pltbutils_sc);
486
    wait for C_WAIT_BEFORE_STOP_TIME;
487
    stop(0); -- VHDL-2008
488
    assert not force
489
    report "--- FORCE END OF SIMULATION ---" &
490
           " (ignore this false failure message, it's not a real failure)"
491
    severity failure;
492
    wait;
493
  end procedure endsim;
494
 
495
  ----------------------------------------------------------------------------
496
  -- testname
497
  --
498
  -- procedure testname(
499
  --   constant num                : in    integer := -1;
500
  --   constant name               : in    string;
501
  --   signal   pltbutils_sc       : out   pltbutils_sc_t
502
  -- ) 
503
  --
504
  -- Sets a number (optional) and a name for a test. The number and name will
505
  -- be printed to the screen, and displayed in the simulator's waveform
506
  -- window. 
507
  -- The test number and name is also included if there errors reported by the
508
  -- check() procedure calls.
509
  --
510
  -- Arguments: 
511
  --   num                      Test number. Optional, default is to increment
512
  --                            the current test number.
513
  --
514
  --   name                     Test name.
515
  --
516
  --   pltbutils_sc             PlTbUtils' global status- and control signal.
517
  --                            Must be set to pltbutils_sc.
518
  --
519
  -- If the test number is omitted, a new test number is automatically
520
  -- computed by incrementing the current test number. 
521
  -- Manually setting the test number may make it easier to find the test code
522
  -- in the testbench code, though.
523
  --
524
  -- Examples:
525
  -- testname("Reset test", pltbutils_sc);
526
  -- testname(1, "Reset test", pltbutils_sc);
527
  ----------------------------------------------------------------------------
528
  procedure testname(
529
    constant num                : in    integer := -1;
530
    constant name               : in    string;
531
    signal   pltbutils_sc       : out   pltbutils_sc_t
532
  ) is
533
  begin
534
    -- VHDL-2002:
535
    if num = -1 then
536
      v_pltbutils_test_num.inc;
537
    else
538
      v_pltbutils_test_num.set(num);
539
    end if;
540
    v_pltbutils_test_name.set(name);
541
    pltbutils_sc_update(pltbutils_sc);
542
    print("Test " & str(v_pltbutils_test_num.value) & ": " & name);
543
    -- VHDL-1993:
544
    --if num = -1 then
545
    --  b_pltbutils_test_num := v_pltbutils_test_num + 1;
546
    --else
547
    --  v_pltbutils_test_num  := num;
548
    --end if;
549
    --printv(v_pltbutils_test_name, name);
550
    --pltbutils_sc_update(pltbutils_sc);
551
    --print("Test " & str(v_pltbutils_test_num) & ": " & name);
552
  end procedure testname;
553
 
554
  procedure testname(
555
    constant name               : in    string;
556
    signal   pltbutils_sc       : out   pltbutils_sc_t
557
  ) is
558
  begin
559
    testname(-1, name, pltbutils_sc);
560
  end procedure testname;
561
 
562
  ----------------------------------------------------------------------------
563
  -- print printv print2
564
  --
565
  -- procedure print(   
566
  --   signal   s                  : out   string;
567
  --   constant txt                : in    string
568
  -- ) 
569
  --
570 6 pela
  -- procedure print(   
571
  --   constant active             : in    boolean;
572
  --   signal   s                  : out   string;
573
  --   constant txt                : in    string
574
  -- ) 
575
  --
576 2 pela
  -- procedure print(
577
  --   signal   pltbutils_sc       : out   pltbutils_sc_t;
578
  --   constant txt                : in    string
579
  -- )
580
  --
581 6 pela
  -- procedure print(
582
  --   constant active             : in    boolean;
583
  --   signal   pltbutils_sc       : out   pltbutils_sc_t;
584
  --   constant txt                : in    string
585
  -- )
586
  --
587 2 pela
  -- procedure printv(
588
  --   variable s                  : out   string;
589
  --   constant txt                : in    string
590
  -- )
591
  --
592 6 pela
  -- procedure printv(
593
  --   constant active             : in    boolean;
594
  --   variable s                  : out   string;
595
  --   constant txt                : in    string
596
  -- )
597
  --
598 2 pela
  -- procedure print2(    
599
  --   signal   s                  : out   string;
600
  --   constant txt                : in    string
601
  -- )
602
  --
603
  -- procedure print2(    
604 6 pela
  --   constant active             : in    boolean;
605
  --   signal   s                  : out   string;
606
  --   constant txt                : in    string
607
  -- )
608
  --
609
  -- procedure print2(    
610 2 pela
  --   signal   pltbutils          : out   pltbutils_sc_t;
611
  --   constant txt                : in    string
612
  -- )
613
  --
614 6 pela
  -- procedure print2(    
615
  --   constant active             : in    boolean;
616
  --   signal   pltbutils          : out   pltbutils_sc_t;
617
  --   constant txt                : in    string
618
  -- )
619
  --
620 2 pela
  -- print() prints text messages to a signal for viewing in the simulator's
621
  -- waveform window. printv() does the same thing, but to a variable instead.
622
  -- print2() prints both to a signal and to the transcript window. 
623
  -- The type of the output can be string or pltbutils_sc_t.
624
  -- If the type is pltbutils_sc_t, the name can be no other than pltbutils_sc.
625
  --
626
  -- Arguments: 
627
  --   s                        Signal or variable of type string to be 
628
  --                            printed to.
629
  --
630
  --   txt                      The text.
631
  --
632 6 pela
  --   active                   The text is only printed if active is true.
633
  --                            Useful for debug switches, etc.
634
  --
635 2 pela
  --   pltbutils_sc             PlTbUtils' global status- and control signal 
636
  --                            of type pltbutils_sc_t. 
637
  --                            The name must be no other than pltbutils_sc.
638
  --
639
  -- If the string txt  is longer than the signal s, the text will be truncated.
640
  -- If txt  is shorter, s will be padded with spaces.
641
  --
642
  -- Examples:
643
  -- print(msg, "Hello, world"); -- Prints to signal msg
644 6 pela
  -- print(G_DEBUG, msg, "Hello, world"); -- Prints to signal msg if 
645
  --                                      -- generic G_DEBUG is true
646 2 pela
  -- printv(v_msg, "Hello, world"); -- Prints to variable msg
647
  -- print(pltbutils_sc, "Hello, world"); -- Prints to "info" in waveform window
648
  -- print2(msg, "Hello, world"); -- Prints to signal and transcript window 
649
  -- print(pltbutils_sc, "Hello, world"); -- Prints to "info" in waveform and
650
  --                                      -- transcript windows
651
  ----------------------------------------------------------------------------
652
  procedure print(
653 6 pela
    constant active             : in    boolean;
654 2 pela
    signal   s                  : out   string;
655
    constant txt                : in    string
656
  ) is
657
    variable j : positive := txt 'low;
658
  begin
659 6 pela
    if active then
660
      for i in s'range loop
661
        if j <= txt 'high then
662
          s(i) <= txt (j);
663
        else
664
          s(i) <= ' ';
665
        end if;
666
        j := j + 1;
667
      end loop;
668
    end if;
669 2 pela
  end procedure print;
670
 
671 6 pela
  procedure print(
672
    signal   s                  : out   string;
673
    constant txt                : in    string
674
  ) is
675
  begin
676
    print(true, s, txt);
677
  end procedure print;
678
 
679 2 pela
  procedure printv(
680 6 pela
    constant active             : in    boolean;
681 2 pela
    variable s                  : out   string;
682
    constant txt                : in    string
683
  ) is
684
    variable j : positive := txt 'low;
685
  begin
686 6 pela
    if active then
687
      for i in s'range loop
688
        if j <= txt 'high then
689
          s(i) := txt (j);
690
        else
691
          s(i) := ' ';
692
        end if;
693
        j := j + 1;
694
      end loop;
695
    end if;
696 2 pela
  end procedure printv;
697
 
698 6 pela
  procedure printv(
699
    variable s                  : out   string;
700
    constant txt                : in    string
701
  ) is
702
  begin
703
    printv(true, s, txt);
704
  end procedure printv;
705
 
706 2 pela
  -- VHDL-2002:
707
  procedure printv(
708 6 pela
    constant active             : in    boolean;
709 2 pela
    variable s                  : inout pltbutils_p_string_t;
710
    constant txt                : in    string
711
  ) is
712
    variable j : positive := txt 'low;
713
  begin
714 6 pela
    if active then
715
      s.set(txt);
716
    end if;
717 2 pela
  end procedure printv;
718 6 pela
 
719
  procedure printv(
720
    variable s                  : inout pltbutils_p_string_t;
721
    constant txt                : in    string
722
  ) is
723
  begin
724
    printv(true, s, txt);
725
  end procedure printv;
726 2 pela
 
727
  -- Print to info element in pltbutils_sc, which shows up in waveform window
728
  procedure print(
729 6 pela
    constant active             : in    boolean;
730 2 pela
    signal   pltbutils_sc       : out   pltbutils_sc_t;
731
    constant txt                : in    string
732
  ) is
733
    variable j : positive := txt 'low;
734
  begin
735 6 pela
    if active then
736
      printv(v_pltbutils_info, txt );
737
      pltbutils_sc_update(pltbutils_sc);
738
    end if;
739 2 pela
  end procedure print;
740 6 pela
 
741
  procedure print(
742
    signal   pltbutils_sc       : out   pltbutils_sc_t;
743
    constant txt                : in    string
744
  ) is
745
  begin
746
    print(true, pltbutils_sc, txt);
747
  end procedure print;
748 2 pela
 
749
  procedure print2(
750 6 pela
    constant active             : in    boolean;
751 2 pela
    signal   s                  : out   string;
752
    constant txt                : in    string
753
  ) is
754
  begin
755 6 pela
    if active then
756
      print(s, txt );
757
      print(txt);
758
    end if;
759 2 pela
  end procedure print2;
760
 
761
  procedure print2(
762 6 pela
    signal   s                  : out   string;
763
    constant txt                : in    string
764
  ) is
765
  begin
766
    print(true, s, txt);
767
  end procedure print2;
768
 
769
  procedure print2(
770
    constant active             : in    boolean;
771 2 pela
    signal   pltbutils_sc       : out   pltbutils_sc_t;
772
    constant txt                : in    string
773
  ) is
774
  begin
775
    print(pltbutils_sc, txt );
776 6 pela
    print(txt);
777 2 pela
  end procedure print2;
778
 
779 6 pela
  procedure print2(
780
    signal   pltbutils_sc       : out   pltbutils_sc_t;
781
    constant txt                : in    string
782
  ) is
783
  begin
784
    print(true, pltbutils_sc, txt);
785
  end procedure print2;
786
 
787 2 pela
  ----------------------------------------------------------------------------
788
  -- waitclks
789
  --
790
  -- procedure waitclks(
791
  --   constant n                  : in    natural;
792
  --   signal   clk                : in    std_logic;
793
  --   signal   pltbutils_sc       : out   pltbutils_sc_t;
794
  --   constant falling            : in    boolean := false;
795
  --   constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
796
  -- )
797
  --
798
  -- Waits specified amount of clock cycles of the specified clock.
799
  -- Or, to be more precise, a specified number of specified clock edges of
800
  -- the specified clock.
801
  --
802
  -- Arguments: 
803
  --   n                        Number of rising or falling clock edges to wait.
804
  --
805
  --   clk                      The clock to wait for.
806
  --
807
  --   pltbutils_sc             PlTbUtils' global status- and control signal.
808
  --                            Must be set to pltbutils_sc.
809
  --
810
  --   falling                  If true, waits for falling edges, otherwise
811
  --                            rising edges. Optional, default is false.
812
  --
813
  --   timeout                  Timeout time, in case the clock is not working.
814
  --                            Optional, default is C_PLTBUTILS_TIMEOUT.  
815
  --
816
  -- Examples:
817
  -- waitclks(5, sys_clk, pltbutils_sc);
818
  -- waitclks(5, sys_clk, pltbutils_sc, true);
819
  -- waitclks(5, sys_clk, pltbutils_sc, true, 1 ms);
820
  ----------------------------------------------------------------------------
821
  procedure waitclks(
822
    constant n                  : in    natural;
823
    signal   clk                : in    std_logic;
824
    signal   pltbutils_sc       : out   pltbutils_sc_t;
825
    constant falling            : in    boolean := false;
826
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
827
  ) is
828
    variable i                  : natural := n;
829
    variable v_timeout_time     : time;
830
  begin
831
    v_timeout_time := now + timeout;
832
    while i > 0 loop
833 6 pela
      if falling then
834 2 pela
        wait until falling_edge(clk) for timeout / n;
835
      else
836
        wait until rising_edge(clk)  for timeout / n;
837
      end if;
838
      i := i - 1;
839
    end loop;
840
    if now >= v_timeout_time then
841
      assert false
842
      report "waitclks() timeout"
843
      severity error;
844
      v_pltbutils_err_cnt.inc; -- VHDL-2002
845
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
846
      pltbutils_sc_update(pltbutils_sc);
847
    end if;
848
  end procedure waitclks;
849 6 pela
 
850
  ----------------------------------------------------------------------------
851
  -- waitsig
852
  --
853
  -- procedure waitsig(
854
  --   signal   s                  : in    integer|std_logic|std_logic_vector|unsigned|signed;
855
  --   constant value              : in    integer|std_logic|std_logic_vector|unsigned|signed;
856
  --   signal   clk                : in    std_logic;
857
  --   signal   pltbutils_sc       : out   pltbutils_sc_t;
858
  --   constant falling            : in    boolean := false;
859
  --   constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
860
  -- )
861
  --
862
  -- Waits until a signal has reached a specified value after specified clock
863
  -- edge.
864
  --
865
  -- Arguments: 
866
  --   s                        The signal to test.
867
  --                            Supported types: integer, std_logic, 
868
  --                            std_logic_vector, unsigned, signed.
869
  --
870
  --   value                    Value to wait for.
871
  --                            Same type as data or integer.
872
  --
873
  --   clk                      The clock.
874
  --
875
  --   pltbutils_sc             PlTbUtils' global status- and control signal.
876
  --                            Must be set to pltbutils_sc.
877
  --
878
  --   falling                  If true, waits for falling edges, otherwise
879
  --                            rising edges. Optional, default is false.
880
  --
881
  --   timeout                  Timeout time, in case the clock is not working.
882
  --                            Optional, default is C_PLTBUTILS_TIMEOUT.  
883
  --
884
  -- Examples:
885
  -- waitsig(wr_en, '1', sys_clk, pltbutils_sc);
886
  -- waitsig(rd_en,   1, sys_clk, pltbutils_sc, true);
887
  -- waitclks(full, '1', sys_clk, pltbutils_sc, true, 1 ms);
888
  ---------------------------------------------------------------------------- 
889
  procedure waitsig(
890
    signal   s                  : in    integer;
891
    constant value              : in    integer;
892
    signal   clk                : in    std_logic;
893
    signal   pltbutils_sc       : out   pltbutils_sc_t;
894
    constant falling            : in    boolean := false;
895
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
896
  ) is
897
    variable v_timeout_time     : time;
898
  begin
899
    v_timeout_time := now + timeout;
900
    l1 : loop
901
      waitclks(1, clk, pltbutils_sc, falling, timeout);
902
      exit l1 when s = value or now >= v_timeout_time;
903
    end loop;
904
    if now >= v_timeout_time then
905
      assert false
906
      report "waitsig() timeout"
907
      severity error;
908
      v_pltbutils_err_cnt.inc; -- VHDL-2002
909
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
910
      pltbutils_sc_update(pltbutils_sc);
911
    end if;
912
  end procedure waitsig;
913
 
914
  procedure waitsig(
915
    signal   s                  : in    std_logic;
916
    constant value              : in    std_logic;
917
    signal   clk                : in    std_logic;
918
    signal   pltbutils_sc       : out   pltbutils_sc_t;
919
    constant falling            : in    boolean := false;
920
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
921
  ) is
922
    variable v_timeout_time     : time;
923
  begin
924
    v_timeout_time := now + timeout;
925
    l1 : loop
926
      waitclks(1, clk, pltbutils_sc, falling, timeout);
927
      exit l1 when s = value or now >= v_timeout_time;
928
    end loop;
929
    if now >= v_timeout_time then
930
      assert false
931
      report "waitsig() timeout"
932
      severity error;
933
      v_pltbutils_err_cnt.inc; -- VHDL-2002
934
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
935
      pltbutils_sc_update(pltbutils_sc);
936
    end if;
937
  end procedure waitsig;
938 2 pela
 
939 6 pela
  procedure waitsig(
940
    signal   s                  : in    std_logic;
941
    constant value              : in    integer;
942
    signal   clk                : in    std_logic;
943
    signal   pltbutils_sc       : out   pltbutils_sc_t;
944
    constant falling            : in    boolean := false;
945
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
946
  ) is
947
    variable v_value            : std_logic;
948
    variable v_timeout_time     : time;
949
  begin
950
    case value is
951
      when 0      => v_value := '0';
952
      when 1      => v_value := '1';
953
      when others => v_value := 'X';
954
    end case;
955
    if v_value /= 'X' then
956
      waitsig(s, v_value, clk,
957
              pltbutils_sc, falling, timeout);
958
    else
959
      assert false
960
        report "waitsig() illegal value to wait for: " & integer'image(value)
961
        severity error;
962
      v_pltbutils_err_cnt.inc; -- VHDL-2002
963
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
964
      pltbutils_sc_update(pltbutils_sc);
965
    end if;
966
  end procedure waitsig;
967
 
968
  procedure waitsig(
969
    signal   s                  : in    std_logic_vector;
970
    constant value              : in    std_logic_vector;
971
    signal   clk                : in    std_logic;
972
    signal   pltbutils_sc       : out   pltbutils_sc_t;
973
    constant falling            : in    boolean := false;
974
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
975
  ) is
976
    variable v_timeout_time     : time;
977
  begin
978
    v_timeout_time := now + timeout;
979
    l1 : loop
980
      waitclks(1, clk, pltbutils_sc, falling, timeout);
981
      exit l1 when s = value or now >= v_timeout_time;
982
    end loop;
983
    if now >= v_timeout_time then
984
      assert false
985
      report "waitsig() timeout"
986
      severity error;
987
      v_pltbutils_err_cnt.inc; -- VHDL-2002
988
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
989
      pltbutils_sc_update(pltbutils_sc);
990
    end if;
991
  end procedure waitsig;
992
 
993
  procedure waitsig(
994
    signal   s                  : in    std_logic_vector;
995
    constant value              : in    integer;
996
    signal   clk                : in    std_logic;
997
    signal   pltbutils_sc       : out   pltbutils_sc_t;
998
    constant falling            : in    boolean := false;
999
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
1000
  ) is
1001
    variable v_timeout_time     : time;
1002
  begin
1003
    waitsig(s, std_logic_vector(to_unsigned(value, s'length)), clk,
1004
            pltbutils_sc, falling, timeout);
1005
  end procedure waitsig;
1006
 
1007
  procedure waitsig(
1008
    signal   s                  : in    unsigned;
1009
    constant value              : in    unsigned;
1010
    signal   clk                : in    std_logic;
1011
    signal   pltbutils_sc       : out   pltbutils_sc_t;
1012
    constant falling            : in    boolean := false;
1013
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
1014
  ) is
1015
    variable v_timeout_time     : time;
1016
  begin
1017
    v_timeout_time := now + timeout;
1018
    l1 : loop
1019
      waitclks(1, clk, pltbutils_sc, falling, timeout);
1020
      exit l1 when s = value or now >= v_timeout_time;
1021
    end loop;
1022
    if now >= v_timeout_time then
1023
      assert false
1024
      report "waitsig() timeout"
1025
      severity error;
1026
      v_pltbutils_err_cnt.inc; -- VHDL-2002
1027
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
1028
      pltbutils_sc_update(pltbutils_sc);
1029
    end if;
1030
  end procedure waitsig;
1031
 
1032
  procedure waitsig(
1033
    signal   s                  : in    unsigned;
1034
    constant value              : in    integer;
1035
    signal   clk                : in    std_logic;
1036
    signal   pltbutils_sc       : out   pltbutils_sc_t;
1037
    constant falling            : in    boolean := false;
1038
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
1039
  ) is
1040
    variable v_timeout_time     : time;
1041
  begin
1042
    waitsig(s, to_unsigned(value, s'length), clk,
1043
            pltbutils_sc, falling, timeout);
1044
  end procedure waitsig;
1045
 
1046
  procedure waitsig(
1047
    signal   s                  : in    signed;
1048
    constant value              : in    signed;
1049
    signal   clk                : in    std_logic;
1050
    signal   pltbutils_sc       : out   pltbutils_sc_t;
1051
    constant falling            : in    boolean := false;
1052
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
1053
  ) is
1054
    variable v_timeout_time     : time;
1055
  begin
1056
    v_timeout_time := now + timeout;
1057
    l1 : loop
1058
      waitclks(1, clk, pltbutils_sc, falling, timeout);
1059
      exit l1 when s = value or now >= v_timeout_time;
1060
    end loop;
1061
    if now >= v_timeout_time then
1062
      assert false
1063
      report "waitsig() timeout"
1064
      severity error;
1065
      v_pltbutils_err_cnt.inc; -- VHDL-2002
1066
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
1067
      pltbutils_sc_update(pltbutils_sc);
1068
    end if;
1069
  end procedure waitsig;
1070
 
1071
  procedure waitsig(
1072
    signal   s                  : in    signed;
1073
    constant value              : in    integer;
1074
    signal   clk                : in    std_logic;
1075
    signal   pltbutils_sc       : out   pltbutils_sc_t;
1076
    constant falling            : in    boolean := false;
1077
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
1078
  ) is
1079
    variable v_timeout_time     : time;
1080
  begin
1081
    waitsig(s, to_signed(value, s'length), clk,
1082
            pltbutils_sc, falling, timeout);
1083
  end procedure waitsig;
1084
 
1085 2 pela
  ----------------------------------------------------------------------------
1086
  -- check
1087
  --
1088
  -- procedure check(
1089
  --  constant rpt              : in    string;
1090
  --  constant data             : in    integer|std_logic|std_logic_vector|unsigned|signed;
1091
  --  constant expected         : in    integer|std_logic|std_logic_vector|unsigned|signed;
1092
  --  signal   pltbutils_sc     : out   pltbutils_sc_t
1093
  --  )
1094
  --
1095
  -- procedure check(
1096
  --  constant rpt              : in    string;
1097
  --  constant data             : in    std_logic_vector;
1098
  --  constant expected         : in    std_logic_vector;
1099
  --  constant mask             : in    std_logic_vector;
1100
  --  signal   pltbutils_sc     : out   pltbutils_sc_t
1101
  --  )
1102
  --
1103
  -- procedure check(
1104
  --   constant rpt            : in    string;
1105
  --   constant expr           : in    boolean;
1106
  --   signal   pltbutils_sc   : out   pltbutils_sc_t
1107
  -- )
1108
  --
1109
  -- Checks that the value of a signal or variable is equal to expected.
1110
  -- If not equal, displays an error message and increments the error counter.
1111
  --
1112
  -- Arguments: 
1113
  --   rpt                      Report message to be displayed in case of 
1114
  --                            mismatch. 
1115
  --                            It is recommended that the message is unique
1116
  --                            and that it contains the name of the signal
1117
  --                            or variable being checked. 
1118
  --                            The message should NOT contain the expected 
1119
  --                            value, becase check() prints that 
1120
  --                            automatically.
1121
  --
1122
  --   data                     The signal or variable to be checked.
1123
  --                            Supported types: integer, std_logic, 
1124
  --                            std_logic_vector, unsigned, signed.
1125
  --
1126
  --   expected                 Expected value. 
1127
  --                            Same type as data or integer.
1128
  --
1129
  --   mask                     Bit mask and:ed to data and expected 
1130
  --                            before comparison.
1131
  --                            Optional if data is std_logic_vector.
1132
  --                            Not allowed for other types.
1133
  --
1134
  --   expr                     boolean expression for checking.
1135
  --                            This makes it possible to check any kind of
1136
  --                            expresion, not just equality.
1137
  -- 
1138
  --   pltbutils_sc             PlTbUtils' global status- and control signal.
1139
  --                            Must be set to the name pltbutils_sc.
1140
  --
1141
  -- Examples:
1142
  -- check("dat_o after reset", dat_o, 0, pltbutils_sc);
1143
  -- -- With mask:
1144
  -- check("Status field in reg_o after start", reg_o, x"01", x"03", pltbutils_sc);
1145
  -- -- Boolean expression:
1146
  -- check("Counter after data burst", cnt_o > 10, pltbutils_sc);
1147
  ----------------------------------------------------------------------------
1148
  -- check integer
1149
  procedure check(
1150
    constant rpt                : in    string;
1151
    constant data               : in    integer;
1152
    constant expected           : in    integer;
1153
    signal   pltbutils_sc       : out   pltbutils_sc_t
1154
  ) is
1155
  begin
1156
    v_pltbutils_chk_cnt.inc; -- VHDL-2002
1157
    --v_pltbutils_chk_cnt := v_pltbutils_chk_cnt + 1; -- VHDL-1993
1158
    if data   /= expected then
1159
      assert false
1160
      report "Check " &
1161
             str(v_pltbutils_chk_cnt.value) & -- VHDL-2002
1162
             --str(v_pltbutils_chk_cnt) & -- VHDL-1993
1163
             "; " & rpt &
1164
             "; Data=" & str(data) &
1165
             " Expected=" & str(expected) &
1166
             " " & --str(character'(lf)) &
1167
             "  in test " &
1168
             str(v_pltbutils_test_num.value) & -- VHDL-2002
1169
             --str(v_pltbutils_test_num) & -- VHDL-1993
1170
             " " &
1171
             v_pltbutils_test_name.value -- VHDL-2002
1172
             --v_pltbutils_test_name -- VHDL-1993
1173
      severity error;
1174
      v_pltbutils_err_cnt.inc; -- VHLD-2002
1175
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
1176
    end if;
1177
    pltbutils_sc_update(pltbutils_sc);
1178
  end procedure check;
1179
 
1180
  -- check std_logic
1181
  procedure check(
1182
    constant rpt                : in    string;
1183
    constant data               : in    std_logic;
1184
    constant expected           : in    std_logic;
1185
    signal   pltbutils_sc       : out   pltbutils_sc_t
1186
  ) is
1187
  begin
1188
    v_pltbutils_chk_cnt.inc; -- VHDL-2002
1189
    --v_pltbutils_chk_cnt := v_pltbutils_chk_cnt + 1; -- VHDL-1993
1190
    if data /= expected   then
1191
      assert false
1192
      report "Check " &
1193
             str(v_pltbutils_chk_cnt.value) & -- VHDL-2002
1194
             --str(v_pltbutils_chk_cnt) & -- VHDL-1993
1195
             "; " & rpt   &
1196
             "; Data=" & str(data) &
1197
             " Expected=" & str(expected) &
1198
             " " & --str(character'(lf)) &
1199
             "  in test " &
1200
             str(v_pltbutils_test_num.value) & -- VHDL-2002
1201
             --str(v_pltbutils_test_num) & -- VHDL-1993
1202
             " " &
1203
             v_pltbutils_test_name.value -- VHDL-2002
1204
             --v_pltbutils_test_name -- VHDL-1993
1205
      severity error;
1206
      v_pltbutils_err_cnt.inc; -- VHLD-2002
1207
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
1208
    end if;
1209
    pltbutils_sc_update(pltbutils_sc);
1210
  end procedure check;
1211
 
1212
  -- check std_logic against integer
1213
  procedure check(
1214
    constant rpt                : in    string;
1215
    constant data               : in    std_logic;
1216
    constant expected           : in    integer;
1217
    signal   pltbutils_sc       : out   pltbutils_sc_t
1218
  ) is
1219
    variable v_expected : std_logic;
1220
  begin
1221
    if expected = 0 then
1222
      check(rpt , data, std_logic'('0'), pltbutils_sc);
1223
    elsif expected = 1 then
1224
      check(rpt , data, std_logic'('1'), pltbutils_sc);
1225
    else
1226
      v_pltbutils_chk_cnt.inc; -- VHDL-2002
1227
      --v_pltbutils_chk_cnt := v_pltbutils_chk_cnt + 1; -- VHDL-1993
1228
      assert false
1229
      report "Check " &
1230
             str(v_pltbutils_chk_cnt.value) & -- VHDL-2002
1231
             --str(v_pltbutils_chk_cnt) & -- VHDL-1993
1232
             "; " & rpt &
1233
             "; Data=" & str(data) &
1234
             " Expected=" & str(expected) &
1235
             " " & --str(character'(lf)) &
1236
             "  in test " &
1237
             str(v_pltbutils_test_num.value) & -- VHDL-2002
1238
             --str(v_pltbutils_test_num) & -- VHDL-1993
1239
             " " &
1240
             v_pltbutils_test_name.value -- VHDL-2002
1241
             --v_pltbutils_test_name -- VHDL-1993
1242
      severity error;
1243
      v_pltbutils_err_cnt.inc; -- VHLD-2002
1244
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
1245
      pltbutils_sc_update(pltbutils_sc);
1246
    end if;
1247
  end procedure check;
1248
 
1249
  -- check std_logic_vector
1250
  procedure check(
1251
    constant rpt                : in    string;
1252
    constant data               : in    std_logic_vector;
1253
    constant expected           : in    std_logic_vector;
1254
    signal   pltbutils_sc       : out   pltbutils_sc_t
1255
  ) is
1256
  begin
1257
    v_pltbutils_chk_cnt.inc; -- VHDL-2002
1258
    --v_pltbutils_chk_cnt := v_pltbutils_chk_cnt + 1; -- VHDL-1993
1259
    if data   /= expected   then
1260
      assert false
1261
      report "Check " &
1262
             str(v_pltbutils_chk_cnt.value) & -- VHDL-2002
1263
             --str(v_pltbutils_chk_cnt) & -- VHDL-1993
1264
             "; " & rpt   &
1265
             "; Data=" & str(data) &
1266
             " Expected=" & str(expected) &
1267
             " " & --str('lf') &
1268
             "  in test " &
1269
             str(v_pltbutils_test_num.value) & -- VHDL-2002
1270
             --str(v_pltbutils_test_num) & -- VHDL-1993
1271
             " " &
1272
             v_pltbutils_test_name.value -- VHDL-2002
1273
             --v_pltbutils_test_name -- VHDL-1993
1274
      severity error;
1275
      v_pltbutils_err_cnt.inc; -- VHDL-2002
1276
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
1277
    end if;
1278
    pltbutils_sc_update(pltbutils_sc);
1279
  end procedure check;
1280
 
1281
  -- check std_logic_vector with mask
1282
  procedure check(
1283
    constant rpt                : in    string;
1284
    constant data               : in    std_logic_vector;
1285
    constant expected           : in    std_logic_vector;
1286
    constant mask               : in    std_logic_vector;
1287
    signal   pltbutils_sc       : out   pltbutils_sc_t
1288
  ) is
1289
  begin
1290
    v_pltbutils_chk_cnt.inc; -- VHDL-2002
1291
    --v_pltbutils_chk_cnt := v_pltbutils_chk_cnt + 1; -- VHDL-1993
1292
    if (data  and mask) /= (expected and mask) then
1293
      assert false
1294
      report "Check " &
1295
             str(v_pltbutils_chk_cnt.value) & -- VHDL-2002
1296
             --str(v_pltbutils_chk_cnt) & -- VHDL-1993
1297
             "; " & rpt &
1298
             "; Data=" & str(data) &
1299
             " Expected=" & str(expected) &
1300
             " Mask=" & str(mask) &
1301
             " " & --str('lf') &
1302
             "  in test " &
1303
             str(v_pltbutils_test_num.value) & -- VHDL-2002
1304
             --str(v_pltbutils_test_num) & -- VHDL-1993
1305
             " " &
1306
             v_pltbutils_test_name.value -- VHDL-2002
1307
             --v_pltbutils_test_name -- VHDL-1993
1308
      severity error;
1309
      v_pltbutils_err_cnt.inc; -- VHDL-2002
1310
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
1311
    end if;
1312
    pltbutils_sc_update(pltbutils_sc);
1313
  end procedure check;
1314
 
1315
  -- check std_logic_vector against integer
1316
  procedure check(
1317
    constant rpt                : in    string;
1318
    constant data               : in    std_logic_vector;
1319
    constant expected           : in    integer;
1320
    signal   pltbutils_sc       : out   pltbutils_sc_t
1321
  ) is
1322
  begin
1323
    check(rpt, data, std_logic_vector(to_signed(expected, data'length)), pltbutils_sc);
1324
  end procedure check;
1325
 
1326
  -- check std_logic_vector with mask against integer
1327
  procedure check(
1328
    constant rpt                : in    string;
1329
    constant data               : in    std_logic_vector;
1330
    constant expected           : in    integer;
1331
    constant mask               : in    std_logic_vector;
1332
    signal   pltbutils_sc       : out   pltbutils_sc_t
1333
  ) is
1334
  begin
1335
    check(rpt, data, std_logic_vector(to_signed(expected, data'length)), mask, pltbutils_sc);
1336
  end procedure check;
1337
 
1338
  -- check unsigned
1339
  procedure check(
1340
    constant rpt                : in    string;
1341
    constant data               : in    unsigned;
1342
    constant expected           : in    unsigned;
1343
    signal   pltbutils_sc       : out   pltbutils_sc_t
1344
  ) is
1345
  begin
1346
    v_pltbutils_chk_cnt.inc; -- VHDL-2002
1347
    --v_pltbutils_chk_cnt := v_pltbutils_chk_cnt + 1; -- VHDL-1993
1348
    if data   /= expected   then
1349
      assert false
1350
      report "Check " &
1351
             str(v_pltbutils_chk_cnt.value) & -- VHDL-2002
1352
             --str(v_pltbutils_chk_cnt) & -- VHDL-1993
1353
             "; " & rpt   &
1354
             "; Data=" & str(std_logic_vector(data)) &
1355
             " Expected=" & str(std_logic_vector(expected)) &
1356
             " " & --str('lf') &
1357
             "  in test " &
1358
             str(v_pltbutils_test_num.value) & -- VHDL-2002
1359
             --str(v_pltbutils_test_num) & -- VHDL-1993
1360
             " " &
1361
             v_pltbutils_test_name.value -- VHDL-2002
1362
             --v_pltbutils_test_name -- VHDL-1993
1363
      severity error;
1364
      v_pltbutils_err_cnt.inc; -- VHDL-2002
1365
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
1366
    end if;
1367
    pltbutils_sc_update(pltbutils_sc);
1368
  end procedure check;
1369
 
1370
  -- check unsigned against integer
1371
  procedure check(
1372
    constant rpt                : in    string;
1373
    constant data               : in    unsigned;
1374
    constant expected           : in    integer;
1375
    signal   pltbutils_sc       : out   pltbutils_sc_t
1376
  ) is
1377
  begin
1378
    check(rpt, data, to_unsigned(expected, data'length), pltbutils_sc);
1379
  end procedure check;
1380
 
1381
  -- check signed
1382
  procedure check(
1383
    constant rpt                : in    string;
1384
    constant data               : in    signed;
1385
    constant expected           : in    signed;
1386
    signal   pltbutils_sc       : out   pltbutils_sc_t
1387
  ) is
1388
  begin
1389
    v_pltbutils_chk_cnt.inc; -- VHDL-2002
1390
    --v_pltbutils_chk_cnt := v_pltbutils_chk_cnt + 1; -- VHDL-1993
1391
    if data /= expected   then
1392
      assert false
1393
      report "Check " &
1394
             str(v_pltbutils_chk_cnt.value) & -- VHDL-2002
1395
             --str(v_pltbutils_chk_cnt) & -- VHDL-1993
1396
             "; " & rpt   &
1397
             "; Data=" & str(std_logic_vector(data)) &
1398
             " Expected=" & str(std_logic_vector(expected)) &
1399
             " " & --str('lf') &
1400
             "  in test " &
1401
             str(v_pltbutils_test_num.value) & -- VHDL-2002
1402
             --str(v_pltbutils_test_num) & -- VHDL-1993
1403
             " " &
1404
             v_pltbutils_test_name.value -- VHDL-2002
1405
             --v_pltbutils_test_name -- VHDL-1993
1406
      severity error;
1407
      v_pltbutils_err_cnt.inc; -- VHDL-2002
1408
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
1409
    end if;
1410
    pltbutils_sc_update(pltbutils_sc);
1411
  end procedure check;
1412
 
1413
  -- check signed against integer
1414
  -- TODO: find the bug reported by tb_pltbutils when expected   is negative (-1):
1415
  --       ** Error: (vsim-86) numstd_conv_unsigned_nu: NATURAL arg value is negative (-1)
1416
  procedure check(
1417
    constant rpt                : in    string;
1418
    constant data               : in    signed;
1419
    constant expected           : in    integer;
1420
    signal   pltbutils_sc       : out   pltbutils_sc_t
1421
  ) is
1422
  begin
1423
    check(rpt, data, to_signed(expected, data'length), pltbutils_sc);
1424
  end procedure check;
1425
 
1426
  -- check with boolean expression
1427
  -- Check signal or variable with a boolean expression as argument C_EXPR.
1428
  -- This allowes any kind of check.
1429
  procedure check(
1430
    constant rpt                : in    string;
1431
    constant expr               : in    boolean;
1432
    signal   pltbutils_sc       : out   pltbutils_sc_t
1433
  ) is
1434
  begin
1435
    v_pltbutils_chk_cnt.inc; -- VHDL-2002
1436
    --v_pltbutils_chk_cnt := v_pltbutils_chk_cnt + 1; -- VHDL-1993
1437
    if not expr then
1438
      assert false
1439
      report "Check " &
1440
             str(v_pltbutils_chk_cnt.value) & -- VHDL-2002
1441
             --str(v_pltbutils_chk_cnt) & -- VHDL-1993
1442
             "; " & rpt   &
1443
             " " & --str('lf') &
1444
             "  in test " &
1445
             str(v_pltbutils_test_num.value) & -- VHDL-2002
1446
             --str(v_pltbutils_test_num) & -- VHDL-1993
1447
             " " &
1448
             v_pltbutils_test_name.value -- VHDL-2002
1449
             --v_pltbutils_test_name -- VHDL-1993
1450
      severity error;
1451
      v_pltbutils_err_cnt.inc; -- VHDL-2002
1452
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
1453
    end if;
1454
    pltbutils_sc_update(pltbutils_sc);
1455
  end procedure check;
1456
 
1457
  ----------------------------------------------------------------------------
1458
  -- pltbutils internal procedure(s), called from other pltbutils procedures.
1459
  -- Do not to call this/these from user's code.
1460
  -- This/these procedures are undocumented in the specification on purpose.
1461
  ----------------------------------------------------------------------------
1462
  procedure pltbutils_sc_update(
1463
              signal pltbutils_sc : out pltbutils_sc_t
1464
            ) is
1465
  begin
1466
    -- VHDL-2002:
1467
    pltbutils_sc.test_num   <= v_pltbutils_test_num.value;
1468
    print(pltbutils_sc.test_name, v_pltbutils_test_name.value);
1469
    print(pltbutils_sc.info, v_pltbutils_info.value);
1470
    pltbutils_sc.chk_cnt    <= v_pltbutils_chk_cnt.value;
1471
    pltbutils_sc.err_cnt    <= v_pltbutils_err_cnt.value;
1472
    pltbutils_sc.stop_sim   <= v_pltbutils_stop_sim.value;
1473
    -- VHDL-1993:
1474
    --pltbutils_sc.test_num   <= v_pltbutils_test_num;
1475
    --print(pltbutils_sc.test_name, v_pltbutils_test_name);
1476
    --print(pltbutils_sc.info, v_pltbutils_info);
1477
    --pltbutils_sc.chk_cnt    <= v_pltbutils_chk_cnt;
1478
    --pltbutils_sc.err_cnt    <= v_pltbutils_err_cnt;
1479
    --pltbutils_sc.stop_sim   <= v_pltbutils_stop_sim;
1480
  end procedure pltbutils_sc_update;
1481
 
1482
end package body pltbutils_func_pkg;

powered by: WebSVN 2.1.0

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