ovm_sequencer_param_base.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 
00022   typedef class ovm_sequence_base;
00023 
00024 class ovm_sequencer_param_base #(type REQ = ovm_sequence_item,
00025                                  type RSP = REQ) extends ovm_sequencer_base;
00026 
00027   typedef ovm_sequencer_param_base #( REQ , RSP) this_type;
00028 
00029 //    static bit sequences[string] = '{default:0};
00030 
00031   REQ m_last_req_buffer[$];
00032   RSP m_last_rsp_buffer[$];
00033 
00034   protected int m_num_last_reqs = 1;
00035   protected int num_last_items = m_num_last_reqs;
00036   protected int m_num_last_rsps = 1;
00037   protected int m_num_reqs_sent = 0;
00038   protected int m_num_rsps_received = 0;
00039 
00040   // Response Analysis Fifo
00041   ovm_analysis_export #(RSP) rsp_export;
00042   sequencer_analysis_fifo #(RSP) sqr_rsp_analysis_fifo;
00043 
00044   // Fifo for handing reqests between scenario and driver
00045   tlm_fifo #(REQ) m_req_fifo;
00046   
00047   function new (string name, ovm_component parent);
00048     super.new(name, parent);
00049 
00050     rsp_export              = new("rsp_export", this);
00051     sqr_rsp_analysis_fifo   = new("sqr_rsp_analysis_fifo", this);
00052     sqr_rsp_analysis_fifo.print_enabled = 0;
00053     m_req_fifo              = new("req_fifo", this);
00054     m_req_fifo.print_enabled = 0;
00055   endfunction // new
00056   
00057   function void do_print (ovm_printer printer);
00058     super.do_print(printer);
00059     printer.print_field("num_last_reqs", m_num_last_reqs, $bits(m_num_last_reqs), OVM_DEC);
00060     printer.print_field("num_last_rsps", m_num_last_rsps, $bits(m_num_last_rsps), OVM_DEC);
00061   endfunction
00062 
00063   function void connect();
00064     rsp_export.connect(sqr_rsp_analysis_fifo.analysis_export);
00065   endfunction // void
00066 
00067   virtual function void build();
00068     super.build();
00069     sqr_rsp_analysis_fifo.sequencer_ptr = this;
00070   endfunction // function
00071   
00073   //
00074   // Local functions
00075   //
00077 
00078   
00080   //
00081   // Methods available to Sequencers
00082   // 
00084   
00085   virtual function void send_request(ovm_sequence_base sequence_ptr, ovm_sequence_item t, bit rerandomize = 0);
00086     REQ param_t;
00087 
00088     if (sequence_ptr == null) begin
00089       ovm_report_fatal("SNDREQ", "Send request sequence_ptr is null");
00090     end
00091 
00092     if (sequence_ptr.m_wait_for_grant_semaphore < 1) begin
00093       ovm_report_fatal("SNDREQ", "Send request called without wait_for_grant");
00094     end
00095     sequence_ptr.m_wait_for_grant_semaphore--;
00096     
00097     assert($cast(param_t, t)) begin
00098       if (param_t.get_transaction_id() == -1) begin
00099         param_t.set_transaction_id(sequence_ptr.m_next_transaction_id++);
00100       end
00101       m_last_req_push_front(param_t);
00102     end else begin
00103       ovm_report_fatal(get_name(),$psprintf("send_request failed to cast sequence item"));
00104 //      $display("\nparam_t: %p\n\nt: %p\n\n", param_t, t);
00105     end
00106 
00107     param_t.set_sequence_id(sequence_ptr.m_get_sqr_sequence_id(m_sequencer_id, 1));
00108     t.set_sequencer(this);
00109     if (m_req_fifo.try_put(param_t) != 1) begin
00110       ovm_report_fatal(get_full_name(), 
00111                        $psprintf("Sequencer send_request not able to put to fifo, depth; %0d", m_req_fifo.size()));
00112     end
00113 
00114     m_num_reqs_sent++;
00115     // Grant any locks as soon as possible
00116     grant_queued_locks();
00117   endfunction
00118     
00119   function REQ get_current_item();
00120     REQ t;
00121 
00122     if (m_req_fifo.try_peek(t) == 0) begin
00123       return (null);
00124     end
00125     return(t);
00126   endfunction // REQ
00127 
00128   function void put_response (RSP t);
00129     ovm_sequence_base sequence_ptr;
00130     
00131     if (t == null) begin
00132       ovm_report_fatal("SQRPUT", "Driver put a null response");
00133     end
00134 `ifndef CDNS_NO_SQR_CHK_SEQ_ID
00135     // Check that set_id_info was called
00136     if (t.get_sequence_id() == -1) begin
00137       ovm_report_fatal("SQRPUT", "Driver put a response with null sequence_id");
00138     end
00139 `endif
00140       
00141     m_last_rsp_push_front(t);
00142     m_num_rsps_received++;
00143 
00144     sequence_ptr = find_sequence(t.get_sequence_id());
00145 
00146     if (sequence_ptr != null) begin
00147       // If the response_handler is enabled for this sequence, then call the response handler
00148       if (sequence_ptr.get_use_response_handler() == 1) begin
00149         sequence_ptr.response_handler(t);
00150         return;
00151       end
00152       
00153       sequence_ptr.put_response(t);
00154     end
00155     else begin
00156       ovm_report_info("Sequencer", $psprintf("Dropping response for sequence %0d, sequence not found", t.get_sequence_id()));
00157     end
00158   endfunction // void
00159   
00160   virtual function void analysis_write(ovm_sequence_item t);
00161     RSP response;
00162 
00163     assert($cast(response, t)) else begin
00164       ovm_report_fatal("ANALWRT", "Failure to cast analysis port write item");
00165     end
00166     put_response(response);
00167   endfunction
00168   
00169 // start_default_sequence
00170 // ----------------------
00171 
00172   task start_default_sequence();
00173     ovm_sequence_base m_seq ;
00174 
00175     if(sequences.size() != 0) begin
00176       
00177       //create the sequence object
00178       if (!$cast(m_seq, factory.create_object_by_name(default_sequence, 
00179                                                    get_full_name(), default_sequence))) 
00180         begin
00181           ovm_report_fatal("FCTSEQ", 
00182                            $psprintf("Default sequence set to invalid value : %0s.", 
00183                                      default_sequence));
00184         end
00185 
00186       assert(m_seq != null) else begin
00187         ovm_report_fatal("STRDEFSEQ", "Null m_sequencer reference");
00188       end
00189       m_seq.print_sequence_info = 1;
00190       m_seq.set_parent_sequence(null);
00191       m_seq.set_sequencer(this);
00192       m_seq.reseed();
00193       assert(m_seq.randomize()) else begin
00194         ovm_report_warning("STRDEFSEQ", "Failed to randomize sequence");
00195       end
00196       if(count != 0)
00197         m_seq.start(this);
00198     end
00199   endtask
00200 
00201   task run();
00202     start_default_sequence();
00203   endtask // run
00204 
00205   // get_num_reqs_sent
00206   // -----------------
00207 
00208   function int get_num_reqs_sent();
00209     return m_num_reqs_sent;
00210   endfunction
00211 
00212   // get_num_rsps_sent
00213   // -----------------
00214 
00215   function int get_num_rsps_received();
00216     return m_num_rsps_received;
00217   endfunction
00218 
00219   // set_num_last_reqs
00220   // -----------------
00221 
00222   function void set_num_last_reqs(int unsigned max);
00223     if(max > 1024) begin
00224       ovm_report_warning("HSTOB", 
00225         $psprintf("Invalid last size; 1024 is the maximum and will be used", max));
00226       max = 1024;
00227     end
00228 
00229     //shrink the buffer
00230     while((m_last_req_buffer.size() != 0) && (m_last_req_buffer.size() > max)) begin
00231       void'(m_last_req_buffer.pop_back());
00232     end
00233 
00234     m_num_last_reqs = max;
00235     num_last_items = max;
00236 
00237   endfunction
00238 
00239   // get_num_last_reqs
00240   // -----------------
00241 
00242   function int unsigned get_num_last_reqs();
00243     return m_num_last_reqs;
00244   endfunction
00245 
00246   // last_req
00247   // --------
00248 
00249   function REQ last_req(int unsigned n = 0);
00250     if(n > m_num_last_reqs) begin
00251       ovm_report_warning("HSTOB",
00252         $psprintf("Invalid last access (%0d), the max history is %0d", n,
00253         m_num_last_reqs));
00254       return null;
00255     end
00256     if(n == m_last_req_buffer.size())
00257       return null;
00258   
00259     return m_last_req_buffer[n];
00260   endfunction
00261   
00262   // m_last_req_push_front
00263   // --------------
00264 
00265   function void m_last_req_push_front(REQ item);
00266     if(!m_num_last_reqs)
00267       return;
00268  
00269     if(m_last_req_buffer.size() == m_num_last_reqs)
00270       void'(m_last_req_buffer.pop_back());
00271 
00272     this.m_last_req_buffer.push_front(item);
00273   endfunction
00274 
00275   // set_num_last_rsps
00276   // -----------------
00277 
00278   function void set_num_last_rsps(int unsigned max);
00279     if(max > 1024) begin
00280       ovm_report_warning("HSTOB", 
00281         $psprintf("Invalid last size; 1024 is the maximum and will be used", max));
00282       max = 1024;
00283     end
00284 
00285     //shrink the buffer
00286     while((m_last_rsp_buffer.size() != 0) && (m_last_rsp_buffer.size() > max)) begin
00287       void'(m_last_rsp_buffer.pop_back());
00288     end
00289 
00290     m_num_last_rsps = max;
00291 
00292   endfunction
00293 
00294   // get_num_last_rsps
00295   // -----------------
00296 
00297   function int unsigned get_num_last_rsps();
00298     return m_num_last_rsps;
00299   endfunction
00300 
00301   // last_rsp
00302   // --------
00303 
00304   function RSP last_rsp(int unsigned n = 0);
00305     if(n > m_num_last_rsps) begin
00306       ovm_report_warning("HSTOB",
00307         $psprintf("Invalid last access (%0d), the max history is %0d", n,
00308         m_num_last_rsps));
00309       return null;
00310     end
00311     if(n == m_last_rsp_buffer.size())
00312       return null;
00313   
00314     return m_last_rsp_buffer[n];
00315   endfunction
00316   
00317   // m_last_rsp_push_front
00318   // --------------
00319 
00320   function void m_last_rsp_push_front(RSP item);
00321     if(!m_num_last_rsps)
00322       return;
00323  
00324     if(m_last_rsp_buffer.size() == m_num_last_rsps)
00325       void'(m_last_rsp_buffer.pop_back());
00326 
00327     this.m_last_rsp_buffer.push_front(item);
00328   endfunction
00329 
00330 virtual task execute_item(ovm_sequence_item item);
00331     ovm_sequence_base temp_seq;
00332     
00333     temp_seq = new();
00334     item.set_sequencer(this);
00335     item.set_parent_sequence(temp_seq);
00336     temp_seq.set_sequencer(this);
00337     temp_seq.start_item(item);
00338     temp_seq.finish_item(item);
00339 endtask // execute_item
00340 
00341   virtual function void m_add_builtin_seqs(bit add_simple = 1);
00342     if(!sequence_ids.exists("ovm_random_sequence"))
00343       add_sequence("ovm_random_sequence");
00344     if(!sequence_ids.exists("ovm_exhaustive_sequence"))
00345       add_sequence("ovm_exhaustive_sequence");
00346     if(add_simple == 1)
00347       if(!sequence_ids.exists("ovm_simple_sequence"))
00348         add_sequence("ovm_simple_sequence");
00349   endfunction
00350 
00352   //
00353   // Backwards Compat
00354   // 
00356 
00357   // set_num_last_items
00358   // ----------------
00359 
00360   function void set_num_last_items(int unsigned max);
00361     set_num_last_reqs(max);
00362   endfunction
00363 
00364   // last
00365   // ----
00366 
00367   function ovm_sequence_item last(int unsigned n);
00368     return last_req(n);
00369   endfunction
00370 
00371 endclass
00372 
00373   
00374 

Intelligent Design Verification
Intelligent Design Verification
Project: OVM, Revision: 2.0.1
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.5.5
Wed Jan 7 19:27:18 2009
Find a documentation bug? Report bugs to: bugs.intelligentdv.com Project: DoxygenFilterSV