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

Subversion Repositories pltbutils

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

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