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

Subversion Repositories pltbutils

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

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

Line No. Rev Author Line
1 2 pela
----------------------------------------------------------------------
2
----                                                              ----
3
---- PlTbUtils Fuctions and Procedures Package                    ----
4
----                                                              ----
5
---- This file is part of the PlTbUtils project                   ----
6
---- http://opencores.org/project,pltbutils                       ----
7
----                                                              ----
8
---- Description:                                                 ----
9
---- PlTbUtils is a collection of functions, procedures and       ----
10
---- components for easily creating stimuli and checking response ----
11
---- in automatic self-checking testbenches.                      ----
12
----                                                              ----
13
---- This file defines fuctions and procedures for controlling    ----
14
---- stimuli to a DUT and checking response.                      ----
15
----                                                              ----
16
---- To Do:                                                       ----
17
---- -                                                            ----
18
----                                                              ----
19
---- Author(s):                                                   ----
20
---- - Per Larsson, pela@opencores.org                            ----
21
----                                                              ----
22
----------------------------------------------------------------------
23
----                                                              ----
24
---- Copyright (C) 2013 Authors and OPENCORES.ORG                 ----
25
----                                                              ----
26
---- This source file may be used and distributed without         ----
27
---- restriction provided that this copyright statement is not    ----
28
---- removed from the file and that any derivative work contains  ----
29
---- the original copyright notice and the associated disclaimer. ----
30
----                                                              ----
31
---- This source file is free software; you can redistribute it   ----
32
---- and/or modify it under the terms of the GNU Lesser General   ----
33
---- Public License as published by the Free Software Foundation; ----
34
---- either version 2.1 of the License, or (at your option) any   ----
35
---- later version.                                               ----
36
----                                                              ----
37
---- This source is distributed in the hope that it will be       ----
38
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ----
39
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ----
40
---- PURPOSE. See the GNU Lesser General Public License for more  ----
41
---- details.                                                     ----
42
----                                                              ----
43
---- You should have received a copy of the GNU Lesser General    ----
44
---- Public License along with this source; if not, download it   ----
45
---- from http://www.opencores.org/lgpl.shtml                     ----
46
----                                                              ----
47
----------------------------------------------------------------------
48
library ieee;
49
use ieee.std_logic_1164.all;
50
use ieee.numeric_std.all;
51
use std.textio.all;
52
use std.env.all; -- VHDL-2008
53
use work.txt_util.all;
54
use work.pltbutils_type_pkg.all; -- Use for VHDL-2002, comment out for VHDL-93
55
 
56
package pltbutils_func_pkg is
57
 
58
  -- See the package body for a description of the functions and procedures.
59
  constant C_PLTBUTILS_STRLEN  : natural := 80;
60
  constant C_PLTBUTILS_TIMEOUT : time    := 10 sec;
61
  constant C_WAIT_BEFORE_STOP_TIME : time := 1 us;
62
 
63
  -- Counters for number of checks and number of errors
64
  -- VHDL-2002:
65
  shared variable v_pltbutils_test_num  : pltbutils_p_integer_t;
66
  shared variable v_pltbutils_test_name : pltbutils_p_string_t;
67
  shared variable v_pltbutils_info      : pltbutils_p_string_t;
68
  shared variable v_pltbutils_chk_cnt   : pltbutils_p_integer_t;
69
  shared variable v_pltbutils_err_cnt   : pltbutils_p_integer_t;
70
  shared variable v_pltbutils_stop_sim  : pltbutils_p_std_logic_t;
71
  -- VHDL-1993:
72
  --shared variable v_pltbutils_test_num  : natural := 0;
73
  --shared variable v_pltbutils_test_name : string(1 to C_PLTBUTILS_STRLEN) := (others => ' ');
74
  --shared variable v_pltbutils_info      : string(1 to C_PLTBUTILS_STRLEN) := (others => ' ');
75
  --shared variable v_pltbutils_chk_cnt   : natural := 0;
76
  --shared variable v_pltbutils_err_cnt   : natural := 0;
77
  --shared variable v_pltbutils_stop_sim  : std_logic := '0';
78
 
79
  -- Global status- and control signal
80
  type pltbutils_sc_t is
81
    record
82
      test_num  : natural;
83
      test_name : string(1 to C_PLTBUTILS_STRLEN);
84
      info      : string(1 to C_PLTBUTILS_STRLEN);
85
      chk_cnt   : natural;
86
      err_cnt   : natural;
87
      stop_sim  : std_logic;
88
    end record;
89
  signal pltbutils_sc : pltbutils_sc_t;
90
 
91
  -- startsim 
92
  procedure startsim(
93
    constant testcase_name      : in    string;
94
    signal   pltbutils_sc       : out   pltbutils_sc_t
95
  );
96
 
97
  -- endsim
98
  procedure endsim(
99
    signal   pltbutils_sc        : out pltbutils_sc_t;
100
    constant show_success_fail   : in   boolean := false;
101
    constant force               : in boolean := false
102
  );
103
 
104
  -- testname
105
  procedure testname(
106
    constant num                : in    integer := -1;
107
    constant name               : in    string;
108
    signal   pltbutils_sc       : out   pltbutils_sc_t
109
  );
110
  procedure testname(
111
    constant name               : in    string;
112
    signal   pltbutils_sc       : out   pltbutils_sc_t
113
  );
114
 
115
  -- print, printv, print2
116
  procedure print(
117
    signal   s                  : out   string;
118
    constant txt                : in    string
119
  );
120
  procedure printv(
121
    variable s                  : out   string;
122
    constant txt                : in    string
123
  );
124
  procedure printv(
125
    variable s                  : inout pltbutils_p_string_t;
126
    constant txt                : in    string
127
  );
128
  procedure print(
129
    signal   pltbutils_sc       : out   pltbutils_sc_t;
130
    constant txt                : in    string
131
  );
132
  procedure print2(
133
    signal   s                  : out   string;
134
    constant txt                : in    string
135
  );
136
  procedure print2(
137
    signal   pltbutils_sc       : out   pltbutils_sc_t;
138
    constant txt                : in    string
139
  );
140
 
141
  -- waitclks
142
  procedure waitclks(
143
    constant N                  : in    natural;
144
    signal   clk                : in    std_logic;
145
    signal   pltbutils_sc       : out   pltbutils_sc_t;
146
    constant falling            : in    boolean := false;
147
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
148
  );
149
 
150
  -- check
151
  procedure check(
152
    constant rpt                : in    string;
153
    constant data               : in    integer;
154
    constant expected           : in    integer;
155
    signal   pltbutils_sc       : out   pltbutils_sc_t
156
  );
157
  procedure check(
158
    constant rpt                : in    string;
159
    constant data               : in    std_logic;
160
    constant expected           : in    std_logic;
161
    signal   pltbutils_sc       : out   pltbutils_sc_t
162
  );
163
  procedure check(
164
    constant rpt                : in    string;
165
    constant data               : in    std_logic;
166
    constant expected           : in    integer;
167
    signal   pltbutils_sc       : out   pltbutils_sc_t
168
  );
169
  procedure check(
170
    constant rpt                : in    string;
171
    constant data               : in    std_logic_vector;
172
    constant expected           : in    std_logic_vector;
173
    signal   pltbutils_sc       : out   pltbutils_sc_t
174
  );
175
  procedure check(
176
    constant rpt                : in    string;
177
    constant data               : in    std_logic_vector;
178
    constant expected           : in    std_logic_vector;
179
    constant mask               : in    std_logic_vector;
180
    signal   pltbutils_sc       : out   pltbutils_sc_t
181
  );
182
  procedure check(
183
    constant rpt                : in    string;
184
    constant data               : in    std_logic_vector;
185
    constant expected           : in    integer;
186
    signal   pltbutils_sc       : out   pltbutils_sc_t
187
  );
188
  procedure check(
189
    constant rpt                : in    string;
190
    constant data               : in    std_logic_vector;
191
    constant expected           : in    integer;
192
    constant mask               : in    std_logic_vector;
193
    signal   pltbutils_sc       : out   pltbutils_sc_t
194
  );
195
  procedure check(
196
    constant rpt                : in    string;
197
    constant data               : in    unsigned;
198
    constant expected           : in    unsigned;
199
    signal   pltbutils_sc       : out   pltbutils_sc_t
200
  );
201
  procedure check(
202
    constant rpt                : in    string;
203
    constant data               : in    unsigned;
204
    constant expected           : in    integer;
205
    signal   pltbutils_sc       : out   pltbutils_sc_t
206
  );
207
  procedure check(
208
    constant rpt                : in    string;
209
    constant data               : in    signed;
210
    constant expected           : in    signed;
211
    signal   pltbutils_sc       : out   pltbutils_sc_t
212
  );
213
  procedure check(
214
    constant rpt                : in    string;
215
    constant data               : in    signed;
216
    constant expected           : in    integer;
217
    signal   pltbutils_sc       : out   pltbutils_sc_t
218
  );
219
  procedure check(
220
    constant rpt                : in    string;
221
    constant expr               : in    boolean;
222
    signal   pltbutils_sc       : out   pltbutils_sc_t
223
  );
224
 
225
  -- pltbutils internal procedure(s), do not call from user's code
226
  procedure pltbutils_sc_update(
227
    signal pltbutils_sc : out pltbutils_sc_t
228
  );
229
 
230
end package pltbutils_func_pkg;
231
 
232
package body pltbutils_func_pkg is
233
 
234
  ----------------------------------------------------------------------------
235
  -- startsim
236
  --
237
  -- procedure startsim(
238
  --   constant testcase_name      : in    string;
239
  --   signal   pltbutils_sc       : out   pltbutils_sc_t
240
  -- )
241
  --
242
  -- Displays a message at start of simulation message, and initializes
243
  -- PlTbUtils' global status and control signal.
244
  -- Call startsim() only once.
245
  --
246
  -- Arguments:
247
  --   testcase_name            Name of the test case, e.g. "tc1".
248
  --
249
  --   pltbutils_sc             PlTbUtils' global status- and control signal.
250
  --                            Must be set to pltbutils_sc.
251
  --
252
  -- NOTE:
253
  -- The start-of-simulation message is not only intended to be informative
254
  -- for humans. It is also intended to be searched for by scripts,
255
  -- e.g. for collecting results from a large number of regression tests.
256
  -- For this reason, the message must be consistent and unique.
257
  --
258
  -- DO NOT MODIFY the message "--- START OF SIMULATION ---".
259
  -- DO NOT OUTPUT AN IDENTICAL MESSAGE anywhere else.
260
  --
261
  -- Example:
262
  -- startsim("tc1", pltbutils_sc);
263
  ----------------------------------------------------------------------------
264
  procedure startsim(
265
    constant testcase_name      : in    string;
266
    signal   pltbutils_sc       : out   pltbutils_sc_t
267
  ) is
268
    variable dummy : integer;
269
  begin
270
    printv(v_pltbutils_info, testcase_name);
271
    print(lf & "--- START OF SIMULATION ---");
272
    print("Testcase: " & testcase_name);
273
    print(time'image(now));
274
    -- VHDL-2002:
275
    v_pltbutils_stop_sim.clr;
276
    v_pltbutils_test_num.clr;
277
    v_pltbutils_test_name.set("START OF SIMULATION");
278
    v_pltbutils_chk_cnt.clr;
279
    v_pltbutils_err_cnt.clr;
280
    pltbutils_sc_update(pltbutils_sc);
281
    -- VHDL-1993:
282
    --v_pltbutils_stop_sim := '0';
283
    --v_pltbutils_test_num := 0;
284
    --printv(v_pltbutils_test_name, "START OF SIMULATION");
285
    --v_pltbutils_chk_cnt := 0;
286
    --v_pltbutils_err_cnt := 0;
287
    --pltbutils_sc_update(pltbutils_sc);
288
  end procedure startsim;
289
 
290
  ----------------------------------------------------------------------------
291
  -- endsim
292
  --
293
  -- procedure endsim(
294
  --   signal   pltbutils_sc       : out pltbutils_sc_t;
295
  --   constant show_success_fail  : in  boolean := false;
296
  --   constant force              : in  boolean := false
297
  -- )
298
  --
299
  -- Displays a message at end of simulation message, presents the simulation
300
  -- results, and stops the simulation. 
301
  -- Call endsim() it only once.
302
  --
303
  -- Arguments: 
304
  --   pltbutils_sc             PlTbUtils' global status- and control signal.
305
  --                            Must be set to pltbutils_sc.
306
  --
307
  --   show_success_fail        If true, endsim() shows "*** SUCCESS ***", 
308
  --                            "*** FAIL ***", or "*** NO CHECKS ***".
309
  --                            Optional, default is false.
310
  --
311
  --   force                    If true, forces the simulation to stop using an
312
  --                            assert failure statement. Use this option only
313
  --                            if the normal way of stopping the simulation
314
  --                            doesn't work (see below).
315
  --                            Optional, default is false.
316
  --
317
  -- The testbench should be designed so that all clocks stop when endsim()
318
  -- sets the signal stop_sim to '1'. This should stop the simulator.
319
  -- In some cases, that doesn't work, then set the force argument to true, which
320
  -- causes a false assert failure, which should stop the simulator.
321
  -- Scripts searching transcript logs for errors and failures, should ignore
322
  -- the failure with "--- FORCE END OF SIMULATION ---" as part of the report.
323
  --
324
  -- NOTE:
325
  -- The end-of-simulation messages and success/fail messages are not only
326
  -- intended to be informative for humans. They are also intended to be
327
  -- searched for by scripts, e.g. for collecting results from a large number
328
  -- of regression tests.
329
  -- For this reason, the message must be consistent and unique.
330
  --
331
  -- DO NOT MODIFY the messages "--- END OF SIMULATION ---", 
332
  -- "*** SUCCESS ***", "*** FAIL ***", "*** NO CHECKS ***".
333
  -- DO NOT OUTPUT IDENTICAL MESSAGES anywhere else.
334
  --
335
  -- Examples:
336
  -- endsim(pltbutils_sc);
337
  -- endsim(pltbutils_sc, true);
338
  -- endsim(pltbutils_sc, true, true);
339
  ----------------------------------------------------------------------------
340
  procedure endsim(
341
    signal   pltbutils_sc       : out pltbutils_sc_t;
342
    constant show_success_fail  : in  boolean := false;
343
    constant force              : in  boolean := false
344
  ) is
345
    variable l : line;
346
  begin
347
    printv(v_pltbutils_info, "");
348
    print(lf & "--- END OF SIMULATION ---");
349
    print("Note: the results presented below are based on the PlTbUtil's check() procedure calls.");
350
    print("      The design may contain more errors, for which there are no check() calls.");
351
    write(l, now, right, 14);
352
    writeline(output, l);
353
    write(l, v_pltbutils_chk_cnt.value, right, 11); -- VHDL-2002
354
    --write(l, v_pltbutils_chk_cnt, right, 11); -- VHDL-1993
355
    write(l, string'(" Checks"));
356
    writeline(output, l);
357
    write(l, v_pltbutils_err_cnt.value, right, 11); -- VHDL-2002
358
    --write(l, v_pltbutils_chk_cnt, right, 11); -- VHDL-1993
359
    write(l, string'(" Errors"));
360
    writeline(output, l);
361
 
362
    if show_success_fail then
363
       if v_pltbutils_err_cnt.value = 0 and v_pltbutils_chk_cnt.value > 0 then -- VHDL-2002
364
       --if v_pltbutils_err_cnt = 0 and v_pltbutils_chk_cnt > 0 then -- VHDL-1993
365
        print("*** SUCCESS ***");
366
      elsif v_pltbutils_chk_cnt.value > 0 then -- VHDL-2002
367
      --elsif v_pltbutils_chk_cnt > 0 then -- VHDL-1993
368
        print("*** FAIL ***");
369
      else
370
        print("*** NO CHECKS ***");
371
      end if;
372
    end if;
373
    -- VHDL-2002:
374
    v_pltbutils_stop_sim.set('1');
375
    v_pltbutils_test_num.clr;
376
    v_pltbutils_test_name.set("END OF SIMULATION");
377
    -- VHDL-1993:
378
    --v_pltbutils_stop_sim := '1';
379
    --v_pltbutils_test_num := 0;
380
    --printv(v_pltbutils_test_name, "END OF SIMULATION");
381
    pltbutils_sc_update(pltbutils_sc);
382
    wait for C_WAIT_BEFORE_STOP_TIME;
383
    stop(0); -- VHDL-2008
384
    assert not force
385
    report "--- FORCE END OF SIMULATION ---" &
386
           " (ignore this false failure message, it's not a real failure)"
387
    severity failure;
388
    wait;
389
  end procedure endsim;
390
 
391
  ----------------------------------------------------------------------------
392
  -- testname
393
  --
394
  -- procedure testname(
395
  --   constant num                : in    integer := -1;
396
  --   constant name               : in    string;
397
  --   signal   pltbutils_sc       : out   pltbutils_sc_t
398
  -- ) 
399
  --
400
  -- Sets a number (optional) and a name for a test. The number and name will
401
  -- be printed to the screen, and displayed in the simulator's waveform
402
  -- window. 
403
  -- The test number and name is also included if there errors reported by the
404
  -- check() procedure calls.
405
  --
406
  -- Arguments: 
407
  --   num                      Test number. Optional, default is to increment
408
  --                            the current test number.
409
  --
410
  --   name                     Test name.
411
  --
412
  --   pltbutils_sc             PlTbUtils' global status- and control signal.
413
  --                            Must be set to pltbutils_sc.
414
  --
415
  -- If the test number is omitted, a new test number is automatically
416
  -- computed by incrementing the current test number. 
417
  -- Manually setting the test number may make it easier to find the test code
418
  -- in the testbench code, though.
419
  --
420
  -- Examples:
421
  -- testname("Reset test", pltbutils_sc);
422
  -- testname(1, "Reset test", pltbutils_sc);
423
  ----------------------------------------------------------------------------
424
  procedure testname(
425
    constant num                : in    integer := -1;
426
    constant name               : in    string;
427
    signal   pltbutils_sc       : out   pltbutils_sc_t
428
  ) is
429
  begin
430
    -- VHDL-2002:
431
    if num = -1 then
432
      v_pltbutils_test_num.inc;
433
    else
434
      v_pltbutils_test_num.set(num);
435
    end if;
436
    v_pltbutils_test_name.set(name);
437
    pltbutils_sc_update(pltbutils_sc);
438
    print("Test " & str(v_pltbutils_test_num.value) & ": " & name);
439
    -- VHDL-1993:
440
    --if num = -1 then
441
    --  b_pltbutils_test_num := v_pltbutils_test_num + 1;
442
    --else
443
    --  v_pltbutils_test_num  := num;
444
    --end if;
445
    --printv(v_pltbutils_test_name, name);
446
    --pltbutils_sc_update(pltbutils_sc);
447
    --print("Test " & str(v_pltbutils_test_num) & ": " & name);
448
  end procedure testname;
449
 
450
  procedure testname(
451
    constant name               : in    string;
452
    signal   pltbutils_sc       : out   pltbutils_sc_t
453
  ) is
454
  begin
455
    testname(-1, name, pltbutils_sc);
456
  end procedure testname;
457
 
458
  ----------------------------------------------------------------------------
459
  -- print printv print2
460
  --
461
  -- procedure print(   
462
  --   signal   s                  : out   string;
463
  --   constant txt                : in    string
464
  -- ) 
465
  --
466
  -- procedure print(
467
  --   signal   pltbutils_sc       : out   pltbutils_sc_t;
468
  --   constant txt                : in    string
469
  -- )
470
  --
471
  -- procedure printv(
472
  --   variable s                  : out   string;
473
  --   constant txt                : in    string
474
  -- )
475
  --
476
  -- procedure print2(    
477
  --   signal   s                  : out   string;
478
  --   constant txt                : in    string
479
  -- )
480
  --
481
  -- procedure print2(    
482
  --   signal   pltbutils          : out   pltbutils_sc_t;
483
  --   constant txt                : in    string
484
  -- )
485
  --
486
  -- print() prints text messages to a signal for viewing in the simulator's
487
  -- waveform window. printv() does the same thing, but to a variable instead.
488
  -- print2() prints both to a signal and to the transcript window. 
489
  -- The type of the output can be string or pltbutils_sc_t.
490
  -- If the type is pltbutils_sc_t, the name can be no other than pltbutils_sc.
491
  --
492
  -- Arguments: 
493
  --   s                        Signal or variable of type string to be 
494
  --                            printed to.
495
  --
496
  --   txt                      The text.
497
  --
498
  --   pltbutils_sc             PlTbUtils' global status- and control signal 
499
  --                            of type pltbutils_sc_t. 
500
  --                            The name must be no other than pltbutils_sc.
501
  --
502
  -- If the string txt  is longer than the signal s, the text will be truncated.
503
  -- If txt  is shorter, s will be padded with spaces.
504
  --
505
  -- Examples:
506
  -- print(msg, "Hello, world"); -- Prints to signal msg
507
  -- printv(v_msg, "Hello, world"); -- Prints to variable msg
508
  -- print(pltbutils_sc, "Hello, world"); -- Prints to "info" in waveform window
509
  -- print2(msg, "Hello, world"); -- Prints to signal and transcript window 
510
  -- print(pltbutils_sc, "Hello, world"); -- Prints to "info" in waveform and
511
  --                                      -- transcript windows
512
  ----------------------------------------------------------------------------
513
  procedure print(
514
    signal   s                  : out   string;
515
    constant txt                : in    string
516
  ) is
517
    variable j : positive := txt 'low;
518
  begin
519
    for i in s'range loop
520
      if j <= txt 'high then
521
        s(i) <= txt (j);
522
      else
523
        s(i) <= ' ';
524
      end if;
525
      j := j + 1;
526
    end loop;
527
  end procedure print;
528
 
529
  procedure printv(
530
    variable s                  : out   string;
531
    constant txt                : in    string
532
  ) is
533
    variable j : positive := txt 'low;
534
  begin
535
    for i in s'range loop
536
      if j <= txt 'high then
537
        s(i) := txt (j);
538
      else
539
        s(i) := ' ';
540
      end if;
541
      j := j + 1;
542
    end loop;
543
  end procedure printv;
544
 
545
  -- VHDL-2002:
546
  procedure printv(
547
    variable s                  : inout pltbutils_p_string_t;
548
    constant txt                : in    string
549
  ) is
550
    variable j : positive := txt 'low;
551
  begin
552
    s.set(txt );
553
  end procedure printv;
554
 
555
  -- Print to info element in pltbutils_sc, which shows up in waveform window
556
  procedure print(
557
    signal   pltbutils_sc       : out   pltbutils_sc_t;
558
    constant txt                : in    string
559
  ) is
560
    variable j : positive := txt 'low;
561
  begin
562
    printv(v_pltbutils_info, txt );
563
    pltbutils_sc_update(pltbutils_sc);
564
  end procedure print;
565
 
566
  procedure print2(
567
    signal   s                  : out   string;
568
    constant txt                : in    string
569
  ) is
570
  begin
571
    print(s, txt );
572
    print(txt );
573
  end procedure print2;
574
 
575
  procedure print2(
576
    signal   pltbutils_sc       : out   pltbutils_sc_t;
577
    constant txt                : in    string
578
  ) is
579
  begin
580
    print(pltbutils_sc, txt );
581
    print(txt );
582
  end procedure print2;
583
 
584
  ----------------------------------------------------------------------------
585
  -- waitclks
586
  --
587
  -- procedure waitclks(
588
  --   constant n                  : in    natural;
589
  --   signal   clk                : in    std_logic;
590
  --   signal   pltbutils_sc       : out   pltbutils_sc_t;
591
  --   constant falling            : in    boolean := false;
592
  --   constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
593
  -- )
594
  --
595
  -- Waits specified amount of clock cycles of the specified clock.
596
  -- Or, to be more precise, a specified number of specified clock edges of
597
  -- the specified clock.
598
  --
599
  -- Arguments: 
600
  --   n                        Number of rising or falling clock edges to wait.
601
  --
602
  --   clk                      The clock to wait for.
603
  --
604
  --   pltbutils_sc             PlTbUtils' global status- and control signal.
605
  --                            Must be set to pltbutils_sc.
606
  --
607
  --   falling                  If true, waits for falling edges, otherwise
608
  --                            rising edges. Optional, default is false.
609
  --
610
  --   timeout                  Timeout time, in case the clock is not working.
611
  --                            Optional, default is C_PLTBUTILS_TIMEOUT.  
612
  --
613
  -- Examples:
614
  -- waitclks(5, sys_clk, pltbutils_sc);
615
  -- waitclks(5, sys_clk, pltbutils_sc, true);
616
  -- waitclks(5, sys_clk, pltbutils_sc, true, 1 ms);
617
  ----------------------------------------------------------------------------
618
  procedure waitclks(
619
    constant n                  : in    natural;
620
    signal   clk                : in    std_logic;
621
    signal   pltbutils_sc       : out   pltbutils_sc_t;
622
    constant falling            : in    boolean := false;
623
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
624
  ) is
625
    variable i                  : natural := n;
626
    variable v_timeout_time     : time;
627
  begin
628
    v_timeout_time := now + timeout;
629
    while i > 0 loop
630
      if FALLING then
631
        wait until falling_edge(clk) for timeout / n;
632
      else
633
        wait until rising_edge(clk)  for timeout / n;
634
      end if;
635
      i := i - 1;
636
    end loop;
637
    if now >= v_timeout_time then
638
      assert false
639
      report "waitclks() timeout"
640
      severity error;
641
      v_pltbutils_err_cnt.inc; -- VHDL-2002
642
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
643
      pltbutils_sc_update(pltbutils_sc);
644
    end if;
645
  end procedure waitclks;
646
 
647
  ----------------------------------------------------------------------------
648
  -- check
649
  --
650
  -- procedure check(
651
  --  constant rpt              : in    string;
652
  --  constant data             : in    integer|std_logic|std_logic_vector|unsigned|signed;
653
  --  constant expected         : in    integer|std_logic|std_logic_vector|unsigned|signed;
654
  --  signal   pltbutils_sc     : out   pltbutils_sc_t
655
  --  )
656
  --
657
  -- procedure check(
658
  --  constant rpt              : in    string;
659
  --  constant data             : in    std_logic_vector;
660
  --  constant expected         : in    std_logic_vector;
661
  --  constant mask             : in    std_logic_vector;
662
  --  signal   pltbutils_sc     : out   pltbutils_sc_t
663
  --  )
664
  --
665
  -- procedure check(
666
  --   constant rpt            : in    string;
667
  --   constant expr           : in    boolean;
668
  --   signal   pltbutils_sc   : out   pltbutils_sc_t
669
  -- )
670
  --
671
  -- Checks that the value of a signal or variable is equal to expected.
672
  -- If not equal, displays an error message and increments the error counter.
673
  --
674
  -- Arguments: 
675
  --   rpt                      Report message to be displayed in case of 
676
  --                            mismatch. 
677
  --                            It is recommended that the message is unique
678
  --                            and that it contains the name of the signal
679
  --                            or variable being checked. 
680
  --                            The message should NOT contain the expected 
681
  --                            value, becase check() prints that 
682
  --                            automatically.
683
  --
684
  --   data                     The signal or variable to be checked.
685
  --                            Supported types: integer, std_logic, 
686
  --                            std_logic_vector, unsigned, signed.
687
  --
688
  --   expected                 Expected value. 
689
  --                            Same type as data or integer.
690
  --
691
  --   mask                     Bit mask and:ed to data and expected 
692
  --                            before comparison.
693
  --                            Optional if data is std_logic_vector.
694
  --                            Not allowed for other types.
695
  --
696
  --   expr                     boolean expression for checking.
697
  --                            This makes it possible to check any kind of
698
  --                            expresion, not just equality.
699
  -- 
700
  --   pltbutils_sc             PlTbUtils' global status- and control signal.
701
  --                            Must be set to the name pltbutils_sc.
702
  --
703
  -- Examples:
704
  -- check("dat_o after reset", dat_o, 0, pltbutils_sc);
705
  -- -- With mask:
706
  -- check("Status field in reg_o after start", reg_o, x"01", x"03", pltbutils_sc);
707
  -- -- Boolean expression:
708
  -- check("Counter after data burst", cnt_o > 10, pltbutils_sc);
709
  ----------------------------------------------------------------------------
710
  -- check integer
711
  procedure check(
712
    constant rpt                : in    string;
713
    constant data               : in    integer;
714
    constant expected           : in    integer;
715
    signal   pltbutils_sc       : out   pltbutils_sc_t
716
  ) is
717
  begin
718
    v_pltbutils_chk_cnt.inc; -- VHDL-2002
719
    --v_pltbutils_chk_cnt := v_pltbutils_chk_cnt + 1; -- VHDL-1993
720
    if data   /= expected then
721
      assert false
722
      report "Check " &
723
             str(v_pltbutils_chk_cnt.value) & -- VHDL-2002
724
             --str(v_pltbutils_chk_cnt) & -- VHDL-1993
725
             "; " & rpt &
726
             "; Data=" & str(data) &
727
             " Expected=" & str(expected) &
728
             " " & --str(character'(lf)) &
729
             "  in test " &
730
             str(v_pltbutils_test_num.value) & -- VHDL-2002
731
             --str(v_pltbutils_test_num) & -- VHDL-1993
732
             " " &
733
             v_pltbutils_test_name.value -- VHDL-2002
734
             --v_pltbutils_test_name -- VHDL-1993
735
      severity error;
736
      v_pltbutils_err_cnt.inc; -- VHLD-2002
737
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
738
    end if;
739
    pltbutils_sc_update(pltbutils_sc);
740
  end procedure check;
741
 
742
  -- check std_logic
743
  procedure check(
744
    constant rpt                : in    string;
745
    constant data               : in    std_logic;
746
    constant expected           : in    std_logic;
747
    signal   pltbutils_sc       : out   pltbutils_sc_t
748
  ) is
749
  begin
750
    v_pltbutils_chk_cnt.inc; -- VHDL-2002
751
    --v_pltbutils_chk_cnt := v_pltbutils_chk_cnt + 1; -- VHDL-1993
752
    if data /= expected   then
753
      assert false
754
      report "Check " &
755
             str(v_pltbutils_chk_cnt.value) & -- VHDL-2002
756
             --str(v_pltbutils_chk_cnt) & -- VHDL-1993
757
             "; " & rpt   &
758
             "; Data=" & str(data) &
759
             " Expected=" & str(expected) &
760
             " " & --str(character'(lf)) &
761
             "  in test " &
762
             str(v_pltbutils_test_num.value) & -- VHDL-2002
763
             --str(v_pltbutils_test_num) & -- VHDL-1993
764
             " " &
765
             v_pltbutils_test_name.value -- VHDL-2002
766
             --v_pltbutils_test_name -- VHDL-1993
767
      severity error;
768
      v_pltbutils_err_cnt.inc; -- VHLD-2002
769
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
770
    end if;
771
    pltbutils_sc_update(pltbutils_sc);
772
  end procedure check;
773
 
774
  -- check std_logic against integer
775
  procedure check(
776
    constant rpt                : in    string;
777
    constant data               : in    std_logic;
778
    constant expected           : in    integer;
779
    signal   pltbutils_sc       : out   pltbutils_sc_t
780
  ) is
781
    variable v_expected : std_logic;
782
  begin
783
    if expected = 0 then
784
      check(rpt , data, std_logic'('0'), pltbutils_sc);
785
    elsif expected = 1 then
786
      check(rpt , data, std_logic'('1'), pltbutils_sc);
787
    else
788
      v_pltbutils_chk_cnt.inc; -- VHDL-2002
789
      --v_pltbutils_chk_cnt := v_pltbutils_chk_cnt + 1; -- VHDL-1993
790
      assert false
791
      report "Check " &
792
             str(v_pltbutils_chk_cnt.value) & -- VHDL-2002
793
             --str(v_pltbutils_chk_cnt) & -- VHDL-1993
794
             "; " & rpt &
795
             "; Data=" & str(data) &
796
             " Expected=" & str(expected) &
797
             " " & --str(character'(lf)) &
798
             "  in test " &
799
             str(v_pltbutils_test_num.value) & -- VHDL-2002
800
             --str(v_pltbutils_test_num) & -- VHDL-1993
801
             " " &
802
             v_pltbutils_test_name.value -- VHDL-2002
803
             --v_pltbutils_test_name -- VHDL-1993
804
      severity error;
805
      v_pltbutils_err_cnt.inc; -- VHLD-2002
806
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
807
      pltbutils_sc_update(pltbutils_sc);
808
    end if;
809
  end procedure check;
810
 
811
  -- check std_logic_vector
812
  procedure check(
813
    constant rpt                : in    string;
814
    constant data               : in    std_logic_vector;
815
    constant expected           : in    std_logic_vector;
816
    signal   pltbutils_sc       : out   pltbutils_sc_t
817
  ) is
818
  begin
819
    v_pltbutils_chk_cnt.inc; -- VHDL-2002
820
    --v_pltbutils_chk_cnt := v_pltbutils_chk_cnt + 1; -- VHDL-1993
821
    if data   /= expected   then
822
      assert false
823
      report "Check " &
824
             str(v_pltbutils_chk_cnt.value) & -- VHDL-2002
825
             --str(v_pltbutils_chk_cnt) & -- VHDL-1993
826
             "; " & rpt   &
827
             "; Data=" & str(data) &
828
             " Expected=" & str(expected) &
829
             " " & --str('lf') &
830
             "  in test " &
831
             str(v_pltbutils_test_num.value) & -- VHDL-2002
832
             --str(v_pltbutils_test_num) & -- VHDL-1993
833
             " " &
834
             v_pltbutils_test_name.value -- VHDL-2002
835
             --v_pltbutils_test_name -- VHDL-1993
836
      severity error;
837
      v_pltbutils_err_cnt.inc; -- VHDL-2002
838
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
839
    end if;
840
    pltbutils_sc_update(pltbutils_sc);
841
  end procedure check;
842
 
843
  -- check std_logic_vector with mask
844
  procedure check(
845
    constant rpt                : in    string;
846
    constant data               : in    std_logic_vector;
847
    constant expected           : in    std_logic_vector;
848
    constant mask               : in    std_logic_vector;
849
    signal   pltbutils_sc       : out   pltbutils_sc_t
850
  ) is
851
  begin
852
    v_pltbutils_chk_cnt.inc; -- VHDL-2002
853
    --v_pltbutils_chk_cnt := v_pltbutils_chk_cnt + 1; -- VHDL-1993
854
    if (data  and mask) /= (expected and mask) then
855
      assert false
856
      report "Check " &
857
             str(v_pltbutils_chk_cnt.value) & -- VHDL-2002
858
             --str(v_pltbutils_chk_cnt) & -- VHDL-1993
859
             "; " & rpt &
860
             "; Data=" & str(data) &
861
             " Expected=" & str(expected) &
862
             " Mask=" & str(mask) &
863
             " " & --str('lf') &
864
             "  in test " &
865
             str(v_pltbutils_test_num.value) & -- VHDL-2002
866
             --str(v_pltbutils_test_num) & -- VHDL-1993
867
             " " &
868
             v_pltbutils_test_name.value -- VHDL-2002
869
             --v_pltbutils_test_name -- VHDL-1993
870
      severity error;
871
      v_pltbutils_err_cnt.inc; -- VHDL-2002
872
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
873
    end if;
874
    pltbutils_sc_update(pltbutils_sc);
875
  end procedure check;
876
 
877
  -- check std_logic_vector against integer
878
  procedure check(
879
    constant rpt                : in    string;
880
    constant data               : in    std_logic_vector;
881
    constant expected           : in    integer;
882
    signal   pltbutils_sc       : out   pltbutils_sc_t
883
  ) is
884
  begin
885
    check(rpt, data, std_logic_vector(to_signed(expected, data'length)), pltbutils_sc);
886
  end procedure check;
887
 
888
  -- check std_logic_vector with mask against integer
889
  procedure check(
890
    constant rpt                : in    string;
891
    constant data               : in    std_logic_vector;
892
    constant expected           : in    integer;
893
    constant mask               : in    std_logic_vector;
894
    signal   pltbutils_sc       : out   pltbutils_sc_t
895
  ) is
896
  begin
897
    check(rpt, data, std_logic_vector(to_signed(expected, data'length)), mask, pltbutils_sc);
898
  end procedure check;
899
 
900
  -- check unsigned
901
  procedure check(
902
    constant rpt                : in    string;
903
    constant data               : in    unsigned;
904
    constant expected           : in    unsigned;
905
    signal   pltbutils_sc       : out   pltbutils_sc_t
906
  ) is
907
  begin
908
    v_pltbutils_chk_cnt.inc; -- VHDL-2002
909
    --v_pltbutils_chk_cnt := v_pltbutils_chk_cnt + 1; -- VHDL-1993
910
    if data   /= expected   then
911
      assert false
912
      report "Check " &
913
             str(v_pltbutils_chk_cnt.value) & -- VHDL-2002
914
             --str(v_pltbutils_chk_cnt) & -- VHDL-1993
915
             "; " & rpt   &
916
             "; Data=" & str(std_logic_vector(data)) &
917
             " Expected=" & str(std_logic_vector(expected)) &
918
             " " & --str('lf') &
919
             "  in test " &
920
             str(v_pltbutils_test_num.value) & -- VHDL-2002
921
             --str(v_pltbutils_test_num) & -- VHDL-1993
922
             " " &
923
             v_pltbutils_test_name.value -- VHDL-2002
924
             --v_pltbutils_test_name -- VHDL-1993
925
      severity error;
926
      v_pltbutils_err_cnt.inc; -- VHDL-2002
927
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
928
    end if;
929
    pltbutils_sc_update(pltbutils_sc);
930
  end procedure check;
931
 
932
  -- check unsigned against integer
933
  procedure check(
934
    constant rpt                : in    string;
935
    constant data               : in    unsigned;
936
    constant expected           : in    integer;
937
    signal   pltbutils_sc       : out   pltbutils_sc_t
938
  ) is
939
  begin
940
    check(rpt, data, to_unsigned(expected, data'length), pltbutils_sc);
941
  end procedure check;
942
 
943
  -- check signed
944
  procedure check(
945
    constant rpt                : in    string;
946
    constant data               : in    signed;
947
    constant expected           : in    signed;
948
    signal   pltbutils_sc       : out   pltbutils_sc_t
949
  ) is
950
  begin
951
    v_pltbutils_chk_cnt.inc; -- VHDL-2002
952
    --v_pltbutils_chk_cnt := v_pltbutils_chk_cnt + 1; -- VHDL-1993
953
    if data /= expected   then
954
      assert false
955
      report "Check " &
956
             str(v_pltbutils_chk_cnt.value) & -- VHDL-2002
957
             --str(v_pltbutils_chk_cnt) & -- VHDL-1993
958
             "; " & rpt   &
959
             "; Data=" & str(std_logic_vector(data)) &
960
             " Expected=" & str(std_logic_vector(expected)) &
961
             " " & --str('lf') &
962
             "  in test " &
963
             str(v_pltbutils_test_num.value) & -- VHDL-2002
964
             --str(v_pltbutils_test_num) & -- VHDL-1993
965
             " " &
966
             v_pltbutils_test_name.value -- VHDL-2002
967
             --v_pltbutils_test_name -- VHDL-1993
968
      severity error;
969
      v_pltbutils_err_cnt.inc; -- VHDL-2002
970
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
971
    end if;
972
    pltbutils_sc_update(pltbutils_sc);
973
  end procedure check;
974
 
975
  -- check signed against integer
976
  -- TODO: find the bug reported by tb_pltbutils when expected   is negative (-1):
977
  --       ** Error: (vsim-86) numstd_conv_unsigned_nu: NATURAL arg value is negative (-1)
978
  procedure check(
979
    constant rpt                : in    string;
980
    constant data               : in    signed;
981
    constant expected           : in    integer;
982
    signal   pltbutils_sc       : out   pltbutils_sc_t
983
  ) is
984
  begin
985
    check(rpt, data, to_signed(expected, data'length), pltbutils_sc);
986
  end procedure check;
987
 
988
  -- check with boolean expression
989
  -- Check signal or variable with a boolean expression as argument C_EXPR.
990
  -- This allowes any kind of check.
991
  procedure check(
992
    constant rpt                : in    string;
993
    constant expr               : in    boolean;
994
    signal   pltbutils_sc       : out   pltbutils_sc_t
995
  ) is
996
  begin
997
    v_pltbutils_chk_cnt.inc; -- VHDL-2002
998
    --v_pltbutils_chk_cnt := v_pltbutils_chk_cnt + 1; -- VHDL-1993
999
    if not expr then
1000
      assert false
1001
      report "Check " &
1002
             str(v_pltbutils_chk_cnt.value) & -- VHDL-2002
1003
             --str(v_pltbutils_chk_cnt) & -- VHDL-1993
1004
             "; " & rpt   &
1005
             " " & --str('lf') &
1006
             "  in test " &
1007
             str(v_pltbutils_test_num.value) & -- VHDL-2002
1008
             --str(v_pltbutils_test_num) & -- VHDL-1993
1009
             " " &
1010
             v_pltbutils_test_name.value -- VHDL-2002
1011
             --v_pltbutils_test_name -- VHDL-1993
1012
      severity error;
1013
      v_pltbutils_err_cnt.inc; -- VHDL-2002
1014
      --v_pltbutils_err_cnt := v_pltbutils_err_cnt + 1; -- VHDL-1993
1015
    end if;
1016
    pltbutils_sc_update(pltbutils_sc);
1017
  end procedure check;
1018
 
1019
  ----------------------------------------------------------------------------
1020
  -- pltbutils internal procedure(s), called from other pltbutils procedures.
1021
  -- Do not to call this/these from user's code.
1022
  -- This/these procedures are undocumented in the specification on purpose.
1023
  ----------------------------------------------------------------------------
1024
  procedure pltbutils_sc_update(
1025
              signal pltbutils_sc : out pltbutils_sc_t
1026
            ) is
1027
  begin
1028
    -- VHDL-2002:
1029
    pltbutils_sc.test_num   <= v_pltbutils_test_num.value;
1030
    print(pltbutils_sc.test_name, v_pltbutils_test_name.value);
1031
    print(pltbutils_sc.info, v_pltbutils_info.value);
1032
    pltbutils_sc.chk_cnt    <= v_pltbutils_chk_cnt.value;
1033
    pltbutils_sc.err_cnt    <= v_pltbutils_err_cnt.value;
1034
    pltbutils_sc.stop_sim   <= v_pltbutils_stop_sim.value;
1035
    -- VHDL-1993:
1036
    --pltbutils_sc.test_num   <= v_pltbutils_test_num;
1037
    --print(pltbutils_sc.test_name, v_pltbutils_test_name);
1038
    --print(pltbutils_sc.info, v_pltbutils_info);
1039
    --pltbutils_sc.chk_cnt    <= v_pltbutils_chk_cnt;
1040
    --pltbutils_sc.err_cnt    <= v_pltbutils_err_cnt;
1041
    --pltbutils_sc.stop_sim   <= v_pltbutils_stop_sim;
1042
  end procedure pltbutils_sc_update;
1043
 
1044
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.