[IV] SystemVerilog packages - EDA Playground
Warning! This exercise has been opened in another tab; autosave has been disabled. Close this tab or refresh to reactivate.

 Languages & Libraries

 Tools & Simulators

 Examples

209


40
 
1
// This tests SystemVerilog packages
2
//
3
// This file ONLY is placed into the Public Domain, for any use,
4
// without warranty, 2012 by Iztok Jeras.
5
module test ();
6
7
   // import all from p1
8
   import p1::*;
9
   // import only p2_* from p2
10
   import p2::p2_prmt;
11
   import p2::p2_type;
12
   import p2::p2_func;
13
   // import nothing from p3
14
15
   // declare a set of variables
16
       p1_type p1_var;
17
       p2_type p2_var;
18
   p3::p3_type p3_var;
19
20
   // error counter
21
   bit err = 0;
22
23
   initial begin
24
      // test parameters
25
      if (    p1_prmt !== 100+10+1) begin $display("FAILED --     p1_prmt = %d != 100+10+1",     p1_prmt); err=1; end
26
      if (    p2_prmt !== 100+20+2) begin $display("FAILED --     p2_prmt = %d != 100+20+2",     p2_prmt); err=1; end
27
      if (p3::p3_prmt !== 100+30+3) begin $display("FAILED -- p3::p3_prmt = %d != 100+30+3", p3::p3_prmt); err=1; end
28
      // test variable bit sizes
29
      if ($bits(p1_var) !== 10+1) begin $display("FAILED -- lv = %d != 10+1", $bits(p1_var)); err=1; end
30
      if ($bits(p2_var) !== 20+2) begin $display("FAILED -- lv = %d != 20+2", $bits(p2_var)); err=1; end
31
      if ($bits(p3_var) !== 30+3) begin $display("FAILED -- lv = %d != 30+3", $bits(p3_var)); err=1; end
32
      // test functions
33
      if (    p1_func(1000) !== 1000+10+1) begin $display("FAILED --     p1_func(1000) = %d != 1000+10+1",     p1_func(1000)); err=1; end
34
      if (    p2_func(1000) !== 1000+20+2) begin $display("FAILED --     p2_func(1000) = %d != 1000+20+2",     p2_func(1000)); err=1; end
35
      if (p3::p3_func(1000) !== 1000+30+3) begin $display("FAILED -- p3::p3_func(1000) = %d != 1000+30+3", p3::p3_func(1000)); err=1; end
36
37
      if (!err) $display("PASSED");
38
   end
39
40
endmodule // test
xxxxxxxxxx
1
50
 
1
// This tests SystemVerilog packages
2
//
3
// This file ONLY is placed into the Public Domain, for any use,
4
// without warranty, 2012 by Iztok Jeras.
5
6
package p1;
7
   localparam int p1_prmt = 100+10+1;
8
   typedef bit [10+1-1:0] p1_type;
9
   function int p1_func (int x);
10
      p1_func = x+10+1;
11
   endfunction
12
endpackage
13
14
package p2;
15
   localparam int p1_prmt = 100+20+1;
16
   typedef bit [20+1-1:0] p1_type;
17
   function int p1_func (int x);
18
      p1_func = x+20+1;
19
   endfunction
20
21
   localparam int p2_prmt = 100+20+2;
22
   typedef bit [20+2-1:0] p2_type;
23
   function int p2_func (int x);
24
      p2_func = x+20+2;
25
   endfunction
26
endpackage
27
28
package p3;
29
   localparam int p1_prmt = 100+30+1;
30
   typedef bit [30+1-1:0] p1_type;
31
   function int p1_func (int x);
32
      p1_func = x+30+1;
33
   endfunction
34
35
   localparam int p2_prmt = 100+30+2;
36
   typedef bit [30+2-1:0] p2_type;
37
   function int p2_func (int x);
38
      p2_func = x+30+2;
39
   endfunction
40
41
   localparam int p3_prmt = 100+30+3;
42
   typedef bit [30+3-1:0] p3_type;
43
   function int p3_func (int x);
44
      p3_func = x+30+3;
45
   endfunction
46
endpackage
47
48
49
50
1917 views and 0 likes     
 
This tests SystemVerilog packages

This tests SystemVerilog packages

140:0