UVM Tutorial for Candy Lovers #32 - 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

211


193
 
1
//------------------------------------------------------------------------------
2
// Class: one_jelly_bean_sequence
3
//------------------------------------------------------------------------------
4
5
class one_jelly_bean_sequence extends uvm_sequence#( jelly_bean_transaction );
6
  `uvm_object_utils( one_jelly_bean_sequence )
7
  
8
  //----------------------------------------------------------------------------
9
  // Function: new
10
  //----------------------------------------------------------------------------
11
12
  function new( string name = "one_jelly_bean_sequence" );
13
    super.new( name );
14
  endfunction: new
15
16
  //----------------------------------------------------------------------------
17
  // Task: body
18
  //----------------------------------------------------------------------------
19
  
20
  task body();
21
    jelly_bean_transaction jb_tx;
22
    jb_tx = jelly_bean_transaction::type_id::create( .name( "jb_tx" ) );
23
    start_item( jb_tx );
24
    assert( jb_tx.randomize() );
25
    finish_item( jb_tx );
26
  endtask: body
27
  
28
endclass: one_jelly_bean_sequence
29
30
//------------------------------------------------------------------------------
31
// Class: same_flavored_jelly_bean_sequence
32
//   Sequence of transactions.
33
//------------------------------------------------------------------------------
34
35
class same_flavored_jelly_bean_sequence extends uvm_sequence#( jelly_bean_transaction );
36
  `uvm_object_utils( same_flavored_jelly_bean_sequence )
37
  
38
  rand int unsigned num_jelly_beans; // knob
39
  rand jelly_bean_transaction flavor_setter;
40
41
  constraint num_jelly_beans_con { num_jelly_beans inside { [2:4] }; }
42
43
  //----------------------------------------------------------------------------
44
  // Function: new
45
  //----------------------------------------------------------------------------
46
47
  function new( string name = "" );
48
    super.new( name );
49
    flavor_setter = jelly_bean_transaction::type_id::create( .name( "flavor_setter" ) );
50
  endfunction: new
51
52
  //----------------------------------------------------------------------------
53
  // Task: body
54
  //----------------------------------------------------------------------------
55
56
  task body();
57
    jelly_bean_transaction jb_tx;
58
//  flavor_e               jb_flavor;
59
60
//  jb_tx = jelly_bean_transaction::type_id::create( .name( "jb_tx" ) );
61
//  assert( jb_tx.randomize() );
62
//  jb_flavor = jb_tx.flavor;
63
64
    repeat ( num_jelly_beans ) begin
65
      jb_tx = jelly_bean_transaction::type_id::create( .name( "jb_tx" ) );
66
      start_item( jb_tx );
67
      assert( jb_tx.randomize() with { jb_tx.flavor == flavor_setter.flavor; } );
68
      finish_item( jb_tx );
69
    end
70
   endtask: body
71
72
  //----------------------------------------------------------------------------
73
  // Function: do_copy
74
  //----------------------------------------------------------------------------
75
76
  virtual function void do_copy( uvm_object rhs );
77
    same_flavored_jelly_bean_sequence that;
78
79
    if ( ! $cast( that, rhs ) ) begin
80
      `uvm_error( get_name(), "rhs is not a same_flavored_jelly_bean_sequence" )
81
      return;
82
    end
83
84
    super.do_copy( rhs );
85
    this.num_jelly_beans = that.num_jelly_beans;
86
  endfunction: do_copy
87
  
88
  //----------------------------------------------------------------------------
89
  // Function: do_compare
90
  //----------------------------------------------------------------------------
91
92
  virtual function bit do_compare( uvm_object rhs, uvm_comparer comparer );
93
    same_flavored_jelly_bean_sequence that;
94
95
    if ( ! $cast( that, rhs ) ) return 0;
96
97
    return ( super.do_compare( rhs, comparer )  &&
98
             this.num_jelly_beans == that.num_jelly_beans );
99
  endfunction: do_compare
100
101
  //----------------------------------------------------------------------------
102
  // Function: convert2string
103
  //----------------------------------------------------------------------------
104
  
105
  virtual function string convert2string();
106
    string s = super.convert2string();
107
    s = { s, $sformatf( "\nnum_jelly_beans: %0d", num_jelly_beans ) };
108
    return s;
109
  endfunction: convert2string
110
111
endclass: same_flavored_jelly_bean_sequence
112
113
//------------------------------------------------------------------------------
114
// Class: gift_boxed_jelly_bean_sequence
115
//   Sequence of sequences.
116
//------------------------------------------------------------------------------
117
118
class gift_boxed_jelly_bean_sequence extends uvm_sequence#( jelly_bean_transaction );
119
  `uvm_object_utils( gift_boxed_jelly_bean_sequence )
120
  
121
  rand int unsigned num_jelly_bean_flavors; // knob
122
123
  constraint num_jelly_bean_flavors_con { num_jelly_bean_flavors inside { [2:3] }; }
124
  
125
  //----------------------------------------------------------------------------
126
  // Function: new
127
  //----------------------------------------------------------------------------
128
129
  function new( string name = "" );
130
    super.new( name );
131
  endfunction: new
132
  
133
  //----------------------------------------------------------------------------
134
  // Task: body
135
  //----------------------------------------------------------------------------
136
137
  task body();
138
    same_flavored_jelly_bean_sequence jb_seq;
139
    
140
    jb_seq = same_flavored_jelly_bean_sequence::type_id::create( .name( "jb_seq" ) );
141
    repeat ( num_jelly_bean_flavors ) begin
142
//    jb_seq = same_flavored_jelly_bean_sequence::type_id::create( .name( "jb_seq" ) );
143
      assert( jb_seq.randomize() );
144
      `uvm_info( get_name(), jb_seq.convert2string(), UVM_NONE )
145
      jb_seq.start( m_sequencer );
146
    end
147
  endtask: body
148
  
149
  //----------------------------------------------------------------------------
150
  // Function: do_copy
151
  //----------------------------------------------------------------------------
152
153
  virtual function void do_copy( uvm_object rhs );
154
    gift_boxed_jelly_bean_sequence that;
155
156
    if ( ! $cast( that, rhs ) ) begin
157
      `uvm_error( get_name(), "rhs is not a gift_boxed_jelly_bean_sequence" )
158
      return;
159
    end
160
161
    super.do_copy( rhs );
162
    this.num_jelly_bean_flavors = that.num_jelly_bean_flavors;
163
  endfunction: do_copy
164
  
165
  //----------------------------------------------------------------------------
166
  // Function: do_compare
167
  //----------------------------------------------------------------------------
168
169
  virtual function bit do_compare( uvm_object rhs, uvm_comparer comparer );
170
    gift_boxed_jelly_bean_sequence that;
171
172
    if ( ! $cast( that, rhs ) ) return 0;
173
174
    return ( super.do_compare( rhs, comparer )  &&
175
             this.num_jelly_bean_flavors == that.num_jelly_bean_flavors );
176
  endfunction: do_compare
177
178
  //----------------------------------------------------------------------------
179
  // Function: convert2string
180
  //----------------------------------------------------------------------------
181
  
182
  virtual function string convert2string();
183
    string s = super.convert2string();
184
    s = { s, $sformatf( "\nnum_jelly_bean_flavors: %0d", num_jelly_bean_flavors ) };
185
    return s;
186
  endfunction: convert2string
187
188
endclass: gift_boxed_jelly_bean_sequence
189
190
//==============================================================================
191
// Copyright (c) 2014 ClueLogic, LLC
192
// http://cluelogic.com/
193
//==============================================================================
45
 
1
//------------------------------------------------------------------------------
2
// Interface: jelly_bean_if
3
//------------------------------------------------------------------------------
4
5
interface jelly_bean_if( input bit clk );
6
  logic [2:0] flavor;
7
  logic [1:0] color;
8
  logic       sugar_free;
9
  logic       sour;
10
  logic [1:0] taste;
11
  
12
  //----------------------------------------------------------------------------
13
  // Clocking block: master_cb
14
  //----------------------------------------------------------------------------
15
16
  clocking master_cb @( posedge clk );
17
    default input #1ns output #1ns;
18
    output flavor, color, sugar_free, sour;
19
    input  taste;
20
  endclocking: master_cb
21
22
  //----------------------------------------------------------------------------
23
  // Clocking block: slave_cb
24
  //----------------------------------------------------------------------------
25
  
26
  clocking slave_cb @( posedge clk );
27
    default input #1ns output #1ns;
28
    input  flavor, color, sugar_free, sour;
29
    output taste;
30
  endclocking: slave_cb
31
32
  //----------------------------------------------------------------------------
33
  // Modports
34
  //----------------------------------------------------------------------------
35
36
  modport master_mp( input clk, taste, output flavor, color, sugar_free, sour );
37
  modport slave_mp ( input clk, flavor, color, sugar_free, sour, output taste );
38
  modport master_sync_mp( clocking master_cb );
39
  modport slave_sync_mp ( clocking slave_cb  );
40
endinterface: jelly_bean_if
41
42
//==============================================================================
43
// Copyright (c) 2014 ClueLogic, LLC
44
// http://cluelogic.com/
45
//==============================================================================
316 views and 0 likes     
 
Using randc

Using randc

120:0