ovm_scenario.svh

Go to the documentation of this file.
00001 //----------------------------------------------------------------------
00002 //   Copyright 2007-2008 Mentor Graphics Corporation
00003 //   Copyright 2007-2008 Cadence Design Systems, Inc.
00004 //   All Rights Reserved Worldwide
00005 //
00006 //   Licensed under the Apache License, Version 2.0 (the
00007 //   "License"); you may not use this file except in
00008 //   compliance with the License.  You may obtain a copy of
00009 //   the License at
00010 //
00011 //       http://www.apache.org/licenses/LICENSE-2.0
00012 //
00013 //   Unless required by applicable law or agreed to in
00014 //   writing, software distributed under the License is
00015 //   distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
00016 //   CONDITIONS OF ANY KIND, either express or implied.  See
00017 //   the License for the specific language governing
00018 //   permissions and limitations under the License.
00019 //----------------------------------------------------------------------
00020 
00021 typedef class ovm_scenario_controller_base;
00022 
00023 class ovm_scenario_base extends ovm_object;
00024 
00025 local static int g_id = 0;
00026 local int id;
00027 local ovm_scenario_base  m_parent;
00028 
00029 // Weighted priority
00030 local int weighted_priority = 100;
00031 
00032 protected bit grant_flag = 0;
00033 protected ovm_scenario_driver_base    m_driver_ptr;
00034 protected ovm_scenario_controller_base m_scenario_controller;
00035 
00036 function new (string name);
00037     super.new(name);
00038     id = g_id++;
00039 endfunction // new
00040 
00041 virtual task pre_apply();
00042   return;
00043 endtask
00044 
00045 virtual task mid_apply();
00046   return;
00047 endtask
00048 
00049 virtual task post_apply();
00050   return;
00051 endtask // post_apply
00052 
00053 virtual task pre_body();
00054   return;
00055 endtask // pre_body
00056 
00057 virtual task body();
00058   return;
00059 endtask
00060 
00061 virtual task post_body();
00062   return;
00063 endtask // post_body
00064 
00066 //
00067 // is_relevant
00068 //   indicate to the scenario_controller if this scenario is
00069 //   ready to provide a ovm_transaction
00071 
00072 virtual function bit is_relevant();
00073     return 1;
00074 endfunction // bit
00075 
00077 //
00078 // get_id
00079 //   provide the unique base_id of this scenario
00081 
00082 function int get_id();
00083     return id;
00084 endfunction
00085 
00086 function int get_weighted_priority();
00087     return (weighted_priority);
00088 endfunction
00089 
00090 function void set_weighted_priority(int val);
00091     weighted_priority = val;
00092 endfunction
00093 
00095 //
00096 // grant
00097 //   called by the scenario_controller to grant a request or
00098 //   lock operation
00100 
00101 virtual function void grant(ovm_scenario_driver_base driver_ptr);
00102     grant_flag = 1;
00103     m_driver_ptr = driver_ptr;
00104 endfunction // void
00105 
00107 //
00108 // get_parent_scenario
00109 //   return a pointer to the parent scenario, or null
00110 //   if this is a top-most scenario
00112   
00113 function ovm_scenario_base get_parent_scenario();
00114     return m_parent;
00115 endfunction // ovm_scenario_base
00116 
00118 //
00119 // get_depth
00120 //   return the number of ancestor scenarios this
00121 //   scenario has
00123   
00124 function int get_depth();
00125     int i;
00126     ovm_scenario_base ptr; 
00127     i = 0;
00128     ptr = get_parent_scenario();
00129 
00130     while (ptr != null) begin
00131       i++;
00132       ptr = ptr.get_parent_scenario();
00133     end
00134     return (i);
00135 endfunction // int
00136 
00138 //
00139 // get_scenario_path_name
00141   
00142 function string get_scenario_path_name();
00143     string s;
00144     ovm_scenario_base seq_ptr; 
00145     seq_ptr = get_parent_scenario();
00146 
00147     $sformat(s, "%s", get_name());
00148     while (seq_ptr != null) begin
00149       $sformat(s, "%s.%s", seq_ptr.get_name(),s);
00150       seq_ptr = seq_ptr.get_parent_scenario();
00151     end
00152     return (s);
00153 endfunction
00154 
00156 //
00157 // Lock
00158 //    Request a scenario_controller lock, wait until lock is granted
00160 
00161 task lock();
00162     
00163     if (m_scenario_controller == null) ovm_report_fatal("seqA", "null m_scenario_controller");
00164     grant_flag = 0;
00165     m_scenario_controller.lock_req(this);
00166     wait (grant_flag == 1);
00167     grant_flag = 0;
00168 endtask // lock
00169 
00171 //
00172 // unlock
00173 //   unlock this scenario if locked
00175   
00176 function void unlock();
00177     if (m_scenario_controller == null) ovm_report_fatal("seqA", "null m_scenario_controller");
00178     m_scenario_controller.unlock_req(this);
00179 endfunction // unlock
00180 
00182 //
00183 // is_blocked
00184 //   indicate if another lock prevents this scenario from
00185 //   executing
00187   
00188 function bit is_blocked();
00189     if (m_scenario_controller == null) ovm_report_fatal("seqA", "null m_scenario_controller");
00190     return(m_scenario_controller.is_blocked(this));
00191 endfunction
00192 
00194 //
00195 // start
00196 //   start execution of this scenario
00198   
00199 virtual task start(ovm_scenario_controller_base scenario_controller, 
00200                    ovm_scenario_base parent_seq = null,
00201          int weighted_priority = 100);
00202 
00203     m_scenario_controller = scenario_controller;
00204     m_parent    = parent_seq;
00205     set_weighted_priority(weighted_priority);
00206     pre_body();
00207     body();
00208     post_body();
00209 endtask // start
00210 
00211 endclass
00212 
00214 //
00215 // Use the ovm_scenario class if the driver only needs
00216 // to pass a single ovm_transaction back and forth
00217 // for each operation.
00219 
00220 virtual class ovm_scenario #(type REQ = ovm_transaction,
00221                               type RSP = ovm_transaction) extends ovm_scenario_base;
00222 
00223 
00224   typedef ovm_scenario_driver #(REQ, RSP) p_drv_t;
00225   protected p_drv_t p_drv;
00226 
00227 function new (string name);
00228     super.new(name);
00229 endfunction // new
00230 
00232 //
00233 // apply
00234 //   send a scenario_item to the driver, and get
00235 //   the response back
00237 
00238   virtual task apply_request(input REQ data_req, input bit randomize = 1);
00239     grant_flag = 0;
00240     if (m_scenario_controller == null) ovm_report_fatal("seqA", "null m_scenario_controller");
00241     m_scenario_controller.request(this);
00242     wait(grant_flag == 1);
00243     pre_apply();
00244 
00245     if (m_driver_ptr == null) ovm_report_fatal(get_full_name(), "null m_driver_ptr");
00246     grant_flag = 0;
00247     if (randomize == 1) begin
00248       assert(data_req.randomize());
00249     end
00250     mid_apply();
00251   endtask
00252   
00253 virtual task apply_send(input REQ data_req, input bit randomize = 1);
00254     
00255     apply_request(data_req, randomize);
00256 
00257     if ($cast(p_drv, m_driver_ptr) == 0) begin
00258       ovm_report_fatal("ovm_scenario", "Error casting pdrv from driver_ptr");
00259     end
00260     
00261     p_drv.put_req.put(data_req);
00262     post_apply();
00263 endtask    
00264     
00265 virtual task apply(input REQ data_req, output RSP data_rsp, input bit randomize = 1);
00266     
00267     apply_request(data_req, randomize);
00268 
00269     if ($cast(p_drv, m_driver_ptr) == 0) begin
00270       ovm_report_fatal("ovm_scenario", "Error casting pdrv from driver_ptr");
00271     end
00272     
00273     p_drv.put_req.put(data_req);
00274     p_drv.get_rsp.get(data_rsp);
00275     post_apply();
00276 endtask    
00277     
00278 endclass
00279 
00281 //
00282 // Use the ovm_scenario_noparam class for drivers
00283 // that need arbitrary ports and communication with
00284 // the sequenc
00286   
00287 virtual class ovm_scenario_noparam extends ovm_scenario_base;
00288 
00289 function new (string name);
00290     super.new(name);
00291 endfunction // new
00292 
00293 virtual task send_request(output ovm_scenario_driver_base driver_ptr);
00294     grant_flag = 0;
00295     
00296     if (m_scenario_controller == null) ovm_report_fatal("seqA", "null m_scenario_controller");
00297     m_scenario_controller.request(this);
00298     wait(grant_flag == 1);
00299     pre_apply();
00300 
00301     if (m_driver_ptr == null) ovm_report_fatal(get_full_name(), "null m_driver_ptr");
00302     grant_flag = 0;
00303     driver_ptr = m_driver_ptr;
00304     return;
00305 endtask
00306 
00307 virtual task send();
00308 endtask    
00309     
00310 endclass
00311 
00312 
00313 static int inst_num = 0;
00314 
00315 class ovm_stimulus_scenario #(type REQ = ovm_transaction) 
00316   extends ovm_scenario  #(REQ, REQ);
00317 
00318 tlm_fifo #(REQ) m_req_fifo;
00319 ovm_blocking_put_export #(REQ) put_req_export;
00320 
00321 
00322 function new (string name, ovm_component parent);
00323     string nm;
00324     super.new(name);
00325     nm.itoa(inst_num);
00326     inst_num++;
00327     // Assign null, since scenarios aren't components
00328     put_req_export = new({"stim_put_req_export_",nm}, null);
00329     m_req_fifo     = new({"stim_req_fifo_",nm}, null, 1);
00330     put_req_export.connect(m_req_fifo.put_export);
00331 endfunction // new
00332 
00333 task body();
00334     REQ req;
00335 
00336     forever begin
00337       m_req_fifo.get(req);
00338       apply_send(req);
00339     end
00340 endtask // body
00341 endclass
00342   

Intelligent Design Verification
Intelligent Design Verification
Project: OVM, Revision: 1.1.0
Copyright (c) 2008 Intelligent Design Verification.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included here:
http://www.intelligentdv.com/licenses/fdl.txt
doxygen
Doxygen Version: 1.4.6
Mon Sep 29 14:20:12 2008
Find a documentation bug? Report bugs to: bugs.intelligentdv.com Project: DoxygenFilterSV