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

Subversion Repositories pltbutils

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

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 24 pela
---- Copyright (C) 2013-2014 Authors and OPENCORES.ORG            ----
25 2 pela
----                                                              ----
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 work.txt_util.all;
53 24 pela
use work.pltbutils_user_cfg_pkg.all;
54 2 pela
 
55
package pltbutils_func_pkg is
56
 
57
  -- See the package body for a description of the functions and procedures.
58
  constant C_PLTBUTILS_STRLEN  : natural := 80;
59
  constant C_PLTBUTILS_TIMEOUT : time    := 10 sec;
60
  constant C_WAIT_BEFORE_STOP_TIME : time := 1 us;
61 36 pela
 
62
  -- Type for status- and control variable
63
  type pltbv_t is
64
    record
65
      testcase_name    : string(1 to C_PLTBUTILS_STRLEN);
66
      testcase_name_len: integer;
67
      test_num         : integer;
68
      test_name        : string(1 to C_PLTBUTILS_STRLEN);
69
      test_name_len    : integer;
70
      info             : string(1 to C_PLTBUTILS_STRLEN);
71
      info_len         : integer;
72
      test_cnt         : integer;
73
      chk_cnt          : integer;
74
      err_cnt          : integer;
75
      chk_cnt_in_test  : integer;
76
      err_cnt_in_test  : integer;
77
      stop_sim         : std_logic;
78
    end record;
79
 
80
  constant C_PLTBV_INIT : pltbv_t := (
81
    (others => ' '),   -- testcase_name
82
    1,                 -- testcase_name_len
83
    0,                 -- test_num
84
    (others => ' '),   -- test_name
85
    1,                 -- test_name_len
86
    (others => ' '),   -- info
87
    1,                 -- info_len
88
    0,                 -- test_cnt
89
    0,                 -- chk_cnt
90
    0,                 -- err_cnt
91
    0,                 -- chk_cnt_in_test
92
    0,                 -- err_cnt_in_test
93
    '0'                -- stop_sim
94
  );
95
 
96
  -- Status- and control signal (subset of pltbv_t)
97
  type pltbs_t is
98
    record
99 2 pela
      test_num  : natural;
100
      test_name : string(1 to C_PLTBUTILS_STRLEN);
101
      info      : string(1 to C_PLTBUTILS_STRLEN);
102
      chk_cnt   : natural;
103
      err_cnt   : natural;
104
      stop_sim  : std_logic;
105
    end record;
106 36 pela
 
107
  constant C_PLTBS_INIT : pltbs_t := (
108
    0,                  -- test_num
109
    (others => ' '),    -- test_name    
110
    (others => ' '),    -- info
111
    0,                  -- chk_cnt
112
    0,                  -- err_cnt
113
    '0'                 -- stop_sim
114
  );
115
 
116
  -- startsim
117 2 pela
  procedure startsim(
118
    constant testcase_name      : in    string;
119 36 pela
    variable pltbv              : inout pltbv_t;
120
    signal   pltbs              : out   pltbs_t
121 2 pela
  );
122 36 pela
 
123 2 pela
  -- endsim
124
  procedure endsim(
125 36 pela
    variable pltbv              : inout pltbv_t;
126
    signal   pltbs              : out   pltbs_t;
127
    constant show_success_fail  : in    boolean := false;
128
    constant force              : in    boolean := false
129 2 pela
  );
130 36 pela
 
131 24 pela
  -- starttest
132
  procedure starttest(
133
    constant num                : in    integer := -1;
134
    constant name               : in    string;
135 36 pela
    variable pltbv              : inout pltbv_t;
136
    signal   pltbs              : out   pltbs_t
137 24 pela
  );
138
  procedure starttest(
139
    constant name               : in    string;
140 36 pela
    variable pltbv              : inout pltbv_t;
141
    signal   pltbs              : out   pltbs_t
142 24 pela
  );
143
 
144
  -- endtest
145
  procedure endtest(
146 36 pela
    variable pltbv              : inout pltbv_t;
147
    signal   pltbs              : out   pltbs_t
148 24 pela
  );
149
 
150 2 pela
  -- print, printv, print2
151
  procedure print(
152 6 pela
    constant active             : in    boolean;
153 2 pela
    signal   s                  : out   string;
154
    constant txt                : in    string
155
  );
156 6 pela
  procedure print(
157
    signal   s                  : out   string;
158
    constant txt                : in    string
159
  );
160 2 pela
  procedure printv(
161 6 pela
    constant active             : in    boolean;
162 2 pela
    variable s                  : out   string;
163
    constant txt                : in    string
164
  );
165
  procedure printv(
166 6 pela
    variable s                  : out   string;
167
    constant txt                : in    string
168
  );
169 2 pela
  procedure print(
170 6 pela
    constant active             : in    boolean;
171 36 pela
    variable pltbv              : inout pltbv_t;
172
    signal   pltbs              : out   pltbs_t;
173 2 pela
    constant txt                : in    string
174
  );
175 6 pela
  procedure print(
176 36 pela
    variable pltbv              : inout pltbv_t;
177
    signal   pltbs              : out   pltbs_t;
178 6 pela
    constant txt                : in    string
179
  );
180 2 pela
  procedure print2(
181 6 pela
    constant active             : in    boolean;
182 2 pela
    signal   s                  : out   string;
183
    constant txt                : in    string
184
  );
185
  procedure print2(
186 6 pela
    signal   s                  : out   string;
187
    constant txt                : in    string
188
  );
189
  procedure print2(
190
    constant active             : in    boolean;
191 36 pela
    variable pltbv              : inout pltbv_t;
192
    signal   pltbs              : out   pltbs_t;
193 2 pela
    constant txt                : in    string
194
  );
195 6 pela
  procedure print2(
196 36 pela
    variable pltbv              : inout pltbv_t;
197
    signal   pltbs              : out   pltbs_t;
198 6 pela
    constant txt                : in    string
199
  );
200 2 pela
 
201
  -- waitclks
202
  procedure waitclks(
203
    constant N                  : in    natural;
204
    signal   clk                : in    std_logic;
205 36 pela
    variable pltbv              : inout pltbv_t;
206
    signal   pltbs              : out   pltbs_t;
207 2 pela
    constant falling            : in    boolean := false;
208
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
209
  );
210 36 pela
 
211 6 pela
  -- waitsig
212
  procedure waitsig(
213
    signal   s                  : in    integer;
214
    constant value              : in    integer;
215
    signal   clk                : in    std_logic;
216 36 pela
    variable pltbv              : inout pltbv_t;
217
    signal   pltbs              : out   pltbs_t;
218 6 pela
    constant falling            : in    boolean := false;
219
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
220
  );
221
  procedure waitsig(
222
    signal   s                  : in    std_logic;
223
    constant value              : in    std_logic;
224
    signal   clk                : in    std_logic;
225 36 pela
    variable pltbv              : inout pltbv_t;
226
    signal   pltbs              : out   pltbs_t;
227 6 pela
    constant falling            : in    boolean := false;
228
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
229
  );
230
  procedure waitsig(
231
    signal   s                  : in    std_logic;
232
    constant value              : in    integer;
233
    signal   clk                : in    std_logic;
234 36 pela
    variable pltbv              : inout pltbv_t;
235
    signal   pltbs              : out   pltbs_t;
236 6 pela
    constant falling            : in    boolean := false;
237
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
238 36 pela
  );
239 6 pela
  procedure waitsig(
240
    signal   s                  : in    std_logic_vector;
241
    constant value              : in    std_logic_vector;
242
    signal   clk                : in    std_logic;
243 36 pela
    variable pltbv              : inout pltbv_t;
244
    signal   pltbs              : out   pltbs_t;
245 6 pela
    constant falling            : in    boolean := false;
246
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
247
  );
248
  procedure waitsig(
249
    signal   s                  : in    std_logic_vector;
250
    constant value              : in    integer;
251
    signal   clk                : in    std_logic;
252 36 pela
    variable pltbv              : inout pltbv_t;
253
    signal   pltbs              : out   pltbs_t;
254 6 pela
    constant falling            : in    boolean := false;
255
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
256
  );
257
  procedure waitsig(
258
    signal   s                  : in    unsigned;
259
    constant value              : in    unsigned;
260
    signal   clk                : in    std_logic;
261 36 pela
    variable pltbv              : inout pltbv_t;
262
    signal   pltbs              : out   pltbs_t;
263 6 pela
    constant falling            : in    boolean := false;
264
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
265 36 pela
  );
266 6 pela
  procedure waitsig(
267
    signal   s                  : in    unsigned;
268
    constant value              : in    integer;
269
    signal   clk                : in    std_logic;
270 36 pela
    variable pltbv              : inout pltbv_t;
271
    signal   pltbs              : out   pltbs_t;
272 6 pela
    constant falling            : in    boolean := false;
273
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
274
  );
275
  procedure waitsig(
276
    signal   s                  : in    signed;
277
    constant value              : in    signed;
278
    signal   clk                : in    std_logic;
279 36 pela
    variable pltbv              : inout pltbv_t;
280
    signal   pltbs              : out   pltbs_t;
281 6 pela
    constant falling            : in    boolean := false;
282
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
283
  );
284
  procedure waitsig(
285
    signal   s                  : in    signed;
286
    constant value              : in    integer;
287
    signal   clk                : in    std_logic;
288 36 pela
    variable pltbv              : inout pltbv_t;
289
    signal   pltbs              : out   pltbs_t;
290 6 pela
    constant falling            : in    boolean := false;
291
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
292 36 pela
  );
293
 
294 2 pela
  -- check
295
  procedure check(
296
    constant rpt                : in    string;
297 24 pela
    constant actual             : in    integer;
298 2 pela
    constant expected           : in    integer;
299 36 pela
    variable pltbv              : inout pltbv_t;
300
    signal   pltbs              : out   pltbs_t
301
  );
302 2 pela
  procedure check(
303
    constant rpt                : in    string;
304 24 pela
    constant actual             : in    std_logic;
305 2 pela
    constant expected           : in    std_logic;
306 36 pela
    variable pltbv              : inout pltbv_t;
307
    signal   pltbs              : out   pltbs_t
308
  );
309 2 pela
  procedure check(
310
    constant rpt                : in    string;
311 24 pela
    constant actual             : in    std_logic;
312 2 pela
    constant expected           : in    integer;
313 36 pela
    variable pltbv              : inout pltbv_t;
314
    signal   pltbs              : out   pltbs_t
315
  );
316 2 pela
  procedure check(
317
    constant rpt                : in    string;
318 24 pela
    constant actual             : in    std_logic_vector;
319 2 pela
    constant expected           : in    std_logic_vector;
320 36 pela
    variable pltbv              : inout pltbv_t;
321
    signal   pltbs              : out   pltbs_t
322 2 pela
  );
323
  procedure check(
324
    constant rpt                : in    string;
325 24 pela
    constant actual             : in    std_logic_vector;
326 2 pela
    constant expected           : in    std_logic_vector;
327
    constant mask               : in    std_logic_vector;
328 36 pela
    variable pltbv              : inout pltbv_t;
329
    signal   pltbs              : out   pltbs_t
330 2 pela
  );
331
  procedure check(
332
    constant rpt                : in    string;
333 24 pela
    constant actual             : in    std_logic_vector;
334 2 pela
    constant expected           : in    integer;
335 36 pela
    variable pltbv              : inout pltbv_t;
336
    signal   pltbs              : out   pltbs_t
337
  );
338 2 pela
  procedure check(
339
    constant rpt                : in    string;
340 24 pela
    constant actual             : in    std_logic_vector;
341 2 pela
    constant expected           : in    integer;
342
    constant mask               : in    std_logic_vector;
343 36 pela
    variable pltbv              : inout pltbv_t;
344
    signal   pltbs              : out   pltbs_t
345
  );
346 2 pela
  procedure check(
347
    constant rpt                : in    string;
348 24 pela
    constant actual             : in    unsigned;
349 2 pela
    constant expected           : in    unsigned;
350 36 pela
    variable pltbv              : inout pltbv_t;
351
    signal   pltbs              : out   pltbs_t
352 2 pela
  );
353
  procedure check(
354
    constant rpt                : in    string;
355 24 pela
    constant actual             : in    unsigned;
356 2 pela
    constant expected           : in    integer;
357 36 pela
    variable pltbv              : inout pltbv_t;
358
    signal   pltbs              : out   pltbs_t
359
  );
360 2 pela
  procedure check(
361
    constant rpt                : in    string;
362 24 pela
    constant actual             : in    signed;
363 2 pela
    constant expected           : in    signed;
364 36 pela
    variable pltbv              : inout pltbv_t;
365
    signal   pltbs              : out   pltbs_t
366 2 pela
  );
367
  procedure check(
368
    constant rpt                : in    string;
369 24 pela
    constant actual             : in    signed;
370 2 pela
    constant expected           : in    integer;
371 36 pela
    variable pltbv              : inout pltbv_t;
372
    signal   pltbs              : out   pltbs_t
373
  );
374 2 pela
  procedure check(
375
    constant rpt                : in    string;
376
    constant expr               : in    boolean;
377 36 pela
    variable pltbv              : inout pltbv_t;
378
    signal   pltbs              : out   pltbs_t
379 2 pela
  );
380 24 pela
   procedure check(
381
    constant rpt                : in    string;
382
    constant expr               : in    boolean;
383
    constant actual             : in    string;
384
    constant expected           : in    string;
385
    constant mask               : in    string;
386 36 pela
    variable pltbv              : inout pltbv_t;
387
    signal   pltbs              : out   pltbs_t
388 24 pela
  );
389 36 pela
 
390 14 pela
  -- to_ascending
391
  function to_ascending(
392
    constant s                  : std_logic_vector
393
  ) return std_logic_vector;
394
  function to_ascending(
395
    constant s                  : unsigned
396
  ) return unsigned;
397
  function to_ascending(
398
    constant s                  : signed
399
  ) return signed;
400 2 pela
 
401 14 pela
  -- to_descending
402
  function to_descending(
403
    constant s                  : std_logic_vector
404
  ) return std_logic_vector;
405
  function to_descending(
406
    constant s                  : unsigned
407
  ) return unsigned;
408
  function to_descending(
409
    constant s                  : signed
410
  ) return signed;
411 36 pela
 
412 14 pela
  -- hxstr
413
  function hxstr(
414
    constant s                  : std_logic_vector;
415 24 pela
    constant prefix             : string := "";
416
    constant postfix            : string := ""
417 14 pela
  ) return string;
418
  function hxstr(
419
    constant s                  : unsigned;
420 24 pela
    constant prefix             : string := "";
421
    constant postfix            : string := ""
422 14 pela
  ) return string;
423
  function hxstr(
424
    constant s                  : signed;
425 24 pela
    constant prefix             : string := "";
426
    constant postfix            : string := ""
427 14 pela
  ) return string;
428
 
429 2 pela
  -- pltbutils internal procedure(s), do not call from user's code
430 36 pela
  procedure pltbs_update(
431
    variable pltbv              : inout pltbv_t;
432
    signal   pltbs              : out   pltbs_t
433 2 pela
  );
434 24 pela
 
435 36 pela
  procedure stopsim(
436
    constant timestamp          : in time
437
  );
438
 
439
  procedure pltbutils_error(
440
    constant rpt                : in string;
441
    variable pltbv              : inout pltbv_t;
442
    signal   pltbs              : out   pltbs_t
443
  );
444
 
445 24 pela
  procedure startsim_msg(
446
    constant testcase_name      : in string;
447
    constant timestamp          : in time
448
  );
449 36 pela
 
450 24 pela
  procedure endsim_msg(
451
    constant testcase_name      : in string;
452
    constant timestamp          : in time;
453
    constant num_tests          : in integer;
454
    constant num_checks         : in integer;
455
    constant num_errors         : in integer;
456
    constant show_success_fail  : in boolean
457
  );
458 36 pela
 
459 24 pela
  procedure starttest_msg(
460
    constant test_num           : in integer;
461
    constant test_name          : in string;
462
    constant timestamp          : in time
463
  );
464 36 pela
 
465 24 pela
  procedure endtest_msg(
466
    constant test_num           : in integer;
467
    constant test_name          : in string;
468
    constant timestamp          : in time;
469
    constant num_checks_in_test : in integer;
470
    constant num_errors_in_test : in integer
471 36 pela
  );
472
 
473 24 pela
  procedure check_msg(
474
    constant rpt                : in string;
475 36 pela
    constant timestamp          : in time;
476
    constant expr               : in boolean;
477 24 pela
    constant actual             : in string;
478
    constant expected           : in string;
479
    constant mask               : in string;
480 36 pela
    constant test_num           : in integer;
481 24 pela
    constant test_name          : in string;
482
    constant check_num          : in integer;
483
    constant err_cnt_in_test    : in integer
484
  );
485
 
486
  procedure error_msg(
487
    constant rpt                : in string;
488
    constant timestamp          : in time;
489 36 pela
    constant test_num           : in integer;
490 24 pela
    constant test_name          : in string;
491
    constant err_cnt_in_test    : in integer
492
  );
493 36 pela
 
494 2 pela
end package pltbutils_func_pkg;
495
 
496
package body pltbutils_func_pkg is
497
 
498
  ----------------------------------------------------------------------------
499
  -- startsim
500
  --
501
  -- procedure startsim(
502
  --   constant testcase_name      : in    string;
503 36 pela
  --   variable pltbv              : inout pltbv_t;
504
  --   signal   pltbs              : out   pltbs_t
505 2 pela
  -- )
506
  --
507
  -- Displays a message at start of simulation message, and initializes
508 36 pela
  -- PlTbUtils' status and control variable and -signal.
509 2 pela
  -- Call startsim() only once.
510
  --
511
  -- Arguments:
512
  --   testcase_name            Name of the test case, e.g. "tc1".
513
  --
514 36 pela
  --   pltbv, pltbs             PlTbUtils' status- and control variable and
515
  --                            -signal.
516 2 pela
  --
517
  -- NOTE:
518
  -- The start-of-simulation message is not only intended to be informative
519
  -- for humans. It is also intended to be searched for by scripts,
520
  -- e.g. for collecting results from a large number of regression tests.
521
  -- For this reason, the message must be consistent and unique.
522
  --
523
  -- DO NOT MODIFY the message "--- START OF SIMULATION ---".
524
  -- DO NOT OUTPUT AN IDENTICAL MESSAGE anywhere else.
525
  --
526
  -- Example:
527 36 pela
  -- startsim("tc1", pltbv, pltbs);
528 2 pela
  ----------------------------------------------------------------------------
529
  procedure startsim(
530
    constant testcase_name      : in    string;
531 36 pela
    variable pltbv              : inout pltbv_t;
532
    signal   pltbs              : out   pltbs_t
533 2 pela
  ) is
534 36 pela
    variable timestamp          : time;
535 2 pela
  begin
536 24 pela
    timestamp := now;
537 36 pela
    pltbv := C_PLTBV_INIT;
538
    printv(pltbv.testcase_name, testcase_name);
539
    pltbv.testcase_name_len := testcase_name'length;
540
    printv(pltbv.test_name, "START OF SIMULATION");
541
    pltbv.test_name_len     := 19;
542
    printv(pltbv.info, testcase_name);
543
    pltbv.info_len          := testcase_name'length;
544
    pltbs_update(pltbv, pltbs);
545 24 pela
    if C_PLTBUTILS_USE_STD_STARTSIM_MSG then
546
      startsim_msg(testcase_name, timestamp);
547
    end if;
548
    if C_PLTBUTILS_USE_CUSTOM_STARTSIM_MSG then
549
      custom_startsim_msg(testcase_name, timestamp);
550
    end if;
551 2 pela
  end procedure startsim;
552
 
553
  ----------------------------------------------------------------------------
554
  -- endsim
555
  --
556
  -- procedure endsim(
557 36 pela
  --   variable pltbv              : inout pltbv_t;
558
  --   signal   pltbs              : out   pltbs_t;
559 2 pela
  --   constant show_success_fail  : in  boolean := false;
560
  --   constant force              : in  boolean := false
561
  -- )
562
  --
563
  -- Displays a message at end of simulation message, presents the simulation
564 36 pela
  -- results, and stops the simulation.
565 2 pela
  -- Call endsim() it only once.
566
  --
567 36 pela
  -- Arguments:
568
  --   pltbv, pltbs             PlTbUtils' status- and control variable and
569
  --                            -signal.
570 2 pela
  --
571 36 pela
  --   show_success_fail        If true, endsim() shows "*** SUCCESS ***",
572 2 pela
  --                            "*** FAIL ***", or "*** NO CHECKS ***".
573
  --                            Optional, default is false.
574
  --
575
  --   force                    If true, forces the simulation to stop using an
576
  --                            assert failure statement. Use this option only
577
  --                            if the normal way of stopping the simulation
578
  --                            doesn't work (see below).
579
  --                            Optional, default is false.
580
  --
581
  -- The testbench should be designed so that all clocks stop when endsim()
582 36 pela
  -- sets the signal pltbs.stop_sim to '1'. This should stop the simulator.
583
  -- In some cases that doesn't work, then set the force argument to true, which
584 2 pela
  -- causes a false assert failure, which should stop the simulator.
585
  -- Scripts searching transcript logs for errors and failures, should ignore
586
  -- the failure with "--- FORCE END OF SIMULATION ---" as part of the report.
587
  --
588
  -- NOTE:
589
  -- The end-of-simulation messages and success/fail messages are not only
590
  -- intended to be informative for humans. They are also intended to be
591
  -- searched for by scripts, e.g. for collecting results from a large number
592
  -- of regression tests.
593
  -- For this reason, the message must be consistent and unique.
594
  --
595 36 pela
  -- DO NOT MODIFY the messages "--- END OF SIMULATION ---",
596 2 pela
  -- "*** SUCCESS ***", "*** FAIL ***", "*** NO CHECKS ***".
597
  -- DO NOT OUTPUT IDENTICAL MESSAGES anywhere else.
598
  --
599
  -- Examples:
600 36 pela
  -- endsim(pltbv, pltbs);
601
  -- endsim(pltbv, pltbs, true);
602
  -- endsim(pltbv, pltbs, true, true);
603 2 pela
  ----------------------------------------------------------------------------
604
  procedure endsim(
605 36 pela
    variable pltbv              : inout pltbv_t;
606
    signal   pltbs              : out   pltbs_t;
607
    constant show_success_fail  : in    boolean := false;
608
    constant force              : in    boolean := false
609 2 pela
  ) is
610 24 pela
    variable timestamp : time;
611 2 pela
  begin
612 24 pela
    timestamp := now;
613
    if C_PLTBUTILS_USE_STD_ENDSIM_MSG then
614 36 pela
      endsim_msg(pltbv.testcase_name(1 to pltbv.testcase_name_len), timestamp,
615
        pltbv.test_cnt, pltbv.chk_cnt, pltbv.err_cnt, show_success_fail);
616 24 pela
    end if;
617
    if C_PLTBUTILS_USE_CUSTOM_ENDSIM_MSG then
618 36 pela
      custom_endsim_msg(pltbv.testcase_name(1 to pltbv.testcase_name_len), timestamp,
619
        pltbv.test_cnt, pltbv.chk_cnt, pltbv.err_cnt, show_success_fail);
620 24 pela
    end if;
621 36 pela
    pltbv.test_num      := 0;
622
    printv(pltbv.test_name, "END OF SIMULATION");
623
    pltbv.test_name_len := 17;
624
    pltbv.stop_sim      := '1';
625
    pltbs_update(pltbv, pltbs);
626 2 pela
    wait for C_WAIT_BEFORE_STOP_TIME;
627 24 pela
    if force then
628
      if C_PLTBUTILS_USE_STD_STOPSIM then
629
        stopsim(now);
630
      end if;
631
      if C_PLTBUTILS_USE_CUSTOM_STOPSIM then
632
        custom_stopsim(now);
633
      end if;
634
    end if;
635 2 pela
    wait;
636
  end procedure endsim;
637
 
638
  ----------------------------------------------------------------------------
639 24 pela
  -- starttest
640 2 pela
  --
641 24 pela
  -- procedure starttest(
642 2 pela
  --   constant num                : in    integer := -1;
643
  --   constant name               : in    string;
644 36 pela
  --   variable pltbv              : inout pltbv_t;
645
  --   signal   pltbs              : out   pltbs_t
646
  -- )
647 2 pela
  --
648
  -- Sets a number (optional) and a name for a test. The number and name will
649
  -- be printed to the screen, and displayed in the simulator's waveform
650 36 pela
  -- window.
651 2 pela
  -- The test number and name is also included if there errors reported by the
652
  -- check() procedure calls.
653
  --
654 36 pela
  -- Arguments:
655 2 pela
  --   num                      Test number. Optional, default is to increment
656
  --                            the current test number.
657
  --
658
  --   name                     Test name.
659
  --
660 36 pela
  --   pltbv, pltbs             PlTbUtils' status- and control variable and
661
  --                            -signal.
662 2 pela
  --
663
  -- If the test number is omitted, a new test number is automatically
664 36 pela
  -- computed by incrementing the current test number.
665 2 pela
  -- Manually setting the test number may make it easier to find the test code
666
  -- in the testbench code, though.
667
  --
668
  -- Examples:
669 36 pela
  -- starttest("Reset test", pltbv, pltbs);
670
  -- starttest(1, "Reset test", pltbv, pltbs);
671 2 pela
  ----------------------------------------------------------------------------
672 24 pela
  procedure starttest(
673 2 pela
    constant num                : in    integer := -1;
674
    constant name               : in    string;
675 36 pela
    variable pltbv              : inout pltbv_t;
676
    signal   pltbs              : out   pltbs_t
677 2 pela
  ) is
678 24 pela
    variable timestamp : time;
679 2 pela
  begin
680 24 pela
    timestamp := now;
681 2 pela
    if num = -1 then
682 36 pela
      pltbv.test_num := pltbv.test_num + 1;
683 2 pela
    else
684 36 pela
      pltbv.test_num := num;
685 2 pela
    end if;
686 36 pela
    printv(pltbv.test_name, name);
687
    pltbv.test_name_len := name'length;
688
    pltbv.test_cnt := pltbv.test_cnt + 1;
689
    pltbv.chk_cnt_in_test := 0;
690
    pltbv.err_cnt_in_test := 0;
691
    pltbs_update(pltbv, pltbs);
692 24 pela
    if C_PLTBUTILS_USE_STD_STARTTEST_MSG then
693 36 pela
     starttest_msg(pltbv.test_num, name, timestamp);
694 24 pela
    end if;
695
    if C_PLTBUTILS_USE_CUSTOM_STARTTEST_MSG then
696 36 pela
     custom_starttest_msg(pltbv.test_num, name, timestamp);
697 24 pela
    end if;
698
  end procedure starttest;
699 36 pela
 
700 24 pela
  procedure starttest(
701
    constant name               : in    string;
702 36 pela
    variable pltbv              : inout pltbv_t;
703
    signal   pltbs              : out   pltbs_t
704 24 pela
  ) is
705
  begin
706 36 pela
    starttest(-1, name, pltbv, pltbs);
707 24 pela
  end procedure starttest;
708 36 pela
 
709 2 pela
  ----------------------------------------------------------------------------
710 24 pela
  -- endtest
711
  --
712
  -- procedure endtest(
713 36 pela
  --   variable pltbv              : inout pltbv_t;
714
  --   signal   pltbs              : out   pltbs_t
715
  -- )
716 24 pela
  --
717
  -- Prints an end-of-test message to the screen.
718
  --
719 36 pela
  -- Arguments:
720
  --   pltbv, pltbs             PlTbUtils' status- and control variable and
721
  --                            -signal.
722 24 pela
  --
723
  -- Example:
724 36 pela
  -- endtest(pltbv, pltbs);
725 24 pela
  ----------------------------------------------------------------------------
726
  procedure endtest(
727 36 pela
    variable pltbv              : inout pltbv_t;
728
    signal   pltbs              : out   pltbs_t
729 24 pela
  ) is
730
    variable timestamp : time;
731
  begin
732
    timestamp := now;
733
    if C_PLTBUTILS_USE_STD_ENDTEST_MSG then
734 36 pela
      endtest_msg(pltbv.test_num, pltbv.test_name(1 to pltbv.test_name_len),
735
        timestamp, pltbv.chk_cnt_in_test, pltbv.err_cnt_in_test);
736
    end if;
737 24 pela
    if C_PLTBUTILS_USE_CUSTOM_ENDTEST_MSG then
738 36 pela
      custom_endtest_msg(pltbv.test_num, pltbv.test_name(1 to pltbv.test_name_len),
739
        timestamp, pltbv.chk_cnt_in_test, pltbv.err_cnt_in_test);
740
    end if;
741
    printv(pltbv.test_name, " ");
742
    pltbv.test_name_len := 1;
743
    pltbs_update(pltbv, pltbs);
744
  end procedure endtest;
745 24 pela
 
746
  ----------------------------------------------------------------------------
747 2 pela
  -- print printv print2
748
  --
749 36 pela
  -- procedure print(
750 2 pela
  --   signal   s                  : out   string;
751
  --   constant txt                : in    string
752 36 pela
  -- )
753 2 pela
  --
754 36 pela
  -- procedure print(
755 6 pela
  --   constant active             : in    boolean;
756
  --   signal   s                  : out   string;
757
  --   constant txt                : in    string
758 36 pela
  -- )
759 6 pela
  --
760 2 pela
  -- procedure print(
761 36 pela
  --   variable pltbv              : inout pltbv_t;
762
  --   signal   pltbs              : out   pltbs_t;
763 2 pela
  --   constant txt                : in    string
764
  -- )
765
  --
766 6 pela
  -- procedure print(
767
  --   constant active             : in    boolean;
768 36 pela
  --   variable pltbv              : inout pltbv_t;
769
  --   signal   pltbs              : out   pltbs_t;
770 6 pela
  --   constant txt                : in    string
771
  -- )
772
  --
773 2 pela
  -- procedure printv(
774
  --   variable s                  : out   string;
775
  --   constant txt                : in    string
776
  -- )
777
  --
778 6 pela
  -- procedure printv(
779
  --   constant active             : in    boolean;
780
  --   variable s                  : out   string;
781
  --   constant txt                : in    string
782
  -- )
783
  --
784 36 pela
  -- procedure print2(
785 2 pela
  --   signal   s                  : out   string;
786
  --   constant txt                : in    string
787
  -- )
788
  --
789 36 pela
  -- procedure print2(
790 6 pela
  --   constant active             : in    boolean;
791
  --   signal   s                  : out   string;
792
  --   constant txt                : in    string
793
  -- )
794
  --
795 36 pela
  -- procedure print2(
796
  --   variable pltbv              : inout pltbv_t;
797
  --   signal   pltbs              : out   pltbs_t;
798 2 pela
  --   constant txt                : in    string
799
  -- )
800
  --
801 36 pela
  -- procedure print2(
802 6 pela
  --   constant active             : in    boolean;
803 36 pela
  --   variable pltbv              : inout pltbv_t;
804
  --   signal   pltbs              : out   pltbs_t;
805 6 pela
  --   constant txt                : in    string
806
  -- )
807
  --
808 2 pela
  -- print() prints text messages to a signal for viewing in the simulator's
809
  -- waveform window. printv() does the same thing, but to a variable instead.
810 36 pela
  -- print2() prints both to a signal and to the transcript window.
811
  -- The type of the output can be string or pltbv_t+pltbs_t.
812 2 pela
  --
813 36 pela
  -- Arguments:
814
  --   s                        Signal or variable of type string to be
815 2 pela
  --                            printed to.
816
  --
817
  --   txt                      The text.
818
  --
819 6 pela
  --   active                   The text is only printed if active is true.
820
  --                            Useful for debug switches, etc.
821
  --
822 36 pela
  --   pltbv, pltbs             PlTbUtils' status- and control variable and
823
  --                            -signal.
824 2 pela
  --
825 36 pela
  -- If the string txt is longer than the signal s, the text will be truncated.
826
  -- If txt is shorter, s will be padded with spaces.
827 2 pela
  --
828
  -- Examples:
829
  -- print(msg, "Hello, world"); -- Prints to signal msg
830 36 pela
  -- print(G_DEBUG, msg, "Hello, world"); -- Prints to signal msg if
831 6 pela
  --                                      -- generic G_DEBUG is true
832 2 pela
  -- printv(v_msg, "Hello, world"); -- Prints to variable msg
833 36 pela
  -- print(pltbv, pltbs, "Hello, world"); -- Prints to "info" in waveform window
834
  -- print2(msg, "Hello, world"); -- Prints to signal and transcript window
835
  -- print2(pltbv, pltbs, "Hello, world"); -- Prints to "info" in waveform and
836 2 pela
  --                                      -- transcript windows
837
  ----------------------------------------------------------------------------
838
  procedure print(
839 6 pela
    constant active             : in    boolean;
840 2 pela
    signal   s                  : out   string;
841
    constant txt                : in    string
842
  ) is
843
    variable j : positive := txt 'low;
844
  begin
845 6 pela
    if active then
846
      for i in s'range loop
847
        if j <= txt 'high then
848
          s(i) <= txt (j);
849
        else
850
          s(i) <= ' ';
851
        end if;
852
        j := j + 1;
853
      end loop;
854
    end if;
855 2 pela
  end procedure print;
856 36 pela
 
857 6 pela
  procedure print(
858
    signal   s                  : out   string;
859
    constant txt                : in    string
860
  ) is
861
  begin
862
    print(true, s, txt);
863
  end procedure print;
864 36 pela
 
865 2 pela
  procedure printv(
866 6 pela
    constant active             : in    boolean;
867 2 pela
    variable s                  : out   string;
868
    constant txt                : in    string
869
  ) is
870
    variable j : positive := txt 'low;
871
  begin
872 6 pela
    if active then
873
      for i in s'range loop
874
        if j <= txt 'high then
875
          s(i) := txt (j);
876
        else
877
          s(i) := ' ';
878
        end if;
879
        j := j + 1;
880
      end loop;
881
    end if;
882 2 pela
  end procedure printv;
883 36 pela
 
884 6 pela
  procedure printv(
885
    variable s                  : out   string;
886
    constant txt                : in    string
887
  ) is
888
  begin
889
    printv(true, s, txt);
890 2 pela
  end procedure printv;
891
 
892 36 pela
  -- Print to info element in pltbv/pltbs, which shows up in waveform window
893 2 pela
  procedure print(
894 6 pela
    constant active             : in    boolean;
895 36 pela
    variable pltbv              : inout pltbv_t;
896
    signal   pltbs              : out   pltbs_t;
897 2 pela
    constant txt                : in    string
898
  ) is
899
    variable j : positive := txt 'low;
900
  begin
901 6 pela
    if active then
902 36 pela
      printv(pltbv.info, txt);
903
      pltbv.info_len := txt'length;
904
      pltbs_update(pltbv, pltbs);
905 6 pela
    end if;
906 2 pela
  end procedure print;
907 6 pela
 
908
  procedure print(
909 36 pela
    variable pltbv              : inout pltbv_t;
910
    signal   pltbs              : out   pltbs_t;
911 6 pela
    constant txt                : in    string
912
  ) is
913
  begin
914 36 pela
    print(true, pltbv, pltbs, txt);
915
  end procedure print;
916
 
917 2 pela
  procedure print2(
918 6 pela
    constant active             : in    boolean;
919 2 pela
    signal   s                  : out   string;
920
    constant txt                : in    string
921
  ) is
922
  begin
923 36 pela
    if active then
924
      print(s, txt);
925 6 pela
      print(txt);
926
    end if;
927 2 pela
  end procedure print2;
928
 
929
  procedure print2(
930 6 pela
    signal   s                  : out   string;
931
    constant txt                : in    string
932
  ) is
933
  begin
934
    print(true, s, txt);
935 36 pela
  end procedure print2;
936
 
937 6 pela
  procedure print2(
938
    constant active             : in    boolean;
939 36 pela
    variable pltbv              : inout pltbv_t;
940
    signal   pltbs              : out   pltbs_t;
941 2 pela
    constant txt                : in    string
942
  ) is
943
  begin
944 36 pela
    print(active, pltbv, pltbs, txt);
945
    print(active, txt);
946 2 pela
  end procedure print2;
947
 
948 6 pela
  procedure print2(
949 36 pela
    variable pltbv              : inout pltbv_t;
950
    signal   pltbs              : out   pltbs_t;
951 6 pela
    constant txt                : in    string
952
  ) is
953
  begin
954 36 pela
    print(true, pltbv, pltbs, txt);
955
  end procedure print2;
956 6 pela
 
957 2 pela
  ----------------------------------------------------------------------------
958
  -- waitclks
959
  --
960
  -- procedure waitclks(
961
  --   constant n                  : in    natural;
962
  --   signal   clk                : in    std_logic;
963 36 pela
  --   variable pltbv              : inout pltbv_t;
964
  --   signal   pltbs              : out   pltbs_t;
965 2 pela
  --   constant falling            : in    boolean := false;
966
  --   constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
967
  -- )
968
  --
969
  -- Waits specified amount of clock cycles of the specified clock.
970
  -- Or, to be more precise, a specified number of specified clock edges of
971
  -- the specified clock.
972
  --
973 36 pela
  -- Arguments:
974 2 pela
  --   n                        Number of rising or falling clock edges to wait.
975
  --
976
  --   clk                      The clock to wait for.
977
  --
978 36 pela
  --   pltbv, pltbs             PlTbUtils' status- and control variable and
979
  --                            -signal.
980 2 pela
  --
981
  --   falling                  If true, waits for falling edges, otherwise
982
  --                            rising edges. Optional, default is false.
983
  --
984
  --   timeout                  Timeout time, in case the clock is not working.
985 36 pela
  --                            Optional, default is C_PLTBUTILS_TIMEOUT.
986 2 pela
  --
987
  -- Examples:
988 36 pela
  -- waitclks(5, sys_clk, pltbv, pltbs);
989
  -- waitclks(5, sys_clk, pltbv, pltbs true);
990
  -- waitclks(5, sys_clk, pltbv, pltbs, true, 1 ms);
991 2 pela
  ----------------------------------------------------------------------------
992
  procedure waitclks(
993
    constant n                  : in    natural;
994
    signal   clk                : in    std_logic;
995 36 pela
    variable pltbv              : inout pltbv_t;
996
    signal   pltbs              : out   pltbs_t;
997 2 pela
    constant falling            : in    boolean := false;
998
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
999
  ) is
1000
    variable i                  : natural := n;
1001
    variable v_timeout_time     : time;
1002
  begin
1003
    v_timeout_time := now + timeout;
1004
    while i > 0 loop
1005 6 pela
      if falling then
1006 2 pela
        wait until falling_edge(clk) for timeout / n;
1007
      else
1008
        wait until rising_edge(clk)  for timeout / n;
1009
      end if;
1010
      i := i - 1;
1011
    end loop;
1012
    if now >= v_timeout_time then
1013 36 pela
      pltbutils_error("waitclks() timeout", pltbv, pltbs);
1014 2 pela
    end if;
1015
  end procedure waitclks;
1016 36 pela
 
1017 6 pela
  ----------------------------------------------------------------------------
1018
  -- waitsig
1019
  --
1020
  -- procedure waitsig(
1021
  --   signal   s                  : in    integer|std_logic|std_logic_vector|unsigned|signed;
1022
  --   constant value              : in    integer|std_logic|std_logic_vector|unsigned|signed;
1023
  --   signal   clk                : in    std_logic;
1024 36 pela
  --   variable pltbv              : inout pltbv_t;
1025
  --   signal   pltbs              : out   pltbs_t;
1026 6 pela
  --   constant falling            : in    boolean := false;
1027
  --   constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
1028
  -- )
1029
  --
1030
  -- Waits until a signal has reached a specified value after specified clock
1031
  -- edge.
1032
  --
1033 36 pela
  -- Arguments:
1034 6 pela
  --   s                        The signal to test.
1035 36 pela
  --                            Supported types: integer, std_logic,
1036 6 pela
  --                            std_logic_vector, unsigned, signed.
1037
  --
1038
  --   value                    Value to wait for.
1039
  --                            Same type as data or integer.
1040
  --
1041
  --   clk                      The clock.
1042
  --
1043 36 pela
  --   pltbv, pltbs             PlTbUtils' status- and control variable and
1044
  --                            -signal.
1045 6 pela
  --
1046
  --   falling                  If true, waits for falling edges, otherwise
1047
  --                            rising edges. Optional, default is false.
1048
  --
1049
  --   timeout                  Timeout time, in case the clock is not working.
1050 36 pela
  --                            Optional, default is C_PLTBUTILS_TIMEOUT.
1051 6 pela
  --
1052
  -- Examples:
1053 36 pela
  -- waitsig(wr_en, '1', sys_clk, pltbv, pltbs);
1054
  -- waitsig(rd_en,   1, sys_clk, pltbv, pltbs, true);
1055
  -- waitclks(full, '1', sys_clk, pltbv, pltbs, true, 1 ms);
1056
  ----------------------------------------------------------------------------
1057 6 pela
  procedure waitsig(
1058
    signal   s                  : in    integer;
1059
    constant value              : in    integer;
1060
    signal   clk                : in    std_logic;
1061 36 pela
    variable pltbv              : inout pltbv_t;
1062
    signal   pltbs              : out   pltbs_t;
1063 6 pela
    constant falling            : in    boolean := false;
1064
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
1065
  ) is
1066
    variable v_timeout_time     : time;
1067
  begin
1068
    v_timeout_time := now + timeout;
1069
    l1 : loop
1070 36 pela
      waitclks(1, clk, pltbv, pltbs, falling, timeout);
1071 6 pela
      exit l1 when s = value or now >= v_timeout_time;
1072
    end loop;
1073
    if now >= v_timeout_time then
1074 36 pela
      pltbutils_error("waitsig() timeout", pltbv, pltbs);
1075 6 pela
    end if;
1076
  end procedure waitsig;
1077
 
1078
  procedure waitsig(
1079
    signal   s                  : in    std_logic;
1080
    constant value              : in    std_logic;
1081
    signal   clk                : in    std_logic;
1082 36 pela
    variable pltbv              : inout pltbv_t;
1083
    signal   pltbs              : out   pltbs_t;
1084 6 pela
    constant falling            : in    boolean := false;
1085
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
1086
  ) is
1087
    variable v_timeout_time     : time;
1088
  begin
1089
    v_timeout_time := now + timeout;
1090
    l1 : loop
1091 36 pela
      waitclks(1, clk, pltbv, pltbs, falling, timeout);
1092 6 pela
      exit l1 when s = value or now >= v_timeout_time;
1093
    end loop;
1094
    if now >= v_timeout_time then
1095 36 pela
      pltbutils_error("waitsig() timeout", pltbv, pltbs);
1096 6 pela
    end if;
1097
  end procedure waitsig;
1098 36 pela
 
1099 6 pela
  procedure waitsig(
1100
    signal   s                  : in    std_logic;
1101
    constant value              : in    integer;
1102
    signal   clk                : in    std_logic;
1103 36 pela
    variable pltbv              : inout pltbv_t;
1104
    signal   pltbs              : out   pltbs_t;
1105 6 pela
    constant falling            : in    boolean := false;
1106
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
1107
  ) is
1108
    variable v_value            : std_logic;
1109
    variable v_timeout_time     : time;
1110
  begin
1111
    case value is
1112
      when 0      => v_value := '0';
1113
      when 1      => v_value := '1';
1114
      when others => v_value := 'X';
1115
    end case;
1116
    if v_value /= 'X' then
1117 36 pela
      waitsig(s, v_value, clk, pltbv, pltbs, falling, timeout);
1118 6 pela
    else
1119 36 pela
      pltbutils_error("waitsig() timeout", pltbv, pltbs);
1120 6 pela
    end if;
1121 36 pela
  end procedure waitsig;
1122
 
1123 6 pela
  procedure waitsig(
1124
    signal   s                  : in    std_logic_vector;
1125
    constant value              : in    std_logic_vector;
1126
    signal   clk                : in    std_logic;
1127 36 pela
    variable pltbv              : inout pltbv_t;
1128
    signal   pltbs              : out   pltbs_t;
1129 6 pela
    constant falling            : in    boolean := false;
1130
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
1131
  ) is
1132
    variable v_timeout_time     : time;
1133
  begin
1134
    v_timeout_time := now + timeout;
1135
    l1 : loop
1136 36 pela
      waitclks(1, clk, pltbv, pltbs, falling, timeout);
1137 6 pela
      exit l1 when s = value or now >= v_timeout_time;
1138
    end loop;
1139
    if now >= v_timeout_time then
1140 36 pela
      pltbutils_error("waitsig() timeout", pltbv, pltbs);
1141 6 pela
    end if;
1142 36 pela
  end procedure waitsig;
1143 6 pela
 
1144
  procedure waitsig(
1145
    signal   s                  : in    std_logic_vector;
1146
    constant value              : in    integer;
1147
    signal   clk                : in    std_logic;
1148 36 pela
    variable pltbv              : inout pltbv_t;
1149
    signal   pltbs              : out   pltbs_t;
1150 6 pela
    constant falling            : in    boolean := false;
1151
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
1152
  ) is
1153
    variable v_timeout_time     : time;
1154
  begin
1155 36 pela
    waitsig(s, std_logic_vector(to_unsigned(value, s'length)), clk,
1156
            pltbv, pltbs, falling, timeout);
1157
  end procedure waitsig;
1158
 
1159 6 pela
  procedure waitsig(
1160
    signal   s                  : in    unsigned;
1161
    constant value              : in    unsigned;
1162
    signal   clk                : in    std_logic;
1163 36 pela
    variable pltbv              : inout pltbv_t;
1164
    signal   pltbs              : out   pltbs_t;
1165 6 pela
    constant falling            : in    boolean := false;
1166
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
1167
  ) is
1168
    variable v_timeout_time     : time;
1169
  begin
1170
    v_timeout_time := now + timeout;
1171
    l1 : loop
1172 36 pela
      waitclks(1, clk, pltbv, pltbs, falling, timeout);
1173 6 pela
      exit l1 when s = value or now >= v_timeout_time;
1174
    end loop;
1175
    if now >= v_timeout_time then
1176 36 pela
      pltbutils_error("waitsig() timeout", pltbv, pltbs);
1177 6 pela
    end if;
1178 36 pela
  end procedure waitsig;
1179
 
1180 6 pela
  procedure waitsig(
1181
    signal   s                  : in    unsigned;
1182
    constant value              : in    integer;
1183
    signal   clk                : in    std_logic;
1184 36 pela
    variable pltbv              : inout pltbv_t;
1185
    signal   pltbs              : out   pltbs_t;
1186 6 pela
    constant falling            : in    boolean := false;
1187
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
1188
  ) is
1189
    variable v_timeout_time     : time;
1190
  begin
1191 36 pela
    waitsig(s, to_unsigned(value, s'length), clk,
1192
            pltbv, pltbs, falling, timeout);
1193
  end procedure waitsig;
1194
 
1195 6 pela
  procedure waitsig(
1196
    signal   s                  : in    signed;
1197
    constant value              : in    signed;
1198
    signal   clk                : in    std_logic;
1199 36 pela
    variable pltbv              : inout pltbv_t;
1200
    signal   pltbs              : out   pltbs_t;
1201 6 pela
    constant falling            : in    boolean := false;
1202
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
1203
  ) is
1204
    variable v_timeout_time     : time;
1205
  begin
1206
    v_timeout_time := now + timeout;
1207
    l1 : loop
1208 36 pela
      waitclks(1, clk, pltbv, pltbs, falling, timeout);
1209 6 pela
      exit l1 when s = value or now >= v_timeout_time;
1210
    end loop;
1211
    if now >= v_timeout_time then
1212 36 pela
      pltbutils_error("waitsig() timeout", pltbv, pltbs);
1213 6 pela
    end if;
1214 36 pela
  end procedure waitsig;
1215 6 pela
 
1216
  procedure waitsig(
1217
    signal   s                  : in    signed;
1218
    constant value              : in    integer;
1219
    signal   clk                : in    std_logic;
1220 36 pela
    variable pltbv              : inout pltbv_t;
1221
    signal   pltbs              : out   pltbs_t;
1222 6 pela
    constant falling            : in    boolean := false;
1223
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
1224
  ) is
1225
    variable v_timeout_time     : time;
1226
  begin
1227 36 pela
    waitsig(s, to_signed(value, s'length), clk,
1228
            pltbv, pltbs, falling, timeout);
1229
  end procedure waitsig;
1230
 
1231 2 pela
  ----------------------------------------------------------------------------
1232
  -- check
1233
  --
1234
  -- procedure check(
1235 36 pela
  --   constant rpt             : in    string;
1236
  --   constant actual          : in    integer|std_logic|std_logic_vector|unsigned|signed;
1237
  --   constant expected        : in    integer|std_logic|std_logic_vector|unsigned|signed;
1238
  --   variable pltbv           : inout pltbv_t;
1239
  --   signal   pltbs           : out   pltbs_t
1240
  -- )
1241 2 pela
  --
1242
  -- procedure check(
1243 36 pela
  --   constant rpt             : in    string;
1244
  --   constant actual          : in    std_logic_vector;
1245
  --   constant expected        : in    std_logic_vector;
1246
  --   constant mask            : in    std_logic_vector;
1247
  --   variable pltbv           : inout pltbv_t;
1248
  --   signal   pltbs           : out   pltbs_t
1249
  -- )
1250 2 pela
  --
1251
  -- procedure check(
1252 36 pela
  --   constant rpt             : in    string;
1253
  --   constant expr            : in    boolean;
1254
  --   variable pltbv           : inout pltbv_t;
1255
  --   signal   pltbs           : out   pltbs_t
1256 2 pela
  -- )
1257
  --
1258
  -- Checks that the value of a signal or variable is equal to expected.
1259
  -- If not equal, displays an error message and increments the error counter.
1260
  --
1261 36 pela
  -- Arguments:
1262
  --   rpt                      Report message to be displayed in case of
1263
  --                            mismatch.
1264 2 pela
  --                            It is recommended that the message is unique
1265
  --                            and that it contains the name of the signal
1266 36 pela
  --                            or variable being checked.
1267
  --                            The message should NOT contain the expected
1268
  --                            value, becase check() prints that
1269 2 pela
  --                            automatically.
1270
  --
1271 24 pela
  --   actual                   The signal or variable to be checked.
1272 36 pela
  --                            Supported types: integer, std_logic,
1273 2 pela
  --                            std_logic_vector, unsigned, signed.
1274
  --
1275 36 pela
  --   expected                 Expected value.
1276 2 pela
  --                            Same type as data or integer.
1277
  --
1278 36 pela
  --   mask                     Bit mask and:ed to data and expected
1279 2 pela
  --                            before comparison.
1280
  --                            Optional if data is std_logic_vector.
1281
  --                            Not allowed for other types.
1282
  --
1283
  --   expr                     boolean expression for checking.
1284
  --                            This makes it possible to check any kind of
1285
  --                            expresion, not just equality.
1286
  --
1287 36 pela
  --   pltbv, pltbs             PlTbUtils' status- and control variable and
1288
  --                            -signal.
1289
  --
1290 2 pela
  -- Examples:
1291 36 pela
  -- check("dat_o after reset", dat_o, 0, pltbv, pltbs);
1292 2 pela
  -- -- With mask:
1293 36 pela
  -- check("Status field in reg_o after start", reg_o, x"01", x"03", pltbv, pltbs);
1294 2 pela
  -- -- Boolean expression:
1295 36 pela
  -- check("Counter after data burst", cnt_o > 10, pltbv, pltbs);
1296 2 pela
  ----------------------------------------------------------------------------
1297
  -- check integer
1298
  procedure check(
1299
    constant rpt                : in    string;
1300 24 pela
    constant actual             : in    integer;
1301 2 pela
    constant expected           : in    integer;
1302 36 pela
    variable pltbv              : inout pltbv_t;
1303
    signal   pltbs              : out   pltbs_t
1304 2 pela
  ) is
1305
  begin
1306 36 pela
    check(rpt, actual = expected, str(actual), str(expected), "", pltbv, pltbs);
1307 2 pela
  end procedure check;
1308
 
1309
  -- check std_logic
1310
  procedure check(
1311
    constant rpt                : in    string;
1312 24 pela
    constant actual             : in    std_logic;
1313 2 pela
    constant expected           : in    std_logic;
1314 36 pela
    variable pltbv              : inout pltbv_t;
1315
    signal   pltbs              : out   pltbs_t
1316 2 pela
  ) is
1317
  begin
1318 36 pela
    check(rpt, actual = expected, str(actual), str(expected), "", pltbv, pltbs);
1319 2 pela
  end procedure check;
1320 36 pela
 
1321 2 pela
  -- check std_logic against integer
1322
  procedure check(
1323
    constant rpt                : in    string;
1324 24 pela
    constant actual             : in    std_logic;
1325 2 pela
    constant expected           : in    integer;
1326 36 pela
    variable pltbv              : inout pltbv_t;
1327
    signal   pltbs              : out   pltbs_t
1328 2 pela
  ) is
1329
  begin
1330 24 pela
    check(rpt, ((actual = '0' and expected = 0) or (actual = '1' and expected = 1)),
1331 36 pela
          str(actual), str(expected), "", pltbv, pltbs);
1332
  end procedure check;
1333
 
1334 2 pela
  -- check std_logic_vector
1335
  procedure check(
1336
    constant rpt                : in    string;
1337 24 pela
    constant actual             : in    std_logic_vector;
1338 2 pela
    constant expected           : in    std_logic_vector;
1339 36 pela
    variable pltbv              : inout pltbv_t;
1340
    signal   pltbs              : out   pltbs_t
1341 2 pela
  ) is
1342
  begin
1343 36 pela
    check(rpt, actual = expected, hxstr(actual, "0x"), hxstr(expected, "0x"), "", pltbv, pltbs);
1344 2 pela
  end procedure check;
1345 36 pela
 
1346 2 pela
  -- check std_logic_vector with mask
1347
  procedure check(
1348
    constant rpt                : in    string;
1349 24 pela
    constant actual             : in    std_logic_vector;
1350 2 pela
    constant expected           : in    std_logic_vector;
1351
    constant mask               : in    std_logic_vector;
1352 36 pela
    variable pltbv              : inout pltbv_t;
1353
    signal   pltbs              : out   pltbs_t
1354 2 pela
  ) is
1355
  begin
1356 24 pela
    check(rpt, (actual and mask) = (expected and mask),
1357 36 pela
          hxstr(actual, "0x"), hxstr(expected, "0x"), hxstr(mask, "0x"), pltbv, pltbs);
1358
  end procedure check;
1359
 
1360 2 pela
  -- check std_logic_vector against integer
1361
  procedure check(
1362
    constant rpt                : in    string;
1363 24 pela
    constant actual             : in    std_logic_vector;
1364 2 pela
    constant expected           : in    integer;
1365 36 pela
    variable pltbv              : inout pltbv_t;
1366
    signal   pltbs              : out   pltbs_t
1367 2 pela
  ) is
1368
  begin
1369 36 pela
    check(rpt, actual, std_logic_vector(to_signed(expected, actual'length)), pltbv, pltbs);
1370 2 pela
  end procedure check;
1371
 
1372
  -- check std_logic_vector with mask against integer
1373
  procedure check(
1374
    constant rpt                : in    string;
1375 24 pela
    constant actual             : in    std_logic_vector;
1376 2 pela
    constant expected           : in    integer;
1377
    constant mask               : in    std_logic_vector;
1378 36 pela
    variable pltbv              : inout pltbv_t;
1379
    signal   pltbs              : out   pltbs_t
1380 2 pela
  ) is
1381
  begin
1382 36 pela
    check(rpt, actual, std_logic_vector(to_signed(expected, actual'length)), mask, pltbv, pltbs);
1383 2 pela
  end procedure check;
1384 36 pela
 
1385 2 pela
  -- check unsigned
1386
  procedure check(
1387
    constant rpt                : in    string;
1388 24 pela
    constant actual             : in    unsigned;
1389 2 pela
    constant expected           : in    unsigned;
1390 36 pela
    variable pltbv              : inout pltbv_t;
1391
    signal   pltbs              : out   pltbs_t
1392 2 pela
  ) is
1393
  begin
1394 36 pela
    check(rpt, actual = expected, hxstr(actual, "0x"), hxstr(expected, "0x"), "", pltbv, pltbs);
1395 2 pela
  end procedure check;
1396 36 pela
 
1397 2 pela
  -- check unsigned against integer
1398
  procedure check(
1399
    constant rpt                : in    string;
1400 24 pela
    constant actual             : in    unsigned;
1401 2 pela
    constant expected           : in    integer;
1402 36 pela
    variable pltbv              : inout pltbv_t;
1403
    signal   pltbs              : out   pltbs_t
1404 2 pela
  ) is
1405
  begin
1406 36 pela
    check(rpt, actual, to_unsigned(expected, actual'length), pltbv, pltbs);
1407
  end procedure check;
1408
 
1409 2 pela
  -- check signed
1410
  procedure check(
1411
    constant rpt                : in    string;
1412 24 pela
    constant actual             : in    signed;
1413 2 pela
    constant expected           : in    signed;
1414 36 pela
    variable pltbv              : inout pltbv_t;
1415
    signal   pltbs              : out   pltbs_t
1416 2 pela
  ) is
1417
  begin
1418 36 pela
    check(rpt, actual = expected, hxstr(actual, "0x"), hxstr(expected, "0x"), "", pltbv, pltbs);
1419 2 pela
  end procedure check;
1420 36 pela
 
1421 2 pela
  -- check signed against integer
1422 24 pela
  -- TODO: find the bug reported by tb_pltbutils when expected  is negative (-1):
1423 2 pela
  --       ** Error: (vsim-86) numstd_conv_unsigned_nu: NATURAL arg value is negative (-1)
1424
  procedure check(
1425
    constant rpt                : in    string;
1426 24 pela
    constant actual             : in    signed;
1427 2 pela
    constant expected           : in    integer;
1428 36 pela
    variable pltbv              : inout pltbv_t;
1429
    signal   pltbs              : out   pltbs_t
1430 2 pela
  ) is
1431
  begin
1432 36 pela
    check(rpt, actual, to_signed(expected, actual'length), pltbv, pltbs);
1433
  end procedure check;
1434
 
1435 2 pela
  -- check with boolean expression
1436
  -- Check signal or variable with a boolean expression as argument C_EXPR.
1437
  -- This allowes any kind of check.
1438
  procedure check(
1439
    constant rpt                : in    string;
1440
    constant expr               : in    boolean;
1441 36 pela
    variable pltbv              : inout pltbv_t;
1442
    signal   pltbs              : out   pltbs_t
1443 2 pela
  ) is
1444
  begin
1445 36 pela
    check(rpt, expr, "", "", "", pltbv, pltbs);
1446
  end procedure check;
1447
 
1448 24 pela
  procedure check(
1449
    constant rpt                : in    string;
1450
    constant expr               : in    boolean;
1451
    constant actual             : in    string;
1452
    constant expected           : in    string;
1453
    constant mask               : in    string;
1454 36 pela
    variable pltbv              : inout pltbv_t;
1455
    signal   pltbs              : out   pltbs_t
1456 24 pela
  ) is
1457 36 pela
    variable timestamp          : time;
1458 24 pela
  begin
1459 36 pela
    timestamp := now;
1460
    pltbv.chk_cnt := pltbv.chk_cnt + 1;
1461
    pltbv.chk_cnt_in_test := pltbv.chk_cnt_in_test + 1;
1462 2 pela
    if not expr then
1463 36 pela
      pltbv.err_cnt := pltbv.err_cnt + 1;
1464
      pltbv.err_cnt_in_test := pltbv.err_cnt_in_test + 1;
1465 2 pela
    end if;
1466 36 pela
    pltbs_update(pltbv, pltbs);
1467 24 pela
    if C_PLTBUTILS_USE_STD_CHECK_MSG then
1468 36 pela
      check_msg(rpt, timestamp, expr, actual, expected, mask, pltbv.test_num,
1469
        pltbv.test_name(1 to pltbv.test_name_len), pltbv.chk_cnt, pltbv.err_cnt_in_test);
1470 24 pela
    end if;
1471
    if C_PLTBUTILS_USE_CUSTOM_CHECK_MSG then
1472 36 pela
      custom_check_msg(rpt, timestamp, expr, actual, expected, mask, pltbv.test_num,
1473
        pltbv.test_name(1 to pltbv.test_name_len), pltbv.chk_cnt, pltbv.err_cnt_in_test);
1474 24 pela
    end if;
1475 36 pela
    pltbs_update(pltbv, pltbs);
1476 24 pela
  end procedure check;
1477 36 pela
 
1478 2 pela
  ----------------------------------------------------------------------------
1479 14 pela
  -- to_ascending
1480
  --
1481
  -- function to_ascending(
1482
  --  constant s                  : std_logic_vector
1483
  -- ) return std_logic_vector;
1484
  --
1485
  -- function to_ascending(
1486
  --  constant s                  : unsigned
1487
  -- ) return unsigned
1488
  --
1489
  -- function to_ascending(
1490
  --  constant s                  : signed
1491
  -- ) return signed;
1492
  --
1493 18 pela
  -- Converts a signal or variable to ascending range ("to-range").
1494 14 pela
  -- The argument s can have ascending or descending range.
1495
  ----------------------------------------------------------------------------
1496
  function to_ascending(
1497
    constant s                  : std_logic_vector
1498
  ) return std_logic_vector is
1499 18 pela
    variable r : std_logic_vector(s'low to s'high);
1500 14 pela
  begin
1501
    for i in r'range loop
1502
      r(i) := s(i);
1503
    end loop;
1504
    return r;
1505
  end function to_ascending;
1506
 
1507
  function to_ascending(
1508
    constant s                  : unsigned
1509
  ) return unsigned is
1510 18 pela
    variable r : unsigned(s'low to s'high);
1511 14 pela
  begin
1512
    for i in r'range loop
1513
      r(i) := s(i);
1514
    end loop;
1515
    return r;
1516
  end function to_ascending;
1517
 
1518
  function to_ascending(
1519
    constant s                  : signed
1520
  ) return signed is
1521 18 pela
    variable r : signed(s'low to s'high);
1522 14 pela
  begin
1523
    for i in r'range loop
1524
      r(i) := s(i);
1525
    end loop;
1526
    return r;
1527
  end function to_ascending;
1528
 
1529
  ----------------------------------------------------------------------------
1530
  -- to_descending
1531
  --
1532
  -- function to_descending(
1533
  --  constant s                  : std_logic_vector
1534
  -- ) return std_logic_vector;
1535
  --
1536
  -- function to_descending(
1537
  --  constant s                  : unsigned
1538
  -- ) return unsigned
1539
  --
1540
  -- function to_descending(
1541
  --  constant s                  : signed
1542
  -- ) return signed;
1543
  --
1544 18 pela
  -- Converts a signal or variable to descending range ("downto-range").
1545 14 pela
  -- The argument s can have ascending or descending range.
1546
  ----------------------------------------------------------------------------
1547
  function to_descending(
1548
    constant s                  : std_logic_vector
1549
  ) return std_logic_vector is
1550 18 pela
    variable r : std_logic_vector(s'high downto s'low);
1551 14 pela
  begin
1552
    for i in r'range loop
1553
      r(i) := s(i);
1554
    end loop;
1555
    return r;
1556
  end function to_descending;
1557 36 pela
 
1558 14 pela
  function to_descending(
1559
    constant s                  : unsigned
1560
  ) return unsigned is
1561 18 pela
    variable r : unsigned(s'high downto s'low);
1562 14 pela
  begin
1563
    for i in r'range loop
1564
      r(i) := s(i);
1565
    end loop;
1566
    return r;
1567
  end function to_descending;
1568
 
1569
  function to_descending(
1570
    constant s                  : signed
1571
  ) return signed is
1572 18 pela
    variable r : signed(s'high downto s'low);
1573 14 pela
  begin
1574
    for i in r'range loop
1575
      r(i) := s(i);
1576
    end loop;
1577
    return r;
1578
  end function to_descending;
1579 36 pela
 
1580 14 pela
  ----------------------------------------------------------------------------
1581
  -- hxstr
1582
  -- function hxstr(
1583
  --  constant s                  : std_logic_vector;
1584 24 pela
  --  constant prefix             : string := "";
1585
  --  constant postfix            : string := ""
1586 14 pela
  -- ) return string;
1587
  --
1588
  -- function hxstr(
1589
  --  constant s                  : unsigned;
1590 24 pela
  --  constant prefix             : string := "";
1591
  --  constant postfix            : string := ""
1592 14 pela
  -- ) return string;
1593
  --
1594
  -- function hxstr(
1595
  --  constant s                  : signed;
1596 24 pela
  --  constant prefix             : string := "";
1597
  --  constant postfix            : string := ""
1598 14 pela
  -- ) return string;
1599
  --
1600
  -- Converts a signal to a string in hexadecimal format.
1601
  -- An optional prefix can be specified, e.g. "0x".
1602
  --
1603 36 pela
  -- The signal can have ascending range ( "to-range" ) or descending range
1604 14 pela
  -- ("downto-range").
1605
  --
1606
  -- hxstr is a wrapper function for hstr in txt_util.
1607
  -- hstr only support std_logic_vector with descending range.
1608
  --
1609
  -- Examples:
1610
  -- print("value=" & hxstr(s));
1611
  -- print("value=" & hxstr(s, "0x"));
1612
  ----------------------------------------------------------------------------
1613
  function hxstr(
1614
    constant s                  : std_logic_vector;
1615 24 pela
    constant prefix             : string := "";
1616
    constant postfix            : string := ""
1617 14 pela
  ) return string is
1618
  begin
1619 24 pela
    return prefix & hstr(to_descending(s)) & postfix;
1620 14 pela
  end function hxstr;
1621 36 pela
 
1622 14 pela
  function hxstr(
1623
    constant s                  : unsigned;
1624 24 pela
    constant prefix             : string := "";
1625
    constant postfix            : string := ""
1626 14 pela
  ) return string is
1627
  begin
1628 24 pela
    return prefix & hstr(to_descending(std_logic_vector(s))) & postfix;
1629 14 pela
  end function hxstr;
1630 36 pela
 
1631 14 pela
  function hxstr(
1632
    constant s                  : signed;
1633 24 pela
    constant prefix             : string := "";
1634
    constant postfix            : string := ""
1635 14 pela
  ) return string is
1636
  begin
1637 24 pela
    return prefix & hstr(to_descending(std_logic_vector(s))) & postfix;
1638 14 pela
  end function hxstr;
1639 36 pela
 
1640 14 pela
  ----------------------------------------------------------------------------
1641 2 pela
  -- pltbutils internal procedure(s), called from other pltbutils procedures.
1642
  -- Do not to call this/these from user's code.
1643
  -- This/these procedures are undocumented in the specification on purpose.
1644
  ----------------------------------------------------------------------------
1645 36 pela
  procedure pltbs_update(
1646
    variable pltbv              : inout pltbv_t;
1647
    signal   pltbs              : out   pltbs_t
1648
  ) is
1649 2 pela
  begin
1650 36 pela
    pltbs.test_num  <= pltbv.test_num;
1651
    print(pltbs.test_name, pltbv.test_name);
1652
    print(pltbs.info, pltbv.info);
1653
    pltbs.chk_cnt   <= pltbv.chk_cnt;
1654
    pltbs.err_cnt   <= pltbv.err_cnt;
1655
    pltbs.stop_sim  <= pltbv.stop_sim;
1656
  end procedure pltbs_update;
1657
 
1658
  procedure pltbutils_error(
1659
    constant rpt                : in string;
1660
    variable pltbv              : inout pltbv_t;
1661
    signal   pltbs              : out   pltbs_t
1662
  ) is
1663
  begin
1664
    pltbv.err_cnt := pltbv.err_cnt + 1;
1665
    pltbv.err_cnt_in_test := pltbv.err_cnt_in_test + 1;
1666
    pltbs_update(pltbv, pltbs);
1667
    if C_PLTBUTILS_USE_STD_ERROR_MSG then
1668
      error_msg(rpt, now, pltbv.test_num,
1669
        pltbv.test_name(1 to pltbv.test_name_len), pltbv.err_cnt_in_test);
1670
    end if;
1671
    if C_PLTBUTILS_USE_CUSTOM_ERROR_MSG then
1672
      custom_error_msg(rpt, now, pltbv.test_num,
1673
        pltbv.test_name(1 to pltbv.test_name_len), pltbv.err_cnt_in_test);
1674
    end if;
1675
  end procedure pltbutils_error;
1676
 
1677
  procedure stopsim(
1678
    constant timestamp          : in time
1679
  ) is
1680
  begin
1681
    assert false
1682
    report "--- FORCE END OF SIMULATION ---" &
1683
           " (ignore this false failure message, it's not a real failure)"
1684
    severity failure;
1685
  end procedure stopsim;
1686
 
1687 24 pela
  procedure startsim_msg(
1688
    constant testcase_name      : in string;
1689
    constant timestamp          : in time
1690
  ) is
1691
  begin
1692
    print(lf & "--- START OF SIMULATION ---");
1693
    print("Testcase: " & testcase_name);
1694
    print(time'image(timestamp));
1695
  end procedure startsim_msg;
1696
 
1697
  procedure endsim_msg(
1698
    constant testcase_name      : in string;
1699
    constant timestamp          : in time;
1700
    constant num_tests          : in integer;
1701
    constant num_checks         : in integer;
1702
    constant num_errors         : in integer;
1703
    constant show_success_fail  : in boolean
1704
  ) is
1705
    variable l : line;
1706
  begin
1707
    print(lf & "--- END OF SIMULATION ---");
1708 36 pela
    print("Note: the results presented below are based on the PlTbUtil's check() procedure calls.");
1709 24 pela
    print("      The design may contain more errors, for which there are no check() calls.");
1710
    write(l, timestamp, right, 14);
1711
    writeline(output, l);
1712
    write(l, num_tests, right, 11);
1713
    write(l, string'(" Tests"));
1714
    writeline(output, l);
1715
    write(l, num_checks, right, 11);
1716
    write(l, string'(" Checks"));
1717
    writeline(output, l);
1718
    write(l, num_errors, right, 11);
1719
    write(l, string'(" Errors"));
1720
    writeline(output, l);
1721
    if show_success_fail then
1722
      if num_errors = 0 and num_checks > 0 then
1723
        print("*** SUCCESS ***");
1724
      elsif num_checks > 0 then
1725
        print("*** FAIL ***");
1726
      else
1727
        print("*** NO CHECKS ***");
1728
      end if;
1729 36 pela
    end if;
1730 24 pela
  end procedure endsim_msg;
1731 36 pela
 
1732 24 pela
  procedure starttest_msg(
1733
    constant test_num           : in integer;
1734
    constant test_name          : in string;
1735
    constant timestamp          : in time
1736
  ) is
1737
  begin
1738 36 pela
    print(lf & "Test " & str(test_num) & ": " & test_name & " (" & time'image(timestamp) & ")");
1739 24 pela
  end procedure starttest_msg;
1740 36 pela
 
1741 24 pela
  procedure endtest_msg(
1742
    constant test_num           : in integer;
1743
    constant test_name          : in string;
1744
    constant timestamp          : in time;
1745
    constant num_checks_in_test : in integer;
1746
    constant num_errors_in_test : in integer
1747
  ) is
1748
  begin
1749
    print("Done with test " & str(test_num) & ": " & test_name & " (" & time'image(timestamp) & ")");
1750
  end procedure endtest_msg;
1751 36 pela
 
1752 24 pela
  procedure check_msg(
1753
    constant rpt                : in string;
1754 36 pela
    constant timestamp          : in time;
1755
    constant expr               : in boolean;
1756 24 pela
    constant actual             : in string;
1757
    constant expected           : in string;
1758
    constant mask               : in string;
1759 36 pela
    constant test_num           : in integer;
1760 24 pela
    constant test_name          : in string;
1761
    constant check_num          : in integer;
1762
    constant err_cnt_in_test    : in integer
1763
  ) is
1764
    variable comparison_str     : string(1 to 32) := (others => ' ');
1765
    variable comparison_str_len : integer := 1;
1766
    variable actual_str         : string(1 to 32) := (others => ' ');
1767
    variable actual_str_len     : integer := 1;
1768
    variable expected_str       : string(1 to 32) := (others => ' ');
1769
    variable expected_str_len   : integer := 1;
1770
    variable mask_str           : string(1 to 32) := (others => ' ');
1771
    variable mask_str_len       : integer := 1;
1772
  begin
1773
    if not expr then -- Output message only if the check fails
1774
      if actual /= "" then
1775
        actual_str_len := 8 + actual'length;
1776
        actual_str(1 to actual_str_len) := " Actual=" & actual;
1777 36 pela
      end if;
1778 24 pela
      if expected /= "" then
1779
        expected_str_len := 10 + expected'length;
1780
        expected_str(1 to expected_str_len) := " Expected=" & expected;
1781 36 pela
      end if;
1782 24 pela
      if mask /= "" then
1783
        mask_str_len := 6 + mask'length;
1784
        mask_str(1 to mask_str_len) := " Mask=" & mask;
1785 36 pela
      end if;
1786 24 pela
      assert false
1787
        report "Check " & str(check_num) & "; " & rpt & "; " &
1788 36 pela
               actual_str(1 to actual_str_len) &
1789 24 pela
               expected_str(1 to expected_str_len) &
1790
               mask_str(1 to mask_str_len) &
1791
               "  in test " & str(test_num) & " " & test_name
1792
        severity error;
1793
    end if;
1794 36 pela
  end procedure check_msg;
1795
 
1796 24 pela
  procedure error_msg(
1797
    constant rpt                : in string;
1798
    constant timestamp          : in time;
1799 36 pela
    constant test_num           : in integer;
1800 24 pela
    constant test_name          : in string;
1801
    constant err_cnt_in_test    : in integer
1802
  ) is
1803
  begin
1804
    assert false
1805
    report rpt & " in test " & str(test_num) & ": " & test_name
1806
    severity error;
1807
  end procedure error_msg;
1808 36 pela
 
1809 2 pela
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.