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

Subversion Repositories pltbutils

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

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