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

Subversion Repositories pltbutils

[/] [pltbutils/] [branches/] [dev_beta0002/] [src/] [vhdl/] [pltbutils_func_pkg.vhd] - Blame information for rev 96

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