Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.45 KB | None | 0 0
  1. import uvm_pkg :: *;
  2.  
  3. class my_seq_item extends uvm_sequence_item;
  4. rand logic [7:0] addr;
  5. rand logic [7:0] data;
  6.  
  7. constraint addr_range_cn {
  8. addr inside {[10:20]};
  9. }
  10. constraint data_range_cn {
  11. data inside {[100:200]};
  12. }
  13. `uvm_object_utils_begin(my_seq_item)
  14. `uvm_field_int(addr, UVM_ALL_ON| UVM_DEC)
  15. `uvm_field_int(data, UVM_ALL_ON| UVM_DEC)
  16. `uvm_object_utils_end
  17.  
  18. function new(string name="my_seq_item");
  19. super.new(name);
  20. endfunction : new
  21.  
  22. virtual function string convert2string();
  23. convert2string = $sformatf("addr=%0d, data=%0d", addr, data);
  24. endfunction : convert2string
  25. endclass : my_seq_item
  26.  
  27. class my_sequencer extends uvm_sequencer #(my_seq_item);
  28. `uvm_component_utils (my_sequencer)
  29.  
  30. function new (string name="my_sequencer", uvm_component parent=null);
  31. super.new(name, parent);
  32. endfunction : new
  33. endclass : my_sequencer
  34.  
  35. class my_driver extends uvm_driver #(my_seq_item);
  36. `uvm_component_utils (my_driver)
  37.  
  38. function new (string name="my_driver", uvm_component parent=null);
  39. super.new(name, parent);
  40. endfunction : new
  41.  
  42. function void build_phase (uvm_phase phase);
  43. super.build_phase(phase);
  44. endfunction : build_phase
  45.  
  46. task run_phase(uvm_phase phase);
  47. forever begin
  48. seq_item_port.get_next_item(req);
  49. `uvm_info(get_name(),
  50. $sformatf("in driver after get_next_item my_seq_item= %s", req.convert2string()), UVM_LOW);
  51. #50;
  52. `uvm_info(get_name(), $sformatf("item_done called"), UVM_LOW);
  53. seq_item_port.item_done();
  54. end
  55. endtask : run_phase
  56. endclass : my_driver
  57.  
  58. class my_agent extends uvm_agent;
  59. `uvm_component_utils (my_agent)
  60. my_sequencer sqr;
  61. my_driver drv;
  62.  
  63. function new (string name="my_agent", uvm_component parent=null);
  64. super.new(name, parent);
  65. endfunction : new
  66.  
  67. function void build_phase (uvm_phase phase);
  68. super.build_phase(phase);
  69. sqr = my_sequencer :: type_id :: create("sqr", this);
  70. drv = my_driver :: type_id :: create("drv", this);
  71. endfunction : build_phase
  72.  
  73. function void connect_phase (uvm_phase phase);
  74. super.connect_phase(phase);
  75. drv.seq_item_port.connect(sqr.seq_item_export);
  76. endfunction : connect_phase
  77. endclass : my_agent
  78.  
  79. class my_seq extends uvm_sequence #(my_seq_item);
  80. `uvm_object_utils (my_seq)
  81. function new(string name="my_seq");
  82. super.new(name);
  83.  
  84. // The most common interaction with the starting phase
  85. // within a sequence is to simply ~raise~ the phase's objection
  86. // prior to executing the sequence, and ~drop~ the objection
  87. // after ending the sequence (either naturally, or
  88. // via a call to <kill>). In order to
  89. // simplify this interaction for the user, the UVM
  90. // provides the ability to perform this functionality
  91. // automatically.
  92.  
  93. // From a timeline point of view, the automatic phase objection
  94. // looks like:
  95. //| start() is executed
  96. //| --! Objection is raised !--
  97. //| pre_start() is executed
  98. //| pre_body() is optionally executed
  99. //| body() is executed
  100. //| post_body() is optionally executed
  101. //| post_start() is executed
  102. //| --! Objection is dropped !--
  103. //| start() unblocks
  104.  
  105. // NEVER set the automatic phase objection bit to 1 if your sequence
  106. // runs with a forever loop inside of the body, as the objection will
  107. // never get dropped!
  108. set_automatic_phase_objection(1);
  109. endfunction : new
  110.  
  111. task body ();
  112. `uvm_create(req)
  113. if(!req.randomize()) begin
  114. `uvm_fatal(get_name(), $sformatf("Randomization failed"))
  115. end
  116. `uvm_info (get_name(),
  117. $sformatf("After randomizating in my_seq my_seq_item= %s",
  118. req.convert2string()), UVM_LOW)
  119. `uvm_send(req)
  120. endtask : body
  121. endclass : my_seq
  122.  
  123. class my_test extends uvm_test;
  124. `uvm_component_utils (my_test)
  125. my_agent agent;
  126.  
  127. function new (string name="my_test", uvm_component parent=null);
  128. super.new(name, parent);
  129. endfunction : new
  130.  
  131. function void build_phase (uvm_phase phase);
  132. super.build_phase(phase);
  133. agent = my_agent::type_id::create("agent", this);
  134. endfunction : build_phase
  135.  
  136. task run_phase(uvm_phase phase);
  137. my_seq seq;
  138. uvm_phase starting_phase;
  139. bit automatic_phase_objection_status;
  140. seq = my_seq::type_id::create ("seq");
  141. // Function: set_starting_phase
  142. // Sets the 'starting phase'.
  143. seq.set_starting_phase(phase);
  144.  
  145. // If set_automatic_phase_objection is not called in new (constructor)
  146. // of sequence then can be calleb from test-case
  147. // seq.set_automatic_phase_objection(1);
  148.  
  149. fork
  150. begin
  151. #30;
  152. // Function: get_starting_phase
  153. // Returns the 'starting phase'.
  154. // If non-null, the starting phase specifies the phase in which this
  155. // sequence was started.
  156. starting_phase = seq.get_starting_phase();
  157. `uvm_info(get_name(),
  158. $sformatf("starting_phase:%s", starting_phase.get_full_name()), UVM_LOW)
  159.  
  160. // Function: get_automatic_phase_objection
  161. // Returns (and locks) the value of the 'automatically object to
  162. // starting phase' bit.
  163. //
  164. // If 1, then the sequence will automatically raise an objection
  165. // to the starting phase (if the starting phase is not ~null~) immediately
  166. // prior to <pre_start> being called. The objection will be dropped
  167. // after <post_start> has executed, or <kill> has been called.
  168. automatic_phase_objection_status = seq.get_automatic_phase_objection();
  169. `uvm_info(get_name(),
  170. $sformatf("during seq is running, get_automatic_phase_objection returns :%b", automatic_phase_objection_status), UVM_LOW)
  171. end
  172. join_none
  173. seq.start(agent.sqr);
  174. automatic_phase_objection_status = seq.get_automatic_phase_objection();
  175. `uvm_info(get_name(),
  176. $sformatf("After seq finished, get_automatic_phase_objection returns :%b", automatic_phase_objection_status), UVM_LOW)
  177. endtask : run_phase
  178. endclass : my_test
  179.  
  180. module top();
  181. initial begin
  182. run_test("my_test");
  183. end
  184. endmodule : top
  185.  
  186. //Output:
  187. // UVM_INFO @ 0: reporter [RNTST] Running test my_test...
  188. // UVM_INFO @ 0: run [OBJTN_TRC] Object uvm_test_top.agent.sqr.seq raised 1 objection(s) (automatic phase objection): count=1 total=1
  189. // UVM_INFO @ 0: run [OBJTN_TRC] Object uvm_test_top.agent.sqr added 1 objection(s) to its total (raised from source object , automatic phase objection): count=0 total=1
  190. // UVM_INFO @ 0: run [OBJTN_TRC] Object uvm_test_top.agent added 1 objection(s) to its total (raised from source object , automatic phase objection): count=0 total=1
  191. // UVM_INFO @ 0: run [OBJTN_TRC] Object uvm_test_top added 1 objection(s) to its total (raised from source object uvm_test_top.agent.sqr.seq, automatic phase objection): count=0 total=1
  192. // UVM_INFO @ 0: run [OBJTN_TRC] Object uvm_top added 1 objection(s) to its total (raised from source object uvm_test_top.agent.sqr.seq, automatic phase objection): count=0 total=1
  193. // UVM_INFO testbench.sv(118) @ 0: uvm_test_top.agent.sqr@@seq [seq] After randomizating in my_seq my_seq_item= addr=19, data=140
  194. // UVM_INFO testbench.sv(50) @ 0: uvm_test_top.agent.drv [drv] in driver after get_next_item my_seq_item= addr=19, data=140
  195. // UVM_INFO testbench.sv(158) @ 30: uvm_test_top [uvm_test_top] starting_phase:common.run
  196. // UVM_INFO testbench.sv(170) @ 30: uvm_test_top [uvm_test_top] during seq is running, get_automatic_phase_objection returns :1
  197. // UVM_INFO testbench.sv(52) @ 50: uvm_test_top.agent.drv [drv] item_done called
  198. // UVM_INFO @ 50: run [OBJTN_TRC] Object uvm_test_top.agent.sqr.seq dropped 1 objection(s) (automatic phase objection): count=0 total=0
  199. // UVM_INFO @ 50: run [OBJTN_TRC] Object uvm_test_top.agent.sqr.seq all_dropped 1 objection(s) (automatic phase objection): count=0 total=0
  200. // UVM_INFO @ 50: run [OBJTN_TRC] Object uvm_test_top.agent.sqr subtracted 1 objection(s) from its total (dropped from source object , automatic phase objection): count=0 total=0
  201. // UVM_INFO @ 50: run [OBJTN_TRC] Object uvm_test_top.agent.sqr subtracted 1 objection(s) from its total (all_dropped from source object , automatic phase objection): count=0 total=0
  202. // UVM_INFO @ 50: run [OBJTN_TRC] Object uvm_test_top.agent subtracted 1 objection(s) from its total (dropped from source object , automatic phase objection): count=0 total=0
  203. // UVM_INFO @ 50: run [OBJTN_TRC] Object uvm_test_top.agent subtracted 1 objection(s) from its total (all_dropped from source object , automatic phase objection): count=0 total=0
  204. // UVM_INFO @ 50: run [OBJTN_TRC] Object uvm_test_top subtracted 1 objection(s) from its total (dropped from source object uvm_test_top.agent.sqr.seq, automatic phase objection): count=0 total=0
  205. // UVM_INFO @ 50: run [OBJTN_TRC] Object uvm_test_top subtracted 1 objection(s) from its total (all_dropped from source object uvm_test_top.agent.sqr.seq, automatic phase objection): count=0 total=0
  206. // UVM_INFO @ 50: run [OBJTN_TRC] Object uvm_top subtracted 1 objection(s) from its total (dropped from source object uvm_test_top.agent.sqr.seq, automatic phase objection): count=0 total=0
  207. // UVM_INFO @ 50: run [OBJTN_TRC] Object uvm_top subtracted 1 objection(s) from its total (all_dropped from source object uvm_test_top.agent.sqr.seq, automatic phase objection): count=0 total=0
  208. // UVM_INFO uvm-1.2/src/base/uvm_objection.svh(1271) @ 50: reporter [TEST_DONE] 'run' phase is ready to proceed to the 'extract' phase
  209. // UVM_INFO testbench.sv(176) @ 50: uvm_test_top [uvm_test_top] After seq finished, get_automatic_phase_objection returns :1
  210. // UVM_INFO uvm-1.2/src/base/uvm_report_server.svh(847) @ 50: reporter [UVM/REPORT/SERVER]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement